Search in sources :

Example 11 with OperationMeta

use of org.apache.servicecomb.core.definition.OperationMeta in project incubator-servicecomb-java-chassis by apache.

the class TestHighwayTransport method commonHighwayMock.

private void commonHighwayMock(Invocation invocation) {
    OperationMeta operationMeta = Mockito.mock(OperationMeta.class);
    Mockito.when(invocation.getOperationMeta()).thenReturn(operationMeta);
    OperationProtobuf operationProtobuf = Mockito.mock(OperationProtobuf.class);
    Mockito.when(operationMeta.getExtData("protobuf")).thenReturn(operationProtobuf);
    Endpoint lEndpoint = Mockito.mock(Endpoint.class);
    Mockito.when(invocation.getEndpoint()).thenReturn(lEndpoint);
    WrapSchema lWrapSchema = Mockito.mock(WrapSchema.class);
    Mockito.when(operationProtobuf.getRequestSchema()).thenReturn(lWrapSchema);
    URIEndpointObject ep = Mockito.mock(URIEndpointObject.class);
    Mockito.when(lEndpoint.getAddress()).thenReturn(ep);
    Mockito.when(ep.getHostOrIp()).thenReturn("127.0.0.1");
    Mockito.when(ep.getPort()).thenReturn(80);
}
Also used : Endpoint(org.apache.servicecomb.core.Endpoint) OperationProtobuf(org.apache.servicecomb.codec.protobuf.definition.OperationProtobuf) OperationMeta(org.apache.servicecomb.core.definition.OperationMeta) WrapSchema(org.apache.servicecomb.codec.protobuf.utils.WrapSchema) URIEndpointObject(org.apache.servicecomb.foundation.common.net.URIEndpointObject)

Example 12 with OperationMeta

use of org.apache.servicecomb.core.definition.OperationMeta in project incubator-servicecomb-java-chassis by apache.

the class OperationInstancesDiscoveryFilter method groupByVersion.

protected Map<MicroserviceVersionMeta, Map<String, MicroserviceInstance>> groupByVersion(Invocation invocation, Map<String, MicroserviceInstance> instances) {
    OperationMeta latestOperationMeta = invocation.getOperationMeta();
    MicroserviceMeta latestMicroserviceMeta = latestOperationMeta.getSchemaMeta().getMicroserviceMeta();
    AppManager appManager = RegistryUtils.getServiceRegistry().getAppManager();
    MicroserviceVersions MicroserviceVersions = appManager.getOrCreateMicroserviceVersions(latestMicroserviceMeta.getAppId(), latestMicroserviceMeta.getName());
    Map<MicroserviceVersionMeta, Map<String, MicroserviceInstance>> versionMap = new IdentityHashMap<>();
    for (MicroserviceInstance instance : instances.values()) {
        MicroserviceVersionMeta versionMeta = MicroserviceVersions.getVersion(instance.getServiceId());
        Map<String, MicroserviceInstance> versionInstances = versionMap.computeIfAbsent(versionMeta, vm -> {
            return new HashMap<>();
        });
        versionInstances.put(instance.getInstanceId(), instance);
    }
    return versionMap;
}
Also used : IdentityHashMap(java.util.IdentityHashMap) HashMap(java.util.HashMap) AppManager(org.apache.servicecomb.serviceregistry.consumer.AppManager) IdentityHashMap(java.util.IdentityHashMap) MicroserviceMeta(org.apache.servicecomb.core.definition.MicroserviceMeta) MicroserviceVersionMeta(org.apache.servicecomb.core.definition.MicroserviceVersionMeta) MicroserviceInstance(org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance) OperationMeta(org.apache.servicecomb.core.definition.OperationMeta) MicroserviceVersions(org.apache.servicecomb.serviceregistry.consumer.MicroserviceVersions) IdentityHashMap(java.util.IdentityHashMap) HashMap(java.util.HashMap) Map(java.util.Map)

Example 13 with OperationMeta

use of org.apache.servicecomb.core.definition.OperationMeta in project incubator-servicecomb-java-chassis by apache.

the class MockUtil method mockAbstractServiceProvider.

public void mockAbstractServiceProvider() {
    new MockUp<AbstractProducerProvider>() {

        @SuppressWarnings("unchecked")
        @Mock
        protected <T> T findProviderSchema(OperationMeta operationMeta) {
            PojoProducerMeta lPojoSchemaMeta = Mockito.mock(PojoProducerMeta.class);
            Mockito.when(lPojoSchemaMeta.getInstance()).thenReturn(lPojoSchemaMeta);
            return (T) lPojoSchemaMeta;
        }
    };
}
Also used : PojoProducerMeta(org.apache.servicecomb.provider.pojo.schema.PojoProducerMeta) MockUp(mockit.MockUp) OperationMeta(org.apache.servicecomb.core.definition.OperationMeta)

Example 14 with OperationMeta

use of org.apache.servicecomb.core.definition.OperationMeta in project incubator-servicecomb-java-chassis by apache.

the class VertxHttpMethod method getMethod.

