use of org.apache.servicecomb.registry.api.registry.MicroserviceInstance in project java-chassis by ServiceComb.
the class RefreshableMicroserviceCache method pullInstance.
void pullInstance(String revisionId) {
MicroserviceInstances serviceInstances = pullInstanceFromServiceCenter(revisionId);
if (serviceInstances == null) {
LOGGER.error("Can not find any instances from service center due to previous errors. service={}/{}/{}", key.getAppId(), key.getServiceName(), key.getVersionRule());
setStatus(MicroserviceCacheStatus.CLIENT_ERROR);
return;
}
if (serviceInstances.isMicroserviceNotExist()) {
setStatus(MicroserviceCacheStatus.SERVICE_NOT_FOUND);
return;
}
if (!serviceInstances.isNeedRefresh()) {
LOGGER.debug("instances revision is not changed, service={}/{}/{}", key.getAppId(), key.getServiceName(), key.getVersionRule());
setStatus(MicroserviceCacheStatus.NO_CHANGE);
return;
}
List<MicroserviceInstance> instances = serviceInstances.getInstancesResponse().getInstances();
LOGGER.info("find instances[{}] from service center success. service={}/{}/{}, old revision={}, new revision={}", instances.size(), key.getAppId(), key.getServiceName(), key.getVersionRule(), this.revisionId, serviceInstances.getRevision());
for (MicroserviceInstance instance : instances) {
LOGGER.info("service id={}, instance id={}, endpoints={}", instance.getServiceId(), instance.getInstanceId(), instance.getEndpoints());
}
safeSetInstances(instances, serviceInstances.getRevision());
}
use of org.apache.servicecomb.registry.api.registry.MicroserviceInstance in project java-chassis by ServiceComb.
the class RefreshableMicroserviceCache method setInstances.
private void setInstances(List<MicroserviceInstance> pulledInstances, String rev) {
Set<MicroserviceInstance> mergedInstances = mergeInstances(pulledInstances);
LOGGER.debug("actually set instances[{}] for {}", mergedInstances.size(), key.plainKey());
for (MicroserviceInstance mergedInstance : mergedInstances) {
LOGGER.debug("serviceId={}, instanceId={}, endpoints={}", mergedInstance.getServiceId(), mergedInstance.getInstanceId(), mergedInstance.getEndpoints());
}
instances = Collections.unmodifiableList(new ArrayList<>(mergedInstances));
revisionId = rev;
}
use of org.apache.servicecomb.registry.api.registry.MicroserviceInstance in project java-chassis by ServiceComb.
the class RegistryUtilsTest method convertCacheToMicroserviceInstances.
@Test
public void convertCacheToMicroserviceInstances() {
MockedMicroserviceCache microserviceCache = new MockedMicroserviceCache();
microserviceCache.setStatus(MicroserviceCacheStatus.CLIENT_ERROR);
MicroserviceInstances microserviceInstances = RegistryUtils.convertCacheToMicroserviceInstances(microserviceCache);
Assert.assertNull(microserviceInstances);
microserviceCache = new MockedMicroserviceCache();
microserviceCache.setStatus(MicroserviceCacheStatus.SETTING_CACHE_ERROR);
microserviceInstances = RegistryUtils.convertCacheToMicroserviceInstances(microserviceCache);
Assert.assertNull(microserviceInstances);
microserviceCache = new MockedMicroserviceCache();
microserviceCache.setStatus(MicroserviceCacheStatus.INIT);
microserviceInstances = RegistryUtils.convertCacheToMicroserviceInstances(microserviceCache);
Assert.assertNull(microserviceInstances);
microserviceCache = new MockedMicroserviceCache();
microserviceCache.setStatus(MicroserviceCacheStatus.SERVICE_NOT_FOUND);
microserviceInstances = RegistryUtils.convertCacheToMicroserviceInstances(microserviceCache);
Assert.assertTrue(microserviceInstances.isMicroserviceNotExist());
Assert.assertFalse(microserviceInstances.isNeedRefresh());
Assert.assertEquals("", microserviceInstances.getRevision());
Assert.assertNull(microserviceInstances.getInstancesResponse());
microserviceCache = new MockedMicroserviceCache();
microserviceCache.setStatus(MicroserviceCacheStatus.REFRESHED);
microserviceCache.setRevisionId("0166f3c18702617d5e55cf911e4e412cc8760dab");
MicroserviceInstance microserviceInstance = new MicroserviceInstance();
microserviceCache.setInstances(Collections.singletonList(microserviceInstance));
microserviceInstances = RegistryUtils.convertCacheToMicroserviceInstances(microserviceCache);
Assert.assertFalse(microserviceInstances.isMicroserviceNotExist());
Assert.assertTrue(microserviceInstances.isNeedRefresh());
Assert.assertEquals("0166f3c18702617d5e55cf911e4e412cc8760dab", microserviceInstances.getRevision());
Assert.assertEquals(1, microserviceInstances.getInstancesResponse().getInstances().size());
Assert.assertSame(microserviceInstance, microserviceInstances.getInstancesResponse().getInstances().get(0));
microserviceCache = new MockedMicroserviceCache();
microserviceCache.setStatus(MicroserviceCacheStatus.NO_CHANGE);
microserviceCache.setRevisionId("0166f3c18702617d5e55cf911e4e412cc8760dab");
microserviceInstances = RegistryUtils.convertCacheToMicroserviceInstances(microserviceCache);
Assert.assertFalse(microserviceInstances.isMicroserviceNotExist());
Assert.assertFalse(microserviceInstances.isNeedRefresh());
Assert.assertEquals("0166f3c18702617d5e55cf911e4e412cc8760dab", microserviceInstances.getRevision());
Assert.assertNull(microserviceInstances.getInstancesResponse());
}
use of org.apache.servicecomb.registry.api.registry.MicroserviceInstance in project java-chassis by ServiceComb.
the class TestConsumers method registryMicroserviceMapping.
@Test
public void registryMicroserviceMapping() {
MicroserviceInstance microserviceInstance = new MicroserviceInstance();
RegistrationManager.INSTANCE.registerMicroserviceMapping("3rd", "1.0.0", Arrays.asList(microserviceInstance), Hello.class);
MicroserviceVersionRule microserviceVersionRule = appManager.getOrCreateMicroserviceVersionRule(appId, "3rd", "0+");
Assert.assertThat(microserviceVersionRule.getInstances().values(), Matchers.contains(microserviceInstance));
}
use of org.apache.servicecomb.registry.api.registry.MicroserviceInstance 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;
}
Aggregations