Search in sources :

Example 16 with ProcessKey

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);
}
Also used : Path(java.nio.file.Path) ProcessKeyCache(com.walmartlabs.concord.server.process.queue.ProcessKeyCache) PolicyManager(com.walmartlabs.concord.server.policy.PolicyManager) SecretStoreConfiguration(com.walmartlabs.concord.server.cfg.SecretStoreConfiguration) OutputStream(java.io.OutputStream) ProcessKey(com.walmartlabs.concord.server.sdk.ProcessKey) ProcessQueueDao(com.walmartlabs.concord.server.process.queue.ProcessQueueDao) ProcessConfiguration(com.walmartlabs.concord.server.cfg.ProcessConfiguration) ConcordObjectMapper(com.walmartlabs.concord.server.ConcordObjectMapper) ProcessLogManager(com.walmartlabs.concord.server.process.logs.ProcessLogManager) ConcordObjectMapper(com.walmartlabs.concord.server.ConcordObjectMapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.jupiter.api.Test) AbstractDaoTest(com.walmartlabs.concord.server.AbstractDaoTest)

Example 17 with ProcessKey

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();
}
Also used : ProcessKey(com.walmartlabs.concord.server.sdk.ProcessKey) ApiOperation(io.swagger.annotations.ApiOperation)

Example 18 with ProcessKey

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);
}
Also used : HttpUtils(com.walmartlabs.concord.server.HttpUtils) ProcessKey(com.walmartlabs.concord.server.sdk.ProcessKey) ProcessLog(com.walmartlabs.concord.server.process.logs.ProcessLogsDao.ProcessLog) WithTimer(com.walmartlabs.concord.server.sdk.metrics.WithTimer) ApiOperation(io.swagger.annotations.ApiOperation)

Example 19 with ProcessKey

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);
}
Also used : ProcessKey(com.walmartlabs.concord.server.sdk.ProcessKey) WithTimer(com.walmartlabs.concord.server.sdk.metrics.WithTimer) ApiOperation(io.swagger.annotations.ApiOperation)

