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