use of io.servicecomb.serviceregistry.api.registry.Microservice in project java-chassis by ServiceComb.
the class SchemaLoader method putSelfBasePathIfAbsent.
public void putSelfBasePathIfAbsent(String microserviceName, String basePath) {
if (basePath == null || basePath.length() == 0) {
return;
}
Microservice microservice = RegistryUtils.getMicroservice();
if (!microservice.getServiceName().equals(microserviceName)) {
return;
}
List<BasePath> paths = microservice.getPaths();
for (BasePath path : paths) {
if (path.getPath().equals(basePath)) {
return;
}
}
BasePath basePathObj = new BasePath();
basePathObj.setPath(basePath);
paths.add(basePathObj);
}
use of io.servicecomb.serviceregistry.api.registry.Microservice 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;
}
}
use of io.servicecomb.serviceregistry.api.registry.Microservice in project java-chassis by ServiceComb.
the class TestDynamicSchemaLoader method init.
@BeforeClass
public static void init() {
UnitTestMeta.init();
SchemaLoader loader = new SchemaLoader();
loader.setMicroserviceMetaManager(microserviceMetaManager);
SchemaListenerManager schemaListenerManager = new SchemaListenerManager();
schemaListenerManager.setSchemaListenerList(Collections.emptyList());
CseContext context = CseContext.getInstance();
context.setSchemaLoader(loader);
context.setSchemaListenerManager(schemaListenerManager);
Microservice microservice = new Microservice();
microservice.setAppId("app");
microservice.setServiceName("ms");
ReflectUtils.setField(RegistryUtils.class, null, "microservice", microservice);
}
use of io.servicecomb.serviceregistry.api.registry.Microservice in project java-chassis by ServiceComb.
the class TestDefinition method setupClass.
@BeforeClass
public static void setupClass() throws Exception {
Microservice microservice = new Microservice();
microservice.setAppId("app");
microservice.setServiceName("testname");
new MockUp<RegistryUtils>() {
@Mock
private Microservice createMicroserviceFromDefinition() {
return microservice;
}
};
}
use of io.servicecomb.serviceregistry.api.registry.Microservice in project java-chassis by ServiceComb.
the class TestConsumerSchemaFactory method init.
@BeforeClass
public static void init() {
ReflectUtils.setField(RegistryClientFactory.class, null, "registryClient", registryClient);
SchemaListenerManager schemaListenerManager = new SchemaListenerManager();
schemaListenerManager.setSchemaListenerList(Arrays.asList(schemaListener));
ConsumerResponseMapperFactory responseMapperFactory = new ConsumerResponseMapperFactory();
responseMapperFactory.setMapperList(Arrays.asList(new ConsumerResponseSame()));
ConsumerArgumentsMapperFactory consumerArgsMapperFactory = new ConsumerArgumentsMapperFactory();
MicroserviceMetaManager microserviceMetaManager = new MicroserviceMetaManager();
SchemaLoader schemaLoader = new SchemaLoader();
CompositeSwaggerGeneratorContext compositeSwaggerGeneratorContext = new CompositeSwaggerGeneratorContext();
ReflectUtils.setField(consumerSchemaFactory, "schemaListenerManager", schemaListenerManager);
ReflectUtils.setField(consumerSchemaFactory, "consumerArgsMapperFactory", consumerArgsMapperFactory);
ReflectUtils.setField(consumerSchemaFactory, "responseMapperFactory", responseMapperFactory);
ReflectUtils.setField(consumerSchemaFactory, "microserviceMetaManager", microserviceMetaManager);
ReflectUtils.setField(consumerSchemaFactory, "schemaLoader", schemaLoader);
ReflectUtils.setField(consumerSchemaFactory, "compositeSwaggerGeneratorContext", compositeSwaggerGeneratorContext);
SchemaMeta schemaMeta = new UnitTestMeta().getOrCreateSchemaMeta(TestConsumerSchemaFactoryImpl.class);
String content = UnitTestSwaggerUtils.pretty(schemaMeta.getSwagger());
Mockito.when(registryClient.getMicroserviceId("app", "ms", "latest")).thenReturn("0");
Mockito.when(registryClient.getSchema("0", "schema")).thenReturn(content);
Microservice microservice = new Microservice();
microservice.setAppId("app");
microservice.setServiceId("0");
microservice.addSchema("schema", content);
Mockito.when(registryClient.getMicroservice("0")).thenReturn(microservice);
}
Aggregations