Search in sources :

Example 1 with ClearTextSecretsProvider

use of org.apache.pulsar.functions.secretsprovider.ClearTextSecretsProvider in project pulsar by apache.

the class LocalRunner method startThreadedMode.

private void startThreadedMode(org.apache.pulsar.functions.proto.Function.FunctionDetails functionDetails, int parallelism, int instanceIdOffset, String serviceUrl, String stateStorageServiceUrl, AuthenticationConfig authConfig, String userCodeFile) throws Exception {
    if (metricsPortStart != null) {
        if (metricsPortStart < 0 || metricsPortStart > 65535) {
            throw new IllegalArgumentException("Metrics port need to be within the range of 0 and 65535");
        }
    }
    SecretsProvider secretsProvider;
    if (secretsProviderClassName != null) {
        secretsProvider = (SecretsProvider) Reflections.createInstance(secretsProviderClassName, ClassLoader.getSystemClassLoader());
        Map<String, String> config = null;
        if (secretsProviderConfig != null) {
            config = (Map<String, String>) new Gson().fromJson(secretsProviderConfig, Map.class);
        }
        secretsProvider.init(config);
    } else {
        secretsProvider = new ClearTextSecretsProvider();
    }
    boolean exposePulsarAdminClientEnabled = false;
    if (functionConfig != null && functionConfig.getExposePulsarAdminClientEnabled() != null) {
        exposePulsarAdminClientEnabled = functionConfig.getExposePulsarAdminClientEnabled();
    }
    // Collector Registry for prometheus metrics
    FunctionCollectorRegistry collectorRegistry = FunctionCollectorRegistry.getDefaultImplementation();
    RuntimeUtils.registerDefaultCollectors(collectorRegistry);
    ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
    try {
        if (userCodeClassLoader != null) {
            Thread.currentThread().setContextClassLoader(userCodeClassLoader);
        }
        runtimeFactory = new ThreadRuntimeFactory("LocalRunnerThreadGroup", serviceUrl, stateStorageImplClass, stateStorageServiceUrl, authConfig, secretsProvider, collectorRegistry, narExtractionDirectory, null, exposePulsarAdminClientEnabled, webServiceUrl);
    } finally {
        Thread.currentThread().setContextClassLoader(originalClassLoader);
    }
    for (int i = 0; i < parallelism; ++i) {
        InstanceConfig instanceConfig = new InstanceConfig();
        instanceConfig.setFunctionDetails(functionDetails);
        // TODO: correctly implement function version and id
        instanceConfig.setFunctionVersion(UUID.randomUUID().toString());
        instanceConfig.setFunctionId(UUID.randomUUID().toString());
        instanceConfig.setInstanceId(i + instanceIdOffset);
        instanceConfig.setMaxBufferedTuples(1024);
        if (metricsPortStart != null) {
            instanceConfig.setMetricsPort(metricsPortStart);
        }
        instanceConfig.setClusterName("local");
        if (functionConfig != null) {
            instanceConfig.setMaxPendingAsyncRequests(functionConfig.getMaxPendingAsyncRequests());
            if (functionConfig.getExposePulsarAdminClientEnabled() != null) {
                instanceConfig.setExposePulsarAdminClientEnabled(functionConfig.getExposePulsarAdminClientEnabled());
            }
        }
        RuntimeSpawner runtimeSpawner = new RuntimeSpawner(instanceConfig, userCodeFile, null, runtimeFactory, instanceLivenessCheck);
        spawners.add(runtimeSpawner);
        runtimeSpawner.start();
    }
    if (metricsPortStart != null) {
        // starting metrics server
        log.info("Starting metrics server on port {}", metricsPortStart);
        metricsServer = new HTTPServer(new InetSocketAddress(metricsPortStart), collectorRegistry, true);
    }
}
Also used : InetSocketAddress(java.net.InetSocketAddress) FunctionCollectorRegistry(org.apache.pulsar.functions.instance.stats.FunctionCollectorRegistry) Gson(com.google.gson.Gson) ClearTextSecretsProvider(org.apache.pulsar.functions.secretsprovider.ClearTextSecretsProvider) HTTPServer(io.prometheus.client.exporter.HTTPServer) InstanceConfig(org.apache.pulsar.functions.instance.InstanceConfig) ThreadRuntimeFactory(org.apache.pulsar.functions.runtime.thread.ThreadRuntimeFactory) SecretsProvider(org.apache.pulsar.functions.secretsprovider.SecretsProvider) ClearTextSecretsProvider(org.apache.pulsar.functions.secretsprovider.ClearTextSecretsProvider) RuntimeSpawner(org.apache.pulsar.functions.runtime.RuntimeSpawner)

Example 2 with ClearTextSecretsProvider

use of org.apache.pulsar.functions.secretsprovider.ClearTextSecretsProvider in project pulsar by yahoo.

the class LocalRunner method startThreadedMode.

