Search in sources :

Example 1 with AskForMasterMountPoint

use of org.opendaylight.netconf.topology.singleton.messages.AskForMasterMountPoint in project netconf by opendaylight.

the class NetconfNodeActorTest method testAskForMasterMountPoint.

@Test
public void testAskForMasterMountPoint() {
    // Test with master not setup yet.
    final TestKit kit = new TestKit(system);
    masterRef.tell(new AskForMasterMountPoint(kit.getRef()), kit.getRef());
    final Failure failure = kit.expectMsgClass(Failure.class);
    assertTrue(failure.cause() instanceof NotMasterException);
    // Now initialize - master should send the RegisterMountPoint message.
    List<SourceIdentifier> sourceIdentifiers = Lists.newArrayList(RevisionSourceIdentifier.create("testID"));
    initializeMaster(sourceIdentifiers);
    masterRef.tell(new AskForMasterMountPoint(kit.getRef()), kit.getRef());
    final RegisterMountPoint registerMountPoint = kit.expectMsgClass(RegisterMountPoint.class);
    assertEquals(sourceIdentifiers, registerMountPoint.getSourceIndentifiers());
}
Also used : SourceIdentifier(org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier) RevisionSourceIdentifier(org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier) RegisterMountPoint(org.opendaylight.netconf.topology.singleton.messages.RegisterMountPoint) TestKit(akka.testkit.javadsl.TestKit) NotMasterException(org.opendaylight.netconf.topology.singleton.messages.NotMasterException) AskForMasterMountPoint(org.opendaylight.netconf.topology.singleton.messages.AskForMasterMountPoint) Failure(akka.actor.Status.Failure) Test(org.junit.Test)

Example 2 with AskForMasterMountPoint

use of org.opendaylight.netconf.topology.singleton.messages.AskForMasterMountPoint in project netconf by opendaylight.

the class NetconfNodeManagerTest method testSlaveMountPointRegistrationFailuresAndRetries.

@SuppressWarnings("unchecked")
@Test
public void testSlaveMountPointRegistrationFailuresAndRetries() throws InterruptedException, ExecutionException, TimeoutException {
    final NodeId nodeId = new NodeId("device");
    final NodeKey nodeKey = new NodeKey(nodeId);
    final String topologyId = "topology-netconf";
    final InstanceIdentifier<Node> nodeListPath = NetconfTopologyUtils.createTopologyNodeListPath(nodeKey, topologyId);
    final NetconfNode netconfNode = newNetconfNode();
    final Node node = new NodeBuilder().setNodeId(nodeId).addAugmentation(netconfNode).build();
    DataObjectModification<Node> mockDataObjModification = mock(DataObjectModification.class);
    doReturn(Iterables.getLast(nodeListPath.getPathArguments())).when(mockDataObjModification).getIdentifier();
    doReturn(WRITE).when(mockDataObjModification).getModificationType();
    doReturn(node).when(mockDataObjModification).getDataAfter();
    // First try the registration where the perceived master hasn't been initialized as the master.
    netconfNodeManager.onDataTreeChanged(Collections.singletonList(new NetconfTopologyManagerTest.CustomTreeModification(DataTreeIdentifier.create(LogicalDatastoreType.OPERATIONAL, nodeListPath), mockDataObjModification)));
    verify(mockMountPointBuilder, after(1000).never()).register();
    // Initialize the master but drop the initial YangTextSchemaSourceRequest message sent to the master so
    // it retries.
    initializeMaster();
    CompletableFuture<AskForMasterMountPoint> yangTextSchemaSourceRequestFuture = new CompletableFuture<>();
    testMasterActorRef.underlyingActor().messagesToDrop.put(YangTextSchemaSourceRequest.class, yangTextSchemaSourceRequestFuture);
    netconfNodeManager.onDataTreeChanged(Collections.singletonList(new NetconfTopologyManagerTest.CustomTreeModification(DataTreeIdentifier.create(LogicalDatastoreType.OPERATIONAL, nodeListPath), mockDataObjModification)));
    yangTextSchemaSourceRequestFuture.get(5, TimeUnit.SECONDS);
    verify(mockMountPointBuilder, timeout(5000)).register();
    // Initiate another registration but drop the initial AskForMasterMountPoint message sent to the master so
    // it retries.
    setupMountPointMocks();
    CompletableFuture<AskForMasterMountPoint> askForMasterMountPointFuture = new CompletableFuture<>();
    testMasterActorRef.underlyingActor().messagesToDrop.put(AskForMasterMountPoint.class, askForMasterMountPointFuture);
    netconfNodeManager.onDataTreeChanged(Collections.singletonList(new NetconfTopologyManagerTest.CustomTreeModification(DataTreeIdentifier.create(LogicalDatastoreType.OPERATIONAL, nodeListPath), mockDataObjModification)));
    askForMasterMountPointFuture.get(5, TimeUnit.SECONDS);
    verify(mockMountPointReg, timeout(5000)).close();
    verify(mockMountPointBuilder, timeout(5000)).register();
    reset(mockMountPointService, mockMountPointBuilder, mockMountPointReg);
    doNothing().when(mockMountPointReg).close();
    netconfNodeManager.close();
    verify(mockMountPointReg, timeout(5000)).close();
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) NetconfNode(org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode) Node(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node) NodeId(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId) NetconfNode(org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode) NetconfNodeBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNodeBuilder) NodeBuilder(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeBuilder) NodeKey(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey) AskForMasterMountPoint(org.opendaylight.netconf.topology.singleton.messages.AskForMasterMountPoint) Test(org.junit.Test)

