use of com.walmartlabs.concord.server.sdk.ProcessKey in project concord by walmartlabs.
the class ProcessResource method uploadAttachments.
/**
* Upload process attachments.
*
* @param instanceId
* @param data
*/
@POST
@javax.ws.rs.Path("{id}/attachment")
@Consumes(MediaType.APPLICATION_OCTET_STREAM)
public void uploadAttachments(@PathParam("id") UUID instanceId, InputStream data) {
ProcessEntry entry = assertProcess(PartialProcessKey.from(instanceId));
ProcessKey processKey = new ProcessKey(entry.instanceId(), entry.createdAt());
Path tmpIn = null;
Path tmpDir = null;
try {
tmpIn = IOUtils.createTempFile("attachments", ".zip");
Files.copy(data, tmpIn, StandardCopyOption.REPLACE_EXISTING);
tmpDir = IOUtils.createTempDir("attachments");
IOUtils.unzip(tmpIn, tmpDir);
assertAttachmentsPolicy(tmpDir, entry);
Path finalTmpDir = tmpDir;
stateManager.tx(tx -> {
stateManager.deleteDirectory(tx, processKey, path(Constants.Files.JOB_ATTACHMENTS_DIR_NAME, Constants.Files.JOB_STATE_DIR_NAME));
stateManager.importPath(tx, processKey, Constants.Files.JOB_ATTACHMENTS_DIR_NAME, finalTmpDir, (p, attrs) -> true);
});
Map<String, Object> out = OutVariablesUtils.read(tmpDir);
if (out.isEmpty()) {
queueDao.removeMeta(processKey, "out");
} else {
queueDao.updateMeta(processKey, Collections.singletonMap("out", out));
}
} catch (PolicyException e) {
throw new ConcordApplicationException(e.getMessage(), Status.FORBIDDEN);
} catch (IOException e) {
log.error("uploadAttachments ['{}'] -> error", processKey, e);
throw new ConcordApplicationException("upload error: " + e.getMessage());
} finally {
if (tmpDir != null) {
try {
IOUtils.deleteRecursively(tmpDir);
} catch (IOException e) {
log.warn("uploadAttachments -> cleanup error: {}", e.getMessage());
}
}
if (tmpIn != null) {
try {
Files.delete(tmpIn);
} catch (IOException e) {
log.warn("uploadAttachments -> cleanup error: {}", e.getMessage());
}
}
}
}
use of com.walmartlabs.concord.server.sdk.ProcessKey in project concord by walmartlabs.
the class ProcessResource method updateStatus.
/**
* Updates a process' status
*
* @param instanceId
* @param status
*/
@POST
@ApiOperation("Update process status")
@javax.ws.rs.Path("{id}/status")
@Consumes(MediaType.TEXT_PLAIN)
@WithTimer
public void updateStatus(@ApiParam @PathParam("id") UUID instanceId, @ApiParam(required = true) @QueryParam("agentId") String agentId, @ApiParam(required = true) ProcessStatus status) {
ProcessKey processKey = assertProcessKey(instanceId);
processManager.updateStatus(processKey, agentId, status);
}
use of com.walmartlabs.concord.server.sdk.ProcessKey in project concord by walmartlabs.
the class ProcessCheckpointResource method restore.
@POST
@ApiOperation(value = "Restore process from checkpoint")
@javax.ws.rs.Path("{id}/checkpoint/restore")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@WithTimer
@Validate
public ResumeProcessResponse restore(@ApiParam @PathParam("id") UUID instanceId, @ApiParam @Valid RestoreCheckpointRequest request) {
UUID checkpointId = request.getId();
// TODO replace with ProcessKeyCache
ProcessEntry entry = processManager.assertProcess(instanceId);
ProcessKey processKey = new ProcessKey(entry.instanceId(), entry.createdAt());
processManager.restoreFromCheckpoint(processKey, checkpointId);
return new ResumeProcessResponse();
}
use of com.walmartlabs.concord.server.sdk.ProcessKey in project concord by walmartlabs.
the class ProcessCheckpointResource method uploadCheckpoint.
@POST
@javax.ws.rs.Path("{id}/checkpoint")
@Consumes(MediaType.MULTIPART_FORM_DATA)
public void uploadCheckpoint(@PathParam("id") UUID instanceId, @ApiParam MultipartInput input) {
// TODO replace with ProcessKeyCache
ProcessEntry entry = processManager.assertProcess(instanceId);
ProcessKey processKey = new ProcessKey(entry.instanceId(), entry.createdAt());
UUID checkpointId = MultipartUtils.assertUuid(input, "id");
UUID correlationId = MultipartUtils.assertUuid(input, "correlationId");
String checkpointName = MultipartUtils.assertString(input, "name");
try (InputStream data = MultipartUtils.assertStream(input, "data");
TemporaryPath tmpIn = IOUtils.tempFile("checkpoint", ".zip")) {
Files.copy(data, tmpIn.path(), StandardCopyOption.REPLACE_EXISTING);
checkpointManager.importCheckpoint(processKey, checkpointId, correlationId, checkpointName, tmpIn.path());
} catch (ValidationErrorsException e) {
throw new ConcordApplicationException(e.getMessage(), Response.Status.BAD_REQUEST);
} catch (IOException e) {
log.error("uploadCheckpoint ['{}'] -> error", processKey, e);
throw new ConcordApplicationException("upload error: " + e.getMessage());
}
log.info("uploadCheckpoint ['{}'] -> done", processKey);
}
use of com.walmartlabs.concord.server.sdk.ProcessKey in project concord by walmartlabs.
the class ProcessCheckpointResource method list.
@GET
@ApiOperation(value = "List the process checkpoints", responseContainer = "list", response = ProcessCheckpointEntry.class)
@javax.ws.rs.Path("{id}/checkpoint")
@Produces(MediaType.APPLICATION_JSON)
@WithTimer
public List<ProcessCheckpointEntry> list(@ApiParam @PathParam("id") UUID instanceId) {
ProcessEntry entry = processManager.assertProcess(instanceId);
ProcessKey processKey = new ProcessKey(entry.instanceId(), entry.createdAt());
checkpointManager.assertProcessAccess(entry);
return checkpointManager.list(processKey);
}
Aggregations