use of com.walmartlabs.concord.server.agent.AgentManager.KeyAndAgent in project concord by walmartlabs.
the class ProcessManager method kill.
public void kill(DSLContext tx, List<ProcessKey> processKeys) {
List<ProcessKey> keys = new ArrayList<>(processKeys);
while (!keys.isEmpty()) {
// TODO: better way
List<ProcessEntry> processes = keys.stream().map(k -> queueDao.get(tx, k, Collections.emptySet())).collect(Collectors.toList());
List<ProcessEntry> terminatedProcesses = filterProcesses(processes, TERMINATED_PROCESS_STATUSES);
terminatedProcesses.forEach(p -> keys.remove(new ProcessKey(p.instanceId(), p.createdAt())));
List<ProcessEntry> serverProcesses = filterProcesses(processes, SERVER_PROCESS_STATUSES);
if (!serverProcesses.isEmpty()) {
List<ProcessKey> serverProcessKeys = serverProcesses.stream().map(p -> new ProcessKey(p.instanceId(), p.createdAt())).collect(Collectors.toList());
List<ProcessKey> updated = queueManager.updateExpectedStatus(tx, serverProcessKeys, SERVER_PROCESS_STATUSES, ProcessStatus.CANCELLED);
serverProcesses.stream().filter(p -> updated.contains(new ProcessKey(p.instanceId(), p.createdAt()))).forEach(this::auditLogOnCancelled);
keys.removeAll(updated);
}
List<ProcessEntry> agentProcesses = filterProcesses(processes, AGENT_PROCESS_STATUSES);
if (!agentProcesses.isEmpty()) {
agentManager.killProcess(agentProcesses.stream().map(p -> new KeyAndAgent(new ProcessKey(p.instanceId(), p.createdAt()), p.lastAgentId())).collect(Collectors.toList()));
agentProcesses.forEach(this::auditLogOnCancelled);
agentProcesses.forEach(p -> keys.remove(new ProcessKey(p.instanceId(), p.createdAt())));
}
}
}
Aggregations