Search in sources :

Example 21 with MicroserviceInstance

use of org.apache.servicecomb.registry.api.registry.MicroserviceInstance in project java-chassis by ServiceComb.

the class LocalRegistryStore method addInstances.

private void addInstances(RegistryBean bean, Microservice microservice) {
    Map<String, MicroserviceInstance> instanceMap = new ConcurrentHashMap<>();
    microserviceInstanceMap.put(microservice.getServiceId(), instanceMap);
    for (Instance item : bean.getInstances().getInstances()) {
        MicroserviceInstance instance = new MicroserviceInstance();
        instance.setInstanceId(UUID.randomUUID().toString());
        instance.setEndpoints(item.getEndpoints());
        instance.setServiceId(microservice.getServiceId());
        instanceMap.put(instance.getInstanceId(), instance);
    }
}
Also used : MicroserviceInstance(org.apache.servicecomb.registry.api.registry.MicroserviceInstance) Instance(org.apache.servicecomb.localregistry.RegistryBean.Instance) MicroserviceInstance(org.apache.servicecomb.registry.api.registry.MicroserviceInstance) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 22 with MicroserviceInstance

use of org.apache.servicecomb.registry.api.registry.MicroserviceInstance in project java-chassis by ServiceComb.

the class ServiceCenterRegistration method updateMicroserviceInstanceStatus.

@Override
public boolean updateMicroserviceInstanceStatus(MicroserviceInstanceStatus status) {
    RegistryUtils.executeOnEachServiceRegistry(sr -> new SuppressedRunnableWrapper(() -> {
        MicroserviceInstance selfInstance = sr.getMicroserviceInstance();
        sr.getServiceRegistryClient().updateMicroserviceInstanceStatus(selfInstance.getServiceId(), selfInstance.getInstanceId(), status);
    }).run());
    return true;
}
Also used : SuppressedRunnableWrapper(org.apache.servicecomb.foundation.common.concurrency.SuppressedRunnableWrapper) MicroserviceInstance(org.apache.servicecomb.registry.api.registry.MicroserviceInstance)

Example 23 with MicroserviceInstance

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

Example 24 with MicroserviceInstance

use of org.apache.servicecomb.registry.api.registry.MicroserviceInstance in project java-chassis by ServiceComb.

the class TestMicroserviceInstanceRegisterTask method setup.

@Before
public void setup() {
    ConfigUtil.installDynamicConfig();
    eventBus = new EventBus();
    taskList = new ArrayList<>();
    eventBus.register(new Object() {

        @Subscribe
        public void onEvent(MicroserviceInstanceRegisterTask task) {
            taskList.add(task);
        }
    });
    microservice = new Microservice();
    microservice.setAppId("app");
    microservice.setServiceName("ms");
    microservice.setServiceId("serviceId");
    microservice.setInstance(new MicroserviceInstance());
    HealthCheck healthCheck = new HealthCheck();
    healthCheck.setMode(HealthCheckMode.HEARTBEAT);
    microservice.getInstance().setHealthCheck(healthCheck);
}
Also used : Microservice(org.apache.servicecomb.registry.api.registry.Microservice) HealthCheck(org.apache.servicecomb.registry.api.registry.HealthCheck) MicroserviceInstance(org.apache.servicecomb.registry.api.registry.MicroserviceInstance) EventBus(com.google.common.eventbus.EventBus) Subscribe(com.google.common.eventbus.Subscribe) Before(org.junit.Before)

Example 25 with MicroserviceInstance

use of org.apache.servicecomb.registry.api.registry.MicroserviceInstance in project java-chassis by ServiceComb.

the class TestMicroserviceInstanceRegisterTask method registerHostSuccess.

@Test
public void registerHostSuccess() {
    MicroserviceInstance instance = microservice.getInstance();
    new Expectations(RegistrationManager.class) {

        {
            RegistrationManager.getPublishHostName();
            result = "hostName";
        }
    };
    new Expectations(RegistryUtils.class) {

        {
            serviceRegistryConfig.isPreferIpAddress();
            result = false;
            serviceRegistryConfig.getHeartbeatInterval();
            result = 10;
            serviceRegistryConfig.getResendHeartBeatTimes();
            result = 20;
            srClient.registerMicroserviceInstance(instance);
            result = "instanceId";
        }
    };
    MicroserviceInstanceRegisterTask registerTask = new MicroserviceInstanceRegisterTask(eventBus, serviceRegistryConfig, srClient, microservice);
    registerTask.taskStatus = TaskStatus.READY;
    registerTask.run();
    Assert.assertEquals(true, registerTask.isRegistered());
    Assert.assertEquals("hostName", instance.getHostName());
    Assert.assertEquals("instanceId", instance.getInstanceId());
    Assert.assertEquals(10, instance.getHealthCheck().getInterval());
    Assert.assertEquals(20, instance.getHealthCheck().getTimes());
    Assert.assertEquals(1, taskList.size());
}
Also used : Expectations(mockit.Expectations) MicroserviceInstance(org.apache.servicecomb.registry.api.registry.MicroserviceInstance) Test(org.junit.Test)

Aggregations

MicroserviceInstance (org.apache.servicecomb.registry.api.registry.MicroserviceInstance)232 Test (org.junit.Test)136 ArrayList (java.util.ArrayList)60 HashMap (java.util.HashMap)42 Invocation (org.apache.servicecomb.core.Invocation)40 DiscoveryTreeNode (org.apache.servicecomb.registry.discovery.DiscoveryTreeNode)40 Microservice (org.apache.servicecomb.registry.api.registry.Microservice)38 Expectations (mockit.Expectations)36 MicroserviceInstances (org.apache.servicecomb.registry.api.registry.MicroserviceInstances)32 CacheEndpoint (org.apache.servicecomb.registry.cache.CacheEndpoint)30 List (java.util.List)22 Transport (org.apache.servicecomb.core.Transport)22 Before (org.junit.Before)22 Map (java.util.Map)18 TransportManager (org.apache.servicecomb.core.transport.TransportManager)18 InstanceCacheManager (org.apache.servicecomb.registry.cache.InstanceCacheManager)18 MockUp (mockit.MockUp)16 MicroserviceMeta (org.apache.servicecomb.core.definition.MicroserviceMeta)14 ServiceCombServer (org.apache.servicecomb.loadbalance.ServiceCombServer)14 Server (com.netflix.loadbalancer.Server)12