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;
}
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;
}
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);
}
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);
}
Aggregations