Skip to content

Commit

Permalink
Merge pull request #38 from andrewshan/main
Browse files Browse the repository at this point in the history
feat: consul加上定位信息
  • Loading branch information
andrewshan authored Aug 23, 2022
2 parents e6e720f + 8320156 commit 3212448
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,11 @@ private List<Instance> convertConsulInstance(Service service, List<HealthService
}
Map<String, String> filters = (null == group ? null : group.getMetadataMap());
for (HealthService healthService : instances) {
LOG.info("[Consul]convert instance {}", healthService);
HealthService.Service instance = healthService.getService();
Map<String, String> metadata = instance.getMeta();
boolean matched = CommonUtils.matchMetadata(metadata, filters);
LOG.info("[Consul]convert instance {}, matched {}", healthService, matched);
if (!matched) {
continue;
}
Expand All @@ -211,7 +213,9 @@ private List<Instance> convertConsulInstance(Service service, List<HealthService
builder.setService(ResponseUtils.toStringValue(service.getService()));
builder.setHost(ResponseUtils.toStringValue(instance.getAddress()));
builder.setPort(ResponseUtils.toUInt32Value(instance.getPort()));
builder.putAllMetadata(CommonUtils.defaultMap(instance.getMeta()));
if (!CollectionUtils.isEmpty(instance.getMeta())) {
builder.putAllMetadata(instance.getMeta());
}
builder.setWeight(ResponseUtils.toUInt32Value(100));
builder.setHealthy(ResponseUtils.toBooleanValue(true));
builder.setIsolate(ResponseUtils.toBooleanValue(false));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,9 @@ private List<ServiceProto.Instance> convertNacosInstances(Service service, List<
builder.setNamespace(ResponseUtils.toStringValue(service.getNamespace()));
builder.setService(ResponseUtils.toStringValue(service.getService()));
builder.setWeight(ResponseUtils.toUInt32Value((int) weight));
builder.putAllMetadata(CommonUtils.defaultMap(metadata));
if (!CollectionUtils.isEmpty(metadata)) {
builder.putAllMetadata(metadata);
}
builder.setHost(ResponseUtils.toStringValue(ip));
builder.setPort(ResponseUtils.toUInt32Value(port));
builder.setIsolate(ResponseUtils.toBooleanValue(!enabled));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,9 @@ private List<ServiceProto.Instance> convertPolarisInstances(com.tencent.polaris.
ServiceProto.Instance.Builder builder = ServiceProto.Instance.newBuilder();
builder.setId(ResponseUtils.toStringValue(instanceId));
builder.setWeight(ResponseUtils.toUInt32Value(instance.getWeight()));
builder.putAllMetadata(CommonUtils.defaultMap(metadata));
if (CollectionUtils.isEmpty(metadata)) {
builder.putAllMetadata(metadata);
}
builder.setHost(ResponseUtils.toStringValue(ip));
builder.setPort(ResponseUtils.toUInt32Value(port));
builder.setIsolate(ResponseUtils.toBooleanValue(instance.isIsolated()));
Expand Down

0 comments on commit 3212448

Please sign in to comment.