Search in sources :

Example 6 with MacroParserOptions

use of io.cdap.cdap.api.macro.MacroParserOptions in project cdap by caskdata.

the class RemoteConnectionTaskBase method getConnector.

/**
 * Returns {@link Connector} after evaluating macros
 *
 * @param systemAppContext {@link SystemAppTaskContext}
 * @param configurer       {@link ServicePluginConfigurer}
 * @param pluginInfo       {@link PluginInfo}
 * @param namespace        namespace string
 * @param pluginSelector   {@link TrackedPluginSelector}
 * @return {@link Connector}
 * @throws Exception
 */
protected Connector getConnector(SystemAppTaskContext systemAppContext, ServicePluginConfigurer configurer, PluginInfo pluginInfo, String namespace, TrackedPluginSelector pluginSelector) throws Exception {
    Map<String, String> arguments = systemAppContext.getPreferencesForNamespace(namespace, true);
    Map<String, MacroEvaluator> evaluators = ImmutableMap.of(SecureStoreMacroEvaluator.FUNCTION_NAME, new SecureStoreMacroEvaluator(namespace, systemAppContext), OAuthMacroEvaluator.FUNCTION_NAME, new OAuthMacroEvaluator(systemAppContext));
    MacroEvaluator macroEvaluator = new DefaultMacroEvaluator(new BasicArguments(arguments), evaluators, Collections.singleton(OAuthMacroEvaluator.FUNCTION_NAME));
    MacroParserOptions options = MacroParserOptions.builder().setEscaping(false).setFunctionWhitelist(evaluators.keySet()).build();
    return ConnectionUtils.getConnector(configurer, pluginInfo, pluginSelector, macroEvaluator, options);
}
Also used : MacroParserOptions(io.cdap.cdap.api.macro.MacroParserOptions) SecureStoreMacroEvaluator(io.cdap.cdap.etl.common.SecureStoreMacroEvaluator) OAuthMacroEvaluator(io.cdap.cdap.etl.common.OAuthMacroEvaluator) DefaultMacroEvaluator(io.cdap.cdap.etl.common.DefaultMacroEvaluator) SecureStoreMacroEvaluator(io.cdap.cdap.etl.common.SecureStoreMacroEvaluator) MacroEvaluator(io.cdap.cdap.api.macro.MacroEvaluator) OAuthMacroEvaluator(io.cdap.cdap.etl.common.OAuthMacroEvaluator) DefaultMacroEvaluator(io.cdap.cdap.etl.common.DefaultMacroEvaluator) BasicArguments(io.cdap.cdap.etl.common.BasicArguments)

Example 7 with MacroParserOptions

use of io.cdap.cdap.api.macro.MacroParserOptions in project cdap by caskdata.

the class ValidationUtilsTest method getPluginConfigurer.

// Mock PluginConfigurer
private PluginConfigurer getPluginConfigurer(PluginClass pluginClass) {
    return new PluginConfigurer() {

        @Override
        public <T> T usePlugin(String pluginType, String pluginName, String pluginId, PluginProperties properties, PluginSelector selector) {
            String tableName = properties.getProperties().get("tableName");
            if (tableName == null || tableName.isEmpty()) {
                throw new InvalidPluginConfigException(pluginClass, Collections.singleton("tableName"), new HashSet<>());
            }
            MockSource.Config config = new MockSource.Config();
            MockSource.ConnectionConfig connectionConfig = new MockSource.ConnectionConfig();
            String schema = properties.getProperties().get("schema");
            String sleep = properties.getProperties().get("sleepInMillis");
            connectionConfig.setTableName(tableName);
            config.setConfig(connectionConfig, schema, null, sleep == null ? null : Long.parseLong(sleep));
            return (T) new MockSource(config);
        }

        @Override
        public <T> Class<T> usePluginClass(String pluginType, String pluginName, String pluginId, PluginProperties properties, PluginSelector selector) {
            return null;
        }

        @Override
        public Map<String, String> evaluateMacros(Map<String, String> properties, MacroEvaluator evaluator, MacroParserOptions options) throws InvalidMacroException {
            return null;
        }
    };
}
Also used : MockSource(io.cdap.cdap.etl.mock.batch.MockSource) PluginSelector(io.cdap.cdap.api.plugin.PluginSelector) MacroEvaluator(io.cdap.cdap.api.macro.MacroEvaluator) InvalidPluginConfigException(io.cdap.cdap.api.plugin.InvalidPluginConfigException) MacroParserOptions(io.cdap.cdap.api.macro.MacroParserOptions) PluginConfigurer(io.cdap.cdap.api.plugin.PluginConfigurer) PluginProperties(io.cdap.cdap.api.plugin.PluginProperties) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

MacroParserOptions (io.cdap.cdap.api.macro.MacroParserOptions)7 MacroEvaluator (io.cdap.cdap.api.macro.MacroEvaluator)6 BasicArguments (io.cdap.cdap.etl.common.BasicArguments)4 DefaultMacroEvaluator (io.cdap.cdap.etl.common.DefaultMacroEvaluator)4 OAuthMacroEvaluator (io.cdap.cdap.etl.common.OAuthMacroEvaluator)4 SecureStoreMacroEvaluator (io.cdap.cdap.etl.common.SecureStoreMacroEvaluator)4 Map (java.util.Map)4 ImmutableMap (com.google.common.collect.ImmutableMap)3 StageSpec (io.cdap.cdap.etl.proto.v2.spec.StageSpec)3 Gson (com.google.gson.Gson)2 GsonBuilder (com.google.gson.GsonBuilder)2 JsonSyntaxException (com.google.gson.JsonSyntaxException)2 ArtifactScope (io.cdap.cdap.api.artifact.ArtifactScope)2 ArtifactVersion (io.cdap.cdap.api.artifact.ArtifactVersion)2 Schema (io.cdap.cdap.api.data.schema.Schema)2 PluginConfigurer (io.cdap.cdap.api.plugin.PluginConfigurer)2 ConnectionMacroEvaluator (io.cdap.cdap.etl.common.ConnectionMacroEvaluator)2 StageValidationRequest (io.cdap.cdap.etl.proto.v2.validation.StageValidationRequest)2 SchemaTypeAdapter (io.cdap.cdap.internal.io.SchemaTypeAdapter)2 Collections (java.util.Collections)2