Example 3 with AskForMasterMountPoint

use of org.opendaylight.netconf.topology.singleton.messages.AskForMasterMountPoint in project netconf by opendaylight.

the class NetconfNodeActor method handleReceive.

@SuppressWarnings("checkstyle:IllegalCatch")
@Override
public void handleReceive(final Object message) {
    LOG.debug("{}:  received message {}", id, message);
    if (message instanceof CreateInitialMasterActorData) {
        // master
        final CreateInitialMasterActorData masterActorData = (CreateInitialMasterActorData) message;
        sourceIdentifiers = masterActorData.getSourceIndentifiers();
        this.deviceDataBroker = masterActorData.getDeviceDataBroker();
        this.netconfService = masterActorData.getNetconfDataTreeService();
        final DOMDataTreeReadTransaction tx = deviceDataBroker.newReadOnlyTransaction();
        readTxActor = context().actorOf(ReadTransactionActor.props(tx));
        this.deviceRpc = masterActorData.getDeviceRpc();
        this.deviceAction = masterActorData.getDeviceAction();
        sender().tell(new MasterActorDataInitialized(), self());
        LOG.debug("{}: Master is ready.", id);
    } else if (message instanceof RefreshSetupMasterActorData) {
        setup = ((RefreshSetupMasterActorData) message).getNetconfTopologyDeviceSetup();
        id = ((RefreshSetupMasterActorData) message).getRemoteDeviceId();
        sender().tell(new MasterActorDataInitialized(), self());
    } else if (message instanceof AskForMasterMountPoint) {
        // master
        AskForMasterMountPoint askForMasterMountPoint = (AskForMasterMountPoint) message;
        // only master contains reference to deviceDataBroker
        if (deviceDataBroker != null) {
            LOG.debug("{}: Sending RegisterMountPoint reply to {}", id, askForMasterMountPoint.getSlaveActorRef());
            askForMasterMountPoint.getSlaveActorRef().tell(new RegisterMountPoint(sourceIdentifiers, self()), sender());
        } else {
            LOG.warn("{}: Received {} but we don't appear to be the master", id, askForMasterMountPoint);
            sender().tell(new Failure(new NotMasterException(self())), self());
        }
    } else if (message instanceof YangTextSchemaSourceRequest) {
        // master
        final YangTextSchemaSourceRequest yangTextSchemaSourceRequest = (YangTextSchemaSourceRequest) message;
        sendYangTextSchemaSourceProxy(yangTextSchemaSourceRequest.getSourceIdentifier(), sender());
    } else if (message instanceof NewReadTransactionRequest) {
        // master
        sender().tell(new Success(readTxActor), self());
    } else if (message instanceof NewWriteTransactionRequest) {
        // master
        try {
            final DOMDataTreeWriteTransaction tx = deviceDataBroker.newWriteOnlyTransaction();
            final ActorRef txActor = context().actorOf(WriteTransactionActor.props(tx, writeTxIdleTimeout));
            sender().tell(new Success(txActor), self());
        } catch (final Exception t) {
            sender().tell(new Failure(t), self());
        }
    } else if (message instanceof NewReadWriteTransactionRequest) {
        try {
            final DOMDataTreeReadWriteTransaction tx = deviceDataBroker.newReadWriteTransaction();
            final ActorRef txActor = context().actorOf(ReadWriteTransactionActor.props(tx, writeTxIdleTimeout));
            sender().tell(new Success(txActor), self());
        } catch (final Exception t) {
            sender().tell(new Failure(t), self());
        }
    } else if (message instanceof InvokeRpcMessage) {
        // master
        final InvokeRpcMessage invokeRpcMessage = (InvokeRpcMessage) message;
        invokeSlaveRpc(invokeRpcMessage.getSchemaPath().lastNodeIdentifier(), invokeRpcMessage.getNormalizedNodeMessage(), sender());
    } else if (message instanceof InvokeActionMessage) {
        // master
        final InvokeActionMessage invokeActionMessage = (InvokeActionMessage) message;
        LOG.info("InvokeActionMessage Details : {}", invokeActionMessage.toString());
        invokeSlaveAction(invokeActionMessage.getSchemaPath(), invokeActionMessage.getContainerNodeMessage(), invokeActionMessage.getDOMDataTreeIdentifier(), sender());
    } else if (message instanceof RegisterMountPoint) {
        // slaves
        RegisterMountPoint registerMountPoint = (RegisterMountPoint) message;
        sourceIdentifiers = registerMountPoint.getSourceIndentifiers();
        registerSlaveMountPoint(registerMountPoint.getMasterActorRef());
        sender().tell(new Success(null), self());
    } else if (message instanceof UnregisterSlaveMountPoint) {
        // slaves
        unregisterSlaveMountPoint();
    } else if (message instanceof RefreshSlaveActor) {
        // slave
        actorResponseWaitTime = ((RefreshSlaveActor) message).getActorResponseWaitTime();
        id = ((RefreshSlaveActor) message).getId();
        schemaRegistry = ((RefreshSlaveActor) message).getSchemaRegistry();
        setup = ((RefreshSlaveActor) message).getSetup();
        schemaRepository = ((RefreshSlaveActor) message).getSchemaRepository();
    } else if (message instanceof NetconfDataTreeServiceRequest) {
        ActorRef netconfActor = context().actorOf(NetconfDataTreeServiceActor.props(netconfService, writeTxIdleTimeout));
        sender().tell(new Success(netconfActor), self());
    }
}
Also used : NewWriteTransactionRequest(org.opendaylight.netconf.topology.singleton.messages.transactions.NewWriteTransactionRequest) NewReadWriteTransactionRequest(org.opendaylight.netconf.topology.singleton.messages.transactions.NewReadWriteTransactionRequest) CreateInitialMasterActorData(org.opendaylight.netconf.topology.singleton.messages.CreateInitialMasterActorData) ActorRef(akka.actor.ActorRef) DOMDataTreeWriteTransaction(org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction) UnregisterSlaveMountPoint(org.opendaylight.netconf.topology.singleton.messages.UnregisterSlaveMountPoint) NetconfDataTreeServiceRequest(org.opendaylight.netconf.topology.singleton.messages.netconf.NetconfDataTreeServiceRequest) RefreshSetupMasterActorData(org.opendaylight.netconf.topology.singleton.messages.RefreshSetupMasterActorData) AskForMasterMountPoint(org.opendaylight.netconf.topology.singleton.messages.AskForMasterMountPoint) Success(akka.actor.Status.Success) NotMasterException(org.opendaylight.netconf.topology.singleton.messages.NotMasterException) AskTimeoutException(akka.pattern.AskTimeoutException) IOException(java.io.IOException) InvokeRpcMessage(org.opendaylight.netconf.topology.singleton.messages.rpc.InvokeRpcMessage) RefreshSlaveActor(org.opendaylight.netconf.topology.singleton.messages.RefreshSlaveActor) DOMDataTreeReadWriteTransaction(org.opendaylight.mdsal.dom.api.DOMDataTreeReadWriteTransaction) YangTextSchemaSourceRequest(org.opendaylight.netconf.topology.singleton.messages.YangTextSchemaSourceRequest) MasterActorDataInitialized(org.opendaylight.netconf.topology.singleton.messages.MasterActorDataInitialized) NewReadTransactionRequest(org.opendaylight.netconf.topology.singleton.messages.transactions.NewReadTransactionRequest) InvokeActionMessage(org.opendaylight.netconf.topology.singleton.messages.action.InvokeActionMessage) RegisterMountPoint(org.opendaylight.netconf.topology.singleton.messages.RegisterMountPoint) NotMasterException(org.opendaylight.netconf.topology.singleton.messages.NotMasterException) DOMDataTreeReadTransaction(org.opendaylight.mdsal.dom.api.DOMDataTreeReadTransaction) Failure(akka.actor.Status.Failure)

