Search in sources :

Example 46 with ProcessKey

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

the class ProcessResource method listAttachments.

/**
 * Lists process attachments.
 *
 * @param instanceId
 * @return
 */
@GET
@ApiOperation(value = "List attachments", responseContainer = "list", response = String.class)
@javax.ws.rs.Path("/{id}/attachment")
@Produces(MediaType.APPLICATION_JSON)
@WithTimer
public List<String> listAttachments(@ApiParam @PathParam("id") UUID instanceId) {
    ProcessEntry processEntry = processManager.assertProcess(instanceId);
    assertProcessAccess(processEntry, "attachments");
    PartialProcessKey processKey = new ProcessKey(processEntry.instanceId(), processEntry.createdAt());
    String resource = Constants.Files.JOB_ATTACHMENTS_DIR_NAME + "/";
    List<String> l = stateManager.list(processKey, resource);
    return l.stream().map(s -> s.substring(resource.length())).collect(Collectors.toList());
}
Also used : ProcessWaitManager(com.walmartlabs.concord.server.process.waits.ProcessWaitManager) Resource(org.sonatype.siesta.Resource) Size(javax.validation.constraints.Size) ProcessLogAccessManager(com.walmartlabs.concord.server.process.logs.ProcessLogAccessManager) PolicyManager(com.walmartlabs.concord.server.policy.PolicyManager) LoggerFactory(org.slf4j.LoggerFactory) ProcessResult(com.walmartlabs.concord.server.process.ProcessManager.ProcessResult) ApiParam(io.swagger.annotations.ApiParam) MultipartInput(org.jboss.resteasy.plugins.providers.multipart.MultipartInput) ProcessKeyCache(com.walmartlabs.concord.server.process.queue.ProcessKeyCache) ApiOperation(io.swagger.annotations.ApiOperation) ProcessQueueDao(com.walmartlabs.concord.server.process.queue.ProcessQueueDao) WithTimer(com.walmartlabs.concord.server.sdk.metrics.WithTimer) ProcessWaitEntry(com.walmartlabs.concord.server.process.ProcessEntry.ProcessWaitEntry) Path(java.nio.file.Path) PartialProcessKey(com.walmartlabs.concord.server.sdk.PartialProcessKey) ProcessConfiguration(com.walmartlabs.concord.server.cfg.ProcessConfiguration) ProcessLogManager(com.walmartlabs.concord.server.process.logs.ProcessLogManager) IOUtils(com.walmartlabs.concord.common.IOUtils) EncryptedProjectValueManager(com.walmartlabs.concord.server.org.project.EncryptedProjectValueManager) ProcessStatus(com.walmartlabs.concord.server.sdk.ProcessStatus) NotNull(javax.validation.constraints.NotNull) Collectors(java.util.stream.Collectors) SecretStoreConfiguration(com.walmartlabs.concord.server.cfg.SecretStoreConfiguration) UnauthorizedException(org.apache.shiro.authz.UnauthorizedException) javax.ws.rs(javax.ws.rs) ValidationErrorsException(org.sonatype.siesta.ValidationErrorsException) CheckResult(com.walmartlabs.concord.policyengine.CheckResult) HttpUtils(com.walmartlabs.concord.server.HttpUtils) java.util(java.util) AbstractWaitCondition(com.walmartlabs.concord.server.process.waits.AbstractWaitCondition) ProcessQueueManager(com.walmartlabs.concord.server.process.queue.ProcessQueueManager) AttachmentsRule(com.walmartlabs.concord.policyengine.AttachmentsRule) ProcessKey(com.walmartlabs.concord.server.sdk.ProcessKey) Singleton(javax.inject.Singleton) ConfigurationUtils(com.walmartlabs.concord.common.ConfigurationUtils) StandardCopyOption(java.nio.file.StandardCopyOption) MessageFormat(java.text.MessageFormat) ProcessStateManager.zipTo(com.walmartlabs.concord.server.process.state.ProcessStateManager.zipTo) Inject(javax.inject.Inject) MultipartUtils(com.walmartlabs.concord.server.MultipartUtils) ExpressionUtils(com.walmartlabs.concord.server.events.ExpressionUtils) EntryPoint(com.walmartlabs.concord.server.process.PayloadManager.EntryPoint) HttpServletRequest(javax.servlet.http.HttpServletRequest) Constants(com.walmartlabs.concord.sdk.Constants) PolicyEngine(com.walmartlabs.concord.policyengine.PolicyEngine) Imports(com.walmartlabs.concord.imports.Imports) OffsetDateTimeParam(com.walmartlabs.concord.server.OffsetDateTimeParam) Api(io.swagger.annotations.Api) ZipArchiveOutputStream(org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream) Named(javax.inject.Named) Status(javax.ws.rs.core.Response.Status) ProcessStatusHistoryEntry(com.walmartlabs.concord.server.process.ProcessEntry.ProcessStatusHistoryEntry) ProcessLog(com.walmartlabs.concord.server.process.logs.ProcessLogsDao.ProcessLog) Roles(com.walmartlabs.concord.server.security.Roles) UserPrincipal(com.walmartlabs.concord.server.security.UserPrincipal) ProcessStateManager(com.walmartlabs.concord.server.process.state.ProcessStateManager) Logger(org.slf4j.Logger) Files(java.nio.file.Files) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Validate(org.sonatype.siesta.Validate) PolicyException(com.walmartlabs.concord.server.policy.PolicyException) ProjectAccessManager(com.walmartlabs.concord.server.org.project.ProjectAccessManager) javax.ws.rs.core(javax.ws.rs.core) ProcessFilter(com.walmartlabs.concord.server.process.queue.ProcessFilter) OrganizationManager(com.walmartlabs.concord.server.org.OrganizationManager) java.io(java.io) ProcessStateManager.path(com.walmartlabs.concord.server.process.state.ProcessStateManager.path) ConcordApplicationException(com.walmartlabs.concord.server.sdk.ConcordApplicationException) ResourceAccessLevel(com.walmartlabs.concord.server.org.ResourceAccessLevel) Authorization(io.swagger.annotations.Authorization) PartialProcessKey(com.walmartlabs.concord.server.sdk.PartialProcessKey) PartialProcessKey(com.walmartlabs.concord.server.sdk.PartialProcessKey) ProcessKey(com.walmartlabs.concord.server.sdk.ProcessKey) WithTimer(com.walmartlabs.concord.server.sdk.metrics.WithTimer) ApiOperation(io.swagger.annotations.ApiOperation)

