Clean-up mdsal-netconf-connector 06/45606/4
authorAlexis de Talhouët <adetalhouet@inocybe.com>
Wed, 14 Sep 2016 22:55:26 +0000 (18:55 -0400)
committerAlexis de Talhouët <adetalhouet@inocybe.com>
Wed, 21 Sep 2016 15:59:41 +0000 (15:59 +0000)
- add FIXME to address duplicated code
- remove unsed API
- remove iner generic type
- use lambda when possible
- reduce visibility of param when  possible

Change-Id: Id0ce780026c20ab67d3621b7162653606235634c
Signed-off-by: Alexis de Talhouët <adetalhouet@inocybe.com>
netconf/mdsal-netconf-connector/pom.xml
netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/CurrentSchemaContext.java
netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/MdsalNetconfOperationServiceFactory.java
netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/OperationProvider.java
netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/TransactionProvider.java
netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/Commit.java
netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/DiscardChanges.java
netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/EditConfig.java
netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/Lock.java
netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/Unlock.java

index f37105ad8b215e803bfd1c851782f1f9bf4bd33b..5980c902e4774b2366d98c6e769f8a26a7a8e6d7 100644 (file)
     <dependency>
       <groupId>org.opendaylight.yangtools</groupId>
       <artifactId>yang-data-impl</artifactId>
-
-      <!-- FIXME: this should not be necessary and it hurts shareability -->
-      <exclusions>
-          <exclusion>
-              <groupId>org.opendaylight.yangtools</groupId>
-              <artifactId>object-cache-api</artifactId>
-          </exclusion>
-      </exclusions>
     </dependency>
     <dependency>
       <groupId>org.opendaylight.yangtools</groupId>
index a45d5a63775787bbf1956c9f63ef013c723606ef..fa7f273465b24a665815026412a8e13f3a2afd57 100644 (file)
@@ -23,10 +23,10 @@ import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
 import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceProvider;
 
 public class CurrentSchemaContext implements SchemaContextListener, AutoCloseable {
-    final AtomicReference<SchemaContext> currentContext = new AtomicReference<SchemaContext>();
+    private final AtomicReference<SchemaContext> currentContext = new AtomicReference();
     private final ListenerRegistration<SchemaContextListener> schemaContextListenerListenerRegistration;
-    private final Set<CapabilityListener> listeners1 = Collections.synchronizedSet(Sets.<CapabilityListener>newHashSet());
-    private SchemaSourceProvider<YangTextSchemaSource> rootSchemaSourceProvider;
+    private final Set<CapabilityListener> listeners1 = Collections.synchronizedSet(Sets.newHashSet());
+    private final SchemaSourceProvider<YangTextSchemaSource> rootSchemaSourceProvider;
 
     public SchemaContext getCurrentContext() {
         Preconditions.checkState(currentContext.get() != null, "Current context not received");
@@ -44,7 +44,7 @@ public class CurrentSchemaContext implements SchemaContextListener, AutoCloseabl
         // FIXME is notifying all the listeners from this callback wise ?
         final Set<Capability> addedCaps = MdsalNetconfOperationServiceFactory.transformCapabilities(currentContext.get(), rootSchemaSourceProvider);
         for (final CapabilityListener listener : listeners1) {
-            listener.onCapabilitiesChanged(addedCaps, Collections.<Capability>emptySet());
+            listener.onCapabilitiesChanged(addedCaps, Collections.emptySet());
         }
     }
 
@@ -58,11 +58,6 @@ public class CurrentSchemaContext implements SchemaContextListener, AutoCloseabl
     public AutoCloseable registerCapabilityListener(final CapabilityListener listener) {
         listener.onCapabilitiesChanged(MdsalNetconfOperationServiceFactory.transformCapabilities(currentContext.get(), rootSchemaSourceProvider), Collections.<Capability>emptySet());
         listeners1.add(listener);
-        return new AutoCloseable() {
-            @Override
-            public void close() throws Exception {
-                listeners1.remove(listener);
-            }
-        };
+        return () -> listeners1.remove(listener);
     }
 }
