Search in sources :

Example 6 with MicroserviceInstances

use of org.apache.servicecomb.registry.api.registry.MicroserviceInstances in project java-chassis by ServiceComb.

the class LocalRegistryStore method findServiceInstances.

// local registry do not care about version and revision
public MicroserviceInstances findServiceInstances(String appId, String serviceName, String versionRule, String revision) {
    MicroserviceInstances microserviceInstances = new MicroserviceInstances();
    FindInstancesResponse findInstancesResponse = new FindInstancesResponse();
    List<MicroserviceInstance> instances = new ArrayList<>();
    Collectors.toList();
    microserviceInstanceMap.values().forEach(allInstances -> allInstances.values().stream().filter(aInstance -> {
        Microservice service = microserviceMap.get(aInstance.getServiceId());
        return service.getAppId().equals(appId) && service.getServiceName().equals(serviceName);
    }).forEach(item -> instances.add(item)));
    if (instances.isEmpty()) {
        microserviceInstances.setMicroserviceNotExist(true);
    } else {
        findInstancesResponse.setInstances(instances);
        microserviceInstances.setMicroserviceNotExist(false);
        microserviceInstances.setInstancesResponse(findInstancesResponse);
    }
    return microserviceInstances;
}
Also used : BeanUtils(org.apache.servicecomb.foundation.common.utils.BeanUtils) MicroserviceFactory(org.apache.servicecomb.registry.api.registry.MicroserviceFactory) MicroserviceInstance(org.apache.servicecomb.registry.api.registry.MicroserviceInstance) Enumeration(java.util.Enumeration) URL(java.net.URL) SwaggerGenerator(org.apache.servicecomb.swagger.generator.SwaggerGenerator) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) IOException(java.io.IOException) HashMap(java.util.HashMap) SwaggerUtils(org.apache.servicecomb.swagger.SwaggerUtils) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) JvmUtils(org.apache.servicecomb.foundation.common.utils.JvmUtils) Instance(org.apache.servicecomb.localregistry.RegistryBean.Instance) ArrayList(java.util.ArrayList) YAMLUtil(org.apache.servicecomb.config.YAMLUtil) MicroserviceInstances(org.apache.servicecomb.registry.api.registry.MicroserviceInstances) List(java.util.List) Map(java.util.Map) Entry(java.util.Map.Entry) Microservice(org.apache.servicecomb.registry.api.registry.Microservice) VisibleForTesting(com.google.common.annotations.VisibleForTesting) FindInstancesResponse(org.apache.servicecomb.registry.api.registry.FindInstancesResponse) InputStream(java.io.InputStream) Microservice(org.apache.servicecomb.registry.api.registry.Microservice) MicroserviceInstances(org.apache.servicecomb.registry.api.registry.MicroserviceInstances) ArrayList(java.util.ArrayList) MicroserviceInstance(org.apache.servicecomb.registry.api.registry.MicroserviceInstance) FindInstancesResponse(org.apache.servicecomb.registry.api.registry.FindInstancesResponse)

Example 7 with MicroserviceInstances

use of org.apache.servicecomb.registry.api.registry.MicroserviceInstances in project java-chassis by ServiceComb.

the class SchemaDiscovery method findServiceInstances.

@Override
public MicroserviceInstances findServiceInstances(String appId, String serviceName, String versionRule, String revision) {
    MicroserviceInstances microserviceInstances = new MicroserviceInstances();
    microserviceInstances.setMicroserviceNotExist(true);
    return microserviceInstances;
}
Also used : MicroserviceInstances(org.apache.servicecomb.registry.api.registry.MicroserviceInstances)

Example 8 with MicroserviceInstances

use of org.apache.servicecomb.registry.api.registry.MicroserviceInstances in project java-chassis by ServiceComb.

the class MicroserviceStore method findServiceInstances.

