Search in sources :

Example 1 with FlowFileTransaction

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);
            }
        }
    }
}
Also used : FlowFileTransaction(org.apache.nifi.remote.protocol.FlowFileTransaction) IOException(java.io.IOException)

Example 2 with FlowFileTransaction

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);
}
Also used : FlowFileTransaction(org.apache.nifi.remote.protocol.FlowFileTransaction) HttpServerCommunicationsSession(org.apache.nifi.remote.io.http.HttpServerCommunicationsSession)

Example 3 with FlowFileTransaction

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));
}
Also used : ProcessSession(org.apache.nifi.processor.ProcessSession) FlowFileTransaction(org.apache.nifi.remote.protocol.FlowFileTransaction) HandshakeProperties(org.apache.nifi.remote.protocol.HandshakeProperties) Test(org.junit.Test)

Example 4 with FlowFileTransaction

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);
}
Also used : FlowFileTransaction(org.apache.nifi.remote.protocol.FlowFileTransaction) HttpServerCommunicationsSession(org.apache.nifi.remote.io.http.HttpServerCommunicationsSession)

Example 5 with FlowFileTransaction

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) {
    }
}
Also used : ProcessSession(org.apache.nifi.processor.ProcessSession) FlowFileTransaction(org.apache.nifi.remote.protocol.FlowFileTransaction) Test(org.junit.Test)

Aggregations

FlowFileTransaction (org.apache.nifi.remote.protocol.FlowFileTransaction)6 ProcessSession (org.apache.nifi.processor.ProcessSession)3 Test (org.junit.Test)3 HttpServerCommunicationsSession (org.apache.nifi.remote.io.http.HttpServerCommunicationsSession)2 IOException (java.io.IOException)1 HandshakeProperties (org.apache.nifi.remote.protocol.HandshakeProperties)1