Search in sources :

Example 1 with MicroserviceVersions

use of org.apache.servicecomb.registry.consumer.MicroserviceVersions in project java-chassis by ServiceComb.

the class SCBEngine method createMicroserviceReferenceConfig.

/**
 * for edge, versionRule maybe controlled by url rule
 * @param microserviceName hortName, or appId:shortName when invoke cross app
 * @param versionRule if is empty, then use configuration value
 * @return
 */
public MicroserviceReferenceConfig createMicroserviceReferenceConfig(String microserviceName, String versionRule) {
    ensureStatusUp();
    MicroserviceVersions microserviceVersions = DiscoveryManager.INSTANCE.getOrCreateMicroserviceVersions(parseAppId(microserviceName), microserviceName);
    ConsumerMicroserviceVersionsMeta microserviceVersionsMeta = CoreMetaUtils.getMicroserviceVersionsMeta(microserviceVersions);
    return new MicroserviceReferenceConfig(microserviceVersionsMeta, versionRule);
}
Also used : ConsumerMicroserviceVersionsMeta(org.apache.servicecomb.core.definition.ConsumerMicroserviceVersionsMeta) MicroserviceReferenceConfig(org.apache.servicecomb.core.provider.consumer.MicroserviceReferenceConfig) MicroserviceVersions(org.apache.servicecomb.registry.consumer.MicroserviceVersions)

Example 2 with MicroserviceVersions

use of org.apache.servicecomb.registry.consumer.MicroserviceVersions 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 3 with MicroserviceVersions

use of org.apache.servicecomb.registry.consumer.MicroserviceVersions in project java-chassis by ServiceComb.

the class ServiceRegistryListener method onCreateMicroservice.

@EnableExceptionPropagation
@SubscriberOrder(-1000)
@Subscribe
public void onCreateMicroservice(CreateMicroserviceEvent event) {
    MicroserviceVersions microserviceVersions = event.getMicroserviceVersions();
    microserviceVersions.getVendorExtensions().put(CORE_MICROSERVICE_VERSIONS_META, new ConsumerMicroserviceVersionsMeta(scbEngine, microserviceVersions));
}
Also used : 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 4 with MicroserviceVersions

use of org.apache.servicecomb.registry.consumer.MicroserviceVersions in project java-chassis by ServiceComb.

the class InstanceCacheChecker method check.

public InstanceCacheSummary check() {
    instanceCacheSummary.setAppId(RegistryUtils.getMicroservice().getAppId());
    instanceCacheSummary.setMicroserviceName(RegistryUtils.getMicroservice().getServiceName());
    instanceCacheSummary.setTimestamp(clock.millis());
    for (MicroserviceManager microserviceManager : appManager.getApps().values()) {
        for (MicroserviceVersions microserviceVersions : microserviceManager.getVersionsByName().values()) {
            if (microserviceVersions instanceof StaticMicroserviceVersions) {
                continue;
            }
            InstanceCacheResult instanceCacheResult = check(microserviceVersions);
            addInstanceCacheResult(instanceCacheResult);
        }
    }
    generateStatus();
    return instanceCacheSummary;
}
Also used : MicroserviceManager(org.apache.servicecomb.registry.consumer.MicroserviceManager) StaticMicroserviceVersions(org.apache.servicecomb.registry.consumer.StaticMicroserviceVersions) MicroserviceVersions(org.apache.servicecomb.registry.consumer.MicroserviceVersions) StaticMicroserviceVersions(org.apache.servicecomb.registry.consumer.StaticMicroserviceVersions)

Example 5 with MicroserviceVersions

use of org.apache.servicecomb.registry.consumer.MicroserviceVersions in project java-chassis by ServiceComb.

the class TestInstanceCacheCheckerMock method check_findInstances_cacheNotMatch.

@Test
public void check_findInstances_cacheNotMatch() {
    Holder<MicroserviceInstances> findHolder = createFindServiceInstancesResult();
    new MockUp<RegistryUtils>() {

        @Mock
        MicroserviceInstances findServiceInstances(String appId, String serviceName, String versionRule) {
            return findHolder.value;
        }
    };
    registerMicroservice(appId, microserviceName);
    MicroserviceVersions microserviceVersions = DiscoveryManager.INSTANCE.getAppManager().getOrCreateMicroserviceVersions(appId, microserviceName);
    microserviceVersions.setRevision("first");
    microserviceVersions.getOrCreateMicroserviceVersionRule(DefinitionConst.VERSION_RULE_ALL);
    Holder<MicroserviceInstances> newFindHolder = createFindServiceInstancesResult();
    newFindHolder.value.getInstancesResponse().getInstances().add(new MicroserviceInstance());
    findHolder.value = newFindHolder.value;
    InstanceCacheSummary instanceCacheSummary = checker.check();
    InstanceCacheResult instanceCacheResult = new InstanceCacheResult();
    instanceCacheResult.setAppId(appId);
    instanceCacheResult.setMicroserviceName(microserviceName);
    instanceCacheResult.setStatus(Status.ABNORMAL);
    instanceCacheResult.setDetail("instance cache not match");
    instanceCacheResult.setPulledInstances(new ArrayList<>());
    expectedSummary.getProducers().add(instanceCacheResult);
    expectedSummary.setStatus(Status.ABNORMAL);
    Assert.assertEquals(Json.encode(expectedSummary), Json.encode(instanceCacheSummary));
    Assert.assertNull(microserviceVersions.getRevision());
}
Also used : MicroserviceInstances(org.apache.servicecomb.registry.api.registry.MicroserviceInstances) MicroserviceInstance(org.apache.servicecomb.registry.api.registry.MicroserviceInstance) MockUp(mockit.MockUp) MicroserviceVersions(org.apache.servicecomb.registry.consumer.MicroserviceVersions) Test(org.junit.Test)

Aggregations

MicroserviceVersions (org.apache.servicecomb.registry.consumer.MicroserviceVersions)9 MicroserviceVersion (org.apache.servicecomb.registry.consumer.MicroserviceVersion)3 Subscribe (com.google.common.eventbus.Subscribe)2 MicroserviceMeta (org.apache.servicecomb.core.definition.MicroserviceMeta)2 EnableExceptionPropagation (org.apache.servicecomb.foundation.common.event.EnableExceptionPropagation)2 SubscriberOrder (org.apache.servicecomb.foundation.common.event.SubscriberOrder)2 MicroserviceInstance (org.apache.servicecomb.registry.api.registry.MicroserviceInstance)2 MicroserviceManager (org.apache.servicecomb.registry.consumer.MicroserviceManager)2 StaticMicroserviceVersions (org.apache.servicecomb.registry.consumer.StaticMicroserviceVersions)2 Test (org.junit.Test)2 Swagger (io.swagger.models.Swagger)1 HashMap (java.util.HashMap)1 MockUp (mockit.MockUp)1 ConsumerMicroserviceVersionsMeta (org.apache.servicecomb.core.definition.ConsumerMicroserviceVersionsMeta)1 OperationMeta (org.apache.servicecomb.core.definition.OperationMeta)1 SchemaMeta (org.apache.servicecomb.core.definition.SchemaMeta)1 MicroserviceReferenceConfig (org.apache.servicecomb.core.provider.consumer.MicroserviceReferenceConfig)1 Microservice (org.apache.servicecomb.registry.api.registry.Microservice)1 MicroserviceInstances (org.apache.servicecomb.registry.api.registry.MicroserviceInstances)1 AppManager (org.apache.servicecomb.registry.consumer.AppManager)1