/
SystemProcessingResource.java
93 lines (80 loc) · 3.47 KB
/
SystemProcessingResource.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/**
* This file is part of Graylog.
*
* Graylog is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Graylog is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Graylog. If not, see <http://www.gnu.org/licenses/>.
*/
package org.graylog2.rest.resources.system;
import com.codahale.metrics.annotation.Timed;
import com.wordnik.swagger.annotations.Api;
import com.wordnik.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.graylog2.plugin.ProcessingPauseLockedException;
import org.graylog2.plugin.ServerStatus;
import org.graylog2.shared.rest.resources.RestResource;
import org.graylog2.shared.security.RestPermissions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.inject.Inject;
import javax.ws.rs.ForbiddenException;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
@RequiresAuthentication
@Api(value = "System/Processing", description = "System processing status control.")
@Path("/system/processing")
public class SystemProcessingResource extends RestResource {
private static final Logger LOG = LoggerFactory.getLogger(SystemProcessingResource.class);
private final ServerStatus serverStatus;
@Inject
public SystemProcessingResource(ServerStatus serverStatus) {
this.serverStatus = serverStatus;
}
// TODO Change to @POST
@PUT
@Timed
@ApiOperation(value = "Pauses message processing",
notes = "If the message journal is enabled, incoming messages will be spooled on disk, if it is disabled, " +
"you might lose messages from inputs which cannot buffer themselves, like AMQP or Kafka-based inputs.")
@Path("pause")
public void pauseProcessing() {
checkPermission(RestPermissions.PROCESSING_CHANGESTATE, serverStatus.getNodeId().toString());
serverStatus.pauseMessageProcessing(false);
LOG.info("Paused message processing - triggered by REST call.");
}
@PUT
@Timed
@ApiOperation(value = "Resume message processing")
@Path("resume")
public void resumeProcessing() {
checkPermission(RestPermissions.PROCESSING_CHANGESTATE, serverStatus.getNodeId().toString());
try {
serverStatus.resumeMessageProcessing();
} catch (ProcessingPauseLockedException e) {
LOG.error("Message processing pause is locked. Returning HTTP 403.");
throw new ForbiddenException(e);
}
LOG.info("Resumed message processing - triggered by REST call.");
}
@PUT
@Timed
@Path("pause/unlock")
public void unlockProcessingPause() {
/*
* This is meant to be only used in exceptional cases, when something that locked the processing pause
* has crashed and never unlocked so we need to unlock manually. #donttellanybody
*/
checkPermission(RestPermissions.PROCESSING_CHANGESTATE, serverStatus.getNodeId().toString());
serverStatus.unlockProcessingPause();
LOG.info("Manually unlocked message processing pause - triggered by REST call.");
}
}