-
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
Changes from 4 commits
83b1585
8d5c0bb
8c5d8e4
cae38de
ff52d42
7ca6e02
004aa32
a76ae7d
2d6e04b
860b5d4
1352218
c100c8a
fc48c8f
83339e8
95bb8bc
89b84d5
568c627
2a0801f
e70bcfb
2da0311
911429c
b4ecf04
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -178,7 +178,8 @@ private VersionedCache calcAvailableInstance(String application, String serviceN | |
| -> new ConcurrentHashMapEx<>()); | ||
| List<StatefulDiscoveryInstance> result = new ArrayList<>(); | ||
| for (StatefulDiscoveryInstance instance : statefulInstances.values()) { | ||
| if (instance.getHistoryStatus() == HistoryStatus.CURRENT) { | ||
| if (instance.getHistoryStatus() == HistoryStatus.CURRENT | ||
| && instance.getMicroserviceInstanceStatus() == MicroserviceInstanceStatus.UP) { | ||
| result.add(instance); | ||
| continue; | ||
| } | ||
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -62,6 +62,7 @@ public enum HistoryStatus { | |
|
|
||
| public StatefulDiscoveryInstance(DiscoveryInstance discoveryInstance) { | ||
| this.discoveryInstance = discoveryInstance; | ||
| this.microserviceInstanceStatus = discoveryInstance.getStatus(); | ||
| } | ||
|
|
||
| public MicroserviceInstanceStatus getMicroserviceInstanceStatus() { | ||
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -57,7 +57,11 @@ public NacosDiscoveryInstance(Instance instance, String application, String serv | |
|
|
||
| @Override | ||
| public MicroserviceInstanceStatus getStatus() { | ||
| return instance.isEnabled() ? MicroserviceInstanceStatus.UP : MicroserviceInstanceStatus.DOWN; | ||
| if (instance.isEnabled()){ | ||
| return MicroserviceInstanceStatus.valueOf(instance.getMetadata().get(NacosConst.NACOS_STATUS)); | ||
|
||
| } else { | ||
| return MicroserviceInstanceStatus.DOWN; | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -49,6 +49,8 @@ public class NacosDiscoveryProperties { | |
|
|
||
| private boolean enableSwaggerRegistration = false; | ||
|
|
||
| private String initialStatus = "UP"; | ||
|
|
||
| public String getServerAddr() { | ||
| return serverAddr; | ||
| } | ||
|
|
@@ -160,4 +162,12 @@ public boolean isEnableSwaggerRegistration() { | |
| public void setEnableSwaggerRegistration(boolean enableSwaggerRegistration) { | ||
| this.enableSwaggerRegistration = enableSwaggerRegistration; | ||
| } | ||
|
|
||
| public String getInitialStatus() { | ||
| return initialStatus; | ||
| } | ||
|
|
||
| public void setInitialStatus(String initialStatus) { | ||
| this.initialStatus = initialStatus; | ||
| } | ||
| } | ||
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -132,9 +132,21 @@ public NacosRegistrationInstance getMicroserviceInstance() { | |
|
|
||
| @Override | ||
| public boolean updateMicroserviceInstanceStatus(MicroserviceInstanceStatus status) { | ||
| // Do not support Nacos update status now. Because update status will fail | ||
| // due to some unknown reasons(Maybe different constrains in register and maintain api). | ||
| return true; | ||
| try { | ||
| 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); | ||
| } | ||
|
||
| } | ||
|
|
||
| @Override | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -76,9 +76,9 @@ public String getVersion() { | |
|
|
||
| @Override | ||
| public DataCenterInfo getDataCenterInfo() { | ||
| return new DataCenterInfo(microserviceInstance.getDataCenterInfo().getName(), | ||
| microserviceInstance.getDataCenterInfo().getRegion(), | ||
| microserviceInstance.getDataCenterInfo().getAvailableZone()); | ||
| return new DataCenterInfo(microserviceInstance.getDataCenterInfo().getName(), | ||
| microserviceInstance.getDataCenterInfo().getRegion(), | ||
| microserviceInstance.getDataCenterInfo().getAvailableZone()); | ||
|
||
| } | ||
|
|
||
| @Override | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -195,4 +195,15 @@ public Microservice getBackendMicroservice() { | |
| public MicroserviceInstance getBackendMicroserviceInstance() { | ||
| return microserviceInstance; | ||
| } | ||
|
|
||
| /** | ||
| * Returns the latest instance for checking when updating the instance status from STARTING to UP. | ||
| * @return MicroserviceInstance | ||
| */ | ||
| public MicroserviceInstance getLatestMicroserviceInstance() { | ||
| MicroserviceInstance latestInstance = serviceCenterClient.getMicroserviceInstance(microserviceInstance.getServiceId(), | ||
| microserviceInstance.getInstanceId()); | ||
| microserviceInstance.setStatus(latestInstance.getStatus()); | ||
| return latestInstance; | ||
| } | ||
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -79,6 +79,8 @@ public AppConfigurationEntry[] getAppConfigurationEntry(String name) { | |
|
|
||
| private RegistrationId registrationId; | ||
|
|
||
| private ServiceDiscovery<ZookeeperInstance> dis; | ||
|
|
||
| @Autowired | ||
| @SuppressWarnings("unused") | ||
| public void setEnvironment(Environment environment) { | ||
|
|
@@ -125,6 +127,8 @@ public void init() { | |
| } | ||
| zookeeperInstance.setProperties(BootStrapProperties.readServiceProperties(environment)); | ||
| zookeeperInstance.setVersion(BootStrapProperties.readServiceVersion(environment)); | ||
|
|
||
| zookeeperInstance.setStatus(MicroserviceInstanceStatus.valueOf(zookeeperRegistryProperties.getInitialStatus())); | ||
| try { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should use
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. don`t need it ,have removed |
||
| this.instance = ServiceInstance.<ZookeeperInstance>builder().name(zookeeperInstance.getServiceName()) | ||
| .id(zookeeperInstance.getInstanceId()).payload(zookeeperInstance).build(); | ||
|
|
@@ -155,7 +159,7 @@ public void run() { | |
| client.start(); | ||
| JsonInstanceSerializer<ZookeeperInstance> serializer = | ||
| new JsonInstanceSerializer<>(ZookeeperInstance.class); | ||
| ServiceDiscovery<ZookeeperInstance> dis = ServiceDiscoveryBuilder.builder(ZookeeperInstance.class) | ||
| dis = ServiceDiscoveryBuilder.builder(ZookeeperInstance.class) | ||
| .client(client) | ||
| .basePath(basePath + "/" + BootStrapProperties.readApplication(environment)) | ||
| .serializer(serializer) | ||
|
|
@@ -187,8 +191,13 @@ public ZookeeperRegistrationInstance getMicroserviceInstance() { | |
|
|
||
| @Override | ||
| public boolean updateMicroserviceInstanceStatus(MicroserviceInstanceStatus status) { | ||
| // not support yet | ||
| return true; | ||
| this.instance.getPayload().setStatus(status); | ||
| try { | ||
| dis.updateService(instance); | ||
| } catch (Exception e){ | ||
| throw new IllegalStateException(e); | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
| @Override | ||
|
|
@@ -212,4 +221,21 @@ public void addProperty(String key, String value) { | |
| public boolean enabled() { | ||
| return zookeeperRegistryProperties.isEnabled(); | ||
| } | ||
|
|
||
| /** | ||
| * Returns the latest instance for checking when updating the instance status from STARTING to UP. | ||
| * @return ZookeeperInstance | ||
| */ | ||
| 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.
Do not comment this statement. Add a configuration to support not update status to
UPwhen 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.