use of com.walmartlabs.concord.server.sdk.ConcordApplicationException 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();
}
use of com.walmartlabs.concord.server.sdk.ConcordApplicationException in project concord by walmartlabs.
the class RoleResource method delete.
@DELETE
@ApiOperation("Delete an existing role")
@Path("/{roleName}")
@Produces(MediaType.APPLICATION_JSON)
public GenericOperationResult delete(@ApiParam @PathParam("roleName") @ConcordKey String roleName) {
assertAdmin();
UUID id = roleDao.getId(roleName);
if (id == null) {
throw new ConcordApplicationException("Role not found: " + roleName, Status.NOT_FOUND);
}
roleDao.delete(id);
auditLog.add(AuditObject.ROLE, AuditAction.DELETE).field("roleId", id).field("name", roleName).log();
return new GenericOperationResult(OperationResult.DELETED);
}
use of com.walmartlabs.concord.server.sdk.ConcordApplicationException in project concord by walmartlabs.
the class RoleResource method get.
@GET
@ApiOperation("Get a role's details")
@Path("/{roleName}")
@Produces(MediaType.APPLICATION_JSON)
@WithTimer
public RoleEntry get(@ApiParam @PathParam("roleName") String roleName) {
assertAdmin();
UUID id = roleDao.getId(roleName);
if (id == null) {
throw new ConcordApplicationException("Role not found: " + roleName, Status.NOT_FOUND);
}
return roleDao.get(id);
}
use of com.walmartlabs.concord.server.sdk.ConcordApplicationException in project concord by walmartlabs.
the class RepositoryRefresher method refresh.
public void refresh(String orgName, String projectName, String repositoryName, boolean sync) {
UUID orgId = orgManager.assertAccess(orgName, true).getId();
ProjectEntry projectEntry = assertProject(orgId, projectName, ResourceAccessLevel.READER, true);
UUID projectId = projectEntry.getId();
RepositoryEntry repositoryEntry = assertRepository(projectEntry, repositoryName);
if (!sync) {
Map<String, Object> event = new HashMap<>();
event.put("event", "repositoryRefresh");
event.put("org", orgName);
event.put("project", projectName);
event.put("repository", repositoryName);
externalEventResource.event("concord", event);
return;
}
try (TemporaryPath tmpRepoPath = IOUtils.tempDir("refreshRepo_")) {
repositoryManager.withLock(repositoryEntry.getUrl(), () -> {
Repository repo = repositoryManager.fetch(projectId, repositoryEntry);
repo.export(tmpRepoPath.path());
return null;
});
tx(tx -> {
for (RepositoryRefreshListener l : listeners) {
l.onRefresh(tx, repositoryEntry, tmpRepoPath.path());
}
});
} catch (Exception e) {
String errorMessage = e.getCause() != null ? e.getCause().getMessage() : e.getMessage();
throw new ConcordApplicationException("Error while refreshing repository: \n" + errorMessage, e);
}
}
use of com.walmartlabs.concord.server.sdk.ConcordApplicationException in project concord by walmartlabs.
the class ProcessLogResourceV2 method append.
/**
* Appends a process' log.
*/
@POST
@Path("{id}/log/segment/{segmentId}/data")
@Consumes(MediaType.APPLICATION_OCTET_STREAM)
@WithTimer
public void append(@ApiParam @PathParam("id") UUID instanceId, @ApiParam @PathParam("segmentId") long segmentId, InputStream data) {
ProcessKey processKey = logAccessManager.assertLogAccess(instanceId);
try {
byte[] ab = IOUtils.toByteArray(data);
int upper = logManager.log(processKey, segmentId, ab);
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());
}
}
Aggregations