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());
}
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();
}
}
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);
}
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);
}
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;
}
Aggregations