Search in sources :

Example 1 with NodeId

use of org.graylog2.plugin.system.NodeId in project graylog2-server by Graylog2.

the class InputServiceImpl method findForThisNode.

@Override
public Input findForThisNode(String nodeId, String id) throws NotFoundException, IllegalArgumentException {
    final List<BasicDBObject> forThisNode = ImmutableList.of(new BasicDBObject(MessageInput.FIELD_NODE_ID, nodeId), new BasicDBObject(MessageInput.FIELD_GLOBAL, false));
    final List<BasicDBObject> query = ImmutableList.of(new BasicDBObject("_id", new ObjectId(id)), new BasicDBObject("$and", forThisNode));
    final DBObject o = findOne(InputImpl.class, new BasicDBObject("$and", query));
    if (o == null) {
        throw new NotFoundException("Couldn't find input " + id + " on Graylog node " + nodeId);
    } else {
        return new InputImpl((ObjectId) o.get("_id"), o.toMap());
    }
}
Also used : BasicDBObject(com.mongodb.BasicDBObject) ObjectId(org.bson.types.ObjectId) NotFoundException(org.graylog2.database.NotFoundException) DBObject(com.mongodb.DBObject) BasicDBObject(com.mongodb.BasicDBObject)

Example 2 with NodeId

use of org.graylog2.plugin.system.NodeId 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 where processing will be paused.", 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 3 with NodeId

use of org.graylog2.plugin.system.NodeId in project graylog2-server by Graylog2.

the class ClusterSystemShutdownResource method shutdown.

@POST
@Timed
@ApiOperation(value = "Shutdown node gracefully.", notes = "Attempts to process all buffered and cached messages before exiting, " + "shuts down inputs first to make sure that no new messages are accepted.")
@AuditEvent(type = AuditEventTypes.NODE_SHUTDOWN_INITIATE)
public void shutdown(@ApiParam(name = "nodeId", value = "The id of the node to shutdown.", required = true) @PathParam("nodeId") String nodeId) throws IOException, NodeNotFoundException {
    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.getCode()) {
        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) ApiOperation(io.swagger.annotations.ApiOperation) AuditEvent(org.graylog2.audit.jersey.AuditEvent)

Example 4 with NodeId

use of org.graylog2.plugin.system.NodeId 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 5 with NodeId

use of org.graylog2.plugin.system.NodeId 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)

Aggregations

Test (org.junit.Test)13 Timed (com.codahale.metrics.annotation.Timed)7 ApiOperation (io.swagger.annotations.ApiOperation)7 Node (org.graylog2.cluster.Node)7 WebApplicationException (javax.ws.rs.WebApplicationException)6 Before (org.junit.Before)6 ChainingClassLoader (org.graylog2.shared.plugins.ChainingClassLoader)5 GET (javax.ws.rs.GET)4 Path (javax.ws.rs.Path)4 Settings (org.elasticsearch.common.settings.Settings)4 ElasticsearchConfiguration (org.graylog2.configuration.ElasticsearchConfiguration)4 File (java.io.File)3 RequiresPermissions (org.apache.shiro.authz.annotation.RequiresPermissions)3 ClusterConfigServiceImpl (org.graylog2.cluster.ClusterConfigServiceImpl)3 JadConfig (com.github.joschi.jadconfig.JadConfig)2 InMemoryRepository (com.github.joschi.jadconfig.repositories.InMemoryRepository)2 BasicDBObject (com.mongodb.BasicDBObject)2 DBObject (com.mongodb.DBObject)2 Map (java.util.Map)2 PUT (javax.ws.rs.PUT)2