Search in sources :

Example 31 with ConcordApplicationException

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

the class TeamManager method addUsers.

public void addUsers(String orgName, String teamName, boolean replace, Collection<TeamUserEntry> users) {
    TeamEntry t = assertTeam(orgName, teamName, TeamRole.MAINTAINER, true, true);
    Map<UUID, TeamRole> effectiveUsers = new HashMap<>();
    for (TeamUserEntry u : users) {
        UserType type = u.getUserType();
        if (type == null) {
            type = UserPrincipal.assertCurrent().getType();
        }
        UUID id = u.getUserId();
        if (id == null) {
            id = userManager.getId(u.getUsername(), u.getUserDomain(), type).orElseThrow(() -> new ConcordApplicationException("User not found: " + u.getUsername()));
        }
        TeamRole role = u.getRole();
        if (role == null) {
            role = TeamRole.MEMBER;
        }
        effectiveUsers.put(id, role);
    }
    teamDao.tx(tx -> {
        if (replace) {
            teamDao.removeUsers(tx, t.getId());
        }
        for (Map.Entry<UUID, TeamRole> u : effectiveUsers.entrySet()) {
            UUID id = u.getKey();
            TeamRole role = u.getValue();
            teamDao.upsertUser(tx, t.getId(), id, role);
        }
        validateUsers(tx, t.getOrgId());
    });
    auditLog.add(AuditObject.TEAM, AuditAction.UPDATE).field("orgId", t.getOrgId()).field("teamId", t.getId()).field("name", t.getName()).field("action", "addUsers").field("users", users).field("replace", replace).log();
}
Also used : HashMap(java.util.HashMap) ConcordApplicationException(com.walmartlabs.concord.server.sdk.ConcordApplicationException) UUID(java.util.UUID) UserType(com.walmartlabs.concord.server.user.UserType) HashMap(java.util.HashMap) Map(java.util.Map)

Example 32 with ConcordApplicationException

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

the class ProcessCheckpointResource method uploadCheckpoint.

@POST
@javax.ws.rs.Path("{id}/checkpoint")
@Consumes(MediaType.MULTIPART_FORM_DATA)
public void uploadCheckpoint(@PathParam("id") UUID instanceId, @ApiParam MultipartInput input) {
    // TODO replace with ProcessKeyCache
    ProcessEntry entry = processManager.assertProcess(instanceId);
    ProcessKey processKey = new ProcessKey(entry.instanceId(), entry.createdAt());
    UUID checkpointId = MultipartUtils.assertUuid(input, "id");
    UUID correlationId = MultipartUtils.assertUuid(input, "correlationId");
    String checkpointName = MultipartUtils.assertString(input, "name");
    try (InputStream data = MultipartUtils.assertStream(input, "data");
        TemporaryPath tmpIn = IOUtils.tempFile("checkpoint", ".zip")) {
        Files.copy(data, tmpIn.path(), StandardCopyOption.REPLACE_EXISTING);
        checkpointManager.importCheckpoint(processKey, checkpointId, correlationId, checkpointName, tmpIn.path());
    } catch (ValidationErrorsException e) {
        throw new ConcordApplicationException(e.getMessage(), Response.Status.BAD_REQUEST);
    } catch (IOException e) {
        log.error("uploadCheckpoint ['{}'] -> error", processKey, e);
        throw new ConcordApplicationException("upload error: " + e.getMessage());
    }
    log.info("uploadCheckpoint ['{}'] -> done", processKey);
}
Also used : InputStream(java.io.InputStream) ConcordApplicationException(com.walmartlabs.concord.server.sdk.ConcordApplicationException) ProcessEntry(com.walmartlabs.concord.server.process.ProcessEntry) ProcessKey(com.walmartlabs.concord.server.sdk.ProcessKey) IOException(java.io.IOException) UUID(java.util.UUID) TemporaryPath(com.walmartlabs.concord.common.TemporaryPath) ValidationErrorsException(org.sonatype.siesta.ValidationErrorsException)

Example 33 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.
 *
 * @param input
 * @param parentInstanceId
 * @param sync
 * @return
 */
@POST
@ApiOperation("Start a new process using multipart request data")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.APPLICATION_JSON)
@WithTimer
public StartProcessResponse start(@ApiParam MultipartInput input, @ApiParam @Deprecated @QueryParam("parentId") UUID parentInstanceId, @ApiParam @Deprecated @DefaultValue("false") @QueryParam("sync") boolean sync, @ApiParam @Deprecated @QueryParam("out") String[] out, @Context HttpServletRequest request) {
    boolean sync2 = MultipartUtils.getBoolean(input, Constants.Multipart.SYNC, false);
    if (sync || sync2) {
        throw syncIsForbidden();
    }
    Payload payload;
    try {
        payload = payloadManager.createPayload(input, request);
        // TODO remove after deprecating the old endpoints
        payload = PayloadBuilder.basedOn(payload).parentInstanceId(parentInstanceId).mergeOutExpressions(out).build();
    } catch (IOException e) {
        log.error("start -> error creating a payload: {}", e.getMessage());
        throw new ConcordApplicationException("Error creating a payload", e);
    }
    return toResponse(processManager.start(payload));
}
Also used : ConcordApplicationException(com.walmartlabs.concord.server.sdk.ConcordApplicationException) WithTimer(com.walmartlabs.concord.server.sdk.metrics.WithTimer) ApiOperation(io.swagger.annotations.ApiOperation)

Example 34 with ConcordApplicationException

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

the class ProcessResource method appendLog.

/**
 * Appends a process' log.
 *
 * @param instanceId
 * @param data
 * @see ProcessLogResourceV2
 * @deprecated in favor of the /api/v2/process/{id}/log* endpoints
 */
@POST
@javax.ws.rs.Path("{id}/log")
@Consumes(MediaType.APPLICATION_OCTET_STREAM)
@WithTimer
@Deprecated
public void appendLog(@PathParam("id") UUID instanceId, InputStream data) {
    ProcessKey processKey = assertProcessKey(instanceId);
    try {
        byte[] ab = IOUtils.toByteArray(data);
        int upper = logManager.log(processKey, ab);
        // whenever we accept logs from an external source (e.g. from an Agent) we need to check
        // the log size limits
        int logSizeLimit = processCfg.getLogSizeLimit();
        if (upper >= logSizeLimit) {
            logManager.error(processKey, "Maximum log size reached: {}. Process cancelled.", logSizeLimit);
            processManager.kill(processKey);
        }
    } catch (IOException e) {
        throw new ConcordApplicationException("Error while appending a log: " + e.getMessage());
    }
}
Also used : ConcordApplicationException(com.walmartlabs.concord.server.sdk.ConcordApplicationException) PartialProcessKey(com.walmartlabs.concord.server.sdk.PartialProcessKey) ProcessKey(com.walmartlabs.concord.server.sdk.ProcessKey) EntryPoint(com.walmartlabs.concord.server.process.PayloadManager.EntryPoint) WithTimer(com.walmartlabs.concord.server.sdk.metrics.WithTimer)

Example 35 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 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)

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