Search in sources :

Example 11 with MicroserviceMeta

use of org.apache.servicecomb.core.definition.MicroserviceMeta in project incubator-servicecomb-java-chassis by apache.

the class ProducerProviderManager method init.

public void init() throws Exception {
    for (ProducerProvider provider : producerProviderList) {
        provider.init();
    }
    Microservice microservice = RegistryUtils.getMicroservice();
    MicroserviceMeta microserviceMeta = microserviceMetaManager.getOrCreateMicroserviceMeta(microservice);
    for (SchemaMeta schemaMeta : microserviceMeta.getSchemaMetas()) {
        String content = SchemaUtils.swaggerToString(schemaMeta.getSwagger());
        microservice.addSchema(schemaMeta.getSchemaId(), content);
    }
}
Also used : Microservice(org.apache.servicecomb.serviceregistry.api.registry.Microservice) ProducerProvider(org.apache.servicecomb.core.ProducerProvider) SchemaMeta(org.apache.servicecomb.core.definition.SchemaMeta) MicroserviceMeta(org.apache.servicecomb.core.definition.MicroserviceMeta)

Example 12 with MicroserviceMeta

use of org.apache.servicecomb.core.definition.MicroserviceMeta in project incubator-servicecomb-java-chassis by apache.

the class AbstractSchemaFactory method getOrCreateSchema.

// 因为aop的存在,schemaInstance的class不一定等于schemaClass
protected SchemaMeta getOrCreateSchema(CONTEXT context) {
    MicroserviceMeta microserviceMeta = context.getMicroserviceMeta();
    SchemaMeta schemaMeta = microserviceMeta.findSchemaMeta(context.getSchemaId());
    if (schemaMeta == null) {
        schemaMeta = createSchema(context);
    }
    context.setSchemaMeta(schemaMeta);
    return schemaMeta;
}
Also used : SchemaMeta(org.apache.servicecomb.core.definition.SchemaMeta) MicroserviceMeta(org.apache.servicecomb.core.definition.MicroserviceMeta)

Example 13 with MicroserviceMeta

use of org.apache.servicecomb.core.definition.MicroserviceMeta in project incubator-servicecomb-java-chassis by apache.

the class ProducerSchemaFactory method getOrCreateProducerSchema.

// 只会在启动流程中调用
public SchemaMeta getOrCreateProducerSchema(String microserviceName, String schemaId, Class<?> producerClass, Object producerInstance) {
    MicroserviceMeta microserviceMeta = microserviceMetaManager.getOrCreateMicroserviceMeta(microserviceName);
    ProducerSchemaContext context = new ProducerSchemaContext();
    context.setMicroserviceMeta(microserviceMeta);
    context.setSchemaId(schemaId);
    context.setProviderClass(producerClass);
    context.setProducerInstance(producerInstance);
    SchemaMeta schemaMeta = getOrCreateSchema(context);
    SwaggerProducer producer = swaggerEnv.createProducer(producerInstance, schemaMeta.getSwagger());
    Executor reactiveExecutor = BeanUtils.getBean(ExecutorManager.EXECUTOR_REACTIVE);
    for (OperationMeta operationMeta : schemaMeta.getOperations()) {
        SwaggerProducerOperation producerOperation = producer.findOperation(operationMeta.getOperationId());
        operationMeta.putExtData(Const.PRODUCER_OPERATION, producerOperation);
        if (CompletableFuture.class.equals(producerOperation.getProducerMethod().getReturnType())) {
            operationMeta.setExecutor(ExecutorManager.findExecutor(operationMeta, reactiveExecutor));
        }
    }
    return schemaMeta;
}
Also used : Executor(java.util.concurrent.Executor) SwaggerProducer(org.apache.servicecomb.swagger.engine.SwaggerProducer) SchemaMeta(org.apache.servicecomb.core.definition.SchemaMeta) MicroserviceMeta(org.apache.servicecomb.core.definition.MicroserviceMeta) SwaggerProducerOperation(org.apache.servicecomb.swagger.engine.SwaggerProducerOperation) OperationMeta(org.apache.servicecomb.core.definition.OperationMeta)

Example 14 with MicroserviceMeta

use of org.apache.servicecomb.core.definition.MicroserviceMeta in project incubator-servicecomb-java-chassis by apache.

the class TestDefinition method testMicroServiceMeta.

@Test
public void testMicroServiceMeta() {
    MicroserviceMeta oMicroMeta = new MicroserviceMeta("app:micro1");
    Assert.assertEquals(0, oMicroMeta.getSchemaMetas().size());
    Assert.assertEquals(0, oMicroMeta.getOperations().size());
    Assert.assertEquals("micro1", oMicroMeta.getShortName());
    Assert.assertEquals("app:micro1", oMicroMeta.getName());
    try {
        oMicroMeta.putExtData("key1", new String("value1"));
        Assert.assertNotEquals(null, oMicroMeta.getExtData("key1"));
    } catch (Exception e) {
        Assert.assertNotNull(e);
    }
}
Also used : MicroserviceMeta(org.apache.servicecomb.core.definition.MicroserviceMeta) Test(org.junit.Test)

Example 15 with MicroserviceMeta

use of org.apache.servicecomb.core.definition.MicroserviceMeta in project incubator-servicecomb-java-chassis by apache.

the class InvocationFactory method forConsumer.

/*
   * 为tcc场景提供的快捷方式,consumer端使用
   */
public static Invocation forConsumer(ReferenceConfig referenceConfig, String operationQualifiedName, Object[] swaggerArguments) {
    MicroserviceMeta microserviceMeta = referenceConfig.getMicroserviceMeta();
    OperationMeta operationMeta = microserviceMeta.ensureFindOperation(operationQualifiedName);
    return forConsumer(referenceConfig, operationMeta, swaggerArguments);
}
Also used : MicroserviceMeta(org.apache.servicecomb.core.definition.MicroserviceMeta) OperationMeta(org.apache.servicecomb.core.definition.OperationMeta)

Aggregations

MicroserviceMeta (org.apache.servicecomb.core.definition.MicroserviceMeta)20 SchemaMeta (org.apache.servicecomb.core.definition.SchemaMeta)10 ServicePathManager (org.apache.servicecomb.common.rest.locator.ServicePathManager)5 OperationMeta (org.apache.servicecomb.core.definition.OperationMeta)5 Swagger (io.swagger.models.Swagger)3 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 RestOperationMeta (org.apache.servicecomb.common.rest.definition.RestOperationMeta)2 Path (io.swagger.models.Path)1 IdentityHashMap (java.util.IdentityHashMap)1 Map (java.util.Map)1 Executor (java.util.concurrent.Executor)1 Mock (mockit.Mock)1 MockUp (mockit.MockUp)1 OperationLocator (org.apache.servicecomb.common.rest.locator.OperationLocator)1 ProducerProvider (org.apache.servicecomb.core.ProducerProvider)1 MicroserviceVersionMeta (org.apache.servicecomb.core.definition.MicroserviceVersionMeta)1 ConsumerSchemaFactory (org.apache.servicecomb.core.definition.schema.ConsumerSchemaFactory)1 ReferenceConfig (org.apache.servicecomb.core.provider.consumer.ReferenceConfig)1