use of com.walmartlabs.concord.server.sdk.ProcessKey in project concord by walmartlabs.
the class ProcessStateManagerTest method testLargeImport.
@Test
public void testLargeImport() throws Exception {
ProcessKey processKey = new ProcessKey(UUID.randomUUID(), OffsetDateTime.now());
int files = 100;
int chunkSize = 1024 * 1024;
int fileSize = 10 * chunkSize;
byte[] ab = new byte[chunkSize];
Arrays.fill(ab, (byte) 0);
Path baseDir = Files.createTempDirectory("test");
for (int i = 0; i < files; i++) {
Path p = baseDir.resolve("file" + i);
try (OutputStream out = Files.newOutputStream(p, StandardOpenOption.CREATE)) {
for (int j = 0; j < fileSize; j += chunkSize) {
out.write(ab);
}
}
}
ProcessKeyCache processKeyCache = new ProcessKeyCache(new ProcessQueueDao(getConfiguration(), new ConcordObjectMapper(new ObjectMapper())));
ProcessConfiguration stateCfg = new ProcessConfiguration(Duration.of(24, ChronoUnit.HOURS), Collections.singletonList(Constants.Files.CONFIGURATION_FILE_NAME));
ProcessStateManager stateManager = new ProcessStateManager(getConfiguration(), mock(SecretStoreConfiguration.class), stateCfg, mock(PolicyManager.class), mock(ProcessLogManager.class), processKeyCache);
stateManager.importPath(processKey, "/", baseDir, (p, attrs) -> true);
}
use of com.walmartlabs.concord.server.sdk.ProcessKey in project concord by walmartlabs.
the class ProcessAnsibleResource method list.
/**
* Lists Ansible hosts of a specific process.
*/
@GET
@ApiOperation("List Ansible hosts of a specific process")
@Path("/{processInstanceId}/ansible/hosts")
@Produces(MediaType.APPLICATION_JSON)
public // @WithTimer
AnsibleHostListResponse list(@PathParam("processInstanceId") UUID processInstanceId, @QueryParam("host") String host, @QueryParam("hostGroup") String hostGroup, @QueryParam("status") AnsibleHostStatus status, @QueryParam("statuses") List<AnsibleHostStatus> statuses, @QueryParam("playbookId") UUID playbookId, @QueryParam("limit") @DefaultValue("30") int limit, @QueryParam("offset") @DefaultValue("0") int offset) {
ProcessKey key = processKeyCache.get(processInstanceId);
if (key == null) {
return null;
}
if (status != null) {
if (statuses == null) {
statuses = new ArrayList<>();
}
statuses.add(status);
}
List<AnsibleHostEntry> hosts = ansibleDao.list(key.getInstanceId(), key.getCreatedAt(), host, hostGroup, statuses, playbookId, limit, offset);
List<String> hostGroups = ansibleDao.listHostGroups(key.getInstanceId(), key.getCreatedAt(), playbookId);
return ImmutableAnsibleHostListResponse.builder().items(hosts).hostGroups(hostGroups).build();
}
use of com.walmartlabs.concord.server.sdk.ProcessKey in project concord by walmartlabs.
the class ProcessLogResourceV2 method data.
/**
* Retrieves a log segment' data.
*/
@GET
@ApiOperation(value = "Retrieve the log")
@Path("/{id}/log/segment/{segmentId}/data")
@Produces(MediaType.APPLICATION_OCTET_STREAM)
@WithTimer
public Response data(@ApiParam @PathParam("id") UUID instanceId, @ApiParam @PathParam("segmentId") long segmentId, @HeaderParam("range") String rangeHeader) {
ProcessKey processKey = logAccessManager.assertLogAccess(instanceId);
HttpUtils.Range range = HttpUtils.parseRangeHeaderValue(rangeHeader);
ProcessLog l = logManager.segmentData(processKey, segmentId, range.start(), range.end());
return toResponse(instanceId, segmentId, l, range);
}
use of com.walmartlabs.concord.server.sdk.ProcessKey in project concord by walmartlabs.
the class ProcessLogResourceV2 method segment.
/**
* Create a new process log segment.
*/
@POST
@ApiOperation(value = "Create process log segment")
@Path("{id}/log/segment")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@WithTimer
public LogSegmentOperationResponse segment(@ApiParam @PathParam("id") UUID instanceId, @ApiParam LogSegmentRequest request) {
ProcessKey processKey = logAccessManager.assertLogAccess(instanceId);
long segmentId = logManager.createSegment(processKey, request.correlationId(), request.name(), request.createdAt());
return new LogSegmentOperationResponse(segmentId, OperationResult.CREATED);
}
use of com.walmartlabs.concord.server.sdk.ProcessKey in project concord by walmartlabs.
the class ProcessResource method downloadState.
/**
* Downloads the current state snapshot of a process.
*/
@GET
@ApiOperation(value = "Download a process state snapshot", response = File.class)
@javax.ws.rs.Path("/{id}/state/snapshot")
@Produces("application/zip")
public Response downloadState(@ApiParam @PathParam("id") UUID instanceId) {
ProcessEntry entry = assertProcess(PartialProcessKey.from(instanceId));
ProcessKey processKey = new ProcessKey(entry.instanceId(), entry.createdAt());
assertProcessAccess(entry, "attachments");
StreamingOutput out = output -> {
try (ZipArchiveOutputStream dst = new ZipArchiveOutputStream(output)) {
stateManager.export(processKey, zipTo(dst));
}
};
return Response.ok(out, "application/zip").header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + instanceId + ".zip\"").build();
}
Aggregations