Search in sources :

Example 1 with Checkpoint

use of com.walmartlabs.concord.runtime.v2.model.Checkpoint in project concord by walmartlabs.

the class CheckpointCommand method execute.

@Override
protected void execute(Runtime runtime, State state, ThreadId threadId) {
    state.peekFrame(threadId).pop();
    // eval the name in case it contains an expression
    Context ctx = runtime.getService(Context.class);
    ExpressionEvaluator ee = runtime.getService(ExpressionEvaluator.class);
    String name = ee.eval(EvalContextFactory.global(ctx), getStep().getName(), String.class);
    runtime.getService(SynchronizationService.class).point(() -> {
        CheckpointService checkpointService = runtime.getService(CheckpointService.class);
        ProcessDefinition processDefinition = runtime.getService(ProcessDefinition.class);
        // cleanup the internal state to reduce the serialized data size
        state.gc();
        // TODO validate checkpoint name
        checkpointService.create(threadId, getCorrelationId(), name, runtime, ProcessSnapshot.builder().vmState(state).processDefinition(processDefinition).build());
    });
}
Also used : Context(com.walmartlabs.concord.runtime.v2.sdk.Context) SynchronizationService(com.walmartlabs.concord.runtime.v2.runner.SynchronizationService) CheckpointService(com.walmartlabs.concord.runtime.v2.runner.checkpoints.CheckpointService) ProcessDefinition(com.walmartlabs.concord.runtime.v2.model.ProcessDefinition) ExpressionEvaluator(com.walmartlabs.concord.runtime.v2.runner.el.ExpressionEvaluator)

Example 2 with Checkpoint

use of com.walmartlabs.concord.runtime.v2.model.Checkpoint in project concord by walmartlabs.

the class ProjectLoaderV2Test method testMultiProjectFiles.

