Forum Discussion

uchi_122495's avatar
May 15, 2015

iControl transaction problem

Here is my code written with iControl Library for Java.

 

// set timeout
interfaces.getSystemSession().set_session_timeout(60);
interfaces.getSystemSession().set_transaction_timeout(30);

// get transaction
final long sessionId = interfaces.getSystemSession().get_session_identifier();
interfaces.getSystemSession().setHeader("urn:iControl", "session", Long.toString(sessionId));
interfaces.getLocalLBPool().setHeader("urn:iControl","session",Long.toString(sessionId);

// start transaction
interfaces.getSystemSession().submit_transaction();

// create pool1
interfaces.getLocalLBPool().create_v2(poolname1, lbmethod1, addressport1);

// sleep 30 sec to wait transaction will be expired
Thread.sleep(30000); 

// create pool2
interfaces.getLocalLBPool().create_v2(poolname2, lbmethod2, addressport2);

// submit transaction 
interfaces.getSystemSession().submit_transaction();

 

I expected that creating both pool1 and pool2 would be rollbacked, but pool2 was succesfully created.

Is there a way to detect transaction expiration and roleback all configuration in transaction ?

  • You are calling submit_transaction() to start the transaction. You should call the System.Session.start_transaction() method to begin the transaction and System.Session.submit_transaction() to commit it. If you don't call start_transaction(), there is no transaction context setup and each call is autonomous. If you want to cancel, you can call the System.Session.rollback_transaction() or let the timeout expire without calling submit_transaction().

     

    One question, What is the purpose of setting the "urn:iControl" headers? I believe the session id needs to be passed in with the "X-iControl-Session" HTTP or SOAP header if you want to use a unique session key for the current transaction.

     

    Hope this helps...

     

    -Joe

     

  • Hi joe, thank you for your reply.

    At first, the first submit_transaction() on my code is just typo. I fixed it to start_transaction. sorry.

    One question, What is the purpose of setting the "urn:iControl" headers? I believe the session id needs to be passed in with the "X-iControl-Session" HTTP or SOAP header if you want to use a unique session key for the current transaction.

    I saw this post describing session as SOAP header for session identifier.

    My problem is the second create_v2() could be executed through out of the transaction and succeeded.

    • Joe_Pruitt's avatar
      Joe_Pruitt
      For the header, you need the header name of "X-iControl-Session". I don't see that in your code. That is what I was getting at with my question on the header. As for the expiration, I believe if a transaction expires, then the state returns to auto-commit. So if you start a transaction, wait until the expiration and then issue a command it will auto-commit. If you start a transaction, issue a command before the timeout and do not end transaction it should not commit. I'll have to go back and do some testing...
  • Thanks, Joe.

    X-iControl-Session is HTTP header. I am using session as SOAP header instead. Is X-iControl-Session required even if SOAP header is setted ?

    So if you start a transaction, wait until the expiration and then issue a command it will auto-commit.

    My code exactly works as you say. The only second create_v2 is executed. My purpose is to avoid committing that second creat_v2, because expiration is unpredictable.