Search in sources :

Example 1 with AppManager

use of org.apache.servicecomb.serviceregistry.consumer.AppManager in project incubator-servicecomb-java-chassis by apache.

the class AbstractServiceRegistry method initAppManager.

protected void initAppManager() throws InstantiationException, IllegalAccessException, ClassNotFoundException {
    appManager = new AppManager(eventBus);
    // we did not remove old InstanceCacheManager now
    // microserviceVersionFactoryClass is null, means use old InstanceCacheManager
    // must not throw exception
    String microserviceVersionFactoryClass = serviceRegistryConfig.getMicroserviceVersionFactory();
    if (microserviceVersionFactoryClass == null) {
        return;
    }
    MicroserviceVersionFactory microserviceVersionFactory = (MicroserviceVersionFactory) Class.forName(microserviceVersionFactoryClass).newInstance();
    appManager.setMicroserviceVersionFactory(microserviceVersionFactory);
    LOGGER.info("microserviceVersionFactory is {}.", microserviceVersionFactoryClass);
}
Also used : AppManager(org.apache.servicecomb.serviceregistry.consumer.AppManager) MicroserviceVersionFactory(org.apache.servicecomb.serviceregistry.consumer.MicroserviceVersionFactory)

Example 2 with AppManager

use of org.apache.servicecomb.serviceregistry.consumer.AppManager in project incubator-servicecomb-java-chassis by apache.

the class OperationInstancesDiscoveryFilter method groupByVersion.

protected Map<MicroserviceVersionMeta, Map<String, MicroserviceInstance>> groupByVersion(Invocation invocation, Map<String, MicroserviceInstance> instances) {
    OperationMeta latestOperationMeta = invocation.getOperationMeta();
    MicroserviceMeta latestMicroserviceMeta = latestOperationMeta.getSchemaMeta().getMicroserviceMeta();
    AppManager appManager = RegistryUtils.getServiceRegistry().getAppManager();
    MicroserviceVersions MicroserviceVersions = appManager.getOrCreateMicroserviceVersions(latestMicroserviceMeta.getAppId(), latestMicroserviceMeta.getName());
    Map<MicroserviceVersionMeta, Map<String, MicroserviceInstance>> versionMap = new IdentityHashMap<>();
    for (MicroserviceInstance instance : instances.values()) {
        MicroserviceVersionMeta versionMeta = MicroserviceVersions.getVersion(instance.getServiceId());
        Map<String, MicroserviceInstance> versionInstances = versionMap.computeIfAbsent(versionMeta, vm -> {
            return new HashMap<>();
        });
        versionInstances.put(instance.getInstanceId(), instance);
    }
    return versionMap;
}
Also used : IdentityHashMap(java.util.IdentityHashMap) HashMap(java.util.HashMap) AppManager(org.apache.servicecomb.serviceregistry.consumer.AppManager) IdentityHashMap(java.util.IdentityHashMap) MicroserviceMeta(org.apache.servicecomb.core.definition.MicroserviceMeta) MicroserviceVersionMeta(org.apache.servicecomb.core.definition.MicroserviceVersionMeta) MicroserviceInstance(org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance) OperationMeta(org.apache.servicecomb.core.definition.OperationMeta) MicroserviceVersions(org.apache.servicecomb.serviceregistry.consumer.MicroserviceVersions) IdentityHashMap(java.util.IdentityHashMap) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

AppManager (org.apache.servicecomb.serviceregistry.consumer.AppManager)2 HashMap (java.util.HashMap)1 IdentityHashMap (java.util.IdentityHashMap)1 Map (java.util.Map)1 MicroserviceMeta (org.apache.servicecomb.core.definition.MicroserviceMeta)1 MicroserviceVersionMeta (org.apache.servicecomb.core.definition.MicroserviceVersionMeta)1 OperationMeta (org.apache.servicecomb.core.definition.OperationMeta)1 MicroserviceInstance (org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance)1 MicroserviceVersionFactory (org.apache.servicecomb.serviceregistry.consumer.MicroserviceVersionFactory)1 MicroserviceVersions (org.apache.servicecomb.serviceregistry.consumer.MicroserviceVersions)1