use of org.apache.servicecomb.registry.api.registry.MicroserviceInstances in project incubator-servicecomb-java-chassis by apache.
the class LocalServiceRegistryClientImpl method findServiceInstances.
@Override
public MicroserviceInstances findServiceInstances(String selfMicroserviceId, String appId, String serviceName, String strVersionRule, String revision) {
int currentRevision = this.revision.get();
List<MicroserviceInstance> allInstances = new ArrayList<>();
MicroserviceInstances microserviceInstances = new MicroserviceInstances();
FindInstancesResponse response = new FindInstancesResponse();
if (revision != null && currentRevision == Integer.parseInt(revision)) {
microserviceInstances.setNeedRefresh(false);
return microserviceInstances;
}
microserviceInstances.setRevision(String.valueOf(currentRevision));
VersionRule versionRule = VersionRuleUtils.getOrCreate(strVersionRule);
Microservice latestMicroservice = findLatest(appId, serviceName, versionRule);
if (latestMicroservice == null) {
microserviceInstances.setMicroserviceNotExist(true);
return microserviceInstances;
}
Version latestVersion = VersionUtils.getOrCreate(latestMicroservice.getVersion());
for (Entry<String, Microservice> entry : microserviceIdMap.entrySet()) {
Microservice microservice = entry.getValue();
if (!isSameMicroservice(microservice, appId, serviceName)) {
continue;
}
Version version = VersionUtils.getOrCreate(entry.getValue().getVersion());
if (!versionRule.isMatch(version, latestVersion)) {
continue;
}
Map<String, MicroserviceInstance> instances = microserviceInstanceMap.get(entry.getValue().getServiceId());
allInstances.addAll(instances.values());
}
response.setInstances(allInstances);
microserviceInstances.setInstancesResponse(response);
return microserviceInstances;
}
use of org.apache.servicecomb.registry.api.registry.MicroserviceInstances in project incubator-servicecomb-java-chassis by apache.
the class LocalServiceRegistryClientImplTest method findServiceInstance_noInstances.
@Test
public void findServiceInstance_noInstances() {
List<MicroserviceInstance> result = registryClient.findServiceInstance("self", appId, microserviceName, DefinitionConst.VERSION_RULE_ALL);
Assert.assertThat(result, Matchers.nullValue());
MicroserviceInstances microserviceInstances = registryClient.findServiceInstances("self", appId, microserviceName, DefinitionConst.VERSION_RULE_ALL, null);
Assert.assertThat(microserviceInstances.isMicroserviceNotExist(), Matchers.is(true));
Assert.assertThat(microserviceInstances.getInstancesResponse(), Matchers.nullValue());
}
use of org.apache.servicecomb.registry.api.registry.MicroserviceInstances in project incubator-servicecomb-java-chassis by apache.
the class LocalServiceRegistryClientImplTest method findServiceInstance_twoSelectOne.
@Test
public void findServiceInstance_twoSelectOne() {
Microservice v1 = mockRegisterMicroservice(appId, microserviceName, "1.0.0");
mockRegisterMicroservice(appId, microserviceName, "2.0.0");
MicroserviceInstance instance = new MicroserviceInstance();
instance.setInstanceId("testid");
instance.setServiceId(v1.getServiceId());
registryClient.registerMicroserviceInstance(instance);
List<MicroserviceInstance> result = registryClient.findServiceInstance("self", appId, microserviceName, "1.0.0");
Assert.assertThat(result, Matchers.contains(instance));
MicroserviceInstances microserviceInstances = registryClient.findServiceInstances("self", appId, microserviceName, "1.0.0", "0");
List<MicroserviceInstance> results = microserviceInstances.getInstancesResponse().getInstances();
Assert.assertThat(results, Matchers.contains(instance));
}
use of org.apache.servicecomb.registry.api.registry.MicroserviceInstances in project incubator-servicecomb-java-chassis by apache.
the class RefreshableServiceRegistryCacheTest method setUp.
@Before
public void setUp() throws Exception {
serviceRegistryCache = new RefreshableServiceRegistryCache(consumerService, null) {
@Override
RefreshableMicroserviceCache createMicroserviceCache(MicroserviceCacheKey microserviceCacheKey) {
return new RefreshableMicroserviceCache(consumerService, microserviceCacheKey, null, false) {
@Override
MicroserviceInstances pullInstanceFromServiceCenter(String revisionId) {
return pullInstanceFromServiceCenterLogic.value.apply(revisionId);
}
};
}
};
consumerService = new Microservice();
consumerService.setServiceId("testConsumer");
}
use of org.apache.servicecomb.registry.api.registry.MicroserviceInstances in project incubator-servicecomb-java-chassis by apache.
the class TestMicroserviceInstances method setUp.
@Before
public void setUp() throws Exception {
microserviceInstances = new MicroserviceInstances();
findInstancesResponse = new FindInstancesResponse();
instances = new ArrayList<>();
instances.add(Mockito.mock(MicroserviceInstance.class));
}
Aggregations