[web-app,manager] 监控启动取消纳管功能
This commit is contained in:
@@ -93,4 +93,29 @@ public class MonitorsController {
|
||||
Message<Void> message = new Message<>();
|
||||
return ResponseEntity.ok(message);
|
||||
}
|
||||
|
||||
@DeleteMapping("manage")
|
||||
@ApiOperation(value = "批量取消纳管监控", notes = "根据监控ID列表批量取消纳管监控项")
|
||||
public ResponseEntity<Message<Void>> cancelManageMonitors(
|
||||
@ApiParam(value = "监控IDs", example = "6565463543") @RequestParam(required = false) List<Long> ids
|
||||
) {
|
||||
if (ids != null && !ids.isEmpty()) {
|
||||
monitorService.cancelManageMonitors(new HashSet<>(ids));
|
||||
}
|
||||
Message<Void> message = new Message<>();
|
||||
return ResponseEntity.ok(message);
|
||||
}
|
||||
|
||||
@GetMapping("manage")
|
||||
@ApiOperation(value = "批量启动纳管监控", notes = "根据监控ID列表批量启动纳管监控项")
|
||||
public ResponseEntity<Message<Void>> enableManageMonitors(
|
||||
@ApiParam(value = "监控IDs", example = "6565463543") @RequestParam(required = false) List<Long> ids
|
||||
) {
|
||||
if (ids != null && !ids.isEmpty()) {
|
||||
monitorService.enableManageMonitors(new HashSet<>(ids));
|
||||
}
|
||||
Message<Void> message = new Message<>();
|
||||
return ResponseEntity.ok(message);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -80,4 +81,16 @@ public interface MonitorService {
|
||||
* @return 查询结果
|
||||
*/
|
||||
Page<Monitor> getMonitors(Specification<Monitor> specification, PageRequest pageRequest);
|
||||
|
||||
/**
|
||||
* 根据监控ID列表批量取消纳管监控项
|
||||
* @param ids 监控IDs
|
||||
*/
|
||||
void cancelManageMonitors(HashSet<Long> ids);
|
||||
|
||||
/**
|
||||
* 根据监控ID列表批量启动纳管监控项
|
||||
* @param ids 监控IDs
|
||||
*/
|
||||
void enableManageMonitors(HashSet<Long> ids);
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
@@ -282,4 +283,48 @@ public class MonitorServiceImpl implements MonitorService {
|
||||
public Page<Monitor> getMonitors(Specification<Monitor> specification, PageRequest pageRequest) {
|
||||
return monitorDao.findAll(specification, pageRequest);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancelManageMonitors(HashSet<Long> ids) {
|
||||
// 更新监控状态 删除对应的监控周期性任务
|
||||
// jobId不删除 待启动纳管之后再次复用jobId
|
||||
List<Monitor> managedMonitors = monitorDao.findMonitorsByIdIn(ids)
|
||||
.stream().filter(monitor ->
|
||||
monitor.getStatus() != CommonConstants.UN_MANAGE && monitor.getJobId() != null)
|
||||
.peek(monitor -> monitor.setStatus(CommonConstants.UN_MANAGE))
|
||||
.collect(Collectors.toList());
|
||||
if (!managedMonitors.isEmpty()) {
|
||||
monitorDao.saveAll(managedMonitors);
|
||||
for (Monitor monitor : managedMonitors) {
|
||||
jobScheduling.cancelAsyncCollectJob(monitor.getJobId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enableManageMonitors(HashSet<Long> ids) {
|
||||
// 更新监控状态 新增对应的监控周期性任务
|
||||
List<Monitor> unManagedMonitors = monitorDao.findMonitorsByIdIn(ids)
|
||||
.stream().filter(monitor ->
|
||||
monitor.getStatus() == CommonConstants.UN_MANAGE && monitor.getJobId() != null)
|
||||
.peek(monitor -> monitor.setStatus(CommonConstants.AVAILABLE))
|
||||
.collect(Collectors.toList());
|
||||
if (!unManagedMonitors.isEmpty()) {
|
||||
monitorDao.saveAll(unManagedMonitors);
|
||||
for (Monitor monitor : unManagedMonitors) {
|
||||
// 构造采集任务Job实体
|
||||
Job appDefine = appService.getAppDefine(monitor.getApp());
|
||||
appDefine.setMonitorId(monitor.getId());
|
||||
appDefine.setInterval(monitor.getIntervals());
|
||||
appDefine.setCyclic(true);
|
||||
appDefine.setTimestamp(System.currentTimeMillis());
|
||||
List<Param> params = paramDao.findParamsByMonitorId(monitor.getId());
|
||||
List<Configmap> configmaps = params.stream().map(param ->
|
||||
new Configmap(param.getField(), param.getValue(), param.getType())).collect(Collectors.toList());
|
||||
appDefine.setConfigmap(configmaps);
|
||||
// 下发采集任务
|
||||
jobScheduling.addAsyncCollectJob(appDefine);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,11 +26,11 @@
|
||||
<i nz-icon nzType="delete" nzTheme="outline"></i>
|
||||
删除
|
||||
</button>
|
||||
<button nz-button nzType="primary">
|
||||
<button nz-button nzType="primary" (click)="onEnableManageMonitors()">
|
||||
<i nz-icon nzType="up-circle" nzTheme="outline"></i>
|
||||
启动纳管
|
||||
启用纳管
|
||||
</button>
|
||||
<button nz-button nzType="primary">
|
||||
<button nz-button nzType="primary" (click)="onCancelManageMonitors()">
|
||||
<i nz-icon nzType="down-circle" nzTheme="outline"></i>
|
||||
取消纳管
|
||||
</button>
|
||||
@@ -93,13 +93,13 @@
|
||||
<button nz-button nzType="primary" (click)="onEditOneMonitor(data.id)">
|
||||
<i nz-icon nzType="edit" nzTheme="outline"></i>
|
||||
</button>
|
||||
<button nz-button nzType="primary"(click)="onDeleteOneMonitor(data.id)">
|
||||
<button nz-button nzType="primary" (click)="onDeleteOneMonitor(data.id)">
|
||||
<i nz-icon nzType="delete" nzTheme="outline"></i>
|
||||
</button>
|
||||
<button nz-button nzType="primary">
|
||||
<button nz-button nzType="primary" (click)="onEnableManageOneMonitor(data.id)">
|
||||
<i nz-icon nzType="up-circle" nzTheme="outline"></i>
|
||||
</button>
|
||||
<button nz-button nzType="primary">
|
||||
<button nz-button nzType="primary" (click)="onCancelManageOneMonitor(data.id)">
|
||||
<i nz-icon nzType="down-circle" nzTheme="outline"></i>
|
||||
</button>
|
||||
</td>
|
||||
|
||||
@@ -38,6 +38,8 @@ export class MonitorListComponent implements OnInit {
|
||||
this.app = paramMap.get("app") || '';
|
||||
this.pageIndex = 1;
|
||||
this.pageSize = 8;
|
||||
this.checkedMonitorIds = new Set<number>();
|
||||
this.tableLoading = true;
|
||||
this.loadMonitorTable();
|
||||
});
|
||||
}
|
||||
@@ -138,6 +140,97 @@ export class MonitorListComponent implements OnInit {
|
||||
);
|
||||
}
|
||||
|
||||
onCancelManageMonitors() {
|
||||
if (this.checkedMonitorIds == null || this.checkedMonitorIds.size === 0) {
|
||||
this.notifySvc.warning("未选中任何待取消项!","");
|
||||
return;
|
||||
}
|
||||
this.modal.confirm({
|
||||
nzTitle: '请确认是否批量取消纳管!',
|
||||
nzOkText: '确定',
|
||||
nzCancelText: '取消',
|
||||
nzOkDanger: true,
|
||||
nzOkType: "primary",
|
||||
nzOnOk: () => this.cancelManageMonitors(this.checkedMonitorIds)
|
||||
});
|
||||
}
|
||||
|
||||
onCancelManageOneMonitor(monitorId: number) {
|
||||
let monitors = new Set<number>();
|
||||
monitors.add(monitorId);
|
||||
this.modal.confirm({
|
||||
nzTitle: '请确认是否取消纳管!',
|
||||
nzOkText: '确定',
|
||||
nzCancelText: '取消',
|
||||
nzOkDanger: true,
|
||||
nzOkType: "primary",
|
||||
nzOnOk: () => this.cancelManageMonitors(monitors)
|
||||
});
|
||||
}
|
||||
|
||||
cancelManageMonitors(monitors: Set<number>) {
|
||||
const cancelManage$ = this.monitorSvc.cancelManageMonitors(monitors)
|
||||
.subscribe(message => {
|
||||
cancelManage$.unsubscribe();
|
||||
if (message.code === 0) {
|
||||
this.notifySvc.success("取消纳管成功!", "");
|
||||
this.loadMonitorTable();
|
||||
} else {
|
||||
this.notifySvc.error("取消纳管失败!", message.msg);
|
||||
}
|
||||
},
|
||||
error => {
|
||||
cancelManage$.unsubscribe();
|
||||
this.notifySvc.error("取消纳管失败!", error.msg)
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
onEnableManageMonitors() {
|
||||
if (this.checkedMonitorIds == null || this.checkedMonitorIds.size === 0) {
|
||||
this.notifySvc.warning("未选中任何待启用纳管项!","");
|
||||
return;
|
||||
}
|
||||
this.modal.confirm({
|
||||
nzTitle: '请确认是否批量启用纳管!',
|
||||
nzOkText: '确定',
|
||||
nzCancelText: '取消',
|
||||
nzOkDanger: true,
|
||||
nzOkType: "primary",
|
||||
nzOnOk: () => this.enableManageMonitors(this.checkedMonitorIds)
|
||||
});
|
||||
}
|
||||
|
||||
onEnableManageOneMonitor(monitorId: number) {
|
||||
let monitors = new Set<number>();
|
||||
monitors.add(monitorId);
|
||||
this.modal.confirm({
|
||||
nzTitle: '请确认是否启用纳管!',
|
||||
nzOkText: '确定',
|
||||
nzCancelText: '取消',
|
||||
nzOkDanger: true,
|
||||
nzOkType: "primary",
|
||||
nzOnOk: () => this.enableManageMonitors(monitors)
|
||||
});
|
||||
}
|
||||
|
||||
enableManageMonitors(monitors: Set<number>) {
|
||||
const enableManage$ = this.monitorSvc.enableManageMonitors(monitors)
|
||||
.subscribe(message => {
|
||||
enableManage$.unsubscribe();
|
||||
if (message.code === 0) {
|
||||
this.notifySvc.success("启用纳管成功!", "");
|
||||
this.loadMonitorTable();
|
||||
} else {
|
||||
this.notifySvc.error("启用纳管失败!", message.msg);
|
||||
}
|
||||
},
|
||||
error => {
|
||||
enableManage$.unsubscribe();
|
||||
this.notifySvc.error("启用纳管失败!", error.msg)
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
// begin: 列表多选逻辑
|
||||
checkedAll: boolean = false;
|
||||
|
||||
@@ -8,6 +8,7 @@ import {Monitor} from "../pojo/Monitor";
|
||||
const monitor_uri = "/monitor";
|
||||
const monitors_uri = "/monitors";
|
||||
const detect_monitor_uri = "/monitor/detect"
|
||||
const manage_monitors_uri = "/monitors/manage";
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
@@ -31,13 +32,34 @@ export class MonitorService {
|
||||
public deleteMonitors(monitorIds: Set<number>) : Observable<Message<any>> {
|
||||
let httpParams = new HttpParams();
|
||||
monitorIds.forEach(monitorId => {
|
||||
// 注意HttpParams是不可变对象 需要保存set后返回的对象为最新对象
|
||||
httpParams = httpParams.set('ids', monitorId);
|
||||
// 注意HttpParams是不可变对象 需要保存append后返回的对象为最新对象
|
||||
// append方法可以叠加同一key, set方法会把key之前的值覆盖只留一个key-value
|
||||
httpParams = httpParams.append('ids', monitorId);
|
||||
})
|
||||
const options = { params: httpParams };
|
||||
return this.http.delete<Message<any>>(monitors_uri, options);
|
||||
}
|
||||
|
||||
public cancelManageMonitors(monitorIds: Set<number>) : Observable<Message<any>> {
|
||||
let httpParams = new HttpParams();
|
||||
monitorIds.forEach(monitorId => {
|
||||
// 注意HttpParams是不可变对象 需要保存append后返回的对象为最新对象
|
||||
// append方法可以叠加同一key, set方法会把key之前的值覆盖只留一个key-value
|
||||
httpParams = httpParams.append('ids', monitorId);
|
||||
})
|
||||
const options = { params: httpParams };
|
||||
return this.http.delete<Message<any>>(manage_monitors_uri, options);
|
||||
}
|
||||
|
||||
public enableManageMonitors(monitorIds: Set<number>) : Observable<Message<any>> {
|
||||
let httpParams = new HttpParams();
|
||||
monitorIds.forEach(monitorId => {
|
||||
httpParams = httpParams.append('ids', monitorId);
|
||||
})
|
||||
const options = { params: httpParams };
|
||||
return this.http.get<Message<any>>(manage_monitors_uri, options);
|
||||
}
|
||||
|
||||
public detectMonitor(body: any) : Observable<Message<any>> {
|
||||
return this.http.post<Message<any>>(detect_monitor_uri, body);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user