private void startThreadedMode(org.apache.pulsar.functions.proto.Function.FunctionDetails functionDetails, int parallelism, int instanceIdOffset, String serviceUrl, String stateStorageServiceUrl, AuthenticationConfig authConfig, String userCodeFile) throws Exception {
    if (metricsPortStart != null) {
        if (metricsPortStart < 0 || metricsPortStart > 65535) {
            throw new IllegalArgumentException("Metrics port need to be within the range of 0 and 65535");
        }
    }
    SecretsProvider secretsProvider;
    if (secretsProviderClassName != null) {
        secretsProvider = (SecretsProvider) Reflections.createInstance(secretsProviderClassName, ClassLoader.getSystemClassLoader());
        Map<String, String> config = null;
        if (secretsProviderConfig != null) {
            config = (Map<String, String>) new Gson().fromJson(secretsProviderConfig, Map.class);
        }
        secretsProvider.init(config);
    } else {
        secretsProvider = new ClearTextSecretsProvider();
    }
    boolean exposePulsarAdminClientEnabled = false;
    if (functionConfig != null && functionConfig.getExposePulsarAdminClientEnabled() != null) {
        exposePulsarAdminClientEnabled = functionConfig.getExposePulsarAdminClientEnabled();
    }
    // Collector Registry for prometheus metrics
    FunctionCollectorRegistry collectorRegistry = FunctionCollectorRegistry.getDefaultImplementation();
    RuntimeUtils.registerDefaultCollectors(collectorRegistry);
    ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
    try {
        if (userCodeClassLoader != null) {
            Thread.currentThread().setContextClassLoader(userCodeClassLoader);
        }
        runtimeFactory = new ThreadRuntimeFactory("LocalRunnerThreadGroup", serviceUrl, stateStorageImplClass, stateStorageServiceUrl, authConfig, secretsProvider, collectorRegistry, narExtractionDirectory, null, exposePulsarAdminClientEnabled, webServiceUrl);
    } finally {
        Thread.currentThread().setContextClassLoader(originalClassLoader);
    }
    for (int i = 0; i < parallelism; ++i) {
        InstanceConfig instanceConfig = new InstanceConfig();
        instanceConfig.setFunctionDetails(functionDetails);
        // TODO: correctly implement function version and id
        instanceConfig.setFunctionVersion(UUID.randomUUID().toString());
        instanceConfig.setFunctionId(UUID.randomUUID().toString());
        instanceConfig.setInstanceId(i + instanceIdOffset);
        instanceConfig.setMaxBufferedTuples(1024);
        if (metricsPortStart != null) {
            instanceConfig.setMetricsPort(metricsPortStart);
        }
        instanceConfig.setClusterName("local");
        if (functionConfig != null) {
            instanceConfig.setMaxPendingAsyncRequests(functionConfig.getMaxPendingAsyncRequests());
            if (functionConfig.getExposePulsarAdminClientEnabled() != null) {
                instanceConfig.setExposePulsarAdminClientEnabled(functionConfig.getExposePulsarAdminClientEnabled());
            }
        }
        RuntimeSpawner runtimeSpawner = new RuntimeSpawner(instanceConfig, userCodeFile, null, runtimeFactory, instanceLivenessCheck);
        spawners.add(runtimeSpawner);
        runtimeSpawner.start();
    }
    if (metricsPortStart != null) {
        // starting metrics server
        log.info("Starting metrics server on port {}", metricsPortStart);
        metricsServer = new HTTPServer(new InetSocketAddress(metricsPortStart), collectorRegistry, true);
    }
}
Also used : InetSocketAddress(java.net.InetSocketAddress) FunctionCollectorRegistry(org.apache.pulsar.functions.instance.stats.FunctionCollectorRegistry) Gson(com.google.gson.Gson) ClearTextSecretsProvider(org.apache.pulsar.functions.secretsprovider.ClearTextSecretsProvider) HTTPServer(io.prometheus.client.exporter.HTTPServer) InstanceConfig(org.apache.pulsar.functions.instance.InstanceConfig) ThreadRuntimeFactory(org.apache.pulsar.functions.runtime.thread.ThreadRuntimeFactory) SecretsProvider(org.apache.pulsar.functions.secretsprovider.SecretsProvider) ClearTextSecretsProvider(org.apache.pulsar.functions.secretsprovider.ClearTextSecretsProvider) RuntimeSpawner(org.apache.pulsar.functions.runtime.RuntimeSpawner)

Example 3 with ClearTextSecretsProvider

use of org.apache.pulsar.functions.secretsprovider.ClearTextSecretsProvider in project incubator-pulsar by apache.

the class LocalRunner method startThreadedMode.

