Search in sources :

Example 1 with Microservice

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

the class ServiceRegistryListener method onCreateMicroserviceVersion.

@EnableExceptionPropagation
@SubscriberOrder(-1000)
@Subscribe
public void onCreateMicroserviceVersion(CreateMicroserviceVersionEvent event) {
    // TODO:如果失败,应该标记出错,以便删除MicroserviceVersions
    MicroserviceVersion microserviceVersion = event.getMicroserviceVersion();
    Microservice microservice = microserviceVersion.getMicroservice();
    // not shortName, to support cross app invoke
    String microserviceName = microserviceVersion.getMicroserviceName();
    MicroserviceMeta microserviceMeta = new MicroserviceMeta(scbEngine, microserviceName, true);
    microserviceMeta.setHandlerChain(scbEngine.getConsumerHandlerManager().getOrCreate(microserviceName));
    microserviceMeta.setFilterChain(scbEngine.getFilterChainsManager().findConsumerChain(microserviceName));
    MicroserviceVersions microserviceVersions = microserviceVersion.getMicroserviceVersions();
    microserviceMeta.setMicroserviceVersionsMeta(getMicroserviceVersionsMeta(microserviceVersions));
    boolean isServiceCenter = DefinitionConst.REGISTRY_APP_ID.equals(microservice.getAppId()) && DefinitionConst.REGISTRY_SERVICE_NAME.equals(microservice.getServiceName());
    // service center better to resolve the problem.
    if (!isServiceCenter) {
        for (String schemaId : microservice.getSchemas()) {
            Swagger swagger = scbEngine.getSwaggerLoader().loadSwagger(microservice, microserviceVersion.getInstances(), schemaId);
            // non java-chassis framework.
            if (swagger != null) {
                microserviceMeta.registerSchemaMeta(schemaId, swagger);
            }
        }
    }
    microserviceMeta.putExtData(CORE_MICROSERVICE_VERSION, microserviceVersion);
    microserviceVersion.getVendorExtensions().put(CORE_MICROSERVICE_META, microserviceMeta);
}
Also used : Microservice(org.apache.servicecomb.registry.api.registry.Microservice) MicroserviceVersion(org.apache.servicecomb.registry.consumer.MicroserviceVersion) Swagger(io.swagger.models.Swagger) MicroserviceVersions(org.apache.servicecomb.registry.consumer.MicroserviceVersions) EnableExceptionPropagation(org.apache.servicecomb.foundation.common.event.EnableExceptionPropagation) SubscriberOrder(org.apache.servicecomb.foundation.common.event.SubscriberOrder) Subscribe(com.google.common.eventbus.Subscribe)

Example 2 with Microservice

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

the class LocalRegistryServerTest method testGetAllMicroservice.

private void testGetAllMicroservice() {
    List<Microservice> microserviceList = DiscoveryManager.INSTANCE.getAllMicroservices();
    int expectedCount = 0;
    for (Microservice m : microserviceList) {
        if (m.getServiceName().equals("demo-local-registry-client") || m.getServiceName().equals("demo-local-registry-server") || m.getServiceName().equals("demo-local-registry-server-bean")) {
            expectedCount++;
        }
    }
    TestMgr.check(3, expectedCount);
}
Also used : Microservice(org.apache.servicecomb.registry.api.registry.Microservice)

Example 3 with Microservice

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

the class MultiRegistriesServerTestCase method testGetAllMicroservice.

private void testGetAllMicroservice() {
    List<Microservice> microserviceList = DiscoveryManager.INSTANCE.getAllMicroservices();
    Set<String> names = new HashSet<>();
    for (Microservice m : microserviceList) {
        if (m.getServiceName().equals("demo-multi-registries-client") || m.getServiceName().equals("demo-multi-registries-server") || m.getServiceName().equals("thirdParty-service-center") || m.getServiceName().equals("thirdParty-no-schema-server")) {
            names.add(m.getServiceName());
        }
    }
    TestMgr.check(4, names.size());
}
Also used : Microservice(org.apache.servicecomb.registry.api.registry.Microservice) HashSet(java.util.HashSet)

Example 4 with Microservice

use of org.apache.servicecomb.registry.api.registry.Microservice 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 5 with Microservice

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

the class DarklaunchServerListFilter method divideServerGroup.

private void divideServerGroup(List<ServiceCombServer> serverList, DarklaunchRule rule, List<ServiceCombServer> defaultGroup) {
    for (ServiceCombServer server : serverList) {
        boolean hasGroup = false;
        for (DarklaunchRuleItem item : rule.getRuleItems()) {
            Microservice microservice = MicroserviceCache.getInstance().getService(server.getInstance().getServiceId());
            item.getGroupCondition().setActual(DarklaunchRule.PROP_VERSION, microservice.getVersion());
            if (item.getGroupCondition().match()) {
                item.addServer(server);
                hasGroup = true;
            }
        }
        if (!hasGroup) {
            defaultGroup.add(server);
        }
    }
}
Also used : ServiceCombServer(org.apache.servicecomb.loadbalance.ServiceCombServer) Microservice(org.apache.servicecomb.registry.api.registry.Microservice)

Aggregations

Microservice (org.apache.servicecomb.registry.api.registry.Microservice)86 Test (org.junit.Test)53 MicroserviceInstance (org.apache.servicecomb.registry.api.registry.MicroserviceInstance)20 Expectations (mockit.Expectations)15 ArrayList (java.util.ArrayList)14 List (java.util.List)13 GetSchemaResponse (org.apache.servicecomb.serviceregistry.api.response.GetSchemaResponse)10 Holder (org.apache.servicecomb.serviceregistry.client.http.Holder)10 HashMap (java.util.HashMap)9 MicroserviceFactory (org.apache.servicecomb.registry.api.registry.MicroserviceFactory)9 Swagger (io.swagger.models.Swagger)8 Before (org.junit.Before)8 MockUp (mockit.MockUp)6 Configuration (org.apache.commons.configuration.Configuration)6 AccessController (org.apache.servicecomb.authentication.provider.AccessController)6 Subscribe (com.google.common.eventbus.Subscribe)5 MicroserviceInstances (org.apache.servicecomb.registry.api.registry.MicroserviceInstances)5 EventBus (com.google.common.eventbus.EventBus)4 Version (org.apache.servicecomb.foundation.common.Version)4 HashSet (java.util.HashSet)3