Search in sources :

Example 66 with ProcessKey

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

the class ForkPolicyProcessor method process.

@Override
public Payload process(Chain chain, Payload payload) {
    ProcessKey processKey = payload.getProcessKey();
    UUID parentInstanceId = payload.getHeader(Payload.PARENT_INSTANCE_ID);
    PolicyEngine policy = payload.getHeader(Payload.POLICY);
    if (policy == null) {
        return chain.process(payload);
    }
    logManager.info(processKey, "Applying fork policies...");
    CheckResult<ForkDepthRule, Integer> result;
    try {
        result = policy.getForkDepthPolicy().check(() -> forkDepthDao.getDepth(parentInstanceId));
    } catch (Exception e) {
        log.error("process -> error", e);
        throw new ProcessException(processKey, "Found fork policy check error", e);
    }
    if (!result.getDeny().isEmpty()) {
        logManager.error(processKey, buildErrorMessage(result.getDeny()));
        throw new ProcessException(processKey, "Found fork policy violations");
    }
    return chain.process(payload);
}
Also used : ProcessException(com.walmartlabs.concord.server.process.ProcessException) ForkDepthRule(com.walmartlabs.concord.policyengine.ForkDepthRule) PolicyEngine(com.walmartlabs.concord.policyengine.PolicyEngine) ProcessKey(com.walmartlabs.concord.server.sdk.ProcessKey) UUID(java.util.UUID) ProcessException(com.walmartlabs.concord.server.process.ProcessException)

Example 67 with ProcessKey

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

the class StateImportingProcessor method process.

@Override
@WithTimer
public Payload process(Chain chain, Payload payload) {
    ProcessKey processKey = payload.getProcessKey();
    Path workspace = payload.getHeader(Payload.WORKSPACE_DIR);
    List<Snapshot> snapshots = payload.getHeader(Payload.REPOSITORY_SNAPSHOT);
    stateManager.replacePath(processKey, workspace, (p, attrs) -> filter(p, attrs, snapshots, workspace));
    return chain.process(payload);
}
Also used : Path(java.nio.file.Path) Snapshot(com.walmartlabs.concord.repository.Snapshot) ProcessKey(com.walmartlabs.concord.server.sdk.ProcessKey) WithTimer(com.walmartlabs.concord.server.sdk.metrics.WithTimer)

Example 68 with ProcessKey

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

the class ProcessLogAccessManager method assertLogAccess.

public ProcessKey assertLogAccess(UUID instanceId) {
    ProcessEntry pe = processManager.assertProcess(instanceId);
    ProcessKey pk = new ProcessKey(pe.instanceId(), pe.createdAt());
    if (!processCfg.isCheckLogPermissions()) {
        return pk;
    }
    if (Roles.isAdmin() || Roles.isGlobalReader()) {
        return pk;
    }
    UserPrincipal principal = UserPrincipal.assertCurrent();
    UUID initiatorId = pe.initiatorId();
    if (principal.getId().equals(initiatorId)) {
        // process owners should be able to view the process' logs
        return pk;
    }
    SessionKeyPrincipal s = SessionKeyPrincipal.getCurrent();
    if (s != null && pk.partOf(s.getProcessKey())) {
        // processes can access their own logs
        return pk;
    }
    if (pe.projectId() != null) {
        projectAccessManager.assertAccess(pe.projectId(), ResourceAccessLevel.WRITER, true);
        return pk;
    }
    throw new UnauthorizedException("The current user (" + principal.getUsername() + ") doesn't have " + "the necessary permissions to view the process log: " + instanceId);
}
Also used : SessionKeyPrincipal(com.walmartlabs.concord.server.security.sessionkey.SessionKeyPrincipal) UnauthorizedException(org.apache.shiro.authz.UnauthorizedException) ProcessEntry(com.walmartlabs.concord.server.process.ProcessEntry) ProcessKey(com.walmartlabs.concord.server.sdk.ProcessKey) UUID(java.util.UUID) UserPrincipal(com.walmartlabs.concord.server.security.UserPrincipal)

Example 69 with ProcessKey

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

the class HostsDao method list.

