Skip to content

Commit bf208d2

Browse files
committed
update updateCommandStateToFailed
1 parent 3e6a12e commit bf208d2

File tree

10 files changed

+90
-199
lines changed

10 files changed

+90
-199
lines changed

datasophon-api/src/main/java/com/datasophon/api/controller/ClusterAlertQuotaController.java

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,7 @@
11
package com.datasophon.api.controller;
22

3-
import java.io.IOException;
43
import java.util.*;
54

6-
import com.datasophon.api.service.FrameServiceService;
7-
import com.datasophon.common.model.AlertItem;
8-
import com.datasophon.common.model.Generators;
9-
import com.datasophon.common.utils.FreemakerUtils;
10-
import com.datasophon.dao.entity.FrameServiceEntity;
11-
import freemarker.template.TemplateException;
12-
import org.apache.commons.lang.StringUtils;
135
import org.springframework.beans.factory.annotation.Autowired;
146
import org.springframework.web.bind.annotation.*;
157
import com.datasophon.common.utils.Result;
@@ -29,44 +21,6 @@ public class ClusterAlertQuotaController {
2921
@Autowired
3022
private ClusterAlertQuotaService clusterAlertQuotaService;
3123

32-
@Autowired
33-
private FrameServiceService service;
34-
35-
36-
/**
37-
* 列表
38-
*/
39-
@RequestMapping("/generateAlertYml")
40-
public Result list(Integer clusterId) throws IOException, TemplateException {
41-
List<ClusterAlertQuota> list = clusterAlertQuotaService.list();
42-
List<FrameServiceEntity> serviceList = service.list();
43-
for (FrameServiceEntity serviceEntity : serviceList) {
44-
Generators generators = new Generators();
45-
generators.setFilename(serviceEntity.getServiceName().toLowerCase()+".yml");
46-
generators.setConfigFormat("prometheus");
47-
generators.setOutputDirectory("D:\\360downloads\\test\\");
48-
ArrayList<AlertItem> alertItems = new ArrayList<>();
49-
for (ClusterAlertQuota clusterAlertQuota : list) {
50-
if(clusterAlertQuota.getServiceCategory().equals(serviceEntity.getServiceName()) && StringUtils.isNotBlank(clusterAlertQuota.getServiceRoleName())){
51-
AlertItem alertItem = new AlertItem();
52-
alertItem.setAlertName(clusterAlertQuota.getAlertQuotaName());
53-
alertItem.setAlertExpr(clusterAlertQuota.getAlertExpr()+" "+ clusterAlertQuota.getCompareMethod()+" "+clusterAlertQuota.getAlertThreshold());
54-
alertItem.setClusterId(clusterId);
55-
alertItem.setServiceRoleName(clusterAlertQuota.getServiceRoleName());
56-
alertItem.setAlertLevel(clusterAlertQuota.getAlertLevel().getDesc());
57-
alertItem.setAlertAdvice(clusterAlertQuota.getAlertAdvice());
58-
alertItem.setTriggerDuration(clusterAlertQuota.getTriggerDuration());
59-
alertItems.add(alertItem);
60-
}
61-
}
62-
if(alertItems.size() > 0){
63-
FreemakerUtils.generatePromAlertFile(generators,alertItems,serviceEntity.getServiceName());
64-
}
65-
}
66-
67-
return Result.success();
68-
}
69-
7024

7125
/**
7226
* 信息

datasophon-api/src/main/java/com/datasophon/api/controller/ClusterServiceInstanceController.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,8 @@ public Result update(@RequestBody ClusterServiceInstanceEntity clusterServiceIns
9595
* 删除
9696
*/
9797
@RequestMapping("/delete")
98-
public Result delete(@RequestBody Integer[] ids){
99-
clusterServiceInstanceService.removeByIds(Arrays.asList(ids));
100-
101-
return Result.success();
98+
public Result delete(Integer serviceInstanceIds){
99+
return clusterServiceInstanceService.delServiceInstance(serviceInstanceIds);
102100
}
103101

104102
}

datasophon-api/src/main/java/com/datasophon/api/master/ServiceExecuteResultActor.java

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,11 @@
77
import com.datasophon.common.command.SubmitActiveTaskNodeCommand;
88
import com.datasophon.common.enums.ServiceExecuteState;
99
import com.datasophon.common.enums.ServiceRoleType;
10-
import com.datasophon.common.model.DAGGraph;
11-
import com.datasophon.common.model.ServiceExecuteResultMessage;
12-
import com.datasophon.common.model.ServiceNode;
13-
import com.datasophon.common.model.ServiceRoleInfo;
10+
import com.datasophon.common.model.*;
1411
import org.slf4j.Logger;
1512
import org.slf4j.LoggerFactory;
1613

14+
import java.util.ArrayList;
1715
import java.util.List;
1816
import java.util.Map;
1917
import java.util.Set;
@@ -37,23 +35,24 @@ public void onReceive(Object message) throws Throwable {
3735
ServiceNode servicNode = dag.getNode(node);
3836
if (result.getServiceRoleType().equals(ServiceRoleType.MASTER)) {
3937
if (result.getServiceExecuteState().equals(ServiceExecuteState.ERROR)) {
40-
//该节点master角色操作失败,移动到error列表
38+
//move to error list
4139
errorTaskList.put(node, "");
4240
activeTaskList.remove(node);
4341
readyToSubmitTaskList.remove(node);
4442
completeTaskList.put(node, "");
45-
//更改指令执行状态,依赖该节点的下游服务指令状态改为取消
46-
logger.info("{} master roles failed , cancel all next node by hostCommandId {}",node,servicNode.getMasterRoles().get(0).getHostCommandId());
47-
String hostCommandId = servicNode.getMasterRoles().get(0).getHostCommandId();
48-
ProcessUtils.updateCommandStateToFailed( hostCommandId);
43+
//cancel all next node
44+
logger.info("{} master roles failed , cancel all next node by commandId {}", node, servicNode.getCommandId());
45+
List<String> commandIds = new ArrayList<String>();
46+
listCancelCommand(dag,node,commandIds);
47+
ProcessUtils.updateCommandStateToFailed(commandIds);
4948
} else if (result.getServiceExecuteState().equals(ServiceExecuteState.SUCCESS)) {
50-
//该节点master角色指令执行完毕,开始执行worker节点操作
49+
//submit worker node
5150
ServiceNode serviceNode = dag.getNode(node);
5251
List<ServiceRoleInfo> elseRoles = serviceNode.getElseRoles();
5352
if (elseRoles.size() > 0) {
5453
logger.info("start to submit worker/client roles");
5554
for (ServiceRoleInfo elseRole : serviceNode.getElseRoles()) {
56-
ActorRef serviceActor = ActorUtils.getLocalActor(WorkerServiceActor.class, result.getClusterCode() + "-serviceActor-" + node+"-"+elseRole.getHostname());
55+
ActorRef serviceActor = ActorUtils.getLocalActor(WorkerServiceActor.class, result.getClusterCode() + "-serviceActor-" + node + "-" + elseRole.getHostname());
5756
ProcessUtils.buildExecuteServiceRoleCommand(
5857
result.getClusterId(),
5958
result.getCommandType(),
@@ -75,14 +74,25 @@ public void onReceive(Object message) throws Throwable {
7574
readyToSubmitTaskList.remove(node);
7675
}
7776
logger.info("start to submit next node");
78-
tellToSubmitActiveTaskNode(result, dag, activeTaskList, errorTaskList, readyToSubmitTaskList, completeTaskList, submitTaskNodeActor,node);
77+
tellToSubmitActiveTaskNode(result, dag, activeTaskList, errorTaskList, readyToSubmitTaskList, completeTaskList, submitTaskNodeActor, node);
7978
}
8079
}
8180
} else {
8281
unhandled(message);
8382
}
8483
}
8584

85+
public void listCancelCommand(DAGGraph<String, ServiceNode, String> dag, String node, List<String> commandIds) {
86+
if (dag.getSubsequentNodes(node).size() == 0) {
87+
return;
88+
}
89+
Set<String> subsequentNodes = dag.getSubsequentNodes(node);
90+
for (String subsequentNode : subsequentNodes) {
91+
commandIds.add(dag.getNode(subsequentNode).getCommandId());
92+
listCancelCommand(dag, subsequentNode, commandIds);
93+
}
94+
}
95+
8696
private void tellToSubmitActiveTaskNode(ServiceExecuteResultMessage result,
8797
DAGGraph<String, ServiceNode, String> dag,
8898
Map<String, ServiceExecuteState> activeTaskList,
@@ -92,7 +102,7 @@ private void tellToSubmitActiveTaskNode(ServiceExecuteResultMessage result,
92102
ActorRef submitTaskNodeActor,
93103
String node) {
94104
Set<String> subsequentNodes = dag.getSubsequentNodes(node);
95-
logger.info("{}'s subsequent nodes is {}", node , subsequentNodes.toString());
105+
logger.info("{}'s subsequent nodes is {}", node, subsequentNodes.toString());
96106
for (String subsequentNode : subsequentNodes) {
97107
readyToSubmitTaskList.put(subsequentNode, "");
98108
}

datasophon-api/src/main/java/com/datasophon/api/master/SubmitTaskNodeActor.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ public void onReceive(Object message) throws Throwable {
4444
for (String previousNode : previousNodes) {
4545
if (errorTaskList.containsKey(previousNode)) {
4646
readyToSubmitTaskList.remove(node);
47+
}
48+
if(!completeTaskList.containsKey(previousNode)){
49+
readyToSubmitTaskList.remove(node);
4750
continue;
4851
}
4952
}

datasophon-api/src/main/java/com/datasophon/api/service/ClusterServiceInstanceService.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,7 @@ public interface ClusterServiceInstanceService extends IService<ClusterServiceIn
2525
Result getServiceRoleType(Integer serviceInstanceId);
2626

2727
Result configVersionCompare(Integer serviceInstanceId,Integer roleGroupId);
28+
29+
Result delServiceInstance(Integer serviceInstanceId);
2830
}
2931

datasophon-api/src/main/java/com/datasophon/api/service/ClusterServiceRoleInstanceService.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,7 @@ public interface ClusterServiceRoleInstanceService extends IService<ClusterServi
4444
List<ClusterServiceRoleInstanceEntity> getObsoleteService(Integer id);
4545

4646
List<ClusterServiceRoleInstanceEntity> getStoppedRoleInstanceOnHost(Integer clusterId, String hostname, ServiceRoleState state);
47+
48+
void reomveRoleInstance(Integer serviceInstanceId);
4749
}
4850

datasophon-api/src/main/java/com/datasophon/api/service/impl/ClusterServiceInstanceServiceImpl.java

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@
2424

2525

2626
import com.datasophon.dao.mapper.ClusterServiceInstanceMapper;
27+
import org.springframework.transaction.annotation.Transactional;
2728

2829

2930
@Service("clusterServiceInstanceService")
31+
@Transactional
3032
public class ClusterServiceInstanceServiceImpl extends ServiceImpl<ClusterServiceInstanceMapper, ClusterServiceInstanceEntity> implements ClusterServiceInstanceService {
3133

3234
@Autowired
@@ -50,9 +52,6 @@ public class ClusterServiceInstanceServiceImpl extends ServiceImpl<ClusterServic
5052
@Autowired
5153
private FrameServiceRoleService frameServiceRoleService;
5254

53-
@Autowired
54-
private ClusterServiceCommandService commandService;
55-
5655
@Autowired
5756
private ClusterServiceRoleGroupConfigService roleGroupConfigService;
5857

@@ -183,4 +182,25 @@ public Result configVersionCompare( Integer serviceInstanceId,Integer roleGroupI
183182
}
184183
return Result.success(map);
185184
}
185+
186+
@Override
187+
public Result delServiceInstance(Integer serviceInstanceId) {
188+
//has role instance?
189+
if(hasRoleInstance(serviceInstanceId)){
190+
return Result.error("has running role instance");
191+
}
192+
this.removeById(serviceInstanceId);
193+
//remove role instance
194+
roleInstanceService.reomveRoleInstance(serviceInstanceId);
195+
return Result.success();
196+
}
197+
198+
private boolean hasRoleInstance(Integer serviceInstanceId) {
199+
200+
List<ClusterServiceRoleInstanceEntity> list = roleInstanceService.getRunningServiceRoleInstanceListByServiceId(serviceInstanceId);
201+
if(list.size() > 0){
202+
return true;
203+
}
204+
return false;
205+
}
186206
}

datasophon-api/src/main/java/com/datasophon/api/service/impl/ClusterServiceRoleInstanceServiceImpl.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,4 +254,11 @@ public List<ClusterServiceRoleInstanceEntity> getStoppedRoleInstanceOnHost(Integ
254254
.eq(Constants.HOSTNAME, hostname)
255255
.eq(Constants.SERVICE_ROLE_STATE, state));
256256
}
257+
258+
@Override
259+
public void reomveRoleInstance(Integer serviceInstanceId) {
260+
this.remove(new QueryWrapper<ClusterServiceRoleInstanceEntity>()
261+
.eq(Constants.SERVICE_ID,serviceInstanceId)
262+
.eq(Constants.SERVICE_ROLE_STATE,ServiceRoleState.STOP));
263+
}
257264
}

datasophon-api/src/main/java/com/datasophon/api/utils/ProcessUtils.java

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -151,38 +151,37 @@ public static void saveHostInstallInfo(StartWorkerMessage message, String cluste
151151
clusterHostService.save(clusterHostEntity);
152152
}
153153

154-
public static void updateCommandStateToFailed(String hostCommandId) {
155-
logger.info("hostCommandId is {}", hostCommandId);
156-
//worker以及下游节点全部取消
157-
ClusterServiceCommandHostCommandService service = SpringTool.getApplicationContext().getBean(ClusterServiceCommandHostCommandService.class);
158-
ClusterServiceCommandHostCommandEntity hostCommand = service.getByHostCommandId(hostCommandId);
159-
logger.info("hostCommandName is {}", hostCommand.getCommandName());
160-
ActorRef commandActor = ActorUtils.getLocalActor(ServiceCommandActor.class, "commandActor");
161-
List<ClusterServiceCommandHostCommandEntity> hostCommandList = service.getHostCommandListByCommandId(hostCommand.getCommandId());
162-
for (ClusterServiceCommandHostCommandEntity hostCommandEntity : hostCommandList) {
163-
if (hostCommandEntity.getCommandState() == CommandState.RUNNING && hostCommandEntity.getHostCommandId() != hostCommandId) {
164-
logger.info("{} host command set to failed", hostCommandEntity.getCommandName());
165-
hostCommandEntity.setCommandState(CommandState.FAILED);
166-
hostCommandEntity.setCommandProgress(100);
167-
service.updateByHostCommandId(hostCommandEntity);
168-
UpdateCommandHostMessage message = new UpdateCommandHostMessage();
169-
message.setCommandId(hostCommand.getCommandId());
170-
message.setCommandHostId(hostCommandEntity.getCommandHostId());
171-
message.setHostname(hostCommandEntity.getHostname());
172-
if (hostCommand.getServiceRoleType() == RoleType.MASTER) {
173-
message.setServiceRoleType(ServiceRoleType.MASTER);
174-
} else {
175-
message.setServiceRoleType(ServiceRoleType.WORKER);
154+
public static void updateCommandStateToFailed(List<String> commandIds) {
155+
for (String commandId : commandIds) {
156+
logger.info("command id is {}", commandId);
157+
//cancel worker and sub node
158+
ClusterServiceCommandHostCommandService service = SpringTool.getApplicationContext().getBean(ClusterServiceCommandHostCommandService.class);
159+
ActorRef commandActor = ActorUtils.getLocalActor(ServiceCommandActor.class, "commandActor");
160+
List<ClusterServiceCommandHostCommandEntity> hostCommandList = service.getHostCommandListByCommandId(commandId);
161+
for (ClusterServiceCommandHostCommandEntity hostCommandEntity : hostCommandList) {
162+
if (hostCommandEntity.getCommandState() == CommandState.RUNNING) {
163+
logger.info("{} host command set to failed", hostCommandEntity.getCommandName());
164+
hostCommandEntity.setCommandState(CommandState.FAILED);
165+
hostCommandEntity.setCommandProgress(100);
166+
service.updateByHostCommandId(hostCommandEntity);
167+
UpdateCommandHostMessage message = new UpdateCommandHostMessage();
168+
message.setCommandId(commandId);
169+
message.setCommandHostId(hostCommandEntity.getCommandHostId());
170+
message.setHostname(hostCommandEntity.getHostname());
171+
if (hostCommandEntity.getServiceRoleType() == RoleType.MASTER) {
172+
message.setServiceRoleType(ServiceRoleType.MASTER);
173+
} else {
174+
message.setServiceRoleType(ServiceRoleType.WORKER);
175+
}
176+
ActorUtils.actorSystem.scheduler().scheduleOnce(
177+
FiniteDuration.apply(3L, TimeUnit.SECONDS),
178+
commandActor,
179+
message,
180+
ActorUtils.actorSystem.dispatcher(),
181+
ActorRef.noSender());
176182
}
177-
ActorUtils.actorSystem.scheduler().scheduleOnce(
178-
FiniteDuration.apply(3L, TimeUnit.SECONDS),
179-
commandActor,
180-
message,
181-
ActorUtils.actorSystem.dispatcher(),
182-
ActorRef.noSender());
183183
}
184184
}
185-
186185
}
187186

188187
public static void tellCommandActorResult(String serviceName, ExecuteServiceRoleCommand executeServiceRoleCommand, ServiceExecuteState state) {

0 commit comments

Comments
 (0)