Search in sources :

Example 6 with PartialProcessKey

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

the class ProcessResource method get.

/**
 * Returns a process instance details.
 *
 * @deprecated use {@link ProcessResourceV2#get(UUID, Set)}
 */
@GET
@ApiOperation("Get a process' details")
@javax.ws.rs.Path("/{id}")
@Produces(MediaType.APPLICATION_JSON)
@WithTimer
@Deprecated
public ProcessEntry get(@ApiParam @PathParam("id") UUID instanceId) {
    PartialProcessKey processKey = PartialProcessKey.from(instanceId);
    ProcessEntry e = processQueueManager.get(processKey);
    if (e == null) {
        log.warn("get ['{}'] -> not found", instanceId);
        throw new ConcordApplicationException("Process instance not found", Status.NOT_FOUND);
    }
    return e;
}
Also used : PartialProcessKey(com.walmartlabs.concord.server.sdk.PartialProcessKey) ConcordApplicationException(com.walmartlabs.concord.server.sdk.ConcordApplicationException) WithTimer(com.walmartlabs.concord.server.sdk.metrics.WithTimer) ApiOperation(io.swagger.annotations.ApiOperation)

Example 7 with PartialProcessKey

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

the class ProcessResource method start.

/**
 * Starts a new process instance using the specified entry point and provided configuration.
 *
 * @param entryPoint
 * @param req
 * @param parentInstanceId
 * @param sync
 * @return
 * @deprecated use {@link #start(MultipartInput, UUID, boolean, String[], HttpServletRequest)}
 */
@POST
@ApiOperation(value = "Start a new process using the specified entry point and provided configuration", hidden = true)
@javax.ws.rs.Path("/{entryPoint}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@WithTimer(suffix = "_json")
@Deprecated
public StartProcessResponse start(@PathParam("entryPoint") String entryPoint, Map<String, Object> req, @QueryParam("parentId") UUID parentInstanceId, @Deprecated @DefaultValue("false") @QueryParam("sync") boolean sync, @QueryParam("out") String[] out) {
    if (sync) {
        throw syncIsForbidden();
    }
    assertPartialKey(parentInstanceId);
    PartialProcessKey processKey = PartialProcessKey.from(UUID.randomUUID());
    UUID orgId = OrganizationManager.DEFAULT_ORG_ID;
    EntryPoint ep = payloadManager.parseEntryPoint(processKey, orgId, entryPoint);
    UserPrincipal userPrincipal = UserPrincipal.assertCurrent();
    Payload payload;
    try {
        payload = payloadManager.createPayload(processKey, parentInstanceId, userPrincipal.getId(), userPrincipal.getUsername(), ep, req, out);
    } catch (IOException e) {
        log.error("start ['{}'] -> error creating a payload: {}", entryPoint, e);
        throw new ConcordApplicationException("Error creating a payload", e);
    }
    return toResponse(processManager.start(payload));
}
Also used : PartialProcessKey(com.walmartlabs.concord.server.sdk.PartialProcessKey) ConcordApplicationException(com.walmartlabs.concord.server.sdk.ConcordApplicationException) EntryPoint(com.walmartlabs.concord.server.process.PayloadManager.EntryPoint) UserPrincipal(com.walmartlabs.concord.server.security.UserPrincipal) WithTimer(com.walmartlabs.concord.server.sdk.metrics.WithTimer) ApiOperation(io.swagger.annotations.ApiOperation)

Example 8 with PartialProcessKey

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

the class ProcessResource method downloadAttachment.

/**
 * Returns a process' attachment file.
 */
@GET
@ApiOperation(value = "Download a process' attachment", response = File.class)
@javax.ws.rs.Path("/{id}/attachment/{name:.*}")
@Produces(MediaType.APPLICATION_OCTET_STREAM)
public Response downloadAttachment(@ApiParam @PathParam("id") UUID instanceId, @PathParam("name") @NotNull @Size(min = 1) String attachmentName) {
    ProcessEntry processEntry = processManager.assertProcess(instanceId);
    assertProcessAccess(processEntry, "attachment");
    PartialProcessKey processKey = new ProcessKey(processEntry.instanceId(), processEntry.createdAt());
    // TODO replace with javax.validation
    if (attachmentName.endsWith("/")) {
        throw new ConcordApplicationException("Invalid attachment name: " + attachmentName, Status.BAD_REQUEST);
    }
    String resource = path(Constants.Files.JOB_ATTACHMENTS_DIR_NAME, attachmentName);
    Optional<Path> o = stateManager.get(processKey, resource, src -> {
        try {
            Path tmp = IOUtils.createTempFile("attachment", ".bin");
            try (OutputStream dst = Files.newOutputStream(tmp)) {
                IOUtils.copy(src, dst);
            }
            return Optional.of(tmp);
        } catch (IOException e) {
            throw new ConcordApplicationException("Error while exporting an attachment: " + attachmentName, e);
        }
    });
    if (!o.isPresent()) {
        return Response.status(Status.NOT_FOUND).build();
    }
    Path tmp = o.get();
    return Response.ok((StreamingOutput) out -> {
        try (InputStream in = Files.newInputStream(tmp)) {
            IOUtils.copy(in, out);
        } finally {
            Files.delete(tmp);
        }
    }).build();
}
Also used : Path(java.nio.file.Path) PartialProcessKey(com.walmartlabs.concord.server.sdk.PartialProcessKey) ConcordApplicationException(com.walmartlabs.concord.server.sdk.ConcordApplicationException) ZipArchiveOutputStream(org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream) PartialProcessKey(com.walmartlabs.concord.server.sdk.PartialProcessKey) ProcessKey(com.walmartlabs.concord.server.sdk.ProcessKey) ApiOperation(io.swagger.annotations.ApiOperation)

Example 9 with PartialProcessKey

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

the class ProcessResource method start.

/**
 * Starts a new process instance using the specified entry point and multipart request data.
 *
 * @param entryPoint
 * @param input
 * @param parentInstanceId
 * @param sync
 * @return
 * @deprecated use {@link #start(MultipartInput, UUID, boolean, String[], HttpServletRequest)}
 */
@POST
@ApiOperation(value = "Start a new process using the specified entry point and multipart request data", hidden = true)
@javax.ws.rs.Path("/{entryPoint}")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.APPLICATION_JSON)
@WithTimer(suffix = "_with_entrypoint")
@Deprecated
public StartProcessResponse start(@PathParam("entryPoint") String entryPoint, MultipartInput input, @QueryParam("parentId") UUID parentInstanceId, @Deprecated @DefaultValue("false") @QueryParam("sync") boolean sync, @QueryParam("out") String[] out) {
    if (sync) {
        throw syncIsForbidden();
    }
    assertPartialKey(parentInstanceId);
    PartialProcessKey processKey = PartialProcessKey.from(UUID.randomUUID());
    UUID orgId = OrganizationManager.DEFAULT_ORG_ID;
    EntryPoint ep = payloadManager.parseEntryPoint(processKey, orgId, entryPoint);
    UserPrincipal userPrincipal = UserPrincipal.assertCurrent();
    Payload payload;
    try {
        payload = payloadManager.createPayload(processKey, parentInstanceId, userPrincipal.getId(), userPrincipal.getUsername(), ep, input, out);
    } catch (IOException e) {
        log.error("start ['{}'] -> error creating a payload: {}", entryPoint, e);
        throw new ConcordApplicationException("Error creating a payload", e);
    }
    return toResponse(processManager.start(payload));
}
Also used : PartialProcessKey(com.walmartlabs.concord.server.sdk.PartialProcessKey) ConcordApplicationException(com.walmartlabs.concord.server.sdk.ConcordApplicationException) EntryPoint(com.walmartlabs.concord.server.process.PayloadManager.EntryPoint) UserPrincipal(com.walmartlabs.concord.server.security.UserPrincipal) WithTimer(com.walmartlabs.concord.server.sdk.metrics.WithTimer) ApiOperation(io.swagger.annotations.ApiOperation)

