Search in sources :

Example 21 with PartialProcessKey

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();
    }
}
Also used : ProcessStatus(com.walmartlabs.concord.server.sdk.ProcessStatus) ConcordApplicationException(com.walmartlabs.concord.server.sdk.ConcordApplicationException) ProcessKey(com.walmartlabs.concord.server.sdk.ProcessKey) PartialProcessKey(com.walmartlabs.concord.server.sdk.PartialProcessKey)

Example 22 with PartialProcessKey

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";
}
Also used : PartialProcessKey(com.walmartlabs.concord.server.sdk.PartialProcessKey) GithubTriggerProcessor(com.walmartlabs.concord.server.events.github.GithubTriggerProcessor) Payload(com.walmartlabs.concord.server.events.github.Payload) UserEntry(com.walmartlabs.concord.server.user.UserEntry) WithTimer(com.walmartlabs.concord.server.sdk.metrics.WithTimer) ApiOperation(io.swagger.annotations.ApiOperation)

Example 23 with PartialProcessKey

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;
}
Also used : PartialProcessKey(com.walmartlabs.concord.server.sdk.PartialProcessKey)

Example 24 with PartialProcessKey

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);
}
Also used : PartialProcessKey(com.walmartlabs.concord.server.sdk.PartialProcessKey) Form(io.takari.bpm.form.Form) FormField(io.takari.bpm.model.form.FormField) ConcordApplicationException(com.walmartlabs.concord.server.sdk.ConcordApplicationException) FormDefinition(io.takari.bpm.model.form.FormDefinition) FormField(io.takari.bpm.model.form.FormField) ApiOperation(io.swagger.annotations.ApiOperation)

Example 25 with PartialProcessKey

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);
    }
}
Also used : PartialProcessKey(com.walmartlabs.concord.server.sdk.PartialProcessKey) FormUtils(com.walmartlabs.concord.forms.FormUtils)

Aggregations

PartialProcessKey (com.walmartlabs.concord.server.sdk.PartialProcessKey)27 ConcordApplicationException (com.walmartlabs.concord.server.sdk.ConcordApplicationException)18 WithTimer (com.walmartlabs.concord.server.sdk.metrics.WithTimer)14 ApiOperation (io.swagger.annotations.ApiOperation)14 UserPrincipal (com.walmartlabs.concord.server.security.UserPrincipal)8 EntryPoint (com.walmartlabs.concord.server.process.PayloadManager.EntryPoint)4 ProcessKey (com.walmartlabs.concord.server.sdk.ProcessKey)4 UUID (java.util.UUID)3 ValidationErrorsException (org.sonatype.siesta.ValidationErrorsException)3 Imports (com.walmartlabs.concord.imports.Imports)2 ProcessStatus (com.walmartlabs.concord.server.sdk.ProcessStatus)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 SettableFuture (com.google.common.util.concurrent.SettableFuture)1 ConfigurationUtils (com.walmartlabs.concord.common.ConfigurationUtils)1 IOUtils (com.walmartlabs.concord.common.IOUtils)1 Form (com.walmartlabs.concord.forms.Form)1 FormField (com.walmartlabs.concord.forms.FormField)1 FormUtils (com.walmartlabs.concord.forms.FormUtils)1 AttachmentsRule (com.walmartlabs.concord.policyengine.AttachmentsRule)1 CheckResult (com.walmartlabs.concord.policyengine.CheckResult)1