Search in sources :

Example 21 with InitializationException

use of org.apache.nifi.reporting.InitializationException in project nifi by apache.

the class TestInvokeGRPC method useSSLContextService.

private void useSSLContextService(final TestRunner controller, final Map<String, String> sslProperties) {
    final SSLContextService service = new StandardSSLContextService();
    try {
        controller.addControllerService("ssl-service", service, sslProperties);
        controller.enableControllerService(service);
    } catch (InitializationException ex) {
        ex.printStackTrace();
        Assert.fail("Could not create SSL Context Service");
    }
    controller.setProperty(InvokeGRPC.PROP_SSL_CONTEXT_SERVICE, "ssl-service");
}
Also used : SSLContextService(org.apache.nifi.ssl.SSLContextService) StandardSSLContextService(org.apache.nifi.ssl.StandardSSLContextService) StandardSSLContextService(org.apache.nifi.ssl.StandardSSLContextService) InitializationException(org.apache.nifi.reporting.InitializationException)

Example 22 with InitializationException

use of org.apache.nifi.reporting.InitializationException in project kylo by Teradata.

the class ThriftConnectionPool method getDriverClassLoader.

/**
 * using Thread.currentThread().getContextClassLoader() will ensure that you are using the ClassLoader for your NAR.
 *
 * @param urlString URL of the class
 * @param drvName   the driver string
 * @return the class loader
 * @throws InitializationException if there is a problem obtaining the ClassLoader
 */
