Search in sources :

Example 1 with AppManager

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());
}
Also used : HashMap(java.util.HashMap) MicroserviceVersion(org.apache.servicecomb.registry.consumer.MicroserviceVersion) AppManager(org.apache.servicecomb.registry.consumer.AppManager) MicroserviceMeta(org.apache.servicecomb.core.definition.MicroserviceMeta) MicroserviceInstance(org.apache.servicecomb.registry.api.registry.MicroserviceInstance) OperationMeta(org.apache.servicecomb.core.definition.OperationMeta) MicroserviceVersions(org.apache.servicecomb.registry.consumer.MicroserviceVersions)

Aggregations

HashMap (java.util.HashMap)1 MicroserviceMeta (org.apache.servicecomb.core.definition.MicroserviceMeta)1 OperationMeta (org.apache.servicecomb.core.definition.OperationMeta)1 MicroserviceInstance (org.apache.servicecomb.registry.api.registry.MicroserviceInstance)1 AppManager (org.apache.servicecomb.registry.consumer.AppManager)1 MicroserviceVersion (org.apache.servicecomb.registry.consumer.MicroserviceVersion)1 MicroserviceVersions (org.apache.servicecomb.registry.consumer.MicroserviceVersions)1