use of org.apache.servicecomb.common.rest.locator.ServicePathManager 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.common.rest.locator.ServicePathManager 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.common.rest.locator.ServicePathManager in project incubator-servicecomb-java-chassis by apache.
the class RestEngineSchemaListener method findPathManager.
protected ServicePathManager findPathManager(Map<String, ServicePathManager> mgrMap, MicroserviceMeta microserviceMeta) {
ServicePathManager mgr = mgrMap.get(microserviceMeta.getName());
if (mgr != null) {
return mgr;
}
mgr = ServicePathManager.getServicePathManager(microserviceMeta);
if (mgr == null) {
mgr = new ServicePathManager(microserviceMeta);
} else {
mgr = mgr.cloneServicePathManager();
}
mgrMap.put(microserviceMeta.getName(), mgr);
return mgr;
}
use of org.apache.servicecomb.common.rest.locator.ServicePathManager in project incubator-servicecomb-java-chassis by apache.
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 org.apache.servicecomb.common.rest.locator.ServicePathManager in project incubator-servicecomb-java-chassis by apache.
the class CseClientHttpRequest method createRequestMeta.
private RequestMeta createRequestMeta(String httpMetod, URI uri) {
String microserviceName = uri.getAuthority();
ReferenceConfig referenceConfig = ReferenceConfigUtils.getForInvoke(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.consumerLocateOperation(path, httpMetod);
RestOperationMeta swaggerRestOperation = locator.getOperation();
Map<String, String> pathParams = locator.getPathVarMap();
return new RequestMeta(referenceConfig, swaggerRestOperation, pathParams);
}
Aggregations