Search in sources :

Example 51 with MicroserviceInstances

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());
}
Also used : Microservice(org.apache.servicecomb.registry.api.registry.Microservice) HashMap(java.util.HashMap) MicroserviceInstances(org.apache.servicecomb.registry.api.registry.MicroserviceInstances) MicroserviceInstance(org.apache.servicecomb.registry.api.registry.MicroserviceInstance) Test(org.junit.Test)

Example 52 with MicroserviceInstances

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());
}
Also used : MicroserviceInstances(org.apache.servicecomb.registry.api.registry.MicroserviceInstances) MicroserviceInstance(org.apache.servicecomb.registry.api.registry.MicroserviceInstance)

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