Search in sources :

Example 6 with WithTimer

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

the class EnqueueingProcessor method process.

@Override
@WithTimer
public Payload process(Chain chain, Payload payload) {
    boolean enqueued = queueManager.enqueue(payload);
    if (!enqueued) {
        // (e.g. "exclusive" processes can be rejected before reaching the ENQUEUED status)
        return payload;
    }
    ProcessKey processKey = payload.getProcessKey();
    Map<String, Object> requirements = PayloadUtils.getRequirements(payload);
    OffsetDateTime startAt = PayloadUtils.getStartAt(payload);
    if (startAt == null) {
        logManager.info(processKey, "Enqueued. Waiting for an agent (requirements={})...", requirements);
    } else {
        logManager.info(processKey, "Enqueued. Starting at {} (requirements={})...", startAt, requirements);
    }
    return chain.process(payload);
}
Also used : OffsetDateTime(java.time.OffsetDateTime) ProcessKey(com.walmartlabs.concord.server.sdk.ProcessKey) WithTimer(com.walmartlabs.concord.server.sdk.metrics.WithTimer)

Example 7 with WithTimer

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

the class ExclusiveGroupProcessor method process.

@Override
@WithTimer
public Payload process(Chain chain, Payload payload) {
    ExclusiveMode exclusive = PayloadUtils.getExclusive(payload);
    if (exclusive == null) {
        return chain.process(payload);
    }
    UUID projectId = payload.getHeader(Payload.PROJECT_ID);
    if (projectId == null) {
        return chain.process(payload);
    }
    ModeProcessor processor = processors.get(exclusive.mode());
    if (processor == null) {
        return chain.process(payload);
    }
    logManager.info(payload.getProcessKey(), "Process' exclusive group: {}", exclusive.group());
    boolean canContinue = processor.process(payload, exclusive);
    if (canContinue) {
        return chain.process(payload);
    }
    return payload;
}
Also used : UUID(java.util.UUID) ExclusiveMode(com.walmartlabs.concord.runtime.v2.model.ExclusiveMode) WithTimer(com.walmartlabs.concord.server.sdk.metrics.WithTimer)

Example 8 with WithTimer

use of com.walmartlabs.concord.server.sdk.metrics.WithTimer 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 9 with WithTimer

use of com.walmartlabs.concord.server.sdk.metrics.WithTimer 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 10 with WithTimer

use of com.walmartlabs.concord.server.sdk.metrics.WithTimer 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)

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