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()));
}
}
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);
}
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);
}
}
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);
}
}
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);
}
Aggregations