use of com.walmartlabs.concord.process.loader.model.ProcessDefinition in project concord by walmartlabs.
the class ProcessDefinitionRefreshListener method onRefresh.
@Override
public void onRefresh(DSLContext ctx, RepositoryEntry repo, Path repoPath) throws Exception {
ProcessDefinition pd = projectLoader.loadProject(repoPath, importsNormalizer.forProject(repo.getProjectId()), ImportsListener.NOP_LISTENER).projectDefinition();
Set<String> pf = pd.publicFlows();
if (pf == null || pf.isEmpty()) {
// all flows are public when no public flows defined
pf = new HashSet<>(pd.flows().keySet());
}
Set<String> entryPoints = pd.flows().keySet().stream().filter(pf::contains).collect(Collectors.toSet());
List<String> profiles = new ArrayList<>(pd.profiles().keySet());
Map<String, Object> meta = new HashMap<>();
meta.put("entryPoints", emptyToNull(entryPoints));
meta.put("profiles", emptyToNull(profiles));
repositoryDao.updateMeta(ctx, repo.getId(), meta);
log.info("onRefresh ['{}', '{}'] -> done ({})", repo.getId(), repoPath, entryPoints);
}
use of com.walmartlabs.concord.process.loader.model.ProcessDefinition in project concord by walmartlabs.
the class TriggerRefreshListener method onRefresh.
@Override
public void onRefresh(DSLContext ctx, RepositoryEntry repo, Path repoPath) throws Exception {
if (repo.isTriggersDisabled()) {
triggerManager.clearTriggers(repo.getProjectId(), repo.getId());
return;
}
log.info("refresh ['{}'] -> triggers", repo.getId());
ProjectLoader.Result result = projectLoader.loadProject(repoPath, importsNormalizer.forProject(repo.getProjectId()), ImportsListener.NOP_LISTENER);
ProcessDefinition pd = result.projectDefinition();
ProjectValidator.Result validationResult = ProjectValidator.validate(pd);
if (!validationResult.isValid()) {
throw new ValidationErrorsException(String.join("\n", validationResult.getErrors()));
}
triggerManager.refresh(repo.getProjectId(), repo.getId(), pd);
}
use of com.walmartlabs.concord.process.loader.model.ProcessDefinition in project concord by walmartlabs.
the class Lint method call.
@Override
public Integer call() throws Exception {
if (!Files.isDirectory(targetDir)) {
throw new IllegalArgumentException("Not a directory: " + targetDir);
}
ProjectLoader loader = new ProjectLoader(new NoopImportManager());
ProcessDefinition pd = loader.loadProject(targetDir, new DummyImportsNormalizer(), verbose ? new CliImportsListener() : null).projectDefinition();
List<LintResult> lintResults = new ArrayList<>();
linters().forEach(l -> lintResults.addAll(l.apply(pd)));
if (!lintResults.isEmpty()) {
print(lintResults);
println();
}
println("Found:");
println(" imports: " + pd.imports().items().size());
println(" profiles: " + pd.profiles().size());
println(" flows: " + pd.flows().size());
println(" forms: " + pd.forms().size());
println(" triggers: " + pd.triggers().size());
println(" (not counting dynamically imported resources)");
println();
printStats(lintResults);
println();
boolean hasErrors = hasErrors(lintResults);
if (hasErrors) {
println("@|red,bold INVALID|@");
} else {
println("@|green,bold VALID|@");
}
return hasErrors ? 10 : 0;
}
use of com.walmartlabs.concord.process.loader.model.ProcessDefinition in project concord by walmartlabs.
the class ProjectLoader method toResult.
private static Result toResult(com.walmartlabs.concord.runtime.v2.ProjectLoaderV2.Result r) {
List<Snapshot> snapshots = r.getSnapshots();
ProcessDefinition pd = new ProcessDefinitionV2(r.getProjectDefinition());
return new Result() {
@Override
public List<Snapshot> snapshots() {
return snapshots;
}
@Override
public ProcessDefinition projectDefinition() {
return pd;
}
};
}
use of com.walmartlabs.concord.process.loader.model.ProcessDefinition in project concord by walmartlabs.
the class ProcessDefinitionProcessor method process.
@Override
public Payload process(Chain chain, Payload payload) {
ProcessKey processKey = payload.getProcessKey();
Path workDir = payload.getHeader(Payload.WORKSPACE_DIR);
if (workDir == null) {
return chain.process(payload);
}
UUID projectId = payload.getHeader(Payload.PROJECT_ID);
try {
String runtime = getRuntimeType(payload);
ProjectLoader.Result result = projectLoader.loadProject(workDir, runtime, importsNormalizer.forProject(projectId), new ProcessImportsListener(processKey));
List<Snapshot> snapshots = result.snapshots();
payload = PayloadUtils.addSnapshots(payload, snapshots);
ProcessDefinition pd = result.projectDefinition();
int depsCount = pd.configuration().dependencies().size();
if (depsCount > MAX_DEPENDENCIES_COUNT) {
String msg = String.format("Too many dependencies. Current: %d, maximum allowed: %d", depsCount, MAX_DEPENDENCIES_COUNT);
throw new ConcordApplicationException(msg, Response.Status.BAD_REQUEST);
}
payload = payload.putHeader(Payload.PROJECT_DEFINITION, pd).putHeader(Payload.RUNTIME, pd.runtime()).putHeader(Payload.IMPORTS, pd.imports()).putHeader(Payload.DEPENDENCIES, pd.configuration().dependencies());
// save the runtime type in the process configuration
Map<String, Object> cfg = payload.getHeader(Payload.CONFIGURATION, Collections.emptyMap());
// make mutable
cfg = new HashMap<>(cfg);
cfg.put(Constants.Request.RUNTIME_KEY, runtime);
payload = payload.putHeader(Payload.CONFIGURATION, cfg);
} catch (ImportProcessingException e) {
throw new ProcessException(processKey, "Error while processing import " + e.getImport() + ". Error: " + e.getMessage(), e);
} catch (Exception e) {
log.warn("process -> ({}) project loading error: {}", workDir, e.getMessage());
throw new ProcessException(processKey, "Error while loading the project, check the syntax. " + e.getMessage(), e);
}
return chain.process(payload);
}
Aggregations