use of com.walmartlabs.concord.server.sdk.PartialProcessKey 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.PartialProcessKey in project concord by walmartlabs.
the class ProcessExceptionMapper method convert.
@Override
protected Response convert(ProcessException e, String id) {
String details = getDetails(e.getCause());
String stacktrace = null;
if (traceEnabled()) {
StringWriter w = new StringWriter();
e.printStackTrace(new PrintWriter(w));
stacktrace = w.toString();
}
PartialProcessKey processKey = e.getProcessKey();
UUID instanceId = processKey.getInstanceId();
ErrorMessage msg = new ErrorMessage(instanceId, e.getMessage(), details, stacktrace);
return Response.status(e.getStatus()).entity(msg).type(MediaType.APPLICATION_JSON_TYPE).build();
}
use of com.walmartlabs.concord.server.sdk.PartialProcessKey in project concord by walmartlabs.
the class ProcessKvResource method assertProjectId.
private UUID assertProjectId(UUID instanceId) {
PartialProcessKey processKey = PartialProcessKey.from(instanceId);
// TODO replace with getProjectId
ProcessEntry entry = processQueueManager.get(processKey);
if (entry == null) {
throw new ConcordApplicationException("Process instance not found", Response.Status.NOT_FOUND);
}
UUID projectId = entry.projectId();
if (projectId == null) {
log.warn("assertProjectId ['{}'] -> no project found, using the default value", processKey);
projectId = DEFAULT_PROJECT_ID;
}
return projectId;
}
use of com.walmartlabs.concord.server.sdk.PartialProcessKey in project concord by walmartlabs.
the class TriggerScheduler method startProcess.
private void startProcess(TriggerSchedulerEntry t) {
if (isDisabled(EVENT_SOURCE)) {
log.warn("startProcess ['{}'] -> disabled, skipping", t);
return;
}
if (isRepositoryDisabled(t)) {
log.warn("startProcess ['{}'] -> repository is disabled, skipping", t);
return;
}
log.info("run -> starting {}...", t);
Map<String, Object> args = new HashMap<>();
if (t.getArguments() != null) {
args.putAll(t.getArguments());
}
args.put("event", makeEvent(t));
Map<String, Object> cfg = t.getCfg();
cfg.put(Constants.Request.ARGUMENTS_KEY, args);
PartialProcessKey processKey = PartialProcessKey.create();
UUID triggerId = t.getTriggerId();
UUID orgId = t.getOrgId();
UUID projectId = t.getProjectId();
UUID repoId = t.getRepositoryId();
String entryPoint = t.getEntryPoint();
Collection<String> activeProfiles = t.getActiveProfiles();
Initiator initiator;
try {
initiator = getInitiator(t);
} catch (Exception e) {
log.error("startProcess ['{}', '{}', '{}', '{}', '{}', {}] -> error getting initiator: {}", triggerId, orgId, projectId, repoId, entryPoint, activeProfiles, e.getMessage());
logFailedToStart(t, e);
return;
}
Payload payload;
try {
payload = PayloadBuilder.start(processKey).initiator(initiator.id(), initiator.name()).organization(orgId).project(projectId).repository(repoId).entryPoint(entryPoint).activeProfiles(activeProfiles).triggeredBy(TriggeredByEntry.builder().trigger(t).build()).configuration(cfg).build();
} catch (Exception e) {
log.error("startProcess ['{}', '{}', '{}', '{}', '{}', {}] -> error creating a payload", triggerId, orgId, projectId, repoId, entryPoint, activeProfiles, e);
logFailedToStart(t, e);
return;
}
try {
processSecurityContext.runAs(initiator.id(), () -> processManager.start(payload));
} catch (Exception e) {
log.error("startProcess ['{}', '{}', '{}', '{}', '{}'] -> error starting process", triggerId, orgId, projectId, repoId, entryPoint, e);
logFailedToStart(t, e);
return;
}
log.info("startProcess ['{}', '{}', '{}', '{}', '{}'] -> process '{}' started", triggerId, orgId, projectId, repoId, entryPoint, processKey);
}
use of com.walmartlabs.concord.server.sdk.PartialProcessKey in project concord by walmartlabs.
the class PayloadManager method createPayload.
@WithTimer
public Payload createPayload(MultipartInput input, HttpServletRequest request) throws IOException {
PartialProcessKey processKey = PartialProcessKey.create();
UUID parentInstanceId = MultipartUtils.getUuid(input, Constants.Multipart.PARENT_INSTANCE_ID);
UUID orgId = getOrg(input);
UUID projectId = getProject(input, orgId);
UUID repoId = getRepo(input, projectId);
if (repoId != null && projectId == null) {
// allow starting processes by specifying repository IDs without project IDs or names
projectId = repositoryDao.getProjectId(repoId);
}
String entryPoint = MultipartUtils.getString(input, Constants.Multipart.ENTRY_POINT);
UserPrincipal initiator = UserPrincipal.assertCurrent();
String[] out = getOutExpressions(input);
Map<String, Object> meta = MultipartUtils.getMap(input, Constants.Multipart.META);
if (meta == null) {
meta = Collections.emptyMap();
}
return PayloadBuilder.start(processKey).parentInstanceId(parentInstanceId).with(input).organization(orgId).project(projectId).repository(repoId).entryPoint(entryPoint).outExpressions(out).initiator(initiator.getId(), initiator.getUsername()).meta(meta).request(request).build();
}
Aggregations