Search in sources :

Example 1 with KeyAndAgent

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())));
        }
    }
}
Also used : java.util(java.util) LoggerFactory(org.slf4j.LoggerFactory) RepositoryEntry(com.walmartlabs.concord.server.org.project.RepositoryEntry) ProcessQueueManager(com.walmartlabs.concord.server.process.queue.ProcessQueueManager) ProcessKey(com.walmartlabs.concord.server.sdk.ProcessKey) ResumePipeline(com.walmartlabs.concord.server.process.pipelines.ResumePipeline) Inject(javax.inject.Inject) ProcessQueueDao(com.walmartlabs.concord.server.process.queue.ProcessQueueDao) Constants(com.walmartlabs.concord.sdk.Constants) AuditAction(com.walmartlabs.concord.server.audit.AuditAction) DSLContext(org.jooq.DSLContext) Named(javax.inject.Named) Status(javax.ws.rs.core.Response.Status) AgentManager(com.walmartlabs.concord.server.agent.AgentManager) PartialProcessKey(com.walmartlabs.concord.server.sdk.PartialProcessKey) SessionKeyPrincipal(com.walmartlabs.concord.server.security.sessionkey.SessionKeyPrincipal) AuditLog(com.walmartlabs.concord.server.audit.AuditLog) Roles(com.walmartlabs.concord.server.security.Roles) UserPrincipal(com.walmartlabs.concord.server.security.UserPrincipal) ProcessCheckpointManager(com.walmartlabs.concord.server.process.state.ProcessCheckpointManager) ProcessStateManager(com.walmartlabs.concord.server.process.state.ProcessStateManager) Chain(com.walmartlabs.concord.server.process.pipelines.processors.Chain) Logger(org.slf4j.Logger) ProcessLogManager(com.walmartlabs.concord.server.process.logs.ProcessLogManager) ExclusiveMode(com.walmartlabs.concord.runtime.v2.model.ExclusiveMode) ProcessStatus(com.walmartlabs.concord.server.sdk.ProcessStatus) IOException(java.io.IOException) ProjectAccessManager(com.walmartlabs.concord.server.org.project.ProjectAccessManager) Collectors(java.util.stream.Collectors) RepositoryDao(com.walmartlabs.concord.server.org.project.RepositoryDao) Serializable(java.io.Serializable) ForkPipeline(com.walmartlabs.concord.server.process.pipelines.ForkPipeline) UnauthorizedException(org.apache.shiro.authz.UnauthorizedException) Response(javax.ws.rs.core.Response) ProcessStateManager.path(com.walmartlabs.concord.server.process.state.ProcessStateManager.path) KeyAndAgent(com.walmartlabs.concord.server.agent.AgentManager.KeyAndAgent) ConcordApplicationException(com.walmartlabs.concord.server.sdk.ConcordApplicationException) AuditObject(com.walmartlabs.concord.server.audit.AuditObject) ResourceAccessLevel(com.walmartlabs.concord.server.org.ResourceAccessLevel) NewProcessPipeline(com.walmartlabs.concord.server.process.pipelines.NewProcessPipeline) KeyAndAgent(com.walmartlabs.concord.server.agent.AgentManager.KeyAndAgent) ProcessKey(com.walmartlabs.concord.server.sdk.ProcessKey) PartialProcessKey(com.walmartlabs.concord.server.sdk.PartialProcessKey)

Aggregations

ExclusiveMode (com.walmartlabs.concord.runtime.v2.model.ExclusiveMode)1 Constants (com.walmartlabs.concord.sdk.Constants)1 AgentManager (com.walmartlabs.concord.server.agent.AgentManager)1 KeyAndAgent (com.walmartlabs.concord.server.agent.AgentManager.KeyAndAgent)1 AuditAction (com.walmartlabs.concord.server.audit.AuditAction)1 AuditLog (com.walmartlabs.concord.server.audit.AuditLog)1 AuditObject (com.walmartlabs.concord.server.audit.AuditObject)1 ResourceAccessLevel (com.walmartlabs.concord.server.org.ResourceAccessLevel)1 ProjectAccessManager (com.walmartlabs.concord.server.org.project.ProjectAccessManager)1 RepositoryDao (com.walmartlabs.concord.server.org.project.RepositoryDao)1 RepositoryEntry (com.walmartlabs.concord.server.org.project.RepositoryEntry)1 ProcessLogManager (com.walmartlabs.concord.server.process.logs.ProcessLogManager)1 ForkPipeline (com.walmartlabs.concord.server.process.pipelines.ForkPipeline)1 NewProcessPipeline (com.walmartlabs.concord.server.process.pipelines.NewProcessPipeline)1 ResumePipeline (com.walmartlabs.concord.server.process.pipelines.ResumePipeline)1 Chain (com.walmartlabs.concord.server.process.pipelines.processors.Chain)1 ProcessQueueDao (com.walmartlabs.concord.server.process.queue.ProcessQueueDao)1 ProcessQueueManager (com.walmartlabs.concord.server.process.queue.ProcessQueueManager)1 ProcessCheckpointManager (com.walmartlabs.concord.server.process.state.ProcessCheckpointManager)1 ProcessStateManager (com.walmartlabs.concord.server.process.state.ProcessStateManager)1