Example 20 with ProcessKey

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();
}
Also used : ProcessWaitManager(com.walmartlabs.concord.server.process.waits.ProcessWaitManager) Resource(org.sonatype.siesta.Resource) Size(javax.validation.constraints.Size) ProcessLogAccessManager(com.walmartlabs.concord.server.process.logs.ProcessLogAccessManager) PolicyManager(com.walmartlabs.concord.server.policy.PolicyManager) LoggerFactory(org.slf4j.LoggerFactory) ProcessResult(com.walmartlabs.concord.server.process.ProcessManager.ProcessResult) ApiParam(io.swagger.annotations.ApiParam) MultipartInput(org.jboss.resteasy.plugins.providers.multipart.MultipartInput) ProcessKeyCache(com.walmartlabs.concord.server.process.queue.ProcessKeyCache) ApiOperation(io.swagger.annotations.ApiOperation) ProcessQueueDao(com.walmartlabs.concord.server.process.queue.ProcessQueueDao) WithTimer(com.walmartlabs.concord.server.sdk.metrics.WithTimer) ProcessWaitEntry(com.walmartlabs.concord.server.process.ProcessEntry.ProcessWaitEntry) Path(java.nio.file.Path) PartialProcessKey(com.walmartlabs.concord.server.sdk.PartialProcessKey) ProcessConfiguration(com.walmartlabs.concord.server.cfg.ProcessConfiguration) ProcessLogManager(com.walmartlabs.concord.server.process.logs.ProcessLogManager) IOUtils(com.walmartlabs.concord.common.IOUtils) EncryptedProjectValueManager(com.walmartlabs.concord.server.org.project.EncryptedProjectValueManager) ProcessStatus(com.walmartlabs.concord.server.sdk.ProcessStatus) NotNull(javax.validation.constraints.NotNull) Collectors(java.util.stream.Collectors) SecretStoreConfiguration(com.walmartlabs.concord.server.cfg.SecretStoreConfiguration) UnauthorizedException(org.apache.shiro.authz.UnauthorizedException) javax.ws.rs(javax.ws.rs) ValidationErrorsException(org.sonatype.siesta.ValidationErrorsException) CheckResult(com.walmartlabs.concord.policyengine.CheckResult) HttpUtils(com.walmartlabs.concord.server.HttpUtils) java.util(java.util) AbstractWaitCondition(com.walmartlabs.concord.server.process.waits.AbstractWaitCondition) ProcessQueueManager(com.walmartlabs.concord.server.process.queue.ProcessQueueManager) AttachmentsRule(com.walmartlabs.concord.policyengine.AttachmentsRule) ProcessKey(com.walmartlabs.concord.server.sdk.ProcessKey) Singleton(javax.inject.Singleton) ConfigurationUtils(com.walmartlabs.concord.common.ConfigurationUtils) StandardCopyOption(java.nio.file.StandardCopyOption) MessageFormat(java.text.MessageFormat) ProcessStateManager.zipTo(com.walmartlabs.concord.server.process.state.ProcessStateManager.zipTo) Inject(javax.inject.Inject) MultipartUtils(com.walmartlabs.concord.server.MultipartUtils) ExpressionUtils(com.walmartlabs.concord.server.events.ExpressionUtils) EntryPoint(com.walmartlabs.concord.server.process.PayloadManager.EntryPoint) HttpServletRequest(javax.servlet.http.HttpServletRequest) Constants(com.walmartlabs.concord.sdk.Constants) PolicyEngine(com.walmartlabs.concord.policyengine.PolicyEngine) Imports(com.walmartlabs.concord.imports.Imports) OffsetDateTimeParam(com.walmartlabs.concord.server.OffsetDateTimeParam) Api(io.swagger.annotations.Api) ZipArchiveOutputStream(org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream) Named(javax.inject.Named) Status(javax.ws.rs.core.Response.Status) ProcessStatusHistoryEntry(com.walmartlabs.concord.server.process.ProcessEntry.ProcessStatusHistoryEntry) ProcessLog(com.walmartlabs.concord.server.process.logs.ProcessLogsDao.ProcessLog) Roles(com.walmartlabs.concord.server.security.Roles) UserPrincipal(com.walmartlabs.concord.server.security.UserPrincipal) ProcessStateManager(com.walmartlabs.concord.server.process.state.ProcessStateManager) Logger(org.slf4j.Logger) Files(java.nio.file.Files) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Validate(org.sonatype.siesta.Validate) PolicyException(com.walmartlabs.concord.server.policy.PolicyException) ProjectAccessManager(com.walmartlabs.concord.server.org.project.ProjectAccessManager) javax.ws.rs.core(javax.ws.rs.core) ProcessFilter(com.walmartlabs.concord.server.process.queue.ProcessFilter) OrganizationManager(com.walmartlabs.concord.server.org.OrganizationManager) java.io(java.io) ProcessStateManager.path(com.walmartlabs.concord.server.process.state.ProcessStateManager.path) ConcordApplicationException(com.walmartlabs.concord.server.sdk.ConcordApplicationException) ResourceAccessLevel(com.walmartlabs.concord.server.org.ResourceAccessLevel) Authorization(io.swagger.annotations.Authorization) ZipArchiveOutputStream(org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream) PartialProcessKey(com.walmartlabs.concord.server.sdk.PartialProcessKey) ProcessKey(com.walmartlabs.concord.server.sdk.ProcessKey) ApiOperation(io.swagger.annotations.ApiOperation)

Aggregations

ProcessKey (com.walmartlabs.concord.server.sdk.ProcessKey)69 WithTimer (com.walmartlabs.concord.server.sdk.metrics.WithTimer)28 Path (java.nio.file.Path)27 PartialProcessKey (com.walmartlabs.concord.server.sdk.PartialProcessKey)25 ApiOperation (io.swagger.annotations.ApiOperation)22 ProcessException (com.walmartlabs.concord.server.process.ProcessException)20 ConcordApplicationException (com.walmartlabs.concord.server.sdk.ConcordApplicationException)16 IOException (java.io.IOException)16 UUID (java.util.UUID)9 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)8 PolicyEngine (com.walmartlabs.concord.policyengine.PolicyEngine)8 Inject (javax.inject.Inject)8 Named (javax.inject.Named)8 ProcessKeyCache (com.walmartlabs.concord.server.process.queue.ProcessKeyCache)7 ProcessQueueDao (com.walmartlabs.concord.server.process.queue.ProcessQueueDao)7 ProcessStateManager (com.walmartlabs.concord.server.process.state.ProcessStateManager)7 UserPrincipal (com.walmartlabs.concord.server.security.UserPrincipal)7 ProcessLogManager (com.walmartlabs.concord.server.process.logs.ProcessLogManager)6 HttpUtils (com.walmartlabs.concord.server.HttpUtils)5 ResourceAccessLevel (com.walmartlabs.concord.server.org.ResourceAccessLevel)5