Search in sources :

Example 26 with WithTimer

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

the class ProcessEventResource method batchEvent.

/**
 * Register multiple events for the specified process.
 */
@POST
@ApiOperation(value = "Register multiple events for the specified process", authorizations = { @Authorization("session_key"), @Authorization("api_key") })
@Path("/{processInstanceId}/eventBatch")
@Consumes(MediaType.APPLICATION_JSON)
@WithTimer
public void batchEvent(@ApiParam @PathParam("processInstanceId") UUID processInstanceId, @ApiParam List<ProcessEventRequest> data) {
    ProcessKey processKey = assertProcessKey(processInstanceId);
    List<NewProcessEvent> events = data.stream().map(req -> NewProcessEvent.builder().processKey(processKey).eventType(req.getEventType()).eventDate(req.getEventDate()).data(req.getData()).build()).collect(Collectors.toList());
    eventManager.event(events);
}
Also used : Resource(org.sonatype.siesta.Resource) java.util(java.util) ApiParam(io.swagger.annotations.ApiParam) ProcessKey(com.walmartlabs.concord.server.sdk.ProcessKey) ProcessKeyCache(com.walmartlabs.concord.server.process.queue.ProcessKeyCache) Singleton(javax.inject.Singleton) Inject(javax.inject.Inject) ApiOperation(io.swagger.annotations.ApiOperation) ProcessQueueDao(com.walmartlabs.concord.server.process.queue.ProcessQueueDao) MediaType(javax.ws.rs.core.MediaType) WithTimer(com.walmartlabs.concord.server.sdk.metrics.WithTimer) Utils.unwrap(com.walmartlabs.concord.server.Utils.unwrap) OffsetDateTimeParam(com.walmartlabs.concord.server.OffsetDateTimeParam) Api(io.swagger.annotations.Api) Named(javax.inject.Named) PartialProcessKey(com.walmartlabs.concord.server.sdk.PartialProcessKey) Roles(com.walmartlabs.concord.server.security.Roles) UserPrincipal(com.walmartlabs.concord.server.security.UserPrincipal) ProjectAccessManager(com.walmartlabs.concord.server.org.project.ProjectAccessManager) Collectors(java.util.stream.Collectors) UnauthorizedException(org.apache.shiro.authz.UnauthorizedException) javax.ws.rs(javax.ws.rs) Response(javax.ws.rs.core.Response) ConcordApplicationException(com.walmartlabs.concord.server.sdk.ConcordApplicationException) ResourceAccessLevel(com.walmartlabs.concord.server.org.ResourceAccessLevel) ProjectIdAndInitiator(com.walmartlabs.concord.server.process.queue.ProcessQueueDao.ProjectIdAndInitiator) Authorization(io.swagger.annotations.Authorization) 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 27 with WithTimer

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

the class ProcessResource method start.

/**
 * Starts a new process instance.
 *
 * @param input
 * @param parentInstanceId
 * @param sync
 * @return
 */
@POST
@ApiOperation("Start a new process using multipart request data")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.APPLICATION_JSON)
@WithTimer
public StartProcessResponse start(@ApiParam MultipartInput input, @ApiParam @Deprecated @QueryParam("parentId") UUID parentInstanceId, @ApiParam @Deprecated @DefaultValue("false") @QueryParam("sync") boolean sync, @ApiParam @Deprecated @QueryParam("out") String[] out, @Context HttpServletRequest request) {
    boolean sync2 = MultipartUtils.getBoolean(input, Constants.Multipart.SYNC, false);
    if (sync || sync2) {
        throw syncIsForbidden();
    }
    Payload payload;
    try {
        payload = payloadManager.createPayload(input, request);
        // TODO remove after deprecating the old endpoints
        payload = PayloadBuilder.basedOn(payload).parentInstanceId(parentInstanceId).mergeOutExpressions(out).build();
    } catch (IOException e) {
        log.error("start -> error creating a payload: {}", e.getMessage());
        throw new ConcordApplicationException("Error creating a payload", e);
    }
    return toResponse(processManager.start(payload));
}
Also used : ConcordApplicationException(com.walmartlabs.concord.server.sdk.ConcordApplicationException) WithTimer(com.walmartlabs.concord.server.sdk.metrics.WithTimer) ApiOperation(io.swagger.annotations.ApiOperation)

Example 28 with WithTimer

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

