use of io.servicecomb.core.definition.MicroserviceMeta in project java-chassis by ServiceComb.
the class CseClientHttpRequest method createRequestMeta.
private RequestMeta createRequestMeta(String httpMetod, URI uri) {
String microserviceName = uri.getAuthority();
ReferenceConfig referenceConfig = CseContext.getInstance().getConsumerProviderManager().getReferenceConfig(microserviceName);
MicroserviceMeta microserviceMeta = referenceConfig.getMicroserviceMeta();
ServicePathManager servicePathManager = ServicePathManager.getServicePathManager(microserviceMeta);
if (servicePathManager == null) {
throw new Error(String.format("no schema defined for %s:%s", microserviceMeta.getAppId(), microserviceMeta.getName()));
}
OperationLocator locator = servicePathManager.locateOperation(uri.getPath(), httpMetod);
RestOperationMeta swaggerRestOperation = locator.getOperation();
Map<String, String> pathParams = locator.getPathVarMap();
return new RequestMeta(referenceConfig, swaggerRestOperation, pathParams);
}
use of io.servicecomb.core.definition.MicroserviceMeta in project java-chassis by ServiceComb.
the class MockUtil method mockRegisterManager.
public void mockRegisterManager() throws InstantiationException, IllegalAccessException {
MicroserviceMeta microserviceMeta = microserviceMetaManager.getOrCreateMicroserviceMeta("app:test");
microserviceMeta.putExtData("RestServicePathManager", new ServicePathManager(microserviceMeta));
ConsumerSchemaFactory consumerSchemaFactory = new MockUp<ConsumerSchemaFactory>() {
@Mock
public MicroserviceMeta getOrCreateConsumer(String microserviceName) {
return microserviceMeta;
}
}.getMockInstance();
CseContext.getInstance().setConsumerSchemaFactory(consumerSchemaFactory);
}
use of io.servicecomb.core.definition.MicroserviceMeta in project java-chassis by ServiceComb.
the class TestConsumerSchemaFactory method testConnectToConsumerSame.
@Test
public void testConnectToConsumerSame() {
MicroserviceMeta microserviceMeta = consumerSchemaFactory.getOrCreateConsumer("ms", "latest");
SchemaMeta schemaMeta = microserviceMeta.ensureFindSchemaMeta("schema");
Map<String, ConsumerOperationMeta> consumerOperationMap = new HashMap<>();
consumerSchemaFactory.connectToConsumer(schemaMeta, null, consumerOperationMap);
Assert.assertEquals(1, consumerOperationMap.size());
ConsumerOperationMeta consumerOperationMeta = consumerOperationMap.get("add");
Assert.assertEquals(ConsumerArgumentSame.class, consumerOperationMeta.getArgsMapper().getArgumentMapper(0).getClass());
Assert.assertEquals(ConsumerResponseSame.class, consumerOperationMeta.getResponseMapper().getClass());
}
use of io.servicecomb.core.definition.MicroserviceMeta in project java-chassis by ServiceComb.
the class ConsumerSchemaFactory method connectToConsumer.
public void connectToConsumer(SchemaMeta schemaMeta, Class<?> consumerIntf, Map<String, ConsumerOperationMeta> consumerOperationMap) {
MicroserviceMeta microserviceMeta = schemaMeta.getMicroserviceMeta();
ConsumerSchemaContext context = new ConsumerSchemaContext();
context.setMicroserviceMeta(microserviceMeta);
context.setSchemaId(schemaMeta.getSchemaId());
context.setSchemaMeta(schemaMeta);
context.setProviderClass(consumerIntf);
context.setConsumerOperationMap(consumerOperationMap);
if (consumerIntf == null) {
consumerIntf = schemaMeta.getSwaggerIntf();
context.setProviderClass(consumerIntf);
}
if (consumerIntf.equals(schemaMeta.getSwaggerIntf())) {
mapSameIntfParameters(context);
return;
}
mapDiffIntfParameters(context);
}
use of io.servicecomb.core.definition.MicroserviceMeta in project java-chassis by ServiceComb.
the class ConsumerSchemaFactory method getOrCreateConsumer.
// 透明rpc场景,因为每次指定schema调用,所以可以懒加载
// 而rest场景,是根据path反向查找schema,所以必须所有的schema都存在才行
// 两种场景可能都会来初始化,为避免管理复杂度,改为全部全量初始化
//
// 用于rest consumer注册的场景,此时启动流程已经完成,需要主动通知listener
// microserviceName可能是本app内的微服务
// 也可能是appid:name形式的其他app的微服务
public MicroserviceMeta getOrCreateConsumer(String microserviceName, String microserviceVersionRule) {
MicroserviceMeta microserviceMeta = microserviceMetaManager.findValue(microserviceName);
if (microserviceMeta != null) {
return microserviceMeta;
}
// 极小概率事件,不必做microservice级的锁分解了
synchronized (lock) {
microserviceMeta = microserviceMetaManager.findValue(microserviceName);
if (microserviceMeta != null) {
return microserviceMeta;
}
// 获取指定服务中有哪些schemaId
// 先取本地,再从服务中心取,如果服务中心取成功了,则将schema id合并处理
microserviceMeta = new MicroserviceMeta(microserviceName);
Set<String> schemaIds = findLocalSchemas(microserviceMeta);
Microservice microservice = findMicroservice(microserviceMeta, microserviceVersionRule);
if (microservice != null) {
schemaIds.addAll(microservice.getSchemas());
}
getOrCreateConsumerSchema(microserviceMeta, schemaIds, microservice);
microserviceMetaManager.register(microserviceName, microserviceMeta);
schemaListenerManager.notifySchemaListener(microserviceMeta);
return microserviceMeta;
}
}
Aggregations