Search in sources :

Example 6 with MicroserviceMeta

use of io.servicecomb.core.definition.MicroserviceMeta in project java-chassis by ServiceComb.

the class TestLocator method testLocateStatic.

@Test
public void testLocateStatic() {
    MicroserviceMeta msm = new MicroserviceMeta("app:ms");
    ServicePathManager spm = new ServicePathManager(msm);
    RestOperationMeta rom = createRestOperatonMeta("GET", "abc/");
    spm.addResource(rom);
    rom = createRestOperatonMeta("POST", "abc/");
    spm.addResource(rom);
    try {
        spm.addResource(rom);
    } catch (Throwable e) {
        Assert.assertEquals("operation with url abc/, method POST is duplicated", e.getMessage());
    }
    Assert.assertEquals(1, spm.getStaticPathOperationMap().size());
    Assert.assertEquals(2, spm.getStaticPathOperationMap().get("abc/").values().size());
    try {
        spm.locateOperation("abcd", "GET");
    } catch (InvocationException e) {
        Assert.assertEquals("Not Found", ((CommonExceptionData) e.getErrorData()).getMessage());
    }
    try {
        spm.locateOperation("abc/", "PUT");
    } catch (InvocationException e) {
        Assert.assertEquals("Method Not Allowed", ((CommonExceptionData) e.getErrorData()).getMessage());
    }
    OperationLocator locator = spm.locateOperation("abc/", "GET");
    Assert.assertEquals(Collections.emptyMap(), locator.getPathVarMap());
    locator.locate(spm, "abc/", "POST");
    Assert.assertEquals(Collections.emptyMap(), locator.getPathVarMap());
}
Also used : RestOperationMeta(io.servicecomb.common.rest.definition.RestOperationMeta) InvocationException(io.servicecomb.core.exception.InvocationException) MicroserviceMeta(io.servicecomb.core.definition.MicroserviceMeta) CommonExceptionData(io.servicecomb.core.exception.CommonExceptionData) Test(org.junit.Test)

Example 7 with MicroserviceMeta

use of io.servicecomb.core.definition.MicroserviceMeta in project java-chassis by ServiceComb.

the class SchemaListenerManager method notifySchemaListener.

public void notifySchemaListener(MicroserviceMeta... microserviceMetas) {
    List<SchemaMeta> schemaMetaList = new ArrayList<>();
    for (MicroserviceMeta microserviceMeta : microserviceMetas) {
        schemaMetaList.addAll(microserviceMeta.getSchemaMetas());
    }
    notifySchemaListener(schemaMetaList.toArray(new SchemaMeta[schemaMetaList.size()]));
}
Also used : SchemaMeta(io.servicecomb.core.definition.SchemaMeta) ArrayList(java.util.ArrayList) MicroserviceMeta(io.servicecomb.core.definition.MicroserviceMeta)

Example 8 with MicroserviceMeta

use of io.servicecomb.core.definition.MicroserviceMeta in project java-chassis by ServiceComb.

the class ProducerSchemaFactory method getOrCreateProducerSchema.

// 只会在启动流程中调用
public SchemaMeta getOrCreateProducerSchema(String microserviceName, String schemaId, Class<?> producerClass, Object producerInstance) {
    MicroserviceMeta microserviceMeta = microserviceMetaManager.getOrCreateMicroserviceMeta(microserviceName);
    ProducerSchemaContext context = new ProducerSchemaContext();
    context.setMicroserviceMeta(microserviceMeta);
    context.setSchemaId(schemaId);
    context.setProviderClass(producerClass);
    context.setProducerInstance(producerInstance);
    return getOrCreateSchema(context);
}
Also used : MicroserviceMeta(io.servicecomb.core.definition.MicroserviceMeta)

Example 9 with MicroserviceMeta

use of io.servicecomb.core.definition.MicroserviceMeta in project java-chassis by ServiceComb.

the class AbstractSchemaFactory method getOrCreateSchema.

// 因为aop的存在,schemaInstance的class不一定等于schemaClass
protected SchemaMeta getOrCreateSchema(CONTEXT context) {
    MicroserviceMeta microserviceMeta = context.getMicroserviceMeta();
    SchemaMeta schemaMeta = microserviceMeta.findSchemaMeta(context.getSchemaId());
    if (schemaMeta == null) {
        schemaMeta = createSchema(context);
    }
    context.setSchemaMeta(schemaMeta);
    connectToProvider(context);
    return schemaMeta;
}
Also used : SchemaMeta(io.servicecomb.core.definition.SchemaMeta) MicroserviceMeta(io.servicecomb.core.definition.MicroserviceMeta)

Example 10 with MicroserviceMeta

use of io.servicecomb.core.definition.MicroserviceMeta in project java-chassis by ServiceComb.

the class AbstractRestServer method findRestOperation.

protected RestOperationMeta findRestOperation(RestServerRequestInternal restRequest) {
    String selfName = RegistryUtils.getMicroservice().getServiceName();
    MicroserviceMeta selfMicroserviceMeta = CseContext.getInstance().getMicroserviceMetaManager().ensureFindValue(selfName);
    ServicePathManager servicePathManager = ServicePathManager.getServicePathManager(selfMicroserviceMeta);
    if (servicePathManager == null) {
        LOGGER.error("No schema in microservice");
        throw new InvocationException(Status.NOT_FOUND, Status.NOT_FOUND.getReasonPhrase());
    }
    OperationLocator locator = servicePathManager.locateOperation(restRequest.getPath(), restRequest.getMethod());
    restRequest.setPathParamMap(locator.getPathVarMap());
    return locator.getOperation();
}
Also used : OperationLocator(io.servicecomb.common.rest.locator.OperationLocator) InvocationException(io.servicecomb.core.exception.InvocationException) MicroserviceMeta(io.servicecomb.core.definition.MicroserviceMeta) ServicePathManager(io.servicecomb.common.rest.locator.ServicePathManager)

Aggregations

MicroserviceMeta (io.servicecomb.core.definition.MicroserviceMeta)24 SchemaMeta (io.servicecomb.core.definition.SchemaMeta)11 Test (org.junit.Test)8 RestOperationMeta (io.servicecomb.common.rest.definition.RestOperationMeta)6 ServicePathManager (io.servicecomb.common.rest.locator.ServicePathManager)5 OperationMeta (io.servicecomb.core.definition.OperationMeta)4 InvocationException (io.servicecomb.core.exception.InvocationException)3 ConsumerOperationMeta (io.servicecomb.core.provider.consumer.ConsumerOperationMeta)3 HashMap (java.util.HashMap)3 OperationLocator (io.servicecomb.common.rest.locator.OperationLocator)2 CommonExceptionData (io.servicecomb.core.exception.CommonExceptionData)2 Swagger (io.swagger.models.Swagger)2 ArrayList (java.util.ArrayList)2 Invocation (io.servicecomb.core.Invocation)1 ProducerProvider (io.servicecomb.core.ProducerProvider)1 ConsumerSchemaFactory (io.servicecomb.core.definition.schema.ConsumerSchemaFactory)1 ReferenceConfig (io.servicecomb.core.provider.consumer.ReferenceConfig)1 Microservice (io.servicecomb.serviceregistry.api.registry.Microservice)1 SwaggerGenerator (io.servicecomb.swagger.generator.core.SwaggerGenerator)1 Mock (mockit.Mock)1