this.actorResponseWaitTime = actorResponseWaitTime;
this.lockDatastore = lockDatastore;
- datastoreAdapter = new NetconfDeviceTopologyAdapter(dataBroker, id);
+ datastoreAdapter = new NetconfDeviceTopologyAdapter(dataBroker, RemoteDeviceId.DEFAULT_TOPOLOGY_IID, id);
}
@Override
import com.google.common.util.concurrent.SettableFuture;
import java.util.concurrent.ExecutionException;
import java.util.stream.Collectors;
+import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.mdsal.binding.api.DataBroker;
import org.opendaylight.mdsal.binding.api.Transaction;
import org.opendaylight.mdsal.binding.api.TransactionChain;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.device.rev221225.connection.oper.unavailable.capabilities.UnavailableCapabilityBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev221225.NetconfNode;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev221225.NetconfNodeBuilder;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeBuilder;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
import org.opendaylight.yangtools.yang.common.Empty;
import org.opendaylight.yangtools.yang.common.Uint16;
import org.slf4j.Logger;
private static final Logger LOG = LoggerFactory.getLogger(NetconfDeviceTopologyAdapter.class);
private final SettableFuture<Empty> closeFuture = SettableFuture.create();
+ private final @NonNull KeyedInstanceIdentifier<Topology, TopologyKey> topologyPath;
private final DataBroker dataBroker;
private final RemoteDeviceId id;
private TransactionChain txChain;
- public NetconfDeviceTopologyAdapter(final DataBroker dataBroker, final RemoteDeviceId id) {
+ public NetconfDeviceTopologyAdapter(final DataBroker dataBroker,
+ final KeyedInstanceIdentifier<Topology, TopologyKey> topologyPath, final RemoteDeviceId id) {
this.dataBroker = requireNonNull(dataBroker);
+ this.topologyPath = requireNonNull(topologyPath);
this.id = requireNonNull(id);
txChain = dataBroker.createMergingTransactionChain(this);
final WriteTransaction writeTx = txChain.newWriteOnlyTransaction();
LOG.trace("{}: Init device state transaction {} putting if absent operational data started.", id,
writeTx.getIdentifier());
- final var nodePath = id.getTopologyBindingPath();
+ final var nodePath = nodePath();
writeTx.put(LogicalDatastoreType.OPERATIONAL, nodePath, new NodeBuilder()
.withKey(nodePath.getKey())
.addAugmentation(new NetconfNodeBuilder()
commitTransaction(writeTx, "init");
}
+ private @NonNull KeyedInstanceIdentifier<Node, NodeKey> nodePath() {
+ return topologyPath.child(Node.class, new NodeKey(new NodeId(id.getName())));
+ }
+
+ private @NonNull InstanceIdentifier<NetconfNode> netconfNodePath() {
+ return nodePath().augmentation(NetconfNode.class);
+ }
+
public void updateDeviceData(final boolean up, final NetconfDeviceCapabilities capabilities) {
final WriteTransaction writeTx = txChain.newWriteOnlyTransaction();
LOG.trace("{}: Update device state transaction {} merging operational data started.",
id, writeTx.getIdentifier());
// FIXME: this needs to be tied together with node's operational existence
- writeTx.mergeParentStructurePut(LogicalDatastoreType.OPERATIONAL,
- id.getTopologyBindingPath().augmentation(NetconfNode.class),
+ writeTx.mergeParentStructurePut(LogicalDatastoreType.OPERATIONAL, netconfNodePath(),
newNetconfNodeBuilder(up, capabilities).build());
LOG.trace("{}: Update device state transaction {} merging operational data ended.",
id, writeTx.getIdentifier());
final WriteTransaction writeTx = txChain.newWriteOnlyTransaction();
LOG.trace("{}: Update device state transaction {} merging operational data started.",
id, writeTx.getIdentifier());
- writeTx.mergeParentStructurePut(LogicalDatastoreType.OPERATIONAL,
- id.getTopologyBindingPath().augmentation(NetconfNode.class),
+ writeTx.mergeParentStructurePut(LogicalDatastoreType.OPERATIONAL, netconfNodePath(),
newNetconfNodeBuilder(up, capabilities)
.setClusteredConnectionStatus(new ClusteredConnectionStatusBuilder()
.setNetconfMasterNode(masterAddress)
LOG.trace(
"{}: Setting device state as failed {} putting operational data started.",
id, writeTx.getIdentifier());
- writeTx.mergeParentStructurePut(LogicalDatastoreType.OPERATIONAL,
- id.getTopologyBindingPath().augmentation(NetconfNode.class), data);
+ writeTx.mergeParentStructurePut(LogicalDatastoreType.OPERATIONAL, netconfNodePath(), data);
LOG.trace(
"{}: Setting device state as failed {} putting operational data ended.",
id, writeTx.getIdentifier());
public void close() {
final WriteTransaction writeTx = txChain.newWriteOnlyTransaction();
LOG.trace("{}: Close device state transaction {} removing all data started.", id, writeTx.getIdentifier());
- writeTx.delete(LogicalDatastoreType.OPERATIONAL, id.getTopologyBindingPath());
+ writeTx.delete(LogicalDatastoreType.OPERATIONAL, nodePath());
LOG.trace("{}: Close device state transaction {} removing all data ended.", id, writeTx.getIdentifier());
commitTransaction(writeTx, "close");
public NetconfTopologyDeviceSalFacade(final RemoteDeviceId id, final DOMMountPointService mountPointService,
final boolean lockDatastore, final DataBroker dataBroker) {
super(id, mountPointService, lockDatastore);
- datastoreAdapter = new NetconfDeviceTopologyAdapter(dataBroker, id);
+ datastoreAdapter = new NetconfDeviceTopologyAdapter(dataBroker, RemoteDeviceId.DEFAULT_TOPOLOGY_IID, id);
}
@Override
import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev221225.NetconfNode;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.augment.test.rev160808.Node1;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyBuilder;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey;
+import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
// FIXME: base on AbstractDataBrokerTest test?
public class NetconfDeficeTopologyAdapterIntegrationTest {
private static final RemoteDeviceId ID = new RemoteDeviceId("test", new InetSocketAddress("localhost", 22));
+ private static final KeyedInstanceIdentifier<Topology, TopologyKey> TEST_TOPOLOGY_ID =
+ // FIXME: do not use this constant
+ RemoteDeviceId.DEFAULT_TOPOLOGY_IID;
private static BindingRuntimeContext RUNTIME_CONTEXT;
customizer.updateSchema(RUNTIME_CONTEXT);
final var tx = dataBroker.newWriteOnlyTransaction();
- tx.put(LogicalDatastoreType.OPERATIONAL, RemoteDeviceId.DEFAULT_TOPOLOGY_IID, new TopologyBuilder()
- .withKey(RemoteDeviceId.DEFAULT_TOPOLOGY_IID.getKey())
+ tx.put(LogicalDatastoreType.OPERATIONAL, TEST_TOPOLOGY_ID, new TopologyBuilder()
+ .withKey(TEST_TOPOLOGY_ID.getKey())
.build());
tx.commit().get(2, TimeUnit.SECONDS);
- adapter = new NetconfDeviceTopologyAdapter(dataBroker, ID);
+ adapter = new NetconfDeviceTopologyAdapter(dataBroker, TEST_TOPOLOGY_ID, ID);
}
@Test
adapter.setDeviceAsFailed(null);
Awaitility.await().atMost(5, TimeUnit.SECONDS).until(() -> dataBroker.newReadWriteTransaction()
- .read(LogicalDatastoreType.OPERATIONAL, ID.getTopologyBindingPath().augmentation(NetconfNode.class))
+ .read(LogicalDatastoreType.OPERATIONAL, TEST_TOPOLOGY_ID
+ .child(Node.class, new NodeKey(new NodeId(ID.getName())))
+ .augmentation(NetconfNode.class))
.get(5, TimeUnit.SECONDS)
.filter(conn -> conn.getConnectionStatus() == ConnectionStatus.UnableToConnect)
.isPresent());
import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
import org.opendaylight.netconf.sal.connect.netconf.listener.NetconfDeviceCapabilities;
import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
@RunWith(MockitoJUnitRunner.StrictStubs.class)
public class NetconfDeviceTopologyAdapterTest {
+ private static final KeyedInstanceIdentifier<Topology, TopologyKey> TEST_TOPOLOGY_ID =
+ RemoteDeviceId.DEFAULT_TOPOLOGY_IID;
private final RemoteDeviceId id = new RemoteDeviceId("test", new InetSocketAddress("localhost", 22));
@Mock
doReturn(CommitInfo.emptyFluentFuture()).when(mockTx).commit();
doReturn(mockChain).when(mockBroker).createMergingTransactionChain(listeners.capture());
- adapter = new NetconfDeviceTopologyAdapter(mockBroker, id);
+ adapter = new NetconfDeviceTopologyAdapter(mockBroker, TEST_TOPOLOGY_ID, id);
}
@Test
adapter.close();
verify(mockChain, times(2)).newWriteOnlyTransaction();
- verify(mockTx).delete(LogicalDatastoreType.OPERATIONAL, id.getTopologyBindingPath());
+ verify(mockTx).delete(LogicalDatastoreType.OPERATIONAL,
+ TEST_TOPOLOGY_ID.child(Node.class, new NodeKey(new NodeId(id.getName()))));
verify(mockTx, times(2)).commit();
}
}
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IetfInetUtil;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev221225.network.topology.topology.topology.types.TopologyNetconf;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
public final class RemoteDeviceId {
+ // FIXME: extract all of this to users, as they are in control of topology-id
private static final String DEFAULT_TOPOLOGY_NAME = TopologyNetconf.QNAME.getLocalName();
private static final YangInstanceIdentifier DEFAULT_TOPOLOGY_NODE = YangInstanceIdentifier.builder()
.node(NetworkTopology.QNAME).node(Topology.QNAME)
private final @NonNull String name;
private final @NonNull YangInstanceIdentifier topologyPath;
- private final @NonNull KeyedInstanceIdentifier<Node, NodeKey> topologyBindingPath;
private InetSocketAddress address;
private Host host;
private RemoteDeviceId(final String name) {
this.name = requireNonNull(name);
topologyPath = DEFAULT_TOPOLOGY_NODE.node(NodeIdentifierWithPredicates.of(Node.QNAME, NODE_ID_QNAME, name));
- topologyBindingPath = DEFAULT_TOPOLOGY_IID.child(Node.class, new NodeKey(new NodeId(name)));
}
public RemoteDeviceId(final String name, final InetSocketAddress address) {
this(name);
this.address = address;
- host = buildHost();
- }
- private Host buildHost() {
final var addr = address.getAddress();
- return addr != null ? new Host(IetfInetUtil.INSTANCE.ipAddressFor(addr))
+ host = addr != null ? new Host(IetfInetUtil.INSTANCE.ipAddressFor(addr))
: new Host(new DomainName(address.getHostString()));
}
return name;
}
- public @NonNull KeyedInstanceIdentifier<Node, NodeKey> getTopologyBindingPath() {
- return topologyBindingPath;
- }
-
public @NonNull YangInstanceIdentifier getTopologyPath() {
return topologyPath;
}