public MicroserviceInstances findServiceInstances(String revision) {
    if (instancesRevision.equals(revision)) {
        return new MicroserviceInstances().setRevision(instancesRevision).setNeedRefresh(false);
    }
    List<MicroserviceInstance> instances = instancesById.values().stream().map(InstanceStore::getInstance).collect(Collectors.toList());
    FindInstancesResponse response = new FindInstancesResponse().setInstances(instances);
    return new MicroserviceInstances().setRevision(instancesRevision).setInstancesResponse(response);
}
Also used : MicroserviceInstances(org.apache.servicecomb.registry.api.registry.MicroserviceInstances) MicroserviceInstance(org.apache.servicecomb.registry.api.registry.MicroserviceInstance) FindInstancesResponse(org.apache.servicecomb.registry.api.registry.FindInstancesResponse)

Example 9 with MicroserviceInstances

use of org.apache.servicecomb.registry.api.registry.MicroserviceInstances in project java-chassis by ServiceComb.

the class DiscoveryManager method findServiceInstances.

public MicroserviceInstances findServiceInstances(String appId, String serviceName, String versionRule, String revision) {
    MicroserviceInstances result = new MicroserviceInstances();
    // default values not suitable for aggregate, reset.
    result.setNeedRefresh(false);
    result.setMicroserviceNotExist(true);
    discoveryList.forEach(discovery -> {
        MicroserviceInstances instances = discovery.findServiceInstances(appId, serviceName, versionRule, revision);
        result.mergeMicroserviceInstances(instances);
    });
    return result;
}
Also used : MicroserviceInstances(org.apache.servicecomb.registry.api.registry.MicroserviceInstances)

Example 10 with MicroserviceInstances

use of org.apache.servicecomb.registry.api.registry.MicroserviceInstances in project java-chassis by ServiceComb.

the class TestServiceRegistryClientImpl method findServiceInstances_microserviceNotExist.

@Test
public void findServiceInstances_microserviceNotExist() {
    HttpClientResponse response = new MockUp<HttpClientResponse>() {

        @Mock
        int statusCode() {
            return 400;
        }

        @Mock
        HttpClientResponse bodyHandler(Handler<Buffer> bodyHandler) {
            Buffer bodyBuffer = Buffer.buffer("{\"errorCode\":\"400012\"}");
            bodyHandler.handle(bodyBuffer);
            return null;
        }
    }.getMockInstance();
    RestResponse restResponse = new RestResponse(null, response);
    new MockUp<RestClientUtil>() {

        @Mock
        void httpDo(RequestContext requestContext, Handler<RestResponse> responseHandler) {
            Assert.assertEquals("appId=appId&global=true&serviceName=serviceName&version=0.0.0.0%2B", requestContext.getParams().getQueryParams());
            restResponse.setRequestContext(requestContext);
            responseHandler.handle(restResponse);
        }
    };
    MicroserviceInstances microserviceInstances = oClient.findServiceInstances("consumerId", "appId", "serviceName", DefinitionConst.VERSION_RULE_ALL, null);
    Assert.assertTrue(microserviceInstances.isMicroserviceNotExist());
    Assert.assertFalse(microserviceInstances.isNeedRefresh());
}
Also used : Buffer(io.vertx.core.buffer.Buffer) HttpClientResponse(io.vertx.core.http.HttpClientResponse) MicroserviceInstances(org.apache.servicecomb.registry.api.registry.MicroserviceInstances) Handler(io.vertx.core.Handler) MockUp(mockit.MockUp) Mock(mockit.Mock) Test(org.junit.Test)

Aggregations

MicroserviceInstances (org.apache.servicecomb.registry.api.registry.MicroserviceInstances)52 MicroserviceInstance (org.apache.servicecomb.registry.api.registry.MicroserviceInstance)34 Test (org.junit.Test)22 FindInstancesResponse (org.apache.servicecomb.registry.api.registry.FindInstancesResponse)18 Microservice (org.apache.servicecomb.registry.api.registry.Microservice)12 ArrayList (java.util.ArrayList)8 MockUp (mockit.MockUp)8 Before (org.junit.Before)6 IOException (java.io.IOException)4 HashMap (java.util.HashMap)4 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 Handler (io.vertx.core.Handler)2 Buffer (io.vertx.core.buffer.Buffer)2 HttpClientResponse (io.vertx.core.http.HttpClientResponse)2 InputStream (java.io.InputStream)2 URL (java.net.URL)2 Enumeration (java.util.Enumeration)2 List (java.util.List)2 Map (java.util.Map)2 Entry (java.util.Map.Entry)2