Skip to content

Commit

Permalink
#371 rest api for getting the count of alarm-jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
IvyLee-cn committed Mar 9, 2018
1 parent 4127af7 commit 86dde2c
Show file tree
Hide file tree
Showing 11 changed files with 265 additions and 201 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.vip.saturn.job.console.controller.gui;

import com.alibaba.fastjson.JSON;
import com.vip.saturn.job.console.aop.annotation.Audit;
import com.vip.saturn.job.console.aop.annotation.AuditParam;
import com.vip.saturn.job.console.controller.SuccessResponseEntity;
Expand Down Expand Up @@ -35,7 +34,6 @@
import org.apache.commons.lang3.StringUtils;
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 @@ -93,13 +91,8 @@ public JobOverviewVo getJobOverviewVo(String namespace) throws SaturnJobConsoleE

private void updateAbnormalJobSizeInOverview(String namespace, JobOverviewVo jobOverviewVo) {
try {
String result = alarmStatisticsService.getAbnormalJobsByNamespace(namespace);
if (result != null) {
List<AbnormalJob> abnormalJobs = JSON.parseArray(result, AbnormalJob.class);
if (abnormalJobs != null) {
jobOverviewVo.setAbnormalNumber(abnormalJobs.size());
}
}
List<AbnormalJob> abnormalJobList = alarmStatisticsService.getAbnormalJobListByNamespace(namespace);
jobOverviewVo.setAbnormalNumber(abnormalJobList.size());
} catch (Exception e) {
log.error(e.getMessage(), e);
}
Expand Down Expand Up @@ -291,6 +284,7 @@ public SuccessResponseEntity batchRemoveJob(final HttpServletRequest request,
successJobNames.add(jobName);
} catch (Exception e) {
failJobNames.add(jobName);
log.info("remove job failed, cause of {}", e);
}
}
if (!failJobNames.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import com.vip.saturn.job.console.service.AlarmStatisticsService;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
Expand All @@ -28,21 +27,28 @@ public class NamespaceAlarmStatisticsController extends AbstractGUIController {
@GetMapping(value = "/abnormalJobs")
public SuccessResponseEntity getAbnormalJobs(@PathVariable String namespace)
throws SaturnJobConsoleException {
return new SuccessResponseEntity(alarmStatisticsService.getAbnormalJobsByNamespace(namespace));
return new SuccessResponseEntity(alarmStatisticsService.getAbnormalJobsStringByNamespace(namespace));
}

@ApiResponses(value = {@ApiResponse(code = 200, message = "Success/Fail", response = RequestResult.class)})
@GetMapping(value = "/unableFailoverJobs")
public SuccessResponseEntity getUnableFailoverJobs(@PathVariable String namespace)
throws SaturnJobConsoleException {
return new SuccessResponseEntity(alarmStatisticsService.getUnableFailoverJobsByNamespace(namespace));
return new SuccessResponseEntity(alarmStatisticsService.getUnableFailoverJobsStringByNamespace(namespace));
}

@ApiResponses(value = {@ApiResponse(code = 200, message = "Success/Fail", response = RequestResult.class)})
@GetMapping(value = "/timeout4AlarmJobs")
public SuccessResponseEntity getTimeout4AlarmJobs(@PathVariable String namespace)
throws SaturnJobConsoleException {
return new SuccessResponseEntity(alarmStatisticsService.getTimeout4AlarmJobsByNamespace(namespace));
return new SuccessResponseEntity(alarmStatisticsService.getTimeout4AlarmJobsStringByNamespace(namespace));
}

@ApiResponses(value = {@ApiResponse(code = 200, message = "Success/Fail", response = RequestResult.class)})
@GetMapping(value = "/countOfAlarmJobs")
public SuccessResponseEntity getCountOfAlarmJobs(@PathVariable String namespace)
throws SaturnJobConsoleException {
return new SuccessResponseEntity(alarmStatisticsService.getCountOfAlarmJobsByNamespace(namespace));
}

@ApiResponses(value = {@ApiResponse(code = 200, message = "Success/Fail", response = RequestResult.class)})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
Expand All @@ -33,29 +32,36 @@ public class OverallAlarmStatisticsController extends AbstractGUIController {
public SuccessResponseEntity getAbnormalJobs(@RequestParam(required = false) String zkClusterKey)
throws SaturnJobConsoleException {
if (StringUtils.isBlank(zkClusterKey)) {
return new SuccessResponseEntity(alarmStatisticsService.getAbnormalJobs());
return new SuccessResponseEntity(alarmStatisticsService.getAbnormalJobsString());
}
return new SuccessResponseEntity(alarmStatisticsService.getAbnormalJobs(zkClusterKey));
return new SuccessResponseEntity(alarmStatisticsService.getAbnormalJobsStringByZKCluster(zkClusterKey));
}

@ApiResponses(value = {@ApiResponse(code = 200, message = "Success/Fail", response = RequestResult.class)})
@GetMapping(value = "/unableFailoverJobs")
public SuccessResponseEntity getUnableFailoverJobs(@RequestParam(required = false) String zkClusterKey)
throws SaturnJobConsoleException {
if (StringUtils.isBlank(zkClusterKey)) {
return new SuccessResponseEntity(alarmStatisticsService.getUnableFailoverJobs());
return new SuccessResponseEntity(alarmStatisticsService.getUnableFailoverJobsString());
}
return new SuccessResponseEntity(alarmStatisticsService.getUnableFailoverJobs(zkClusterKey));
return new SuccessResponseEntity(alarmStatisticsService.getUnableFailoverJobsStringByZKCluster(zkClusterKey));
}

@ApiResponses(value = {@ApiResponse(code = 200, message = "Success/Fail", response = RequestResult.class)})
@GetMapping(value = "/timeout4AlarmJobs")
public SuccessResponseEntity getTimeout4AlarmJobs(@RequestParam(required = false) String zkClusterKey)
throws SaturnJobConsoleException {
if (StringUtils.isBlank(zkClusterKey)) {
return new SuccessResponseEntity(alarmStatisticsService.getTimeout4AlarmJobs());
return new SuccessResponseEntity(alarmStatisticsService.getTimeout4AlarmJobsString());
}
return new SuccessResponseEntity(alarmStatisticsService.getTimeout4AlarmJobs(zkClusterKey));
return new SuccessResponseEntity(alarmStatisticsService.getTimeout4AlarmJobsStringByZKCluster(zkClusterKey));
}

@ApiResponses(value = {@ApiResponse(code = 200, message = "Success/Fail", response = RequestResult.class)})
@GetMapping(value = "/countOfAlarmJobs")
public SuccessResponseEntity getCountOfAlarmJobs()
throws SaturnJobConsoleException {
return new SuccessResponseEntity(alarmStatisticsService.getCountOfAlarmJobs());
}

@ApiResponses(value = {@ApiResponse(code = 200, message = "Success/Fail", response = RequestResult.class)})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@
*/
public class AbnormalJob extends AbstractAlarmJob {

private String uuid;

private String jobDegree;

private String timeZone;

private long nextFireTime;
Expand All @@ -20,9 +16,7 @@ public class AbnormalJob extends AbstractAlarmJob {

private String cause;

private boolean read = false;

private transient long nextFireTimeAfterEnabledMtimeOrLastCompleteTime;
private long nextFireTimeAfterEnabledMtimeOrLastCompleteTime;

public AbnormalJob() {
}
Expand All @@ -31,22 +25,6 @@ public AbnormalJob(String jobName, String domainName, String nns, String degree)
super(jobName, domainName, nns, degree);
}

public String getUuid() {
return uuid;
}

public void setUuid(String uuid) {
this.uuid = uuid;
}

public String getJobDegree() {
return jobDegree;
}

public void setJobDegree(String jobDegree) {
this.jobDegree = jobDegree;
}

public String getTimeZone() {
return timeZone;
}
Expand Down Expand Up @@ -88,14 +66,6 @@ public void setNextFireTimeAfterEnabledMtimeOrLastCompleteTime(
this.nextFireTimeAfterEnabledMtimeOrLastCompleteTime = nextFireTimeAfterEnabledMtimeOrLastCompleteTime;
}

public boolean isRead() {
return read;
}

public void setRead(boolean read) {
this.read = read;
}

@Override
public int hashCode() {
int result = jobName.hashCode();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ public class AbstractAlarmJob {
*/
protected String degree;

protected String uuid;

protected boolean read;

protected String jobDegree;

public AbstractAlarmJob() {
}

Expand All @@ -41,4 +47,29 @@ public String getDomainName() {
public void setDomainName(String domainName) {
this.domainName = domainName;
}

public String getUuid() {

return uuid;
}

public void setUuid(String uuid) {
this.uuid = uuid;
}

public boolean isRead() {
return read;
}

public void setRead(boolean read) {
this.read = read;
}

public String getJobDegree() {
return jobDegree;
}

public void setJobDegree(String jobDegree) {
this.jobDegree = jobDegree;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.vip.saturn.job.console.domain;

import java.io.Serializable;

/**
* Created by ivy01.li on 2018/3/9.
*/
public class AlarmJobCount implements Serializable {
private static final long serialVersionUID = 1L;

private String alarmJobType;
private int count;

public AlarmJobCount() {}

public AlarmJobCount(String alarmJobType, int count) {
this.alarmJobType = alarmJobType;
this.count = count;
}

public String getAlarmJobType() {
return alarmJobType;
}

public int getCount() {
return count;
}

public void setAlarmJobType(String alarmJobType) {
this.alarmJobType = alarmJobType;
}

public void setCount(int count) {
this.count = count;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@
*/
public class Timeout4AlarmJob extends AbstractAlarmJob {

private String uuid;

private boolean read;

private String jobDegree;

private int timeout4AlarmSeconds;

private List<Integer> timeoutItems = new ArrayList<>();
Expand All @@ -25,30 +19,6 @@ public Timeout4AlarmJob(String jobName, String domainName, String nns, String de
super(jobName, domainName, nns, degree);
}

public String getUuid() {
return uuid;
}

public void setUuid(String uuid) {
this.uuid = uuid;
}

public boolean isRead() {
return read;
}

public void setRead(boolean read) {
this.read = read;
}

public String getJobDegree() {
return jobDegree;
}

public void setJobDegree(String jobDegree) {
this.jobDegree = jobDegree;
}

public int getTimeout4AlarmSeconds() {
return timeout4AlarmSeconds;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
package com.vip.saturn.job.console.service;

import com.vip.saturn.job.console.domain.AbnormalJob;
import com.vip.saturn.job.console.domain.AlarmJobCount;
import com.vip.saturn.job.console.domain.Timeout4AlarmJob;
import com.vip.saturn.job.console.exception.SaturnJobConsoleException;

import java.util.List;

/**
* @author hebelala
*/
public interface AlarmStatisticsService {

// 所有集群的告警统计

String getAbnormalJobs() throws SaturnJobConsoleException;
String getAbnormalJobsString() throws SaturnJobConsoleException;

String getUnableFailoverJobsString() throws SaturnJobConsoleException;

String getUnableFailoverJobs() throws SaturnJobConsoleException;
String getTimeout4AlarmJobsString() throws SaturnJobConsoleException;

String getTimeout4AlarmJobs() throws SaturnJobConsoleException;
List<AlarmJobCount> getCountOfAlarmJobs() throws SaturnJobConsoleException;

String getAbnormalContainers() throws SaturnJobConsoleException;

Expand All @@ -25,21 +30,25 @@ public interface AlarmStatisticsService {

// 集群的告警统计

String getAbnormalJobs(String zkClusterKey) throws SaturnJobConsoleException;
String getAbnormalJobsStringByZKCluster(String zkClusterKey) throws SaturnJobConsoleException;

String getUnableFailoverJobs(String zkClusterKey) throws SaturnJobConsoleException;
String getUnableFailoverJobsStringByZKCluster(String zkClusterKey) throws SaturnJobConsoleException;

String getTimeout4AlarmJobs(String zkClusterKey) throws SaturnJobConsoleException;
String getTimeout4AlarmJobsStringByZKCluster(String zkClusterKey) throws SaturnJobConsoleException;

String getAbnormalContainers(String zkClusterKey) throws SaturnJobConsoleException;

// 域的告警统计

String getAbnormalJobsByNamespace(String namespace) throws SaturnJobConsoleException;
String getAbnormalJobsStringByNamespace(String namespace) throws SaturnJobConsoleException;

String getUnableFailoverJobsStringByNamespace(String namespace) throws SaturnJobConsoleException;

String getTimeout4AlarmJobsStringByNamespace(String namespace) throws SaturnJobConsoleException;

String getUnableFailoverJobsByNamespace(String namespace) throws SaturnJobConsoleException;
List<AlarmJobCount> getCountOfAlarmJobsByNamespace(String namespace) throws SaturnJobConsoleException;

String getTimeout4AlarmJobsByNamespace(String namespace) throws SaturnJobConsoleException;
List<AbnormalJob> getAbnormalJobListByNamespace(String namespace) throws SaturnJobConsoleException;

String getAbnormalContainersByNamespace(String namespace) throws SaturnJobConsoleException;

Expand Down
Loading

0 comments on commit 86dde2c

Please sign in to comment.