本文整理汇总了Java中com.spotify.apollo.Status类的典型用法代码示例。如果您正苦于以下问题:Java Status类的具体用法?Java Status怎么用?Java Status使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Status类属于com.spotify.apollo包,在下文中一共展示了Status类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: shouldThrowIfNotOK
import com.spotify.apollo.Status; //导入依赖的package包/类
@Test
public void shouldThrowIfNotOK() throws Exception {
when(client.send(any(Request.class)))
.thenReturn(CompletableFuture.completedFuture(Response.forStatus(Status.BAD_REQUEST)));
try {
RktCommandHelper.sendRequest(client,
"http://localhost:8080/rkt/gc",
GcOptions
.builder()
.markOnly(true)
.build(),
GcOutput.class)
.toCompletableFuture().get();
fail();
} catch (ExecutionException e) {
assertSame(RktLauncherRemoteHttpException.class, e.getCause().getClass());
assertEquals(400, ((RktLauncherRemoteHttpException) e.getCause()).getCode());
}
}
示例2: compose
import com.spotify.apollo.Status; //导入依赖的package包/类
private CompletionStage<Response<ByteString>> compose(final RequestContext context, final RouteMatch match,
final Response<ByteString> response) {
if (match.shouldProxy()) {
return CompletableFuture.completedFuture(response);
}
if (response.status().code() != Status.OK.code() || !response.payload().isPresent()) {
// Do whatever suits your environment, retrieve the data from a cache,
// re-execute the request or just fail.
return defaultResponse();
}
final String responseAsUtf8 = response.payload().get().utf8();
return composerFactory.build(context.requestScopedClient(), match.parsedPathArguments())
.composeTemplate(response.withPayload(responseAsUtf8))
.thenApply(r -> toByteString(r)
.withHeaders(transformHeaders(response.headerEntries())));
}
示例3: clientValidator
import com.spotify.apollo.Status; //导入依赖的package包/类
public static <T> Middleware<AsyncHandler<Response<T>>, AsyncHandler<Response<T>>> clientValidator(
Supplier<List<String>> supplier) {
return innerHandler -> requestContext -> {
if (requestContext.request().header("User-Agent")
// TODO: should the blacklist be a set so this lookup is O(1) instead of O(n) ?
.map(header -> supplier.get().contains(header))
.orElse(false)) {
// TODO: fire some stats
return
completedFuture(Response.forStatus(Status.NOT_ACCEPTABLE.withReasonPhrase(
"blacklisted client version, please upgrade")));
} else {
return innerHandler.invoke(requestContext);
}
};
}
示例4: testAuditLoggingForPutWithBrokenAuthorization
import com.spotify.apollo.Status; //导入依赖的package包/类
@Test
public void testAuditLoggingForPutWithBrokenAuthorization()
throws InterruptedException, ExecutionException, TimeoutException {
RequestContext requestContext = mock(RequestContext.class);
Request request = Request.forUri("/", "PUT")
.withHeader(HttpHeaders.AUTHORIZATION, "Bearer broken")
.withPayload(ByteString.encodeUtf8("hello"));
when(requestContext.request()).thenReturn(request);
Response<Object> response = Middlewares.auditLogger().and(Middlewares.exceptionHandler())
.apply(mockInnerHandler(requestContext))
.invoke(requestContext)
.toCompletableFuture().get(5, SECONDS);
assertThat(response, hasStatus(withCode(Status.BAD_REQUEST)));
}
示例5: testExceptionHandlerForAsyncException
import com.spotify.apollo.Status; //导入依赖的package包/类
@Test
public void testExceptionHandlerForAsyncException()
throws InterruptedException, ExecutionException, TimeoutException {
RequestContext requestContext = mock(RequestContext.class);
Request request = Request.forUri("/", "GET");
when(requestContext.request()).thenReturn(request);
CompletableFuture<?> failedFuture = new CompletableFuture();
failedFuture.completeExceptionally(new ResponseException(Response.forStatus(Status.IM_A_TEAPOT)));
Response<Object> response = Middlewares.exceptionHandler()
.apply(mockInnerHandler(requestContext, failedFuture))
.invoke(requestContext)
.toCompletableFuture().get(5, SECONDS);
assertThat(response, hasStatus(withCode(Status.IM_A_TEAPOT)));
}
示例6: testUnathorizedMissingCredentialsApiError
import com.spotify.apollo.Status; //导入依赖的package包/类
@Test
public void testUnathorizedMissingCredentialsApiError() throws Exception {
when(auth.getToken(any())).thenReturn(Optional.empty());
when(client.send(any()))
.thenReturn(CompletableFuture.completedFuture(Response.forStatus(Status.UNAUTHORIZED)));
final StyxApolloClient styx = new StyxApolloClient(client, CLIENT_HOST, auth);
try {
styx.triggerWorkflowInstance("foo", "bar", "baz").toCompletableFuture().get();
fail();
} catch (ExecutionException e) {
assertThat(e.getCause(), instanceOf(ApiErrorException.class));
ApiErrorException apiErrorException = (ApiErrorException) e.getCause();
assertThat(apiErrorException.isAuthenticated(), is(false));
}
}
示例7: instances
import com.spotify.apollo.Status; //导入依赖的package包/类
private Response<List<WorkflowInstanceExecutionData>> instances(
String componentId,
String id,
Request request) {
final WorkflowId workflowId = WorkflowId.create(componentId, id);
final String offset = request.parameter("offset").orElse("");
final int limit = request.parameter("limit").map(Integer::parseInt).orElse(DEFAULT_PAGE_LIMIT);
final String start = request.parameter("start").orElse("");
final String stop = request.parameter("stop").orElse("");
final List<WorkflowInstanceExecutionData> data;
try {
if (Strings.isNullOrEmpty(start)) {
data = storage.executionData(workflowId, offset, limit);
} else {
data = storage.executionData(workflowId, start, stop);
}
} catch (IOException e) {
return Response.forStatus(
Status.INTERNAL_SERVER_ERROR.withReasonPhrase("Couldn't fetch execution info."));
}
return Response.forPayload(data);
}
示例8: instance
import com.spotify.apollo.Status; //导入依赖的package包/类
private Response<WorkflowInstanceExecutionData> instance(
String componentId,
String id,
String instanceId) {
final WorkflowId workflowId = WorkflowId.create(componentId, id);
final WorkflowInstance workflowInstance = WorkflowInstance.create(workflowId, instanceId);
try {
final WorkflowInstanceExecutionData workflowInstanceExecutionData =
storage.executionData(workflowInstance);
return Response.forPayload(workflowInstanceExecutionData);
} catch (IOException e) {
return Response.forStatus(
Status.INTERNAL_SERVER_ERROR.withReasonPhrase("Couldn't fetch execution info."));
}
}
示例9: updateResource
import com.spotify.apollo.Status; //导入依赖的package包/类
private Response<Resource> updateResource(String id, Resource resource) {
if (!resource.id().equals(id)) {
return Response.forStatus(
Status.BAD_REQUEST.withReasonPhrase("ID of payload does not match ID in uri."));
}
try {
storage.storeResource(resource);
} catch (IOException e) {
return Response
.forStatus(
Status.INTERNAL_SERVER_ERROR.withReasonPhrase("Failed to store resource."));
}
return Response.forStatus(Status.OK).withPayload(resource);
}
示例10: haltActiveBackfillInstances
import com.spotify.apollo.Status; //导入依赖的package包/类
private CompletionStage<Response<ByteString>> haltActiveBackfillInstances(Backfill backfill, Client client) {
return CompletableFutures.allAsList(
retrieveBackfillStatuses(backfill).stream()
.filter(BackfillResource::isActiveState)
.map(RunStateData::workflowInstance)
.map(workflowInstance -> haltActiveBackfillInstance(workflowInstance, client))
.collect(toList()))
.handle((result, throwable) -> {
if (throwable != null || result.contains(Boolean.FALSE)) {
return Response.forStatus(
Status.INTERNAL_SERVER_ERROR
.withReasonPhrase(
"some active instances cannot be halted, however no new ones will be triggered"));
} else {
return Response.ok();
}
});
}
示例11: updateBackfill
import com.spotify.apollo.Status; //导入依赖的package包/类
public Response<Backfill> updateBackfill(String id, Backfill backfill) {
if (!backfill.id().equals(id)) {
return Response.forStatus(
Status.BAD_REQUEST.withReasonPhrase("ID of payload does not match ID in uri."));
}
try {
storage.storeBackfill(backfill);
} catch (IOException e) {
return Response
.forStatus(
Status.INTERNAL_SERVER_ERROR.withReasonPhrase("Failed to store backfill."));
}
return Response.forStatus(Status.OK).withPayload(backfill);
}
示例12: verifyPassesHeaders
import com.spotify.apollo.Status; //导入依赖的package包/类
@Test
public void verifyPassesHeaders() throws Exception {
sinceVersion(Api.Version.V3);
serviceHelper.stubClient()
.respond(Response.forStatus(Status.ACCEPTED))
.to(SCHEDULER_BASE + "/api/v0/trigger");
awaitResponse(serviceHelper.request(Request
.forUri(path("/trigger"), "POST")
.withHeader("foo", "bar")
.withHeader(HttpHeaders.AUTHORIZATION, "decafbad")));
final Request schedulerRequest = Iterables.getOnlyElement(serviceHelper.stubClient().sentRequests());
assertThat(schedulerRequest.header("foo"), is(Optional.of("bar")));
assertThat(schedulerRequest.header(HttpHeaders.AUTHORIZATION), is(Optional.of("decafbad")));
}
示例13: shouldReturnCurrentWorkflowState
import com.spotify.apollo.Status; //导入依赖的package包/类
@Test
public void shouldReturnCurrentWorkflowState() throws Exception {
sinceVersion(Api.Version.V3);
Response<ByteString> response =
awaitResponse(serviceHelper.request("GET", path("/foo/bar/state")));
assertThat(response, hasStatus(withCode(Status.OK)));
assertJson(response, "enabled", equalTo(false));
storage.patchState(WORKFLOW.id(),
WorkflowState.patchEnabled(true));
response =
awaitResponse(serviceHelper.request("GET", path("/foo/bar/state")));
assertThat(response, hasStatus(withCode(Status.OK)));
assertJson(response, "enabled", equalTo(true));
}
示例14: shouldReturnWorkflowInstanceDataBackfill
import com.spotify.apollo.Status; //导入依赖的package包/类
@Test
public void shouldReturnWorkflowInstanceDataBackfill() throws Exception {
sinceVersion(Api.Version.V3);
WorkflowInstance wfi = WorkflowInstance.create(WORKFLOW.id(), "2016-08-10");
storage.writeEvent(create(Event.triggerExecution(wfi, BACKFILL_TRIGGER), 0L, ms("07:00:00")));
Response<ByteString> response =
awaitResponse(serviceHelper.request("GET", path("/foo/bar/instances/2016-08-10")));
assertThat(response, hasStatus(withCode(Status.OK)));
assertJson(response, "workflow_instance.parameter", is("2016-08-10"));
assertJson(response, "workflow_instance.workflow_id.component_id", is("foo"));
assertJson(response, "workflow_instance.workflow_id.id", is("bar"));
assertJson(response, "triggers", hasSize(1));
assertJson(response, "triggers.[0].trigger_id", is("backfill-1"));
assertJson(response, "triggers.[0].timestamp", is("2016-08-10T07:00:00Z"));
assertJson(response, "triggers.[0].complete", is(false));
}
示例15: shouldPaginateWorkflowInstancesData
import com.spotify.apollo.Status; //导入依赖的package包/类
@Test
public void shouldPaginateWorkflowInstancesData() throws Exception {
sinceVersion(Api.Version.V3);
WorkflowInstance wfi1 = WorkflowInstance.create(WORKFLOW.id(), "2016-08-11");
WorkflowInstance wfi2 = WorkflowInstance.create(WORKFLOW.id(), "2016-08-12");
WorkflowInstance wfi3 = WorkflowInstance.create(WORKFLOW.id(), "2016-08-13");
storage.writeEvent(create(Event.triggerExecution(wfi1, NATURAL_TRIGGER), 0L, ms("07:00:00")));
storage.writeEvent(create(Event.triggerExecution(wfi2, NATURAL_TRIGGER), 0L, ms("07:00:00")));
storage.writeEvent(create(Event.triggerExecution(wfi3, NATURAL_TRIGGER), 0L, ms("07:00:00")));
Response<ByteString> response = awaitResponse(
serviceHelper.request("GET", path("/foo/bar/instances?offset=2016-08-12&limit=1")));
assertThat(response, hasStatus(withCode(Status.OK)));
assertJson(response, "[*]", hasSize(1));
assertJson(response, "[0].workflow_instance.parameter", is("2016-08-12"));
}