use of org.apache.servicecomb.registry.consumer.AppManager in project java-chassis by ServiceComb.
the class OperationInstancesDiscoveryFilter method sortedMicroserviceVersion.
protected List<MicroserviceVersion> sortedMicroserviceVersion(Invocation invocation, Map<String, MicroserviceInstance> instances) {
OperationMeta latestOperationMeta = invocation.getOperationMeta();
MicroserviceMeta latestMicroserviceMeta = latestOperationMeta.getSchemaMeta().getMicroserviceMeta();
AppManager appManager = DiscoveryManager.INSTANCE.getAppManager();
MicroserviceVersions microserviceVersions = appManager.getOrCreateMicroserviceVersions(latestMicroserviceMeta.getAppId(), latestMicroserviceMeta.getMicroserviceName());
Map<String, MicroserviceVersion> uniqueMicroserviceVersion = new HashMap<>();
for (MicroserviceInstance instance : instances.values()) {
MicroserviceVersion microserviceVersion = microserviceVersions.getVersion(instance.getServiceId());
uniqueMicroserviceVersion.put(instance.getServiceId(), microserviceVersion);
}
return uniqueMicroserviceVersion.values().stream().sorted(Comparator.comparing(MicroserviceVersion::getVersion)).collect(Collectors.toList());
}
Aggregations