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);
}
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);
}
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));
}
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;
}
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());
}
Aggregations