Skip to content

Commit

Permalink
#295 rest api of restarting executor
Browse files Browse the repository at this point in the history
  • Loading branch information
IvyLee-cn committed Mar 7, 2018
1 parent 5191658 commit 9e7dbfe
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import javax.servlet.http.HttpServletRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
Expand Down Expand Up @@ -215,4 +214,20 @@ public SuccessResponseEntity dump(final HttpServletRequest request,
executorService.dump(namespace, executorName);
return new SuccessResponseEntity();
}

/**
* 一键重启。
*/
@ApiResponses(value = {@ApiResponse(code = 200, message = "Success/Fail", response = RequestResult.class)})
@Audit
@PostMapping(value = "/{executorName}/restart")
public SuccessResponseEntity restart(final HttpServletRequest request,
@AuditParam("namespace") @PathVariable String namespace,
@AuditParam("executorName") @PathVariable String executorName)
throws SaturnJobConsoleException {
// check executor is existed and online.
checkExecutorStatus(namespace, executorName, ServerStatus.ONLINE, "Executor必须在线才可以重启");
executorService.restart(namespace, executorName);
return new SuccessResponseEntity();
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
package com.vip.saturn.job.console.service;

import com.vip.saturn.job.console.domain.JobConfig;
import com.vip.saturn.job.console.domain.RequestResult;
import com.vip.saturn.job.console.domain.ServerAllocationInfo;
import com.vip.saturn.job.console.domain.ServerBriefInfo;
import com.vip.saturn.job.console.domain.ServerStatus;
import com.vip.saturn.job.console.exception.SaturnJobConsoleException;
import java.io.File;
import java.util.List;

/**
Expand Down Expand Up @@ -89,4 +86,12 @@ public interface ExecutorService {
* @param executorName 目标executor
*/
void dump(String namespace, String executorName) throws SaturnJobConsoleException;

/**
* 一键restart。
*
* @param namespace 域
* @param executorName 目标executor
*/
void restart(String namespace, String executorName) throws SaturnJobConsoleException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public List<ServerBriefInfo> getExecutors(String namespace, ServerStatus expecte
CuratorRepository.CuratorFrameworkOp curatorFrameworkOp = getCuratorFrameworkOp(namespace);

List<String> executors = curatorFrameworkOp.getChildren(ExecutorNodePath.getExecutorNodePath());
if (executors == null || executors.size() == 0) {
if (executors == null || executors.isEmpty()) {
return Lists.newArrayList();
}

Expand Down Expand Up @@ -118,10 +118,6 @@ public ServerAllocationInfo getExecutorAllocation(String namespace, String execu

ServerAllocationInfo serverAllocationInfo = new ServerAllocationInfo(executorName);

if (unSystemJobs == null || unSystemJobs.size() == 0) {
return serverAllocationInfo;
}

for (JobConfig jobConfig : unSystemJobs) {
String jobName = jobConfig.getJobName();
String serverNodePath = JobNodePath.getServerNodePath(jobName);
Expand Down Expand Up @@ -201,6 +197,14 @@ public void dump(String namespace, String executorName) throws SaturnJobConsoleE
curatorFrameworkOp.create(dumpNodePath);
}

@Override
public void restart(String namespace, String executorName) throws SaturnJobConsoleException {
CuratorRepository.CuratorFrameworkOp curatorFrameworkOp = getCuratorFrameworkOp(namespace);
String restartNodePath = ExecutorNodePath.getExecutorRestartNodePath(executorName);
curatorFrameworkOp.delete(restartNodePath);
curatorFrameworkOp.create(restartNodePath);
}

private void validateIfExecutorNameExisted(String executorName,
CuratorRepository.CuratorFrameworkOp curatorFrameworkOp) throws SaturnJobConsoleException {
if (!curatorFrameworkOp.checkExists(ExecutorNodePath.getExecutorNodePath(executorName))) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,8 @@ public static String getExecutorDumpNodePath(final String executorName) {
return getExecutorNodePath(executorName, "dump");
}

public static String getExecutorRestartNodePath(final String executorName) {
return getExecutorNodePath(executorName, "restart");
}

}

0 comments on commit 9e7dbfe

Please sign in to comment.