@Test public void testTakesChangesUsername() throws Exception { URL resource = Thread.currentThread().getContextClassLoader().getResource("com/collective/celos/defaults-oozie-props"); File defaults = new File(resource.toURI()); WorkflowConfigurationParser parser = new WorkflowConfigurationParser(defaults, ImmutableMap.of("CELOS_USER_JS_VAR", "nameIsChanged")); String func = "function (slotId) {" + " return {" + " \"oozie.wf.application.path\": \"/workflow.xml\"," + " \"inputDir\": \"/input\"," + " \"outputDir\": \"/output\"" + " }" + " }"; String str = "importDefaults(\"test\"); celos.makePropertiesGen(" + func + "); "; NativeJavaObject jsResult = (NativeJavaObject) parser.evaluateReader(new StringReader(str), "string", new MemoryStateDatabase().openConnection()); PropertiesGenerator generator = (PropertiesGenerator) jsResult.unwrap(); Assert.assertEquals(generator.getProperties(null).get("user.name").asText(), "nameIsChanged"); }
Object evaluateReader(Reader r, String fileName, StateDatabaseConnection connection) throws Exception { Global scope = jsConfigParser.createGlobalScope(); Object wrappedThis = Context.javaToJS(this, scope); Map jsProperties = Maps.newHashMap(additionalJsVariables); jsProperties.put("celosWorkflowConfigurationParser", wrappedThis); jsProperties.put("celosConnection", connection); jsConfigParser.putPropertiesInScope(jsProperties, scope); InputStream scripts = WorkflowConfigurationParser.class.getResourceAsStream(CELOS_SCRIPTS_FILENAME); jsConfigParser.evaluateReader(scope, new InputStreamReader(scripts), CELOS_SCRIPTS_FILENAME); return jsConfigParser.evaluateReader(scope, r, fileName); }
WorkflowConfigurationParser { Object evaluateReader(Reader r, String fileName, StateDatabaseConnection connection) throws Exception { Global scope = jsConfigParser.createGlobalScope(); Object wrappedThis = Context.javaToJS(this, scope); Map jsProperties = Maps.newHashMap(additionalJsVariables); jsProperties.put("celosWorkflowConfigurationParser", wrappedThis); jsProperties.put("celosConnection", connection); jsConfigParser.putPropertiesInScope(jsProperties, scope); InputStream scripts = WorkflowConfigurationParser.class.getResourceAsStream(CELOS_SCRIPTS_FILENAME); jsConfigParser.evaluateReader(scope, new InputStreamReader(scripts), CELOS_SCRIPTS_FILENAME); return jsConfigParser.evaluateReader(scope, r, fileName); } }
WorkflowConfigurationParser { Object evaluateReader(Reader r, String fileName, StateDatabaseConnection connection) throws Exception { Global scope = jsConfigParser.createGlobalScope(); Object wrappedThis = Context.javaToJS(this, scope); Map jsProperties = Maps.newHashMap(additionalJsVariables); jsProperties.put("celosWorkflowConfigurationParser", wrappedThis); jsProperties.put("celosConnection", connection); jsConfigParser.putPropertiesInScope(jsProperties, scope); InputStream scripts = WorkflowConfigurationParser.class.getResourceAsStream(CELOS_SCRIPTS_FILENAME); jsConfigParser.evaluateReader(scope, new InputStreamReader(scripts), CELOS_SCRIPTS_FILENAME); return jsConfigParser.evaluateReader(scope, r, fileName); } WorkflowConfigurationParser(File defaultsDir, Map<String, String> additionalJsVariables); }
WorkflowConfigurationParser { Object evaluateReader(Reader r, String fileName, StateDatabaseConnection connection) throws Exception { Global scope = jsConfigParser.createGlobalScope(); Object wrappedThis = Context.javaToJS(this, scope); Map jsProperties = Maps.newHashMap(additionalJsVariables); jsProperties.put("celosWorkflowConfigurationParser", wrappedThis); jsProperties.put("celosConnection", connection); jsConfigParser.putPropertiesInScope(jsProperties, scope); InputStream scripts = WorkflowConfigurationParser.class.getResourceAsStream(CELOS_SCRIPTS_FILENAME); jsConfigParser.evaluateReader(scope, new InputStreamReader(scripts), CELOS_SCRIPTS_FILENAME); return jsConfigParser.evaluateReader(scope, r, fileName); } WorkflowConfigurationParser(File defaultsDir, Map<String, String> additionalJsVariables); WorkflowConfigurationParser parseConfiguration(File workflowsDir, StateDatabaseConnection connection); WorkflowConfiguration getWorkflowConfiguration(); void importDefaultsIntoScope(String label, Global scope); void addWorkflow(Workflow wf); }
WorkflowConfigurationParser { Object evaluateReader(Reader r, String fileName, StateDatabaseConnection connection) throws Exception { Global scope = jsConfigParser.createGlobalScope(); Object wrappedThis = Context.javaToJS(this, scope); Map jsProperties = Maps.newHashMap(additionalJsVariables); jsProperties.put("celosWorkflowConfigurationParser", wrappedThis); jsProperties.put("celosConnection", connection); jsConfigParser.putPropertiesInScope(jsProperties, scope); InputStream scripts = WorkflowConfigurationParser.class.getResourceAsStream(CELOS_SCRIPTS_FILENAME); jsConfigParser.evaluateReader(scope, new InputStreamReader(scripts), CELOS_SCRIPTS_FILENAME); return jsConfigParser.evaluateReader(scope, r, fileName); } WorkflowConfigurationParser(File defaultsDir, Map<String, String> additionalJsVariables); WorkflowConfigurationParser parseConfiguration(File workflowsDir, StateDatabaseConnection connection); WorkflowConfiguration getWorkflowConfiguration(); void importDefaultsIntoScope(String label, Global scope); void addWorkflow(Workflow wf); static final String WORKFLOW_FILE_EXTENSION; }