Search in sources :

Example 36 with ProcessKey

use of com.walmartlabs.concord.server.sdk.ProcessKey in project concord by walmartlabs.

the class ProcessLogResourceV2 method updateSegment.

/**
 * Update a process log segment.
 */
@POST
@ApiOperation(value = "Update process log segment")
@Path("{id}/log/segment/{segmentId}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@WithTimer
public LogSegmentOperationResponse updateSegment(@ApiParam @PathParam("id") UUID instanceId, @ApiParam @PathParam("segmentId") long segmentId, @ApiParam LogSegmentUpdateRequest request) {
    ProcessKey processKey = logAccessManager.assertLogAccess(instanceId);
    logManager.updateSegment(processKey, segmentId, request.status(), request.warnings(), request.errors());
    return new LogSegmentOperationResponse(segmentId, OperationResult.UPDATED);
}
Also used : ProcessKey(com.walmartlabs.concord.server.sdk.ProcessKey) WithTimer(com.walmartlabs.concord.server.sdk.metrics.WithTimer) ApiOperation(io.swagger.annotations.ApiOperation)

Example 37 with ProcessKey

use of com.walmartlabs.concord.server.sdk.ProcessKey in project concord by walmartlabs.

the class ProcessLogResourceV2 method append.

/**
 * Appends a process' log.
 */
@POST
@Path("{id}/log/segment/{segmentId}/data")
@Consumes(MediaType.APPLICATION_OCTET_STREAM)
@WithTimer
public void append(@ApiParam @PathParam("id") UUID instanceId, @ApiParam @PathParam("segmentId") long segmentId, InputStream data) {
    ProcessKey processKey = logAccessManager.assertLogAccess(instanceId);
    try {
        byte[] ab = IOUtils.toByteArray(data);
        int upper = logManager.log(processKey, segmentId, ab);
        int logSizeLimit = processCfg.getLogSizeLimit();
        if (upper >= logSizeLimit) {
            logManager.error(processKey, "Maximum log size reached: {}. Process cancelled.", logSizeLimit);
            processManager.kill(processKey);
        }
    } catch (IOException e) {
        throw new ConcordApplicationException("Error while appending a log: " + e.getMessage());
    }
}
Also used : ConcordApplicationException(com.walmartlabs.concord.server.sdk.ConcordApplicationException) ProcessKey(com.walmartlabs.concord.server.sdk.ProcessKey) IOException(java.io.IOException) WithTimer(com.walmartlabs.concord.server.sdk.metrics.WithTimer)

Example 38 with ProcessKey

use of com.walmartlabs.concord.server.sdk.ProcessKey in project concord by walmartlabs.

the class ProcessManager method start.

private ProcessResult start(Chain pipeline, Payload payload) {
    assertRepositoryDisabled(payload);
    ProcessKey processKey = payload.getProcessKey();
    try {
        pipeline.process(payload);
    } catch (ProcessException e) {
        throw e;
    } catch (Exception e) {
        log.error("start ['{}'] -> error starting the process", processKey, e);
        throw new ProcessException(processKey, "Error starting the process", e, Status.INTERNAL_SERVER_ERROR);
    }
    UUID instanceId = processKey.getInstanceId();
    return new ProcessResult(instanceId);
}
Also used : ProcessKey(com.walmartlabs.concord.server.sdk.ProcessKey) PartialProcessKey(com.walmartlabs.concord.server.sdk.PartialProcessKey) IOException(java.io.IOException) UnauthorizedException(org.apache.shiro.authz.UnauthorizedException) ConcordApplicationException(com.walmartlabs.concord.server.sdk.ConcordApplicationException)

Example 39 with ProcessKey

use of com.walmartlabs.concord.server.sdk.ProcessKey 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)

Example 40 with ProcessKey

use of com.walmartlabs.concord.server.sdk.ProcessKey in project concord by walmartlabs.

the class ProcessResource method setWaitCondition.

/**
 * Set the process' wait condition.
 */
@POST
@ApiOperation(value = "Set the process' wait condition")
@javax.ws.rs.Path("{id}/wait")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@WithTimer
public Response setWaitCondition(@ApiParam @PathParam("id") UUID instanceId, @ApiParam Map<String, Object> waitCondition) {
    ProcessKey processKey = assertProcessKey(instanceId);
    AbstractWaitCondition condition = objectMapper.convertValue(waitCondition, AbstractWaitCondition.class);
    processWaitManager.addWait(processKey, condition);
    return Response.ok().build();
}
Also used : PartialProcessKey(com.walmartlabs.concord.server.sdk.PartialProcessKey) ProcessKey(com.walmartlabs.concord.server.sdk.ProcessKey) AbstractWaitCondition(com.walmartlabs.concord.server.process.waits.AbstractWaitCondition) WithTimer(com.walmartlabs.concord.server.sdk.metrics.WithTimer) ApiOperation(io.swagger.annotations.ApiOperation)

Aggregations

ProcessKey (com.walmartlabs.concord.server.sdk.ProcessKey)69 WithTimer (com.walmartlabs.concord.server.sdk.metrics.WithTimer)28 Path (java.nio.file.Path)27 PartialProcessKey (com.walmartlabs.concord.server.sdk.PartialProcessKey)25 ApiOperation (io.swagger.annotations.ApiOperation)22 ProcessException (com.walmartlabs.concord.server.process.ProcessException)20 ConcordApplicationException (com.walmartlabs.concord.server.sdk.ConcordApplicationException)16 IOException (java.io.IOException)16 UUID (java.util.UUID)9 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)8 PolicyEngine (com.walmartlabs.concord.policyengine.PolicyEngine)8 Inject (javax.inject.Inject)8 Named (javax.inject.Named)8 ProcessKeyCache (com.walmartlabs.concord.server.process.queue.ProcessKeyCache)7 ProcessQueueDao (com.walmartlabs.concord.server.process.queue.ProcessQueueDao)7 ProcessStateManager (com.walmartlabs.concord.server.process.state.ProcessStateManager)7 UserPrincipal (com.walmartlabs.concord.server.security.UserPrincipal)7 ProcessLogManager (com.walmartlabs.concord.server.process.logs.ProcessLogManager)6 HttpUtils (com.walmartlabs.concord.server.HttpUtils)5 ResourceAccessLevel (com.walmartlabs.concord.server.org.ResourceAccessLevel)5