Search in sources :

Example 1 with MicroserviceReferenceConfig

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);
}
Also used : ConsumerMicroserviceVersionsMeta(org.apache.servicecomb.core.definition.ConsumerMicroserviceVersionsMeta) MicroserviceReferenceConfig(org.apache.servicecomb.core.provider.consumer.MicroserviceReferenceConfig) MicroserviceVersions(org.apache.servicecomb.registry.consumer.MicroserviceVersions)

Example 2 with MicroserviceReferenceConfig

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);
}
Also used : MicroserviceReferenceConfig(org.apache.servicecomb.core.provider.consumer.MicroserviceReferenceConfig) SwaggerConsumer(org.apache.servicecomb.swagger.engine.SwaggerConsumer) SchemaMeta(org.apache.servicecomb.core.definition.SchemaMeta) MicroserviceMeta(org.apache.servicecomb.core.definition.MicroserviceMeta) PojoConsumerMeta(org.apache.servicecomb.provider.pojo.definition.PojoConsumerMeta)

Example 3 with MicroserviceReferenceConfig

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;
}
Also used : MicroserviceReferenceConfig(org.apache.servicecomb.core.provider.consumer.MicroserviceReferenceConfig) SchemaMeta(org.apache.servicecomb.core.definition.SchemaMeta) MicroserviceMeta(org.apache.servicecomb.core.definition.MicroserviceMeta)

Example 4 with MicroserviceReferenceConfig

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);
}
Also used : OperationLocator(org.apache.servicecomb.common.rest.locator.OperationLocator) MicroserviceReferenceConfig(org.apache.servicecomb.core.provider.consumer.MicroserviceReferenceConfig) RestOperationMeta(org.apache.servicecomb.common.rest.definition.RestOperationMeta) ReferenceConfig(org.apache.servicecomb.core.provider.consumer.ReferenceConfig) MicroserviceReferenceConfig(org.apache.servicecomb.core.provider.consumer.MicroserviceReferenceConfig) MicroserviceMeta(org.apache.servicecomb.core.definition.MicroserviceMeta) OperationMeta(org.apache.servicecomb.core.definition.OperationMeta) RestOperationMeta(org.apache.servicecomb.common.rest.definition.RestOperationMeta) ServicePathManager(org.apache.servicecomb.common.rest.locator.ServicePathManager)

Example 5 with MicroserviceReferenceConfig

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());
}
Also used : MicroserviceVersionRule(org.apache.servicecomb.registry.consumer.MicroserviceVersionRule) MicroserviceReferenceConfig(org.apache.servicecomb.core.provider.consumer.MicroserviceReferenceConfig) SchemaMeta(org.apache.servicecomb.core.definition.SchemaMeta) MicroserviceMeta(org.apache.servicecomb.core.definition.MicroserviceMeta) MicroserviceInstance(org.apache.servicecomb.registry.api.registry.MicroserviceInstance) URIEndpointObject(org.apache.servicecomb.foundation.common.net.URIEndpointObject)

Aggregations

MicroserviceReferenceConfig (org.apache.servicecomb.core.provider.consumer.MicroserviceReferenceConfig)5 MicroserviceMeta (org.apache.servicecomb.core.definition.MicroserviceMeta)4 SchemaMeta (org.apache.servicecomb.core.definition.SchemaMeta)3 RestOperationMeta (org.apache.servicecomb.common.rest.definition.RestOperationMeta)1 OperationLocator (org.apache.servicecomb.common.rest.locator.OperationLocator)1 ServicePathManager (org.apache.servicecomb.common.rest.locator.ServicePathManager)1 ConsumerMicroserviceVersionsMeta (org.apache.servicecomb.core.definition.ConsumerMicroserviceVersionsMeta)1 OperationMeta (org.apache.servicecomb.core.definition.OperationMeta)1 ReferenceConfig (org.apache.servicecomb.core.provider.consumer.ReferenceConfig)1 URIEndpointObject (org.apache.servicecomb.foundation.common.net.URIEndpointObject)1 PojoConsumerMeta (org.apache.servicecomb.provider.pojo.definition.PojoConsumerMeta)1 MicroserviceInstance (org.apache.servicecomb.registry.api.registry.MicroserviceInstance)1 MicroserviceVersionRule (org.apache.servicecomb.registry.consumer.MicroserviceVersionRule)1 MicroserviceVersions (org.apache.servicecomb.registry.consumer.MicroserviceVersions)1 SwaggerConsumer (org.apache.servicecomb.swagger.engine.SwaggerConsumer)1