@Override public long getId() { return flowFile.getId(); }
@Override public boolean equals(final Object obj) { if (obj == null) { return false; } if (obj == this) { return true; } if (obj instanceof FlowFile) { return ((FlowFile) obj).getId() == this.id; } return false; }
/** * Checks if a FlowFile is known in this session. * * @param flowFile the FlowFile to check * @return <code>true</code> if the FlowFile is known in this session, * <code>false</code> otherwise. */ boolean isFlowFileKnown(final FlowFile flowFile) { return records.containsKey(flowFile.getId()); }
private StandardRepositoryRecord getRecord(final FlowFile flowFile) { return records.get(flowFile.getId()); }
private StandardRepositoryRecord getRecord(final FlowFile flowFile) { return records.get(flowFile.getId()); } }
@Override public boolean equals(final Object other) { if (this == other) { return true; } if (!(other instanceof FlowFile)) { return false; } final FlowFile otherRecord = (FlowFile) other; return new EqualsBuilder().append(id, otherRecord.getId()).isEquals(); }
@Override public void transfer(FlowFile flowFile) { flowFile = validateState(flowFile); if (!(flowFile instanceof MockFlowFile)) { throw new IllegalArgumentException("I only accept MockFlowFile"); } // if the flowfile provided was created in this session (i.e. it's in currentVersions and not in original versions), // then throw an exception indicating that you can't transfer flowfiles back to self. // this mimics the same behavior in StandardProcessSession if(currentVersions.get(flowFile.getId()) != null && originalVersions.get(flowFile.getId()) == null) { throw new IllegalArgumentException("Cannot transfer FlowFiles that are created in this Session back to self"); } final MockFlowFile mockFlowFile = (MockFlowFile) flowFile; beingProcessed.remove(flowFile.getId()); processorQueue.offer(mockFlowFile); updateLastQueuedDate(mockFlowFile); }
static final Map<String, String> extractFlowFileProperties(final FlowFile flowFile) { final Map<String, String> flowFileProps = new HashMap<>(); flowFileProps.put("flowFileId", String.valueOf(flowFile.getId())); flowFileProps.put("fileSize", String.valueOf(flowFile.getSize())); flowFileProps.put("entryDate", String.valueOf(flowFile.getEntryDate())); flowFileProps.put("lineageStartDate", String.valueOf(flowFile.getLineageStartDate())); flowFileProps.put("lastQueueDate", String.valueOf(flowFile.getLastQueueDate())); flowFileProps.put("queueDateIndex", String.valueOf(flowFile.getQueueDateIndex())); return flowFileProps; }
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 remove(FlowFile flowFile) { flowFile = validateState(flowFile); final Iterator<MockFlowFile> penalizedItr = penalized.iterator(); while (penalizedItr.hasNext()) { final MockFlowFile ff = penalizedItr.next(); if (Objects.equals(ff.getId(), flowFile.getId())) { penalizedItr.remove(); penalized.remove(ff); break; } } final Iterator<Long> processedItr = beingProcessed.iterator(); while (processedItr.hasNext()) { final Long ffId = processedItr.next(); if (ffId != null && ffId.equals(flowFile.getId())) { processedItr.remove(); beingProcessed.remove(ffId); removedFlowFiles.add(flowFile.getId()); currentVersions.remove(ffId); return; } } throw new ProcessException(flowFile + " not found in queue"); }
@Override public Map<String, String> getHeaders() { synchronized (headers) { if (!headersLoaded) { headers.putAll(flowFile.getAttributes()); headers.put(ENTRY_DATE_HEADER, Long.toString(flowFile.getEntryDate())); headers.put(ID_HEADER, Long.toString(flowFile.getId())); headers.put(LAST_QUEUE_DATE_HEADER, Long.toString(flowFile.getLastQueueDate())); headers.put(LINEAGE_START_DATE_HEADER, Long.toString(flowFile.getLineageStartDate())); headers.put(SIZE_HEADER, Long.toString(flowFile.getSize())); headersLoaded = true; } } return headers; }
@Override public void transfer(FlowFile flowFile, final Relationship relationship) { if (relationship == Relationship.SELF) { transfer(flowFile); return; } if(!processor.getRelationships().contains(relationship)){ throw new IllegalArgumentException("this relationship " + relationship.getName() + " is not known"); } flowFile = validateState(flowFile); List<MockFlowFile> list = transferMap.computeIfAbsent(relationship, r -> new ArrayList<>()); beingProcessed.remove(flowFile.getId()); list.add((MockFlowFile) flowFile); updateLastQueuedDate((MockFlowFile) flowFile); }
public MockFlowFile unpenalize(FlowFile flowFile) { flowFile = validateState(flowFile); final MockFlowFile newFlowFile = new MockFlowFile(flowFile.getId(), flowFile); currentVersions.put(newFlowFile.getId(), newFlowFile); newFlowFile.setPenalized(false); penalized.remove(newFlowFile); return newFlowFile; }
@Override public MockFlowFile merge(Collection<FlowFile> sources, FlowFile destination, byte[] header, byte[] footer, byte[] demarcator) { sources = validateState(sources); destination = validateState(destination); final ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { if (header != null) { baos.write(header); } int count = 0; for (final FlowFile flowFile : sources) { baos.write(((MockFlowFile) flowFile).getData()); if (demarcator != null && ++count != sources.size()) { baos.write(demarcator); } } if (footer != null) { baos.write(footer); } } catch (final IOException e) { throw new AssertionError("failed to write data to BAOS"); } final MockFlowFile newFlowFile = new MockFlowFile(destination.getId(), destination); newFlowFile.setData(baos.toByteArray()); currentVersions.put(newFlowFile.getId(), newFlowFile); return newFlowFile; }
/** * Provides the natural ordering for FlowFile objects which is based on their identifier. * * @param other other * @return standard compare contract */ @Override public int compareTo(final FlowFile other) { return new CompareToBuilder().append(id, other.getId()).toComparison(); }
public void rollback() { complete = true; logger.debug("Marked {} as complete because rollback() was called", new Object[] {this}); writeLock.lock(); try { if (recordWriter != null) { try { recordWriter.close(); } catch (IOException e) { logger.warn("Failed to close Record Writer", e); } } session.rollback(); if (logger.isDebugEnabled()) { final List<String> ids = flowFiles.stream().map(ff -> " id=" + ff.getId() + ",").collect(Collectors.toList()); logger.debug("Rolled back bin {} containing input FlowFiles {}", new Object[] {this, ids}); } } finally { writeLock.unlock(); } }
/** * Checks if a FlowFile is known in this session. * * @param flowFile * the FlowFile to check * @return <code>true</code> if the FlowFile is known in this session, * <code>false</code> otherwise. */ boolean isFlowFileKnown(final FlowFile flowFile) { final FlowFile curFlowFile = currentVersions.get(flowFile.getId()); if (curFlowFile == null) { return false; } final String curUuid = curFlowFile.getAttribute(CoreAttributes.UUID.key()); final String providedUuid = curFlowFile.getAttribute(CoreAttributes.UUID.key()); if (!curUuid.equals(providedUuid)) { return false; } return true; } }
@Override public MockFlowFile merge(Collection<FlowFile> sources, FlowFile destination) { sources = validateState(sources); destination = validateState(destination); final ByteArrayOutputStream baos = new ByteArrayOutputStream(); for (final FlowFile flowFile : sources) { final MockFlowFile mock = (MockFlowFile) flowFile; final byte[] data = mock.getData(); try { baos.write(data); } catch (final IOException e) { throw new AssertionError("Failed to write to BAOS"); } } final MockFlowFile newFlowFile = new MockFlowFile(destination.getId(), destination); newFlowFile.setData(baos.toByteArray()); currentVersions.put(newFlowFile.getId(), newFlowFile); return newFlowFile; }
final FlowFile currentVersion = currentVersions.get(flowFile.getId()); if (currentVersion == null) { throw new FlowFileHandlingException(flowFile + " is not known in this session");
final List<FlowFile> flowFiles = session.get(FlowFileFilters.newSizeBasedFilter(250, DataUnit.KB, 250)); if (getLogger().isDebugEnabled()) { final List<String> ids = flowFiles.stream().map(ff -> "id=" + ff.getId()).collect(Collectors.toList()); getLogger().debug("Pulled {} FlowFiles from queue: {}", new Object[] {ids.size(), ids});