Skip to content

Commit

Permalink
fix #72
Browse files Browse the repository at this point in the history
  • Loading branch information
terrymanu committed Mar 18, 2016
1 parent 9f6e974 commit d2e89da
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,9 @@ public void resumeAllJobs(final JobServer jobServer) {
public void shutdownJob(final JobServer jobServer) {
jobOperationService.shutdownJob(jobServer.getJobName(), jobServer.getIp());
}

@RequestMapping(value = "remove", method = RequestMethod.POST)
public void removeJob(final JobServer jobServer) {
jobOperationService.removeJob(jobServer.getJobName(), jobServer.getIp());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public void update(final String znode, final Object value) {
public void delete(final String znode) {
try {
if (null != SessionCuratorClient.getCuratorClient().checkExists().forPath(znode)) {
SessionCuratorClient.getCuratorClient().delete().forPath(znode);
SessionCuratorClient.getCuratorClient().delete().deletingChildrenIfNeeded().forPath(znode);
}
} catch (final NoNodeException ex) {
//CHECKSTYLE:OFF
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,6 @@ public interface JobOperationService {
void resumeAllJobsByServer(String serverIp);

void shutdownJob(String jobName, String serverIp);

boolean removeJob(String jobName, String serverIp);
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,13 @@ public void resumeAllJobsByServer(final String serverIp) {
public void shutdownJob(final String jobName, final String serverIp) {
curatorRepository.create(JobNodePath.getServerNodePath(jobName, serverIp, "shutdown"));
}

@Override
public boolean removeJob(final String jobName, final String serverIp) {
if (!curatorRepository.checkExists(JobNodePath.getServerNodePath(jobName, serverIp, "status")) || curatorRepository.checkExists(JobNodePath.getServerNodePath(jobName, serverIp, "shutdown"))) {
curatorRepository.delete(JobNodePath.getServerNodePath(jobName, serverIp));
return true;
}
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ public Collection<JobServer> getJobs(final String serverIp) {
List<String> jobs = curatorRepository.getChildren("/");
Collection<JobServer> result = new ArrayList<>(jobs.size());
for (String each : jobs) {
result.add(getJob(serverIp, each));
if (curatorRepository.checkExists(JobNodePath.getServerNodePath(each, serverIp))) {
result.add(getJob(serverIp, each));
}
}
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ public static String getServerNodePath(final String jobName) {
return String.format("/%s/servers", jobName);
}

public static String getServerNodePath(final String jobName, final String serverIp) {
return String.format("%s/%s", getServerNodePath(jobName), serverIp);
}

public static String getServerNodePath(final String jobName, final String serverIp, final String nodeName) {
return String.format("%s/%s/%s", getServerNodePath(jobName), serverIp, nodeName);
}
Expand Down
38 changes: 26 additions & 12 deletions elastic-job-console/src/main/webapp/js/job_detail.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ $(function() {
bindResumeButtons();
bindResumeAllButton();
bindShutdownButtons();
bindRemoveButtons();
});

function renderSettings() {
Expand Down Expand Up @@ -81,18 +82,21 @@ function renderServers() {
leaderStatus = status;
}
var baseTd = "<td>" + data[i].ip + "</td><td>" + data[i].hostName + "</td><td>" + status + "</td><td>" + data[i].processSuccessCount + "</td><td>" + data[i].processFailureCount + "</td><td>" + data[i].sharding + "</td><td>" + (true === leader ? "<span class='glyphicon glyphicon-ok'></span>" : "<span class='glyphicon glyphicon-remove'></span>") + "</td>";
var operationTd;
if ("SHUTDOWN" === status) {
operationTd = "-";
} else if ("STOPED" === status) {
operationTd = "<button operation='resume' class='btn btn-success' ip='" + data[i].ip + "' leader='" + leader + "'>恢复</button>";
} else if ("DISABLED" !== status && "CRASHED" !== status) {
operationTd = "<button operation='stop' class='btn btn-warning' ip='" + data[i].ip + "'" + (leader ? "data-toggle='modal' data-target='#stop-leader-confirm-dialog'" : "") + ">暂停</button>";
} else {
operationTd = "-";
var operationTd = "";
var resumeButton = "<button operation='resume' class='btn btn-success' ip='" + data[i].ip + "' leader='" + leader + "'>恢复</button>";
var stopButton = "<button operation='stop' class='btn btn-warning' ip='" + data[i].ip + "'" + (leader ? "data-toggle='modal' data-target='#stop-leader-confirm-dialog'" : "") + ">暂停</button>";
var shutdownButton = "<button operation='shutdown' class='btn btn-danger' ip='" + data[i].ip + "'>关闭</button>";
var removeButton = "<button operation='remove' class='btn btn-danger' ip='" + data[i].ip + "'>删除</button>";
if ("STOPED" === status) {
operationTd = resumeButton + "&nbsp;";
} else if ("DISABLED" !== status && "CRASHED" !== status && "SHUTDOWN" !== status) {
operationTd = stopButton + "&nbsp;";
}
if ("SHUTDOWN" !== status) {
operationTd = operationTd + shutdownButton + "&nbsp;";
}
if ("-" !== operationTd) {
operationTd = operationTd + "&nbsp;<button operation='shutdown' class='btn btn-danger' ip='" + data[i].ip + "'>关闭</button>";
if ("SHUTDOWN" === status || "CRASHED" === status) {
operationTd = operationTd + removeButton;
}
operationTd = "<td>" + operationTd + "</td>";
var trClass = "";
Expand Down Expand Up @@ -187,4 +191,14 @@ function bindShutdownButtons() {
showSuccessDialog();
});
});
}
}

function bindRemoveButtons() {
$(document).on("click", "button[operation='remove']", function(event) {
var jobName = $("#job-name").text();
$.post("job/remove", {jobName : jobName, ip : $(event.currentTarget).attr("ip")}, function (data) {
renderServers();
showSuccessDialog();
});
});
}
41 changes: 29 additions & 12 deletions elastic-job-console/src/main/webapp/js/server_detail.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ $(function() {
bindStopAllButton();
bindResumeAllButton();
bindShutdownButtons();
bindRemoveButtons();
});

function renderJobs() {
Expand All @@ -16,22 +17,26 @@ function renderJobs() {
var status = data[i].status;
var leader = data[i].leader;
var baseTd = "<td>" + data[i].jobName + "</td><td>" + status + "</td><td>" + data[i].processSuccessCount + "</td><td>" + data[i].processFailureCount + "</td><td>" + data[i].sharding + "</td><td>" + (true === leader ? "<span class='glyphicon glyphicon-ok'></span>" : "<span class='glyphicon glyphicon-remove'></span>") + "</td>";
var operationTd;
if ("SHUTDOWN" === status) {
operationTd = "-";
} else if ("STOPED" === status) {
var operationTd = "";
var resumeButton = "<button operation='resume' class='btn btn-success' job-name='" + data[i].jobName + "'>恢复</button>";
var resumeWithWarningButton = "<button operation='resume' class='btn btn-success disabled' job-name='" + data[i].jobName + "' disabled title='先恢复主节点才能恢复从节点作业'>恢复</button>";
var stopButton = "<button operation='stop' class='btn btn-warning' job-name='" + data[i].jobName + "'" + (leader ? "data-toggle='modal' data-target='#stop-leader-confirm-dialog'" : "") + ">暂停</button>";
var shutdownButton = "<button operation='shutdown' class='btn btn-danger' job-name='" + data[i].jobName + "'>关闭</button>";
var removeButton = "<button operation='remove' class='btn btn-danger' job-name='" + data[i].jobName + "'>删除</button>";
if ("STOPED" === status) {
if (data[i].leaderStoped && !leader) {
operationTd = "<button operation='resume' class='btn btn-success disabled' job-name='" + data[i].jobName + "' disabled title='先恢复主节点才能恢复从节点作业'>恢复</button>";
operationTd = resumeWithWarningButton + "&nbsp;";
} else {
operationTd = "<button operation='resume' class='btn btn-success' job-name='" + data[i].jobName + "'>恢复</button>";
operationTd = resumeButton + "&nbsp;";
}
} else if ("DISABLED" !== status && "CRASHED" !== status) {
operationTd = "<button operation='stop' class='btn btn-warning' job-name='" + data[i].jobName + "'" + (leader ? "data-toggle='modal' data-target='#stop-leader-confirm-dialog'" : "") + ">暂停</button>";
} else {
operationTd = "";
} else if ("DISABLED" !== status && "CRASHED" !== status && "SHUTDOWN" !== status) {
operationTd = stopButton + "&nbsp;";
}
if ("-" !== operationTd) {
operationTd = operationTd + "&nbsp;<button operation='shutdown' class='btn btn-danger' job-name='" + data[i].jobName + "'>关闭</button>";
if ("SHUTDOWN" !== status) {
operationTd = operationTd + shutdownButton + "&nbsp;";
}
if ("SHUTDOWN" === status || "CRASHED" === status) {
operationTd = operationTd + removeButton;
}
operationTd = "<td>" + operationTd + "</td>";
var trClass = "";
Expand Down Expand Up @@ -109,3 +114,15 @@ function bindShutdownButtons() {
$("#chosen-job-name").text($(event.currentTarget).attr("job-name"));
});
}

function bindRemoveButtons() {
$(document).on("click", "button[operation='remove']", function(event) {
$.post("job/remove", {jobName : $(event.currentTarget).attr("job-name"), ip : $("#server-ip").text()}, function (data) {
renderJobs();
showSuccessDialog();
});
});
$(document).on("click", "button[operation='remove']", function(event) {
$("#chosen-job-name").text($(event.currentTarget).attr("job-name"));
});
}
1 change: 1 addition & 0 deletions elastic-job-doc/content/post/release_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ weight=1
### 功能提升

1. [ISSUE #71](https://github.com/dangdangdotcom/elastic-job/issues/71) 作业关闭功能(shutdown)
1. [ISSUE #72](https://github.com/dangdangdotcom/elastic-job/issues/72) 关闭的作业可删除

### 缺陷修正

Expand Down

0 comments on commit d2e89da

Please sign in to comment.