Search in sources :

Example 26 with Node

use of org.graylog2.indexer.cluster.Node in project graylog2-server by Graylog2.

the class ClusterSystemPluginResource method list.

@GET
@Timed
@ApiOperation(value = "List all installed plugins on the given node")
public PluginList list(@ApiParam(name = "nodeId", value = "The id of the node where processing will be paused.", required = true) @PathParam("nodeId") String nodeId) throws IOException, NodeNotFoundException {
    final Node targetNode = nodeService.byNodeId(nodeId);
    final RemoteSystemPluginResource remoteSystemPluginResource = remoteInterfaceProvider.get(targetNode, this.authenticationToken, RemoteSystemPluginResource.class);
    final Response<PluginList> response = remoteSystemPluginResource.list().execute();
    if (response.isSuccessful()) {
        return response.body();
    } else {
        LOG.warn("Unable to get plugin list on node {}: {}", nodeId, response.message());
        throw new WebApplicationException(response.message(), BAD_GATEWAY);
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) Node(org.graylog2.cluster.Node) PluginList(org.graylog2.rest.models.system.plugins.responses.PluginList) RemoteSystemPluginResource(org.graylog2.shared.rest.resources.system.RemoteSystemPluginResource) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation)

Example 27 with Node

use of org.graylog2.indexer.cluster.Node in project graylog2-server by Graylog2.

the class ClusterSystemResource method jvm.

@GET
@Timed
@ApiOperation(value = "Get JVM information of the given node")
@Path("{nodeId}/jvm")
public SystemJVMResponse jvm(@ApiParam(name = "nodeId", value = "The id of the node to retrieve JVM information.", required = true) @PathParam("nodeId") String nodeId) throws IOException, NodeNotFoundException {
    final Node targetNode = nodeService.byNodeId(nodeId);
    final RemoteSystemResource remoteSystemResource = remoteInterfaceProvider.get(targetNode, this.authenticationToken, RemoteSystemResource.class);
    final Response<SystemJVMResponse> response = remoteSystemResource.jvm().execute();
    if (response.isSuccessful()) {
        return response.body();
    } else {
        LOG.warn("Unable to get jvm information on node {}: {}", nodeId, response.message());
        throw new WebApplicationException(response.message(), BAD_GATEWAY);
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) RemoteSystemResource(org.graylog2.shared.rest.resources.system.RemoteSystemResource) Node(org.graylog2.cluster.Node) SystemJVMResponse(org.graylog2.rest.models.system.responses.SystemJVMResponse) Path(javax.ws.rs.Path) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation)

Example 28 with Node

use of org.graylog2.indexer.cluster.Node in project graylog2-server by Graylog2.

the class ClusterSystemShutdownResource method shutdown.

@POST
@Timed
@AuditEvent(type = AuditEventTypes.NODE_SHUTDOWN_INITIATE)
public void shutdown(@PathParam("nodeId") String nodeId) throws IOException, NodeNotFoundException {
    LOG.warn("Deprecated API endpoint /cluster/{nodeId}/shutdown was called. Shutting down nodes via the API is " + "discouraged in favor of using a service manager to control the server process.");
    final Node targetNode = nodeService.byNodeId(nodeId);
    RemoteSystemShutdownResource remoteSystemShutdownResource = remoteInterfaceProvider.get(targetNode, this.authenticationToken, RemoteSystemShutdownResource.class);
    final Response response = remoteSystemShutdownResource.shutdown().execute();
    if (response.code() != ACCEPTED.getStatusCode()) {
        LOG.warn("Unable send shut down signal to node {}: {}", nodeId, response.message());
        throw new WebApplicationException(response.message(), BAD_GATEWAY);
    }
}
Also used : Response(retrofit2.Response) RemoteSystemShutdownResource(org.graylog2.rest.resources.system.RemoteSystemShutdownResource) WebApplicationException(javax.ws.rs.WebApplicationException) Node(org.graylog2.cluster.Node) POST(javax.ws.rs.POST) Timed(com.codahale.metrics.annotation.Timed) AuditEvent(org.graylog2.audit.jersey.AuditEvent)

