X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fnetconf%2Fconfig-netconf-connector%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetconf%2Fconfignetconfconnector%2Ftransactions%2FTransactionProvider.java;h=b2ee63a987836102fa31ae8c97e8dac899a33198;hp=250af688eac0db0a796b2e4dd668f84684949b99;hb=662f3629fea2904f8c14526ef412ef1650961e83;hpb=84248dac9ed8aa37e996e39429c8aa8ece473eaf diff --git a/opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/transactions/TransactionProvider.java b/opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/transactions/TransactionProvider.java index 250af688ea..b2ee63a987 100644 --- a/opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/transactions/TransactionProvider.java +++ b/opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/transactions/TransactionProvider.java @@ -10,6 +10,11 @@ package org.opendaylight.controller.netconf.confignetconfconnector.transactions; import com.google.common.base.Optional; import com.google.common.base.Preconditions; +import java.util.ArrayList; +import java.util.List; +import java.util.Set; +import javax.management.InstanceNotFoundException; +import javax.management.ObjectName; import org.opendaylight.controller.config.api.ConflictingVersionException; import org.opendaylight.controller.config.api.ValidationException; import org.opendaylight.controller.config.api.jmx.CommitStatus; @@ -20,14 +25,8 @@ import org.opendaylight.controller.netconf.confignetconfconnector.exception.NoTr import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import javax.management.InstanceNotFoundException; -import javax.management.ObjectName; -import java.util.ArrayList; -import java.util.List; -import java.util.Set; - public class TransactionProvider implements AutoCloseable { - private static final Logger logger = LoggerFactory.getLogger(TransactionProvider.class); + private static final Logger LOG = LoggerFactory.getLogger(TransactionProvider.class); private final ConfigRegistryClient configRegistryClient; @@ -49,13 +48,13 @@ public class TransactionProvider implements AutoCloseable { configRegistryClient.getConfigTransactionClient(tx).abortConfig(); } } catch (Exception e) { - logger.debug("Ignoring exception while closing transaction {}", tx, e); + LOG.debug("Ignoring exception while closing transaction {}", tx, e); } } allOpenedTransactions.clear(); } - public Optional getTransaction() { + public synchronized Optional getTransaction() { if (transaction == null){ return Optional.absent(); @@ -63,7 +62,7 @@ public class TransactionProvider implements AutoCloseable { // Transaction was already closed somehow if (!isStillOpenTransaction(transaction)) { - logger.warn("Fixing illegal state: transaction {} was closed in {}", transaction, + LOG.warn("Fixing illegal state: transaction {} was closed in {}", transaction, netconfSessionIdForReporting); transaction = null; return Optional.absent(); @@ -78,8 +77,9 @@ public class TransactionProvider implements AutoCloseable { public synchronized ObjectName getOrCreateTransaction() { Optional ta = getTransaction(); - if (ta.isPresent()) + if (ta.isPresent()) { return ta.get(); + } transaction = configRegistryClient.beginConfig(); allOpenedTransactions.add(transaction); return transaction; @@ -114,10 +114,10 @@ public class TransactionProvider implements AutoCloseable { return status; } catch (ValidationException validationException) { // no clean up: user can reconfigure and recover this transaction - logger.warn("Transaction {} failed on {}", taON, validationException.toString()); + LOG.warn("Transaction {} failed on {}", taON, validationException.toString()); throw validationException; } catch (ConflictingVersionException e) { - logger.error("Exception while commit of {}, aborting transaction", taON, e); + LOG.error("Exception while commit of {}, aborting transaction", taON, e); // clean up abortTransaction(); throw e; @@ -125,7 +125,7 @@ public class TransactionProvider implements AutoCloseable { } public synchronized void abortTransaction() { - logger.debug("Aborting current transaction"); + LOG.debug("Aborting current transaction"); Optional taON = getTransaction(); Preconditions.checkState(taON.isPresent(), NO_TRANSACTION_FOUND_FOR_SESSION + netconfSessionIdForReporting); @@ -136,7 +136,7 @@ public class TransactionProvider implements AutoCloseable { } public synchronized void abortTestTransaction(ObjectName testTx) { - logger.debug("Aborting transaction {}", testTx); + LOG.debug("Aborting transaction {}", testTx); ConfigTransactionClient transactionClient = configRegistryClient.getConfigTransactionClient(testTx); allOpenedTransactions.remove(testTx); transactionClient.abortConfig(); @@ -156,41 +156,40 @@ public class TransactionProvider implements AutoCloseable { } public void wipeTestTransaction(ObjectName taON) { - wipeInternal(taON, true, null); + wipeInternal(taON, true); } /** * Wiping means removing all module instances keeping the transaction open + service references. */ - synchronized void wipeInternal(ObjectName taON, boolean isTest, String moduleName) { + synchronized void wipeInternal(ObjectName taON, boolean isTest) { ConfigTransactionClient transactionClient = configRegistryClient.getConfigTransactionClient(taON); - Set lookupConfigBeans = moduleName == null ? transactionClient.lookupConfigBeans() - : transactionClient.lookupConfigBeans(moduleName); + Set lookupConfigBeans = transactionClient.lookupConfigBeans(); int i = lookupConfigBeans.size(); for (ObjectName instance : lookupConfigBeans) { try { transactionClient.destroyModule(instance); } catch (InstanceNotFoundException e) { if (isTest){ - logger.debug("Unable to clean configuration in transactiom {}", taON, e); + LOG.debug("Unable to clean configuration in transactiom {}", taON, e); } else { - logger.warn("Unable to clean configuration in transactiom {}", taON, e); + LOG.warn("Unable to clean configuration in transactiom {}", taON, e); } throw new IllegalStateException("Unable to clean configuration in transactiom " + taON, e); } } - logger.debug("Transaction {} wiped clean of {} config beans", taON, i); + LOG.debug("Transaction {} wiped clean of {} config beans", taON, i); transactionClient.removeAllServiceReferences(); - logger.debug("Transaction {} wiped clean of all service references", taON); + LOG.debug("Transaction {} wiped clean of all service references", taON); } public void wipeTransaction() { Optional taON = getTransaction(); Preconditions.checkState(taON.isPresent(), NO_TRANSACTION_FOUND_FOR_SESSION + netconfSessionIdForReporting); - wipeInternal(taON.get(), false, null); + wipeInternal(taON.get(), false); } }