use of org.apache.servicecomb.registry.consumer.MicroserviceVersion 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.MicroserviceVersion in project java-chassis by ServiceComb.
the class TestConsumers method getOrCreateMicroserviceVersionRule.
@Test
public void getOrCreateMicroserviceVersionRule() {
MicroserviceVersionRule microserviceVersionRule = appManager.getOrCreateMicroserviceVersionRule(appId, serviceName, versionRule);
Assert.assertEquals("0.0.0.0+", microserviceVersionRule.getVersionRule().getVersionRule());
Assert.assertEquals(1, microserviceManager.getVersionsByName().size());
MicroserviceVersion microserviceVersion = microserviceVersionRule.getLatestMicroserviceVersion();
Assert.assertEquals(serviceName, microserviceVersion.getMicroserviceName());
Assert.assertEquals(serviceId, microserviceVersion.getMicroserviceId());
Assert.assertEquals(version, microserviceVersion.getVersion().getVersion());
}
use of org.apache.servicecomb.registry.consumer.MicroserviceVersion in project java-chassis by ServiceComb.
the class ITSCBAsyncRestTemplate method ensureProviderBasePath.
private void ensureProviderBasePath(String producerName) {
MicroserviceManager microserviceManager = DiscoveryManager.INSTANCE.getAppManager().getOrCreateMicroserviceManager(RegistrationManager.INSTANCE.getMicroservice().getAppId());
MicroserviceVersions producerMicroserviceVersions = microserviceManager.getOrCreateMicroserviceVersions(producerName);
Optional<MicroserviceVersion> latestMicroserviceVersion = producerMicroserviceVersions.getVersions().values().stream().max(Comparator.comparing(MicroserviceVersion::getVersion));
latestMicroserviceVersion.ifPresent(microserviceVersion -> {
MicroserviceMeta microserviceMeta = microserviceVersion.getVendorExtensions().get(CORE_MICROSERVICE_META);
SchemaMeta schemaMeta = microserviceMeta.ensureFindSchemaMeta(schemaId);
basePath = schemaMeta.getSwagger().getBasePath();
});
latestMicroserviceVersion.orElseThrow(() -> new IllegalStateException("cannot find producer: " + producerName));
}
use of org.apache.servicecomb.registry.consumer.MicroserviceVersion in project java-chassis by ServiceComb.
the class OperationInstancesDiscoveryFilter method init.
@Override
public void init(DiscoveryContext context, DiscoveryTreeNode parent) {
Invocation invocation = context.getInputParameters();
// sort versions
List<MicroserviceVersion> microserviceVersions = sortedMicroserviceVersion(invocation, parent.data());
Map<String, DiscoveryTreeNode> operationNodes = new ConcurrentHashMapEx<>();
for (MicroserviceVersion microserviceVersion : microserviceVersions) {
MicroserviceMeta microserviceMeta = CoreMetaUtils.getMicroserviceMeta(microserviceVersion);
for (OperationMeta operationMeta : microserviceMeta.getOperations()) {
DiscoveryTreeNode node = operationNodes.get(operationMeta.getMicroserviceQualifiedName());
if (node == null) {
Map<String, MicroserviceInstance> instanceMap = microserviceVersion.getInstances().stream().collect(Collectors.toMap(MicroserviceInstance::getInstanceId, Function.identity()));
DiscoveryTreeNode tempNode = createOperationNode(parent, microserviceVersion);
tempNode.data(instanceMap);
operationNodes.put(operationMeta.getMicroserviceQualifiedName(), tempNode);
continue;
}
// exist, append instances
microserviceVersion.getInstances().forEach(microserviceInstance -> node.mapData().put(microserviceInstance.getInstanceId(), microserviceInstance));
}
}
parent.children(operationNodes);
}
use of org.apache.servicecomb.registry.consumer.MicroserviceVersion in project java-chassis by ServiceComb.
the class OperationInstancesDiscoveryFilter method sortedMicroserviceVersion.
protected List<MicroserviceVersion> sortedMicroserviceVersion(Invocation invocation, Map<String, MicroserviceInstance> instances) {
OperationMeta latestOperationMeta = invocation.getOperationMeta();
MicroserviceMeta latestMicroserviceMeta = latestOperationMeta.getSchemaMeta().getMicroserviceMeta();
AppManager appManager = DiscoveryManager.INSTANCE.getAppManager();
MicroserviceVersions microserviceVersions = appManager.getOrCreateMicroserviceVersions(latestMicroserviceMeta.getAppId(), latestMicroserviceMeta.getMicroserviceName());
Map<String, MicroserviceVersion> uniqueMicroserviceVersion = new HashMap<>();
for (MicroserviceInstance instance : instances.values()) {
MicroserviceVersion microserviceVersion = microserviceVersions.getVersion(instance.getServiceId());
uniqueMicroserviceVersion.put(instance.getServiceId(), microserviceVersion);
}
return uniqueMicroserviceVersion.values().stream().sorted(Comparator.comparing(MicroserviceVersion::getVersion)).collect(Collectors.toList());
}
Aggregations