Search in sources :

Example 6 with ServerStateManager

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

the class ServerResource method connectorStartStop.

private CompletionStage<RestResponse> connectorStartStop(RestRequest restRequest) {
    NettyRestResponse.Builder builder = new NettyRestResponse.Builder().status(NO_CONTENT);
    String connectorName = restRequest.variables().get("connector");
    ProtocolServer connector = invocationHelper.getServer().getProtocolServers().get(connectorName);
    if (connector == null)
        return completedFuture(builder.status(NOT_FOUND).build());
    ServerStateManager serverStateManager = invocationHelper.getServer().getServerStateManager();
    switch(restRequest.getAction()) {
        case "start":
            return Security.doAs(restRequest.getSubject(), (PrivilegedAction<CompletionStage<RestResponse>>) () -> serverStateManager.connectorStart(connectorName).thenApply(r -> builder.build()));
        case "stop":
            if (connector.equals(invocationHelper.getProtocolServer()) || connector.equals(invocationHelper.getProtocolServer().getEnclosingProtocolServer())) {
                return completedFuture(builder.status(CONFLICT).entity(Messages.MSG.connectorMatchesRequest(connectorName)).build());
            } else {
                return Security.doAs(restRequest.getSubject(), (PrivilegedAction<CompletionStage<RestResponse>>) () -> serverStateManager.connectorStop(connectorName).thenApply(r -> builder.build()));
            }
    }
    return completedFuture(builder.status(BAD_REQUEST).build());
}
Also used : ProtocolServer(org.infinispan.server.core.ProtocolServer) ServerStateManager(org.infinispan.server.core.ServerStateManager) NettyRestResponse(org.infinispan.rest.NettyRestResponse) CompletionStage(java.util.concurrent.CompletionStage)

Example 7 with ServerStateManager

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

the class ServerResource method connectorStatus.

private CompletionStage<RestResponse> connectorStatus(RestRequest restRequest) {
    NettyRestResponse.Builder builder = new NettyRestResponse.Builder();
    String connectorName = restRequest.variables().get("connector");
    ProtocolServer connector = getProtocolServer(restRequest);
    if (connector == null)
        return completedFuture(builder.status(NOT_FOUND).build());
    ServerStateManager serverStateManager = invocationHelper.getServer().getServerStateManager();
    Json info = Json.object().set("name", connectorName).set("ip-filter-rules", ipFilterRulesAsJson(connector));
    Transport transport = connector.getTransport();
    if (transport != null) {
        info.set("host", transport.getHostName()).set("port", transport.getPort()).set("local-connections", transport.getNumberOfLocalConnections()).set("global-connections", transport.getNumberOfGlobalConnections()).set("io-threads", transport.getNumberIOThreads()).set("pending-tasks", transport.getPendingTasks()).set("total-bytes-read", transport.getTotalBytesRead()).set("total-bytes-written", transport.getTotalBytesWritten()).set("send-buffer-size", transport.getSendBufferSize()).set("receive-buffer-size", transport.getReceiveBufferSize());
    }
    return Security.doAs(restRequest.getSubject(), (PrivilegedAction<CompletionStage<RestResponse>>) () -> serverStateManager.connectorStatus(connectorName).thenApply(b -> builder.contentType(APPLICATION_JSON).entity(info.set("enabled", b)).build()));
}
Also used : ProtocolServer(org.infinispan.server.core.ProtocolServer) ServerStateManager(org.infinispan.server.core.ServerStateManager) ResourceUtil.addEntityAsJson(org.infinispan.rest.resources.ResourceUtil.addEntityAsJson) Json(org.infinispan.commons.dataconversion.internal.Json) Transport(org.infinispan.server.core.transport.Transport) NettyRestResponse(org.infinispan.rest.NettyRestResponse) CompletionStage(java.util.concurrent.CompletionStage)

Aggregations

ServerStateManager (org.infinispan.server.core.ServerStateManager)7 CompletionStage (java.util.concurrent.CompletionStage)5 NettyRestResponse (org.infinispan.rest.NettyRestResponse)5 ProtocolServer (org.infinispan.server.core.ProtocolServer)4 DefaultCacheManager (org.infinispan.manager.DefaultCacheManager)3 Json (org.infinispan.commons.dataconversion.internal.Json)2 ResourceUtil.addEntityAsJson (org.infinispan.rest.resources.ResourceUtil.addEntityAsJson)2 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 ObjectInput (java.io.ObjectInput)1 ObjectOutput (java.io.ObjectOutput)1 InetSocketAddress (java.net.InetSocketAddress)1 URL (java.net.URL)1 Path (java.nio.file.Path)1 Paths (java.nio.file.Paths)1 PrivilegedAction (java.security.PrivilegedAction)1 PrivilegedActionException (java.security.PrivilegedActionException)1 ArrayList (java.util.ArrayList)1