Search in sources :

Example 1 with NodeNotFoundException

use of org.graylog2.cluster.NodeNotFoundException 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 2 with NodeNotFoundException

use of org.graylog2.cluster.NodeNotFoundException 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 3 with NodeNotFoundException

use of org.graylog2.cluster.NodeNotFoundException 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 4 with NodeNotFoundException

use of org.graylog2.cluster.NodeNotFoundException 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 NodeNotFoundException

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

the class NodePingThread method doRun.

@Override
public synchronized // This method is "synchronized" because we are also calling it directly in AutomaticLeaderElectionService
void doRun() {
    final boolean isLeader = leaderElectionService.isLeader();
    try {
        Node node = nodeService.byNodeId(serverStatus.getNodeId());
        nodeService.markAsAlive(node, isLeader, httpConfiguration.getHttpPublishUri().resolve(HttpConfiguration.PATH_API));
    } catch (NodeNotFoundException e) {
        LOG.warn("Did not find meta info of this node. Re-registering.");
        nodeService.registerServer(serverStatus.getNodeId().toString(), isLeader, httpConfiguration.getHttpPublishUri().resolve(HttpConfiguration.PATH_API), Tools.getLocalCanonicalHostname());
    }
    try {
        // Remove old nodes that are no longer running. (Just some housekeeping)
        nodeService.dropOutdated();
        // Check that we still have a leader node in the cluster, if not, warn the user.
        if (nodeService.isAnyLeaderPresent()) {
            if (fixNoLeaderNotification()) {
                activityWriter.write(new Activity("Notification condition [" + NotificationImpl.Type.NO_LEADER + "] " + "has been fixed.", NodePingThread.class));
            }
        } else {
            Notification notification = notificationService.buildNow().addNode(serverStatus.getNodeId().toString()).addType(Notification.Type.NO_LEADER).addSeverity(Notification.Severity.URGENT);
            notificationService.publishIfFirst(notification);
        }
    } catch (Exception e) {
        LOG.warn("Caught exception during node ping.", e);
    }
}
Also used : NodeNotFoundException(org.graylog2.cluster.NodeNotFoundException) Node(org.graylog2.cluster.Node) Activity(org.graylog2.shared.system.activities.Activity) Notification(org.graylog2.notifications.Notification) NodeNotFoundException(org.graylog2.cluster.NodeNotFoundException)

Aggregations

Node (org.graylog2.cluster.Node)9 Timed (com.codahale.metrics.annotation.Timed)8 ApiOperation (io.swagger.annotations.ApiOperation)7 WebApplicationException (javax.ws.rs.WebApplicationException)7 GET (javax.ws.rs.GET)5 Path (javax.ws.rs.Path)5 RequiresPermissions (org.apache.shiro.authz.annotation.RequiresPermissions)4 RemoteSystemResource (org.graylog2.shared.rest.resources.system.RemoteSystemResource)3 PUT (javax.ws.rs.PUT)2 NoAuditEvent (org.graylog2.audit.jersey.NoAuditEvent)2 Notification (org.graylog2.notifications.Notification)2 Response (retrofit2.Response)2 ApiResponses (io.swagger.annotations.ApiResponses)1 POST (javax.ws.rs.POST)1 RequiresAuthentication (org.apache.shiro.authz.annotation.RequiresAuthentication)1 AuditEvent (org.graylog2.audit.jersey.AuditEvent)1 NodeNotFoundException (org.graylog2.cluster.NodeNotFoundException)1 PluginList (org.graylog2.rest.models.system.plugins.responses.PluginList)1 SystemJVMResponse (org.graylog2.rest.models.system.responses.SystemJVMResponse)1 SystemProcessBufferDumpResponse (org.graylog2.rest.models.system.responses.SystemProcessBufferDumpResponse)1