Search in sources :

Example 16 with Microservice

use of org.apache.servicecomb.serviceregistry.api.registry.Microservice in project incubator-servicecomb-java-chassis by apache.

the class Consumer method prepareEdge.

private URIEndpointObject prepareEdge() {
    Microservice microservice = RegistryUtils.getMicroservice();
    EndpointsCache endpointsCache = new EndpointsCache(microservice.getAppId(), "edge", "latest", "");
    Endpoint ep = endpointsCache.getLatestEndpoints().get(0);
    URIEndpointObject edgeAddress = (URIEndpointObject) ep.getAddress();
    edgePrefix = String.format("http://%s:%d/api/business", edgeAddress.getHostOrIp(), edgeAddress.getPort());
    return edgeAddress;
}
Also used : Microservice(org.apache.servicecomb.serviceregistry.api.registry.Microservice) Endpoint(org.apache.servicecomb.core.Endpoint) EndpointsCache(org.apache.servicecomb.core.endpoint.EndpointsCache) URIEndpointObject(org.apache.servicecomb.foundation.common.net.URIEndpointObject)

Example 17 with Microservice

use of org.apache.servicecomb.serviceregistry.api.registry.Microservice in project incubator-servicecomb-java-chassis by apache.

the class TestOperationInstancesDiscoveryFilter method regMicroservice.

private Microservice regMicroservice(String serviceId, String version, Class<?> schemaCls, int instanceCount) {
    String schemaId = "sid";
    Microservice microservice = new Microservice();
    microservice.setServiceId(serviceId);
    microservice.setAppId(appId);
    microservice.setServiceName(microserviceName);
    microservice.setVersion(version);
    microservice.setSchemas(Arrays.asList(schemaId));
    serviceRegistry.getServiceRegistryClient().registerMicroservice(microservice);
    SwaggerGenerator generator = new SwaggerGenerator(swaggerGeneratorContext, schemaCls);
    String schemaContent = SwaggerUtils.swaggerToString(generator.generate());
    serviceRegistry.getServiceRegistryClient().registerSchema(serviceId, schemaId, schemaContent);
    for (int idx = 0; idx < instanceCount; idx++) {
        MicroserviceInstance instance = createInstance(serviceId);
        serviceRegistry.getServiceRegistryClient().registerMicroserviceInstance(instance);
    }
    return microservice;
}
Also used : Microservice(org.apache.servicecomb.serviceregistry.api.registry.Microservice) SwaggerGenerator(org.apache.servicecomb.swagger.generator.core.SwaggerGenerator) MicroserviceInstance(org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance)

Example 18 with Microservice

use of org.apache.servicecomb.serviceregistry.api.registry.Microservice in project incubator-servicecomb-java-chassis by apache.

the class PojoProducerProvider method init.

@Override
public void init() throws Exception {
    for (PojoProducerMeta pojoProducerMeta : pojoProducers.getProducers()) {
        initPojoProducerMeta(pojoProducerMeta);
        Microservice microservice = RegistryUtils.getMicroservice();
        try {
            producerSchemaFactory.getOrCreateProducerSchema(microservice.getServiceName(), pojoProducerMeta.getSchemaId(), pojoProducerMeta.getInstanceClass(), pojoProducerMeta.getInstance());
        } catch (Throwable e) {
            throw new IllegalArgumentException("create producer schema failed, class=" + pojoProducerMeta.getInstanceClass().getName(), e);
        }
    }
}
Also used : Microservice(org.apache.servicecomb.serviceregistry.api.registry.Microservice) PojoProducerMeta(org.apache.servicecomb.provider.pojo.schema.PojoProducerMeta)

Example 19 with Microservice

use of org.apache.servicecomb.serviceregistry.api.registry.Microservice in project incubator-servicecomb-java-chassis by apache.

the class TestClientHttp method testServiceRegistryClientImpl.

