Search in sources :

Example 1 with ProcessEntry

use of com.walmartlabs.concord.server.process.ProcessEntry in project concord by walmartlabs.

the class ProcessLocksResource method unlock.

/**
 * Releases the lock.
 */
@POST
@ApiOperation("Releases the lock")
@Path("/{processInstanceId}/unlock/{lockName}")
@WithTimer
public void unlock(@PathParam("processInstanceId") UUID instanceId, @PathParam("lockName") String lockName, @QueryParam("scope") @DefaultValue("PROJECT") ProcessLockScope scope) {
    ProcessEntry e = assertProcess(instanceId);
    dao.delete(e.instanceId(), e.orgId(), e.projectId(), scope, lockName);
}
Also used : ProcessEntry(com.walmartlabs.concord.server.process.ProcessEntry) WithTimer(com.walmartlabs.concord.server.sdk.metrics.WithTimer) ApiOperation(io.swagger.annotations.ApiOperation)

Example 2 with ProcessEntry

use of com.walmartlabs.concord.server.process.ProcessEntry in project concord by walmartlabs.

the class ProcessLocksResource method tryLock.

/**
 * Acquires the lock if it is available and returns the LockResult.acquired = true.
 * If the lock is not available then this method will return the LockResult.acquired = false.
 */
@POST
@ApiOperation("Try lock")
@Path("/{processInstanceId}/lock/{lockName}")
@Produces(MediaType.APPLICATION_JSON)
@WithTimer
public LockResult tryLock(@PathParam("processInstanceId") UUID instanceId, @PathParam("lockName") String lockName, @QueryParam("scope") @DefaultValue("PROJECT") ProcessLockScope scope) {
    ProcessEntry e = assertProcess(instanceId);
    LockEntry lock = dao.tryLock(new ProcessKey(e.instanceId(), e.createdAt()), e.orgId(), e.projectId(), scope, lockName);
    boolean acquired = lock.instanceId().equals(instanceId);
    return LockResult.builder().acquired(acquired).info(lock).build();
}
Also used : ProcessEntry(com.walmartlabs.concord.server.process.ProcessEntry) ProcessKey(com.walmartlabs.concord.server.sdk.ProcessKey) PartialProcessKey(com.walmartlabs.concord.server.sdk.PartialProcessKey) WithTimer(com.walmartlabs.concord.server.sdk.metrics.WithTimer) ApiOperation(io.swagger.annotations.ApiOperation)

Example 3 with ProcessEntry

use of com.walmartlabs.concord.server.process.ProcessEntry in project concord by walmartlabs.

the class ForkRepositoryInfoProcessor method process.

@Override
@WithTimer
public Payload process(Chain chain, Payload payload) {
    UUID parentInstanceId = payload.getHeader(Payload.PARENT_INSTANCE_ID);
    ProcessEntry parent = queueManager.get(PartialProcessKey.from(parentInstanceId));
    if (parent == null) {
        throw new ProcessException(payload.getProcessKey(), "Parent process '" + parentInstanceId + "' not found");
    }
    RepositoryProcessor.CommitInfo ci = new RepositoryProcessor.CommitInfo(parent.commitId(), parent.commitBranch(), null, parent.commitMsg());
    RepositoryProcessor.RepositoryInfo i = new RepositoryProcessor.RepositoryInfo(parent.repoId(), parent.repoName(), parent.repoUrl(), parent.repoPath(), parent.commitBranch(), parent.commitId(), ci);
    payload = payload.putHeader(REPOSITORY_INFO_KEY, i);
    return chain.process(payload);
}
Also used : ProcessException(com.walmartlabs.concord.server.process.ProcessException) ProcessEntry(com.walmartlabs.concord.server.process.ProcessEntry) UUID(java.util.UUID) WithTimer(com.walmartlabs.concord.server.sdk.metrics.WithTimer)

Example 4 with ProcessEntry

use of com.walmartlabs.concord.server.process.ProcessEntry in project concord by walmartlabs.

the class ProcessCheckpointResource method restore.

@POST
@ApiOperation(value = "Restore process from checkpoint")
@javax.ws.rs.Path("{id}/checkpoint/restore")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@WithTimer
@Validate
public ResumeProcessResponse restore(@ApiParam @PathParam("id") UUID instanceId, @ApiParam @Valid RestoreCheckpointRequest request) {
    UUID checkpointId = request.getId();
    // TODO replace with ProcessKeyCache
    ProcessEntry entry = processManager.assertProcess(instanceId);
    ProcessKey processKey = new ProcessKey(entry.instanceId(), entry.createdAt());
    processManager.restoreFromCheckpoint(processKey, checkpointId);
    return new ResumeProcessResponse();
}
Also used : ProcessEntry(com.walmartlabs.concord.server.process.ProcessEntry) ProcessKey(com.walmartlabs.concord.server.sdk.ProcessKey) UUID(java.util.UUID) ResumeProcessResponse(com.walmartlabs.concord.server.process.ResumeProcessResponse) Validate(org.sonatype.siesta.Validate) WithTimer(com.walmartlabs.concord.server.sdk.metrics.WithTimer) ApiOperation(io.swagger.annotations.ApiOperation)

Example 5 with ProcessEntry

use of com.walmartlabs.concord.server.process.ProcessEntry 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);
}
Also used : InputStream(java.io.InputStream) ConcordApplicationException(com.walmartlabs.concord.server.sdk.ConcordApplicationException) ProcessEntry(com.walmartlabs.concord.server.process.ProcessEntry) ProcessKey(com.walmartlabs.concord.server.sdk.ProcessKey) IOException(java.io.IOException) UUID(java.util.UUID) TemporaryPath(com.walmartlabs.concord.common.TemporaryPath) ValidationErrorsException(org.sonatype.siesta.ValidationErrorsException)

Aggregations

ProcessEntry (com.walmartlabs.concord.server.process.ProcessEntry)11 WithTimer (com.walmartlabs.concord.server.sdk.metrics.WithTimer)7 ProcessKey (com.walmartlabs.concord.server.sdk.ProcessKey)6 ApiOperation (io.swagger.annotations.ApiOperation)5 UUID (java.util.UUID)4 ConcordApplicationException (com.walmartlabs.concord.server.sdk.ConcordApplicationException)3 UserPrincipal (com.walmartlabs.concord.server.security.UserPrincipal)3 PartialProcessKey (com.walmartlabs.concord.server.sdk.PartialProcessKey)2 SessionKeyPrincipal (com.walmartlabs.concord.server.security.sessionkey.SessionKeyPrincipal)2 UnauthorizedException (org.apache.shiro.authz.UnauthorizedException)2 TemporaryPath (com.walmartlabs.concord.common.TemporaryPath)1 ProcessException (com.walmartlabs.concord.server.process.ProcessException)1 ResumeProcessResponse (com.walmartlabs.concord.server.process.ResumeProcessResponse)1 ProcessFilter (com.walmartlabs.concord.server.process.queue.ProcessFilter)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 OffsetDateTime (java.time.OffsetDateTime)1 Validate (org.sonatype.siesta.Validate)1 ValidationErrorsException (org.sonatype.siesta.ValidationErrorsException)1