Search in sources :

Example 1 with TakeOfflineConfiguration

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);
}
Also used : TakeOfflineConfiguration(org.infinispan.configuration.cache.TakeOfflineConfiguration) TakeOfflineConfigurationBuilder(org.infinispan.configuration.cache.TakeOfflineConfigurationBuilder) OfflineStatus(org.infinispan.xsite.OfflineStatus) ControlledTimeService(org.infinispan.util.ControlledTimeService)

Example 2 with TakeOfflineConfiguration

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());
}
Also used : TakeOfflineConfiguration(org.infinispan.configuration.cache.TakeOfflineConfiguration) XSiteAdminOperations(org.infinispan.xsite.XSiteAdminOperations) GlobalXSiteAdminOperations(org.infinispan.xsite.GlobalXSiteAdminOperations) NettyRestResponse(org.infinispan.rest.NettyRestResponse)

Example 3 with TakeOfflineConfiguration

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());
}
Also used : TakeOfflineConfiguration(org.infinispan.configuration.cache.TakeOfflineConfiguration) Json(org.infinispan.commons.dataconversion.internal.Json) ResourceUtil.addEntityAsJson(org.infinispan.rest.resources.ResourceUtil.addEntityAsJson) XSiteAdminOperations(org.infinispan.xsite.XSiteAdminOperations) GlobalXSiteAdminOperations(org.infinispan.xsite.GlobalXSiteAdminOperations) NettyRestResponse(org.infinispan.rest.NettyRestResponse)

Aggregations

TakeOfflineConfiguration (org.infinispan.configuration.cache.TakeOfflineConfiguration)3 NettyRestResponse (org.infinispan.rest.NettyRestResponse)2 GlobalXSiteAdminOperations (org.infinispan.xsite.GlobalXSiteAdminOperations)2 XSiteAdminOperations (org.infinispan.xsite.XSiteAdminOperations)2 Json (org.infinispan.commons.dataconversion.internal.Json)1 TakeOfflineConfigurationBuilder (org.infinispan.configuration.cache.TakeOfflineConfigurationBuilder)1 ResourceUtil.addEntityAsJson (org.infinispan.rest.resources.ResourceUtil.addEntityAsJson)1 ControlledTimeService (org.infinispan.util.ControlledTimeService)1 OfflineStatus (org.infinispan.xsite.OfflineStatus)1