aboutsummaryrefslogtreecommitdiffstats
path: root/sdclient/discovery-service/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'sdclient/discovery-service/src/main')
-rw-r--r--sdclient/discovery-service/src/main/java/org/onap/msb/sdclient/wrapper/ConsulClientApp.java153
-rw-r--r--sdclient/discovery-service/src/main/java/org/onap/msb/sdclient/wrapper/consul/cache/ConsulCache.java7
-rw-r--r--sdclient/discovery-service/src/main/java/org/onap/msb/sdclient/wrapper/consul/cache/HealthCache.java16
3 files changed, 80 insertions, 96 deletions
diff --git a/sdclient/discovery-service/src/main/java/org/onap/msb/sdclient/wrapper/ConsulClientApp.java b/sdclient/discovery-service/src/main/java/org/onap/msb/sdclient/wrapper/ConsulClientApp.java
index 28937bc..9ddb2e7 100644
--- a/sdclient/discovery-service/src/main/java/org/onap/msb/sdclient/wrapper/ConsulClientApp.java
+++ b/sdclient/discovery-service/src/main/java/org/onap/msb/sdclient/wrapper/ConsulClientApp.java
@@ -72,115 +72,112 @@ public class ConsulClientApp {
*/
public HealthCache startHealthNodeListen(final String serviceName) {
final HealthCache healthCache = HealthCache.newCache(healthClient, serviceName, 30);
- healthCache.addListener(new HealthCache.Listener<String, ServiceHealth>() {
- @Override
- public void notify(Map<String, ServiceHealth> newValues) {
- // do Something with updated server map
- LOGGER.info(serviceName + "--new node notify--");
-
-
- if (newValues.isEmpty()) {
- LOGGER.warn(serviceName + "--nodeList is Empty--");
- PublishAddressWrapper.publishApigateWayList.remove(serviceName);
-
- try {
- healthCache.stop();
- LOGGER.info(serviceName + " Node Listen stopped");
- } catch (Exception e) {
- LOGGER.error(serviceName + " Node Listen stop throw exception", e);
- }
+ healthCache.addListener(newValues -> {
+ // do Something with updated server map
+ LOGGER.info(serviceName + "--new node notify--");
+
- return;
+ if (newValues.isEmpty()) {
+ LOGGER.warn(serviceName + "--nodeList is Empty--");
+ PublishAddressWrapper.publishApigateWayList.remove(serviceName);
+
+ try {
+ healthCache.stop();
+ LOGGER.info(serviceName + " Node Listen stopped");
+ } catch (Exception e) {
+ LOGGER.error(serviceName + " Node Listen stop throw exception", e);
}
- // 服务发现变化
- List<MicroServiceFullInfo> nodeAddressList = new ArrayList<MicroServiceFullInfo>();
- for (Map.Entry<String, ServiceHealth> entry : newValues.entrySet()) {
- MicroServiceFullInfo microServiceInfo = new MicroServiceFullInfo();
+ return;
+ }
+ // 服务发现变化
+ List<MicroServiceFullInfo> nodeAddressList = new ArrayList<MicroServiceFullInfo>();
+ for (Map.Entry<String, ServiceHealth> entry : newValues.entrySet()) {
- ServiceHealth value = (ServiceHealth) entry.getValue();
- Service service = value.getService();
+ MicroServiceFullInfo microServiceInfo = new MicroServiceFullInfo();
- NodeInfo node = new NodeInfo();
- node.setIp(service.getAddress());
- node.setPort(String.valueOf(service.getPort()));
- Set<NodeInfo> nodes = new HashSet<NodeInfo>();
- nodes.add(node);
- microServiceInfo.setNodes(nodes);
+ ServiceHealth value = (ServiceHealth) entry.getValue();
+ Service service = value.getService();
+ NodeInfo node = new NodeInfo();
+ node.setIp(service.getAddress());
+ node.setPort(String.valueOf(service.getPort()));
+ Set<NodeInfo> nodes = new HashSet<NodeInfo>();
+ nodes.add(node);
+ microServiceInfo.setNodes(nodes);
- microServiceInfo.setServiceName(serviceName);
- try {
- List<String> tagList = service.getTags();
+ microServiceInfo.setServiceName(serviceName);
+ try {
+ List<String> tagList = service.getTags();
- for (String tag : tagList) {
- if (tag.startsWith("\"ns\"")) {
- String ms_ns_json = tag.split("\"ns\":")[1];
- Map<String, String> nsMap =
- (Map<String, String>) JacksonJsonUtil.jsonToBean(ms_ns_json, Map.class);
+ for (String tag : tagList) {
- if (nsMap.get("namespace") != null) {
- microServiceInfo.setNamespace(nsMap.get("namespace"));
- }
+ if (tag.startsWith("\"ns\"")) {
+ String ms_ns_json = tag.split("\"ns\":")[1];
+ Map<String, String> nsMap =
+ (Map<String, String>) JacksonJsonUtil.jsonToBean(ms_ns_json, Map.class);
- continue;
+ if (nsMap.get("namespace") != null) {
+ microServiceInfo.setNamespace(nsMap.get("namespace"));
}
- if (tag.startsWith("\"labels\"")) {
- String ms_labels_json = "{" + tag.split("\"labels\":\\{")[1];
- Map<String, String> labelMap = (Map<String, String>) JacksonJsonUtil
- .jsonToBean(ms_labels_json, Map.class);
-
- List<String> nodeLabels = new ArrayList<String>();
- for (Map.Entry<String, String> labelEntry : labelMap.entrySet()) {
- if ("visualRange".equals(labelEntry.getKey())) {
- microServiceInfo.setVisualRange(labelEntry.getValue());
- } else if ("network_plane_type".equals(labelEntry.getKey())) {
- microServiceInfo.setNetwork_plane_type(labelEntry.getValue());
- } else {
- nodeLabels.add(labelEntry.getKey() + ":" + labelEntry.getValue());
- }
+ continue;
+ }
+ if (tag.startsWith("\"labels\"")) {
+ String ms_labels_json = "{" + tag.split("\"labels\":\\{")[1];
+ Map<String, String> labelMap = (Map<String, String>) JacksonJsonUtil
+ .jsonToBean(ms_labels_json, Map.class);
+
+ List<String> nodeLabels = new ArrayList<String>();
+ for (Map.Entry<String, String> labelEntry : labelMap.entrySet()) {
+ if ("visualRange".equals(labelEntry.getKey())) {
+ microServiceInfo.setVisualRange(labelEntry.getValue());
+ } else if ("network_plane_type".equals(labelEntry.getKey())) {
+ microServiceInfo.setNetwork_plane_type(labelEntry.getValue());
+ } else {
+ nodeLabels.add(labelEntry.getKey() + ":" + labelEntry.getValue());
}
- microServiceInfo.setLabels(nodeLabels);
- continue;
}
- if (tag.startsWith("\"metadata\"")) {
- String ms_metadata_json = "{" + tag.split("\"metadata\":\\{")[1];
- Map<String, String> metadataMap = (Map<String, String>) JacksonJsonUtil
- .jsonToBean(ms_metadata_json, Map.class);
+ microServiceInfo.setLabels(nodeLabels);
+ continue;
+ }
- List<KeyVaulePair> ms_metadata = new ArrayList<KeyVaulePair>();
+ if (tag.startsWith("\"metadata\"")) {
+ String ms_metadata_json = "{" + tag.split("\"metadata\":\\{")[1];
+ Map<String, String> metadataMap = (Map<String, String>) JacksonJsonUtil
+ .jsonToBean(ms_metadata_json, Map.class);
+ List<KeyVaulePair> ms_metadata = new ArrayList<KeyVaulePair>();
- for (Map.Entry<String, String> metadataEntry : metadataMap.entrySet()) {
- KeyVaulePair keyVaulePair = new KeyVaulePair();
- keyVaulePair.setKey(metadataEntry.getKey());
- keyVaulePair.setValue(metadataEntry.getValue());
- ms_metadata.add(keyVaulePair);
- }
- microServiceInfo.setMetadata(ms_metadata);
- continue;
- }
+ for (Map.Entry<String, String> metadataEntry : metadataMap.entrySet()) {
+ KeyVaulePair keyVaulePair = new KeyVaulePair();
+ keyVaulePair.setKey(metadataEntry.getKey());
+ keyVaulePair.setValue(metadataEntry.getValue());
+ ms_metadata.add(keyVaulePair);
+ }
+ microServiceInfo.setMetadata(ms_metadata);
+ continue;
}
-
- } catch (Exception e) {
- LOGGER.error(serviceName + " read tag throw exception", e);
}
- nodeAddressList.add(microServiceInfo);
- }
- PublishAddressWrapper.publishApigateWayList.put(serviceName, nodeAddressList);
+ } catch (Exception e) {
+ LOGGER.error(serviceName + " read tag throw exception", e);
+ }
+ nodeAddressList.add(microServiceInfo);
}
+
+ PublishAddressWrapper.publishApigateWayList.put(serviceName, nodeAddressList);
+
});
try {
LOGGER.info(serviceName + " Node Listen start");
diff --git a/sdclient/discovery-service/src/main/java/org/onap/msb/sdclient/wrapper/consul/cache/ConsulCache.java b/sdclient/discovery-service/src/main/java/org/onap/msb/sdclient/wrapper/consul/cache/ConsulCache.java
index ab8098b..4abe051 100644
--- a/sdclient/discovery-service/src/main/java/org/onap/msb/sdclient/wrapper/consul/cache/ConsulCache.java
+++ b/sdclient/discovery-service/src/main/java/org/onap/msb/sdclient/wrapper/consul/cache/ConsulCache.java
@@ -110,12 +110,7 @@ public class ConsulCache<K, V> {
LOGGER.error(String.format("Error getting response from consul. will retry in %d %s", backoffDelayQty,
backoffDelayUnit), throwable);
- executorService.schedule(new Runnable() {
- @Override
- public void run() {
- runCallback();
- }
- }, backoffDelayQty, backoffDelayUnit);
+ executorService.schedule(ConsulCache.this::runCallback, backoffDelayQty, backoffDelayUnit);
}
};
}
diff --git a/sdclient/discovery-service/src/main/java/org/onap/msb/sdclient/wrapper/consul/cache/HealthCache.java b/sdclient/discovery-service/src/main/java/org/onap/msb/sdclient/wrapper/consul/cache/HealthCache.java
index 60ba877..cf42689 100644
--- a/sdclient/discovery-service/src/main/java/org/onap/msb/sdclient/wrapper/consul/cache/HealthCache.java
+++ b/sdclient/discovery-service/src/main/java/org/onap/msb/sdclient/wrapper/consul/cache/HealthCache.java
@@ -36,20 +36,12 @@ public class HealthCache extends ConsulCache<String, ServiceHealth> {
public static HealthCache newCache(final HealthClient healthClient, final String serviceName,
final int watchSeconds) {
- Function<ServiceHealth, String> keyExtractor = new Function<ServiceHealth, String>() {
- @Override
- public String apply(ServiceHealth input) {
- // return input.getKey().substring(rootPath.length() + 1);
- return input.getService().getId();
- }
+ Function<ServiceHealth, String> keyExtractor = input -> {
+ // return input.getKey().substring(rootPath.length() + 1);
+ return input.getService().getId();
};
- final CallbackConsumer<ServiceHealth> callbackConsumer = new CallbackConsumer<ServiceHealth>() {
- @Override
- public void consume(BigInteger index, ConsulResponseCallback<List<ServiceHealth>> callback) {
- healthClient.getHealthyServiceInstances(serviceName, watchParams(index, watchSeconds), callback);
- }
- };
+ final CallbackConsumer<ServiceHealth> callbackConsumer = (index, callback) -> healthClient.getHealthyServiceInstances(serviceName, watchParams(index, watchSeconds), callback);
return new HealthCache(keyExtractor, callbackConsumer, serviceName);