use of org.infinispan.configuration.cache.TakeOfflineConfiguration in project infinispan by infinispan.
the class OfflineStatusTest method createNew.
private static TestContext createNew(long minWait, int afterFailures) {
ControlledTimeService t = new ControlledTimeService();
ListenerImpl l = new ListenerImpl();
TakeOfflineConfiguration c = new TakeOfflineConfigurationBuilder(null, null).afterFailures(afterFailures).minTimeToWait(minWait).create();
return new TestContext(new OfflineStatus(c, t, l), t, l);
}
use of org.infinispan.configuration.cache.TakeOfflineConfiguration in project infinispan by infinispan.
the class XSiteResource method getXSiteTakeOffline.
private CompletionStage<RestResponse> getXSiteTakeOffline(RestRequest request) {
NettyRestResponse.Builder responseBuilder = new NettyRestResponse.Builder();
String site = request.variables().get("site");
Optional<XSiteAdminOperations> xsiteAdminOpt = getXSiteAdminAndCheckSite(request, responseBuilder);
xsiteAdminOpt.ifPresent(ops -> {
TakeOfflineConfiguration config = ops.getTakeOfflineConfiguration(site);
assert config != null;
addEntityAsJson(new TakeOffline(config), responseBuilder);
});
return completedFuture(responseBuilder.build());
}
use of org.infinispan.configuration.cache.TakeOfflineConfiguration in project infinispan by infinispan.
the class XSiteResource method updateTakeOffline.
private CompletionStage<RestResponse> updateTakeOffline(RestRequest request) {
NettyRestResponse.Builder responseBuilder = new NettyRestResponse.Builder().status(NO_CONTENT);
String site = request.variables().get("site");
Optional<XSiteAdminOperations> xsiteAdminOpt = getXSiteAdminAndCheckSite(request, responseBuilder);
if (!xsiteAdminOpt.isPresent()) {
return completedFuture(responseBuilder.build());
}
XSiteAdminOperations xsiteAdmin = xsiteAdminOpt.get();
TakeOfflineConfiguration current = xsiteAdmin.getTakeOfflineConfiguration(site);
assert current != null;
String content = request.contents().asString();
if (content == null || content.isEmpty()) {
return completedFuture(responseBuilder.status(BAD_REQUEST).build());
}
int afterFailures, minWait;
try {
Json json = Json.read(content);
Json minWaitValue = json.at(MIN_WAIT_FIELD);
Json afterFailuresValue = json.at(AFTER_FAILURES_FIELD);
if (minWaitValue == null || afterFailuresValue == null) {
return completedFuture(responseBuilder.status(BAD_REQUEST).build());
}
minWait = minWaitValue.asInteger();
afterFailures = afterFailuresValue.asInteger();
} catch (Exception e) {
Throwable rootCause = Util.getRootCause(e);
return completedFuture(responseBuilder.status(BAD_REQUEST).entity(rootCause.getMessage()).build());
}
if (afterFailures == current.afterFailures() && minWait == current.minTimeToWait()) {
return completedFuture(responseBuilder.status(NOT_MODIFIED).build());
}
return supplyAsync(() -> {
String status = Security.doAs(request.getSubject(), (PrivilegedAction<String>) () -> xsiteAdmin.amendTakeOffline(site, afterFailures, minWait));
if (!status.equals(XSiteAdminOperations.SUCCESS)) {
responseBuilder.status(INTERNAL_SERVER_ERROR).entity(site);
}
return responseBuilder.build();
}, invocationHelper.getExecutor());
}
Aggregations