use of org.apache.nifi.flowfile.FlowFile in project nifi by apache.
the class TestStandardProcessSession method testProvenanceEventsEmittedForRemove.
@Test
public void testProvenanceEventsEmittedForRemove() throws IOException {
final FlowFileRecord flowFileRecord = new StandardFlowFileRecord.Builder().addAttribute("uuid", "12345678-1234-1234-1234-123456789012").entryDate(System.currentTimeMillis()).build();
flowFileQueue.put(flowFileRecord);
final FlowFile orig = session.get();
final FlowFile newFlowFile = session.create(orig);
final FlowFile secondNewFlowFile = session.create(orig);
session.remove(newFlowFile);
session.transfer(secondNewFlowFile, new Relationship.Builder().name("A").build());
session.commit();
assertEquals(1, provenanceRepo.getEvents(0L, 100000).size());
}
use of org.apache.nifi.flowfile.FlowFile in project nifi by apache.
the class TestStandardProcessSession method testAppendToChildThrowsIOExceptionThenRemove.
@Test
public void testAppendToChildThrowsIOExceptionThenRemove() throws IOException {
final FlowFileRecord flowFileRecord = new StandardFlowFileRecord.Builder().id(1000L).addAttribute("uuid", "12345678-1234-1234-1234-123456789012").entryDate(System.currentTimeMillis()).build();
flowFileQueue.put(flowFileRecord);
FlowFile original = session.get();
assertNotNull(original);
FlowFile child = session.create(original);
child = session.append(child, out -> out.write("hello".getBytes()));
// Force an IOException. This will decrement out claim count for the resource claim.
try {
child = session.append(child, out -> {
throw new IOException();
});
Assert.fail("append() callback threw IOException but it was not wrapped in ProcessException");
} catch (final ProcessException pe) {
// expected
}
session.remove(child);
session.transfer(original);
session.commit();
final int numClaims = contentRepo.getExistingClaims().size();
assertEquals(0, numClaims);
}
use of org.apache.nifi.flowfile.FlowFile in project nifi by apache.
the class TestStandardPropertyValue method testFlowFileEntryYear.
@Test
public void testFlowFileEntryYear() {
final Calendar now = Calendar.getInstance();
final int year = now.get(Calendar.YEAR);
final PropertyValue value = new StandardPropertyValue("${entryDate:toNumber():toDate():format('yyyy')}", lookup);
final FlowFile flowFile = new StandardFlowFileRecord.Builder().entryDate(now.getTimeInMillis()).build();
final int val = value.evaluateAttributeExpressions(flowFile).asInteger().intValue();
assertEquals(year, val);
}
use of org.apache.nifi.flowfile.FlowFile in project nifi by apache.
the class TestStandardPropertyValue method testFileSize.
@Test
public void testFileSize() {
final PropertyValue value = new StandardPropertyValue("${fileSize}", lookup);
final FlowFile flowFile = new StandardFlowFileRecord.Builder().size(1024 * 1024L).build();
final long val = value.evaluateAttributeExpressions(flowFile).asLong().longValue();
assertEquals(1024 * 1024L, val);
}
use of org.apache.nifi.flowfile.FlowFile in project nifi by apache.
the class StandardRemoteGroupPort method onTrigger.
@Override
public void onTrigger(final ProcessContext context, final ProcessSession session) {
if (!remoteGroup.isTransmitting()) {
logger.debug("{} {} is not transmitting; will not send/receive", this, remoteGroup);
return;
}
if (getConnectableType() == ConnectableType.REMOTE_INPUT_PORT && session.getQueueSize().getObjectCount() == 0) {
logger.debug("{} No data to send", this);
return;
}
final String url = getRemoteProcessGroup().getTargetUri();
// If we are sending data, we need to ensure that we have at least 1 FlowFile to send. Otherwise,
// we don't want to create a transaction at all.
final FlowFile firstFlowFile;
if (getConnectableType() == ConnectableType.REMOTE_INPUT_PORT) {
firstFlowFile = session.get();
if (firstFlowFile == null) {
return;
}
} else {
firstFlowFile = null;
}
final SiteToSiteClient client = getSiteToSiteClient();
final Transaction transaction;
try {
transaction = client.createTransaction(transferDirection);
} catch (final PortNotRunningException e) {
context.yield();
this.targetRunning.set(false);
final String message = String.format("%s failed to communicate with %s because the remote instance indicates that the port is not in a valid state", this, url);
logger.error(message);
session.rollback();
remoteGroup.getEventReporter().reportEvent(Severity.ERROR, CATEGORY, message);
return;
} catch (final UnknownPortException e) {
context.yield();
this.targetExists.set(false);
final String message = String.format("%s failed to communicate with %s because the remote instance indicates that the port no longer exists", this, url);
logger.error(message);
session.rollback();
remoteGroup.getEventReporter().reportEvent(Severity.ERROR, CATEGORY, message);
return;
} catch (final UnreachableClusterException e) {
context.yield();
final String message = String.format("%s failed to communicate with %s due to %s", this, url, e.toString());
logger.error(message);
session.rollback();
remoteGroup.getEventReporter().reportEvent(Severity.ERROR, CATEGORY, message);
return;
} catch (final IOException e) {
// we do not yield here because the 'peer' will be penalized, and we won't communicate with that particular nifi instance
// for a while due to penalization, but we can continue to talk to other nifi instances
final String message = String.format("%s failed to communicate with %s due to %s", this, url, e.toString());
logger.error(message);
if (logger.isDebugEnabled()) {
logger.error("", e);
}
session.rollback();
remoteGroup.getEventReporter().reportEvent(Severity.ERROR, CATEGORY, message);
return;
}
if (transaction == null) {
logger.debug("{} Unable to create transaction to communicate with; all peers must be penalized, so yielding context", this);
session.rollback();
context.yield();
return;
}
try {
if (getConnectableType() == ConnectableType.REMOTE_INPUT_PORT) {
transferFlowFiles(transaction, context, session, firstFlowFile);
} else {
final int numReceived = receiveFlowFiles(transaction, context, session);
if (numReceived == 0) {
context.yield();
}
}
session.commit();
} catch (final Throwable t) {
final String message = String.format("%s failed to communicate with remote NiFi instance due to %s", this, t.toString());
logger.error("{} failed to communicate with remote NiFi instance due to {}", this, t.toString());
if (logger.isDebugEnabled()) {
logger.error("", t);
}
remoteGroup.getEventReporter().reportEvent(Severity.ERROR, CATEGORY, message);
transaction.error();
session.rollback();
}
}
Aggregations