Skip to content

Commit

Permalink
For #240.
Browse files Browse the repository at this point in the history
  • Loading branch information
haocao committed Mar 23, 2017
1 parent 2cc16e8 commit 428146f
Show file tree
Hide file tree
Showing 31 changed files with 527 additions and 485 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ public static void main(final String[] args) throws Exception {
RestfulServer restfulServer = new RestfulServer(PORT);
restfulServer.addFilter(WwwAuthFilter.class, "/")
.addFilter(WwwAuthFilter.class, "*.html")
.addFilter(WwwAuthFilter.class, "*.js")
.addFilter(WwwAuthFilter.class, "*.css")
.start(LiteJobRestfulApi.class.getPackage().getName(), Optional.of(CONSOLE_PATH));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,11 @@

package com.dangdang.ddframe.job.lite.console.restful;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import javax.sql.DataSource;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.UriInfo;

import org.apache.commons.dbcp.BasicDataSource;

import com.dangdang.ddframe.job.event.rdb.JobEventRdbSearch;
import com.dangdang.ddframe.job.event.type.JobExecutionEvent;
import com.dangdang.ddframe.job.event.type.JobStatusTraceEvent;
import com.dangdang.ddframe.job.event.rdb.JobEventRdbSearch.Condition;
import com.dangdang.ddframe.job.event.rdb.JobEventRdbSearch.Result;
import com.dangdang.ddframe.job.event.type.JobExecutionEvent;
import com.dangdang.ddframe.job.event.type.JobStatusTraceEvent;
import com.dangdang.ddframe.job.lite.console.domain.DataSourceConfiguration;
import com.dangdang.ddframe.job.lite.console.service.JobAPIService;
import com.dangdang.ddframe.job.lite.console.service.impl.JobAPIServiceImpl;
Expand All @@ -52,6 +32,24 @@
import com.dangdang.ddframe.job.lite.lifecycle.domain.ServerInfo;
import com.google.common.base.Optional;
import com.google.common.base.Strings;
import org.apache.commons.dbcp.BasicDataSource;

import javax.sql.DataSource;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.UriInfo;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Path("/job")
public class LiteJobRestfulApi {
Expand Down Expand Up @@ -102,92 +100,92 @@ public Collection<ExecutionInfo> getExecutionInfo(@PathParam("jobName") final St
@Path("/trigger")
@Consumes(MediaType.APPLICATION_JSON)
public void triggerJob(final ServerInfo jobServer) {
jobAPIService.getJobOperatorAPI().trigger(Optional.of(jobServer.getJobName()), Optional.of(jobServer.getIp()));
jobAPIService.getJobOperatorAPI().trigger(Optional.of(jobServer.getJobName()), Optional.of(jobServer.getIp()), Optional.of(jobServer.getInstanceId()));
}

@POST
@Path("/pause")
@Consumes(MediaType.APPLICATION_JSON)
public void pauseJob(final ServerInfo jobServer) {
jobAPIService.getJobOperatorAPI().pause(Optional.of(jobServer.getJobName()), Optional.of(jobServer.getIp()));
jobAPIService.getJobOperatorAPI().pause(Optional.of(jobServer.getJobName()), Optional.of(jobServer.getIp()), Optional.of(jobServer.getInstanceId()));
}

@POST
@Path("/resume")
@Consumes(MediaType.APPLICATION_JSON)
public void resumeJob(final ServerInfo jobServer) {
jobAPIService.getJobOperatorAPI().resume(Optional.of(jobServer.getJobName()), Optional.of(jobServer.getIp()));
jobAPIService.getJobOperatorAPI().resume(Optional.of(jobServer.getJobName()), Optional.of(jobServer.getIp()), Optional.of(jobServer.getInstanceId()));
}

@POST
@Path("/triggerAll/name")
@Consumes(MediaType.APPLICATION_JSON)
public void triggerAllJobsByJobName(final ServerInfo jobServer) {
jobAPIService.getJobOperatorAPI().trigger(Optional.of(jobServer.getJobName()), Optional.<String>absent());
jobAPIService.getJobOperatorAPI().trigger(Optional.of(jobServer.getJobName()), Optional.<String>absent(), Optional.<String>absent());
}

@POST
@Path("/pauseAll/name")
@Consumes(MediaType.APPLICATION_JSON)
public void pauseAllJobsByJobName(final ServerInfo jobServer) {
jobAPIService.getJobOperatorAPI().pause(Optional.of(jobServer.getJobName()), Optional.<String>absent());
jobAPIService.getJobOperatorAPI().pause(Optional.of(jobServer.getJobName()), Optional.<String>absent(), Optional.<String>absent());
}

@POST
@Path("/resumeAll/name")
@Consumes(MediaType.APPLICATION_JSON)
public void resumeAllJobsByJobName(final ServerInfo jobServer) {
jobAPIService.getJobOperatorAPI().resume(Optional.of(jobServer.getJobName()), Optional.<String>absent());
jobAPIService.getJobOperatorAPI().resume(Optional.of(jobServer.getJobName()), Optional.<String>absent(), Optional.<String>absent());
}

@POST
@Path("/triggerAll/ip")
@Consumes(MediaType.APPLICATION_JSON)
public void triggerAllJobs(final ServerInfo jobServer) {
jobAPIService.getJobOperatorAPI().trigger(Optional.<String>absent(), Optional.of(jobServer.getIp()));
jobAPIService.getJobOperatorAPI().trigger(Optional.<String>absent(), Optional.of(jobServer.getIp()), Optional.of(jobServer.getInstanceId()));
}

@POST
@Path("/pauseAll/ip")
@Consumes(MediaType.APPLICATION_JSON)
public void pauseAllJobs(final ServerInfo jobServer) {
jobAPIService.getJobOperatorAPI().pause(Optional.<String>absent(), Optional.of(jobServer.getIp()));
jobAPIService.getJobOperatorAPI().pause(Optional.<String>absent(), Optional.of(jobServer.getIp()), Optional.of(jobServer.getInstanceId()));
}

@POST
@Path("/resumeAll/ip")
@Consumes(MediaType.APPLICATION_JSON)
public void resumeAllJobs(final ServerInfo jobServer) {
jobAPIService.getJobOperatorAPI().resume(Optional.<String>absent(), Optional.of(jobServer.getIp()));
jobAPIService.getJobOperatorAPI().resume(Optional.<String>absent(), Optional.of(jobServer.getIp()), Optional.of(jobServer.getInstanceId()));
}

@POST
@Path("/shutdown")
@Consumes(MediaType.APPLICATION_JSON)
public void shutdownJob(final ServerInfo jobServer) {
jobAPIService.getJobOperatorAPI().shutdown(Optional.of(jobServer.getJobName()), Optional.of(jobServer.getIp()));
jobAPIService.getJobOperatorAPI().shutdown(Optional.of(jobServer.getJobName()), Optional.of(jobServer.getIp()), Optional.of(jobServer.getInstanceId()));
}

@POST
@Path("/remove")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Collection<String> removeJob(final ServerInfo jobServer) {
return jobAPIService.getJobOperatorAPI().remove(Optional.of(jobServer.getJobName()), Optional.of(jobServer.getIp()));
return jobAPIService.getJobOperatorAPI().remove(Optional.of(jobServer.getJobName()), Optional.of(jobServer.getIp()), Optional.of(jobServer.getInstanceId()));
}

@POST
@Path("/disable")
@Consumes(MediaType.APPLICATION_JSON)
public void disableJob(final ServerInfo jobServer) {
jobAPIService.getJobOperatorAPI().disable(Optional.of(jobServer.getJobName()), Optional.of(jobServer.getIp()));
jobAPIService.getJobOperatorAPI().disable(Optional.of(jobServer.getJobName()), Optional.of(jobServer.getIp()), Optional.of(jobServer.getInstanceId()));
}

@POST
@Path("/enable")
@Consumes(MediaType.APPLICATION_JSON)
public void enableJob(final ServerInfo jobServer) {
jobAPIService.getJobOperatorAPI().enable(Optional.of(jobServer.getJobName()), Optional.of(jobServer.getIp()));
jobAPIService.getJobOperatorAPI().enable(Optional.of(jobServer.getJobName()), Optional.of(jobServer.getIp()), Optional.of(jobServer.getInstanceId()));
}

@GET
Expand All @@ -196,15 +194,15 @@ public void enableJob(final ServerInfo jobServer) {
@Produces(MediaType.APPLICATION_JSON)
public Result<JobExecutionEvent> findJobExecutionEvents(@Context final UriInfo info) throws ParseException {
JobEventRdbSearch jobEventRdbSearch = new JobEventRdbSearch(setUpEventTraceDataSource());
return jobEventRdbSearch.findJobExecutionEvents(buildCondition(info, new String[]{"jobName", "taskId", "ip", "isSuccess"}));
return jobEventRdbSearch.findJobExecutionEvents(buildCondition(info, new String[]{"jobName", "ip", "isSuccess"}));
}

@GET
@Path("events/statusTraces")
@Consumes(MediaType.APPLICATION_JSON)
public Result<JobStatusTraceEvent> findJobStatusTraceEvents(@Context final UriInfo info) throws ParseException {
JobEventRdbSearch jobEventRdbSearch = new JobEventRdbSearch(setUpEventTraceDataSource());
return jobEventRdbSearch.findJobStatusTraceEvents(buildCondition(info, new String[]{"jobName", "taskId", "slaveId", "source", "executionType", "state"}));
return jobEventRdbSearch.findJobStatusTraceEvents(buildCondition(info, new String[]{"jobName", "source", "executionType", "state"}));
}

private DataSource setUpEventTraceDataSource() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,18 @@

package com.dangdang.ddframe.job.lite.console.restful;

import java.util.Collection;
import com.dangdang.ddframe.job.lite.console.service.JobAPIService;
import com.dangdang.ddframe.job.lite.console.service.impl.JobAPIServiceImpl;
import com.dangdang.ddframe.job.lite.lifecycle.domain.ServerBriefInfo;
import com.dangdang.ddframe.job.lite.lifecycle.domain.ServerInfo;

import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import com.dangdang.ddframe.job.lite.console.service.JobAPIService;
import com.dangdang.ddframe.job.lite.console.service.impl.JobAPIServiceImpl;
import com.dangdang.ddframe.job.lite.lifecycle.domain.ServerBriefInfo;
import com.dangdang.ddframe.job.lite.lifecycle.domain.ServerInfo;
import java.util.Collection;

@Path("/server")
public class ServerRestfulApi {
Expand All @@ -44,10 +43,10 @@ public Collection<ServerBriefInfo> getAllServersBriefInfo() {
}

@GET
@Path("/jobs/{ip}")
@Path("/jobs/{ip}/{instanceId}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Collection<ServerInfo> getJobs(@PathParam("ip") final String ip) {
return jobAPIService.getServerStatisticsAPI().getJobs(ip);
public Collection<ServerInfo> getJobs(@PathParam("ip") final String ip, @PathParam("instanceId") final String instanceId) {
return jobAPIService.getServerStatisticsAPI().getJobs(ip, instanceId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ <h4>事件追踪数据源配置</h4>
</section>
<section class="content">
<table id="data-sources" data-pagination="true" data-page-list="[10, 20, 50, 100]"></table>
<button type="button" class="label label-success" data-toggle="modal" id="add-data-source">添加</button>
<button type="button" class="btn-xs btn-success" data-toggle="modal" id="add-data-source">添加</button>
</section>
</div>
<div id="add-data-source-center" class="modal" tabindex="-1" role="dialog">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ <h4>注册中心配置</h4>
</section>
<section class="content">
<table id="reg-centers" data-pagination="true" data-page-list="[10, 20, 50, 100]"></table>
<button type="button" class="label label-success" data-toggle="modal" id="add-register">添加</button>
<button type="button" class="btn-xs btn-success" data-toggle="modal" id="add-register">添加</button>
</section>
</div>
<div id="add-reg-center" class="modal" tabindex="-1" role="dialog">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,5 @@ <h4>历史作业执行轨迹 </h4>
<script src="lib/input-mask/jquery.inputmask.js"></script>
<script src="lib/input-mask/jquery.inputmask.date.extensions.js"></script>
<script src="lib/input-mask/jquery.inputmask.extensions.js"></script>
<script src="js/common/formatter.js"></script>
<script src="js/util/formatter.js"></script>
<script src="js/history/job_event_trace_history.js"></script>
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,5 @@ <h4>历史作业执行状态 </h4>
<script src="lib/input-mask/jquery.inputmask.js"></script>
<script src="lib/input-mask/jquery.inputmask.date.extensions.js"></script>
<script src="lib/input-mask/jquery.inputmask.extensions.js"></script>
<script src="js/common/formatter.js"></script>
<script src="js/util/formatter.js"></script>
<script src="js/history/job_event_trace_history.js"></script>
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<div class="index-content">
<section class="content">
<h4>服务器IP地址:<span id="server-ip"></span></h4>
<h4>服务器IP地址:<span id="server-ip"></span></h4><br/>
<h4>服务器实例ID:<span id="server-instance-id"></span></h4>
<table id="jobs"></table>
<span id="chosen-job-name" class="hide"></span>
</section>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@
<nav class="navbar navbar-static-top" role="navigation">
<div id="navbar" class="navbar-custom-menu">
<ul class="nav navbar-nav">
<li class="dropdown"><a href="#" class="dropdown-toggle" data-toggle="dropdown">注册中心管理<span class="caret"></span></a>
<li class="dropdown"><a href="#" class="dropdown-toggle" data-toggle="dropdown">注册中心<span class="caret"></span></a>
<ul class="dropdown-menu" id="registry-center-dimension"></ul>
</li>
<li class="dropdown"><a href="#" class="dropdown-toggle" data-toggle="dropdown">事件追踪数据源管理<span class="caret"></span></a>
<li class="dropdown"><a href="#" class="dropdown-toggle" data-toggle="dropdown">事件追踪数据源<span class="caret"></span></a>
<ul class="dropdown-menu" id="data-source-dimension"></ul>
</li>
<li><a href="#" data-toggle="control-sidebar"><i class="fa fa-gears"></i></a></li>
Expand Down Expand Up @@ -65,10 +65,6 @@
<li class="treeview" id="server">
<a href="#">
<i class="fa fa-tasks">&nbsp;&nbsp;作业状态</i><i class="pull-right fa fa-angle-left "></i>
<div class="pull-right">
<span id="server-nav-tag" class="label label-primary"></span>
<span id="job-nav-tag" class="label label-primary"></span>
</div>
</a>
<ul class="treeview-menu">
<li><a href="#" id="server-status" class="sub-menu"><i class="fa fa-circle-o"></i>服务器维度</a></li>
Expand Down Expand Up @@ -124,7 +120,7 @@ <h4 class="control-sidebar-heading">更换主题皮肤</h4>
<span class="down-span-right"></span>
</div>
</a>
<p class="text-center no-margin">黑白</p>
<p class="text-center no-margin">白色</p>
</li>
<li>
<a href="javascript:void(0);" data-skin="skin-purple" class="clearfix full-opacity-hover">
Expand Down Expand Up @@ -196,7 +192,7 @@ <h4 class="control-sidebar-heading">更换主题皮肤</h4>
<span class="down-span-right"></span>
</div>
</a>
<p class="text-center no-margin">黑白高亮</p>
<p class="text-center no-margin">白色高亮</p>
</li>
<li>
<a href="javascript:void(0);" data-skin="skin-purple-light" class="clearfix full-opacity-hover">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ function bindConnectButtons() {
$("#reg-centers").bootstrapTable("refresh");
renderRegCenterForDashboardNav();
getJobNavTag();
getServerNavTag();
showSuccessDialog();
} else {
showFailureDialog("switch-reg-center-failure-dialog");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,6 @@ function renderJobsOverview() {
url: "/api/job/jobs",
method: "get",
cache: false,
rowStyle: function (row, index) {
var strclass = "";
if ("OK" === row.status) {
strclass = "success";
} else if ("MANUALLY_DISABLED" === row.status) {
strclass = "info";
} else if ("PARTIAL_ALIVE" === row.status) {
strclass = "warning";
} else if ("ALL_CRASHED" === row.status) {
strclass = "danger";
} else {
return {};
}
return { classes: strclass }
},
columns:
[{
field: "jobName",
Expand All @@ -38,13 +23,34 @@ function renderJobsOverview() {
field: "description",
title: "描述"
}, {
fidle: "operation",
field: "status",
title: "状态",
formatter: "statusFormatter"
}, {
field: "operation",
title: "操作",
formatter: "generateOperationButtons"
}]
});
}

function statusFormatter(value, row) {
switch(value) {
case "OK":
return "<span class='label label-success'>全部可用</span>";
break;
case "MANUALLY_DISABLED":
return "<span class='label label-info'>被禁用</span>";
break;
case "PARTIAL_ALIVE":
return "<span class='label label-warning'>部分可用</span>";
break;
case "ALL_CRASHED":
return "<span class='label label-danger'>全部宕机</span>";
break;
}
}

function generateOperationButtons(val, row) {
var modifyButton = "<button operation='modifyJob' class='btn-xs btn-warning' jobName='" + row.jobName + "'>修改</button>";
var removeButton = "<button operation='removeJob' class='btn-xs btn-danger' jobName='" + row.jobName + "'>删除</button>";
Expand Down
Loading

0 comments on commit 428146f

Please sign in to comment.