use of com.walmartlabs.concord.server.sdk.ProcessKey in project concord by walmartlabs.
the class ProcessResource method fork.
/**
* Starts a new child process by forking the start of the specified parent process.
*
* @param parentInstanceId
* @param req
* @param sync
* @return
*/
@POST
@ApiOperation("Fork a process")
@javax.ws.rs.Path("/{id}/fork")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@WithTimer
public StartProcessResponse fork(@ApiParam @PathParam("id") UUID parentInstanceId, @ApiParam Map<String, Object> req, @ApiParam @Deprecated @DefaultValue("false") @QueryParam("sync") boolean sync, @ApiParam @QueryParam("out") String[] out) {
if (sync) {
throw syncIsForbidden();
}
ProcessEntry parent = processQueueManager.get(PartialProcessKey.from(parentInstanceId));
if (parent == null) {
throw new ValidationErrorsException("Unknown parent instance ID: " + parentInstanceId);
}
PartialProcessKey processKey = PartialProcessKey.from(UUID.randomUUID());
ProcessKey parentProcessKey = new ProcessKey(parent.instanceId(), parent.createdAt());
UUID projectId = parent.projectId();
UserPrincipal userPrincipal = UserPrincipal.assertCurrent();
Set<String> handlers = parent.handlers();
Imports imports = queueDao.getImports(parentProcessKey);
Payload payload;
try {
payload = payloadManager.createFork(processKey, parentProcessKey, ProcessKind.DEFAULT, userPrincipal.getId(), userPrincipal.getUsername(), projectId, req, out, handlers, imports);
} catch (IOException e) {
log.error("fork ['{}', '{}'] -> error creating a payload: {}", processKey, parentProcessKey, e);
throw new ConcordApplicationException("Error creating a payload", e);
}
return toResponse(processManager.startFork(payload));
}
use of com.walmartlabs.concord.server.sdk.ProcessKey in project concord by walmartlabs.
the class ProcessResource method downloadStateFile.
/**
* Downloads a single file from the current state snapshot of a process.
*/
@GET
@ApiOperation(value = "Download a single file from a process state snapshot", response = File.class)
@javax.ws.rs.Path("/{id}/state/snapshot/{name:.*}")
@Produces(MediaType.APPLICATION_OCTET_STREAM)
@Validate
public Response downloadStateFile(@ApiParam @PathParam("id") UUID instanceId, @ApiParam @PathParam("name") @NotNull @Size(min = 1) String fileName) {
ProcessEntry p = assertProcess(PartialProcessKey.from(instanceId));
ProcessKey processKey = new ProcessKey(p.instanceId(), p.createdAt());
assertProcessAccess(p, "state");
StreamingOutput out = output -> {
Path tmp = stateManager.get(processKey, fileName, ProcessResource::copyToTmp).orElseThrow(() -> new ConcordApplicationException("State file not found: " + fileName, Status.NOT_FOUND));
try (InputStream in = Files.newInputStream(tmp)) {
IOUtils.copy(in, output);
} finally {
Files.delete(tmp);
}
};
return Response.ok(out).build();
}
use of com.walmartlabs.concord.server.sdk.ProcessKey in project concord by walmartlabs.
the class ProcessResource method assertAttachmentsPolicy.
private void assertAttachmentsPolicy(Path tmpDir, ProcessEntry entry) throws IOException {
PolicyEngine policy = policyManager.get(entry.orgId(), entry.projectId(), UserPrincipal.assertCurrent().getUser().getId());
if (policy == null) {
return;
}
CheckResult<AttachmentsRule, Long> checkResult = policy.getAttachmentsPolicy().check(tmpDir);
if (!checkResult.getDeny().isEmpty()) {
String errorMessage = buildErrorMessage(checkResult.getDeny());
processLogManager.error(new ProcessKey(entry.instanceId(), entry.createdAt()), errorMessage);
throw new PolicyException("Found forbidden policy: " + errorMessage);
}
}
use of com.walmartlabs.concord.server.sdk.ProcessKey in project concord by walmartlabs.
the class ProcessResource method getLog.
/**
* Retrieves a process' log.
*
* @param instanceId
* @param rangeHeader
* @return
* @see ProcessLogResourceV2
* @deprecated in favor of the /api/v2/process/{id}/log* endpoints
*/
@GET
@ApiOperation(value = "Retrieve the log")
@javax.ws.rs.Path("/{id}/log")
@Produces(MediaType.APPLICATION_OCTET_STREAM)
@WithTimer
@Deprecated
public Response getLog(@ApiParam @PathParam("id") UUID instanceId, @HeaderParam("range") String rangeHeader) {
// check the permissions, logs can contain sensitive data
ProcessKey processKey = logAccessManager.assertLogAccess(instanceId);
HttpUtils.Range range = HttpUtils.parseRangeHeaderValue(rangeHeader);
ProcessLog l = logManager.get(processKey, range.start(), range.end());
return ProcessLogResourceV2.toResponse(instanceId, 0, l, range);
}
use of com.walmartlabs.concord.server.sdk.ProcessKey in project concord by walmartlabs.
the class ProcessResource method kill.
/**
* Forcefully stops a process.
*
* @param instanceId
*/
@DELETE
@ApiOperation("Forcefully stops a process")
@javax.ws.rs.Path("/{id}")
@WithTimer
public void kill(@ApiParam @PathParam("id") UUID instanceId) {
ProcessKey processKey = assertProcessKey(instanceId);
processManager.kill(processKey);
}
Aggregations