use of com.walmartlabs.concord.project.model.ProjectDefinition in project concord by walmartlabs.
the class ProjectLoaderTest method testMultiProjectFiles.
@Test
@SuppressWarnings("unchecked")
public void testMultiProjectFiles() throws Exception {
ProjectLoader loader = new ProjectLoader(mock(ImportManager.class));
URI uri = ClassLoader.getSystemResource("multiProjectFile").toURI();
ProjectDefinition pd = loader.loadProject(Paths.get(uri), new NoopImportsNormalizer(), ImportsListener.NOP_LISTENER).getProjectDefinition();
assertNotNull(pd);
assertNotNull(pd.getFlows().get("default"));
assertNotNull(pd.getForms().get("myForm"));
assertFalse(pd.getTriggers().isEmpty());
Map<String, Object> cfg = pd.getConfiguration();
assertNotNull(cfg);
assertEquals("ttt", ((Map<String, Object>) cfg.get("arguments")).get("abc"));
assertEquals("234", ((Map<String, Object>) ((Map<String, Object>) cfg.get("arguments")).get("nested")).get("value"));
}
use of com.walmartlabs.concord.project.model.ProjectDefinition in project concord by walmartlabs.
the class ProjectLoaderTest method testComplex.
@Test
public void testComplex() throws Exception {
ProjectLoader loader = new ProjectLoader(mock(ImportManager.class));
URI uri = ClassLoader.getSystemResource("complex").toURI();
ProjectDefinition pd = loader.loadProject(Paths.get(uri), new NoopImportsNormalizer(), ImportsListener.NOP_LISTENER).getProjectDefinition();
assertNotNull(pd);
// --- triggers
assertNotNull(pd.getTriggers());
assertEquals(4, pd.getTriggers().size());
assertEquals("manual", pd.getTriggers().get(3).getName());
assertEquals("integration", pd.getTriggers().get(3).getEntryPoint());
assertEquals("Run Integration Tests", pd.getTriggers().get(3).getCfg().get("name"));
// --- imports
assertNotNull(pd.getImports());
assertEquals(3, pd.getImports().items().size());
assertEquals("git", pd.getImports().items().get(0).type());
assertNotNull(pd.getResources());
assertEquals(1, pd.getResources().getDefinitionPaths().size());
assertEquals("myFlows", pd.getResources().getDefinitionPaths().get(0));
assertEquals(1, pd.getResources().getDisabledDirs().size());
assertEquals("processes", pd.getResources().getDisabledDirs().get(0));
assertEquals(1, pd.getResources().getProfilesPaths().size());
assertEquals("myProfiles", pd.getResources().getProfilesPaths().get(0));
}
use of com.walmartlabs.concord.project.model.ProjectDefinition in project concord by walmartlabs.
the class ProjectLoader method loadProject.
/**
* Loads the project definition using the supplied path. Processes the configured
* imports, templates and extra directories with project files.
*
* @param workDir the directory containing the project files. If {@code imports} are
* configured, the directory will be used as a target for repository
* checkouts.
*/
public Result loadProject(Path workDir, ImportsNormalizer importsNormalizer, ImportsListener listener) throws Exception {
workDir = workDir.normalize().toAbsolutePath();
ProjectDefinition initial = initialLoad(workDir);
Resources resources = initial.getResources();
Imports imports = importsNormalizer.normalize(initial.getImports());
List<Snapshot> snapshots = importManager.process(imports, workDir, listener);
ProjectDefinitionBuilder b = new ProjectDefinitionBuilder(parser);
List<String> projectPaths = resources.getProjectFilePaths();
if (projectPaths != null) {
for (String n : projectPaths) {
Path p = assertLocal(workDir, workDir.resolve(n));
if (Files.exists(p)) {
b.addProjects(p);
}
}
}
for (String n : Constants.Files.PROJECT_ROOT_FILE_NAMES) {
Path p = assertLocal(workDir, workDir.resolve(n));
if (Files.exists(p)) {
b.addProjectFile(workDir, p);
break;
}
}
List<String> definitionPaths = resources.getDefinitionPaths();
if (definitionPaths != null) {
for (String n : definitionPaths) {
Path p = assertLocal(workDir, workDir.resolve(n));
if (Files.exists(p)) {
b.addDefinitions(p);
}
}
}
List<String> profilesPaths = resources.getProfilesPaths();
if (profilesPaths != null) {
for (String n : profilesPaths) {
Path p = assertLocal(workDir, workDir.resolve(n));
if (Files.exists(p)) {
b.addProfiles(p);
}
}
}
ProjectDefinition pd = b.build();
// save the normalized imports, so the exact same workDir structure
// can be re-created later (e.g. by the Agent)
pd = new ProjectDefinition(pd, imports);
return new Result(snapshots, pd);
}
use of com.walmartlabs.concord.project.model.ProjectDefinition in project concord by walmartlabs.
the class Main method executeProcess.
private void executeProcess(String instanceId, CheckpointManager checkpointManager, Path baseDir, Map<String, Object> processCfg) throws ExecutionException {
// get active profiles from the request data
Collection<String> activeProfiles = getActiveProfiles(processCfg);
// load the project
ProjectDefinition project = loadProject(baseDir);
// read the list of metadata variables
Set<String> metaVariables = getMetaVariables(processCfg);
// event recording processCfg
EventConfiguration eventCfg = getEventCfg(processCfg);
Engine engine = engineFactory.create(project, baseDir, activeProfiles, metaVariables, eventCfg);
Map<String, Object> resumeCheckpointReq = null;
while (true) {
Collection<Event> resultEvents;
// check if we need to resume the process from a saved point
Set<String> eventNames = StateManager.readResumeEvents(baseDir);
if (eventNames == null || eventNames.isEmpty()) {
// running fresh
// let's check if there are some saved variables (e.g. from the parent process)
Variables vars = readSavedVariables(baseDir);
resultEvents = start(engine, vars, processCfg, instanceId, baseDir);
} else {
if (eventNames.size() > 1) {
throw new IllegalStateException("Runtime v1 supports resuming for only one event at the time. Got: " + eventNames);
}
String eventName = eventNames.iterator().next();
resultEvents = resume(engine, processCfg, instanceId, baseDir, eventName);
}
Event checkpointEvent = resultEvents.stream().filter(e -> e.getPayload() instanceof Map).filter(e -> getCheckpointId(e) != null).findFirst().orElse(null);
// found a checkpoint, resume the process immediately
if (checkpointEvent != null) {
checkpointManager.process(getCheckpointId(checkpointEvent), getCorrelationId(checkpointEvent), checkpointEvent.getName(), baseDir);
// clear arguments
if (resumeCheckpointReq == null) {
resumeCheckpointReq = new HashMap<>(processCfg);
resumeCheckpointReq.remove(Constants.Request.ARGUMENTS_KEY);
}
processCfg = resumeCheckpointReq;
} else {
// no checkpoints, stop the execution and wait for an external event
return;
}
}
}
use of com.walmartlabs.concord.project.model.ProjectDefinition in project concord by walmartlabs.
the class ProjectLoaderTest method testSimple.
@Test
public void testSimple() throws Exception {
ProjectLoader loader = new ProjectLoader(mock(ImportManager.class));
URI uri = ClassLoader.getSystemResource("simple").toURI();
ProjectDefinition pd = loader.loadProject(Paths.get(uri), new NoopImportsNormalizer(), ImportsListener.NOP_LISTENER).getProjectDefinition();
assertNotNull(pd);
assertNotNull(pd.getFlows().get("main"));
assertNotNull(pd.getFlows().get("other"));
assertNotNull(pd.getForms().get("myForm"));
}
Aggregations