@Nullable @Override public String method(@Nonnull Invocation invocation) { return invocation.getOperationMeta().getHttpMethod(); }
@Nullable @Override public String method(@Nonnull Invocation invocation) { return invocation.getOperationMeta().getHttpMethod(); }
@Nullable @Override public String path(@Nonnull Invocation request) { return request.getOperationMeta().getOperationPath(); }
public QpsController getOrCreate(String microserviceName, Invocation invocation) { return qualifiedNameControllerMap .computeIfAbsent(microserviceName + SEPARATOR + invocation.getOperationMeta().getSchemaQualifiedName(), key -> { return create(key, microserviceName, invocation); }); }
@Nullable @Override public String path(@Nonnull Invocation request) { return request.getOperationMeta().getOperationPath(); }
@Override public TcpOutputStream createStream() { try { return HighwayCodec.encodeRequest(msgId, invocation, operationProtobuf); } catch (Exception e) { String msg = String.format("encode request failed. appid=%s, qualifiedName=%s", invocation.getAppId(), invocation.getOperationMeta().getMicroserviceQualifiedName()); throw new Error(msg, e); } } }
public static HystrixCommandGroupKey toHystrixCommandGroupKey(String type, Invocation invocation) { return CustomizeCommandGroupKey.asKey(type + "." + invocation.getOperationMeta().getMicroserviceQualifiedName(), invocation); }
private static FallbackPolicy getPolicy(String type, Invocation invocation) { String policyKey = Configuration.INSTANCE.getFallbackPolicyPolicy(type, invocation.getMicroserviceName(), invocation.getOperationMeta().getMicroserviceQualifiedName()); FallbackPolicy policy = null; if (policyKey != null) { policy = POLICIES.get(policyKey.toLowerCase()); } return policy; } }
public static HystrixCommandKey toHystrixCommandKey(String type, Invocation invocation) { return HystrixCommandKey.Factory .asKey(type + "." + invocation.getOperationMeta().getMicroserviceQualifiedName()); } }
public InvocationToHttpServletRequest(Invocation invocation) { this.swaggerOperation = invocation.getOperationMeta().getExtData(RestConst.SWAGGER_REST_OPERATION); this.args = invocation.getArgs(); this.sockerAddress = (SocketAddress) invocation.getHandlerContext().get(Const.REMOTE_ADDRESS); }
@Override public Response afterReceiveRequest(Invocation invocation, HttpServletRequestEx requestEx) { OperationMeta operationMeta = invocation.getOperationMeta(); RestOperationMeta restOperationMeta = operationMeta.getExtData(RestConst.SWAGGER_REST_OPERATION); Object[] args = RestCodec.restToArgs(requestEx, restOperationMeta); invocation.setSwaggerArguments(args); return null; }
private HttpMethod getMethod() { OperationMeta operationMeta = invocation.getOperationMeta(); RestOperationMeta swaggerRestOperation = operationMeta.getExtData(RestConst.SWAGGER_REST_OPERATION); String method = swaggerRestOperation.getHttpMethod(); return HttpMethod.valueOf(method); }
public String getInvocationQualifiedName() { return invocationType.name() + " " + getRealTransportName() + " " + getOperationMeta().getMicroserviceQualifiedName(); }
@Override public Response getFallbackResponse(Invocation invocation) { return Response.failResp(invocation.getInvocationType(), BizkeeperExceptionUtils .createBizkeeperException(BizkeeperExceptionUtils.SERVICECOMB_BIZKEEPER_FALLBACK, null, invocation.getOperationMeta().getMicroserviceQualifiedName())); } }
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 -> new HashMap<>()); versionInstances.put(instance.getInstanceId(), instance); } return versionMap; } }
protected HystrixObservable<Response> createBizkeeperCommand(Invocation invocation) { if (Configuration.INSTANCE.isFallbackForce(handler.groupname, invocation.getMicroserviceName(), invocation.getOperationMeta().getMicroserviceQualifiedName())) { return forceFallbackCommand(invocation); } return handler.createBizkeeperCommand(invocation); }
@Override public void beforeSendRequest(Invocation invocation, HttpServletRequestEx requestEx) { RestClientRequestImpl restClientRequest = (RestClientRequestImpl) invocation.getHandlerContext() .get(RestConst.INVOCATION_HANDLER_REQUESTCLIENT); OperationMeta operationMeta = invocation.getOperationMeta(); RestOperationMeta swaggerRestOperation = operationMeta.getExtData(RestConst.SWAGGER_REST_OPERATION); try { RestCodec.argsToRest(invocation.getArgs(), swaggerRestOperation, restClientRequest); requestEx.setBodyBuffer(restClientRequest.getBodyBuffer()); } catch (Throwable e) { throw ExceptionFactory.convertConsumerException(e); } }
public static Response getFallbackResponse(String type, Throwable error, Invocation invocation) { FallbackPolicy policy = getPolicy(type, invocation); if (policy != null) { return policy.getFallbackResponse(invocation); } else { return Response.failResp(invocation.getInvocationType(), BizkeeperExceptionUtils .createBizkeeperException(BizkeeperExceptionUtils.SERVICECOMB_BIZKEEPER_FALLBACK, error, invocation.getOperationMeta().getMicroserviceQualifiedName())); } }
protected void handleResponse(HttpClientResponse httpClientResponse) { this.clientResponse = httpClientResponse; if (HttpStatus.isSuccess(clientResponse.statusCode()) && Part.class.equals(invocation.getOperationMeta().getMethod().getReturnType())) { ReadStreamPart part = new ReadStreamPart(httpClientWithContext.context(), httpClientResponse); invocation.getHandlerContext().put(RestConst.READ_STREAM_PART, part); processResponseBody(null); return; } httpClientResponse.exceptionHandler(e -> { LOGGER.error("Failed to receive response from {}.", httpClientResponse.netSocket().remoteAddress(), e); fail(e); }); clientResponse.bodyHandler(responseBuf -> { processResponseBody(responseBuf); }); }
@Override public void handle(Invocation invocation, AsyncResponse asyncResp) throws Exception { SwaggerProducerOperation producerOperation = invocation.getOperationMeta().getExtData(Const.PRODUCER_OPERATION); if (producerOperation == null) { asyncResp.producerFail( ExceptionUtils.producerOperationNotExist(invocation.getSchemaId(), invocation.getOperationName())); return; } producerOperation.invoke(invocation, asyncResp); } }