Search in sources :

Example 16 with MicroserviceMeta

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);
}
Also used : OperationLocator(io.servicecomb.common.rest.locator.OperationLocator) RestOperationMeta(io.servicecomb.common.rest.definition.RestOperationMeta) ReferenceConfig(io.servicecomb.core.provider.consumer.ReferenceConfig) MicroserviceMeta(io.servicecomb.core.definition.MicroserviceMeta) ServicePathManager(io.servicecomb.common.rest.locator.ServicePathManager)

Example 17 with MicroserviceMeta

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);
}
Also used : MicroserviceMeta(io.servicecomb.core.definition.MicroserviceMeta) ConsumerSchemaFactory(io.servicecomb.core.definition.schema.ConsumerSchemaFactory) Mock(mockit.Mock) ServicePathManager(io.servicecomb.common.rest.locator.ServicePathManager)

Example 18 with MicroserviceMeta

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());
}
Also used : HashMap(java.util.HashMap) SchemaMeta(io.servicecomb.core.definition.SchemaMeta) MicroserviceMeta(io.servicecomb.core.definition.MicroserviceMeta) ConsumerOperationMeta(io.servicecomb.core.provider.consumer.ConsumerOperationMeta) Test(org.junit.Test)

Example 19 with MicroserviceMeta

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);
}
Also used : MicroserviceMeta(io.servicecomb.core.definition.MicroserviceMeta)

Example 20 with MicroserviceMeta

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;
    }
}
Also used : Microservice(io.servicecomb.serviceregistry.api.registry.Microservice) MicroserviceMeta(io.servicecomb.core.definition.MicroserviceMeta)

Aggregations

MicroserviceMeta (io.servicecomb.core.definition.MicroserviceMeta)24 SchemaMeta (io.servicecomb.core.definition.SchemaMeta)11 Test (org.junit.Test)8 RestOperationMeta (io.servicecomb.common.rest.definition.RestOperationMeta)6 ServicePathManager (io.servicecomb.common.rest.locator.ServicePathManager)5 OperationMeta (io.servicecomb.core.definition.OperationMeta)4 InvocationException (io.servicecomb.core.exception.InvocationException)3 ConsumerOperationMeta (io.servicecomb.core.provider.consumer.ConsumerOperationMeta)3 HashMap (java.util.HashMap)3 OperationLocator (io.servicecomb.common.rest.locator.OperationLocator)2 CommonExceptionData (io.servicecomb.core.exception.CommonExceptionData)2 Swagger (io.swagger.models.Swagger)2 ArrayList (java.util.ArrayList)2 Invocation (io.servicecomb.core.Invocation)1 ProducerProvider (io.servicecomb.core.ProducerProvider)1 ConsumerSchemaFactory (io.servicecomb.core.definition.schema.ConsumerSchemaFactory)1 ReferenceConfig (io.servicecomb.core.provider.consumer.ReferenceConfig)1 Microservice (io.servicecomb.serviceregistry.api.registry.Microservice)1 SwaggerGenerator (io.servicecomb.swagger.generator.core.SwaggerGenerator)1 Mock (mockit.Mock)1