private HttpMethod getMethod(Invocation invocation) {
    OperationMeta operationMeta = invocation.getOperationMeta();
    RestOperationMeta swaggerRestOperation = operationMeta.getExtData(RestConst.SWAGGER_REST_OPERATION);
    String method = swaggerRestOperation.getHttpMethod();
    return HttpMethod.valueOf(method);
}
Also used : RestOperationMeta(org.apache.servicecomb.common.rest.definition.RestOperationMeta) OperationMeta(org.apache.servicecomb.core.definition.OperationMeta) RestOperationMeta(org.apache.servicecomb.common.rest.definition.RestOperationMeta)

Example 15 with OperationMeta

use of org.apache.servicecomb.core.definition.OperationMeta in project incubator-servicecomb-java-chassis by apache.

the class VertxHttpMethod method doMethod.

public void doMethod(HttpClientWithContext httpClientWithContext, Invocation invocation, AsyncResponse asyncResp) throws Exception {
    OperationMeta operationMeta = invocation.getOperationMeta();
    RestOperationMeta swaggerRestOperation = operationMeta.getExtData(RestConst.SWAGGER_REST_OPERATION);
    String path = this.createRequestPath(invocation, swaggerRestOperation);
    IpPort ipPort = (IpPort) invocation.getEndpoint().getAddress();
    HttpClientRequest clientRequest = this.createRequest(httpClientWithContext.getHttpClient(), invocation, ipPort, path, asyncResp);
    clientRequest.putHeader(org.apache.servicecomb.core.Const.TARGET_MICROSERVICE, invocation.getMicroserviceName());
    RestClientRequestImpl restClientRequest = new RestClientRequestImpl(clientRequest, httpClientWithContext.context().owner(), asyncResp);
    invocation.getHandlerContext().put(RestConst.INVOCATION_HANDLER_REQUESTCLIENT, restClientRequest);
    Buffer requestBodyBuffer = restClientRequest.getBodyBuffer();
    HttpServletRequestEx requestEx = new VertxClientRequestToHttpServletRequest(clientRequest, requestBodyBuffer);
    for (HttpClientFilter filter : httpClientFilters) {
        filter.beforeSendRequest(invocation, requestEx);
    }
    clientRequest.exceptionHandler(e -> {
        LOGGER.error(e.toString());
        asyncResp.fail(invocation.getInvocationType(), e);
    });
    // 从业务线程转移到网络线程中去发送
    httpClientWithContext.runOnContext(httpClient -> {
        this.setCseContext(invocation, clientRequest);
        clientRequest.setTimeout(AbstractTransport.getRequestTimeoutProperty().get());
        try {
            restClientRequest.end();
        } catch (Throwable e) {
            LOGGER.error("send http request failed,", e);
            asyncResp.fail(invocation.getInvocationType(), e);
        }
    });
}
Also used : Buffer(io.vertx.core.buffer.Buffer) HttpClientRequest(io.vertx.core.http.HttpClientRequest) HttpClientFilter(org.apache.servicecomb.common.rest.filter.HttpClientFilter) RestOperationMeta(org.apache.servicecomb.common.rest.definition.RestOperationMeta) RestClientRequestImpl(org.apache.servicecomb.common.rest.codec.param.RestClientRequestImpl) VertxClientRequestToHttpServletRequest(org.apache.servicecomb.foundation.vertx.http.VertxClientRequestToHttpServletRequest) IpPort(org.apache.servicecomb.foundation.common.net.IpPort) OperationMeta(org.apache.servicecomb.core.definition.OperationMeta) RestOperationMeta(org.apache.servicecomb.common.rest.definition.RestOperationMeta) HttpServletRequestEx(org.apache.servicecomb.foundation.vertx.http.HttpServletRequestEx)

Aggregations

OperationMeta (org.apache.servicecomb.core.definition.OperationMeta)33 Test (org.junit.Test)14 RestOperationMeta (org.apache.servicecomb.common.rest.definition.RestOperationMeta)12 Invocation (org.apache.servicecomb.core.Invocation)9 SchemaMeta (org.apache.servicecomb.core.definition.SchemaMeta)8 MockUp (mockit.MockUp)6 AsyncResponse (org.apache.servicecomb.swagger.invocation.AsyncResponse)6 Endpoint (org.apache.servicecomb.core.Endpoint)5 MicroserviceMeta (org.apache.servicecomb.core.definition.MicroserviceMeta)5 OperationProtobuf (org.apache.servicecomb.codec.protobuf.definition.OperationProtobuf)4 Response (org.apache.servicecomb.swagger.invocation.Response)4 HttpClientRequest (io.vertx.core.http.HttpClientRequest)3 Holder (javax.xml.ws.Holder)3 WrapSchema (org.apache.servicecomb.codec.protobuf.utils.WrapSchema)3 ProduceProcessor (org.apache.servicecomb.common.rest.codec.produce.ProduceProcessor)3 URLPathBuilder (org.apache.servicecomb.common.rest.definition.path.URLPathBuilder)3 ReactiveExecutor (org.apache.servicecomb.core.executor.ReactiveExecutor)3 URIEndpointObject (org.apache.servicecomb.foundation.common.net.URIEndpointObject)3 InvocationException (org.apache.servicecomb.swagger.invocation.exception.InvocationException)3 Buffer (io.vertx.core.buffer.Buffer)2