the class ProcessResource method appendLog.

/**
 * Appends a process' log.
 *
 * @param instanceId
 * @param data
 * @see ProcessLogResourceV2
 * @deprecated in favor of the /api/v2/process/{id}/log* endpoints
 */
@POST
@javax.ws.rs.Path("{id}/log")
@Consumes(MediaType.APPLICATION_OCTET_STREAM)
@WithTimer
@Deprecated
public void appendLog(@PathParam("id") UUID instanceId, InputStream data) {
    ProcessKey processKey = assertProcessKey(instanceId);
    try {
        byte[] ab = IOUtils.toByteArray(data);
        int upper = logManager.log(processKey, ab);
        // whenever we accept logs from an external source (e.g. from an Agent) we need to check
        // the log size limits
        int logSizeLimit = processCfg.getLogSizeLimit();
        if (upper >= logSizeLimit) {
            logManager.error(processKey, "Maximum log size reached: {}. Process cancelled.", logSizeLimit);
            processManager.kill(processKey);
        }
    } catch (IOException e) {
        throw new ConcordApplicationException("Error while appending a log: " + e.getMessage());
    }
}
Also used : ConcordApplicationException(com.walmartlabs.concord.server.sdk.ConcordApplicationException) PartialProcessKey(com.walmartlabs.concord.server.sdk.PartialProcessKey) ProcessKey(com.walmartlabs.concord.server.sdk.ProcessKey) EntryPoint(com.walmartlabs.concord.server.process.PayloadManager.EntryPoint) WithTimer(com.walmartlabs.concord.server.sdk.metrics.WithTimer)

Example 29 with WithTimer

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

the class ProcessResource method start.

/**
 * Starts a new process instance using the specified entry point and provided configuration.
 *
 * @param entryPoint
 * @param req
 * @param parentInstanceId
 * @param sync
 * @return
 * @deprecated use {@link #start(MultipartInput, UUID, boolean, String[], HttpServletRequest)}
 */
@POST
@ApiOperation(value = "Start a new process using the specified entry point and provided configuration", hidden = true)
@javax.ws.rs.Path("/{entryPoint}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@WithTimer(suffix = "_json")
@Deprecated
public StartProcessResponse start(@PathParam("entryPoint") String entryPoint, Map<String, Object> req, @QueryParam("parentId") UUID parentInstanceId, @Deprecated @DefaultValue("false") @QueryParam("sync") boolean sync, @QueryParam("out") String[] out) {
    if (sync) {
        throw syncIsForbidden();
    }
    assertPartialKey(parentInstanceId);
    PartialProcessKey processKey = PartialProcessKey.from(UUID.randomUUID());
    UUID orgId = OrganizationManager.DEFAULT_ORG_ID;
    EntryPoint ep = payloadManager.parseEntryPoint(processKey, orgId, entryPoint);
    UserPrincipal userPrincipal = UserPrincipal.assertCurrent();
    Payload payload;
    try {
        payload = payloadManager.createPayload(processKey, parentInstanceId, userPrincipal.getId(), userPrincipal.getUsername(), ep, req, out);
    } catch (IOException e) {
        log.error("start ['{}'] -> error creating a payload: {}", entryPoint, e);
        throw new ConcordApplicationException("Error creating a payload", e);
    }
    return toResponse(processManager.start(payload));
}
Also used : PartialProcessKey(com.walmartlabs.concord.server.sdk.PartialProcessKey) ConcordApplicationException(com.walmartlabs.concord.server.sdk.ConcordApplicationException) EntryPoint(com.walmartlabs.concord.server.process.PayloadManager.EntryPoint) UserPrincipal(com.walmartlabs.concord.server.security.UserPrincipal) WithTimer(com.walmartlabs.concord.server.sdk.metrics.WithTimer) ApiOperation(io.swagger.annotations.ApiOperation)

Example 30 with WithTimer

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

the class ProcessResource method disable.

/**
 * Disable a process.
 *
 * @param instanceId
 * @param disabled
 */
@POST
@ApiOperation("Disable a process")
@javax.ws.rs.Path("/{id}/disable/{disabled}")
@WithTimer
public void disable(@ApiParam @PathParam("id") UUID instanceId, @ApiParam @PathParam("disabled") boolean disabled) {
    ProcessKey processKey = assertProcessKey(instanceId);
    processManager.disable(processKey, disabled);
}
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)

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