Example 10 with PartialProcessKey

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

the class ProcessResource method fork.

/**
 * Starts a new child process by forking the start of the specified parent process.
 *
 * @param parentInstanceId
 * @param req
 * @param sync
 * @return
 */
@POST
@ApiOperation("Fork a process")
@javax.ws.rs.Path("/{id}/fork")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@WithTimer
public StartProcessResponse fork(@ApiParam @PathParam("id") UUID parentInstanceId, @ApiParam Map<String, Object> req, @ApiParam @Deprecated @DefaultValue("false") @QueryParam("sync") boolean sync, @ApiParam @QueryParam("out") String[] out) {
    if (sync) {
        throw syncIsForbidden();
    }
    ProcessEntry parent = processQueueManager.get(PartialProcessKey.from(parentInstanceId));
    if (parent == null) {
        throw new ValidationErrorsException("Unknown parent instance ID: " + parentInstanceId);
    }
    PartialProcessKey processKey = PartialProcessKey.from(UUID.randomUUID());
    ProcessKey parentProcessKey = new ProcessKey(parent.instanceId(), parent.createdAt());
    UUID projectId = parent.projectId();
    UserPrincipal userPrincipal = UserPrincipal.assertCurrent();
    Set<String> handlers = parent.handlers();
    Imports imports = queueDao.getImports(parentProcessKey);
    Payload payload;
    try {
        payload = payloadManager.createFork(processKey, parentProcessKey, ProcessKind.DEFAULT, userPrincipal.getId(), userPrincipal.getUsername(), projectId, req, out, handlers, imports);
    } catch (IOException e) {
        log.error("fork ['{}', '{}'] -> error creating a payload: {}", processKey, parentProcessKey, e);
        throw new ConcordApplicationException("Error creating a payload", e);
    }
    return toResponse(processManager.startFork(payload));
}
Also used : PartialProcessKey(com.walmartlabs.concord.server.sdk.PartialProcessKey) ConcordApplicationException(com.walmartlabs.concord.server.sdk.ConcordApplicationException) PartialProcessKey(com.walmartlabs.concord.server.sdk.PartialProcessKey) ProcessKey(com.walmartlabs.concord.server.sdk.ProcessKey) Imports(com.walmartlabs.concord.imports.Imports) ValidationErrorsException(org.sonatype.siesta.ValidationErrorsException) UserPrincipal(com.walmartlabs.concord.server.security.UserPrincipal) WithTimer(com.walmartlabs.concord.server.sdk.metrics.WithTimer) ApiOperation(io.swagger.annotations.ApiOperation)

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