Search in sources :

Example 6 with ProtocolServer

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

the class ServerResource method connectorIpFilterClear.

private CompletionStage<RestResponse> connectorIpFilterClear(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();
    return Security.doAs(restRequest.getSubject(), (PrivilegedAction<CompletionStage<RestResponse>>) () -> serverStateManager.clearConnectorIpFilterRules(connectorName).thenApply(r -> builder.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 ProtocolServer

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

the class ServerResource method connectorIpFilterList.

private CompletionStage<RestResponse> connectorIpFilterList(RestRequest restRequest) {
    NettyRestResponse.Builder builder = new NettyRestResponse.Builder();
    ProtocolServer connector = getProtocolServer(restRequest);
    if (connector == null)
        return completedFuture(builder.status(NOT_FOUND).build());
    return completedFuture(addEntityAsJson(ipFilterRulesAsJson(connector), builder).build());
}
Also used : ProtocolServer(org.infinispan.server.core.ProtocolServer) NettyRestResponse(org.infinispan.rest.NettyRestResponse)

Example 8 with ProtocolServer

use of org.infinispan.server.core.ProtocolServer 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 9 with ProtocolServer

use of org.infinispan.server.core.ProtocolServer 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

ProtocolServer (org.infinispan.server.core.ProtocolServer)9 CompletionStage (java.util.concurrent.CompletionStage)6 NettyRestResponse (org.infinispan.rest.NettyRestResponse)5 ServerStateManager (org.infinispan.server.core.ServerStateManager)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 BasicComponentRegistry (org.infinispan.factories.impl.BasicComponentRegistry)3 EmbeddedCacheManager (org.infinispan.manager.EmbeddedCacheManager)3 RestServer (org.infinispan.rest.RestServer)3 RoutingTable (org.infinispan.server.router.RoutingTable)3 SinglePortRouterConfiguration (org.infinispan.server.router.configuration.SinglePortRouterConfiguration)3 HotRodServerRouteDestination (org.infinispan.server.router.routes.hotrod.HotRodServerRouteDestination)3 RespServerRouteDestination (org.infinispan.server.router.routes.resp.RespServerRouteDestination)3 RestServerRouteDestination (org.infinispan.server.router.routes.rest.RestServerRouteDestination)3 SinglePortRouteSource (org.infinispan.server.router.routes.singleport.SinglePortRouteSource)3 BufferedReader (java.io.BufferedReader)2 File (java.io.File)2 IOException (java.io.IOException)2 InputStreamReader (java.io.InputStreamReader)2 ObjectInput (java.io.ObjectInput)2