Search in sources :

Example 1 with ProjectDefinition

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"));
}
Also used : ImportManager(com.walmartlabs.concord.imports.ImportManager) URI(java.net.URI) Map(java.util.Map) ProjectDefinition(com.walmartlabs.concord.project.model.ProjectDefinition) Test(org.junit.jupiter.api.Test)

Example 2 with ProjectDefinition

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));
}
Also used : ImportManager(com.walmartlabs.concord.imports.ImportManager) URI(java.net.URI) ProjectDefinition(com.walmartlabs.concord.project.model.ProjectDefinition) Test(org.junit.jupiter.api.Test)

Example 3 with ProjectDefinition

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);
}
Also used : Path(java.nio.file.Path) Snapshot(com.walmartlabs.concord.repository.Snapshot) Resources(com.walmartlabs.concord.project.model.Resources) Imports(com.walmartlabs.concord.imports.Imports) ProjectDefinition(com.walmartlabs.concord.project.model.ProjectDefinition) FileVisitResult(java.nio.file.FileVisitResult)

Example 4 with ProjectDefinition

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;
        }
    }
}
Also used : MapUtils(com.walmartlabs.concord.sdk.MapUtils) Module(com.google.inject.Module) PolicyEngineRules(com.walmartlabs.concord.policyengine.PolicyEngineRules) URL(java.net.URL) LoggerFactory(org.slf4j.LoggerFactory) ObjectInputStream(java.io.ObjectInputStream) UserDefinedException(com.walmartlabs.concord.sdk.UserDefinedException) URLClassLoader(java.net.URLClassLoader) ImportsListener(com.walmartlabs.concord.imports.ImportsListener) ProjectLoader(com.walmartlabs.concord.project.ProjectLoader) Path(java.nio.file.Path) io.takari.bpm.api(io.takari.bpm.api) StandardOpenOption(java.nio.file.StandardOpenOption) IOUtils(com.walmartlabs.concord.common.IOUtils) ApiClientFactory(com.walmartlabs.concord.client.ApiClientFactory) TypeEncounter(com.google.inject.spi.TypeEncounter) Collectors(java.util.stream.Collectors) Jdk8Module(com.fasterxml.jackson.datatype.jdk8.Jdk8Module) URLClassSpace(org.eclipse.sisu.space.URLClassSpace) ApiClientConfiguration(com.walmartlabs.concord.client.ApiClientConfiguration) Stream(java.util.stream.Stream) ProjectDefinition(com.walmartlabs.concord.project.model.ProjectDefinition) TypeLiteral(com.google.inject.TypeLiteral) NoopImportsNormalizer(com.walmartlabs.concord.project.NoopImportsNormalizer) SpaceModule(org.eclipse.sisu.space.SpaceModule) java.util(java.util) EngineFactory(com.walmartlabs.concord.runner.engine.EngineFactory) StateManager(com.walmartlabs.concord.runtime.common.StateManager) Singleton(javax.inject.Singleton) Inject(javax.inject.Inject) Constants(com.walmartlabs.concord.sdk.Constants) PolicyEngine(com.walmartlabs.concord.policyengine.PolicyEngine) BeanScanning(org.eclipse.sisu.space.BeanScanning) Task(com.walmartlabs.concord.sdk.Task) RunnerConfiguration(com.walmartlabs.concord.runtime.common.cfg.RunnerConfiguration) Named(javax.inject.Named) OutputStream(java.io.OutputStream) WireModule(org.eclipse.sisu.wire.WireModule) Logger(org.slf4j.Logger) MalformedURLException(java.net.MalformedURLException) Files(java.nio.file.Files) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ProcessHeartbeat(com.walmartlabs.concord.runtime.common.ProcessHeartbeat) IOException(java.io.IOException) ApiClient(com.walmartlabs.concord.ApiClient) ProcessEntry(com.walmartlabs.concord.client.ProcessEntry) Injector(com.google.inject.Injector) AbstractMatcher(com.google.inject.matcher.AbstractMatcher) GuavaModule(com.fasterxml.jackson.datatype.guava.GuavaModule) Paths(java.nio.file.Paths) EventConfiguration(com.walmartlabs.concord.runner.engine.EventConfiguration) Guice(com.google.inject.Guice) TypeListener(com.google.inject.spi.TypeListener) NoopImportManager(com.walmartlabs.concord.imports.NoopImportManager) AbstractModule(com.google.inject.AbstractModule) ProcessErrorProcessor(com.walmartlabs.concord.runner.engine.ProcessErrorProcessor) InputStream(java.io.InputStream) ProjectDefinition(com.walmartlabs.concord.project.model.ProjectDefinition) EventConfiguration(com.walmartlabs.concord.runner.engine.EventConfiguration) PolicyEngine(com.walmartlabs.concord.policyengine.PolicyEngine)

Example 5 with ProjectDefinition

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"));
}
Also used : ImportManager(com.walmartlabs.concord.imports.ImportManager) URI(java.net.URI) ProjectDefinition(com.walmartlabs.concord.project.model.ProjectDefinition) Test(org.junit.jupiter.api.Test)

Aggregations

ProjectDefinition (com.walmartlabs.concord.project.model.ProjectDefinition)6 ImportManager (com.walmartlabs.concord.imports.ImportManager)3 Imports (com.walmartlabs.concord.imports.Imports)2 Resources (com.walmartlabs.concord.project.model.Resources)2 URI (java.net.URI)2 Test (org.junit.jupiter.api.Test)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 GuavaModule (com.fasterxml.jackson.datatype.guava.GuavaModule)1 Jdk8Module (com.fasterxml.jackson.datatype.jdk8.Jdk8Module)1 AbstractModule (com.google.inject.AbstractModule)1 Guice (com.google.inject.Guice)1 Injector (com.google.inject.Injector)1 Module (com.google.inject.Module)1 TypeLiteral (com.google.inject.TypeLiteral)1 AbstractMatcher (com.google.inject.matcher.AbstractMatcher)1 TypeEncounter (com.google.inject.spi.TypeEncounter)1 TypeListener (com.google.inject.spi.TypeListener)1 ApiClient (com.walmartlabs.concord.ApiClient)1 ApiClientConfiguration (com.walmartlabs.concord.client.ApiClientConfiguration)1 ApiClientFactory (com.walmartlabs.concord.client.ApiClientFactory)1