10
10
import com .vip .saturn .job .console .exception .SaturnJobConsoleException ;
11
11
import com .vip .saturn .job .console .exception .SaturnJobConsoleGUIException ;
12
12
import com .vip .saturn .job .console .service .ExecutorService ;
13
+ import com .vip .saturn .job .console .utils .Permissions ;
13
14
import io .swagger .annotations .ApiResponse ;
14
15
import io .swagger .annotations .ApiResponses ;
15
- import java .util .List ;
16
- import javax .annotation .Resource ;
17
- import javax .servlet .http .HttpServletRequest ;
16
+ import org .apache .shiro .authz .annotation .RequiresPermissions ;
18
17
import org .slf4j .Logger ;
19
18
import org .slf4j .LoggerFactory ;
20
- import org .springframework .web .bind .annotation .DeleteMapping ;
21
- import org .springframework .web .bind .annotation .GetMapping ;
22
- import org .springframework .web .bind .annotation .PathVariable ;
23
- import org .springframework .web .bind .annotation .PostMapping ;
24
- import org .springframework .web .bind .annotation .RequestMapping ;
25
- import org .springframework .web .bind .annotation .RequestParam ;
19
+ import org .springframework .web .bind .annotation .*;
20
+
21
+ import javax .annotation .Resource ;
22
+ import javax .servlet .http .HttpServletRequest ;
23
+ import java .util .List ;
26
24
27
25
/**
28
26
* Executor overview related operations.
@@ -46,9 +44,8 @@ public class ExecutorOverviewController extends AbstractGUIController {
46
44
*/
47
45
@ ApiResponses (value = {@ ApiResponse (code = 200 , message = "Success/Fail" , response = RequestResult .class )})
48
46
@ GetMapping
49
- public SuccessResponseEntity getExecutors (final HttpServletRequest request ,
50
- @ PathVariable String namespace , @ RequestParam (required = false ) String status )
51
- throws SaturnJobConsoleException {
47
+ public SuccessResponseEntity getExecutors (final HttpServletRequest request , @ PathVariable String namespace ,
48
+ @ RequestParam (required = false ) String status ) throws SaturnJobConsoleException {
52
49
if ("online" .equalsIgnoreCase (status )) {
53
50
return new SuccessResponseEntity (executorService .getExecutors (namespace , ServerStatus .ONLINE ));
54
51
}
@@ -61,8 +58,8 @@ public SuccessResponseEntity getExecutors(final HttpServletRequest request,
61
58
*/
62
59
@ ApiResponses (value = {@ ApiResponse (code = 200 , message = "Success/Fail" , response = RequestResult .class )})
63
60
@ GetMapping (value = "/{executorName}/allocation" )
64
- public SuccessResponseEntity getExecutorAllocation (final HttpServletRequest request ,
65
- @ PathVariable String namespace , @ PathVariable String executorName ) throws SaturnJobConsoleException {
61
+ public SuccessResponseEntity getExecutorAllocation (final HttpServletRequest request , @ PathVariable String namespace ,
62
+ @ PathVariable String executorName ) throws SaturnJobConsoleException {
66
63
return new SuccessResponseEntity (executorService .getExecutorAllocation (namespace , executorName ));
67
64
}
68
65
@@ -71,10 +68,10 @@ public SuccessResponseEntity getExecutorAllocation(final HttpServletRequest requ
71
68
*/
72
69
@ ApiResponses (value = {@ ApiResponse (code = 200 , message = "Success/Fail" , response = RequestResult .class )})
73
70
@ Audit
71
+ @ RequiresPermissions (Permissions .executorShardAllAtOnce )
74
72
@ PostMapping (value = "/shardAll" )
75
73
public SuccessResponseEntity shardAll (final HttpServletRequest request ,
76
- @ AuditParam ("namespace" ) @ PathVariable String namespace )
77
- throws SaturnJobConsoleException {
74
+ @ AuditParam ("namespace" ) @ PathVariable String namespace ) throws SaturnJobConsoleException {
78
75
executorService .shardAll (namespace );
79
76
return new SuccessResponseEntity ();
80
77
}
@@ -84,12 +81,12 @@ public SuccessResponseEntity shardAll(final HttpServletRequest request,
84
81
*/
85
82
@ ApiResponses (value = {@ ApiResponse (code = 200 , message = "Success/Fail" , response = RequestResult .class )})
86
83
@ Audit
84
+ @ RequiresPermissions (Permissions .executorExtractOrRecoverTraffic )
87
85
@ PostMapping (value = "/{executorName}/traffic" )
88
86
public SuccessResponseEntity extractOrRecoverTraffic (final HttpServletRequest request ,
89
87
@ AuditParam ("namespace" ) @ PathVariable String namespace ,
90
88
@ AuditParam ("executorName" ) @ PathVariable String executorName ,
91
- @ AuditParam ("operation" ) @ RequestParam String operation )
92
- throws SaturnJobConsoleException {
89
+ @ AuditParam ("operation" ) @ RequestParam String operation ) throws SaturnJobConsoleException {
93
90
extractOrRecoverTraffic (namespace , executorName , operation );
94
91
return new SuccessResponseEntity ();
95
92
}
@@ -99,12 +96,12 @@ public SuccessResponseEntity extractOrRecoverTraffic(final HttpServletRequest re
99
96
*/
100
97
@ ApiResponses (value = {@ ApiResponse (code = 200 , message = "Success/Fail" , response = RequestResult .class )})
101
98
@ Audit
99
+ @ RequiresPermissions (Permissions .executorBatchExtractOrRecoverTraffic )
102
100
@ PostMapping (value = "/traffic" )
103
101
public SuccessResponseEntity batchExtractOrRecoverTraffic (final HttpServletRequest request ,
104
102
@ AuditParam ("namespace" ) @ PathVariable String namespace ,
105
103
@ AuditParam ("executorNames" ) @ RequestParam List <String > executorNames ,
106
- @ AuditParam ("operation" ) @ RequestParam String operation )
107
- throws SaturnJobConsoleException {
104
+ @ AuditParam ("operation" ) @ RequestParam String operation ) throws SaturnJobConsoleException {
108
105
List <String > success2ExtractOrRecoverTrafficExecutors = Lists .newArrayList ();
109
106
List <String > fail2ExtractOrRecoverTrafficExecutors = Lists .newArrayList ();
110
107
for (String executorName : executorNames ) {
@@ -120,8 +117,7 @@ public SuccessResponseEntity batchExtractOrRecoverTraffic(final HttpServletReque
120
117
if (!fail2ExtractOrRecoverTrafficExecutors .isEmpty ()) {
121
118
StringBuilder message = new StringBuilder ();
122
119
message .append ("操作成功的executor:" + success2ExtractOrRecoverTrafficExecutors .toString ()).append ("," )
123
- .append ("操作失败的executor:" )
124
- .append (fail2ExtractOrRecoverTrafficExecutors .toString ());
120
+ .append ("操作失败的executor:" ).append (fail2ExtractOrRecoverTrafficExecutors .toString ());
125
121
throw new SaturnJobConsoleGUIException (message .toString ());
126
122
}
127
123
@@ -144,11 +140,11 @@ private void extractOrRecoverTraffic(String namespace, String executorName, Stri
144
140
*/
145
141
@ ApiResponses (value = {@ ApiResponse (code = 200 , message = "Success/Fail" , response = RequestResult .class )})
146
142
@ Audit
143
+ @ RequiresPermissions (Permissions .executorRemove )
147
144
@ DeleteMapping (value = "/{executorName}" )
148
145
public SuccessResponseEntity removeExecutor (final HttpServletRequest request ,
149
146
@ AuditParam ("namespace" ) @ PathVariable String namespace ,
150
- @ AuditParam ("executorName" ) @ PathVariable String executorName )
151
- throws SaturnJobConsoleException {
147
+ @ AuditParam ("executorName" ) @ PathVariable String executorName ) throws SaturnJobConsoleException {
152
148
// check executor is existed and online.
153
149
checkExecutorStatus (namespace , executorName , ServerStatus .OFFLINE , "Executor在线,不能移除" );
154
150
executorService .removeExecutor (namespace , executorName );
@@ -160,11 +156,11 @@ public SuccessResponseEntity removeExecutor(final HttpServletRequest request,
160
156
*/
161
157
@ ApiResponses (value = {@ ApiResponse (code = 200 , message = "Success/Fail" , response = RequestResult .class )})
162
158
@ Audit
159
+ @ RequiresPermissions (Permissions .executorBatchRemove )
163
160
@ DeleteMapping
164
161
public SuccessResponseEntity batchRemoveExecutors (final HttpServletRequest request ,
165
162
@ AuditParam ("namespace" ) @ PathVariable String namespace ,
166
- @ AuditParam ("executorNames" ) @ RequestParam List <String > executorNames )
167
- throws SaturnJobConsoleException {
163
+ @ AuditParam ("executorNames" ) @ RequestParam List <String > executorNames ) throws SaturnJobConsoleException {
168
164
// check executor is existed and online.
169
165
List <String > success2RemoveExecutors = Lists .newArrayList ();
170
166
List <String > fail2RemoveExecutors = Lists .newArrayList ();
@@ -204,11 +200,11 @@ private void checkExecutorStatus(String namespace, String executorName, ServerSt
204
200
*/
205
201
@ ApiResponses (value = {@ ApiResponse (code = 200 , message = "Success/Fail" , response = RequestResult .class )})
206
202
@ Audit
203
+ @ RequiresPermissions (Permissions .executorDump )
207
204
@ PostMapping (value = "/{executorName}/dump" )
208
205
public SuccessResponseEntity dump (final HttpServletRequest request ,
209
206
@ AuditParam ("namespace" ) @ PathVariable String namespace ,
210
- @ AuditParam ("executorName" ) @ PathVariable String executorName )
211
- throws SaturnJobConsoleException {
207
+ @ AuditParam ("executorName" ) @ PathVariable String executorName ) throws SaturnJobConsoleException {
212
208
// check executor is existed and online.
213
209
checkExecutorStatus (namespace , executorName , ServerStatus .ONLINE , "Executor必须在线才可以dump" );
214
210
executorService .dump (namespace , executorName );
@@ -220,11 +216,11 @@ public SuccessResponseEntity dump(final HttpServletRequest request,
220
216
*/
221
217
@ ApiResponses (value = {@ ApiResponse (code = 200 , message = "Success/Fail" , response = RequestResult .class )})
222
218
@ Audit
219
+ @ RequiresPermissions (Permissions .executorRestart )
223
220
@ PostMapping (value = "/{executorName}/restart" )
224
221
public SuccessResponseEntity restart (final HttpServletRequest request ,
225
- @ AuditParam ("namespace" ) @ PathVariable String namespace ,
226
- @ AuditParam ("executorName" ) @ PathVariable String executorName )
227
- throws SaturnJobConsoleException {
222
+ @ AuditParam ("namespace" ) @ PathVariable String namespace ,
223
+ @ AuditParam ("executorName" ) @ PathVariable String executorName ) throws SaturnJobConsoleException {
228
224
// check executor is existed and online.
229
225
checkExecutorStatus (namespace , executorName , ServerStatus .ONLINE , "Executor必须在线才可以重启" );
230
226
executorService .restart (namespace , executorName );
0 commit comments