@Test
@SuppressWarnings("unchecked")
public void testMultiProjectFiles() throws Exception {
    ProjectLoaderV2 loader = new ProjectLoaderV2(mock(ImportManager.class));
    URI uri = ClassLoader.getSystemResource("multiProjectFile").toURI();
    ProjectLoaderV2.Result result = loader.load(Paths.get(uri), new NoopImportsNormalizer(), ImportsListener.NOP_LISTENER);
    assertNotNull(result);
    assertNotNull(result.getProjectDefinition());
    ProcessDefinition pd = result.getProjectDefinition();
    // configuration:
    ProcessDefinitionConfiguration cfg = pd.configuration();
    assertNotNull(cfg);
    // configuration.debug: should be collected from ROOT concord.yml
    assertTrue(cfg.debug());
    // configuration.activeProfiles: should be collected from ROOT concord.yml
    assertEquals(Collections.singletonList("concord.yml"), cfg.activeProfiles());
    // configuration.entryPoint: should be collected from ROOT concord.yml
    assertEquals("root", cfg.entryPoint());
    // configuration.dependencies: should be collected from ALL *.concord.yml
    assertEquals(Arrays.asList("2.concord.yml", "concord.yml"), cfg.dependencies());
    // configuration.arguments: should be collected from ALL *.concord.yml and mereged
    assertEquals("ttt", cfg.arguments().get("abc"));
    assertEquals("234", ((Map<String, Object>) cfg.arguments().get("nested")).get("value"));
    // configuration.meta: should be collected from ROOT concord.yml
    assertEquals(Collections.singletonMap("k", "concord.yml"), cfg.meta());
    // configuration.events: should be collected from ROOT concord.yml
    assertEquals(EventConfiguration.builder().recordTaskInVars(true).recordTaskOutVars(true).truncateInVars(true).truncateOutVars(true).truncateMaxStringLength(1).truncateMaxArrayLength(2).truncateMaxDepth(3).inVarsBlacklist(Arrays.asList("apiKey", "apiRootToken")).recordTaskMeta(true).truncateMeta(true).build(), cfg.events());
    // configuration.requirements: should be collected from ROOT concord.yml
    assertEquals(Collections.singletonMap("req", "concord.yml"), cfg.requirements());
    // configuration.processTimeout: should be collected from ROOT concord.yml
    assertEquals("PT1H", cfg.processTimeout().toString());
    // configuration.suspendTimeout: should be collected from ROOT concord.yml
    assertEquals("PT26H", cfg.suspendTimeout().toString());
    // configuration.out: should be collected from ROOT concord.yml
    assertEquals(Collections.singletonList("from-root"), cfg.out());
    // configuration.template: should be collected from ROOT concord.yml
    assertNotNull(cfg.template());
    assertEquals("mytemplate", cfg.template());
    // flows: should be collected from ALL *.concord.yml
    // if flow has same name then most recent used
    assertEquals(new HashSet<>(Arrays.asList("default", "flowN3")), pd.flows().keySet());
    assertEquals(1, pd.flows().get("default").size());
    assertTrue(pd.flows().get("default").get(0) instanceof Checkpoint);
    assertEquals("root", ((Checkpoint) pd.flows().get("default").get(0)).getName());
    // publicFlows: should be collected from ROOT concord.yml
    assertEquals(Collections.singleton("root"), pd.publicFlows());
    // profiles: should be collected from ALL *.concord.yml
    // if profile has same name then most recent used
    assertEquals(Collections.emptyMap(), pd.profiles());
    // triggers: should be collected from ALL *.concord.yml
    assertEquals(3, pd.triggers().size());
    assertEquals(Arrays.asList("1.concord.yml", "2.concord.yml", "concord.yml"), pd.triggers().stream().map(t -> t.configuration().get("entryPoint")).collect(Collectors.toList()));
    // imports: should be collected from ALL *.concord.yml
    assertEquals(2, pd.imports().items().size());
    assertEquals(Arrays.asList("2.concord.yml", "concord.yml"), pd.imports().items().stream().map(i -> ((Import.GitDefinition) i).url()).collect(Collectors.toList()));
    // forms: should be collected from ALL *.concord.yml
    // if form has same name then most recent used
    assertEquals(1, pd.forms().size());
    assertNotNull(pd.forms().get("myForm"));
    assertEquals(1, pd.forms().get("myForm").fields().size());
    assertEquals("myName3", pd.forms().get("myForm").fields().get(0).name());
    // resources: should be collected from ALL *.concord.yml
    assertEquals(Arrays.asList("glob:concord/{**/,}{*.,}concord.{yml,yaml}", "glob:tmp/1.yml"), pd.resources().concord());
}
Also used : ImportManager(com.walmartlabs.concord.imports.ImportManager) ProcessDefinitionConfiguration(com.walmartlabs.concord.runtime.v2.model.ProcessDefinitionConfiguration) ProjectLoaderV2(com.walmartlabs.concord.runtime.v2.ProjectLoaderV2) Checkpoint(com.walmartlabs.concord.runtime.v2.model.Checkpoint) Import(com.walmartlabs.concord.imports.Import) NoopImportsNormalizer(com.walmartlabs.concord.runtime.v2.NoopImportsNormalizer) ProcessDefinition(com.walmartlabs.concord.runtime.v2.model.ProcessDefinition) URI(java.net.URI) Test(org.junit.jupiter.api.Test)

Aggregations

ProcessDefinition (com.walmartlabs.concord.runtime.v2.model.ProcessDefinition)2 Import (com.walmartlabs.concord.imports.Import)1 ImportManager (com.walmartlabs.concord.imports.ImportManager)1 NoopImportsNormalizer (com.walmartlabs.concord.runtime.v2.NoopImportsNormalizer)1 ProjectLoaderV2 (com.walmartlabs.concord.runtime.v2.ProjectLoaderV2)1 Checkpoint (com.walmartlabs.concord.runtime.v2.model.Checkpoint)1 ProcessDefinitionConfiguration (com.walmartlabs.concord.runtime.v2.model.ProcessDefinitionConfiguration)1 SynchronizationService (com.walmartlabs.concord.runtime.v2.runner.SynchronizationService)1 CheckpointService (com.walmartlabs.concord.runtime.v2.runner.checkpoints.CheckpointService)1 ExpressionEvaluator (com.walmartlabs.concord.runtime.v2.runner.el.ExpressionEvaluator)1 Context (com.walmartlabs.concord.runtime.v2.sdk.Context)1 URI (java.net.URI)1 Test (org.junit.jupiter.api.Test)1