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