Search in sources :

Example 1 with ServerManagement

use of org.infinispan.server.core.ServerManagement in project infinispan by infinispan.

the class ServerResource method doIgnoreOp.

private CompletionStage<RestResponse> doIgnoreOp(RestRequest restRequest) {
    NettyRestResponse.Builder builder = new NettyRestResponse.Builder().status(NO_CONTENT);
    boolean add = restRequest.method().equals(POST);
    String cacheManagerName = restRequest.variables().get("cache-manager");
    DefaultCacheManager cacheManager = invocationHelper.getServer().getCacheManager(cacheManagerName);
    if (cacheManager == null)
        return completedFuture(builder.status(NOT_FOUND).build());
    String cacheName = restRequest.variables().get("cache");
    if (!cacheManager.getCacheNames().contains(cacheName)) {
        return completedFuture(builder.status(NOT_FOUND).build());
    }
    ServerManagement server = invocationHelper.getServer();
    ServerStateManager ignoreManager = server.getServerStateManager();
    return Security.doAs(restRequest.getSubject(), (PrivilegedAction<CompletionStage<Void>>) () -> add ? ignoreManager.ignoreCache(cacheName) : ignoreManager.unignoreCache(cacheName)).thenApply(r -> builder.build());
}
Also used : DefaultCacheManager(org.infinispan.manager.DefaultCacheManager) ServerStateManager(org.infinispan.server.core.ServerStateManager) PrivilegedAction(java.security.PrivilegedAction) ServerManagement(org.infinispan.server.core.ServerManagement) NettyRestResponse(org.infinispan.rest.NettyRestResponse)

Example 2 with ServerManagement

use of org.infinispan.server.core.ServerManagement in project infinispan by infinispan.

the class ServerResource method report.

private CompletionStage<RestResponse> report(RestRequest restRequest) {
    ServerManagement server = invocationHelper.getServer();
    NettyRestResponse.Builder responseBuilder = new NettyRestResponse.Builder();
    return Security.doAs(restRequest.getSubject(), (PrivilegedAction<CompletionStage<RestResponse>>) () -> server.getServerReport().handle((path, t) -> {
        if (t != null) {
            return responseBuilder.status(HttpResponseStatus.INTERNAL_SERVER_ERROR).build();
        } else {
            return responseBuilder.contentType(MediaType.fromString("application/gzip")).header("Content-Disposition", String.format("attachment; filename=\"%s-%s-%3$tY%3$tm%3$td%3$tH%3$tM%3$tS-report.tar.gz\"", Version.getBrandName().toLowerCase().replaceAll("\\s", "-"), invocationHelper.getRestCacheManager().getNodeName(), Calendar.getInstance())).entity(path.toFile()).build();
        }
    }));
}
Also used : ServerManagement(org.infinispan.server.core.ServerManagement) NettyRestResponse(org.infinispan.rest.NettyRestResponse) CompletionStage(java.util.concurrent.CompletionStage)

Aggregations

NettyRestResponse (org.infinispan.rest.NettyRestResponse)2 ServerManagement (org.infinispan.server.core.ServerManagement)2 PrivilegedAction (java.security.PrivilegedAction)1 CompletionStage (java.util.concurrent.CompletionStage)1 DefaultCacheManager (org.infinispan.manager.DefaultCacheManager)1 ServerStateManager (org.infinispan.server.core.ServerStateManager)1