\ No newline at end of file
index 56eb032a99bb937a9379d51f85d4e3c7235e92db..b450a9d0c8310cc5fd9a738d5b179f8372eaa9ec 100644 (file)
@@ -96,7 +96,7 @@ public class MdsalNetconfOperationServiceFactory implements NetconfOperationServ
             final Module module, final SchemaSourceProvider<YangTextSchemaSource> rootSchemaSourceProviderDependency) {
 
         final SourceIdentifier moduleSourceIdentifier = SourceIdentifier.create(module.getName(),
-                (SimpleDateFormatUtil.DEFAULT_DATE_REV == module.getRevision() ? Optional.<String>absent() :
+                (SimpleDateFormatUtil.DEFAULT_DATE_REV == module.getRevision() ? Optional.absent() :
                         Optional.of(SimpleDateFormatUtil.getRevisionFormat().format(module.getRevision()))));
 
         InputStream sourceStream = null;
index c356e4f361366624f286f0f810c579424a0f4c78..5bf9fb15ad80d01ed55e0bdaeda50cdaeb504e0d 100644 (file)
@@ -40,7 +40,7 @@ final class OperationProvider {
     }
 
     Set<NetconfOperation> getOperations() {
-        return Sets.<NetconfOperation>newHashSet(
+        return Sets.newHashSet(
                 new Commit(netconfSessionIdForReporting, transactionProvider),
                 new DiscardChanges(netconfSessionIdForReporting, transactionProvider),
                 new EditConfig(netconfSessionIdForReporting, schemaContext, transactionProvider),
index f5e303ebd660fb745335f20b1bd9bee09ad8caef..a39042f881cdc5bbd00f4263c710fa63986083f0 100644 (file)
@@ -112,21 +112,6 @@ public class TransactionProvider implements AutoCloseable{
         return runningTransaction;
     }
 
-    public synchronized boolean commitRunningTransaction(DOMDataReadWriteTransaction tx) throws DocumentedException {
-        allOpenReadWriteTransactions.remove(tx);
-
-        CheckedFuture<Void, TransactionCommitFailedException> future = tx.submit();
-        try {
-            future.checkedGet();
-        } catch (TransactionCommitFailedException e) {
-            LOG.debug("Transaction {} failed on", tx, e);
-            throw new DocumentedException("Transaction commit failed on " + e.getMessage() + " " + netconfSessionIdForReporting,
-                    ErrorType.application, ErrorTag.operation_failed, ErrorSeverity.error);
-        }
-
-        return true;
-    }
-
     public synchronized void abortRunningTransaction(DOMDataReadWriteTransaction tx) {
         LOG.debug("Aborting current running Transaction");
         Preconditions.checkState(runningTransaction != null, NO_TRANSACTION_FOUND_FOR_SESSION + netconfSessionIdForReporting);
index 43e12a34945df1feb2b93fd0fe73f180ff538ca2..820cca65ad5686975fb8a2f37303e9d7810804c1 100644 (file)
@@ -20,6 +20,8 @@ import org.slf4j.LoggerFactory;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 
+// FIXME duplicated code
+// netconf/netconf/config-netconf-connector/src/main/java/org/opendaylight/netconf/confignetconfconnector/Commit.java
 public class Commit extends AbstractSingletonNetconfOperation {
 
     private static final Logger LOG = LoggerFactory.getLogger(Commit.class);
@@ -39,7 +41,7 @@ public class Commit extends AbstractSingletonNetconfOperation {
         boolean commitStatus = transactionProvider.commitTransaction();
         LOG.trace("Commit completed successfully {}", commitStatus);
 
-        return XmlUtil.createElement(document, XmlNetconfConstants.OK, Optional.<String>absent());
+        return XmlUtil.createElement(document, XmlNetconfConstants.OK, Optional.absent());
     }
 
     @Override
index bc7ee21e58f5d309dc1f0cf3f8c496a480b15767..8d3765e10920ecbe562d19026599055484481f7f 100644 (file)
@@ -52,7 +52,7 @@ public class DiscardChanges extends AbstractSingletonNetconfOperation {
             throw new DocumentedException(e.getMessage(), e, ErrorType.application, ErrorTag.operation_failed,
                     ErrorSeverity.error, errorInfo);
         }
-        return XmlUtil.createElement(document, XmlNetconfConstants.OK, Optional.<String>absent());
+        return XmlUtil.createElement(document, XmlNetconfConstants.OK, Optional.absent());
     }
 
     @Override
index 48c353ec5ed38bf4432619ae45cfe1301a96e63c..0d569e60121b2db634a281faf9f8973787a4f2e9 100644 (file)
@@ -87,7 +87,7 @@ public class EditConfig extends AbstractSingletonNetconfOperation {
             executeOperations(changeTracker);
         }
 
-        return XmlUtil.createElement(document, XmlNetconfConstants.OK, Optional.<String>absent());
+        return XmlUtil.createElement(document, XmlNetconfConstants.OK, Optional.absent());
     }
 
     private void executeOperations(final DataTreeChangeTracker changeTracker) throws DocumentedException {
index 15e58b0d54cbc970b949984f51defbd034c8ae05..73559967f2e2f9f0a97b2cd58360239e2c0f17e9 100644 (file)
@@ -19,6 +19,8 @@ import org.slf4j.LoggerFactory;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 
+// FIXME Duplicated code
+// netconf/netconf/config-netconf-connector/src/main/java/org/opendaylight/netconf/confignetconfconnector/operations/Lock.java
 public class Lock extends AbstractSingletonNetconfOperation {
 
     private static final Logger LOG = LoggerFactory.getLogger(Lock.class);
index 2284d11ea35461603547ac38c0654a751e330c9a..9d2daa5189e7a13dc4836d9056c5df726bb25181 100644 (file)
@@ -19,6 +19,8 @@ import org.slf4j.LoggerFactory;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 
+// FIXME Duplicated code
+// netconf/netconf/config-netconf-connector/src/main/java/org/opendaylight/netconf/confignetconfconnector/operations/UnLock.java
 public class Unlock extends AbstractSingletonNetconfOperation {
 
     private static final Logger LOG = LoggerFactory.getLogger(Unlock.class);