Search in sources :

Example 46 with WithTimer

use of com.walmartlabs.concord.server.sdk.metrics.WithTimer in project concord by walmartlabs.

the class ProcessResource method kill.

/**
 * Forcefully stops a process.
 *
 * @param instanceId
 */
@DELETE
@ApiOperation("Forcefully stops a process")
@javax.ws.rs.Path("/{id}")
@WithTimer
public void kill(@ApiParam @PathParam("id") UUID instanceId) {
    ProcessKey processKey = assertProcessKey(instanceId);
    processManager.kill(processKey);
}
Also used : PartialProcessKey(com.walmartlabs.concord.server.sdk.PartialProcessKey) ProcessKey(com.walmartlabs.concord.server.sdk.ProcessKey) WithTimer(com.walmartlabs.concord.server.sdk.metrics.WithTimer) ApiOperation(io.swagger.annotations.ApiOperation)

Example 47 with WithTimer

use of com.walmartlabs.concord.server.sdk.metrics.WithTimer in project concord by walmartlabs.

the class ProcessResource method listAttachments.

/**
 * Lists process attachments.
 *
 * @param instanceId
 * @return
 */
@GET
@ApiOperation(value = "List attachments", responseContainer = "list", response = String.class)
@javax.ws.rs.Path("/{id}/attachment")
@Produces(MediaType.APPLICATION_JSON)
@WithTimer
public List<String> listAttachments(@ApiParam @PathParam("id") UUID instanceId) {
    ProcessEntry processEntry = processManager.assertProcess(instanceId);
    assertProcessAccess(processEntry, "attachments");
    PartialProcessKey processKey = new ProcessKey(processEntry.instanceId(), processEntry.createdAt());
    String resource = Constants.Files.JOB_ATTACHMENTS_DIR_NAME + "/";
    List<String> l = stateManager.list(processKey, resource);
    return l.stream().map(s -> s.substring(resource.length())).collect(Collectors.toList());
}
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) PartialProcessKey(com.walmartlabs.concord.server.sdk.PartialProcessKey) PartialProcessKey(com.walmartlabs.concord.server.sdk.PartialProcessKey) ProcessKey(com.walmartlabs.concord.server.sdk.ProcessKey) WithTimer(com.walmartlabs.concord.server.sdk.metrics.WithTimer) ApiOperation(io.swagger.annotations.ApiOperation)

Example 48 with WithTimer

use of com.walmartlabs.concord.server.sdk.metrics.WithTimer in project concord by walmartlabs.

the class ProcessResourceV2 method get.

/**
 * Returns a process instance's details.
 */
@GET
@ApiOperation("Get a process' details")
@Path("/{id}")
@Produces(MediaType.APPLICATION_JSON)
@WithTimer
public ProcessEntry get(@ApiParam @PathParam("id") UUID instanceId, @ApiParam @QueryParam("include") Set<ProcessDataInclude> includes) {
    PartialProcessKey processKey = PartialProcessKey.from(instanceId);
    ProcessEntry e = processQueueManager.get(processKey, includes);
    if (e == null) {
        log.warn("get ['{}'] -> not found", instanceId);
        throw new ConcordApplicationException("Process instance not found", Status.NOT_FOUND);
    }
    if (e.projectId() != null) {
        projectAccessManager.assertAccess(e.orgId(), e.projectId(), null, ResourceAccessLevel.READER, false);
    }
    return e;
}
Also used : PartialProcessKey(com.walmartlabs.concord.server.sdk.PartialProcessKey) ConcordApplicationException(com.walmartlabs.concord.server.sdk.ConcordApplicationException) WithTimer(com.walmartlabs.concord.server.sdk.metrics.WithTimer) ApiOperation(io.swagger.annotations.ApiOperation)

Example 49 with WithTimer

use of com.walmartlabs.concord.server.sdk.metrics.WithTimer in project concord by walmartlabs.

the class PayloadManager method createPayload.

