Search in sources :

Example 6 with MicroserviceInstance

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

the class HealthMonitorDataProvider method getMonitorData.

private MonitorData getMonitorData() {
    Collection<HystrixCommandMetrics> instances = HystrixCommandMetrics.getInstances();
    MonitorData monitorData = new MonitorData();
    Microservice microservice = RegistryUtils.getMicroservice();
    MicroserviceInstance microserviceInstance = RegistryUtils.getMicroserviceInstance();
    monitorData.setAppId(microservice.getAppId());
    monitorData.setName(microservice.getServiceName());
    monitorData.setVersion(microservice.getVersion());
    monitorData.setServiceId(microservice.getServiceId());
    monitorData.setInstance(microserviceInstance.getHostName());
    monitorData.setInstanceId(microserviceInstance.getInstanceId());
    if (MonitorConstant.insCacheEnabled()) {
        InstanceCacheChecker checker = new InstanceCacheChecker(DiscoveryManager.INSTANCE.getAppManager());
        monitorData.setProvidersCache(checker.check().getProducers());
    }
    exactProcessInfo(monitorData);
    synchronized (lock) {
        if (this.instanceCacheSummary != null) {
            Diagnosis diagnosis = new Diagnosis();
            diagnosis.setInstanceCache(instanceCacheSummary);
            monitorData.setDiagnosis(diagnosis);
            this.instanceCacheSummary = null;
        }
    }
    if (instances.isEmpty()) {
        return monitorData;
    }
    for (HystrixCommandMetrics instance : instances) {
        monitorData.appendInterfaceInfo(instance);
    }
    return monitorData;
}
Also used : InstanceCacheChecker(org.apache.servicecomb.serviceregistry.diagnosis.instance.InstanceCacheChecker) Microservice(org.apache.servicecomb.registry.api.registry.Microservice) MicroserviceInstance(org.apache.servicecomb.registry.api.registry.MicroserviceInstance) Diagnosis(org.apache.servicecomb.huaweicloud.dashboard.monitor.data.Diagnosis) HystrixCommandMetrics(com.netflix.hystrix.HystrixCommandMetrics) MonitorData(org.apache.servicecomb.huaweicloud.dashboard.monitor.data.MonitorData)

Example 7 with MicroserviceInstance

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

the class TestServiceCombServer method setUp.

@Before
public void setUp() {
    MicroserviceInstance instance = new MicroserviceInstance();
    instance.setInstanceId("123456");
    cs = new ServiceCombServer(null, transport, new CacheEndpoint("abcd", instance));
}
Also used : CacheEndpoint(org.apache.servicecomb.registry.cache.CacheEndpoint) MicroserviceInstance(org.apache.servicecomb.registry.api.registry.MicroserviceInstance) Before(org.junit.Before)

Example 8 with MicroserviceInstance

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

the class TestSessionSticknessRule method testRuleFullOperation.

@Test
public void testRuleFullOperation() {
    SessionStickinessRule rule = new SessionStickinessRule();
    LoadBalancer mockedLb = mock(LoadBalancer.class);
    Transport transport = mock(Transport.class);
    MicroserviceInstance instance1 = new MicroserviceInstance();
    instance1.setInstanceId("1234");
    ServiceCombServer mockedServer = new ServiceCombServer(null, transport, new CacheEndpoint("rest:127.0.0.1:8889", instance1));
    Invocation invocation = mock(Invocation.class);
    LoadBalancerStats stats = mock(LoadBalancerStats.class);
    Mockito.when(mockedLb.getLoadBalancerStats()).thenReturn(stats);
    Deencapsulation.invoke(rule, "chooseServerWhenTimeout", Arrays.asList(mockedServer), invocation);
    mockedServer.setAlive(true);
    mockedServer.setReadyToServe(true);
    List<ServiceCombServer> allServers = Arrays.asList(mockedServer);
    rule.setLoadBalancer(mockedLb);
    Server s = rule.choose(allServers, invocation);
    Assert.assertEquals(s, mockedServer);
    s = rule.choose(allServers, invocation);
    Assert.assertEquals(s, mockedServer);
}
Also used : Invocation(org.apache.servicecomb.core.Invocation) Server(com.netflix.loadbalancer.Server) CacheEndpoint(org.apache.servicecomb.registry.cache.CacheEndpoint) LoadBalancerStats(com.netflix.loadbalancer.LoadBalancerStats) MicroserviceInstance(org.apache.servicecomb.registry.api.registry.MicroserviceInstance) Transport(org.apache.servicecomb.core.Transport) Test(org.junit.Test)

Example 9 with MicroserviceInstance

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

the class PriorityInstancePropertyDiscoveryFilterTest method testGetFilteredListOfServers.

@Test
public void testGetFilteredListOfServers() {
    // complete match
    executeTest("", Sets.newHashSet("instance.empty"));
    executeTest("local", Sets.newHashSet("instance.local"));
    executeTest("local.feature1", Sets.newHashSet("instance.local.feature1"));
    executeTest("local.feature1.sprint1", Sets.newHashSet("instance.local.feature1.sprint1"));
    // priority match
    executeTest("test", Sets.newHashSet("instance.empty"));
    executeTest("local.feature2", Sets.newHashSet("instance.local"));
    executeTest("local.feature1.sprint2", Sets.newHashSet("instance.local.feature1"));
    executeTest("local.feature2.sprint1", Sets.newHashSet("instance.local"));
    executeTest("local.feature1.sprint2.temp", Sets.newHashSet("instance.local.feature1"));
    // none match
    MicroserviceInstance instance1 = instances.remove("instance.empty");
    executeTest("", Collections.emptySet());
    executeTest("foo", Collections.emptySet());
    instances.put("instance.empty", instance1);
}
Also used : MicroserviceInstance(org.apache.servicecomb.registry.api.registry.MicroserviceInstance) Test(org.junit.Test)

Example 10 with MicroserviceInstance

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

the class TestEnvAdapterManager method testProcessInstance.

@Test
public void testProcessInstance() {
    MicroserviceInstance instance = new MicroserviceInstance();
    manager.processInstanceWithAdapters(instance);
    assertEquals("order=0", instance.getProperties().get("cas_env_one"));
    assertEquals("order=0", instance.getProperties().get("cas_env_two"));
    assertNull(instance.getProperties().get("default-env-adapter"));
}
Also used : 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