Search in sources :

Example 6 with OnEnabled

use of org.apache.nifi.annotation.lifecycle.OnEnabled in project nifi by apache.

the class GraphiteMetricReporterService method onEnabled.

/**
 * Create the {@link #graphiteSender} according to configuration.
 *
 * @param context used to access properties.
 */
@OnEnabled
public void onEnabled(final ConfigurationContext context) {
    String host = context.getProperty(HOST).evaluateAttributeExpressions().getValue();
    int port = context.getProperty(PORT).evaluateAttributeExpressions().asInteger();
    Charset charset = Charset.forName(context.getProperty(CHARSET).getValue());
    graphiteSender = createSender(host, port, charset);
    metricNamePrefix = context.getProperty(METRIC_NAME_PREFIX).evaluateAttributeExpressions().getValue();
}
Also used : Charset(java.nio.charset.Charset) OnEnabled(org.apache.nifi.annotation.lifecycle.OnEnabled)

Example 7 with OnEnabled

use of org.apache.nifi.annotation.lifecycle.OnEnabled in project nifi by apache.

the class DBCPConnectionPool method onConfigured.

/**
 * Configures connection pool by creating an instance of the
 * {@link BasicDataSource} based on configuration provided with
 * {@link ConfigurationContext}.
 *
 * This operation makes no guarantees that the actual connection could be
 * made since the underlying system may still go off-line during normal
 * operation of the connection pool.
 *
 * @param context
 *            the configuration context
 * @throws InitializationException
 *             if unable to create a database connection
 */
@OnEnabled
public void onConfigured(final ConfigurationContext context) throws InitializationException {
    final String drv = context.getProperty(DB_DRIVERNAME).evaluateAttributeExpressions().getValue();
    final String user = context.getProperty(DB_USER).evaluateAttributeExpressions().getValue();
    final String passw = context.getProperty(DB_PASSWORD).evaluateAttributeExpressions().getValue();
    final Long maxWaitMillis = context.getProperty(MAX_WAIT_TIME).asTimePeriod(TimeUnit.MILLISECONDS);
    final Integer maxTotal = context.getProperty(MAX_TOTAL_CONNECTIONS).asInteger();
    final String validationQuery = context.getProperty(VALIDATION_QUERY).evaluateAttributeExpressions().getValue();
    dataSource = new BasicDataSource();
    dataSource.setDriverClassName(drv);
    // Optional driver URL, when exist, this URL will be used to locate driver jar file location
    final String urlString = context.getProperty(DB_DRIVER_LOCATION).evaluateAttributeExpressions().getValue();
    dataSource.setDriverClassLoader(getDriverClassLoader(urlString, drv));
    final String dburl = context.getProperty(DATABASE_URL).evaluateAttributeExpressions().getValue();
    dataSource.setMaxWait(maxWaitMillis);
    dataSource.setMaxActive(maxTotal);
    if (validationQuery != null && !validationQuery.isEmpty()) {
        dataSource.setValidationQuery(validationQuery);
        dataSource.setTestOnBorrow(true);
    }
    dataSource.setUrl(dburl);
    dataSource.setUsername(user);
    dataSource.setPassword(passw);
    context.getProperties().keySet().stream().filter(PropertyDescriptor::isDynamic).forEach((dynamicPropDescriptor) -> dataSource.addConnectionProperty(dynamicPropDescriptor.getName(), context.getProperty(dynamicPropDescriptor).evaluateAttributeExpressions().getValue()));
}
Also used : BasicDataSource(org.apache.commons.dbcp.BasicDataSource) OnEnabled(org.apache.nifi.annotation.lifecycle.OnEnabled)

Example 8 with OnEnabled

use of org.apache.nifi.annotation.lifecycle.OnEnabled in project nifi by apache.

the class HBase_1_1_2_ClientService method onEnabled.

/**
 * As of Apache NiFi 1.5.0, due to changes made to
 * {@link SecurityUtil#loginKerberos(Configuration, String, String)}, which is used by this
 * class to authenticate a principal with Kerberos, HBase controller services no longer
 * attempt relogins explicitly.  For more information, please read the documentation for
 * {@link SecurityUtil#loginKerberos(Configuration, String, String)}.
 * <p/>
 * In previous versions of NiFi, a {@link org.apache.nifi.hadoop.KerberosTicketRenewer} was started
 * when the HBase controller service was enabled.  The use of a separate thread to explicitly relogin could cause
 * race conditions with the implicit relogin attempts made by hadoop/HBase code on a thread that references the same
 * {@link UserGroupInformation} instance.  One of these threads could leave the
 * {@link javax.security.auth.Subject} in {@link UserGroupInformation} to be cleared or in an unexpected state
 * while the other thread is attempting to use the {@link javax.security.auth.Subject}, resulting in failed
 * authentication attempts that would leave the HBase controller service in an unrecoverable state.
 *
 * @see SecurityUtil#loginKerberos(Configuration, String, String)
 */
@OnEnabled
public void onEnabled(final ConfigurationContext context) throws InitializationException, IOException, InterruptedException {
    this.connection = createConnection(context);
    // connection check
    if (this.connection != null) {
        final Admin admin = this.connection.getAdmin();
        if (admin != null) {
            admin.listTableNames();
            masterAddress = admin.getClusterStatus().getMaster().getHostAndPort();
        }
    }
}
Also used : Admin(org.apache.hadoop.hbase.client.Admin) OnEnabled(org.apache.nifi.annotation.lifecycle.OnEnabled)

