Search in sources :

Example 16 with PartialProcessKey

use of com.walmartlabs.concord.server.sdk.PartialProcessKey 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 17 with PartialProcessKey

use of com.walmartlabs.concord.server.sdk.PartialProcessKey in project concord by walmartlabs.

the class ProcessExceptionMapper method convert.

@Override
protected Response convert(ProcessException e, String id) {
    String details = getDetails(e.getCause());
    String stacktrace = null;
    if (traceEnabled()) {
        StringWriter w = new StringWriter();
        e.printStackTrace(new PrintWriter(w));
        stacktrace = w.toString();
    }
    PartialProcessKey processKey = e.getProcessKey();
    UUID instanceId = processKey.getInstanceId();
    ErrorMessage msg = new ErrorMessage(instanceId, e.getMessage(), details, stacktrace);
    return Response.status(e.getStatus()).entity(msg).type(MediaType.APPLICATION_JSON_TYPE).build();
}
Also used : PartialProcessKey(com.walmartlabs.concord.server.sdk.PartialProcessKey) StringWriter(java.io.StringWriter) UUID(java.util.UUID) PrintWriter(java.io.PrintWriter)

Example 18 with PartialProcessKey

use of com.walmartlabs.concord.server.sdk.PartialProcessKey in project concord by walmartlabs.

the class ProcessKvResource method assertProjectId.

private UUID assertProjectId(UUID instanceId) {
    PartialProcessKey processKey = PartialProcessKey.from(instanceId);
    // TODO replace with getProjectId
    ProcessEntry entry = processQueueManager.get(processKey);
    if (entry == null) {
        throw new ConcordApplicationException("Process instance not found", Response.Status.NOT_FOUND);
    }
    UUID projectId = entry.projectId();
    if (projectId == null) {
        log.warn("assertProjectId ['{}'] -> no project found, using the default value", processKey);
        projectId = DEFAULT_PROJECT_ID;
    }
    return projectId;
}
Also used : PartialProcessKey(com.walmartlabs.concord.server.sdk.PartialProcessKey) ConcordApplicationException(com.walmartlabs.concord.server.sdk.ConcordApplicationException) UUID(java.util.UUID)

Example 19 with PartialProcessKey

use of com.walmartlabs.concord.server.sdk.PartialProcessKey in project concord by walmartlabs.

the class TriggerScheduler method startProcess.

private void startProcess(TriggerSchedulerEntry t) {
    if (isDisabled(EVENT_SOURCE)) {
        log.warn("startProcess ['{}'] -> disabled, skipping", t);
        return;
    }
    if (isRepositoryDisabled(t)) {
        log.warn("startProcess ['{}'] -> repository is disabled, skipping", t);
        return;
    }
    log.info("run -> starting {}...", t);
    Map<String, Object> args = new HashMap<>();
    if (t.getArguments() != null) {
        args.putAll(t.getArguments());
    }
    args.put("event", makeEvent(t));
    Map<String, Object> cfg = t.getCfg();
    cfg.put(Constants.Request.ARGUMENTS_KEY, args);
    PartialProcessKey processKey = PartialProcessKey.create();
    UUID triggerId = t.getTriggerId();
    UUID orgId = t.getOrgId();
    UUID projectId = t.getProjectId();
    UUID repoId = t.getRepositoryId();
    String entryPoint = t.getEntryPoint();
    Collection<String> activeProfiles = t.getActiveProfiles();
    Initiator initiator;
    try {
        initiator = getInitiator(t);
    } catch (Exception e) {
        log.error("startProcess ['{}', '{}', '{}', '{}', '{}', {}] -> error getting initiator: {}", triggerId, orgId, projectId, repoId, entryPoint, activeProfiles, e.getMessage());
        logFailedToStart(t, e);
        return;
    }
    Payload payload;
    try {
        payload = PayloadBuilder.start(processKey).initiator(initiator.id(), initiator.name()).organization(orgId).project(projectId).repository(repoId).entryPoint(entryPoint).activeProfiles(activeProfiles).triggeredBy(TriggeredByEntry.builder().trigger(t).build()).configuration(cfg).build();
    } catch (Exception e) {
        log.error("startProcess ['{}', '{}', '{}', '{}', '{}', {}] -> error creating a payload", triggerId, orgId, projectId, repoId, entryPoint, activeProfiles, e);
        logFailedToStart(t, e);
        return;
    }
    try {
        processSecurityContext.runAs(initiator.id(), () -> processManager.start(payload));
    } catch (Exception e) {
        log.error("startProcess ['{}', '{}', '{}', '{}', '{}'] -> error starting process", triggerId, orgId, projectId, repoId, entryPoint, e);
        logFailedToStart(t, e);
        return;
    }
    log.info("startProcess ['{}', '{}', '{}', '{}', '{}'] -> process '{}' started", triggerId, orgId, projectId, repoId, entryPoint, processKey);
}
Also used : PartialProcessKey(com.walmartlabs.concord.server.sdk.PartialProcessKey) AuditObject(com.walmartlabs.concord.server.audit.AuditObject)

Example 20 with PartialProcessKey

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

Aggregations

PartialProcessKey (com.walmartlabs.concord.server.sdk.PartialProcessKey)27 ConcordApplicationException (com.walmartlabs.concord.server.sdk.ConcordApplicationException)18 WithTimer (com.walmartlabs.concord.server.sdk.metrics.WithTimer)14 ApiOperation (io.swagger.annotations.ApiOperation)14 UserPrincipal (com.walmartlabs.concord.server.security.UserPrincipal)8 EntryPoint (com.walmartlabs.concord.server.process.PayloadManager.EntryPoint)4 ProcessKey (com.walmartlabs.concord.server.sdk.ProcessKey)4 UUID (java.util.UUID)3 ValidationErrorsException (org.sonatype.siesta.ValidationErrorsException)3 Imports (com.walmartlabs.concord.imports.Imports)2 ProcessStatus (com.walmartlabs.concord.server.sdk.ProcessStatus)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 SettableFuture (com.google.common.util.concurrent.SettableFuture)1 ConfigurationUtils (com.walmartlabs.concord.common.ConfigurationUtils)1 IOUtils (com.walmartlabs.concord.common.IOUtils)1 Form (com.walmartlabs.concord.forms.Form)1 FormField (com.walmartlabs.concord.forms.FormField)1 FormUtils (com.walmartlabs.concord.forms.FormUtils)1 AttachmentsRule (com.walmartlabs.concord.policyengine.AttachmentsRule)1 CheckResult (com.walmartlabs.concord.policyengine.CheckResult)1