Search in sources :

Example 1 with Transport

use of org.infinispan.server.core.transport.Transport in project infinispan by infinispan.

the class ServerStateManagerImpl method updateIpFilters.

private CompletionStage<Void> updateIpFilters(String connector, Collection<IpFilterRule> rules) {
    ProtocolServer protocolServer = server.getProtocolServers().get(connector);
    if (rules.isEmpty()) {
        protocolServer.getConfiguration().ipFilter().rules(Collections.emptyList());
        Server.log.connectorIpFilterCleared(connector);
        return CompletableFutures.completedNull();
    } else {
        List<IpSubnetFilterRule> localRules = new ArrayList<>(rules.size());
        for (IpFilterRule rule : rules) {
            localRules.add(new IpSubnetFilterRule(rule.cidr, IpFilterRuleType.valueOf(rule.type)));
        }
        protocolServer.getConfiguration().ipFilter().rules(localRules);
        Transport transport = getTransport(protocolServer);
        CompositeChannelMatcher matcher = new CompositeChannelMatcher(protocolServer.getChannelMatcher(), new IpFilterRuleChannelMatcher(localRules));
        return transport.closeChannels(matcher).thenApply(v -> {
            Server.log.connectorIpFilterSet(connector, localRules);
            return v;
        });
    }
}
Also used : ProtocolServer(org.infinispan.server.core.ProtocolServer) IpFilterRuleChannelMatcher(org.infinispan.server.core.transport.IpFilterRuleChannelMatcher) CompositeChannelMatcher(org.infinispan.server.core.transport.CompositeChannelMatcher) ArrayList(java.util.ArrayList) Transport(org.infinispan.server.core.transport.Transport) IpSubnetFilterRule(org.infinispan.server.core.transport.IpSubnetFilterRule)

Example 2 with Transport

use of org.infinispan.server.core.transport.Transport 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)2 Transport (org.infinispan.server.core.transport.Transport)2 ArrayList (java.util.ArrayList)1 CompletionStage (java.util.concurrent.CompletionStage)1 Json (org.infinispan.commons.dataconversion.internal.Json)1 NettyRestResponse (org.infinispan.rest.NettyRestResponse)1 ResourceUtil.addEntityAsJson (org.infinispan.rest.resources.ResourceUtil.addEntityAsJson)1 ServerStateManager (org.infinispan.server.core.ServerStateManager)1 CompositeChannelMatcher (org.infinispan.server.core.transport.CompositeChannelMatcher)1 IpFilterRuleChannelMatcher (org.infinispan.server.core.transport.IpFilterRuleChannelMatcher)1 IpSubnetFilterRule (org.infinispan.server.core.transport.IpSubnetFilterRule)1