Example 47 with ProcessKey

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

the class ProcessCheckpointV2Resource method processCheckpoint.

@GET
@ApiOperation(value = "Process checkpoint")
@javax.ws.rs.Path("{id}/checkpoint")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@WithTimer
public GenericCheckpointResponse processCheckpoint(@ApiParam @PathParam("id") UUID instanceId, @ApiParam @QueryParam("name") String checkpointName, @ApiParam @QueryParam("action") String action) {
    ProcessEntry entry = processManager.assertProcess(instanceId);
    ProcessKey processKey = new ProcessKey(entry.instanceId(), entry.createdAt());
    switch(action) {
        case RESTORE_PROCESS_ACTION:
            {
                return restore(processKey, checkpointName);
            }
        default:
            {
                throw new ConcordApplicationException("Invalid action type: " + action);
            }
    }
}
Also used : ConcordApplicationException(com.walmartlabs.concord.server.sdk.ConcordApplicationException) ProcessEntry(com.walmartlabs.concord.server.process.ProcessEntry) ProcessKey(com.walmartlabs.concord.server.sdk.ProcessKey) WithTimer(com.walmartlabs.concord.server.sdk.metrics.WithTimer) ApiOperation(io.swagger.annotations.ApiOperation)

Example 48 with ProcessKey

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

the class ProcessEventDao method list.

