Search in sources :

Example 41 with Microservice

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;
        }
    }
}
Also used : Microservice(org.apache.servicecomb.serviceregistry.api.registry.Microservice) Endpoint(org.apache.servicecomb.core.Endpoint) Transport(org.apache.servicecomb.core.Transport)

Example 42 with Microservice

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);
}
Also used : Microservice(org.apache.servicecomb.serviceregistry.api.registry.Microservice) BasePath(org.apache.servicecomb.serviceregistry.api.registry.BasePath)

Example 43 with Microservice

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();
}
Also used : Expectations(mockit.Expectations) Microservice(org.apache.servicecomb.serviceregistry.api.registry.Microservice) InvocationException(org.apache.servicecomb.swagger.invocation.exception.InvocationException) ExpectedException(org.junit.rules.ExpectedException) Test(org.junit.Test)

Example 44 with Microservice

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());
    }
}
Also used : ProducerMeta(org.apache.servicecomb.core.provider.producer.ProducerMeta) Microservice(org.apache.servicecomb.serviceregistry.api.registry.Microservice)

Example 45 with Microservice

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());
}
Also used : Expectations(mockit.Expectations) Microservice(org.apache.servicecomb.serviceregistry.api.registry.Microservice) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) MicroserviceInstance(org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance) DiscoveryClient(org.springframework.cloud.client.discovery.DiscoveryClient) Test(org.junit.Test)

Aggregations

Microservice (org.apache.servicecomb.serviceregistry.api.registry.Microservice)47 Test (org.junit.Test)24 MicroserviceInstance (org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance)15 Expectations (mockit.Expectations)11 HashMap (java.util.HashMap)6 ArrayList (java.util.ArrayList)5 EventBus (com.google.common.eventbus.EventBus)4 Before (org.junit.Before)4 Subscribe (com.google.common.eventbus.Subscribe)3 MockUp (mockit.MockUp)3 ServiceRegistry (org.apache.servicecomb.serviceregistry.ServiceRegistry)3 MicroserviceFactory (org.apache.servicecomb.serviceregistry.api.registry.MicroserviceFactory)3 MicroserviceInstances (org.apache.servicecomb.serviceregistry.client.http.MicroserviceInstances)3 Endpoint (org.apache.servicecomb.core.Endpoint)2 SchemaMeta (org.apache.servicecomb.core.definition.SchemaMeta)2 ClientException (org.apache.servicecomb.serviceregistry.client.ClientException)2 Version (org.apache.servicecomb.serviceregistry.version.Version)2 VersionRule (org.apache.servicecomb.serviceregistry.version.VersionRule)2 Handler (io.vertx.core.Handler)1 HttpClientOptions (io.vertx.core.http.HttpClientOptions)1