Search in sources :

Example 6 with ProcessStatus

use of com.walmartlabs.concord.server.sdk.ProcessStatus in project concord by walmartlabs.

the class ProcessQueueGaugeModule method configure.

@Override
@SuppressWarnings("rawtypes")
protected void configure() {
    Provider<ProcessQueueDao> queueDaoProvider = getProvider(ProcessQueueDao.class);
    // create the base gauge that caches all individual values
    Gauge<Map<String, Integer>> base = new CachedGauge<Map<String, Integer>>(15, TimeUnit.SECONDS) {

        @Override
        protected Map<String, Integer> loadValue() {
            return queueDaoProvider.get().getStatistics();
        }
    };
    Multibinder<GaugeProvider> gauges = Multibinder.newSetBinder(binder(), GaugeProvider.class);
    gauges.addBinding().toInstance(createBaseProvider(base));
    for (ProcessStatus s : ProcessStatus.values()) {
        gauges.addBinding().toInstance(create(base, s.toString()));
    }
    gauges.addBinding().toInstance(create(base, ProcessQueueDao.ENQUEUED_NOW_METRIC));
}
Also used : ProcessStatus(com.walmartlabs.concord.server.sdk.ProcessStatus) CachedGauge(com.codahale.metrics.CachedGauge) GaugeProvider(com.walmartlabs.concord.server.sdk.metrics.GaugeProvider) Map(java.util.Map)

Example 7 with ProcessStatus

use of com.walmartlabs.concord.server.sdk.ProcessStatus in project concord by walmartlabs.

the class ProcessQueueManager method enqueue.

/**
 * Updates an existing record, moving the process into the ENQUEUED status.
 */
public boolean enqueue(Payload payload) {
    ProcessKey processKey = payload.getProcessKey();
    ProcessStatus s = queueDao.getStatus(processKey);
    if (s == null) {
        throw new ProcessException(processKey, "Process not found: " + processKey);
    }
    if (s == ProcessStatus.CANCELLED) {
        // (e.g. it was a process in an "exclusive" group)
        return false;
    }
    if (!TO_ENQUEUED_STATUSES.contains(s)) {
        // something's wrong (e.g. someone tried to change the process' status directly in the DB and was unlucky)
        throw new ProcessException(processKey, "Invalid process status: " + s);
    }
    Set<String> tags = payload.getHeader(Payload.PROCESS_TAGS);
    OffsetDateTime startAt = PayloadUtils.getStartAt(payload);
    Map<String, Object> requirements = PayloadUtils.getRequirements(payload);
    Long processTimeout = getProcessTimeout(payload);
    Long suspendTimeout = getSuspendTimeout(payload);
    Set<String> handlers = payload.getHeader(Payload.PROCESS_HANDLERS);
    Map<String, Object> meta = getMeta(getCfg(payload));
    Imports imports = payload.getHeader(Payload.IMPORTS);
    ExclusiveMode exclusive = PayloadUtils.getExclusive(payload);
    String runtime = payload.getHeader(Payload.RUNTIME);
    List<String> dependencies = payload.getHeader(Payload.DEPENDENCIES);
    return queueDao.txResult(tx -> {
        boolean updated = queueDao.enqueue(tx, processKey, tags, startAt, requirements, processTimeout, handlers, meta, imports, exclusive, runtime, dependencies, suspendTimeout, TO_ENQUEUED_STATUSES);
        if (updated) {
            notifyStatusChange(tx, processKey, ProcessStatus.ENQUEUED);
        }
        return updated;
    });
}
Also used : ProcessStatus(com.walmartlabs.concord.server.sdk.ProcessStatus) ProcessKey(com.walmartlabs.concord.server.sdk.ProcessKey) PartialProcessKey(com.walmartlabs.concord.server.sdk.PartialProcessKey) Imports(com.walmartlabs.concord.imports.Imports) ExclusiveMode(com.walmartlabs.concord.runtime.v2.model.ExclusiveMode) OffsetDateTime(java.time.OffsetDateTime)

Example 8 with ProcessStatus

use of com.walmartlabs.concord.server.sdk.ProcessStatus in project concord by walmartlabs.

the class CustomFormServiceV1 method continueSession.

