use of org.apache.nifi.remote.protocol.FlowFileTransaction in project nifi by apache.
the class HttpRemoteSiteListener method cancelTransaction.
public void cancelTransaction(String transactionId) {
TransactionWrapper wrapper = transactions.remove(transactionId);
if (wrapper == null) {
logger.debug("The transaction was not found. transactionId={}", transactionId);
} else {
logger.debug("Cancel a transaction. transactionId={}", transactionId);
FlowFileTransaction t = wrapper.transaction;
if (t != null && t.getSession() != null) {
logger.info("Cancel a transaction, rollback its session. transactionId={}", transactionId);
try {
t.getSession().rollback();
} catch (Exception e) {
// Swallow exception so that it can keep expiring other transactions.
logger.error("Failed to rollback. transactionId={}", transactionId, e);
}
}
}
}
use of org.apache.nifi.remote.protocol.FlowFileTransaction in project nifi by apache.
the class StandardHttpFlowFileServerProtocol method commitReceiveTransaction.
@Override
public int commitReceiveTransaction(Peer peer) throws IOException, IllegalStateException {
logger.debug("{} Committing the receive transaction. peer={}", this, peer);
HttpServerCommunicationsSession commSession = (HttpServerCommunicationsSession) peer.getCommunicationsSession();
String transactionId = commSession.getTransactionId();
FlowFileTransaction transaction = transactionManager.finalizeTransaction(transactionId);
commSession.setStatus(Transaction.TransactionState.TRANSACTION_CONFIRMED);
return super.commitReceiveTransaction(peer, transaction);
}
use of org.apache.nifi.remote.protocol.FlowFileTransaction in project nifi by apache.
the class TestHttpRemoteSiteListener method testNormalTransactionProgress.
@Test
public void testNormalTransactionProgress() {
HttpRemoteSiteListener transactionManager = HttpRemoteSiteListener.getInstance(NiFiProperties.createBasicNiFiProperties(null, null));
String transactionId = transactionManager.createTransaction();
assertTrue("Transaction should be active.", transactionManager.isTransactionActive(transactionId));
ProcessSession processSession = Mockito.mock(ProcessSession.class);
FlowFileTransaction transaction = new FlowFileTransaction(processSession, null, null, 0, null, null);
transactionManager.holdTransaction(transactionId, transaction, new HandshakeProperties());
assertNotNull(transactionManager.getHandshakenProperties(transactionId));
transaction = transactionManager.finalizeTransaction(transactionId);
assertNotNull(transaction);
assertFalse("Transaction should not be active anymore.", transactionManager.isTransactionActive(transactionId));
}
use of org.apache.nifi.remote.protocol.FlowFileTransaction in project nifi by apache.
the class StandardHttpFlowFileServerProtocol method commitTransferTransaction.
@Override
public int commitTransferTransaction(Peer peer, String clientChecksum) throws IOException, IllegalStateException {
logger.debug("{} Committing the transfer transaction. peer={} clientChecksum={}", this, peer, clientChecksum);
HttpServerCommunicationsSession commSession = (HttpServerCommunicationsSession) peer.getCommunicationsSession();
String transactionId = commSession.getTransactionId();
FlowFileTransaction transaction = transactionManager.finalizeTransaction(transactionId);
commSession.setChecksum(clientChecksum);
commSession.setStatus(Transaction.TransactionState.DATA_EXCHANGED);
return super.commitTransferTransaction(peer, transaction);
}
use of org.apache.nifi.remote.protocol.FlowFileTransaction in project nifi by apache.
the class TestHttpRemoteSiteListener method testDuplicatedTransactionId.
@Test
public void testDuplicatedTransactionId() {
HttpRemoteSiteListener transactionManager = HttpRemoteSiteListener.getInstance(NiFiProperties.createBasicNiFiProperties(null, null));
String transactionId = transactionManager.createTransaction();
assertTrue("Transaction should be active.", transactionManager.isTransactionActive(transactionId));
ProcessSession processSession = Mockito.mock(ProcessSession.class);
FlowFileTransaction transaction = new FlowFileTransaction(processSession, null, null, 0, null, null);
transactionManager.holdTransaction(transactionId, transaction, null);
try {
transactionManager.holdTransaction(transactionId, transaction, null);
fail("The same transaction id can't hold another transaction");
} catch (IllegalStateException e) {
}
}
Aggregations