@WithTimer
public Payload createPayload(MultipartInput input, HttpServletRequest request) throws IOException {
    PartialProcessKey processKey = PartialProcessKey.create();
    UUID parentInstanceId = MultipartUtils.getUuid(input, Constants.Multipart.PARENT_INSTANCE_ID);
    UUID orgId = getOrg(input);
    UUID projectId = getProject(input, orgId);
    UUID repoId = getRepo(input, projectId);
    if (repoId != null && projectId == null) {
        // allow starting processes by specifying repository IDs without project IDs or names
        projectId = repositoryDao.getProjectId(repoId);
    }
    String entryPoint = MultipartUtils.getString(input, Constants.Multipart.ENTRY_POINT);
    UserPrincipal initiator = UserPrincipal.assertCurrent();
    String[] out = getOutExpressions(input);
    Map<String, Object> meta = MultipartUtils.getMap(input, Constants.Multipart.META);
    if (meta == null) {
        meta = Collections.emptyMap();
    }
    return PayloadBuilder.start(processKey).parentInstanceId(parentInstanceId).with(input).organization(orgId).project(projectId).repository(repoId).entryPoint(entryPoint).outExpressions(out).initiator(initiator.getId(), initiator.getUsername()).meta(meta).request(request).build();
}
Also used : PartialProcessKey(com.walmartlabs.concord.server.sdk.PartialProcessKey) UUID(java.util.UUID) UserPrincipal(com.walmartlabs.concord.server.security.UserPrincipal) WithTimer(com.walmartlabs.concord.server.sdk.metrics.WithTimer)

Example 50 with WithTimer

use of com.walmartlabs.concord.server.sdk.metrics.WithTimer in project concord by walmartlabs.

the class ProcessCheckpointV2Resource method processCheckpoint.

@GET
@ApiOperation(value = "Process checkpoint")
@javax.ws.rs.Path("{id}/checkpoint")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@WithTimer
public GenericCheckpointResponse processCheckpoint(@ApiParam @PathParam("id") UUID instanceId, @ApiParam @QueryParam("name") String checkpointName, @ApiParam @QueryParam("action") String action) {
    ProcessEntry entry = processManager.assertProcess(instanceId);
    ProcessKey processKey = new ProcessKey(entry.instanceId(), entry.createdAt());
    switch(action) {
        case RESTORE_PROCESS_ACTION:
            {
                return restore(processKey, checkpointName);
            }
        default:
            {
                throw new ConcordApplicationException("Invalid action type: " + action);
            }
    }
}
Also used : ConcordApplicationException(com.walmartlabs.concord.server.sdk.ConcordApplicationException) ProcessEntry(com.walmartlabs.concord.server.process.ProcessEntry) ProcessKey(com.walmartlabs.concord.server.sdk.ProcessKey) WithTimer(com.walmartlabs.concord.server.sdk.metrics.WithTimer) ApiOperation(io.swagger.annotations.ApiOperation)

Aggregations

WithTimer (com.walmartlabs.concord.server.sdk.metrics.WithTimer)64 ApiOperation (io.swagger.annotations.ApiOperation)32 ProcessKey (com.walmartlabs.concord.server.sdk.ProcessKey)26 PartialProcessKey (com.walmartlabs.concord.server.sdk.PartialProcessKey)24 ConcordApplicationException (com.walmartlabs.concord.server.sdk.ConcordApplicationException)22 UserPrincipal (com.walmartlabs.concord.server.security.UserPrincipal)16 UnauthorizedException (org.apache.shiro.authz.UnauthorizedException)10 UUID (java.util.UUID)9 ProcessEntry (com.walmartlabs.concord.server.process.ProcessEntry)7 EntryPoint (com.walmartlabs.concord.server.process.PayloadManager.EntryPoint)6 Inject (javax.inject.Inject)5 Named (javax.inject.Named)5 Payload (com.walmartlabs.concord.server.process.Payload)4 Path (java.nio.file.Path)4 ValidationErrorsException (org.sonatype.siesta.ValidationErrorsException)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 HttpUtils (com.walmartlabs.concord.server.HttpUtils)3 ProcessFilter (com.walmartlabs.concord.server.process.queue.ProcessFilter)3 UserEntry (com.walmartlabs.concord.server.user.UserEntry)3 IOException (java.io.IOException)3