use of org.apache.servicecomb.core.provider.consumer.MicroserviceReferenceConfig in project java-chassis by ServiceComb.
the class SCBEngine method createMicroserviceReferenceConfig.
/**
* for edge, versionRule maybe controlled by url rule
* @param microserviceName hortName, or appId:shortName when invoke cross app
* @param versionRule if is empty, then use configuration value
* @return
*/
public MicroserviceReferenceConfig createMicroserviceReferenceConfig(String microserviceName, String versionRule) {
ensureStatusUp();
MicroserviceVersions microserviceVersions = DiscoveryManager.INSTANCE.getOrCreateMicroserviceVersions(parseAppId(microserviceName), microserviceName);
ConsumerMicroserviceVersionsMeta microserviceVersionsMeta = CoreMetaUtils.getMicroserviceVersionsMeta(microserviceVersions);
return new MicroserviceReferenceConfig(microserviceVersionsMeta, versionRule);
}
use of org.apache.servicecomb.core.provider.consumer.MicroserviceReferenceConfig in project java-chassis by ServiceComb.
the class PojoConsumerMetaRefresher method refreshMeta.
protected PojoConsumerMeta refreshMeta() {
MicroserviceReferenceConfig microserviceReferenceConfig = scbEngine.createMicroserviceReferenceConfig(microserviceName);
MicroserviceMeta microserviceMeta = microserviceReferenceConfig.getLatestMicroserviceMeta();
SchemaMeta schemaMeta = findSchemaMeta(microserviceMeta);
if (schemaMeta == null) {
throw new IllegalStateException(String.format("Schema not exist, microserviceName=%s, schemaId=%s, consumer interface=%s; " + "new producer not running or not deployed.", microserviceName, schemaId, consumerIntf.getName()));
}
SwaggerConsumer swaggerConsumer = scbEngine.getSwaggerEnvironment().createConsumer(consumerIntf, schemaMeta.getSwagger());
return new PojoConsumerMeta(microserviceReferenceConfig, swaggerConsumer, schemaMeta);
}
use of org.apache.servicecomb.core.provider.consumer.MicroserviceReferenceConfig in project java-chassis by ServiceComb.
the class ITSCBRestTemplate method init.
public ITSCBRestTemplate init() {
String producerName = ITJUnitUtils.getProducerName();
MicroserviceReferenceConfig microserviceReferenceConfig = SCBEngine.getInstance().createMicroserviceReferenceConfig(producerName);
MicroserviceMeta microserviceMeta = microserviceReferenceConfig.getLatestMicroserviceMeta();
SchemaMeta schemaMeta = microserviceMeta.ensureFindSchemaMeta(schemaId);
basePath = schemaMeta.getSwagger().getBasePath();
urlPrefix = String.format("cse://%s%s", producerName, basePath);
instance = DiscoveryManager.INSTANCE.getAppManager().getOrCreateMicroserviceManager(RegistrationManager.INSTANCE.getMicroservice().getAppId()).getOrCreateMicroserviceVersions(producerName).getPulledInstances().get(0);
setUriTemplateHandler(new ITUriTemplateHandler(urlPrefix));
setRequestFactory(new ITClientHttpRequestFactory());
return this;
}
use of org.apache.servicecomb.core.provider.consumer.MicroserviceReferenceConfig in project java-chassis by ServiceComb.
the class CseClientHttpRequest method createRequestMeta.
protected RequestMeta createRequestMeta(String httpMethod, URI uri) {
String microserviceName = uri.getAuthority();
MicroserviceReferenceConfig microserviceReferenceConfig = SCBEngine.getInstance().createMicroserviceReferenceConfig(microserviceName);
MicroserviceMeta microserviceMeta = microserviceReferenceConfig.getLatestMicroserviceMeta();
ServicePathManager servicePathManager = ServicePathManager.getServicePathManager(microserviceMeta);
if (servicePathManager == null) {
throw new Error(String.format("no schema defined for %s:%s", microserviceMeta.getAppId(), microserviceMeta.getMicroserviceName()));
}
OperationLocator locator = servicePathManager.consumerLocateOperation(path, httpMethod);
RestOperationMeta swaggerRestOperation = locator.getOperation();
OperationMeta operationMeta = locator.getOperation().getOperationMeta();
ReferenceConfig referenceConfig = microserviceReferenceConfig.createReferenceConfig(operationMeta);
Map<String, String> pathParams = locator.getPathVarMap();
return new RequestMeta(referenceConfig, swaggerRestOperation, pathParams);
}
use of org.apache.servicecomb.core.provider.consumer.MicroserviceReferenceConfig in project java-chassis by ServiceComb.
the class GateRestTemplate method getUrlPrefix.
private String getUrlPrefix(String gateName, String producerName, String schemaId) {
MicroserviceVersionRule microserviceVersionRule = DiscoveryManager.INSTANCE.getAppManager().getOrCreateMicroserviceVersionRule(RegistrationManager.INSTANCE.getMicroservice().getAppId(), gateName, DefinitionConst.VERSION_RULE_ALL);
MicroserviceInstance microserviceInstance = microserviceVersionRule.getInstances().values().stream().findFirst().get();
URIEndpointObject edgeAddress = new URIEndpointObject(microserviceInstance.getEndpoints().get(0));
String urlSchema = "http";
if (edgeAddress.isSslEnabled()) {
urlSchema = "https";
}
MicroserviceReferenceConfig microserviceReferenceConfig = SCBEngine.getInstance().createMicroserviceReferenceConfig(producerName);
MicroserviceMeta microserviceMeta = microserviceReferenceConfig.getLatestMicroserviceMeta();
SchemaMeta schemaMeta = microserviceMeta.ensureFindSchemaMeta(schemaId);
return String.format("%s://%s:%d/rest/%s%s", urlSchema, edgeAddress.getHostOrIp(), edgeAddress.getPort(), producerName, schemaMeta.getSwagger().getBasePath());
}
Aggregations