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);
}
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());
}
}
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);
}
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())));
}
}
}
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();
}
Aggregations