use of com.thinkbiganalytics.nifi.core.api.metadata.FeedIdNotFoundException in project kylo by Teradata.
the class LoadHighWaterMark method onTrigger.
/* (non-Javadoc)
* @see org.apache.nifi.processor.AbstractProcessor#onTrigger(org.apache.nifi.processor.ProcessContext, org.apache.nifi.processor.ProcessSession)
*/
@Override
public void onTrigger(ProcessContext context, ProcessSession session) throws ProcessException {
FlowFile inputFF = session.get();
FlowFile outputFF = inputFF;
boolean createdFlowfile = false;
// Create the flow file if we are the start of the flow.
if (outputFF == null && !context.hasNonLoopConnection()) {
outputFF = session.create();
createdFlowfile = true;
}
if (outputFF != null) {
try {
outputFF = initialize(context, session, outputFF);
} catch (FeedIdNotFoundException e) {
// Otherwise re-throw the exception.
if (createdFlowfile && outputFF.getAttribute(FEED_ID_ATTR) == null) {
getLog().debug("ID for feed was not available yet - yielding");
session.remove(outputFF);
context.yield();
return;
} else {
throw e;
}
}
MetadataRecorder recorder = context.getProperty(CommonProperties.METADATA_SERVICE).asControllerService(MetadataProviderService.class).getRecorder();
String waterMark = context.getProperty(HIGH_WATER_MARK).getValue();
String propName = context.getProperty(PROPERTY_NAME).getValue();
String initialValue = context.getProperty(INITIAL_VALUE).getValue();
try {
String feedId = getFeedId(context, outputFF);
try {
outputFF = recorder.loadWaterMark(session, outputFF, feedId, waterMark, propName, initialValue);
} catch (WaterMarkActiveException e) {
throw e;
} catch (Exception e) {
getLog().error("Failed to load the current high-water mark: {} for feed {}", new Object[] { waterMark, feedId }, e);
session.transfer(outputFF, CommonProperties.REL_FAILURE);
}
this.yieldCount.set(0);
session.transfer(outputFF, CommonProperties.REL_SUCCESS);
} catch (WaterMarkActiveException e) {
String activeStrategy = context.getProperty(ACTIVE_WATER_MARK_STRATEGY).getValue();
if ("ROUTE".equals(activeStrategy)) {
handleRouteOnActive(session, outputFF, waterMark);
} else {
PropertyValue value = context.getProperty(MAX_YIELD_COUNT);
int maxCount = value.isSet() ? value.asInteger() : Integer.MAX_VALUE - 1;
int count = this.yieldCount.incrementAndGet();
if (maxCount > 0 && count > maxCount) {
handleMaxYieldCount(context, session, recorder, outputFF, waterMark, propName, initialValue);
} else {
// If this processor created this flow file (1st processor in flow) then we will yield no matter what the strategy.
handleYieldOnActive(context, session, outputFF, createdFlowfile, activeStrategy, waterMark, count, maxCount);
}
}
}
}
}
Aggregations