protected ClassLoader getDriverClassLoader(String urlString, String drvName) throws InitializationException {
    if (urlString != null && urlString.length() > 0) {
        try {
            final URL[] urls = new URL[] { new URL(urlString) };
            final URLClassLoader ucl = new URLClassLoader(urls);
            // Workaround which allows to use URLClassLoader for JDBC driver loading.
            // (Because the DriverManager will refuse to use a driver not loaded by the system ClassLoader.)
            final Class<?> clazz = Class.forName(drvName, true, ucl);
            if (clazz == null) {
                throw new InitializationException("Can't load Database Driver " + drvName);
            }
            final Driver driver = (Driver) clazz.newInstance();
            DriverManager.registerDriver(new DriverShim(driver));
            return ucl;
        } catch (final MalformedURLException e) {
            throw new InitializationException("Invalid Database Driver Jar Url", e);
        } catch (final Exception e) {
            throw new InitializationException("Can't load Database Driver", e);
        }
    } else {
        // That will ensure that you are using the ClassLoader for you NAR.
        return Thread.currentThread().getContextClassLoader();
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) URLClassLoader(java.net.URLClassLoader) Driver(java.sql.Driver) InitializationException(org.apache.nifi.reporting.InitializationException) URL(java.net.URL) InitializationException(org.apache.nifi.reporting.InitializationException) ProcessException(org.apache.nifi.processor.exception.ProcessException) SQLException(java.sql.SQLException) MalformedURLException(java.net.MalformedURLException)

Example 23 with InitializationException

use of org.apache.nifi.reporting.InitializationException in project nifi by apache.

the class StandardFlowSynchronizer method getOrCreateReportingTask.

private ReportingTaskNode getOrCreateReportingTask(final FlowController controller, final ReportingTaskDTO dto, final boolean controllerInitialized, final boolean existingFlowEmpty) throws ReportingTaskInstantiationException {
    // create a new reporting task node when the controller is not initialized or the flow is empty
    if (!controllerInitialized || existingFlowEmpty) {
        BundleCoordinate coordinate;
        try {
            coordinate = BundleUtils.getCompatibleBundle(dto.getType(), dto.getBundle());
        } catch (final IllegalStateException e) {
            final BundleDTO bundleDTO = dto.getBundle();
            if (bundleDTO == null) {
                coordinate = BundleCoordinate.UNKNOWN_COORDINATE;
            } else {
                coordinate = new BundleCoordinate(bundleDTO.getGroup(), bundleDTO.getArtifact(), bundleDTO.getVersion());
            }
        }
        final ReportingTaskNode reportingTask = controller.createReportingTask(dto.getType(), dto.getId(), coordinate, false);
        reportingTask.setName(dto.getName());
        reportingTask.setComments(dto.getComments());
        reportingTask.setSchedulingPeriod(dto.getSchedulingPeriod());
        reportingTask.setSchedulingStrategy(SchedulingStrategy.valueOf(dto.getSchedulingStrategy()));
        reportingTask.setAnnotationData(dto.getAnnotationData());
        reportingTask.setProperties(dto.getProperties());
        final ComponentLog componentLog = new SimpleProcessLogger(dto.getId(), reportingTask.getReportingTask());
        final ReportingInitializationContext config = new StandardReportingInitializationContext(dto.getId(), dto.getName(), SchedulingStrategy.valueOf(dto.getSchedulingStrategy()), dto.getSchedulingPeriod(), componentLog, controller, nifiProperties, controller);
        try {
            reportingTask.getReportingTask().initialize(config);
        } catch (final InitializationException ie) {
            throw new ReportingTaskInstantiationException("Failed to initialize reporting task of type " + dto.getType(), ie);
        }
        return reportingTask;
    } else {
        // otherwise return the existing reporting task node
        return controller.getReportingTaskNode(dto.getId());
    }
}
Also used : ReportingTaskInstantiationException(org.apache.nifi.controller.reporting.ReportingTaskInstantiationException) ReportingInitializationContext(org.apache.nifi.reporting.ReportingInitializationContext) StandardReportingInitializationContext(org.apache.nifi.controller.reporting.StandardReportingInitializationContext) SimpleProcessLogger(org.apache.nifi.processor.SimpleProcessLogger) BundleDTO(org.apache.nifi.web.api.dto.BundleDTO) StandardReportingInitializationContext(org.apache.nifi.controller.reporting.StandardReportingInitializationContext) InitializationException(org.apache.nifi.reporting.InitializationException) BundleCoordinate(org.apache.nifi.bundle.BundleCoordinate) ComponentLog(org.apache.nifi.logging.ComponentLog)

Example 24 with InitializationException

use of org.apache.nifi.reporting.InitializationException in project nifi by apache.

the class CaptureChangeMySQL method registerDriver.

protected void registerDriver(String locationString, String drvName) throws InitializationException {
    if (locationString != null && locationString.length() > 0) {
        try {
            // Split and trim the entries
            final ClassLoader classLoader = ClassLoaderUtils.getCustomClassLoader(locationString, this.getClass().getClassLoader(), (dir, name) -> name != null && name.endsWith(".jar"));
            // Workaround which allows to use URLClassLoader for JDBC driver loading.
            // (Because the DriverManager will refuse to use a driver not loaded by the system ClassLoader.)
            final Class<?> clazz = Class.forName(drvName, true, classLoader);
            if (clazz == null) {
                throw new InitializationException("Can't load Database Driver " + drvName);
            }
            final Driver driver = (Driver) clazz.newInstance();
            DriverManager.registerDriver(new DriverShim(driver));
        } catch (final InitializationException e) {
            throw e;
        } catch (final MalformedURLException e) {
            throw new InitializationException("Invalid Database Driver Jar Url", e);
        } catch (final Exception e) {
            throw new InitializationException("Can't load Database Driver", e);
        }
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) Driver(java.sql.Driver) InitializationException(org.apache.nifi.reporting.InitializationException) InitializationException(org.apache.nifi.reporting.InitializationException) SQLFeatureNotSupportedException(java.sql.SQLFeatureNotSupportedException) TimeoutException(java.util.concurrent.TimeoutException) RowEventException(org.apache.nifi.cdc.event.RowEventException) CDCException(org.apache.nifi.cdc.CDCException) ProcessException(org.apache.nifi.processor.exception.ProcessException) SQLException(java.sql.SQLException) ConnectException(java.net.ConnectException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException)

Example 25 with InitializationException

use of org.apache.nifi.reporting.InitializationException in project nifi by apache.

the class ElasticSearchClientServiceImpl method setupClient.

private void setupClient(ConfigurationContext context) throws MalformedURLException, InitializationException {
    final String hosts = context.getProperty(HTTP_HOSTS).evaluateAttributeExpressions().getValue();
    String[] hostsSplit = hosts.split(",[\\s]*");
    this.url = hostsSplit[0];
    final SSLContextService sslService = context.getProperty(PROP_SSL_CONTEXT_SERVICE).asControllerService(SSLContextService.class);
    final String username = context.getProperty(USERNAME).evaluateAttributeExpressions().getValue();
    final String password = context.getProperty(PASSWORD).evaluateAttributeExpressions().getValue();
    final Integer connectTimeout = context.getProperty(CONNECT_TIMEOUT).asInteger();
    final Integer readTimeout = context.getProperty(SOCKET_TIMEOUT).asInteger();
    final Integer retryTimeout = context.getProperty(RETRY_TIMEOUT).asInteger();
    HttpHost[] hh = new HttpHost[hostsSplit.length];
    for (int x = 0; x < hh.length; x++) {
        URL u = new URL(hostsSplit[x]);
        hh[x] = new HttpHost(u.getHost(), u.getPort(), u.getProtocol());
    }
    final SSLContext sslContext;
    try {
        sslContext = (sslService != null && sslService.isKeyStoreConfigured() && sslService.isTrustStoreConfigured()) ? buildSslContext(sslService) : null;
    } catch (IOException | CertificateException | NoSuchAlgorithmException | UnrecoverableKeyException | KeyStoreException | KeyManagementException e) {
        getLogger().error("Error building up SSL Context from the supplied configuration.", e);
        throw new InitializationException(e);
    }
    RestClientBuilder builder = RestClient.builder(hh).setHttpClientConfigCallback(httpClientBuilder -> {
        if (sslContext != null) {
            httpClientBuilder = httpClientBuilder.setSSLContext(sslContext);
        }
        if (username != null && password != null) {
            final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
            credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(username, password));
            httpClientBuilder = httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider);
        }
        return httpClientBuilder;
    }).setRequestConfigCallback(requestConfigBuilder -> {
        requestConfigBuilder.setConnectTimeout(connectTimeout);
        requestConfigBuilder.setSocketTimeout(readTimeout);
        return requestConfigBuilder;
    }).setMaxRetryTimeoutMillis(retryTimeout);
    this.client = builder.build();
}
Also used : RestClient(org.elasticsearch.client.RestClient) SSLContext(javax.net.ssl.SSLContext) RestClientBuilder(org.elasticsearch.client.RestClientBuilder) ConfigurationContext(org.apache.nifi.controller.ConfigurationContext) InitializationException(org.apache.nifi.reporting.InitializationException) URL(java.net.URL) HashMap(java.util.HashMap) KeyStoreException(java.security.KeyStoreException) PropertyDescriptor(org.apache.nifi.components.PropertyDescriptor) ArrayList(java.util.ArrayList) SecureRandom(java.security.SecureRandom) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) Charset(java.nio.charset.Charset) UnrecoverableKeyException(java.security.UnrecoverableKeyException) Map(java.util.Map) AbstractControllerService(org.apache.nifi.controller.AbstractControllerService) NStringEntity(org.apache.http.nio.entity.NStringEntity) OnEnabled(org.apache.nifi.annotation.lifecycle.OnEnabled) TrustManagerFactory(javax.net.ssl.TrustManagerFactory) MalformedURLException(java.net.MalformedURLException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) HttpEntity(org.apache.http.HttpEntity) ContentType(org.apache.http.entity.ContentType) SSLContextService(org.apache.nifi.ssl.SSLContextService) KeyManagerFactory(javax.net.ssl.KeyManagerFactory) IOException(java.io.IOException) KeyStore(java.security.KeyStore) FileInputStream(java.io.FileInputStream) KeyManagementException(java.security.KeyManagementException) CertificateException(java.security.cert.CertificateException) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) AuthScope(org.apache.http.auth.AuthScope) Response(org.elasticsearch.client.Response) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) CredentialsProvider(org.apache.http.client.CredentialsProvider) HttpHost(org.apache.http.HttpHost) Collections(java.util.Collections) OnDisabled(org.apache.nifi.annotation.lifecycle.OnDisabled) InputStream(java.io.InputStream) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) RestClientBuilder(org.elasticsearch.client.RestClientBuilder) CertificateException(java.security.cert.CertificateException) SSLContext(javax.net.ssl.SSLContext) IOException(java.io.IOException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) KeyStoreException(java.security.KeyStoreException) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) CredentialsProvider(org.apache.http.client.CredentialsProvider) InitializationException(org.apache.nifi.reporting.InitializationException) URL(java.net.URL) KeyManagementException(java.security.KeyManagementException) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials) UnrecoverableKeyException(java.security.UnrecoverableKeyException) HttpHost(org.apache.http.HttpHost) SSLContextService(org.apache.nifi.ssl.SSLContextService)

Aggregations

InitializationException (org.apache.nifi.reporting.InitializationException)30 IOException (java.io.IOException)10 OnEnabled (org.apache.nifi.annotation.lifecycle.OnEnabled)7 MalformedURLException (java.net.MalformedURLException)6 PropertyDescriptor (org.apache.nifi.components.PropertyDescriptor)5 SSLContextService (org.apache.nifi.ssl.SSLContextService)5 SQLException (java.sql.SQLException)4 HashMap (java.util.HashMap)4 ProcessException (org.apache.nifi.processor.exception.ProcessException)4 StandardSSLContextService (org.apache.nifi.ssl.StandardSSLContextService)4 Test (org.junit.Test)4 ConnectException (java.net.ConnectException)3 KeyManagementException (java.security.KeyManagementException)3 KeyStoreException (java.security.KeyStoreException)3 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)3 UnrecoverableKeyException (java.security.UnrecoverableKeyException)3 CertificateException (java.security.cert.CertificateException)3 Driver (java.sql.Driver)3 ArrayList (java.util.ArrayList)3 MockRecordParser (org.apache.nifi.serialization.record.MockRecordParser)3