@Override public void clientError(Response<?> response) { System.out.println("CLIENT ERROR " + response.code() + " " + response.message()); }
@Override public void serverError(Response<?> response) { System.out.println("SERVER ERROR " + response.code() + " " + response.message()); }
public HttpException(Response<?> response) { super(getMessage(response)); this.code = response.code(); this.message = response.message(); this.response = response; }
private static String getMessage(Response<?> response) { checkNotNull(response, "response == null"); return "HTTP " + response.code() + " " + response.message(); }
@POST @Timed @ApiOperation(value = "Resume message processing on node") @Path("resume") @NoAuditEvent("proxy resource, audit event will be emitted on target node") public void resume(@ApiParam(name = "nodeId", value = "The id of the node where processing will be resumed.", required = true) @PathParam("nodeId") String nodeId) throws IOException, NodeNotFoundException { final Response response = this.getRemoteSystemProcessingResource(nodeId).resume().execute(); if (!response.isSuccessful()) { LOG.warn("Unable to resume message processing on node {}: {}", nodeId, response.message()); throw new WebApplicationException(response.message(), BAD_GATEWAY); } } }
@POST @Timed @ApiOperation(value = "Pause message processing on node", notes = "If the message journal is enabled, incoming messages will be spooled on disk, if it is disabled, " + "you might lose messages from inputs which cannot buffer themselves, like AMQP or Kafka-based inputs.") @Path("pause") @NoAuditEvent("proxy resource, audit event will be emitted on target node") public void pause(@ApiParam(name = "nodeId", value = "The id of the node where processing will be paused.", required = true) @PathParam("nodeId") String nodeId) throws IOException, NodeNotFoundException { final Response response = this.getRemoteSystemProcessingResource(nodeId).pause().execute(); if (!response.isSuccessful()) { LOG.warn("Unable to pause message processing on node {}: {}", nodeId, response.message()); throw new WebApplicationException(response.message(), BAD_GATEWAY); } }
@GET @Timed @Path("/namespace/{namespace}") @ApiOperation(value = "Get all metrics of a namespace from node") @ApiResponses(value = { @ApiResponse(code = 404, message = "No such metric namespace") }) public MetricsSummaryResponse byNamespace(@ApiParam(name = "nodeId", value = "The id of the node whose metrics we want.", required = true) @PathParam("nodeId") String nodeId, @ApiParam(name = "namespace", required = true) @PathParam("namespace") String namespace) throws IOException, NodeNotFoundException { final Response<MetricsSummaryResponse> result = getResourceForNode(nodeId).byNamespace(namespace).execute(); if (result.isSuccessful()) { return result.body(); } else { throw new WebApplicationException(result.message(), BAD_GATEWAY); } } }
@GET @Timed @ApiOperation(value = "Get JVM information of the given node") @Path("{nodeId}/jvm") public SystemJVMResponse jvm(@ApiParam(name = "nodeId", value = "The id of the node where processing will be paused.", required = true) @PathParam("nodeId") String nodeId) throws IOException, NodeNotFoundException { final Node targetNode = nodeService.byNodeId(nodeId); final RemoteSystemResource remoteSystemResource = remoteInterfaceProvider.get(targetNode, this.authenticationToken, RemoteSystemResource.class); final Response<SystemJVMResponse> response = remoteSystemResource.jvm().execute(); if (response.isSuccessful()) { return response.body(); } else { LOG.warn("Unable to get jvm information on node {}: {}", nodeId, response.message()); throw new WebApplicationException(response.message(), BAD_GATEWAY); } }
@GET @Timed @ApiOperation(value = "List all installed plugins on the given node") public PluginList list(@ApiParam(name = "nodeId", value = "The id of the node where processing will be paused.", required = true) @PathParam("nodeId") String nodeId) throws IOException, NodeNotFoundException { final Node targetNode = nodeService.byNodeId(nodeId); final RemoteSystemPluginResource remoteSystemPluginResource = remoteInterfaceProvider.get(targetNode, this.authenticationToken, RemoteSystemPluginResource.class); final Response<PluginList> response = remoteSystemPluginResource.list().execute(); if (response.isSuccessful()) { return response.body(); } else { LOG.warn("Unable to get plugin list on node {}: {}", nodeId, response.message()); throw new WebApplicationException(response.message(), BAD_GATEWAY); } } }
private static String getErrorMessage(final retrofit2.Response<?> response) { final ResponseBody errorBody = response.errorBody(); final String errorMessage; try { errorMessage = Objects.isNull(errorBody) ? response.message() : errorBody.string(); } catch (IOException e) { throw new ServiceException("could not read error body", e); } return errorMessage; }
return Optional.of(transformer.apply(response.body())); } else { LOG.warn("Unable to call {} on node <{}>, result: {}", call.request().url(), node, response.message()); return Optional.<FinalResponseType>empty();
@POST @Timed @Path("/multiple") @ApiOperation("Get the values of multiple metrics at once from node") @ApiResponses(value = { @ApiResponse(code = 400, message = "Malformed body") }) @NoAuditEvent("only used to get multiple metric values") public MetricsSummaryResponse multipleMetrics(@ApiParam(name = "nodeId", value = "The id of the node whose metrics we want.", required = true) @PathParam("nodeId") String nodeId, @ApiParam(name = "Requested metrics", required = true) @Valid @NotNull MetricsReadRequest request) throws IOException, NodeNotFoundException { final Response<MetricsSummaryResponse> result = getResourceForNode(nodeId).multipleMetrics(request).execute(); if (result.isSuccessful()) { return result.body(); } else { throw new WebApplicationException(result.message(), BAD_GATEWAY); } }
@GET @Timed @Path("/names") @ApiOperation(value = "Get all metrics keys/names from node") @RequiresPermissions(RestPermissions.METRICS_ALLKEYS) public MetricNamesResponse metricNames(@ApiParam(name = "nodeId", value = "The id of the node whose metrics we want.", required = true) @PathParam("nodeId") String nodeId) throws IOException, NodeNotFoundException { final Response<MetricNamesResponse> result = getResourceForNode(nodeId).metricNames().execute(); if (result.isSuccessful()) { return result.body(); } else { throw new WebApplicationException(result.message(), BAD_GATEWAY); } }
@GET @Timed @ApiOperation(value = "Get a thread dump of the given node") @RequiresPermissions(RestPermissions.THREADS_DUMP) @Path("{nodeId}/threaddump") public SystemThreadDumpResponse threadDump(@ApiParam(name = "nodeId", value = "The id of the node where processing will be paused.", required = true) @PathParam("nodeId") String nodeId) throws IOException, NodeNotFoundException { final Node targetNode = nodeService.byNodeId(nodeId); final RemoteSystemResource remoteSystemResource = remoteInterfaceProvider.get(targetNode, this.authenticationToken, RemoteSystemResource.class); final Response<SystemThreadDumpResponse> response = remoteSystemResource.threadDump().execute(); if (response.isSuccessful()) { return response.body(); } else { LOG.warn("Unable to get thread dump on node {}: {}", nodeId, response.message()); throw new WebApplicationException(response.message(), BAD_GATEWAY); } } }
public HttpException(Response<?> response) { super(getMessage(response)); this.code = response.code(); this.message = response.message(); this.response = response; }
@POST @Timed @ApiOperation(value = "Shutdown node gracefully.", notes = "Attempts to process all buffered and cached messages before exiting, " + "shuts down inputs first to make sure that no new messages are accepted.") @AuditEvent(type = AuditEventTypes.NODE_SHUTDOWN_INITIATE) public void shutdown(@ApiParam(name = "nodeId", value = "The id of the node to shutdown.", required = true) @PathParam("nodeId") String nodeId) throws IOException, NodeNotFoundException { final Node targetNode = nodeService.byNodeId(nodeId); RemoteSystemShutdownResource remoteSystemShutdownResource = remoteInterfaceProvider.get(targetNode, this.authenticationToken, RemoteSystemShutdownResource.class); final Response response = remoteSystemShutdownResource.shutdown().execute(); if (response.code() != ACCEPTED.getStatusCode()) { LOG.warn("Unable send shut down signal to node {}: {}", nodeId, response.message()); throw new WebApplicationException(response.message(), BAD_GATEWAY); } } }
@GET @Timed @ApiOperation(value = "Get message journal information of a given node") @RequiresPermissions(RestPermissions.JOURNAL_READ) public JournalSummaryResponse get(@ApiParam(name = "nodeId", value = "The id of the node to get message journal information.", required = true) @PathParam("nodeId") String nodeId) throws IOException, NodeNotFoundException { final Node targetNode = nodeService.byNodeId(nodeId); final RemoteJournalResource remoteJournalResource = remoteInterfaceProvider.get(targetNode, this.authenticationToken, RemoteJournalResource.class); final Response<JournalSummaryResponse> response = remoteJournalResource.get().execute(); if (response.isSuccessful()) { return response.body(); } else { LOG.warn("Unable to get message journal information on node {}: {}", nodeId, response.message()); throw new WebApplicationException(response.message(), BAD_GATEWAY); } } }
private static String getMessage(Response<?> response) { checkNotNull(response, "response == null"); return "HTTP " + response.code() + " " + response.message(); }
@PUT @Timed @RequiresAuthentication @RequiresPermissions(RestPermissions.LBSTATUS_CHANGE) @ApiOperation(value = "Override load balancer status of this graylog-server node. Next lifecycle " + "change will override it again to its default. Set to ALIVE, DEAD, or THROTTLED.") @Path("/override/{status}") @NoAuditEvent("this is a proxy resource, the audit event will be emitted on the target node") public void override(@ApiParam(name = "nodeId", value = "The id of the node whose LB status will be changed", required = true) @PathParam("nodeId") String nodeId, @ApiParam(name = "status") @PathParam("status") String status) throws IOException, NodeNotFoundException { final Node targetNode = nodeService.byNodeId(nodeId); RemoteLoadBalancerStatusResource remoteLoadBalancerStatusResource = remoteInterfaceProvider.get(targetNode, this.authenticationToken, RemoteLoadBalancerStatusResource.class); final Response response = remoteLoadBalancerStatusResource.override(status).execute(); if (!response.isSuccessful()) { LOG.warn("Unable to override load balancer status on node {}: {}", nodeId, response.message()); throw new WebApplicationException(response.message(), BAD_GATEWAY); } } }
@Override public Response<T> execute() throws IOException { CircuitBreakerUtils.isCallPermitted(circuitBreaker); final StopWatch stopWatch = StopWatch.start(circuitBreaker.getName()); try { final Response<T> response = call.execute(); if (responseSuccess.test(response)) { circuitBreaker.onSuccess(stopWatch.stop().getProcessingDuration().toNanos()); } else { final Throwable throwable = new Throwable("Response error: HTTP " + response.code() + " - " + response.message()); circuitBreaker.onError(stopWatch.stop().getProcessingDuration().toNanos(), throwable); } return response; } catch (Throwable throwable) { circuitBreaker.onError(stopWatch.stop().getProcessingDuration().toNanos(), throwable); throw throwable; } } };