Search in sources :

Example 1 with Variables

use of io.takari.bpm.api.Variables in project concord by walmartlabs.

the class SerializationUtils method reportNotSerializableItems.

@SuppressWarnings({ "unchecked", "rawtypes" })
private static void reportNotSerializableItems(NotSerializableException err, Object o) throws IOException {
    if (o instanceof Variables) {
        Variables v = (Variables) o;
        reportNotSerializableItems(err, v.asMap());
        return;
    } else if (o instanceof Map) {
        Map<Object, Object> m = (Map<Object, Object>) o;
        for (Map.Entry<Object, Object> e : m.entrySet()) {
            if (!isSerializable(e.getKey())) {
                log.warn("Not serializable key: {}", e.getKey());
            }
            Object v = e.getValue();
            if (v == null) {
                continue;
            }
            if (!isSerializable(v)) {
                Class k = v.getClass();
                log.warn("Not serializable value: {} -> {} = {}", e.getKey(), k, v);
            }
        }
    } else if (o instanceof ProcessInstance) {
        ProcessInstance i = (ProcessInstance) o;
        reportNotSerializableItems(err, i.getVariables());
        return;
    }
    throw err;
}
Also used : Variables(io.takari.bpm.api.Variables) ProcessInstance(io.takari.bpm.state.ProcessInstance) Map(java.util.Map)

Example 2 with Variables

use of io.takari.bpm.api.Variables in project concord by walmartlabs.

the class VariablesSnapshotListener method processState.

private ProcessInstance processState(ProcessInstance state) {
    Variables vars = state.getVariables();
    // remove some internal variables before saving
    vars = BpmnErrorHelper.clear(vars);
    try {
        Path dst = stateDir.resolve(InternalConstants.Files.LAST_KNOWN_VARIABLES_FILE_NAME);
        try (OutputStream out = Files.newOutputStream(dst, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING)) {
            SerializationUtils.serialize(out, vars);
        }
    } catch (IOException e) {
        log.error("Can't save a snapshot of the process variables. Process forks (including onError, onCancel and " + "other handlers) may not receive the updated variables. Error: {}", e.getMessage());
    }
    return state;
}
Also used : Variables(io.takari.bpm.api.Variables) Path(java.nio.file.Path) OutputStream(java.io.OutputStream) IOException(java.io.IOException)

Example 3 with Variables

use of io.takari.bpm.api.Variables in project concord by walmartlabs.

the class ConcordExecutionContextTest method ctx.

private ConcordExecutionContext ctx() {
    ExecutionContextFactory<? extends ExecutionContext> ctxFactory = null;
    ExpressionManager expressionManager = null;
    FormService formService = null;
    Variables source = new Variables();
    return new ConcordExecutionContext(ctxFactory, expressionManager, source, varContext, formService);
}
Also used : Variables(io.takari.bpm.api.Variables) ExpressionManager(io.takari.bpm.el.ExpressionManager) FormService(io.takari.bpm.form.FormService) ConcordExecutionContext(com.walmartlabs.concord.runner.engine.ConcordExecutionContextFactory.ConcordExecutionContext)

Example 4 with Variables

use of io.takari.bpm.api.Variables in project concord by walmartlabs.

the class PolicyPreprocessorTest method testPreprocess.

@Test
public void testPreprocess() throws Exception {
    ExpressionManager expressionManager = new DefaultExpressionManager(new String[] { InternalConstants.Context.CONTEXT_KEY, InternalConstants.Context.EXECUTION_CONTEXT_KEY }, new InjectVariableELResolver());
    Context ctx = new ConcordExecutionContextFactory.ConcordExecutionContext(null, expressionManager, new Variables(), null, null);
    ctx.setVariable("gatekeeperArtifacts", Arrays.asList("a", "b", "c"));
    Path workDir = Files.createTempDirectory("concord-test");
    Files.createDirectories(workDir.resolve(InternalConstants.Files.CONCORD_SYSTEM_DIR_NAME));
    // -- read original policy
    String originalPolicy;
    try (InputStream is = PolicyPreprocessorTest.class.getResourceAsStream("/com/walmartlabs/concord/runner/policy.json")) {
        ObjectMapper om = new ObjectMapper();
        originalPolicy = om.writeValueAsString(om.readValue(is, Map.class));
    }
    // -- write tmp policy
    Path policyFile = workDir.resolve(InternalConstants.Files.CONCORD_SYSTEM_DIR_NAME).resolve(InternalConstants.Files.POLICY_FILE_NAME);
    try (InputStream is = PolicyPreprocessorTest.class.getResourceAsStream("/com/walmartlabs/concord/runner/policy.json")) {
        Files.copy(is, policyFile, StandardCopyOption.REPLACE_EXISTING);
    }
    // ---
    PolicyPreprocessor pp = new PolicyPreprocessor(workDir);
    pp.preTask("ansible", null, ctx);
    String processedPolicy = new String(Files.readAllBytes(policyFile));
    assertEquals(EXPECTED_PROCESSED_POLICY, processedPolicy);
    // ---
    pp.postTask("ansible", null, ctx);
    String restoredPolicy = new String(Files.readAllBytes(policyFile));
    assertEquals(originalPolicy, restoredPolicy);
}
Also used : Context(com.walmartlabs.concord.sdk.Context) Variables(io.takari.bpm.api.Variables) Path(java.nio.file.Path) DefaultExpressionManager(io.takari.bpm.el.DefaultExpressionManager) ExpressionManager(io.takari.bpm.el.ExpressionManager) DefaultExpressionManager(io.takari.bpm.el.DefaultExpressionManager) InputStream(java.io.InputStream) InjectVariableELResolver(com.walmartlabs.concord.runner.engine.el.InjectVariableELResolver) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.jupiter.api.Test)

Aggregations

Variables (io.takari.bpm.api.Variables)4 ExpressionManager (io.takari.bpm.el.ExpressionManager)2 Path (java.nio.file.Path)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ConcordExecutionContext (com.walmartlabs.concord.runner.engine.ConcordExecutionContextFactory.ConcordExecutionContext)1 InjectVariableELResolver (com.walmartlabs.concord.runner.engine.el.InjectVariableELResolver)1 Context (com.walmartlabs.concord.sdk.Context)1 DefaultExpressionManager (io.takari.bpm.el.DefaultExpressionManager)1 FormService (io.takari.bpm.form.FormService)1 ProcessInstance (io.takari.bpm.state.ProcessInstance)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 Map (java.util.Map)1 Test (org.junit.jupiter.api.Test)1