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();
}
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);
}
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));
}
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());
}
}
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));
}
Aggregations