use of com.walmartlabs.concord.server.sdk.PartialProcessKey in project concord by walmartlabs.
the class ProjectProcessResource method proceed.
private Response proceed(PartialProcessKey processKey) {
ProcessEntry entry = processQueueManager.get(processKey);
if (entry == null) {
throw new ConcordApplicationException("Process not found: " + processKey, Status.NOT_FOUND);
}
ProcessKey pk = new ProcessKey(entry.instanceId(), entry.createdAt());
ProcessStatus s = entry.status();
if (s == ProcessStatus.FAILED || s == ProcessStatus.CANCELLED || s == ProcessStatus.TIMED_OUT) {
return processError(processKey, "Process failed: " + s, null);
} else if (s == ProcessStatus.FINISHED) {
return processFinished(processKey);
} else if (s == ProcessStatus.SUSPENDED) {
String nextFormId = nextFormId(pk);
if (nextFormId == null) {
return processError(processKey, "Invalid process state: no forms found", null);
}
String url = "/#/process/" + entry.instanceId() + "/wizard";
return Response.status(Status.MOVED_PERMANENTLY).header(HttpHeaders.LOCATION, url).build();
} else {
Map<String, Object> args = prepareArgumentsForInProgressTemplate(entry);
return responseTemplates.inProgressWait(Response.ok(), args).build();
}
}
use of com.walmartlabs.concord.server.sdk.PartialProcessKey in project concord by walmartlabs.
the class GithubEventResource method onEvent.
@POST
@ApiOperation("Handles GitHub repository level events")
@Path("/webhook")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.TEXT_PLAIN)
@WithTimer
public String onEvent(@ApiParam Map<String, Object> data, @HeaderParam("X-GitHub-Delivery") String deliveryId, @HeaderParam("X-GitHub-Event") String eventName, @Context UriInfo uriInfo) {
log.info("onEvent ['{}', '{}'] -> processing...", deliveryId, eventName);
if ("ping".equalsIgnoreCase(eventName)) {
return "ok";
}
if (executor.isDisabled(eventName)) {
log.warn("event ['{}', '{}'] -> disabled", deliveryId, eventName);
return "ok";
}
if (githubCfg.isLogEvents()) {
auditLog.add(AuditObject.EXTERNAL_EVENT, AuditAction.ACCESS).field("source", EVENT_SOURCE).field("eventId", deliveryId).field("githubEvent", eventName).field("payload", data).log();
}
Payload payload = Payload.from(eventName, data);
if (payload == null) {
log.warn("event ['{}', '{}'] -> can't parse payload", deliveryId, eventName);
return "ok";
}
List<GithubTriggerProcessor.Result> results = new ArrayList<>();
processors.forEach(p -> p.process(eventName, payload, uriInfo, results));
Supplier<UserEntry> initiatorSupplier = memo(new GithubEventInitiatorSupplier(userManager, ldapManager, payload));
int startedProcesses = 0;
for (GithubTriggerProcessor.Result r : results) {
Event e = Event.builder().id(deliveryId).name(EVENT_SOURCE).attributes(r.event()).initiator(initiatorSupplier).build();
List<PartialProcessKey> processes = executor.execute(e, r.triggers(), initiatorResolver, (t, cfg) -> {
// if `useEventCommitId` is true then the process is forced to use the specified commit ID
String commitId = MapUtils.getString(r.event(), COMMIT_ID_KEY);
if (commitId != null && TriggerUtils.isUseEventCommitId(t)) {
cfg.put(Constants.Request.REPO_COMMIT_ID, commitId);
cfg.put(Constants.Request.REPO_BRANCH_OR_TAG, payload.getHead());
}
return cfg;
}, new GithubExclusiveParamsResolver(payload));
startedProcesses += processes.size();
}
startedProcessesPerEvent.update(startedProcesses);
log.info("onEvent ['{}', '{}'] -> done, started process count: {}", deliveryId, eventName, startedProcesses);
return "ok";
}
use of com.walmartlabs.concord.server.sdk.PartialProcessKey in project concord by walmartlabs.
the class TriggerProcessExecutor method startProcess.
private PartialProcessKey startProcess(String eventId, UUID orgId, TriggerEntry t, Map<String, Object> cfg, UserEntry initiator) throws Exception {
PartialProcessKey processKey = PartialProcessKey.create();
processSecurityContext.runAs(initiator.getId(), () -> {
Payload payload = PayloadBuilder.start(processKey).initiator(initiator.getId(), initiator.getName()).organization(orgId).project(t.getProjectId()).repository(t.getRepositoryId()).configuration(cfg).triggeredBy(TriggeredByEntry.builder().externalEventId(eventId).trigger(t).build()).build();
processManager.start(payload);
return null;
});
return processKey;
}
use of com.walmartlabs.concord.server.sdk.PartialProcessKey in project concord by walmartlabs.
the class FormResourceV1 method get.
/**
* Return the current state of a form instance.
*/
@GET
@ApiOperation("Get the current state of a form")
@Path("/{processInstanceId}/form/{formName}")
@Produces(MediaType.APPLICATION_JSON)
public FormInstanceEntry get(@ApiParam @PathParam("processInstanceId") UUID processInstanceId, @ApiParam @PathParam("formName") String formName) {
PartialProcessKey processKey = PartialProcessKey.from(processInstanceId);
Form form = formService.get(processKey, formName);
if (form == null) {
throw new ConcordApplicationException("Form " + formName + " not found. Process ID: " + processKey, Status.NOT_FOUND);
}
Map<String, Object> data = FormUtils.values(form);
boolean yield = MapUtils.getBoolean(form.getOptions(), "yield", false);
Map<String, Object> allowedValues = form.getAllowedValues();
if (allowedValues == null) {
allowedValues = Collections.emptyMap();
}
List<FormInstanceEntry.Field> fields = new ArrayList<>();
FormDefinition fd = form.getFormDefinition();
for (FormField f : fd.getFields()) {
String fieldName = f.getName();
FormInstanceEntry.Cardinality c = map(f.getCardinality());
String type = f.getType();
Object value = data.get(fieldName);
Object allowedValue = allowedValues.get(fieldName);
fields.add(new FormInstanceEntry.Field(fieldName, f.getLabel(), type, c, value, allowedValue, f.getOptions()));
}
String pbk = form.getProcessBusinessKey();
String name = fd.getName();
String resourcePath = FORMS_RESOURCES_PATH + "/" + name;
boolean isCustomForm = formService.exists(processKey, resourcePath);
return new FormInstanceEntry(pbk, name, fields, isCustomForm, yield);
}
use of com.walmartlabs.concord.server.sdk.PartialProcessKey in project concord by walmartlabs.
the class FormResourceV2 method submit.
/**
* Submit form instance's data, potentially resuming a suspended process.
*/
public FormSubmitResponse submit(UUID processInstanceId, String formName, Map<String, Object> data) {
PartialProcessKey processKey = PartialProcessKey.from(processInstanceId);
try {
FormSubmitResult result = formService.submit(processKey, formName, data);
Map<String, String> errors = com.walmartlabs.concord.server.process.form.FormUtils.mergeErrors(result.getErrors());
return new FormSubmitResponse(result.getProcessInstanceId(), errors);
} catch (FormUtils.ValidationException e) {
Map<String, String> errors = Collections.singletonMap(e.getField().name(), e.getMessage());
return new FormSubmitResponse(processInstanceId, errors);
}
}
Aggregations