-
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 2 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 |
|---|---|---|
|
|
@@ -142,7 +142,11 @@ public static MicroserviceInstance createMicroserviceInstance( | |
| properties.putAll(BootStrapProperties.readServiceProperties(environment)); | ||
| properties.putAll(genCasProperties(environment)); | ||
| microserviceInstance.setProperties(properties); | ||
| microserviceInstance.setStatus(MicroserviceInstanceStatus.valueOf(scConfigurationProperties.getInitialStatus())); | ||
| if (scConfigurationProperties.isEnableElegantUpDown()){ | ||
| microserviceInstance.setStatus(MicroserviceInstanceStatus.STARTING); | ||
| }else { | ||
| microserviceInstance.setStatus(MicroserviceInstanceStatus.UP); | ||
| } | ||
|
||
| return microserviceInstance; | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,6 +28,8 @@ public class SCConfigurationProperties { | |
|
|
||
| private boolean enableSwaggerRegistration = false; | ||
|
|
||
| private boolean enableElegantUpDown = false; | ||
|
|
||
| /** | ||
| * for registration service | ||
| * when swagger is different between local with remote serviceCenter. if ignoreSwaggerDifferent is true. | ||
|
|
@@ -171,4 +173,12 @@ public boolean isEnableSwaggerRegistration() { | |
| public void setEnableSwaggerRegistration(boolean enableSwaggerRegistration) { | ||
| this.enableSwaggerRegistration = enableSwaggerRegistration; | ||
| } | ||
|
|
||
| public boolean isEnableElegantUpDown() { | ||
| return enableElegantUpDown; | ||
| } | ||
|
|
||
| public void setEnableElegantUpDown(boolean enableElegantUpDown) { | ||
| this.enableElegantUpDown = enableElegantUpDown; | ||
| } | ||
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -76,9 +76,13 @@ public String getVersion() { | |
|
|
||
| @Override | ||
| public DataCenterInfo getDataCenterInfo() { | ||
| return new DataCenterInfo(microserviceInstance.getDataCenterInfo().getName(), | ||
| microserviceInstance.getDataCenterInfo().getRegion(), | ||
| microserviceInstance.getDataCenterInfo().getAvailableZone()); | ||
| 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(); | ||
|
||
| } | ||
|
|
||
| @Override | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -195,4 +195,10 @@ public Microservice getBackendMicroservice() { | |
| public MicroserviceInstance getBackendMicroserviceInstance() { | ||
| 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 |
|---|---|---|
|
|
@@ -23,6 +23,7 @@ | |
|
|
||
| import org.apache.servicecomb.registry.api.DataCenterInfo; | ||
| import org.apache.servicecomb.registry.api.MicroserviceInstance; | ||
| import org.apache.servicecomb.registry.api.MicroserviceInstanceStatus; | ||
|
|
||
| public class ZookeeperInstance implements MicroserviceInstance { | ||
| private String serviceId; | ||
|
|
@@ -49,6 +50,8 @@ public class ZookeeperInstance implements MicroserviceInstance { | |
|
|
||
| private Map<String, String> properties = new HashMap<>(); | ||
|
|
||
| private MicroserviceInstanceStatus status; | ||
|
|
||
| public ZookeeperInstance() { | ||
|
|
||
| } | ||
|
|
@@ -66,6 +69,8 @@ public ZookeeperInstance(ZookeeperInstance other) { | |
| this.endpoints = other.endpoints; | ||
| this.schemas = other.schemas; | ||
| this.properties = other.properties; | ||
| this.status = other.status; | ||
|
|
||
| } | ||
|
|
||
| public void setServiceId(String serviceId) { | ||
|
|
@@ -187,4 +192,12 @@ public String getInstanceId() { | |
| public String getServiceId() { | ||
| return serviceId; | ||
| } | ||
|
|
||
| public MicroserviceInstanceStatus getStatus() { | ||
| return status; | ||
| } | ||
|
|
||
| public void setStatus(MicroserviceInstanceStatus status) { | ||
| this.status = status; | ||
|
||
| } | ||
| } | ||
| 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,12 @@ public void init() { | |
| } | ||
| zookeeperInstance.setProperties(BootStrapProperties.readServiceProperties(environment)); | ||
| zookeeperInstance.setVersion(BootStrapProperties.readServiceVersion(environment)); | ||
|
|
||
| if (zookeeperRegistryProperties.isEnableElegantUpDown()){ | ||
| zookeeperInstance.setStatus(MicroserviceInstanceStatus.STARTING); | ||
| }else { | ||
| zookeeperInstance.setStatus(MicroserviceInstanceStatus.UP); | ||
| } | ||
| 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 +163,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 +195,19 @@ public ZookeeperRegistrationInstance getMicroserviceInstance() { | |
|
|
||
| @Override | ||
| public boolean updateMicroserviceInstanceStatus(MicroserviceInstanceStatus status) { | ||
| // not support yet | ||
| return true; | ||
| 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); | ||
| } | ||
|
|
||
|
||
| return true; | ||
| } | ||
|
|
||
| @Override | ||
|
|
@@ -212,4 +231,17 @@ public void addProperty(String key, String value) { | |
| public boolean enabled() { | ||
| return zookeeperRegistryProperties.isEnabled(); | ||
| } | ||
|
|
||
| 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.