use of org.apache.servicecomb.registry.api.registry.MicroserviceInstances in project incubator-servicecomb-java-chassis by apache.
the class TestRegistry method testDelegate.
@SuppressWarnings("deprecation")
@Test
public void testDelegate() {
ServiceRegistry serviceRegistry = LocalServiceRegistryFactory.createLocal();
serviceRegistry.init();
RegistryUtils.init();
serviceRegistry.run();
RegistryUtils.setServiceRegistry(serviceRegistry);
Assert.assertEquals(serviceRegistry, RegistryUtils.getServiceRegistry());
Assert.assertEquals(serviceRegistry.getServiceRegistryClient(), RegistryUtils.getServiceRegistryClient());
Microservice microservice = RegistryUtils.getMicroservice();
Assert.assertEquals(serviceRegistry.getMicroservice(), microservice);
Assert.assertEquals(serviceRegistry.getMicroserviceInstance(), RegistryUtils.getMicroserviceInstance());
List<MicroserviceInstance> instanceList = RegistryUtils.findServiceInstance("default", "default", "0.0.1");
Assert.assertEquals(1, instanceList.size());
Assert.assertEquals(RegistryUtils.getMicroservice().getServiceId(), instanceList.get(0).getServiceId());
instanceList = RegistryUtils.findServiceInstance("default", "notExists", "0.0.1");
Assert.assertNull(instanceList);
MicroserviceInstances microserviceInstances = RegistryUtils.findServiceInstances("default", "default", "0.0.1");
List<MicroserviceInstance> instanceLists = microserviceInstances.getInstancesResponse().getInstances();
Assert.assertEquals(1, instanceLists.size());
Assert.assertEquals(RegistryUtils.getMicroservice().getServiceId(), instanceLists.get(0).getServiceId());
Map<String, String> properties = new HashMap<>();
properties.put("k", "v");
RegistryUtils.updateInstanceProperties(properties);
Assert.assertEquals(properties, RegistryUtils.getMicroserviceInstance().getProperties());
Assert.assertEquals(microservice, RegistryUtils.getMicroservice(microservice.getServiceId()));
RegistryUtils.updateMicroserviceProperties(properties);
Assert.assertEquals(properties, RegistryUtils.getMicroservice().getProperties());
Assert.assertEquals("default", RegistryUtils.getAppId());
}
use of org.apache.servicecomb.registry.api.registry.MicroserviceInstances in project incubator-servicecomb-java-chassis by apache.
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());
}
Aggregations