Example 4 with AskForMasterMountPoint

use of org.opendaylight.netconf.topology.singleton.messages.AskForMasterMountPoint in project netconf by opendaylight.

the class NetconfNodeManager method handleSlaveMountPoint.

private synchronized void handleSlaveMountPoint(final DataObjectModification<Node> rootNode) {
    if (closed) {
        return;
    }
    @SuppressWarnings("ConstantConditions") final NetconfNode netconfNodeAfter = rootNode.getDataAfter().augmentation(NetconfNode.class);
    if (NetconfNodeConnectionStatus.ConnectionStatus.Connected.equals(netconfNodeAfter.getConnectionStatus())) {
        lastUpdateCount++;
        createOrUpdateActorRef();
        final String masterAddress = netconfNodeAfter.getClusteredConnectionStatus().getNetconfMasterNode();
        final String masterActorPath = NetconfTopologyUtils.createActorPath(masterAddress, NetconfTopologyUtils.createMasterActorName(id.getName(), netconfNodeAfter.getClusteredConnectionStatus().getNetconfMasterNode()));
        final AskForMasterMountPoint askForMasterMountPoint = new AskForMasterMountPoint(slaveActorRef);
        final ActorSelection masterActor = setup.getActorSystem().actorSelection(masterActorPath);
        LOG.debug("{}: Sending {} message to master {}", id, askForMasterMountPoint, masterActor);
        sendAskForMasterMountPointWithRetries(askForMasterMountPoint, masterActor, 1, lastUpdateCount);
    } else {
        unregisterSlaveMountpoint();
    }
}
Also used : ActorSelection(akka.actor.ActorSelection) NetconfNode(org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode) AskForMasterMountPoint(org.opendaylight.netconf.topology.singleton.messages.AskForMasterMountPoint)

