use of org.apache.servicecomb.registry.consumer.MicroserviceManager in project java-chassis by ServiceComb.
the class InstanceCacheChecker method check.
public InstanceCacheSummary check() {
instanceCacheSummary.setAppId(RegistryUtils.getMicroservice().getAppId());
instanceCacheSummary.setMicroserviceName(RegistryUtils.getMicroservice().getServiceName());
instanceCacheSummary.setTimestamp(clock.millis());
for (MicroserviceManager microserviceManager : appManager.getApps().values()) {
for (MicroserviceVersions microserviceVersions : microserviceManager.getVersionsByName().values()) {
if (microserviceVersions instanceof StaticMicroserviceVersions) {
continue;
}
InstanceCacheResult instanceCacheResult = check(microserviceVersions);
addInstanceCacheResult(instanceCacheResult);
}
}
generateStatus();
return instanceCacheSummary;
}
use of org.apache.servicecomb.registry.consumer.MicroserviceManager in project java-chassis by ServiceComb.
the class ITSCBAsyncRestTemplate method ensureProviderBasePath.
private void ensureProviderBasePath(String producerName) {
MicroserviceManager microserviceManager = DiscoveryManager.INSTANCE.getAppManager().getOrCreateMicroserviceManager(RegistrationManager.INSTANCE.getMicroservice().getAppId());
MicroserviceVersions producerMicroserviceVersions = microserviceManager.getOrCreateMicroserviceVersions(producerName);
Optional<MicroserviceVersion> latestMicroserviceVersion = producerMicroserviceVersions.getVersions().values().stream().max(Comparator.comparing(MicroserviceVersion::getVersion));
latestMicroserviceVersion.ifPresent(microserviceVersion -> {
MicroserviceMeta microserviceMeta = microserviceVersion.getVendorExtensions().get(CORE_MICROSERVICE_META);
SchemaMeta schemaMeta = microserviceMeta.ensureFindSchemaMeta(schemaId);
basePath = schemaMeta.getSwagger().getBasePath();
});
latestMicroserviceVersion.orElseThrow(() -> new IllegalStateException("cannot find producer: " + producerName));
}
use of org.apache.servicecomb.registry.consumer.MicroserviceManager in project java-chassis by ServiceComb.
the class RegistrationManager method registerMicroserviceMapping.
/**
* <p>
* Register a third party service if not registered before, and set it's instances into
* {@linkplain StaticMicroserviceVersions StaticMicroserviceVersions}.
* </p>
* <p>
* The registered third party service has the same {@code appId} and {@code environment} as this microservice instance has,
* and there is only one schema represented by {@code schemaIntfCls}, whose name is the same as {@code microserviceName}.
* </p>
* <em>
* This method is for initializing 3rd party service endpoint config.
* i.e. If this service has not been registered before, this service will be registered and the instances will be set;
* otherwise, NOTHING will happen.
* </em>
*
* @param microserviceName name of the 3rd party service, and this param also specifies the schemaId
* @param version version of this 3rd party service
* @param instances the instances of this 3rd party service. Users only need to specify the endpoint information, other
* necessary information will be generate and set in the implementation of this method.
* @param schemaIntfCls the producer interface of the service. This interface is used to generate swagger schema and
* can also be used for the proxy interface of RPC style invocation.
*/
public void registerMicroserviceMapping(String microserviceName, String version, List<MicroserviceInstance> instances, Class<?> schemaIntfCls) {
MicroserviceNameParser parser = new MicroserviceNameParser(getAppId(), microserviceName);
MicroserviceManager microserviceManager = DiscoveryManager.INSTANCE.getAppManager().getOrCreateMicroserviceManager(parser.getAppId());
microserviceManager.getVersionsByName().computeIfAbsent(microserviceName, svcName -> new StaticMicroserviceVersions(DiscoveryManager.INSTANCE.getAppManager(), parser.getAppId(), microserviceName).init(schemaIntfCls, version, instances));
}
Aggregations