Search in sources :

Example 1 with MicroserviceVersionRule

use of org.apache.servicecomb.registry.consumer.MicroserviceVersionRule in project java-chassis by ServiceComb.

the class TestConsumers method getOrCreateMicroserviceVersionRule.

@Test
public void getOrCreateMicroserviceVersionRule() {
    MicroserviceVersionRule microserviceVersionRule = appManager.getOrCreateMicroserviceVersionRule(appId, serviceName, versionRule);
    Assert.assertEquals("0.0.0.0+", microserviceVersionRule.getVersionRule().getVersionRule());
    Assert.assertEquals(1, microserviceManager.getVersionsByName().size());
    MicroserviceVersion microserviceVersion = microserviceVersionRule.getLatestMicroserviceVersion();
    Assert.assertEquals(serviceName, microserviceVersion.getMicroserviceName());
    Assert.assertEquals(serviceId, microserviceVersion.getMicroserviceId());
    Assert.assertEquals(version, microserviceVersion.getVersion().getVersion());
}
Also used : MicroserviceVersionRule(org.apache.servicecomb.registry.consumer.MicroserviceVersionRule) MicroserviceVersion(org.apache.servicecomb.registry.consumer.MicroserviceVersion) Test(org.junit.Test)

Example 2 with MicroserviceVersionRule

use of org.apache.servicecomb.registry.consumer.MicroserviceVersionRule in project java-chassis by ServiceComb.

the class TestConsumers method registryMicroserviceMapping.

@Test
public void registryMicroserviceMapping() {
    MicroserviceInstance microserviceInstance = new MicroserviceInstance();
    RegistrationManager.INSTANCE.registerMicroserviceMapping("3rd", "1.0.0", Arrays.asList(microserviceInstance), Hello.class);
    MicroserviceVersionRule microserviceVersionRule = appManager.getOrCreateMicroserviceVersionRule(appId, "3rd", "0+");
    Assert.assertThat(microserviceVersionRule.getInstances().values(), Matchers.contains(microserviceInstance));
}
Also used : MicroserviceVersionRule(org.apache.servicecomb.registry.consumer.MicroserviceVersionRule) MicroserviceInstance(org.apache.servicecomb.registry.api.registry.MicroserviceInstance) Test(org.junit.Test)

Example 3 with MicroserviceVersionRule

use of org.apache.servicecomb.registry.consumer.MicroserviceVersionRule in project java-chassis by ServiceComb.

the class TestConsumers method registryMicroserviceMappingByEndpoints.

@Test
public void registryMicroserviceMappingByEndpoints() {
    RegistrationManager.INSTANCE.registerMicroserviceMappingByEndpoints("3rd", "1.0.0", Arrays.asList("cse://127.0.0.1:8080", "cse://127.0.0.1:8081"), Hello.class);
    MicroserviceVersionRule microserviceVersionRule = appManager.getOrCreateMicroserviceVersionRule(appId, "3rd", "0+");
    Assert.assertEquals(2, microserviceVersionRule.getInstances().size());
    Assert.assertThat(microserviceVersionRule.getInstances().values().stream().flatMap(inst -> inst.getEndpoints().stream()).toArray(), Matchers.arrayContainingInAnyOrder("cse://127.0.0.1:8080", "cse://127.0.0.1:8081"));
}
Also used : MicroserviceVersionRule(org.apache.servicecomb.registry.consumer.MicroserviceVersionRule) Test(org.junit.Test)

Example 4 with MicroserviceVersionRule

use of org.apache.servicecomb.registry.consumer.MicroserviceVersionRule in project java-chassis by ServiceComb.

the class MicroserviceDeploy method ensureReady.

