4
4
import com .google .common .collect .ImmutableMap ;
5
5
import org .nlpcn .jcoder .domain .TaskInfo ;
6
6
import org .nlpcn .jcoder .filter .AuthoritiesManager ;
7
+ import org .nlpcn .jcoder .scheduler .QuartzSchedulerManager ;
7
8
import org .nlpcn .jcoder .scheduler .TaskException ;
8
- import org .nlpcn .jcoder .scheduler .ThreadManager ;
9
+ import org .nlpcn .jcoder .scheduler .TaskRunManager ;
9
10
import org .nlpcn .jcoder .service .ProxyService ;
10
11
import org .nlpcn .jcoder .util .ApiException ;
11
12
import org .nlpcn .jcoder .util .Restful ;
12
13
import org .nlpcn .jcoder .util .StaticValue ;
13
14
import org .nlpcn .jcoder .util .StringUtil ;
14
15
import org .nlpcn .jcoder .util .dao .BasicDao ;
15
- import org .nutz .http .Response ;
16
16
import org .nutz .ioc .loader .annotation .Inject ;
17
17
import org .nutz .ioc .loader .annotation .IocBean ;
18
18
import org .nutz .mvc .annotation .*;
19
19
import org .slf4j .Logger ;
20
20
import org .slf4j .LoggerFactory ;
21
21
22
- import javax .xml .transform .Result ;
23
22
import java .util .ArrayList ;
24
23
import java .util .Collections ;
25
24
import java .util .List ;
26
25
import java .util .Map ;
27
- import java .util .concurrent .ArrayBlockingQueue ;
28
- import java .util .concurrent .BlockingQueue ;
29
- import java .util .concurrent .LinkedBlockingDeque ;
30
26
import java .util .stream .Collectors ;
31
27
32
28
@ IocBean
@@ -75,7 +71,7 @@ public Restful list(@Param("hostPorts[]") String[] hostPorts, @Param("groupName"
75
71
for (Map .Entry <String , Restful > entry : post .entrySet ()) {
76
72
Restful ref = entry .getValue ();
77
73
if (!ref .isOk ()) {
78
- LOG .error (entry .getKey ()+ ":" + entry .getValue ().toJsonString ());
74
+ LOG .error (entry .getKey () + ":" + entry .getValue ().toJsonString ());
79
75
continue ;
80
76
}
81
77
JSONObject jsonObject = ref .obj2JsonObject ();
@@ -105,22 +101,22 @@ public Restful list(@Param("hostPorts[]") String[] hostPorts, @Param("groupName"
105
101
if (StringUtil .isNotBlank (type )) {
106
102
switch (type ) {
107
103
case "threads" :
108
- threads = ThreadManager .getAllThread ();
104
+ threads = TaskRunManager .getAllThread ();
109
105
break ;
110
106
case "schedulers" :
111
- schedulers = ThreadManager .getAllScheduler ();
107
+ schedulers = QuartzSchedulerManager .getAllScheduler ();
112
108
break ;
113
109
case "actions" :
114
- actions = ThreadManager .getAllAction ();
110
+ actions = TaskRunManager .getAllAction ();
115
111
break ;
116
112
default :
117
113
throw new ApiException (500 , "err type " + type );
118
114
}
119
115
120
116
} else {
121
- threads = ThreadManager .getAllThread ();
122
- schedulers = ThreadManager .getAllScheduler ();
123
- actions = ThreadManager .getAllAction ();
117
+ threads = TaskRunManager .getAllThread ();
118
+ schedulers = QuartzSchedulerManager .getAllScheduler ();
119
+ actions = TaskRunManager .getAllAction ();
124
120
}
125
121
126
122
final String gn = groupName ;
@@ -132,11 +128,11 @@ public Restful list(@Param("hostPorts[]") String[] hostPorts, @Param("groupName"
132
128
133
129
JSONObject json = new JSONObject ();
134
130
135
- json .put ("threads" , threads );
136
- json .put ("schedulers" , schedulers );
137
- json .put ("actions" , actions );
131
+ json .put ("threads" , threads );
132
+ json .put ("schedulers" , schedulers );
133
+ json .put ("actions" , actions );
138
134
139
- return Restful .ok ().obj (json );
135
+ return Restful .ok ().obj (json );
140
136
}
141
137
}
142
138
@@ -146,52 +142,41 @@ public Restful list(@Param("hostPorts[]") String[] hostPorts, @Param("groupName"
146
142
* 停止一个运行的action,或者task
147
143
*/
148
144
@ At
149
- public Restful stop (@ Param ("hostPort" ) String hostPort , @ Param ("key" ) String key ,@ Param (value = "first" , df = "true" ) boolean first ) throws Exception {
150
- if (first ) {
151
- JSONObject json = new JSONObject ();
152
- Map <String , Restful > post = proxyService .post (new String []{hostPort }, "/admin/thread/stop" , ImmutableMap .of ("key" , key ,"first" ,false ), 100000 );
153
- for (Map .Entry <String , Restful > entry : post .entrySet ()) {
154
- Restful ref = entry .getValue ();
155
- if (!ref .isOk ()) {
156
- LOG .error (entry .getKey ()+":" +entry .getValue ().toJsonString ());
157
- continue ;
158
- }
159
- JSONObject jsonObject = ref .obj2JsonObject ();
160
- json .put ("msg" ,jsonObject .getString ("msg" ));
161
- json .put ("flag" ,ref .isOk ());
162
- return Restful .ok ().obj (json );
163
- }
164
- }else {
165
- boolean flag = false ;
166
- String msg = "" ;
167
- JSONObject json = new JSONObject ();
168
- try {
169
- flag = ThreadManager .stop (key );
170
- msg = "停止任务成功!" ;
171
- json .put ("msg" ,msg );
172
- return Restful .ok ().obj (json );
173
- } catch (TaskException e ) {
174
- e .printStackTrace ();
175
- flag = false ;
176
- msg = "停止任务失败!" ;
177
- LOG .error ("stop action err" , e );
178
- json .put ("msg" ,msg );
179
- return Restful .fail ().obj (json );
180
- }
181
- }
182
- return null ;
183
- }
184
-
185
- /**
186
- * 停止一个运行的job的所有实例线程
187
- */
188
- @ At
189
- public void stopAllJob (String groupName , String taskName ) throws Exception {
190
- try {
191
- ThreadManager .stopAllJob (groupName , taskName );
192
- } catch (Exception e ) {
193
- LOG .error ("author err" , e );
194
- throw e ;
145
+ public Restful stop (@ Param ("hostPort" ) String hostPort , @ Param ("key" ) String key , @ Param (value = "first" , df = "true" ) boolean first ) throws Exception {
146
+ if (first ) {
147
+ JSONObject json = new JSONObject ();
148
+ Map <String , Restful > post = proxyService .post (new String []{hostPort }, "/admin/thread/stop" , ImmutableMap .of ("key" , key , "first" , false ), 100000 );
149
+ for (Map .Entry <String , Restful > entry : post .entrySet ()) {
150
+ Restful ref = entry .getValue ();
151
+ if (!ref .isOk ()) {
152
+ LOG .error (entry .getKey () + ":" + entry .getValue ().toJsonString ());
153
+ continue ;
154
+ }
155
+ return Restful .instance (ref .isOk (),ref .getMessage ()) ;
156
+ }
157
+ } else {
158
+ try {
159
+ TaskRunManager .stop (key );
160
+ return Restful .ok ().msg ("停止任务成功!" );
161
+ } catch (TaskException e ) {
162
+ e .printStackTrace ();
163
+ LOG .error ("stop action err" , e );
164
+ return Restful .fail ().msg ("停止任务失败!" );
165
+ }
195
166
}
167
+ return null ;
196
168
}
169
+
170
+ // /**
171
+ // * 停止一个运行的job的所有实例线程
172
+ // */
173
+ // @At
174
+ // public void stopAllJob(String groupName, String taskName) throws Exception {
175
+ // try {
176
+ // TaskRunManager.stopAll(groupName, taskName);
177
+ // } catch (Exception e) {
178
+ // LOG.error("author err", e);
179
+ // throw e;
180
+ // }
181
+ // }
197
182
}
0 commit comments