Search in sources :

Example 31 with WithTimer

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

the class RoleResource method get.

@GET
@ApiOperation("Get a role's details")
@Path("/{roleName}")
@Produces(MediaType.APPLICATION_JSON)
@WithTimer
public RoleEntry get(@ApiParam @PathParam("roleName") String roleName) {
    assertAdmin();
    UUID id = roleDao.getId(roleName);
    if (id == null) {
        throw new ConcordApplicationException("Role not found: " + roleName, Status.NOT_FOUND);
    }
    return roleDao.get(id);
}
Also used : ConcordApplicationException(com.walmartlabs.concord.server.sdk.ConcordApplicationException) UUID(java.util.UUID) WithTimer(com.walmartlabs.concord.server.sdk.metrics.WithTimer) ApiOperation(io.swagger.annotations.ApiOperation)

Example 32 with WithTimer

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

the class ProcessStateManager method importPath.

@WithTimer
public void importPath(DSLContext tx, ProcessKey processKey, String path, Path src, BiFunction<Path, BasicFileAttributes, Boolean> filter) {
    PolicyEngine policyEngine = assertPolicy(tx, processKey, src, filter);
    String prefix = fixPath(path);
    List<BatchItem> batch = new ArrayList<>();
    try {
        Files.walkFileTree(src, new SimpleFileVisitor<Path>() {

            @Override
            public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
                if (!filter.apply(file, attrs)) {
                    return FileVisitResult.CONTINUE;
                }
                Path p = src.relativize(file);
                // the caller shouldn't attempt to import anything but regular files
                if (!Files.isRegularFile(file, LinkOption.NOFOLLOW_LINKS)) {
                    throw new IllegalStateException("Can't import non-regular files into the process state: " + p + " This is most likely a bug.");
                }
                String n = p.toString();
                if (prefix != null) {
                    n = prefix + n;
                }
                Set<PosixFilePermission> permissions = Files.getPosixFilePermissions(file);
                int unixMode = Posix.unixMode(permissions);
                boolean needsEncryption = secureFiles.contains(n);
                tx.deleteFrom(PROCESS_STATE).where(PROCESS_STATE.INSTANCE_ID.eq(processKey.getInstanceId()).and(PROCESS_STATE.INSTANCE_CREATED_AT.eq(processKey.getCreatedAt())).and(PROCESS_STATE.ITEM_PATH.eq(n))).execute();
                batch.add(new BatchItem(n, file, unixMode, needsEncryption));
                if (batch.size() >= INSERT_BATCH_SIZE) {
                    insert(tx, processKey.getInstanceId(), processKey.getCreatedAt(), batch);
                    batch.clear();
                }
                return FileVisitResult.CONTINUE;
            }
        });
        if (!batch.isEmpty()) {
            insert(tx, processKey.getInstanceId(), processKey.getCreatedAt(), batch);
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    assertPolicy(tx, processKey, policyEngine);
}
Also used : ResultSet(java.sql.ResultSet) PolicyEngine(com.walmartlabs.concord.policyengine.PolicyEngine) IOException(java.io.IOException) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes) WithTimer(com.walmartlabs.concord.server.sdk.metrics.WithTimer)

Example 33 with WithTimer

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

the class ProcessWaitWatchdog method resumeProcess.

@WithTimer
void resumeProcess(ProcessKey key, Set<String> events) {
    Payload payload;
    try {
        payload = payloadManager.createResumePayload(key, events, null);
    } catch (IOException e) {
        throw new RuntimeException("Error creating a payload", e);
    }
    processManager.resume(payload);
    log.info("resumeProcess ['{}', '{}'] -> done", key, events);
}
Also used : Payload(com.walmartlabs.concord.server.process.Payload) IOException(java.io.IOException) WithTimer(com.walmartlabs.concord.server.sdk.metrics.WithTimer)

Example 34 with WithTimer

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

the class ApiKeyRealm method doGetAuthenticationInfo.

@Override
@WithTimer
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
    ApiKey t = (ApiKey) token;
    UserEntry u = userManager.get(t.getUserId()).orElse(null);
    if (u == null) {
        return null;
    }
    if (u.isDisabled()) {
        throw new AuthenticationException("User account '" + u.getName() + "' is disabled");
    }
    auditLog.add(AuditObject.SYSTEM, AuditAction.ACCESS).userId(u.getId()).field("realm", REALM_NAME).field("apiKeyId", t.getKeyId()).log();
    UserPrincipal p = new UserPrincipal(REALM_NAME, u);
    return new SimpleAccount(Arrays.asList(p, t), t.getKey(), getName());
}
Also used : SimpleAccount(org.apache.shiro.authc.SimpleAccount) AuthenticationException(org.apache.shiro.authc.AuthenticationException) UserEntry(com.walmartlabs.concord.server.user.UserEntry) UserPrincipal(com.walmartlabs.concord.server.security.UserPrincipal) WithTimer(com.walmartlabs.concord.server.sdk.metrics.WithTimer)

Example 35 with WithTimer

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

the class ProcessLogResourceV2 method updateSegment.

/**
 * Update a process log segment.
 */
@POST
@ApiOperation(value = "Update process log segment")
@Path("{id}/log/segment/{segmentId}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@WithTimer
public LogSegmentOperationResponse updateSegment(@ApiParam @PathParam("id") UUID instanceId, @ApiParam @PathParam("segmentId") long segmentId, @ApiParam LogSegmentUpdateRequest request) {
    ProcessKey processKey = logAccessManager.assertLogAccess(instanceId);
    logManager.updateSegment(processKey, segmentId, request.status(), request.warnings(), request.errors());
    return new LogSegmentOperationResponse(segmentId, OperationResult.UPDATED);
}
Also used : 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