Search in sources :

Example 6 with SchemaMeta

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

the class TestRestEngineSchemaListener method test.

@Test
public void test() {
    BeanUtils.setContext(Mockito.mock(ApplicationContext.class));
    MicroserviceMeta mm = new MicroserviceMeta("app:ms");
    List<SchemaMeta> smList = new ArrayList<>();
    SwaggerGenerator generator = new SwaggerGenerator(context, TestRestEngineSchemaListenerSchemaImpl.class);
    Swagger swagger = generator.generate();
    swagger.setBasePath("");
    SchemaMeta sm1 = new SchemaMeta(swagger, mm, "sid1");
    smList.add(sm1);
    RestEngineSchemaListener listener = new RestEngineSchemaListener();
    SchemaMeta[] smArr = smList.toArray(new SchemaMeta[smList.size()]);
    listener.onSchemaLoaded(smArr);
    // 重复调用,不应该出异常
    listener.onSchemaLoaded(smArr);
    ServicePathManager spm = ServicePathManager.getServicePathManager(mm);
    Assert.assertEquals(mm, spm.getMicroserviceMeta());
    Assert.assertSame(sm1, spm.consumerLocateOperation("/add/", "POST").getOperation().getOperationMeta().getSchemaMeta());
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) SwaggerGenerator(org.apache.servicecomb.swagger.generator.core.SwaggerGenerator) SchemaMeta(org.apache.servicecomb.core.definition.SchemaMeta) Swagger(io.swagger.models.Swagger) MicroserviceMeta(org.apache.servicecomb.core.definition.MicroserviceMeta) ArrayList(java.util.ArrayList) ServicePathManager(org.apache.servicecomb.common.rest.locator.ServicePathManager) Test(org.junit.Test)

Example 7 with SchemaMeta

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

the class RestEngineSchemaListener method onSchemaLoaded.

@Override
public void onSchemaLoaded(SchemaMeta... schemaMetas) {
    // 此时相应的ServicePathManager可能正在被使用,为避免太高的复杂度,使用copy on write逻辑
    Map<String, ServicePathManager> mgrMap = new HashMap<>();
    for (SchemaMeta schemaMeta : schemaMetas) {
        MicroserviceMeta microserviceMeta = schemaMeta.getMicroserviceMeta();
        ServicePathManager mgr = findPathManager(mgrMap, microserviceMeta);
        mgr.addSchema(schemaMeta);
    }
    for (ServicePathManager mgr : mgrMap.values()) {
        // 对具有动态path operation进行排序
        mgr.sortPath();
        mgr.saveToMicroserviceMeta();
    }
}
Also used : HashMap(java.util.HashMap) SchemaMeta(org.apache.servicecomb.core.definition.SchemaMeta) MicroserviceMeta(org.apache.servicecomb.core.definition.MicroserviceMeta) ServicePathManager(org.apache.servicecomb.common.rest.locator.ServicePathManager)

Example 8 with SchemaMeta

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

the class DynamicSchemaLoader method registerSchemas.

/**
 * 动态注册指定目录下的schema契约到指定服务
 * @param microserviceName name of microservice
 * @param schemaLocation eg. "classpath*:schemas/*.yaml"
 */
public void registerSchemas(String microserviceName, String schemaLocation) {
    LOGGER.info("dynamic register schemas for {} in {}", microserviceName, schemaLocation);
    List<SchemaMeta> schemaMetaList = new ArrayList<>();
    Resource[] resArr = PaaSResourceUtils.getResources(schemaLocation);
    for (Resource resource : resArr) {
        SchemaMeta schemaMeta = CseContext.getInstance().getSchemaLoader().registerSchema(microserviceName, resource);
        schemaMetaList.add(schemaMeta);
    }
    CseContext.getInstance().getSchemaListenerManager().notifySchemaListener(schemaMetaList);
}
Also used : SchemaMeta(org.apache.servicecomb.core.definition.SchemaMeta) ArrayList(java.util.ArrayList) Resource(org.springframework.core.io.Resource)

Example 9 with SchemaMeta

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

the class TestOperationProtobuf method testOperationProtobuf.

