use of com.walmartlabs.concord.runner.engine.el.InjectVariableELResolver in project concord by walmartlabs.
the class EngineFactory method create.
@SuppressWarnings("deprecation")
public Engine create(ProjectDefinition project, Path baseDir, Collection<String> activeProfiles, Set<String> metaVariables, EventConfiguration eventCfg) {
Path attachmentsDir = baseDir.resolve(InternalConstants.Files.JOB_ATTACHMENTS_DIR_NAME);
Path stateDir = attachmentsDir.resolve(InternalConstants.Files.JOB_STATE_DIR_NAME);
Path eventsDir = stateDir.resolve("events");
Path instancesDir = stateDir.resolve("instances");
Path formsDir = stateDir.resolve(InternalConstants.Files.JOB_FORMS_DIR_NAME);
try {
Files.createDirectories(eventsDir);
Files.createDirectories(instancesDir);
Files.createDirectories(formsDir);
} catch (IOException e) {
throw new RuntimeException(e);
}
ExpressionManager expressionManager = new DefaultExpressionManager(new String[] { InternalConstants.Context.CONTEXT_KEY, InternalConstants.Context.EXECUTION_CONTEXT_KEY }, new TaskResolver(taskRegistry), new InjectVariableELResolver()) {
@Override
protected ELResolver createResolver(ExecutionContext ctx) {
CompositeELResolver cr = new CompositeELResolver();
cr.add(new ExecutionContextVariableResolver(ctx));
for (ELResolver r : resolvers) {
cr.add(r);
}
return cr;
}
};
FormStorage formStorage = new FileFormStorage(formsDir);
// here we create a separate ContextFactory to avoid circular references
// between ConcordFormService and ConcordExecutionContextFactory
// TODO find a better way
FormService formService = new ConcordFormService(new DefaultExecutionContextFactory(expressionManager), new NoopResumeHandler(), formStorage);
ProtectedVarContext protectedVarContext = new ProtectedVarContext(PolicyEngineHolder.INSTANCE.getEngine());
ConcordExecutionContextFactory contextFactory = new ConcordExecutionContextFactory(expressionManager, protectedVarContext, formService);
EventStorage eventStorage = new FileEventStorage(eventsDir);
PersistenceManager persistenceManager = new FilePersistenceManager(instancesDir);
ProjectDefinitionAdapter adapter = new ProjectDefinitionAdapter(project, activeProfiles, baseDir);
UserTaskHandler uth = new FormTaskHandler(contextFactory, adapter.forms(), formService);
Configuration cfg = new Configuration();
cfg.setInterpolateInputVariables(true);
cfg.setWrapAllExceptionsAsBpmnErrors(true);
cfg.setCopyAllCallActivityOutVariables(true);
ElementEventProcessor eventProcessor;
if (eventCfg.isRecordEvents()) {
eventProcessor = new DefaultElementEventProcessor(apiClientFactory, adapter.processes());
} else {
eventProcessor = new NopElementEventProcessor();
}
ProcessOutVariables outVariables = new ProcessOutVariables(contextFactory);
List<TaskInterceptor> taskInterceptors = new ArrayList<>();
taskInterceptors.add(protectedVarContext);
taskInterceptors.add(new TaskEventInterceptor(eventCfg, eventProcessor));
taskInterceptors.add(new PolicyPreprocessor(baseDir));
Engine engine = new EngineBuilder().withContextFactory(contextFactory).withLockManager(new NoopLockManager()).withExpressionManager(expressionManager).withDefinitionProvider(adapter.processes()).withTaskRegistry(taskRegistry).withJavaDelegateHandler(new JavaDelegateHandlerImpl(taskInterceptors)).withEventStorage(eventStorage).withPersistenceManager(persistenceManager).withUserTaskHandler(uth).withConfiguration(cfg).withListener(new ProcessOutVariablesListener(attachmentsDir, outVariables)).withListener(new VariablesSnapshotListener(stateDir)).withResourceResolver(new ResourceResolverImpl(baseDir)).build();
engine.addInterceptor(new ProcessElementInterceptor(eventProcessor, new ProcessMetadataProcessor(apiClientFactory, metaVariables)));
return engine;
}
use of com.walmartlabs.concord.runner.engine.el.InjectVariableELResolver 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