Search in sources :

Example 1 with OnScheduled

use of org.apache.nifi.annotation.lifecycle.OnScheduled in project kylo by Teradata.

the class BeginFeed method ensureFeedMetadata.

@OnScheduled
public Feed ensureFeedMetadata(ProcessContext context) {
    MetadataProvider provider = getProviderService(context).getProvider();
    String feedName = context.getProperty(FEED_NAME).getValue();
    String categoryName = context.getProperty(CATEGORY_NAME).getValue();
    Feed feed = provider.ensureFeed(categoryName, feedName, "");
    // this.feedId.set(feed.getId());
    String datasourcesName = context.getProperty(SRC_DATASOURCES_NAME).getValue();
    if (!StringUtils.isEmpty(datasourcesName)) {
        String[] dsNameArr = datasourcesName.split("\\s*,\\s*");
        for (String dsName : dsNameArr) {
            setupSource(context, feed, dsName.trim());
        }
        ensurePreconditon(context, feed, dsNameArr);
        ensurePreconditonListener(context, feed, dsNameArr);
    }
    return feed;
}
Also used : MetadataProvider(com.thinkbiganalytics.nifi.core.api.metadata.MetadataProvider) Feed(com.thinkbiganalytics.metadata.rest.model.feed.Feed) OnScheduled(org.apache.nifi.annotation.lifecycle.OnScheduled)

Example 2 with OnScheduled

use of org.apache.nifi.annotation.lifecycle.OnScheduled in project kylo by Teradata.

the class GetFeedMetadata method onScheduled.

/**
 * Initializes resources required to trigger this processor.
 *
 * @param context the process context
 */
@OnScheduled
public void onScheduled(@Nonnull final ProcessContext context) {
    getLog().debug("Scheduled");
    TimeUnit timeUnit = TimeUnit.NANOSECONDS;
    Long nanos = context.getProperty(CACHE_EXPIRE_DURATION).asTimePeriod(timeUnit);
    cachedFeed = CacheBuilder.newBuilder().maximumSize(CACHE_SIZE).expireAfterWrite(nanos, timeUnit).build(new CacheLoader<FeedKey, String>() {

        public String load(@Nonnull FeedKey key) {
            return ObjectMapperSerializer.serialize(getMetadataService(context).getProvider().getFeed(key.categoryName, key.feedName));
        }
    });
}
Also used : Nonnull(javax.annotation.Nonnull) TimeUnit(java.util.concurrent.TimeUnit) CacheLoader(com.google.common.cache.CacheLoader) OnScheduled(org.apache.nifi.annotation.lifecycle.OnScheduled)

Example 3 with OnScheduled

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

the class QueryCassandra method onScheduled.

@OnScheduled
public void onScheduled(final ProcessContext context) {
    ComponentLog log = getLogger();
    try {
        connectToCassandra(context);
        final int fetchSize = context.getProperty(FETCH_SIZE).evaluateAttributeExpressions().asInteger();
        if (fetchSize > 0) {
            synchronized (cluster.get()) {
                cluster.get().getConfiguration().getQueryOptions().setFetchSize(fetchSize);
            }
        }
    } catch (final NoHostAvailableException nhae) {
        log.error("No host in the Cassandra cluster can be contacted successfully to execute this query", nhae);
        // Log up to 10 error messages. Otherwise if a 1000-node cluster was specified but there was no connectivity,
        // a thousand error messages would be logged. However we would like information from Cassandra itself, so
        // cap the error limit at 10, format the messages, and don't include the stack trace (it is displayed by the
        // logger message above).
        log.error(nhae.getCustomMessage(10, true, false));
        throw new ProcessException(nhae);
    } catch (final AuthenticationException ae) {
        log.error("Invalid username/password combination", ae);
        throw new ProcessException(ae);
    }
}
Also used : ProcessException(org.apache.nifi.processor.exception.ProcessException) NoHostAvailableException(com.datastax.driver.core.exceptions.NoHostAvailableException) AuthenticationException(com.datastax.driver.core.exceptions.AuthenticationException) ComponentLog(org.apache.nifi.logging.ComponentLog) OnScheduled(org.apache.nifi.annotation.lifecycle.OnScheduled)

Example 4 with OnScheduled

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

the class GetAzureEventHub method onScheduled.

