use of io.cdap.cdap.api.macro.MacroEvaluator in project cdap by caskdata.
the class PipelinePhase method registerPlugins.
/**
* Registers all the plugin to the given pluginConfigurer by calling {@link PluginConfigurer#usePluginClass(String,
* String, String, PluginProperties, PluginSelector)}
*
* @param pluginConfigurer the {@link PluginConfigurer} to which the plugins in this {@link PipelinePhase} needs to be
* registered
* @param runtimeConfigurer the runtime configurer to provide runtime arguments to resolve macro better, null
* if this is the initial deploy
* @param namespace namespace the app is deployed
*/
public void registerPlugins(PluginConfigurer pluginConfigurer, @Nullable RuntimeConfigurer runtimeConfigurer, String namespace) {
MacroParserOptions options = MacroParserOptions.builder().skipInvalidMacros().setEscaping(false).setFunctionWhitelist(ConnectionMacroEvaluator.FUNCTION_NAME).build();
MacroEvaluator runtimeEvaluator = null;
if (runtimeConfigurer != null) {
Map<String, MacroEvaluator> evaluators = Collections.singletonMap(ConnectionMacroEvaluator.FUNCTION_NAME, new ConnectionMacroEvaluator(namespace, runtimeConfigurer));
runtimeEvaluator = new DefaultMacroEvaluator(new BasicArguments(runtimeConfigurer.getRuntimeArguments()), evaluators, Collections.singleton(ConnectionMacroEvaluator.FUNCTION_NAME));
}
for (StageSpec stageSpec : stagesByName.values()) {
// we don't need to register connectors only source, sink and transform plugins
if (stageSpec.getPluginType().equals(Constants.Connector.PLUGIN_TYPE)) {
continue;
}
PluginSpec pluginSpec = stageSpec.getPlugin();
ArtifactVersion version = pluginSpec.getArtifact().getVersion();
ArtifactSelector artifactSelector = new ArtifactSelector(pluginSpec.getArtifact().getScope(), pluginSpec.getArtifact().getName(), new ArtifactVersionRange(version, true, version, true));
Map<String, String> prop = pluginSpec.getProperties();
pluginConfigurer.usePluginClass(pluginSpec.getType(), pluginSpec.getName(), stageSpec.getName(), PluginProperties.builder().addAll(runtimeConfigurer == null ? prop : pluginConfigurer.evaluateMacros(prop, runtimeEvaluator, options)).build(), artifactSelector);
}
}
use of io.cdap.cdap.api.macro.MacroEvaluator in project cdap by caskdata.
the class MacroParserTest method testSkipInvalidMacrosInMacroFunctions.
@Test
public void testSkipInvalidMacrosInMacroFunctions() {
MacroEvaluator evaluator = new TestMacroEvaluator(Collections.emptyMap(), Collections.emptyMap(), true);
MacroParser parser = new MacroParser(evaluator, MacroParserOptions.builder().skipInvalidMacros().build());
// test macros in the macro function still get skipped correctly
Assert.assertEquals("${test(${k1})}", parser.parse("${test(${k1})}"));
Assert.assertEquals("${test(${k1${k2}})}", parser.parse("${test(${k1${k2}})}"));
Assert.assertEquals("${test(${k1})}${t(${t1})}", parser.parse("${test(${k1})}${t(${t1})}"));
}
use of io.cdap.cdap.api.macro.MacroEvaluator in project cdap by caskdata.
the class MacroParserTest method assertSubstitution.
private static void assertSubstitution(String macro, String expected, Map<String, String> propertySubstitutions, Map<String, String> macroFunctionSubstitutions) {
MacroEvaluator macroEvaluator = new TestMacroEvaluator(propertySubstitutions, macroFunctionSubstitutions);
MacroParser macroParser = new MacroParser(macroEvaluator);
Assert.assertEquals(expected, macroParser.parse(macro));
}
use of io.cdap.cdap.api.macro.MacroEvaluator in project cdap by caskdata.
the class MacroParserTest method testDisableFunctions.
@Test
public void testDisableFunctions() {
MacroEvaluator evaluator = new TestMacroEvaluator(Collections.emptyMap(), Collections.emptyMap());
MacroParser parser = new MacroParser(evaluator, MacroParserOptions.builder().disableFunctions().build());
Assert.assertEquals("${test(key)}", parser.parse("${test(key)}"));
}
use of io.cdap.cdap.api.macro.MacroEvaluator in project cdap by caskdata.
the class MacroParserTest method testFunctionWhitelist.
@Test
public void testFunctionWhitelist() {
MacroEvaluator evaluator = new TestMacroEvaluator(Collections.emptyMap(), ImmutableMap.of("key", "val"));
MacroParser parser = new MacroParser(evaluator, MacroParserOptions.builder().setFunctionWhitelist("t").build());
// $t(key) should get evaluated, but $test(key) should get skipped.
Assert.assertEquals("${test(key)}val", parser.parse("${test(key)}${t(key)}"));
Assert.assertEquals("val${test(key)}", parser.parse("${t(key)}${test(key)}"));
Assert.assertEquals("${test(val)}", parser.parse("${test(${t(key)})}"));
}
Aggregations