use of com.walmartlabs.concord.server.sdk.ConcordApplicationException 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.ConcordApplicationException in project concord by walmartlabs.
the class ProcessResource method resume.
/**
* Resumes an existing process.
*/
@POST
@ApiOperation("Resume a process")
@javax.ws.rs.Path("/{id}/resume/{eventName}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@WithTimer
public ResumeProcessResponse resume(@ApiParam @PathParam("id") UUID instanceId, @ApiParam @PathParam("eventName") @NotNull String eventName, @ApiParam @QueryParam("saveAs") String saveAs, @ApiParam Map<String, Object> req) {
PartialProcessKey processKey = PartialProcessKey.from(instanceId);
if (saveAs != null && !saveAs.isEmpty() && req != null) {
req = ConfigurationUtils.toNested(saveAs, req);
}
req = ExpressionUtils.escapeMap(req);
Payload payload;
try {
payload = payloadManager.createResumePayload(processKey, eventName, req);
} catch (IOException e) {
log.error("resume ['{}', '{}'] -> error creating a payload: {}", instanceId, eventName, e);
throw new ConcordApplicationException("Error creating a payload", e);
}
processManager.resume(payload);
return new ResumeProcessResponse();
}
use of com.walmartlabs.concord.server.sdk.ConcordApplicationException in project concord by walmartlabs.
the class ProcessResource method start.
/**
* Starts a new process instance.
*
* @param in
* @param parentInstanceId
* @param sync
* @return
* @deprecated use {@link #start(MultipartInput, UUID, boolean, String[], HttpServletRequest)}
*/
@POST
@ApiOperation(value = "Start a new process instance using the supplied payload archive", hidden = true)
@Consumes(MediaType.APPLICATION_OCTET_STREAM)
@Produces(MediaType.APPLICATION_JSON)
@WithTimer(suffix = "_octetstream")
@Deprecated
public StartProcessResponse start(InputStream in, @QueryParam("parentId") UUID parentInstanceId, @Deprecated @DefaultValue("false") @QueryParam("sync") boolean sync, @QueryParam("out") String[] out) {
if (sync) {
throw syncIsForbidden();
}
assertPartialKey(parentInstanceId);
PartialProcessKey processKey = PartialProcessKey.from(UUID.randomUUID());
UserPrincipal userPrincipal = UserPrincipal.assertCurrent();
Payload payload;
try {
payload = payloadManager.createPayload(processKey, parentInstanceId, userPrincipal.getId(), userPrincipal.getUsername(), in, out);
} catch (IOException e) {
log.error("start -> error creating a payload: {}", e.getMessage());
throw new ConcordApplicationException("Error creating a payload", e);
}
return toResponse(processManager.start(payload));
}
use of com.walmartlabs.concord.server.sdk.ConcordApplicationException in project concord by walmartlabs.
the class ProcessResourceV2 method get.
/**
* Returns a process instance's details.
*/
@GET
@ApiOperation("Get a process' details")
@Path("/{id}")
@Produces(MediaType.APPLICATION_JSON)
@WithTimer
public ProcessEntry get(@ApiParam @PathParam("id") UUID instanceId, @ApiParam @QueryParam("include") Set<ProcessDataInclude> includes) {
PartialProcessKey processKey = PartialProcessKey.from(instanceId);
ProcessEntry e = processQueueManager.get(processKey, includes);
if (e == null) {
log.warn("get ['{}'] -> not found", instanceId);
throw new ConcordApplicationException("Process instance not found", Status.NOT_FOUND);
}
if (e.projectId() != null) {
projectAccessManager.assertAccess(e.orgId(), e.projectId(), null, ResourceAccessLevel.READER, false);
}
return e;
}
use of com.walmartlabs.concord.server.sdk.ConcordApplicationException in project concord by walmartlabs.
the class ProcessResourceV2 method createProcessFilter.
private ProcessFilter createProcessFilter(UUID orgId, String orgName, UUID projectId, String projectName, UUID repoId, String repoName, OffsetDateTimeParam afterCreatedAt, OffsetDateTimeParam beforeCreatedAt, Set<String> tags, ProcessStatus processStatus, String initiator, UUID parentId, Set<ProcessDataInclude> processData, Integer limit, Integer offset, UriInfo uriInfo) {
UUID effectiveOrgId = orgId;
Set<UUID> orgIds = null;
if (orgId != null) {
// we got an org ID, use it as it is
orgIds = Collections.singleton(effectiveOrgId);
} else if (orgName != null) {
// we got an org name, validate it first by resolving its ID
OrganizationEntry org = orgManager.assertExisting(null, orgName);
effectiveOrgId = org.getId();
orgIds = Collections.singleton(effectiveOrgId);
} else {
// we got a query that is not limited to any specific org
// let's check if we can return all processes from all orgs or if we should limit it to the user's orgs
boolean canSeeAllOrgs = Roles.isAdmin() || Permission.isPermitted(Permission.GET_PROCESS_QUEUE_ALL_ORGS);
if (!canSeeAllOrgs) {
// non-admin users can only see their org's processes or processes w/o projects
orgIds = getCurrentUserOrgIds();
}
}
UUID effectiveProjectId = projectId;
if (effectiveProjectId == null && projectName != null) {
if (effectiveOrgId == null) {
throw new ValidationErrorsException("Organization name or ID is required");
}
effectiveProjectId = projectDao.getId(effectiveOrgId, projectName);
if (effectiveProjectId == null) {
throw new ConcordApplicationException("Project not found: " + projectName, Response.Status.NOT_FOUND);
}
}
if (effectiveProjectId != null) {
projectAccessManager.assertAccess(effectiveProjectId, effectiveProjectId, null, ResourceAccessLevel.READER, false);
} else if (effectiveOrgId != null) {
orgManager.assertAccess(effectiveOrgId, null, false);
} else {
// we don't have to do the permissions check when neither the org or the project are specified
// it is done implicitly by calling getCurrentUserOrgIds for all non-admin users (see above)
}
UUID effectiveRepoId = repoId;
if (effectiveRepoId == null && repoName != null && effectiveProjectId != null) {
effectiveRepoId = repositoryDao.getId(effectiveProjectId, repoName);
}
// collect all metadata filters, we assume that they have "meta." prefix in their query parameter names
List<MetadataFilter> metaFilters = MetadataUtils.parseMetadataFilters(uriInfo);
// can't allow seq scans, we don't index PROCESS_QUEUE.META (yet?)
if (!metaFilters.isEmpty() && effectiveProjectId == null) {
throw new ValidationErrorsException("Process metadata filters require a project name or an ID to be included in the query.");
}
return ProcessFilter.builder().parentId(parentId).projectId(effectiveProjectId).orgIds(orgIds).includeWithoutProject(effectiveOrgId == null && effectiveProjectId == null).afterCreatedAt(unwrap(afterCreatedAt)).beforeCreatedAt(unwrap(beforeCreatedAt)).repoId(effectiveRepoId).repoName(repoName).tags(tags).status(processStatus).initiator(initiator).metaFilters(metaFilters).requirements(FilterUtils.parseJson("requirements", uriInfo)).startAt(FilterUtils.parseDate("startAt", uriInfo)).includes(processData != null ? processData : Collections.emptySet()).limit(limit).offset(offset).build();
}
Aggregations