@Override protected boolean matchesSafely(StatusType item) { return item.code() == code; }
static StatusType transformStatus(int code, Optional<String> message) { final StatusType statusType = Status.createForCode(code); if (message.isPresent() && !message.get().equals(statusType.reasonPhrase())) { return statusType.withReasonPhrase(message.get()); } else { return statusType; } } }
private void sendReply(Response<ByteString> response) { if (!replied.compareAndSet(false, true)) { LOGGER.warn("Already replied to ongoing request {} - spurious response {}", request, response); } else { final HttpServletResponse httpResponse = (HttpServletResponse) asyncContext.getResponse(); final StatusType status = response.status(); httpResponse.setStatus(status.code(), status.reasonPhrase()); response.headerEntries().forEach(entry -> httpResponse.addHeader(entry.getKey(), entry.getValue())); response.payload().ifPresent(payload -> { try { payload.write(httpResponse.getOutputStream()); } catch (IOException e) { LOGGER.warn("Failed to write response", e); } }); asyncContext.complete(); logger.accept(this, Optional.of(response)); } }
@Override protected StatusType.Family featureValueOf(StatusType item) { return item.family(); } };
@Override protected String featureValueOf(StatusType item) { return item.reasonPhrase(); } };
@Override public void response(Response<ByteString> response) { requestRateCounter.ifPresent(consumer -> consumer.accept(response)); responseSizeHistogram .ifPresent(histogram -> response.payload() .ifPresent(payload -> histogram.update(payload.size()))); sentReplies.mark(); timerContext.ifPresent(timer -> { final long duration = timer.stop(); final long durationMs = TimeUnit.NANOSECONDS.toMillis(duration); durationThresholdTracker.ifPresent(counter -> { counter.markDurationThresholds(durationMs); }); }); StatusType.Family family = response.status().family(); if (family != INFORMATIONAL && family != SUCCESSFUL) { sentErrors.mark(); } if (family == CLIENT_ERROR) { sentErrors4xx.mark(); } if (family == SERVER_ERROR) { sentErrors5xx.mark(); } }
@Override protected String featureValueOf(StatusType item) { return item.reasonPhrase(); } };
@Override protected StatusType.Family featureValueOf(StatusType item) { return item.family(); } };
@Override protected void describeMismatchSafely(StatusType item, Description mismatchDescription) { mismatchDescription.appendText("the status code was ").appendValue(item.code()); } };
private CompletionStage<Boolean> haltActiveBackfillInstance(WorkflowInstance workflowInstance, Client client) { try { final ByteString payload = serialize(Event.halt(workflowInstance)); final Request request = Request.forUri(schedulerApiUrl("events"), "POST") .withPayload(payload); return client.send(request) .thenApply(response -> response.status().family().equals(SUCCESSFUL)); } catch (JsonProcessingException e) { return CompletableFuture.completedFuture(false); } }
@Override protected void describeMismatchSafely(StatusType item, Description mismatchDescription) { mismatchDescription.appendText("the status code was ").appendValue(item.code()); } };
@Override public void describeTo(Description description) { description.appendText("a status type with status code equals to ").appendValue(code.code()); }
private Optional<Consumer<Response<ByteString>>> requestRateCounter(MetricId id) { return enabledMetrics.test(ENDPOINT_REQUEST_RATE) ? Optional.of(response -> requestRateMeter(id, response.status().code()).mark()) : Optional.empty(); }
@Override protected boolean matchesSafely(StatusType item) { return item.code() == code; }
@Override protected void describeMismatchSafely(StatusType item, Description mismatchDescription) { mismatchDescription.appendText("the status code was ").appendValue(item.code()); } };
@Override protected void describeMismatchSafely(StatusType item, Description mismatchDescription) { mismatchDescription.appendText("the status code was ").appendValue(item.code()); } };
@Override public void describeTo(Description description) { description.appendText("a status type with status code equals to ").appendValue(code.code()); }