Search in sources :

Example 1 with UnregisterSlaveMountPoint

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

the class NetconfNodeActorTest method testRegisterAndUnregisterMountPoint.

@Test
public void testRegisterAndUnregisterMountPoint() throws Exception {
    ActorRef slaveRef = registerSlaveMountPoint();
    // Unregister
    slaveRef.tell(new UnregisterSlaveMountPoint(), testKit.getRef());
    verify(mockMountPointReg, timeout(5000)).close();
    verify(mockSchemaSourceReg1, timeout(1000)).close();
    verify(mockSchemaSourceReg2, timeout(1000)).close();
    // Test registration with another interleaved registration that completes while the first registration
    // is resolving the schema context.
    reset(mockSchemaSourceReg1, mockRegistry, mockSchemaRepository);
    resetMountPointMocks();
    doReturn(mockSchemaSourceReg1).when(mockRegistry).registerSchemaSource(any(), withSourceId(SOURCE_IDENTIFIER1));
    final SchemaSourceRegistration<?> newMockSchemaSourceReg = mock(SchemaSourceRegistration.class);
    final EffectiveModelContextFactory newMockSchemaContextFactory = mock(EffectiveModelContextFactory.class);
    doReturn(Futures.immediateFuture(mockSchemaContext)).when(newMockSchemaContextFactory).createEffectiveModelContext(anyCollection());
    doAnswer(unused -> {
        SettableFuture<SchemaContext> future = SettableFuture.create();
        new Thread(() -> {
            doReturn(newMockSchemaSourceReg).when(mockRegistry).registerSchemaSource(any(), withSourceId(SOURCE_IDENTIFIER1));
            doReturn(newMockSchemaContextFactory).when(mockSchemaRepository).createEffectiveModelContextFactory();
            slaveRef.tell(new RegisterMountPoint(ImmutableList.of(SOURCE_IDENTIFIER1), masterRef), testKit.getRef());
            future.set(mockSchemaContext);
        }).start();
        return future;
    }).when(mockSchemaContextFactory).createEffectiveModelContext(anyCollection());
    doReturn(mockSchemaContextFactory).when(mockSchemaRepository).createEffectiveModelContextFactory();
    slaveRef.tell(new RegisterMountPoint(ImmutableList.of(SOURCE_IDENTIFIER1), masterRef), testKit.getRef());
    verify(mockMountPointBuilder, timeout(5000)).register();
    verify(mockMountPointBuilder, after(500)).addService(eq(DOMDataBroker.class), any());
    verify(mockMountPointBuilder).addService(eq(DOMRpcService.class), any());
    verify(mockMountPointBuilder).addService(eq(DOMActionService.class), any());
    verify(mockMountPointBuilder).addService(eq(DOMNotificationService.class), any());
    verify(mockMountPointBuilder).addService(eq(DOMSchemaService.class), any());
    verify(mockSchemaSourceReg1).close();
    verify(mockRegistry, times(2)).registerSchemaSource(any(), withSourceId(SOURCE_IDENTIFIER1));
    verify(mockSchemaRepository, times(2)).createEffectiveModelContextFactory();
    verifyNoMoreInteractions(mockMountPointBuilder, newMockSchemaSourceReg);
    // Stop the slave actor and verify schema source registrations are closed.
    final Future<Boolean> stopFuture = Patterns.gracefulStop(slaveRef, TIMEOUT.duration());
    Await.result(stopFuture, TIMEOUT.duration());
    verify(mockMountPointReg).close();
    verify(newMockSchemaSourceReg).close();
}
Also used : DOMRpcService(org.opendaylight.mdsal.dom.api.DOMRpcService) ActorRef(akka.actor.ActorRef) TestActorRef(akka.testkit.TestActorRef) UnregisterSlaveMountPoint(org.opendaylight.netconf.topology.singleton.messages.UnregisterSlaveMountPoint) EffectiveModelContextFactory(org.opendaylight.yangtools.yang.model.repo.api.EffectiveModelContextFactory) DOMNotificationService(org.opendaylight.mdsal.dom.api.DOMNotificationService) DOMActionService(org.opendaylight.mdsal.dom.api.DOMActionService) RegisterMountPoint(org.opendaylight.netconf.topology.singleton.messages.RegisterMountPoint) SchemaContext(org.opendaylight.yangtools.yang.model.api.SchemaContext) DOMDataBroker(org.opendaylight.mdsal.dom.api.DOMDataBroker) DOMSchemaService(org.opendaylight.mdsal.dom.api.DOMSchemaService) Test(org.junit.Test)

Example 2 with UnregisterSlaveMountPoint

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

the class NetconfNodeManager method unregisterSlaveMountpoint.

private synchronized void unregisterSlaveMountpoint() {
    lastUpdateCount++;
    if (slaveActorRef != null) {
        LOG.debug("{}: Sending message to unregister slave mountpoint to {}", id, slaveActorRef);
        slaveActorRef.tell(new UnregisterSlaveMountPoint(), ActorRef.noSender());
    }
}
Also used : UnregisterSlaveMountPoint(org.opendaylight.netconf.topology.singleton.messages.UnregisterSlaveMountPoint)

Example 3 with UnregisterSlaveMountPoint

use of org.opendaylight.netconf.topology.singleton.messages.UnregisterSlaveMountPoint 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)

Aggregations

UnregisterSlaveMountPoint (org.opendaylight.netconf.topology.singleton.messages.UnregisterSlaveMountPoint)3 ActorRef (akka.actor.ActorRef)2 RegisterMountPoint (org.opendaylight.netconf.topology.singleton.messages.RegisterMountPoint)2 Failure (akka.actor.Status.Failure)1 Success (akka.actor.Status.Success)1 AskTimeoutException (akka.pattern.AskTimeoutException)1 TestActorRef (akka.testkit.TestActorRef)1 IOException (java.io.IOException)1 Test (org.junit.Test)1 DOMActionService (org.opendaylight.mdsal.dom.api.DOMActionService)1 DOMDataBroker (org.opendaylight.mdsal.dom.api.DOMDataBroker)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 DOMNotificationService (org.opendaylight.mdsal.dom.api.DOMNotificationService)1 DOMRpcService (org.opendaylight.mdsal.dom.api.DOMRpcService)1 DOMSchemaService (org.opendaylight.mdsal.dom.api.DOMSchemaService)1 AskForMasterMountPoint (org.opendaylight.netconf.topology.singleton.messages.AskForMasterMountPoint)1 CreateInitialMasterActorData (org.opendaylight.netconf.topology.singleton.messages.CreateInitialMasterActorData)1 MasterActorDataInitialized (org.opendaylight.netconf.topology.singleton.messages.MasterActorDataInitialized)1