@SuppressWarnings("unchecked")
@Test
public void testServiceRegistryClientImpl(@Mocked IpPortManager manager) {
    IpPort ipPort = new IpPort("127.0.0.1", 8853);
    new Expectations() {

        {
            manager.getAvailableAddress();
            result = ipPort;
        }
    };
    new MockUp<CountDownLatch>() {

        @Mock
        public void await() throws InterruptedException {
        }
    };
    new MockUp<RestUtils>() {

        @Mock
        void httpDo(RequestContext requestContext, Handler<RestResponse> responseHandler) {
        }
    };
    new MockUp<WebsocketUtils>() {

        @Mock
        void open(IpPort ipPort, String url, Handler<Void> onOpen, Handler<Void> onClose, Handler<Buffer> onMessage, Handler<Throwable> onException, Handler<Throwable> onConnectFailed) {
        }
    };
    MicroserviceFactory microserviceFactory = new MicroserviceFactory();
    Microservice microservice = microserviceFactory.create("app", "ms");
    ServiceRegistryClientImpl oClient = new ServiceRegistryClientImpl(manager);
    oClient.init();
    oClient.registerMicroservice(microservice);
    oClient.registerMicroserviceInstance(microservice.getInstance());
    Assert.assertEquals(null, oClient.getMicroservice(microservice.getServiceId()));
    Assert.assertEquals(null, oClient.getMicroserviceInstance("testConsumerID", "testproviderID"));
    Assert.assertEquals(null, oClient.findServiceInstance(microservice.getServiceId(), microservice.getAppId(), microservice.getServiceName(), microservice.getVersion()));
    Assert.assertEquals(null, oClient.findServiceInstances(microservice.getServiceId(), microservice.getAppId(), microservice.getServiceName(), microservice.getVersion(), "0"));
    Assert.assertEquals(null, oClient.getMicroserviceId(microservice.getAppId(), microservice.getServiceName(), microservice.getVersion()));
    Assert.assertEquals(null, oClient.heartbeat(microservice.getServiceId(), microservice.getInstance().getInstanceId()));
    oClient.watch("", Mockito.mock(AsyncResultCallback.class));
    Assert.assertEquals(false, oClient.unregisterMicroserviceInstance(microservice.getServiceId(), microservice.getInstance().getInstanceId()));
}
Also used : Expectations(mockit.Expectations) Microservice(org.apache.servicecomb.serviceregistry.api.registry.Microservice) Handler(io.vertx.core.Handler) IpPort(org.apache.servicecomb.foundation.common.net.IpPort) MockUp(mockit.MockUp) MicroserviceFactory(org.apache.servicecomb.serviceregistry.api.registry.MicroserviceFactory) AsyncResultCallback(org.apache.servicecomb.foundation.vertx.AsyncResultCallback) Test(org.junit.Test)

Example 20 with Microservice

use of org.apache.servicecomb.serviceregistry.api.registry.Microservice in project incubator-servicecomb-java-chassis by apache.

the class TestServiceRegistryClientImpl method testException.

@Test
public void testException() {
    MicroserviceFactory microserviceFactory = new MicroserviceFactory();
    Microservice microservice = microserviceFactory.create("app", "ms");
    Assert.assertEquals(null, oClient.registerMicroservice(microservice));
    Assert.assertEquals(null, oClient.registerMicroserviceInstance(microservice.getInstance()));
    oClient.init();
    Assert.assertEquals(null, oClient.getMicroserviceId(microservice.getAppId(), microservice.getServiceName(), microservice.getVersion()));
    Assert.assertThat(oClient.getAllMicroservices().isEmpty(), is(true));
    Assert.assertEquals(null, oClient.registerMicroservice(microservice));
    Assert.assertEquals(null, oClient.getMicroservice("microserviceId"));
    Assert.assertEquals(null, oClient.getMicroserviceInstance("consumerId", "providerId"));
    Assert.assertEquals(false, oClient.unregisterMicroserviceInstance("microserviceId", "microserviceInstanceId"));
    Assert.assertEquals(null, oClient.heartbeat("microserviceId", "microserviceInstanceId"));
    Assert.assertEquals(null, oClient.findServiceInstance("selfMicroserviceId", "appId", "serviceName", "versionRule"));
    Assert.assertEquals(null, oClient.findServiceInstances("selfMicroserviceId", "appId", "serviceName", "versionRule", "0"));
    Assert.assertEquals("a", new ClientException("a").getMessage());
}
Also used : Microservice(org.apache.servicecomb.serviceregistry.api.registry.Microservice) ClientException(org.apache.servicecomb.serviceregistry.client.ClientException) MicroserviceFactory(org.apache.servicecomb.serviceregistry.api.registry.MicroserviceFactory) 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