Search in sources :

Example 1 with MicroserviceVersions

use of org.apache.servicecomb.serviceregistry.consumer.MicroserviceVersions 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)

Example 2 with MicroserviceVersions

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

the class TestOperationInstancesDiscoveryFilter method discovery_v1_0_0.

@Test
public void discovery_v1_0_0() {
    regMicroservice("1", "1.0.0", V1_0_0.class, 2);
    MicroserviceVersions MicroserviceVersions = serviceRegistry.getAppManager().getOrCreateMicroserviceVersions(appId, microserviceName);
    MicroserviceVersions.submitPull();
    MicroserviceVersionRule microserviceVersionRule = MicroserviceVersions.getOrCreateMicroserviceVersionRule(DefinitionConst.VERSION_RULE_ALL);
    MicroserviceVersionMeta latestMicroserviceVersionMeta = microserviceVersionRule.getLatestMicroserviceVersion();
    latestOperationMeta = latestMicroserviceVersionMeta.getMicroserviceMeta().ensureFindOperation("sid.add");
    DiscoveryTreeNode parent = new DiscoveryTreeNode().fromCache(microserviceVersionRule.getVersionedCache());
    setupOnChange();
    result = filter.discovery(context, parent);
    Assert.assertEquals(2, result.mapData().size());
    result.mapData().values().forEach(instance -> {
        Assert.assertEquals("1", ((MicroserviceInstance) instance).getServiceId());
    });
}
Also used : MicroserviceVersionRule(org.apache.servicecomb.serviceregistry.consumer.MicroserviceVersionRule) MicroserviceVersionMeta(org.apache.servicecomb.core.definition.MicroserviceVersionMeta) DiscoveryTreeNode(org.apache.servicecomb.serviceregistry.discovery.DiscoveryTreeNode) MicroserviceVersions(org.apache.servicecomb.serviceregistry.consumer.MicroserviceVersions) Test(org.junit.Test)

Example 3 with MicroserviceVersions

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

the class TestOperationInstancesDiscoveryFilter method discovery_v1_1_0_dec.

@Test
public void discovery_v1_1_0_dec() {
    regMicroservice("1", "1.0.0", V1_0_0.class, 2);
    regMicroservice("2", "1.1.0", V1_1_0.class, 2);
    MicroserviceVersions MicroserviceVersions = serviceRegistry.getAppManager().getOrCreateMicroserviceVersions(appId, microserviceName);
    MicroserviceVersions.submitPull();
    MicroserviceVersionRule microserviceVersionRule = MicroserviceVersions.getOrCreateMicroserviceVersionRule(DefinitionConst.VERSION_RULE_ALL);
    MicroserviceVersionMeta latestMicroserviceVersionMeta = microserviceVersionRule.getLatestMicroserviceVersion();
    latestOperationMeta = latestMicroserviceVersionMeta.getMicroserviceMeta().ensureFindOperation("sid.dec");
    DiscoveryTreeNode parent = new DiscoveryTreeNode().fromCache(microserviceVersionRule.getVersionedCache());
    setupOnChange();
    result = filter.discovery(context, parent);
    Assert.assertEquals(2, result.mapData().size());
    Set<String> ids = new HashSet<>();
    result.mapData().values().forEach(instance -> {
        ids.add(((MicroserviceInstance) instance).getServiceId());
    });
    Assert.assertThat(ids, Matchers.containsInAnyOrder("2"));
}
Also used : MicroserviceVersionRule(org.apache.servicecomb.serviceregistry.consumer.MicroserviceVersionRule) MicroserviceVersionMeta(org.apache.servicecomb.core.definition.MicroserviceVersionMeta) DiscoveryTreeNode(org.apache.servicecomb.serviceregistry.discovery.DiscoveryTreeNode) MicroserviceVersions(org.apache.servicecomb.serviceregistry.consumer.MicroserviceVersions) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 4 with MicroserviceVersions

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

the class TestOperationInstancesDiscoveryFilter method discovery_v1_1_0_add.

@Test
public void discovery_v1_1_0_add() {
    regMicroservice("1", "1.0.0", V1_0_0.class, 2);
    regMicroservice("2", "1.1.0", V1_1_0.class, 2);
    MicroserviceVersions MicroserviceVersions = serviceRegistry.getAppManager().getOrCreateMicroserviceVersions(appId, microserviceName);
    MicroserviceVersions.submitPull();
    MicroserviceVersionRule microserviceVersionRule = MicroserviceVersions.getOrCreateMicroserviceVersionRule(DefinitionConst.VERSION_RULE_ALL);
    MicroserviceVersionMeta latestMicroserviceVersionMeta = microserviceVersionRule.getLatestMicroserviceVersion();
    latestOperationMeta = latestMicroserviceVersionMeta.getMicroserviceMeta().ensureFindOperation("sid.add");
    DiscoveryTreeNode parent = new DiscoveryTreeNode().fromCache(microserviceVersionRule.getVersionedCache());
    setupOnChange();
    result = filter.discovery(context, parent);
    Assert.assertEquals(4, result.mapData().size());
    Set<String> ids = new HashSet<>();
    result.mapData().values().forEach(instance -> {
        ids.add(((MicroserviceInstance) instance).getServiceId());
    });
    Assert.assertThat(ids, Matchers.containsInAnyOrder("1", "2"));
}
Also used : MicroserviceVersionRule(org.apache.servicecomb.serviceregistry.consumer.MicroserviceVersionRule) MicroserviceVersionMeta(org.apache.servicecomb.core.definition.MicroserviceVersionMeta) DiscoveryTreeNode(org.apache.servicecomb.serviceregistry.discovery.DiscoveryTreeNode) MicroserviceVersions(org.apache.servicecomb.serviceregistry.consumer.MicroserviceVersions) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

MicroserviceVersionMeta (org.apache.servicecomb.core.definition.MicroserviceVersionMeta)4 MicroserviceVersions (org.apache.servicecomb.serviceregistry.consumer.MicroserviceVersions)4 MicroserviceVersionRule (org.apache.servicecomb.serviceregistry.consumer.MicroserviceVersionRule)3 DiscoveryTreeNode (org.apache.servicecomb.serviceregistry.discovery.DiscoveryTreeNode)3 Test (org.junit.Test)3 HashSet (java.util.HashSet)2 HashMap (java.util.HashMap)1 IdentityHashMap (java.util.IdentityHashMap)1 Map (java.util.Map)1 MicroserviceMeta (org.apache.servicecomb.core.definition.MicroserviceMeta)1 OperationMeta (org.apache.servicecomb.core.definition.OperationMeta)1 MicroserviceInstance (org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance)1 AppManager (org.apache.servicecomb.serviceregistry.consumer.AppManager)1