Search in sources :

Example 41 with ConcordApplicationException

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

the class ProcessManager method assertRepositoryDisabled.

private void assertRepositoryDisabled(Payload payload) {
    UUID repoId = payload.getHeader(Payload.REPOSITORY_ID);
    if (repoId == null) {
        return;
    }
    RepositoryEntry repo = repositoryDao.get(repoId);
    if (repo.isDisabled()) {
        throw new ConcordApplicationException("Repository is disabled -> " + repo.getName());
    }
}
Also used : ConcordApplicationException(com.walmartlabs.concord.server.sdk.ConcordApplicationException) RepositoryEntry(com.walmartlabs.concord.server.org.project.RepositoryEntry)

Example 42 with ConcordApplicationException

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

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

Example 44 with ConcordApplicationException

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

the class ProcessResource method decrypt.

/**
 * Decrypt a base64 string previosly encrypted with the process' project key.
 *
 * @param instanceId
 * @param data
 * @return
 */
@POST
@javax.ws.rs.Path("{id}/decrypt")
@Consumes(MediaType.APPLICATION_OCTET_STREAM)
@Produces(MediaType.APPLICATION_OCTET_STREAM)
@WithTimer
public Response decrypt(@PathParam("id") UUID instanceId, InputStream data) {
    ProcessEntry entry = assertProcess(PartialProcessKey.from(instanceId));
    if (entry.projectId() == null) {
        throw new ConcordApplicationException("Project is required", Status.BAD_REQUEST);
    }
    ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
    try {
        int read;
        byte[] buf = new byte[1024];
        while ((read = data.read(buf)) > 0) {
            baos.write(buf, 0, read);
            if (baos.size() > secretStoreCfg.getMaxEncryptedStringLength()) {
                throw new ConcordApplicationException("Value too big, limit: " + secretStoreCfg.getMaxEncryptedStringLength(), Status.BAD_REQUEST);
            }
        }
    } catch (IOException e) {
        throw new ConcordApplicationException("Error while reading encrypted data: " + e.getMessage(), e);
    }
    try {
        UUID projectId = entry.projectId();
        byte[] result = encryptedValueManager.decrypt(projectId, baos.toByteArray());
        return Response.ok((StreamingOutput) output -> output.write(result)).build();
    } catch (SecurityException e) {
        throw new ConcordApplicationException(e.getMessage(), Status.BAD_REQUEST);
    } catch (Exception e) {
        throw new ConcordApplicationException("Decrypt error: " + e.getMessage());
    }
}
Also used : ConcordApplicationException(com.walmartlabs.concord.server.sdk.ConcordApplicationException) EntryPoint(com.walmartlabs.concord.server.process.PayloadManager.EntryPoint) UnauthorizedException(org.apache.shiro.authz.UnauthorizedException) ValidationErrorsException(org.sonatype.siesta.ValidationErrorsException) PolicyException(com.walmartlabs.concord.server.policy.PolicyException) ConcordApplicationException(com.walmartlabs.concord.server.sdk.ConcordApplicationException) WithTimer(com.walmartlabs.concord.server.sdk.metrics.WithTimer)

Example 45 with ConcordApplicationException

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

the class ProcessResource method start.

/**
 * Starts a new process instance using the specified entry point and payload archive.
 *
 * @param entryPoint
 * @param in
 * @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 payload archive", hidden = true)
@javax.ws.rs.Path("/{entryPoint}")
@Consumes(MediaType.APPLICATION_OCTET_STREAM)
@Produces(MediaType.APPLICATION_JSON)
@WithTimer(suffix = "_octetstream_and_entrypoint")
@Deprecated
public StartProcessResponse start(@PathParam("entryPoint") String entryPoint, InputStream in, @QueryParam("parentId") UUID parentInstanceId, @Deprecated @DefaultValue("false") @QueryParam("sync") boolean sync, @QueryParam("out") String[] out) {
    if (sync) {
        throw syncIsForbidden();
    }
    // allow empty POST requests
    if (isEmpty(in)) {
        return start(entryPoint, parentInstanceId, sync, out);
    }
    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, in, 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)

Aggregations

ConcordApplicationException (com.walmartlabs.concord.server.sdk.ConcordApplicationException)70 ApiOperation (io.swagger.annotations.ApiOperation)28 UUID (java.util.UUID)22 WithTimer (com.walmartlabs.concord.server.sdk.metrics.WithTimer)21 PartialProcessKey (com.walmartlabs.concord.server.sdk.PartialProcessKey)18 IOException (java.io.IOException)14 ValidationErrorsException (org.sonatype.siesta.ValidationErrorsException)12 GenericOperationResult (com.walmartlabs.concord.server.GenericOperationResult)11 ProcessKey (com.walmartlabs.concord.server.sdk.ProcessKey)11 Validate (org.sonatype.siesta.Validate)11 Path (java.nio.file.Path)10 UserPrincipal (com.walmartlabs.concord.server.security.UserPrincipal)9 OrganizationEntry (com.walmartlabs.concord.server.org.OrganizationEntry)8 EntryPoint (com.walmartlabs.concord.server.process.PayloadManager.EntryPoint)6 ProcessStatus (com.walmartlabs.concord.server.sdk.ProcessStatus)6 UnauthorizedException (org.apache.shiro.authz.UnauthorizedException)6 UserEntry (com.walmartlabs.concord.server.user.UserEntry)5 InputStream (java.io.InputStream)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 Form (com.walmartlabs.concord.forms.Form)3