private void verifyFlowFileKnown(final FlowFile flowFile) { if (session != null && !session.isFlowFileKnown(flowFile)) { throw new FlowFileHandlingException(flowFile + " is not known to " + session); } }
private void verifyFlowFileKnown(final FlowFile flowFile) { if (session != null && !session.isFlowFileKnown(flowFile)) { throw new FlowFileHandlingException(flowFile + " is not known to " + session); } }
private void closeStreams(final Map<FlowFile, ? extends Closeable> streamMap, final boolean enforceClosed) { final Map<FlowFile, ? extends Closeable> openStreamCopy = new HashMap<>(streamMap); // avoid ConcurrentModificationException by creating a copy of the List for (final Map.Entry<FlowFile, ? extends Closeable> entry : openStreamCopy.entrySet()) { final FlowFile flowFile = entry.getKey(); final Closeable openStream = entry.getValue(); try { openStream.close(); } catch (IOException e) { throw new FlowFileAccessException("Failed to close stream for " + flowFile, e); } if (enforceClosed) { throw new FlowFileHandlingException("Cannot commit session because the following streams were created via " + "calls to ProcessSession.read(FlowFile) or ProcessSession.write(FlowFile) and never closed: " + streamMap); } } }
private MockFlowFile validateState(final FlowFile flowFile) { Objects.requireNonNull(flowFile); final MockFlowFile currentVersion = currentVersions.get(flowFile.getId()); if (currentVersion == null) { throw new FlowFileHandlingException(flowFile + " is not known in this session"); } if (readRecursionSet.containsKey(flowFile)) { throw new IllegalStateException(flowFile + " already in use for an active callback or InputStream created by ProcessSession.read(FlowFile) has not been closed"); } if (writeRecursionSet.contains(flowFile)) { throw new IllegalStateException(flowFile + " already in use for an active callback or OutputStream created by ProcessSession.write(FlowFile) has not been closed"); } for (final List<MockFlowFile> flowFiles : transferMap.values()) { if (flowFiles.contains(flowFile)) { throw new IllegalStateException(flowFile + " has already been transferred"); } } return currentVersion; }
@Override public void commit() { if (!beingProcessed.isEmpty()) { throw new FlowFileHandlingException("Cannot commit session because the following FlowFiles have not been removed or transferred: " + beingProcessed); } closeStreams(openInputStreams, enforceStreamsClosed); closeStreams(openOutputStreams, enforceStreamsClosed); committed = true; beingProcessed.clear(); currentVersions.clear(); originalVersions.clear(); for (final Map.Entry<String, Long> entry : counterMap.entrySet()) { sharedState.adjustCounter(entry.getKey(), entry.getValue()); } sharedState.addProvenanceEvents(provenanceReporter.getEvents()); counterMap.clear(); }
private FlowFile validateRecordState(final FlowFile flowFile, final boolean allowRecursiveRead) { if (!allowRecursiveRead && readRecursionSet.containsKey(flowFile)) { throw new IllegalStateException(flowFile + " already in use for an active callback or an InputStream created by ProcessSession.read(FlowFile) has not been closed"); } if (writeRecursionSet.contains(flowFile)) { throw new IllegalStateException(flowFile + " already in use for an active callback or an OutputStream created by ProcessSession.write(FlowFile) has not been closed"); } final StandardRepositoryRecord record = getRecord(flowFile); if (record == null) { rollback(); throw new FlowFileHandlingException(flowFile + " is not known in this session (" + toString() + ")"); } if (record.getTransferRelationship() != null) { rollback(); throw new FlowFileHandlingException(flowFile + " is already marked for transfer"); } if (record.isMarkedForDelete()) { rollback(); throw new FlowFileHandlingException(flowFile + " has already been marked for removal"); } return record.getCurrent(); }
@Override public MockFlowFile clone(FlowFile flowFile, final long offset, final long size) { flowFile = validateState(flowFile); if (offset + size > flowFile.getSize()) { throw new FlowFileHandlingException("Specified offset of " + offset + " and size " + size + " exceeds size of " + flowFile.toString()); } final MockFlowFile newFlowFile = new MockFlowFile(sharedState.nextFlowFileId(), flowFile); final byte[] newContent = Arrays.copyOfRange(((MockFlowFile) flowFile).getData(), (int) offset, (int) (offset + size)); newFlowFile.setData(newContent); currentVersions.put(newFlowFile.getId(), newFlowFile); beingProcessed.add(newFlowFile.getId()); return newFlowFile; }
throw new FlowFileHandlingException(flowFile + " is not known in this session");
throw new FlowFileHandlingException(flowFile + " is not known in this session (" + toString() + ")");
if (relationship == null) { rollback(); throw new FlowFileHandlingException(record.getCurrent() + " transfer relationship not specified"); if (relationship != Relationship.SELF) { rollback(); throw new FlowFileHandlingException(relationship + " does not have any destinations for " + context.getConnectable());
@Override public FlowFile clone(FlowFile example, final long offset, final long size) { verifyTaskActive(); example = validateRecordState(example); final StandardRepositoryRecord exampleRepoRecord = getRecord(example); final FlowFileRecord currRec = exampleRepoRecord.getCurrent(); final ContentClaim claim = exampleRepoRecord.getCurrentClaim(); if (offset + size > example.getSize()) { throw new FlowFileHandlingException("Specified offset of " + offset + " and size " + size + " exceeds size of " + example.toString()); } final StandardFlowFileRecord.Builder builder = new StandardFlowFileRecord.Builder().fromFlowFile(currRec); builder.id(context.getNextFlowFileSequence()); builder.contentClaimOffset(currRec.getContentClaimOffset() + offset); builder.size(size); final String newUuid = UUID.randomUUID().toString(); builder.addAttribute(CoreAttributes.UUID.key(), newUuid); final FlowFileRecord clone = builder.build(); if (claim != null) { context.getContentRepository().incrementClaimaintCount(claim); } final StandardRepositoryRecord record = new StandardRepositoryRecord(null); record.setWorking(clone, clone.getAttributes()); records.put(clone.getId(), record); if (offset == 0L && size == example.getSize()) { provenanceReporter.clone(example, clone); } else { registerForkEvent(example, clone); } return clone; }
throw new FlowFileHandlingException(flowFile + " is not known in this session (" + toString() + ")");
private void verifyFlowFileKnown(final FlowFile flowFile) { if (session != null && !session.isFlowFileKnown(flowFile)) { throw new FlowFileHandlingException(flowFile + " is not known to " + session); } }
private void closeStreams(final Map<FlowFile, ? extends Closeable> streamMap, final boolean enforceClosed) { final Map<FlowFile, ? extends Closeable> openStreamCopy = new HashMap<>(streamMap); // avoid ConcurrentModificationException by creating a copy of the List for (final Map.Entry<FlowFile, ? extends Closeable> entry : openStreamCopy.entrySet()) { final FlowFile flowFile = entry.getKey(); final Closeable openStream = entry.getValue(); try { openStream.close(); } catch (IOException e) { throw new FlowFileAccessException("Failed to close stream for " + flowFile, e); } if (enforceClosed) { throw new FlowFileHandlingException("Cannot commit session because the following streams were created via " + "calls to ProcessSession.read(FlowFile) or ProcessSession.write(FlowFile) and never closed: " + streamMap); } } }
private MockFlowFile validateState(final FlowFile flowFile) { Objects.requireNonNull(flowFile); final MockFlowFile currentVersion = currentVersions.get(flowFile.getId()); if (currentVersion == null) { throw new FlowFileHandlingException(flowFile + " is not known in this session"); } if (readRecursionSet.containsKey(flowFile)) { throw new IllegalStateException(flowFile + " already in use for an active callback or InputStream created by ProcessSession.read(FlowFile) has not been closed"); } if (writeRecursionSet.contains(flowFile)) { throw new IllegalStateException(flowFile + " already in use for an active callback or OutputStream created by ProcessSession.write(FlowFile) has not been closed"); } for (final List<MockFlowFile> flowFiles : transferMap.values()) { if (flowFiles.contains(flowFile)) { throw new IllegalStateException(flowFile + " has already been transferred"); } } return currentVersion; }
@Override public void commit() { if (!beingProcessed.isEmpty()) { throw new FlowFileHandlingException("Cannot commit session because the following FlowFiles have not been removed or transferred: " + beingProcessed); } closeStreams(openInputStreams, enforceStreamsClosed); closeStreams(openOutputStreams, enforceStreamsClosed); committed = true; beingProcessed.clear(); currentVersions.clear(); originalVersions.clear(); for (final Map.Entry<String, Long> entry : counterMap.entrySet()) { sharedState.adjustCounter(entry.getKey(), entry.getValue()); } sharedState.addProvenanceEvents(provenanceReporter.getEvents()); counterMap.clear(); }
@Override public MockFlowFile clone(FlowFile flowFile, final long offset, final long size) { flowFile = validateState(flowFile); if (offset + size > flowFile.getSize()) { throw new FlowFileHandlingException("Specified offset of " + offset + " and size " + size + " exceeds size of " + flowFile.toString()); } final MockFlowFile newFlowFile = new MockFlowFile(sharedState.nextFlowFileId(), flowFile); final byte[] newContent = Arrays.copyOfRange(((MockFlowFile) flowFile).getData(), (int) offset, (int) (offset + size)); newFlowFile.setData(newContent); currentVersions.put(newFlowFile.getId(), newFlowFile); beingProcessed.add(newFlowFile.getId()); return newFlowFile; }
throw new FlowFileHandlingException(flowFile + " is not known in this session");