Search in sources :

Example 1 with InitializationException

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

the class ExtensionManager method initializeTempComponent.

private static void initializeTempComponent(final ConfigurableComponent configurableComponent) {
    ConfigurableComponentInitializer initializer = null;
    try {
        initializer = ConfigurableComponentInitializerFactory.createComponentInitializer(configurableComponent.getClass());
        initializer.initialize(configurableComponent);
    } catch (final InitializationException e) {
        logger.warn(String.format("Unable to initialize component %s due to %s", configurableComponent.getClass().getName(), e.getMessage()));
    }
}
Also used : InitializationException(org.apache.nifi.reporting.InitializationException) ConfigurableComponentInitializer(org.apache.nifi.init.ConfigurableComponentInitializer)

Example 2 with InitializationException

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

the class CaptureChangeMySQL method connect.

protected void connect(List<InetSocketAddress> hosts, String username, String password, Long serverId, boolean createEnrichmentConnection, String driverLocation, String driverName, long connectTimeout) throws IOException {
    int connectionAttempts = 0;
    final int numHosts = hosts.size();
    InetSocketAddress connectedHost = null;
    Exception lastConnectException = new Exception("Unknown connection error");
    if (createEnrichmentConnection) {
        try {
            // Ensure driverLocation and driverName are correct before establishing binlog connection
            // to avoid failing after binlog messages are received.
            // Actual JDBC connection is created after binlog client gets started, because we need
            // the connect-able host same as the binlog client.
            registerDriver(driverLocation, driverName);
        } catch (InitializationException e) {
            throw new RuntimeException("Failed to register JDBC driver. Ensure MySQL Driver Location(s)" + " and MySQL Driver Class Name are configured correctly. " + e, e);
        }
    }
    while (connectedHost == null && connectionAttempts < numHosts) {
        if (binlogClient == null) {
            connectedHost = hosts.get(currentHost);
            binlogClient = createBinlogClient(connectedHost.getHostString(), connectedHost.getPort(), username, password);
        }
        // Add an event listener and lifecycle listener for binlog and client events, respectively
        if (eventListener == null) {
            eventListener = createBinlogEventListener(binlogClient, queue);
        }
        eventListener.start();
        binlogClient.registerEventListener(eventListener);
        if (lifecycleListener == null) {
            lifecycleListener = createBinlogLifecycleListener();
        }
        binlogClient.registerLifecycleListener(lifecycleListener);
        binlogClient.setBinlogFilename(currentBinlogFile);
        if (currentBinlogPosition != DO_NOT_SET) {
            binlogClient.setBinlogPosition(currentBinlogPosition);
        }
        if (serverId != null) {
            binlogClient.setServerId(serverId);
        }
        try {
            if (connectTimeout == 0) {
                connectTimeout = Long.MAX_VALUE;
            }
            binlogClient.connect(connectTimeout);
            transitUri = "mysql://" + connectedHost.getHostString() + ":" + connectedHost.getPort();
        } catch (IOException | TimeoutException te) {
            // Try the next host
            connectedHost = null;
            transitUri = "<unknown>";
            currentHost = (currentHost + 1) % numHosts;
            connectionAttempts++;
            lastConnectException = te;
        }
    }
    if (!binlogClient.isConnected()) {
        binlogClient.disconnect();
        binlogClient = null;
        throw new IOException("Could not connect binlog client to any of the specified hosts due to: " + lastConnectException.getMessage(), lastConnectException);
    }
    if (createEnrichmentConnection) {
        try {
            jdbcConnection = getJdbcConnection(driverLocation, driverName, connectedHost, username, password, null);
        } catch (InitializationException | SQLException e) {
            binlogClient.disconnect();
            binlogClient = null;
            throw new IOException("Error creating binlog enrichment JDBC connection to any of the specified hosts", e);
        }
    }
    doStop.set(false);
}
Also used : SQLException(java.sql.SQLException) InetSocketAddress(java.net.InetSocketAddress) IOException(java.io.IOException) 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) TimeoutException(java.util.concurrent.TimeoutException)

Example 3 with InitializationException

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

the class CouchbaseClusterService method onConfigured.

/**
 * Establish a connection to a Couchbase cluster.
 * @param context the configuration context
 * @throws InitializationException if unable to connect a Couchbase cluster
 */
@OnEnabled
public void onConfigured(final ConfigurationContext context) throws InitializationException {
    for (PropertyDescriptor p : context.getProperties().keySet()) {
        if (p.isDynamic() && p.getName().startsWith(DYNAMIC_PROP_BUCKET_PASSWORD)) {
            String bucketName = p.getName().substring(DYNAMIC_PROP_BUCKET_PASSWORD.length());
            String password = context.getProperty(p).getValue();
            bucketPasswords.put(bucketName, password);
        }
    }
    try {
        cluster = CouchbaseCluster.fromConnectionString(context.getProperty(CONNECTION_STRING).getValue());
    } catch (CouchbaseException e) {
        throw new InitializationException(e);
    }
}
Also used : CouchbaseException(com.couchbase.client.core.CouchbaseException) PropertyDescriptor(org.apache.nifi.components.PropertyDescriptor) InitializationException(org.apache.nifi.reporting.InitializationException) OnEnabled(org.apache.nifi.annotation.lifecycle.OnEnabled)

Example 4 with InitializationException

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

the class ElasticSearchClientServiceImpl method onEnabled.

@OnEnabled
public void onEnabled(final ConfigurationContext context) throws InitializationException {
    try {
        setupClient(context);
        charset = Charset.forName(context.getProperty(CHARSET).getValue());
    } catch (Exception ex) {
        getLogger().error("Could not initialize ElasticSearch client.", ex);
        throw new InitializationException(ex);
    }
}
Also used : InitializationException(org.apache.nifi.reporting.InitializationException) InitializationException(org.apache.nifi.reporting.InitializationException) KeyStoreException(java.security.KeyStoreException) UnrecoverableKeyException(java.security.UnrecoverableKeyException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) KeyManagementException(java.security.KeyManagementException) CertificateException(java.security.cert.CertificateException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) OnEnabled(org.apache.nifi.annotation.lifecycle.OnEnabled)

Example 5 with InitializationException

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

the class TestPutElasticsearchHttpRecord method generateTestData.

private void generateTestData() throws IOException {
    final MockRecordParser parser = new MockRecordParser();
    try {
        runner.addControllerService("parser", parser);
    } catch (InitializationException e) {
        throw new IOException(e);
    }
    runner.enableControllerService(parser);
    runner.setProperty(PutElasticsearchHttpRecord.RECORD_READER, "parser");
    parser.addSchemaField("id", RecordFieldType.INT);
    parser.addSchemaField("name", RecordFieldType.STRING);
    parser.addSchemaField("code", RecordFieldType.INT);
    parser.addRecord(1, "rec1", 101);
    parser.addRecord(2, "rec2", 102);
    parser.addRecord(3, "rec3", 103);
    parser.addRecord(4, "rec4", 104);
}
Also used : IOException(java.io.IOException) InitializationException(org.apache.nifi.reporting.InitializationException) MockRecordParser(org.apache.nifi.serialization.record.MockRecordParser)

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