Search in sources :

Example 1 with InstanceCache

use of org.apache.servicecomb.registry.cache.InstanceCache in project java-chassis by ServiceComb.

the class ClassificationAddress method generateZoneAndRegionAddress.

private Map<String, List<String>> generateZoneAndRegionAddress(String key) {
    InstanceCache KieCaches = instanceCacheManager.getOrCreate(REGISTRY_APP_ID, key, DefinitionConst.VERSION_RULE_LATEST);
    List<CacheEndpoint> CacheEndpoints = new ArrayList<>();
    if (REGISTRY_SERVICE_NAME.equals(key)) {
        CacheEndpoints = KieCaches.getOrCreateTransportMap().get(defaultTransport);
        maxRetryTimes = CacheEndpoints.size();
    } else {
        if (KieCaches.getInstanceMap().size() <= 0) {
            return null;
        }
        CacheEndpoints = KieCaches.getOrCreateTransportMap().get(defaultTransport);
    }
    Map<String, List<String>> zoneAndRegion = new HashMap<>();
    dataCenterInfo = findRegion(CacheEndpoints);
    Set<String> sameZone = new HashSet<>();
    Set<String> sameRegion = new HashSet<>();
    for (CacheEndpoint cacheEndpoint : CacheEndpoints) {
        if (regionAndAZMatch(dataCenterInfo, cacheEndpoint.getInstance())) {
            sameZone.add(cacheEndpoint.getEndpoint());
        } else {
            sameRegion.add(cacheEndpoint.getEndpoint());
        }
    }
    zoneAndRegion.put("sameZone", new ArrayList<>(sameZone));
    zoneAndRegion.put("sameRegion", new ArrayList<>(sameRegion));
    return zoneAndRegion;
}
Also used : CacheEndpoint(org.apache.servicecomb.registry.cache.CacheEndpoint) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) InstanceCache(org.apache.servicecomb.registry.cache.InstanceCache) ArrayList(java.util.ArrayList) List(java.util.List) HashSet(java.util.HashSet)

Example 2 with InstanceCache

use of org.apache.servicecomb.registry.cache.InstanceCache in project java-chassis by ServiceComb.

the class TestClientTimeout method getServiceCombServerStats.

private static ServiceCombServerStats getServiceCombServerStats() {
    InstanceCache instanceCache = DiscoveryManager.INSTANCE.getInstanceCacheManager().getOrCreate(RegistrationManager.INSTANCE.getAppId(), "jaxrs", "0+");
    org.apache.servicecomb.registry.api.registry.MicroserviceInstance microserviceInstance = instanceCache.getInstanceMap().values().iterator().next();
    ServiceCombServer serviceCombServer = ServiceCombLoadBalancerStats.INSTANCE.getServiceCombServer(microserviceInstance);
    return ServiceCombLoadBalancerStats.INSTANCE.getServiceCombServerStats(serviceCombServer);
}
Also used : ServiceCombServer(org.apache.servicecomb.loadbalance.ServiceCombServer) InstanceCache(org.apache.servicecomb.registry.cache.InstanceCache)

Example 3 with InstanceCache

use of org.apache.servicecomb.registry.cache.InstanceCache in project java-chassis by ServiceComb.

the class MicroserviceVersionRule method initData.

private void initData(MicroserviceVersionRuleData data) {
    if (data.latestVersion == null) {
        data.latestVersion = findLatest(data.versions, data.instances.values());
    }
    data.instanceCache = new InstanceCache(appId, microserviceName, versionRule.getVersionRule(), data.instances);
    data.versionedCache = new VersionedCache().name(versionRule.getVersionRule()).autoCacheVersion().data(data.instances);
}
Also used : VersionedCache(org.apache.servicecomb.foundation.common.cache.VersionedCache) InstanceCache(org.apache.servicecomb.registry.cache.InstanceCache)

Example 4 with InstanceCache

use of org.apache.servicecomb.registry.cache.InstanceCache in project java-chassis by ServiceComb.

the class TestInstanceCache method testCacheChanged.

@Test
public void testCacheChanged() {
    InstanceCache newCache = new InstanceCache("testAppID", "testMicroServiceName", "1.0", instanceCache.getInstanceMap());
    Assert.assertTrue(instanceCache.cacheChanged(newCache));
}
Also used : InstanceCache(org.apache.servicecomb.registry.cache.InstanceCache) Test(org.junit.Test)

Example 5 with InstanceCache

use of org.apache.servicecomb.registry.cache.InstanceCache in project java-chassis by ServiceComb.

the class TestInstanceCache method beforeClass.

@BeforeClass
public static void beforeClass() {
    MicroserviceInstance instance = new MicroserviceInstance();
    instance.setStatus(MicroserviceInstanceStatus.UP);
    List<String> endpoints = new ArrayList<>();
    endpoints.add("rest://127.0.0.1:8080");
    instance.setEndpoints(endpoints);
    instance.setInstanceId("1");
    instMap.put(instance.getInstanceId(), instance);
    instanceCache = new InstanceCache("testAppID", "testMicroServiceName", "1.0", instMap);
}
Also used : ArrayList(java.util.ArrayList) MicroserviceInstance(org.apache.servicecomb.registry.api.registry.MicroserviceInstance) InstanceCache(org.apache.servicecomb.registry.cache.InstanceCache) BeforeClass(org.junit.BeforeClass)

Aggregations

InstanceCache (org.apache.servicecomb.registry.cache.InstanceCache)5 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 VersionedCache (org.apache.servicecomb.foundation.common.cache.VersionedCache)1 ServiceCombServer (org.apache.servicecomb.loadbalance.ServiceCombServer)1 MicroserviceInstance (org.apache.servicecomb.registry.api.registry.MicroserviceInstance)1 CacheEndpoint (org.apache.servicecomb.registry.cache.CacheEndpoint)1 BeforeClass (org.junit.BeforeClass)1 Test (org.junit.Test)1