Cache topology path 64/73664/2
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 2 Jul 2018 18:43:55 +0000 (20:43 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 2 Jul 2018 19:23:50 +0000 (21:23 +0200)
Instead of creating base InstanceIdentifier over and over, cache
it in a field.

Change-Id: I54d1bb7555a94fc20c5cf406f6f6f6dd69d7fc5d
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/util/NetconfTopologyRPCProvider.java

index 1683a35f2d3de951684cb505abcdd6aab2d8774c..44e4ff99aca010816ee1eea3d497c26732afbb02 100644 (file)
@@ -48,16 +48,17 @@ import org.slf4j.LoggerFactory;
 public class NetconfTopologyRPCProvider implements NetconfNodeTopologyService {
     private static final Logger LOG = LoggerFactory.getLogger(NetconfTopologyRPCProvider.class);
 
+    private final InstanceIdentifier<Topology> topologyPath;
     private final AAAEncryptionService encryptionService;
     private final DataBroker dataBroker;
-    private final String topologyId;
 
     public NetconfTopologyRPCProvider(final DataBroker dataBroker,
                                       final AAAEncryptionService encryptionService,
                                       final String topologyId) {
         this.dataBroker = dataBroker;
         this.encryptionService = Preconditions.checkNotNull(encryptionService);
-        this.topologyId = Preconditions.checkNotNull(topologyId);
+        this.topologyPath = InstanceIdentifier.builder(NetworkTopology.class)
+                .child(Topology.class, new TopologyKey(new TopologyId(Preconditions.checkNotNull(topologyId)))).build();
     }
 
     @Override
@@ -99,10 +100,7 @@ public class NetconfTopologyRPCProvider implements NetconfNodeTopologyService {
             final SettableFuture<RpcResult<CreateDeviceOutput>> futureResult) {
 
         final WriteTransaction writeTransaction = dataBroker.newWriteOnlyTransaction();
-        final InstanceIdentifier<NetworkTopology> networkTopologyId =
-                InstanceIdentifier.builder(NetworkTopology.class).build();
-        final InstanceIdentifier<NetconfNode> niid = networkTopologyId.child(Topology.class,
-                new TopologyKey(new TopologyId(topologyId))).child(Node.class,
+        final InstanceIdentifier<NetconfNode> niid = topologyPath.child(Node.class,
                 new NodeKey(nodeId)).augmentation(NetconfNode.class);
         writeTransaction.merge(LogicalDatastoreType.CONFIGURATION, niid, node, true);
         final ListenableFuture<Void> future = writeTransaction.submit();
@@ -127,11 +125,7 @@ public class NetconfTopologyRPCProvider implements NetconfNodeTopologyService {
     public ListenableFuture<RpcResult<DeleteDeviceOutput>> deleteDevice(final DeleteDeviceInput input) {
         final NodeId nodeId = new NodeId(input.getNodeId());
 
-        final InstanceIdentifier<NetworkTopology> networkTopologyId =
-                InstanceIdentifier.builder(NetworkTopology.class).build();
-        final InstanceIdentifier<Node> niid = networkTopologyId.child(Topology.class,
-                new TopologyKey(new TopologyId(topologyId))).child(Node.class,
-                new NodeKey(nodeId));
+        final InstanceIdentifier<Node> niid = topologyPath.child(Node.class, new NodeKey(nodeId));
 
         final WriteTransaction wtx = dataBroker.newWriteOnlyTransaction();
         wtx.delete(LogicalDatastoreType.CONFIGURATION, niid);