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());
}
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));
}
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"));
}
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);
}
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());
}
Aggregations