public void ensureReady() throws Throwable {
    MicroserviceVersionRule microserviceVersionRule = DiscoveryManager.INSTANCE.getAppManager().getOrCreateMicroserviceVersionRule(microserviceDeployDefinition.getAppId(), microserviceDeployDefinition.getMicroserviceName(), microserviceDeployDefinition.getVersion());
    if (microserviceVersionRule.getInstances().size() > 0) {
        LOGGER.info("{} already ready.", microserviceDeployDefinition.getDisplayName());
        return;
    }
    deploy();
    waitStartComplete();
    ITUtils.waitMicroserviceReady(microserviceDeployDefinition.getAppId(), microserviceDeployDefinition.getMicroserviceName(), microserviceDeployDefinition.getVersion(), 1);
}
Also used : MicroserviceVersionRule(org.apache.servicecomb.registry.consumer.MicroserviceVersionRule)

Example 5 with MicroserviceVersionRule

use of org.apache.servicecomb.registry.consumer.MicroserviceVersionRule in project java-chassis by ServiceComb.

the class GateRestTemplate method getUrlPrefix.

private String getUrlPrefix(String gateName, String producerName, String schemaId) {
    MicroserviceVersionRule microserviceVersionRule = DiscoveryManager.INSTANCE.getAppManager().getOrCreateMicroserviceVersionRule(RegistrationManager.INSTANCE.getMicroservice().getAppId(), gateName, DefinitionConst.VERSION_RULE_ALL);
    MicroserviceInstance microserviceInstance = microserviceVersionRule.getInstances().values().stream().findFirst().get();
    URIEndpointObject edgeAddress = new URIEndpointObject(microserviceInstance.getEndpoints().get(0));
    String urlSchema = "http";
    if (edgeAddress.isSslEnabled()) {
        urlSchema = "https";
    }
    MicroserviceReferenceConfig microserviceReferenceConfig = SCBEngine.getInstance().createMicroserviceReferenceConfig(producerName);
    MicroserviceMeta microserviceMeta = microserviceReferenceConfig.getLatestMicroserviceMeta();
    SchemaMeta schemaMeta = microserviceMeta.ensureFindSchemaMeta(schemaId);
    return String.format("%s://%s:%d/rest/%s%s", urlSchema, edgeAddress.getHostOrIp(), edgeAddress.getPort(), producerName, schemaMeta.getSwagger().getBasePath());
}
Also used : MicroserviceVersionRule(org.apache.servicecomb.registry.consumer.MicroserviceVersionRule) MicroserviceReferenceConfig(org.apache.servicecomb.core.provider.consumer.MicroserviceReferenceConfig) SchemaMeta(org.apache.servicecomb.core.definition.SchemaMeta) MicroserviceMeta(org.apache.servicecomb.core.definition.MicroserviceMeta) MicroserviceInstance(org.apache.servicecomb.registry.api.registry.MicroserviceInstance) URIEndpointObject(org.apache.servicecomb.foundation.common.net.URIEndpointObject)

Aggregations

MicroserviceVersionRule (org.apache.servicecomb.registry.consumer.MicroserviceVersionRule)10 Test (org.junit.Test)7 MicroserviceInstance (org.apache.servicecomb.registry.api.registry.MicroserviceInstance)3 MicroserviceMeta (org.apache.servicecomb.core.definition.MicroserviceMeta)1 SchemaMeta (org.apache.servicecomb.core.definition.SchemaMeta)1 MicroserviceReferenceConfig (org.apache.servicecomb.core.provider.consumer.MicroserviceReferenceConfig)1 URIEndpointObject (org.apache.servicecomb.foundation.common.net.URIEndpointObject)1 MicroserviceKey (org.apache.servicecomb.registry.api.MicroserviceKey)1 MicroserviceInstanceChangedEvent (org.apache.servicecomb.registry.api.event.MicroserviceInstanceChangedEvent)1 MicroserviceVersion (org.apache.servicecomb.registry.consumer.MicroserviceVersion)1 MicroserviceVersions (org.apache.servicecomb.registry.consumer.MicroserviceVersions)1