public List<HostEntry> list(HostFilter filter, Set<HostsDataInclude> includes, int limit, int offset) {
    NodeRosterHosts nrh = NODE_ROSTER_HOSTS.as("nrh");
    NodeRosterProcessHosts nrph = NODE_ROSTER_PROCESS_HOSTS.as("nrph");
    NodeRosterHostArtifacts nrha = NODE_ROSTER_HOST_ARTIFACTS.as("nrha");
    SelectQuery<Record> query = dsl().selectQuery();
    query.addSelect(nrh.HOST_ID, nrh.NORMALIZED_HOSTNAME, nrh.CREATED_AT);
    query.addFrom(nrh);
    if (filter.host() != null) {
        query.addConditions(nrh.NORMALIZED_HOSTNAME.containsIgnoreCase(filter.host()));
    }
    ProcessKey key = null;
    if (filter.processInstanceId() != null) {
        key = processKeyCache.get(filter.processInstanceId());
        if (key == null) {
            return Collections.emptyList();
        }
        query.addFrom(nrph);
        query.addConditions(nrh.HOST_ID.eq(nrph.HOST_ID).and(nrph.INSTANCE_ID.eq(key.getInstanceId()).and(nrph.INSTANCE_CREATED_AT.eq(key.getCreatedAt()))));
    }
    if ((includes != null && includes.contains(HostsDataInclude.ARTIFACTS)) || filter.artifact() != null) {
        query.addSelect(nrha.ARTIFACT_URL);
        query.addFrom(nrha);
        query.addConditions(nrh.HOST_ID.eq(nrha.HOST_ID));
    }
    if (filter.artifact() != null) {
        query.addConditions(nrha.ARTIFACT_URL.likeRegex(filter.artifact()));
        if (key != null) {
            query.addConditions(nrha.INSTANCE_ID.eq(key.getInstanceId()).and(nrha.INSTANCE_CREATED_AT.eq(key.getCreatedAt())));
        }
    }
    query.addOrderBy(nrh.CREATED_AT.desc());
    query.addLimit(limit);
    query.addOffset(offset);
    return query.fetch(HostsDao::toHostEntry);
}
Also used : Record(org.jooq.Record) NodeRosterHostArtifacts(com.walmartlabs.concord.server.plugins.noderoster.jooq.tables.NodeRosterHostArtifacts) ProcessKey(com.walmartlabs.concord.server.sdk.ProcessKey) NodeRosterProcessHosts(com.walmartlabs.concord.server.plugins.noderoster.jooq.tables.NodeRosterProcessHosts) NodeRosterHosts(com.walmartlabs.concord.server.plugins.noderoster.jooq.tables.NodeRosterHosts)

Aggregations

ProcessKey (com.walmartlabs.concord.server.sdk.ProcessKey)69 WithTimer (com.walmartlabs.concord.server.sdk.metrics.WithTimer)28 Path (java.nio.file.Path)27 PartialProcessKey (com.walmartlabs.concord.server.sdk.PartialProcessKey)25 ApiOperation (io.swagger.annotations.ApiOperation)22 ProcessException (com.walmartlabs.concord.server.process.ProcessException)20 ConcordApplicationException (com.walmartlabs.concord.server.sdk.ConcordApplicationException)16 IOException (java.io.IOException)16 UUID (java.util.UUID)9 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)8 PolicyEngine (com.walmartlabs.concord.policyengine.PolicyEngine)8 Inject (javax.inject.Inject)8 Named (javax.inject.Named)8 ProcessKeyCache (com.walmartlabs.concord.server.process.queue.ProcessKeyCache)7 ProcessQueueDao (com.walmartlabs.concord.server.process.queue.ProcessQueueDao)7 ProcessStateManager (com.walmartlabs.concord.server.process.state.ProcessStateManager)7 UserPrincipal (com.walmartlabs.concord.server.security.UserPrincipal)7 ProcessLogManager (com.walmartlabs.concord.server.process.logs.ProcessLogManager)6 HttpUtils (com.walmartlabs.concord.server.HttpUtils)5 ResourceAccessLevel (com.walmartlabs.concord.server.org.ResourceAccessLevel)5