-
Notifications
You must be signed in to change notification settings - Fork 826
Submit a feature that applies graceful up and down #4670
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| discoveryManager.run(); | ||
| // ensure can invoke services in AFTER_REGISTRY | ||
| registrationManager.updateMicroserviceInstanceStatus(MicroserviceInstanceStatus.UP); | ||
| // registrationManager.updateMicroserviceInstanceStatus(MicroserviceInstanceStatus.UP); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not comment this statement. Add a configuration to support not update status to UP when service is registered.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checked the code, only service-center implements this method, the other registry just return true, the initialization status to properties/yml inside, the default is true, the registration status is also true, I think it will not affect the compatibility of this line of code to remove!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. Delete this line.
| if (instance.getHistoryStatus() == HistoryStatus.CURRENT | ||
| && instance.getMicroserviceInstanceStatus() == MicroserviceInstanceStatus.UP) { | ||
| result.add(instance); | ||
| continue; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Non UP status should added to list. InstanceStatusDiscoveryFilter will handle status priority.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've removed this filter.
| this.microserviceInstanceStatus = discoveryInstance.getStatus(); | ||
| } | ||
|
|
||
| public MicroserviceInstanceStatus getMicroserviceInstanceStatus() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can delete method getMicroserviceInstanceStatus and use getStatus for all appearances.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, the 'getMicroserviceInstanceStatus' method has been added to the MicroserviceInstance class.,as getStatus().
| if (scConfigurationProperties.isEnableElegantUpDown()){ | ||
| microserviceInstance.setStatus(MicroserviceInstanceStatus.STARTING); | ||
| }else { | ||
| microserviceInstance.setStatus(MicroserviceInstanceStatus.UP); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe do not need this modification. Users can configure initial status to STARTING when need elegant up down.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don`t need it ,have removed
| public boolean isEnableElegantUpDown() { | ||
| return enableElegantUpDown; | ||
| } | ||
|
|
||
| public void setEnableElegantUpDown(boolean enableElegantUpDown) { | ||
| this.enableElegantUpDown = enableElegantUpDown; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See above, maybe do not need this modification.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don`t need it ,have removed
| org.apache.servicecomb.service.center.client.model.DataCenterInfo dataCenterInfo = microserviceInstance.getDataCenterInfo(); | ||
| if (dataCenterInfo != null) { | ||
| return new DataCenterInfo(microserviceInstance.getDataCenterInfo().getName(), | ||
| microserviceInstance.getDataCenterInfo().getRegion(), | ||
| microserviceInstance.getDataCenterInfo().getAvailableZone()); | ||
| } | ||
| return new DataCenterInfo(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When DataCenterInfo is null? Can we add a fix to register DataCenterInfo?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| public MicroserviceInstance getLatestMicroserviceInstance() { | ||
| MicroserviceInstance latestInstance = serviceCenterClient.getMicroserviceInstance(microserviceInstance.getServiceId(), | ||
| microserviceInstance.getInstanceId()); | ||
| microserviceInstance.setStatus(latestInstance.getStatus()); | ||
| return latestInstance; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method is never used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method is used to externally query the latest instance state, and when the warm-up function updates the instance state, only the instance state that is STARTING can be updated to UP.
| public MicroserviceInstanceStatus getStatus() { | ||
| return status; | ||
| } | ||
|
|
||
| public void setStatus(MicroserviceInstanceStatus status) { | ||
| this.status = status; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can add getStatus to MicroserviceInstance and force all implementations provide status information.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, the 'getMicroserviceInstanceStatus' method has been added to the MicroserviceInstance class.,as getStatus().
| public ZookeeperInstance getZookeeperInstance(){ | ||
| try { | ||
| ServiceInstance<ZookeeperInstance> zkInstance = dis.queryForInstance(instance.getName(), instance.getId()); | ||
| if (zkInstance != null){ | ||
| return zkInstance.getPayload(); | ||
| } | ||
| } catch (Exception e) { | ||
| throw new RuntimeException(e); | ||
| } | ||
| return null; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method never used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method is used to externally query the latest instance state, and when the warm-up function updates the instance state, only the instance state that is STARTING can be updated to UP
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don`t need it ,remove
| this.instance.getPayload().setStatus(status); | ||
| try { | ||
| if (status == MicroserviceInstanceStatus.UP){ | ||
| dis.updateService(instance); | ||
| } | ||
| if (status == MicroserviceInstanceStatus.DOWN){ | ||
| dis.registerService(instance); | ||
| } | ||
| } catch (Exception e){ | ||
| throw new IllegalStateException(e); | ||
| } | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why use registerService when Down?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
has been changed to updateService()
| }else { | ||
| zookeeperInstance.setStatus(MicroserviceInstanceStatus.UP); | ||
| } | ||
| try { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should use initialstatus, do not need isEnableElegantUpDown
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don`t need it ,have removed
| microserviceInstance.getDataCenterInfo().getRegion(), | ||
| microserviceInstance.getDataCenterInfo().getAvailableZone()); | ||
| org.apache.servicecomb.service.center.client.model.DataCenterInfo dataCenterInfo = microserviceInstance.getDataCenterInfo(); | ||
| if (dataCenterInfo != null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe you can init DataCenterInfo when init MicroserviceInstance, so that not need this modification.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don`t need it ,have removed, Setting the initial value on DataCenterProperties
| public MicroserviceInstanceStatus getStatus() { | ||
| return instance.isEnabled() ? MicroserviceInstanceStatus.UP : MicroserviceInstanceStatus.DOWN; | ||
| if (instance.isEnabled()){ | ||
| return MicroserviceInstanceStatus.valueOf(instance.getMetadata().get(NacosConst.NACOS_STATUS)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instance.getMetadata().get(NacosConst.NACOS_STATUS maybe null for old versions instance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new version will definitely have status in metadata, so Returns up if status is not found in the old version in metadata.
| public String getInitialStatus() { | ||
| return initialStatus; | ||
| } | ||
|
|
||
| public void setInitialStatus(String initialStatus) { | ||
| this.initialStatus = initialStatus; | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use common configration servicecomb.instance.initialStatus, see SC how to read it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nacos,ZK,ServiceCenter has used common configration servicecomb.instance.initialStatus
| if (MicroserviceInstanceStatus.UP == status){ | ||
| instance.getMetadata().put(NacosConst.NACOS_STATUS, MicroserviceInstanceStatus.UP.name()); | ||
| namingService.registerInstance(nacosRegistrationInstance.getServiceName(), | ||
| nacosRegistrationInstance.getApplication(), instance); | ||
| } | ||
| if (MicroserviceInstanceStatus.DOWN == status){ | ||
| instance.getMetadata().put(NacosConst.NACOS_STATUS, MicroserviceInstanceStatus.DOWN.name()); | ||
| namingService.deregisterInstance(nacosRegistrationInstance.getServiceName(), | ||
| nacosRegistrationInstance.getApplication(), instance); | ||
| } | ||
| return true; | ||
| } catch (Exception e) { | ||
| throw new RuntimeException(e); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about update to other status? like TESTING?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, Instance status equal DOWN to exec 'deregisterInstance()' method, the other exec 'registerInstance()'
| * This is the core service registration interface. <br/> | ||
| */ | ||
| public interface Registration<R extends RegistrationInstance> extends SPIEnabled, SPIOrder, LifeCycle { | ||
| public interface Registration<R extends MicroserviceInstance> extends SPIEnabled, SPIOrder, LifeCycle { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why made this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don`r need method 'getnitialStatus()' and 'getReadyStatus()'
| return instance.isEnabled() ? MicroserviceInstanceStatus.UP : MicroserviceInstanceStatus.DOWN; | ||
| if (instance.isEnabled()) { | ||
| String instanceStatus = instance.getMetadata().get(NacosConst.NACOS_STATUS); | ||
| if (StringUtils.isBlank(instanceStatus)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be isEmpty?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
U said "instance.getMetadata().get(NacosConst.NACOS_STATUS maybe null for old versions instance." before,so i do it .
| if (MicroserviceInstanceStatus.DOWN == status) { | ||
| instance.getMetadata().put(NacosConst.NACOS_STATUS, MicroserviceInstanceStatus.DOWN.name()); | ||
| namingService.deregisterInstance(nacosRegistrationInstance.getServiceName(), | ||
| nacosRegistrationInstance.getApplication(), instance); | ||
| } else { | ||
| instance.getMetadata().put(NacosConst.NACOS_STATUS, status.name()); | ||
| namingService.registerInstance(nacosRegistrationInstance.getServiceName(), | ||
| nacosRegistrationInstance.getApplication(), instance); | ||
| } | ||
| return true; | ||
| } catch (Exception e) { | ||
| throw new RuntimeException(e); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whatever status, update. No need to check status. Will registerInstance cause two instances? If Nacos do not support update status, maybe we can not use this feature for nacos.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nacos register Instance again ,old instance will be covery. For Down, just deregister instance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's better only set status, do not deregister instance.
| return new DataCenterInfo(microserviceInstance.getDataCenterInfo().getName(), | ||
| microserviceInstance.getDataCenterInfo().getRegion(), | ||
| microserviceInstance.getDataCenterInfo().getAvailableZone()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seams nothing changed, but format is wrong .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it`s changed
…thod 'getInitialStatus()' and 'getReadyStatus()'
… to replace customizable settings

Modify the zookeeper and service-center registry code to be able to modify the state to support graceful application up and down.