private Response continueSession(UriInfo uriInfo, HttpHeaders headers, ProcessKey processKey, String formName, Map<String, Object> data) {
    // TODO locking
    Form form = assertForm(processKey, formName);
    // TODO constants
    Map<String, Object> opts = form.getOptions();
    boolean yield = opts != null && (boolean) opts.getOrDefault("yield", false);
    Path dst = cfg.getBaseDir().resolve(processKey.toString()).resolve(formName);
    Path formDir = dst.resolve(FORM_DIR_NAME);
    try {
        Map<String, Object> m = new HashMap<>();
        try {
            m = FormUtils.convert(new ExternalFileFormValidatorLocale(processKey, formName, stateManager), form, data);
            FormSubmitResult r = formService.submit(processKey, formName, m);
            if (r.isValid()) {
                if (yield) {
                    // this was the last "interactive" form. The process will continue in "background"
                    // and users should get a success page.
                    writeData(formDir, success(form, m));
                } else {
                    while (true) {
                        ProcessStatus s = queueDao.getStatus(processKey);
                        if (s == ProcessStatus.SUSPENDED) {
                            String nextFormId = formService.nextFormId(processKey);
                            if (nextFormId == null) {
                                writeData(formDir, success(form, m));
                                break;
                            } else {
                                FormSessionResponse nextSession = startSession(processKey, nextFormId);
                                return redirectTo(nextSession.getUri());
                            }
                        } else if (s == ProcessStatus.FAILED || s == ProcessStatus.CANCELLED || s == ProcessStatus.TIMED_OUT) {
                            writeData(formDir, processFailed(form, m));
                            break;
                        } else if (s == ProcessStatus.FINISHED) {
                            writeData(formDir, success(form, m));
                            break;
                        }
                        try {
                            // TODO exp back off?
                            Thread.sleep(STATUS_REFRESH_DELAY);
                        } catch (InterruptedException e) {
                            Thread.currentThread().interrupt();
                        }
                    }
                }
            } else {
                writeData(formDir, prepareData(form, m, r.getErrors()));
            }
        } catch (ValidationException e) {
            ValidationError err = ValidationError.of(e.getField().getName(), e.getMessage());
            FormData d = prepareData(form, m, Collections.singletonList(err));
            writeData(formDir, d);
        }
    } catch (Exception e) {
        throw new ConcordApplicationException("Error while submitting a form", e);
    }
    return redirectToForm(uriInfo, headers, processKey, formName);
}
Also used : Path(java.nio.file.Path) ValidationException(com.walmartlabs.concord.server.process.form.FormUtils.ValidationException) Form(io.takari.bpm.form.Form) ProcessStatus(com.walmartlabs.concord.server.sdk.ProcessStatus) FormSubmitResult(com.walmartlabs.concord.server.process.form.FormSubmitResult) ValidationException(com.walmartlabs.concord.server.process.form.FormUtils.ValidationException) IOException(java.io.IOException) ConcordApplicationException(com.walmartlabs.concord.server.sdk.ConcordApplicationException) ConcordApplicationException(com.walmartlabs.concord.server.sdk.ConcordApplicationException) ValidationError(com.walmartlabs.concord.forms.ValidationError) ExternalFileFormValidatorLocale(com.walmartlabs.concord.server.process.form.ExternalFileFormValidatorLocale)

Example 9 with ProcessStatus

use of com.walmartlabs.concord.server.sdk.ProcessStatus 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)

Aggregations

ProcessStatus (com.walmartlabs.concord.server.sdk.ProcessStatus)9 ConcordApplicationException (com.walmartlabs.concord.server.sdk.ConcordApplicationException)5 IOException (java.io.IOException)3 ValidationError (com.walmartlabs.concord.forms.ValidationError)2 FormSubmitResult (com.walmartlabs.concord.server.process.form.FormSubmitResult)2 PartialProcessKey (com.walmartlabs.concord.server.sdk.PartialProcessKey)2 ProcessKey (com.walmartlabs.concord.server.sdk.ProcessKey)2 Path (java.nio.file.Path)2 CachedGauge (com.codahale.metrics.CachedGauge)1 Form (com.walmartlabs.concord.forms.Form)1 FormUtils (com.walmartlabs.concord.forms.FormUtils)1 Imports (com.walmartlabs.concord.imports.Imports)1 ExclusiveMode (com.walmartlabs.concord.runtime.v2.model.ExclusiveMode)1 FormData (com.walmartlabs.concord.server.console.CustomFormServiceV1.FormData)1 ProcessCheckpoints (com.walmartlabs.concord.server.jooq.tables.ProcessCheckpoints)1 ProcessEvents (com.walmartlabs.concord.server.jooq.tables.ProcessEvents)1 ProcessQueue (com.walmartlabs.concord.server.jooq.tables.ProcessQueue)1 ProcessQueueRecord (com.walmartlabs.concord.server.jooq.tables.records.ProcessQueueRecord)1 ExternalFileFormValidatorLocale (com.walmartlabs.concord.server.process.form.ExternalFileFormValidatorLocale)1 ExternalFileFormValidatorLocaleV2 (com.walmartlabs.concord.server.process.form.ExternalFileFormValidatorLocaleV2)1