Example 29 with Node

use of org.graylog2.indexer.cluster.Node in project graylog2-server by Graylog2.

the class ClusterLoggersResource method setSubsystemLoggerLevel.

@PUT
@Timed
@Path("/{nodeId}/subsystems/{subsystem}/level/{level}")
@ApiOperation(value = "Set the loglevel of a whole subsystem", notes = "Provided level is falling back to DEBUG if it does not exist")
@ApiResponses(value = { @ApiResponse(code = 404, message = "No such subsystem.") })
@NoAuditEvent("proxy resource, audit event will be emitted on target nodes")
public void setSubsystemLoggerLevel(@ApiParam(name = "nodeId", required = true) @PathParam("nodeId") @NotEmpty String nodeId, @ApiParam(name = "subsystem", required = true) @PathParam("subsystem") @NotEmpty String subsystemTitle, @ApiParam(name = "level", required = true) @PathParam("level") @NotEmpty String level) throws NodeNotFoundException, IOException {
    final Node node = this.nodeService.byNodeId(nodeId);
    final RemoteLoggersResource remoteLoggersResource = this.remoteInterfaceProvider.get(node, this.authenticationToken, RemoteLoggersResource.class);
    remoteLoggersResource.setSubsystemLoggerLevel(subsystemTitle, level).execute();
}
Also used : Node(org.graylog2.cluster.Node) RemoteLoggersResource(org.graylog2.rest.resources.system.logs.RemoteLoggersResource) Path(javax.ws.rs.Path) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) PUT(javax.ws.rs.PUT) ApiResponses(io.swagger.annotations.ApiResponses) NoAuditEvent(org.graylog2.audit.jersey.NoAuditEvent)

Example 30 with Node

use of org.graylog2.indexer.cluster.Node in project graylog2-server by Graylog2.

the class LoadBalancerStatusResource method status.

@GET
@Timed
@Produces(MediaType.TEXT_PLAIN)
@ApiOperation(value = "Get status of this Graylog server node for load balancers. " + "Returns ALIVE with HTTP 200, DEAD with HTTP 503, or THROTTLED with HTTP 429.")
public Response status() {
    final LoadBalancerStatus lbStatus = serverStatus.getLifecycle().getLoadbalancerStatus();
    Response.StatusType status;
    switch(lbStatus) {
        case ALIVE:
            status = Response.Status.OK;
            break;
        case THROTTLED:
            status = new TooManyRequestsStatus();
            break;
        default:
            status = Response.Status.SERVICE_UNAVAILABLE;
    }
    return Response.status(status).entity(lbStatus.toString().toUpperCase(Locale.ENGLISH)).build();
}
Also used : Response(javax.ws.rs.core.Response) TooManyRequestsStatus(org.graylog2.rest.TooManyRequestsStatus) LoadBalancerStatus(org.graylog2.plugin.lifecycles.LoadBalancerStatus) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation)

Aggregations

Timed (com.codahale.metrics.annotation.Timed)29 ApiOperation (io.swagger.annotations.ApiOperation)28 MessageInput (org.graylog2.plugin.inputs.MessageInput)23 ApiResponses (io.swagger.annotations.ApiResponses)19 Path (javax.ws.rs.Path)19 Input (org.graylog2.inputs.Input)15 AuditEvent (org.graylog2.audit.jersey.AuditEvent)14 Test (org.junit.Test)14 GET (javax.ws.rs.GET)13 Produces (javax.ws.rs.Produces)12 Node (org.graylog2.cluster.Node)12 Map (java.util.Map)7 WebApplicationException (javax.ws.rs.WebApplicationException)7 PUT (javax.ws.rs.PUT)6 RequiresPermissions (org.apache.shiro.authz.annotation.RequiresPermissions)6 Notification (org.graylog2.notifications.Notification)6 Activity (org.graylog2.shared.system.activities.Activity)6 JsonNode (com.fasterxml.jackson.databind.JsonNode)5 EventBus (com.google.common.eventbus.EventBus)5 URI (java.net.URI)5