Example 9 with OnEnabled

use of org.apache.nifi.annotation.lifecycle.OnEnabled in project nifi by apache.

the class JettyWebSocketClient method startClient.

@OnEnabled
@Override
public void startClient(final ConfigurationContext context) throws Exception {
    final SSLContextService sslService = context.getProperty(SSL_CONTEXT).asControllerService(SSLContextService.class);
    SslContextFactory sslContextFactory = null;
    if (sslService != null) {
        sslContextFactory = createSslFactory(sslService, false, false);
    }
    client = new WebSocketClient(sslContextFactory);
    configurePolicy(context, client.getPolicy());
    client.start();
    activeSessions.clear();
    webSocketUri = new URI(context.getProperty(WS_URI).getValue());
    connectionTimeoutMillis = context.getProperty(CONNECTION_TIMEOUT).asTimePeriod(TimeUnit.MILLISECONDS);
    final Long sessionMaintenanceInterval = context.getProperty(SESSION_MAINTENANCE_INTERVAL).asTimePeriod(TimeUnit.MILLISECONDS);
    sessionMaintenanceScheduler = Executors.newSingleThreadScheduledExecutor();
    sessionMaintenanceScheduler.scheduleAtFixedRate(() -> {
        try {
            maintainSessions();
        } catch (final Exception e) {
            getLogger().warn("Failed to maintain sessions due to {}", new Object[] { e }, e);
        }
    }, sessionMaintenanceInterval, sessionMaintenanceInterval, TimeUnit.MILLISECONDS);
}
Also used : SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) SSLContextService(org.apache.nifi.ssl.SSLContextService) WebSocketClient(org.eclipse.jetty.websocket.client.WebSocketClient) URI(java.net.URI) WebSocketConfigurationException(org.apache.nifi.websocket.WebSocketConfigurationException) IOException(java.io.IOException) OnEnabled(org.apache.nifi.annotation.lifecycle.OnEnabled)

Example 10 with OnEnabled

use of org.apache.nifi.annotation.lifecycle.OnEnabled in project nifi by apache.

the class JettyWebSocketServer method startServer.

@OnEnabled
@Override
public void startServer(final ConfigurationContext context) throws Exception {
    if (server != null && server.isRunning()) {
        getLogger().info("A WebSocket server is already running. {}", new Object[] { server });
        return;
    }
    configuredPolicy = WebSocketPolicy.newServerPolicy();
    configurePolicy(context, configuredPolicy);
    server = new Server();
    final ContextHandlerCollection handlerCollection = new ContextHandlerCollection();
    final ServletContextHandler contextHandler = new ServletContextHandler();
    servletHandler = new ServletHandler();
    contextHandler.insertHandler(servletHandler);
    handlerCollection.setHandlers(new Handler[] { contextHandler });
    server.setHandler(handlerCollection);
    listenPort = context.getProperty(LISTEN_PORT).asInteger();
    final SslContextFactory sslContextFactory = createSslFactory(context);
    final ServerConnector serverConnector = createConnector(sslContextFactory, listenPort);
    server.setConnectors(new Connector[] { serverConnector });
    servletHandler.addServletWithMapping(JettyWebSocketServlet.class, "/*");
    getLogger().info("Starting JettyWebSocketServer on port {}.", new Object[] { listenPort });
    server.start();
    portToControllerService.put(listenPort, this);
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) ServletHandler(org.eclipse.jetty.servlet.ServletHandler) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) Server(org.eclipse.jetty.server.Server) ContextHandlerCollection(org.eclipse.jetty.server.handler.ContextHandlerCollection) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) OnEnabled(org.apache.nifi.annotation.lifecycle.OnEnabled)

Aggregations

OnEnabled (org.apache.nifi.annotation.lifecycle.OnEnabled)24 InitializationException (org.apache.nifi.reporting.InitializationException)7 PropertyDescriptor (org.apache.nifi.components.PropertyDescriptor)4 ComponentLog (org.apache.nifi.logging.ComponentLog)4 SSLContextService (org.apache.nifi.ssl.SSLContextService)4 IOException (java.io.IOException)3 File (java.io.File)2 URI (java.net.URI)2 Map (java.util.Map)2 SSLContext (javax.net.ssl.SSLContext)2 BasicDataSource (org.apache.commons.dbcp.BasicDataSource)2 ProcessException (org.apache.nifi.processor.exception.ProcessException)2 LastModifiedMonitor (org.apache.nifi.util.file.monitor.LastModifiedMonitor)2 SynchronousFileWatcher (org.apache.nifi.util.file.monitor.SynchronousFileWatcher)2 SslContextFactory (org.eclipse.jetty.util.ssl.SslContextFactory)2 CouchbaseException (com.couchbase.client.core.CouchbaseException)1 JsonPath (com.jayway.jsonpath.JsonPath)1 Timestamper (com.metamx.tranquility.typeclass.Timestamper)1 MetadataClient (com.thinkbiganalytics.metadata.rest.client.MetadataClient)1 SpringContextService (com.thinkbiganalytics.nifi.core.api.spring.SpringContextService)1