private static FlowFile penalize(final ProcessContext context, final ProcessSession session, final FlowFile flowFile, final ErrorTypes.Penalty penalty) { switch (penalty) { case Penalize: return session.penalize(flowFile); case Yield: context.yield(); } return flowFile; }
/** * Sets a penalty for the given FlowFile which will make it unavailable to * be operated on any further during the penalty period. * * @param flowFile to penalize * @return FlowFile the new FlowFile reference to use * @throws IllegalStateException if detected that this method is being called from within a callback of another method in this session and for the given FlowFile(s) * @throws FlowFileHandlingException if the given FlowFile is already transferred or removed or doesn't belong to this session. Automatic rollback will occur. * @throws NullPointerException if the argument null */ @Override public SessionFile penalize(FlowFile flowFile) { SessionFile sf = wrap(flowFile); sf.flowFile = onMod(s.penalize(sf.flowFile)); return sf; }
/** * event handler method to perform the required actions when a failure has occurred. The FlowFile is penalized, forwarded to the failure relationship and the context is yielded. * * @param context * - the current process context. * * @param session * - the current process session. * @param flowFile * - the FlowFile that has failed to have been processed. */ protected void onFailure(final ProcessContext context, final ProcessSession session, final FlowFile flowFile) { session.transfer(session.penalize(flowFile), REL_FAILURE); session.commit(); context.yield(); }
/** * Event handler method to perform the required actions when a failure has occurred. The FlowFile is penalized, forwarded to the failure relationship and the context is yielded. * * @param context * - the current process context. * * @param session * - the current process session. * @param flowFile * - the FlowFile that has failed to have been processed. */ protected void onFailure(final ProcessContext context, final ProcessSession session, final FlowFile flowFile) { session.transfer(session.penalize(flowFile), REL_FAILURE); session.commit(); context.yield(); }
private void failFlowWithBlankEvaluatedProperty(ProcessSession session, FlowFile flowFile, PropertyDescriptor pd) { getLogger().error("{} value is blank after attribute expression language evaluation", new Object[]{pd.getName()}); flowFile = session.penalize(flowFile); session.transfer(flowFile, REL_FAILURE); }
final FlowFile penalizedFlowFile = session.penalize(flowFile); session.transfer(penalizedFlowFile, REL_FAILURE); session.commit();
session.transfer(child, relationship); } else { child = session.penalize(child); session.transfer(child, relationship);
} catch (URISyntaxException | StorageException e) { getLogger().error("Failed to write the message to Azure Queue Storage due to {}", new Object[]{e}); flowFile = session.penalize(flowFile); session.transfer(flowFile, REL_FAILURE); return;
final List<FlowFile> penalizedFlowFiles = new ArrayList<>(); for (final FlowFile flowFile : flowFiles) { penalizedFlowFiles.add(session.penalize(flowFile));
/** * transfers all input files to relationship and drops other files. * * @param r where to transfer flow files, when null then transfers to input with penalize. * @param t the cause why we do this transfer, when relationship specified then additional properties populated: ERROR_MESSAGE and ERROR_STACKTRACE. */ public void revertReceivedTo(Relationship r, Throwable t) { for (FlowFile f : toDrop.values()) { s.remove(f); } String errorMessage = Throwables.getMessage(t, null, 950); String stackTrace = Throwables.stringStackTrace(t); for (FlowFile f : toFail) { if (t != null && r != null) { f = s.putAttribute(f, ERROR_MESSAGE, errorMessage); f = s.putAttribute(f, ERROR_STACKTRACE, stackTrace); } if (r != null) { s.transfer(f, r); } else { f = s.penalize(f); s.transfer(f); } } s.commit(); onClear(); } /*============================================= NATIVE METHODS ================================================*/
} catch (final Exception e) { getLogger().error("Failed to send messages to Amazon SQS due to {}; routing to failure", new Object[]{e}); flowFile = session.penalize(flowFile); session.transfer(flowFile, REL_FAILURE); return;
} catch (Exception e) { getLogger().error(e.getMessage(), e); flowFile = session.penalize(flowFile); session.transfer(flowFile, REL_FAILURE); return;
} catch (ProcessException e) { logger.error("Failed to extract media metadata from {} due to {}", new Object[]{flowFile, e}); flowFile = session.penalize(flowFile); session.transfer(flowFile, FAILURE);
} catch ( StorageException | URISyntaxException e) { getLogger().error("Failed to delete the specified blob {} from Azure Storage. Routing to failure", new Object[]{blobPath}, e); flowFile = session.penalize(flowFile); session.transfer(flowFile, REL_FAILURE);
/** * */ private void sendToSpring(FlowFile flowFileToProcess, ProcessContext context, ProcessSession processSession) { byte[] payload = this.extractMessage(flowFileToProcess, processSession); boolean sent = false; try { sent = this.exchanger.send(payload, flowFileToProcess.getAttributes(), this.sendTimeout); if (sent) { processSession.getProvenanceReporter().send(flowFileToProcess, this.applicationContextConfigFileName); processSession.remove(flowFileToProcess); } else { processSession.transfer(processSession.penalize(flowFileToProcess), REL_FAILURE); this.getLogger().error("Timed out while sending FlowFile to Spring Application Context " + this.applicationContextConfigFileName); context.yield(); } } catch (Exception e) { processSession.transfer(flowFileToProcess, REL_FAILURE); this.getLogger().error("Failed while sending FlowFile to Spring Application Context " + this.applicationContextConfigFileName + "; " + e.getMessage(), e); context.yield(); } }
flowFile = session.penalize(flowFile); session.transfer(flowFile, REL_FAILURE); return;
session.getProvenanceReporter().send(flowFile, connection.toString() + "/E:" + exchange + "/RK:" + routingKey); } catch (Exception e) { session.transfer(session.penalize(flowFile), REL_FAILURE); getLogger().error("Failed while sending message to AMQP via " + publisher, e);
/** * Will rendezvous with Kafka if {@link ProcessSession} contains {@link FlowFile} * producing a result {@link FlowFile}. * <br> * The result {@link FlowFile} that is successful is then transferred to {@link #REL_SUCCESS} * <br> * The result {@link FlowFile} that is failed is then transferred to {@link #REL_FAILURE} * */ @Override protected boolean rendezvousWithKafka(ProcessContext context, ProcessSession session) throws ProcessException { boolean processed = false; FlowFile flowFile = session.get(); if (flowFile != null) { flowFile = this.doRendezvousWithKafka(flowFile, context, session); if (!this.isFailedFlowFile(flowFile)) { session.getProvenanceReporter().send(flowFile, context.getProperty(SEED_BROKERS).evaluateAttributeExpressions(flowFile).getValue() + "/" + context.getProperty(TOPIC).evaluateAttributeExpressions(flowFile).getValue()); session.transfer(flowFile, REL_SUCCESS); } else { session.transfer(session.penalize(flowFile), REL_FAILURE); } processed = true; } return processed; }
@Override public void onTrigger(final ProcessContext context, final ProcessSession session) throws ProcessException { FlowFile flowFile = session.get(); if (flowFile == null) { return; } final StopWatch stopWatch = new StopWatch(true); final byte[] buffer = new byte[(int) flowFile.getSize()]; session.read(flowFile, in -> StreamUtils.fillBuffer(in, buffer)); try { sendMessage(buffer); } catch (final ProcessException processException) { getLogger().error("Failed to send {} to EventHub due to {}; routing to failure", new Object[]{flowFile, processException}, processException); session.transfer(session.penalize(flowFile), REL_FAILURE); return; } final String namespace = context.getProperty(NAMESPACE).getValue(); final String eventHubName = context.getProperty(EVENT_HUB_NAME).getValue(); session.getProvenanceReporter().send(flowFile, "amqps://" + namespace + ".servicebus.windows.net" + "/" + eventHubName, stopWatch.getElapsed(TimeUnit.MILLISECONDS)); session.transfer(flowFile, REL_SUCCESS); }