public List<ProcessEventEntry> list(ProcessEventFilter filter) {
    ProcessKey processKey = filter.processKey();
    SelectConditionStep<Record5<Long, UUID, String, OffsetDateTime, JSONB>> q = dsl().select(PROCESS_EVENTS.EVENT_SEQ, PROCESS_EVENTS.EVENT_ID, PROCESS_EVENTS.EVENT_TYPE, PROCESS_EVENTS.EVENT_DATE, function("jsonb_strip_nulls", JSONB.class, PROCESS_EVENTS.EVENT_DATA)).from(PROCESS_EVENTS).where(PROCESS_EVENTS.INSTANCE_ID.eq(processKey.getInstanceId()).and(PROCESS_EVENTS.INSTANCE_CREATED_AT.eq(processKey.getCreatedAt())));
    OffsetDateTime after = filter.after();
    if (after != null) {
        q.and(PROCESS_EVENTS.EVENT_DATE.ge(after));
    }
    Long fromId = filter.fromId();
    if (fromId != null) {
        q.and(PROCESS_EVENTS.EVENT_SEQ.greaterThan(fromId));
    }
    String eventType = filter.eventType();
    if (eventType != null) {
        q.and(PROCESS_EVENTS.EVENT_TYPE.eq(eventType));
    }
    UUID eventCorrelationId = filter.eventCorrelationId();
    if (eventCorrelationId != null) {
        q.and(PgUtils.jsonbText(PROCESS_EVENTS.EVENT_DATA, "correlationId").eq(eventCorrelationId.toString()));
    }
    EventPhase eventPhase = filter.eventPhase();
    if (eventPhase != null) {
        q.and(PgUtils.jsonbText(PROCESS_EVENTS.EVENT_DATA, "phase").eq(eventPhase.getKey()));
    }
    int limit = filter.limit();
    if (limit > 0) {
        q.limit(limit);
    }
    int offset = filter.offset();
    if (offset > 0) {
        q.offset(offset);
    }
    return q.orderBy(PROCESS_EVENTS.EVENT_SEQ).fetch(this::toEntry);
}
Also used : OffsetDateTime(java.time.OffsetDateTime) ProcessKey(com.walmartlabs.concord.server.sdk.ProcessKey)

Example 49 with ProcessKey

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

the class ProcessEventResource method event.

/**
 * Register a process event.
 */
@POST
@ApiOperation(value = "Register a process event", authorizations = { @Authorization("session_key"), @Authorization("api_key") })
@Path("/{processInstanceId}/event")
@Consumes(MediaType.APPLICATION_JSON)
@WithTimer
public void event(@ApiParam @PathParam("processInstanceId") UUID processInstanceId, @ApiParam ProcessEventRequest req) {
    ProcessKey processKey = assertProcessKey(processInstanceId);
    NewProcessEvent e = NewProcessEvent.builder().processKey(processKey).eventType(req.getEventType()).eventDate(req.getEventDate()).data(req.getData()).build();
    eventManager.event(Collections.singletonList(e));
}
Also used : ProcessKey(com.walmartlabs.concord.server.sdk.ProcessKey) PartialProcessKey(com.walmartlabs.concord.server.sdk.PartialProcessKey) WithTimer(com.walmartlabs.concord.server.sdk.metrics.WithTimer) ApiOperation(io.swagger.annotations.ApiOperation)

Example 50 with ProcessKey

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

ProcessKey (com.walmartlabs.concord.server.sdk.ProcessKey)69 WithTimer (com.walmartlabs.concord.server.sdk.metrics.WithTimer)28 Path (java.nio.file.Path)27 PartialProcessKey (com.walmartlabs.concord.server.sdk.PartialProcessKey)25 ApiOperation (io.swagger.annotations.ApiOperation)22 ProcessException (com.walmartlabs.concord.server.process.ProcessException)20 ConcordApplicationException (com.walmartlabs.concord.server.sdk.ConcordApplicationException)16 IOException (java.io.IOException)16 UUID (java.util.UUID)9 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)8 PolicyEngine (com.walmartlabs.concord.policyengine.PolicyEngine)8 Inject (javax.inject.Inject)8 Named (javax.inject.Named)8 ProcessKeyCache (com.walmartlabs.concord.server.process.queue.ProcessKeyCache)7 ProcessQueueDao (com.walmartlabs.concord.server.process.queue.ProcessQueueDao)7 ProcessStateManager (com.walmartlabs.concord.server.process.state.ProcessStateManager)7 UserPrincipal (com.walmartlabs.concord.server.security.UserPrincipal)7 ProcessLogManager (com.walmartlabs.concord.server.process.logs.ProcessLogManager)6 HttpUtils (com.walmartlabs.concord.server.HttpUtils)5 ResourceAccessLevel (com.walmartlabs.concord.server.org.ResourceAccessLevel)5