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);
}
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);
}
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);
}
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);
}
Aggregations