@Test
public void testOperationProtobuf() throws Exception {
    UnitTestMeta meta = new UnitTestMeta();
    SchemaMeta schemaMeta = meta.getOrCreateSchemaMeta(Impl.class);
    OperationMeta operationMeta = schemaMeta.findOperation("test");
    OperationProtobuf operationProtobuf = ProtobufManager.getOrCreateOperation(operationMeta);
    Assert.assertEquals(operationMeta, operationProtobuf.getOperationMeta());
    Assert.assertEquals(ArgsNotWrapSchema.class, operationProtobuf.getRequestSchema().getClass());
    Assert.assertEquals(NormalWrapSchema.class, operationProtobuf.getResponseSchema().getClass());
    WrapSchema responseSchema = operationProtobuf.findResponseSchema(200);
    Assert.assertEquals(operationProtobuf.getResponseSchema(), responseSchema);
    responseSchema = operationProtobuf.findResponseSchema(300);
    Assert.assertNotNull(responseSchema);
    Assert.assertNotEquals(operationProtobuf.getResponseSchema(), responseSchema);
}
Also used : UnitTestMeta(org.apache.servicecomb.core.unittest.UnitTestMeta) SchemaMeta(org.apache.servicecomb.core.definition.SchemaMeta) OperationMeta(org.apache.servicecomb.core.definition.OperationMeta) ArgsNotWrapSchema(org.apache.servicecomb.codec.protobuf.utils.schema.ArgsNotWrapSchema) NormalWrapSchema(org.apache.servicecomb.codec.protobuf.utils.schema.NormalWrapSchema) WrapSchema(org.apache.servicecomb.codec.protobuf.utils.WrapSchema) Test(org.junit.Test)

Example 10 with SchemaMeta

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

the class HighwayServerInvoke method doInit.

private void doInit(TcpConnection connection, long msgId, RequestHeader header, Buffer bodyBuffer) throws Exception {
    this.connection = connection;
    this.msgId = msgId;
    this.header = header;
    MicroserviceMeta microserviceMeta = microserviceMetaManager.ensureFindValue(header.getDestMicroservice());
    SchemaMeta schemaMeta = microserviceMeta.ensureFindSchemaMeta(header.getSchemaId());
    this.operationMeta = schemaMeta.ensureFindOperation(header.getOperationName());
    this.operationProtobuf = ProtobufManager.getOrCreateOperation(operationMeta);
    this.bodyBuffer = bodyBuffer;
}
Also used : SchemaMeta(org.apache.servicecomb.core.definition.SchemaMeta) MicroserviceMeta(org.apache.servicecomb.core.definition.MicroserviceMeta)

Aggregations

SchemaMeta (org.apache.servicecomb.core.definition.SchemaMeta)58 OperationMeta (org.apache.servicecomb.core.definition.OperationMeta)28 MicroserviceMeta (org.apache.servicecomb.core.definition.MicroserviceMeta)25 Test (org.junit.Test)24 Invocation (org.apache.servicecomb.core.Invocation)13 Swagger (io.swagger.models.Swagger)9 ArrayList (java.util.ArrayList)8 HashMap (java.util.HashMap)6 Executor (java.util.concurrent.Executor)5 InvocationRuntimeType (org.apache.servicecomb.core.definition.InvocationRuntimeType)5 ReferenceConfig (org.apache.servicecomb.core.provider.consumer.ReferenceConfig)5 MicroserviceInstance (org.apache.servicecomb.registry.api.registry.MicroserviceInstance)5 SwaggerProducerOperation (org.apache.servicecomb.swagger.engine.SwaggerProducerOperation)5 MockUp (mockit.MockUp)4 NonSwaggerInvocation (org.apache.servicecomb.core.NonSwaggerInvocation)4 Transport (org.apache.servicecomb.core.Transport)4 TransportManager (org.apache.servicecomb.core.transport.TransportManager)4 InstanceCacheManager (org.apache.servicecomb.registry.cache.InstanceCacheManager)4 DiscoveryTreeNode (org.apache.servicecomb.registry.discovery.DiscoveryTreeNode)4 ServiceRegistry (org.apache.servicecomb.serviceregistry.ServiceRegistry)4