use of org.apache.servicecomb.serviceregistry.api.registry.Microservice in project incubator-servicecomb-java-chassis by apache.
the class TransportManager method init.
public void init() throws Exception {
buildTransportMap();
for (Transport transport : transportMap.values()) {
if (transport.init()) {
Endpoint endpoint = transport.getPublishEndpoint();
if (endpoint != null && endpoint.getEndpoint() != null) {
LOGGER.info("endpoint to publish: {}", endpoint.getEndpoint());
Microservice microservice = RegistryUtils.getMicroservice();
microservice.getInstance().getEndpoints().add(endpoint.getEndpoint());
}
continue;
}
}
}
use of org.apache.servicecomb.serviceregistry.api.registry.Microservice in project incubator-servicecomb-java-chassis by apache.
the class SchemaLoader method putSelfBasePathIfAbsent.
public void putSelfBasePathIfAbsent(String microserviceName, String basePath) {
if (basePath == null || basePath.length() == 0) {
return;
}
Microservice microservice = RegistryUtils.getMicroservice();
if (!microservice.getServiceName().equals(microserviceName)) {
return;
}
String urlPrefix = System.getProperty(Const.URL_PREFIX);
if (!StringUtils.isEmpty(urlPrefix) && !basePath.startsWith(urlPrefix)) {
basePath = urlPrefix + basePath;
}
List<BasePath> paths = microservice.getPaths();
for (BasePath path : paths) {
if (path.getPath().equals(basePath)) {
return;
}
}
BasePath basePathObj = new BasePath();
basePathObj.setPath(basePath);
paths.add(basePathObj);
}
use of org.apache.servicecomb.serviceregistry.api.registry.Microservice in project incubator-servicecomb-java-chassis by apache.
the class TestRestProducerInvocation method findRestOperationNameFromRegistry.
@Test
public void findRestOperationNameFromRegistry() {
Microservice microservice = new Microservice();
microservice.setServiceName("ms");
Exception e = new Exception("stop");
new Expectations(RegistryUtils.class) {
{
requestEx.getHeader(Const.TARGET_MICROSERVICE);
result = null;
RegistryUtils.getMicroservice();
result = microservice;
microserviceMetaManager.ensureFindValue("ms");
result = e;
}
};
restProducerInvocation = new RestProducerInvocation();
initRestProducerInvocation();
expectedException.expect(Exception.class);
expectedException.expectMessage("stop");
restProducerInvocation.findRestOperation();
}
use of org.apache.servicecomb.serviceregistry.api.registry.Microservice in project incubator-servicecomb-java-chassis by apache.
the class RestProducerProvider method init.
@Override
public void init() throws Exception {
for (ProducerMeta producerMeta : restProducers.getProducerMetaList()) {
Microservice microservice = RegistryUtils.getMicroservice();
producerSchemaFactory.getOrCreateProducerSchema(microservice.getServiceName(), producerMeta.getSchemaId(), producerMeta.getInstanceClass(), producerMeta.getInstance());
}
}
use of org.apache.servicecomb.serviceregistry.api.registry.Microservice in project incubator-servicecomb-java-chassis by apache.
the class TestCseDiscoveryClient method testCseDiscoveryClient.
@Test
public void testCseDiscoveryClient(@Mocked RegistryUtils registryUtils, @Injectable ServiceRegistryClient serviceRegistryClient, @Mocked DiscoveryTree discoveryTree, @Injectable DiscoveryTreeNode versionedCache) {
List<Microservice> microserviceList = new ArrayList<>();
Microservice service1 = new Microservice();
service1.setServiceName("service1");
microserviceList.add(service1);
Microservice server2 = new Microservice();
microserviceList.add(server2);
server2.setServiceName("server2");
Map<String, MicroserviceInstance> servers = new HashMap<>();
List<String> endpoints = new ArrayList<>();
endpoints.add("rest://localhost:3333");
endpoints.add("rest://localhost:4444");
MicroserviceInstance instance1 = new MicroserviceInstance();
instance1.setServiceId("service1");
instance1.setInstanceId("service1-instance1");
instance1.setEndpoints(endpoints);
servers.put("service1-instance1", instance1);
new Expectations() {
{
RegistryUtils.getServiceRegistryClient();
result = serviceRegistryClient;
serviceRegistryClient.getAllMicroservices();
result = microserviceList;
discoveryTree.discovery((DiscoveryContext) any, anyString, anyString, anyString);
result = versionedCache;
versionedCache.data();
result = servers;
}
};
DiscoveryClient client = new CseDiscoveryClient();
Assert.assertEquals("Spring Cloud CSE Discovery Client", client.description());
Assert.assertEquals(null, client.getLocalServiceInstance());
Assert.assertEquals(2, client.getServices().size());
Assert.assertEquals("server2", client.getServices().get(1));
Assert.assertEquals(2, client.getInstances("service1-instance1").size());
Assert.assertEquals(4444, client.getInstances("service1-instance1").get(1).getPort());
}
Aggregations