@OnScheduled
public void onScheduled(final ProcessContext context) throws ProcessException, URISyntaxException {
    final BlockingQueue<String> partitionNames = new LinkedBlockingQueue<>();
    for (int i = 0; i < context.getProperty(NUM_PARTITIONS).asInteger(); i++) {
        partitionNames.add(String.valueOf(i));
    }
    this.partitionNames = partitionNames;
    final String policyName = context.getProperty(ACCESS_POLICY).getValue();
    final String policyKey = context.getProperty(POLICY_PRIMARY_KEY).getValue();
    final String namespace = context.getProperty(NAMESPACE).getValue();
    final String eventHubName = context.getProperty(EVENT_HUB_NAME).getValue();
    final String serviceBusEndpoint = context.getProperty(SERVICE_BUS_ENDPOINT).getValue();
    if (context.getProperty(ENQUEUE_TIME).isSet()) {
        configuredEnqueueTime = Instant.parse(context.getProperty(ENQUEUE_TIME).toString());
    } else {
        configuredEnqueueTime = null;
    }
    if (context.getProperty(RECEIVER_FETCH_SIZE).isSet()) {
        receiverFetchSize = context.getProperty(RECEIVER_FETCH_SIZE).asInteger();
    } else {
        receiverFetchSize = 100;
    }
    if (context.getProperty(RECEIVER_FETCH_TIMEOUT).isSet()) {
        receiverFetchTimeout = Duration.ofMillis(context.getProperty(RECEIVER_FETCH_TIMEOUT).asLong());
    } else {
        receiverFetchTimeout = null;
    }
    final String connectionString = new ConnectionStringBuilder(new URI("amqps://" + namespace + serviceBusEndpoint), eventHubName, policyName, policyKey).toString();
    setupReceiver(connectionString);
}
Also used : ConnectionStringBuilder(com.microsoft.azure.servicebus.ConnectionStringBuilder) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) URI(java.net.URI) OnScheduled(org.apache.nifi.annotation.lifecycle.OnScheduled)

Example 5 with OnScheduled

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

the class PutAzureEventHub method setupClient.

@OnScheduled
public final void setupClient(final ProcessContext context) throws ProcessException {
    final String policyName = context.getProperty(ACCESS_POLICY).getValue();
    final String policyKey = context.getProperty(POLICY_PRIMARY_KEY).getValue();
    final String namespace = context.getProperty(NAMESPACE).getValue();
    final String eventHubName = context.getProperty(EVENT_HUB_NAME).getValue();
    final int numThreads = context.getMaxConcurrentTasks();
    senderQueue = new LinkedBlockingQueue<>(numThreads);
    for (int i = 0; i < numThreads; i++) {
        final EventHubClient client = createEventHubClient(namespace, eventHubName, policyName, policyKey);
        if (null != client) {
            senderQueue.offer(client);
        }
    }
}
Also used : EventHubClient(com.microsoft.azure.eventhubs.EventHubClient) OnScheduled(org.apache.nifi.annotation.lifecycle.OnScheduled)

Aggregations

OnScheduled (org.apache.nifi.annotation.lifecycle.OnScheduled)59 PropertyDescriptor (org.apache.nifi.components.PropertyDescriptor)12 ProcessException (org.apache.nifi.processor.exception.ProcessException)12 IOException (java.io.IOException)10 HashMap (java.util.HashMap)10 ComponentLog (org.apache.nifi.logging.ComponentLog)8 SSLContextService (org.apache.nifi.ssl.SSLContextService)7 Map (java.util.Map)6 SSLContext (javax.net.ssl.SSLContext)6 StateMap (org.apache.nifi.components.state.StateMap)5 FileInputStream (java.io.FileInputStream)4 PropertyValue (org.apache.nifi.components.PropertyValue)4 RestrictedSSLContextService (org.apache.nifi.ssl.RestrictedSSLContextService)4 InetAddress (java.net.InetAddress)3 CacheLoader (com.google.common.cache.CacheLoader)2 SslContextBuilder (io.netty.handler.ssl.SslContextBuilder)2 File (java.io.File)2 InputStream (java.io.InputStream)2 InetSocketAddress (java.net.InetSocketAddress)2 NetworkInterface (java.net.NetworkInterface)2