private void startThreadedMode(org.apache.pulsar.functions.proto.Function.FunctionDetails functionDetails, int parallelism, int instanceIdOffset, String serviceUrl, String stateStorageServiceUrl, AuthenticationConfig authConfig, String userCodeFile) throws Exception {
    if (metricsPortStart != null) {
        if (metricsPortStart < 0 || metricsPortStart > 65535) {
            throw new IllegalArgumentException("Metrics port need to be within the range of 0 and 65535");
        }
    }
    SecretsProvider secretsProvider;
    if (secretsProviderClassName != null) {
        secretsProvider = (SecretsProvider) Reflections.createInstance(secretsProviderClassName, ClassLoader.getSystemClassLoader());
        Map<String, String> config = null;
        if (secretsProviderConfig != null) {
            config = (Map<String, String>) new Gson().fromJson(secretsProviderConfig, Map.class);
        }
        secretsProvider.init(config);
    } else {
        secretsProvider = new ClearTextSecretsProvider();
    }
    boolean exposePulsarAdminClientEnabled = false;
    if (functionConfig != null && functionConfig.getExposePulsarAdminClientEnabled() != null) {
        exposePulsarAdminClientEnabled = functionConfig.getExposePulsarAdminClientEnabled();
    }
    // Collector Registry for prometheus metrics
    FunctionCollectorRegistry collectorRegistry = FunctionCollectorRegistry.getDefaultImplementation();
    RuntimeUtils.registerDefaultCollectors(collectorRegistry);
    ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
    try {
        if (userCodeClassLoader != null) {
            Thread.currentThread().setContextClassLoader(userCodeClassLoader);
        }
        runtimeFactory = new ThreadRuntimeFactory("LocalRunnerThreadGroup", serviceUrl, stateStorageImplClass, stateStorageServiceUrl, authConfig, secretsProvider, collectorRegistry, narExtractionDirectory, null, exposePulsarAdminClientEnabled, webServiceUrl);
    } finally {
        Thread.currentThread().setContextClassLoader(originalClassLoader);
    }
    for (int i = 0; i < parallelism; ++i) {
        InstanceConfig instanceConfig = new InstanceConfig();
        instanceConfig.setFunctionDetails(functionDetails);
        // TODO: correctly implement function version and id
        instanceConfig.setFunctionVersion(UUID.randomUUID().toString());
        instanceConfig.setFunctionId(UUID.randomUUID().toString());
        instanceConfig.setInstanceId(i + instanceIdOffset);
        instanceConfig.setMaxBufferedTuples(1024);
        if (metricsPortStart != null) {
            instanceConfig.setMetricsPort(metricsPortStart);
        }
        instanceConfig.setClusterName("local");
        if (functionConfig != null) {
            instanceConfig.setMaxPendingAsyncRequests(functionConfig.getMaxPendingAsyncRequests());
            if (functionConfig.getExposePulsarAdminClientEnabled() != null) {
                instanceConfig.setExposePulsarAdminClientEnabled(functionConfig.getExposePulsarAdminClientEnabled());
            }
        }
        RuntimeSpawner runtimeSpawner = new RuntimeSpawner(instanceConfig, userCodeFile, null, runtimeFactory, instanceLivenessCheck);
        spawners.add(runtimeSpawner);
        runtimeSpawner.start();
    }
    if (metricsPortStart != null) {
        // starting metrics server
        log.info("Starting metrics server on port {}", metricsPortStart);
        metricsServer = new HTTPServer(new InetSocketAddress(metricsPortStart), collectorRegistry, true);
    }
}
Also used : InetSocketAddress(java.net.InetSocketAddress) FunctionCollectorRegistry(org.apache.pulsar.functions.instance.stats.FunctionCollectorRegistry) Gson(com.google.gson.Gson) ClearTextSecretsProvider(org.apache.pulsar.functions.secretsprovider.ClearTextSecretsProvider) HTTPServer(io.prometheus.client.exporter.HTTPServer) InstanceConfig(org.apache.pulsar.functions.instance.InstanceConfig) ThreadRuntimeFactory(org.apache.pulsar.functions.runtime.thread.ThreadRuntimeFactory) SecretsProvider(org.apache.pulsar.functions.secretsprovider.SecretsProvider) ClearTextSecretsProvider(org.apache.pulsar.functions.secretsprovider.ClearTextSecretsProvider) RuntimeSpawner(org.apache.pulsar.functions.runtime.RuntimeSpawner)

Aggregations

Gson (com.google.gson.Gson)3 HTTPServer (io.prometheus.client.exporter.HTTPServer)3 InetSocketAddress (java.net.InetSocketAddress)3 InstanceConfig (org.apache.pulsar.functions.instance.InstanceConfig)3 FunctionCollectorRegistry (org.apache.pulsar.functions.instance.stats.FunctionCollectorRegistry)3 RuntimeSpawner (org.apache.pulsar.functions.runtime.RuntimeSpawner)3 ThreadRuntimeFactory (org.apache.pulsar.functions.runtime.thread.ThreadRuntimeFactory)3 ClearTextSecretsProvider (org.apache.pulsar.functions.secretsprovider.ClearTextSecretsProvider)3 SecretsProvider (org.apache.pulsar.functions.secretsprovider.SecretsProvider)3