Skip to content

Commit 9480266

Browse files
committed
#295 rest api of restarting executor
1 parent 07d2321 commit 9480266

File tree

4 files changed

+46
-6
lines changed

4 files changed

+46
-6
lines changed

saturn-console-api/src/main/java/com/vip/saturn/job/console/domain/ServerBriefInfo.java

+16-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
/**
2-
* Copyright 2016 vip.com. <p> Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
3-
* except in compliance with the License. You may obtain a copy of the License at
2+
* Copyright 2016 vip.com.
3+
* <p>
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
5+
* the License. You may obtain a copy of the License at
46
*
57
* http://www.apache.org/licenses/LICENSE-2.0
68
*
79
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
810
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
9-
* specific language governing permissions and limitations under the License. </p>
11+
* specific language governing permissions and limitations under the License.
12+
* </p>
1013
*/
1114

1215
package com.vip.saturn.job.console.domain;
@@ -40,6 +43,8 @@ public final class ServerBriefInfo implements Serializable {
4043

4144
private boolean isContainer;
4245

46+
private boolean isRestarting;
47+
4348
private String groupName;
4449

4550
public ServerBriefInfo(String executorName) {
@@ -90,6 +95,14 @@ public void setStatus(ServerStatus status) {
9095
this.status = status;
9196
}
9297

98+
public boolean isRestarting() {
99+
return isRestarting;
100+
}
101+
102+
public void setRestarting(boolean restarting) {
103+
isRestarting = restarting;
104+
}
105+
93106
public String getVersion() {
94107
return this.version;
95108
}

saturn-console-api/src/main/java/com/vip/saturn/job/console/service/helper/SystemConfigProperties.java

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ public class SystemConfigProperties {
99

1010
public static final String MAX_JOB_NUM = "MAX_JOB_NUM";
1111

12+
public static final String MAX_SECONDS_FORCE_KILL_EXECUTOR = "MAX_SECONDS_FORCE_KILL_EXECUTOR";
13+
1214
public static final String CONSOLE_ZK_CLUSTER_MAPPING = "CONSOLE_ZK_CLUSTER_MAPPING";
1315

1416
public static final String IDC_CONSOLE_DOMAIN_MAPPING = "IDC_CONSOLE_DOMAIN_MAPPING";

saturn-console-api/src/main/java/com/vip/saturn/job/console/service/impl/ExecutorServiceImpl.java

+26-3
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,19 @@
1212
import com.vip.saturn.job.console.service.ExecutorService;
1313
import com.vip.saturn.job.console.service.JobService;
1414
import com.vip.saturn.job.console.service.RegistryCenterService;
15+
import com.vip.saturn.job.console.service.SystemConfigService;
16+
import com.vip.saturn.job.console.service.helper.SystemConfigProperties;
1517
import com.vip.saturn.job.console.utils.ExecutorNodePath;
1618
import com.vip.saturn.job.console.utils.JobNodePath;
1719
import com.vip.saturn.job.console.utils.SaturnConsoleUtils;
18-
import java.util.List;
19-
import javax.annotation.Resource;
2020
import org.apache.commons.lang3.StringUtils;
2121
import org.slf4j.Logger;
2222
import org.slf4j.LoggerFactory;
23-
import org.springframework.stereotype.Service;
2423
import org.springframework.util.CollectionUtils;
2524

25+
import javax.annotation.Resource;
26+
import java.util.List;
27+
2628
/**
2729
* Default implementation of ExecutorService.
2830
*
@@ -33,6 +35,8 @@ public class ExecutorServiceImpl implements ExecutorService {
3335

3436
private static final Logger log = LoggerFactory.getLogger(ExecutorServiceImpl.class);
3537

38+
private static final int DEFAULT_MAX_SECONDS_FORCE_KILL_EXECUTOR = 300;
39+
3640
@Resource
3741
private CuratorRepository curatorRepository;
3842

@@ -42,6 +46,9 @@ public class ExecutorServiceImpl implements ExecutorService {
4246
@Resource
4347
private RegistryCenterService registryCenterService;
4448

49+
@Resource
50+
private SystemConfigService systemConfigService;
51+
4552
@Override
4653
public List<ServerBriefInfo> getExecutors(String namespace) throws SaturnJobConsoleException {
4754
return getExecutors(namespace, null);
@@ -88,6 +95,22 @@ private ServerBriefInfo getServerBriefInfo(String executorName, CuratorFramework
8895
} else {
8996
executorInfo.setStatus(ServerStatus.OFFLINE);
9097
}
98+
99+
String restartNodePath = ExecutorNodePath.getExecutorRestartNodePath(executorName);
100+
long restartTriggerTime = curatorFrameworkOp.getCtime(restartNodePath);
101+
long now = System.currentTimeMillis();
102+
103+
long maxRestartInv = systemConfigService.getIntegerValue(SystemConfigProperties.MAX_SECONDS_FORCE_KILL_EXECUTOR,
104+
DEFAULT_MAX_SECONDS_FORCE_KILL_EXECUTOR) * 1000L;
105+
106+
// 如果executor在线并且restart结点存在,restarting结点存在的时间<300s,executor状态列显示RESTARTING;
107+
if (0 != restartTriggerTime && now - restartTriggerTime < maxRestartInv
108+
&& ServerStatus.ONLINE.equals(executorInfo.getStatus())) {
109+
executorInfo.setRestarting(true);
110+
} else {
111+
executorInfo.setRestarting(false);
112+
}
113+
91114
// 是否已被摘流量
92115
executorInfo.setNoTraffic(curatorFrameworkOp
93116
.checkExists(ExecutorNodePath.getExecutorNoTrafficNodePath(executorName)));

saturn-console-api/src/main/resources/system-config-meta.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ job_configs:
88
executor_configs:
99
- name: ALARM_RAISED_ON_EXECUTOR_RESTART
1010
desc_zh: executor restart是否发送告警
11+
- name: MAX_SECONDS_FORCE_KILL_EXECUTOR
12+
desc_zh: executor stop时最长等待时间
1113

1214
cluster_configs:
1315
- name: CONSOLE_ZK_CLUSTER_MAPPING

0 commit comments

Comments
 (0)