Aggregations

AskForMasterMountPoint (org.opendaylight.netconf.topology.singleton.messages.AskForMasterMountPoint)4 Failure (akka.actor.Status.Failure)2 Test (org.junit.Test)2 NotMasterException (org.opendaylight.netconf.topology.singleton.messages.NotMasterException)2 RegisterMountPoint (org.opendaylight.netconf.topology.singleton.messages.RegisterMountPoint)2 NetconfNode (org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode)2 ActorRef (akka.actor.ActorRef)1 ActorSelection (akka.actor.ActorSelection)1 Success (akka.actor.Status.Success)1 AskTimeoutException (akka.pattern.AskTimeoutException)1 TestKit (akka.testkit.javadsl.TestKit)1 IOException (java.io.IOException)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 DOMDataTreeReadTransaction (org.opendaylight.mdsal.dom.api.DOMDataTreeReadTransaction)1 DOMDataTreeReadWriteTransaction (org.opendaylight.mdsal.dom.api.DOMDataTreeReadWriteTransaction)1 DOMDataTreeWriteTransaction (org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction)1 CreateInitialMasterActorData (org.opendaylight.netconf.topology.singleton.messages.CreateInitialMasterActorData)1 MasterActorDataInitialized (org.opendaylight.netconf.topology.singleton.messages.MasterActorDataInitialized)1 RefreshSetupMasterActorData (org.opendaylight.netconf.topology.singleton.messages.RefreshSetupMasterActorData)1 RefreshSlaveActor (org.opendaylight.netconf.topology.singleton.messages.RefreshSlaveActor)1