Search in sources :

Example 1 with NetconfTopologySetup

use of org.opendaylight.netconf.topology.singleton.impl.utils.NetconfTopologySetup in project netconf by opendaylight.

the class MountPointEndToEndTest method setupSlave.

private void setupSlave() throws Exception {
    AbstractConcurrentDataBrokerTest dataBrokerTest = newDataBrokerTest();
    slaveDataBroker = dataBrokerTest.getDataBroker();
    slaveSystem = ActorSystem.create(ACTOR_SYSTEM_NAME, ConfigFactory.load().getConfig("Slave"));
    doReturn(slaveSystem).when(mockSlaveActorSystemProvider).getActorSystem();
    doReturn(mockSlaveClusterSingletonServiceReg).when(mockSlaveClusterSingletonServiceProvider).registerClusterSingletonService(any());
    slaveNetconfTopologyManager = new NetconfTopologyManager(BASE_SCHEMAS, slaveDataBroker, mockRpcProviderRegistry, mockActionProviderRegistry, mockSlaveClusterSingletonServiceProvider, mockKeepaliveExecutor, mockThreadPool, mockSlaveActorSystemProvider, eventExecutor, mockClientDispatcher, TOPOLOGY_ID, config, slaveMountPointService, mockEncryptionService, mockRpcProviderService, deviceActionFactory, resourceManager) {

        @Override
        protected NetconfTopologyContext newNetconfTopologyContext(final NetconfTopologySetup setup, final ServiceGroupIdentifier serviceGroupIdent, final Timeout actorResponseWaitTime, final DeviceActionFactory actionFactory) {
            NetconfTopologyContext spiedContext = spy(super.newNetconfTopologyContext(setup, serviceGroupIdent, actorResponseWaitTime, actionFactory));
            slaveNetconfTopologyContextFuture.set(spiedContext);
            return spiedContext;
        }
    };
    slaveNetconfTopologyManager.init();
    verifyTopologyNodesCreated(slaveDataBroker);
    slaveTxChain = slaveDataBroker.createTransactionChain(new TransactionChainListener() {

        @Override
        public void onTransactionChainSuccessful(final TransactionChain chain) {
        }

        @Override
        public void onTransactionChainFailed(final TransactionChain chain, final Transaction transaction, final Throwable cause) {
            LOG.error("Slave transaction chain failed", cause);
        }
    });
}
Also used : TransactionChainListener(org.opendaylight.mdsal.binding.api.TransactionChainListener) WriteTransaction(org.opendaylight.mdsal.binding.api.WriteTransaction) DOMDataTreeWriteTransaction(org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction) ReadTransaction(org.opendaylight.mdsal.binding.api.ReadTransaction) DOMDataTreeReadWriteTransaction(org.opendaylight.mdsal.dom.api.DOMDataTreeReadWriteTransaction) Transaction(org.opendaylight.mdsal.binding.api.Transaction) Timeout(akka.util.Timeout) TransactionChain(org.opendaylight.mdsal.binding.api.TransactionChain) ServiceGroupIdentifier(org.opendaylight.mdsal.singleton.common.api.ServiceGroupIdentifier) DeviceActionFactory(org.opendaylight.netconf.sal.connect.api.DeviceActionFactory) AbstractConcurrentDataBrokerTest(org.opendaylight.mdsal.binding.dom.adapter.test.AbstractConcurrentDataBrokerTest) NetconfTopologySetup(org.opendaylight.netconf.topology.singleton.impl.utils.NetconfTopologySetup)

Example 2 with NetconfTopologySetup

use of org.opendaylight.netconf.topology.singleton.impl.utils.NetconfTopologySetup in project netconf by opendaylight.

the class NetconfTopologyManagerTest method testOnDataTreeChanged.

@SuppressWarnings("unchecked")
@Test
public void testOnDataTreeChanged() throws Exception {
    // Notify of 2 created Node objects.
    final NodeId nodeId1 = new NodeId("node-id-1");
    final InstanceIdentifier<Node> nodeInstanceId1 = NetconfTopologyUtils.createTopologyNodeListPath(new NodeKey(nodeId1), TOPOLOGY_ID);
    final NodeId nodeId2 = new NodeId("node-id-2");
    final InstanceIdentifier<Node> nodeInstanceId2 = NetconfTopologyUtils.createTopologyNodeListPath(new NodeKey(nodeId2), TOPOLOGY_ID);
    final NetconfNode netconfNode1 = new NetconfNodeBuilder().setHost(new Host(new IpAddress(new Ipv4Address("127.0.0.1")))).setPort(new PortNumber(Uint16.valueOf(1111))).setActorResponseWaitTime(ACTOR_RESPONSE_WAIT_TIME).build();
    final Node node1 = new NodeBuilder().setNodeId(nodeId1).addAugmentation(netconfNode1).build();
    final DataObjectModification<Node> dataObjectModification1 = mock(DataObjectModification.class);
    doReturn(WRITE).when(dataObjectModification1).getModificationType();
    doReturn(node1).when(dataObjectModification1).getDataAfter();
    doReturn(InstanceIdentifier.IdentifiableItem.of(Node.class, new NodeKey(nodeId1))).when(dataObjectModification1).getIdentifier();
    final NetconfNode netconfNode2 = new NetconfNodeBuilder().setHost(new Host(new IpAddress(new Ipv4Address("127.0.0.1")))).setPort(new PortNumber(Uint16.valueOf(2222))).setActorResponseWaitTime(ACTOR_RESPONSE_WAIT_TIME).build();
    final Node node2 = new NodeBuilder().setNodeId(nodeId2).addAugmentation(netconfNode2).build();
    final DataObjectModification<Node> dataObjectModification2 = mock(DataObjectModification.class);
    doReturn(WRITE).when(dataObjectModification2).getModificationType();
    doReturn(node2).when(dataObjectModification2).getDataAfter();
    doReturn(InstanceIdentifier.IdentifiableItem.of(Node.class, new NodeKey(nodeId2))).when(dataObjectModification2).getIdentifier();
    final NetconfTopologyContext mockContext1 = mock(NetconfTopologyContext.class);
    mockContextMap.put(nodeInstanceId1, setup -> {
        assertEquals(node1, setup.getNode());
        assertEquals(TOPOLOGY_ID, setup.getTopologyId());
        return mockContext1;
    });
    final NetconfTopologyContext mockContext2 = mock(NetconfTopologyContext.class);
    mockContextMap.put(nodeInstanceId2, setup -> {
        assertEquals(node2, setup.getNode());
        assertEquals(TOPOLOGY_ID, setup.getTopologyId());
        return mockContext2;
    });
    ClusterSingletonServiceRegistration mockClusterRegistration1 = mock(ClusterSingletonServiceRegistration.class);
    ClusterSingletonServiceRegistration mockClusterRegistration2 = mock(ClusterSingletonServiceRegistration.class);
    doReturn(mockClusterRegistration1).when(clusterSingletonServiceProvider).registerClusterSingletonService(mockContext1);
    doReturn(mockClusterRegistration2).when(clusterSingletonServiceProvider).registerClusterSingletonService(mockContext2);
    netconfTopologyManager.onDataTreeChanged(Arrays.asList(new CustomTreeModification(DataTreeIdentifier.create(LogicalDatastoreType.CONFIGURATION, nodeInstanceId1), dataObjectModification1), new CustomTreeModification(DataTreeIdentifier.create(LogicalDatastoreType.CONFIGURATION, nodeInstanceId2), dataObjectModification2)));
    verify(clusterSingletonServiceProvider).registerClusterSingletonService(mockContext1);
    verify(clusterSingletonServiceProvider).registerClusterSingletonService(mockContext2);
    // Notify of Node 1 replaced and Node 2 subtree modified.
    mockContextMap.clear();
    final NetconfNode updatedNetconfNode1 = new NetconfNodeBuilder(netconfNode1).setPort(new PortNumber(Uint16.valueOf(33333))).build();
    final Node updatedNode1 = new NodeBuilder().setNodeId(nodeId1).addAugmentation(updatedNetconfNode1).build();
    doReturn(WRITE).when(dataObjectModification1).getModificationType();
    doReturn(updatedNode1).when(dataObjectModification1).getDataAfter();
    doReturn(SUBTREE_MODIFIED).when(dataObjectModification2).getModificationType();
    doReturn(node2).when(dataObjectModification2).getDataAfter();
    doNothing().when(mockContext1).refresh(any());
    doNothing().when(mockContext2).refresh(any());
    netconfTopologyManager.onDataTreeChanged(Arrays.asList(new CustomTreeModification(DataTreeIdentifier.create(LogicalDatastoreType.CONFIGURATION, nodeInstanceId1), dataObjectModification1), new CustomTreeModification(DataTreeIdentifier.create(LogicalDatastoreType.CONFIGURATION, nodeInstanceId2), dataObjectModification2)));
    ArgumentCaptor<NetconfTopologySetup> mockContext1Setup = ArgumentCaptor.forClass(NetconfTopologySetup.class);
    verify(mockContext1).refresh(mockContext1Setup.capture());
    assertEquals(updatedNode1, mockContext1Setup.getValue().getNode());
    verify(mockContext2).refresh(any());
    verifyNoMoreInteractions(clusterSingletonServiceProvider);
    // Notify of Node 1 deleted.
    doReturn(DELETE).when(dataObjectModification1).getModificationType();
    netconfTopologyManager.onDataTreeChanged(Arrays.asList(new CustomTreeModification(DataTreeIdentifier.create(LogicalDatastoreType.CONFIGURATION, nodeInstanceId1), dataObjectModification1)));
    verify(mockClusterRegistration1).close();
    verify(mockContext1).close();
    verifyNoMoreInteractions(clusterSingletonServiceProvider, mockClusterRegistration2, mockContext2);
    // Notify of Node 1 created again.
    reset(clusterSingletonServiceProvider);
    final NetconfTopologyContext newMockContext1 = mock(NetconfTopologyContext.class);
    final ClusterSingletonServiceRegistration newMockClusterRegistration1 = mock(ClusterSingletonServiceRegistration.class);
    doThrow(new RuntimeException("mock error")).doReturn(newMockClusterRegistration1).when(clusterSingletonServiceProvider).registerClusterSingletonService(newMockContext1);
    doReturn(WRITE).when(dataObjectModification1).getModificationType();
    doReturn(node1).when(dataObjectModification1).getDataAfter();
    mockContextMap.put(nodeInstanceId1, setup -> {
        assertEquals(node1, setup.getNode());
        assertEquals(TOPOLOGY_ID, setup.getTopologyId());
        return newMockContext1;
    });
    netconfTopologyManager.onDataTreeChanged(Arrays.asList(new CustomTreeModification(DataTreeIdentifier.create(LogicalDatastoreType.CONFIGURATION, nodeInstanceId1), dataObjectModification1)));
    verify(clusterSingletonServiceProvider, times(2)).registerClusterSingletonService(newMockContext1);
    verifyNoMoreInteractions(mockClusterRegistration1, mockContext1, mockClusterRegistration2, mockContext2, newMockContext1, newMockClusterRegistration1, clusterSingletonServiceProvider);
    // Test close.
    netconfTopologyManager.close();
    verify(newMockClusterRegistration1).close();
    verify(newMockContext1).close();
    verify(mockClusterRegistration2).close();
    verify(mockContext2).close();
    netconfTopologyManager.close();
    verifyNoMoreInteractions(mockClusterRegistration1, mockContext1, mockClusterRegistration2, mockContext2, newMockContext1, newMockClusterRegistration1, clusterSingletonServiceProvider);
}
Also used : NetconfNodeBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNodeBuilder) 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) NetconfNode(org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode) Host(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Host) 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) NetconfTopologySetup(org.opendaylight.netconf.topology.singleton.impl.utils.NetconfTopologySetup) ClusterSingletonServiceRegistration(org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceRegistration) NodeId(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId) IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress) PortNumber(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber) NodeKey(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey) Ipv4Address(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address) AbstractDataBrokerTest(org.opendaylight.mdsal.binding.dom.adapter.test.AbstractDataBrokerTest) Test(org.junit.Test)

Example 3 with NetconfTopologySetup

use of org.opendaylight.netconf.topology.singleton.impl.utils.NetconfTopologySetup in project netconf by opendaylight.

the class NetconfNodeActorTest method testRegisterMountPointWithSchemaFailures.

@SuppressWarnings("unchecked")
@Test
public void testRegisterMountPointWithSchemaFailures() throws Exception {
    SchemaResourcesDTO schemaResourceDTO2 = mock(SchemaResourcesDTO.class);
    doReturn(mockRegistry).when(schemaResourceDTO2).getSchemaRegistry();
    doReturn(mockSchemaRepository).when(schemaResourceDTO2).getSchemaRepository();
    final NetconfTopologySetup setup = NetconfTopologySetupBuilder.create().setSchemaResourceDTO(schemaResourceDTO2).setBaseSchemas(BASE_SCHEMAS).setActorSystem(system).build();
    final ActorRef slaveRef = system.actorOf(NetconfNodeActor.props(setup, remoteDeviceId, TIMEOUT, mockMountPointService));
    // Test unrecoverable failure.
    doReturn(Futures.immediateFailedFuture(new SchemaResolutionException("mock"))).when(mockSchemaContextFactory).createEffectiveModelContext(anyCollection());
    slaveRef.tell(new RegisterMountPoint(ImmutableList.of(SOURCE_IDENTIFIER1, SOURCE_IDENTIFIER2), masterRef), testKit.getRef());
    testKit.expectMsgClass(Success.class);
    verify(mockRegistry, timeout(5000)).registerSchemaSource(any(), withSourceId(SOURCE_IDENTIFIER1));
    verify(mockRegistry, timeout(5000)).registerSchemaSource(any(), withSourceId(SOURCE_IDENTIFIER2));
    verify(mockMountPointBuilder, after(1000).never()).register();
    verify(mockSchemaSourceReg1, timeout(1000)).close();
    verify(mockSchemaSourceReg2, timeout(1000)).close();
    // Test recoverable AskTimeoutException - schema context resolution should be retried.
    reset(mockSchemaSourceReg1, mockSchemaSourceReg2);
    doReturn(Futures.immediateFailedFuture(new SchemaResolutionException("mock", new AskTimeoutException("timeout")))).doReturn(Futures.immediateFuture(mockSchemaContext)).when(mockSchemaContextFactory).createEffectiveModelContext(anyCollection());
    slaveRef.tell(new RegisterMountPoint(ImmutableList.of(SOURCE_IDENTIFIER1, SOURCE_IDENTIFIER2), masterRef), testKit.getRef());
    testKit.expectMsgClass(Success.class);
    verify(mockMountPointBuilder, timeout(5000)).register();
    verifyNoMoreInteractions(mockSchemaSourceReg1, mockSchemaSourceReg2);
    // Test AskTimeoutException with an interleaved successful registration. The first schema context resolution
    // attempt should not be retried.
    reset(mockSchemaSourceReg1, mockSchemaSourceReg2, mockSchemaRepository, mockSchemaContextFactory);
    resetMountPointMocks();
    final EffectiveModelContextFactory mockSchemaContextFactorySuccess = mock(EffectiveModelContextFactory.class);
    doReturn(Futures.immediateFuture(mockSchemaContext)).when(mockSchemaContextFactorySuccess).createEffectiveModelContext(anyCollection());
    doAnswer(unused -> {
        SettableFuture<SchemaContext> future = SettableFuture.create();
        new Thread(() -> {
            doReturn(mockSchemaContextFactorySuccess).when(mockSchemaRepository).createEffectiveModelContextFactory();
            slaveRef.tell(new RegisterMountPoint(ImmutableList.of(SOURCE_IDENTIFIER1, SOURCE_IDENTIFIER2), masterRef), testKit.getRef());
            future.setException(new SchemaResolutionException("mock", new AskTimeoutException("timeout")));
        }).start();
        return future;
    }).when(mockSchemaContextFactory).createEffectiveModelContext(anyCollection());
    doReturn(mockSchemaContextFactory).when(mockSchemaRepository).createEffectiveModelContextFactory();
    slaveRef.tell(new RegisterMountPoint(ImmutableList.of(SOURCE_IDENTIFIER1, SOURCE_IDENTIFIER2), masterRef), testKit.getRef());
    verify(mockMountPointBuilder, timeout(5000)).register();
    verify(mockSchemaRepository, times(2)).createEffectiveModelContextFactory();
}
Also used : SchemaResolutionException(org.opendaylight.yangtools.yang.model.repo.api.SchemaResolutionException) ActorRef(akka.actor.ActorRef) TestActorRef(akka.testkit.TestActorRef) EffectiveModelContextFactory(org.opendaylight.yangtools.yang.model.repo.api.EffectiveModelContextFactory) RegisterMountPoint(org.opendaylight.netconf.topology.singleton.messages.RegisterMountPoint) AskTimeoutException(akka.pattern.AskTimeoutException) SchemaContext(org.opendaylight.yangtools.yang.model.api.SchemaContext) SchemaResourcesDTO(org.opendaylight.netconf.sal.connect.netconf.NetconfDevice.SchemaResourcesDTO) NetconfTopologySetup(org.opendaylight.netconf.topology.singleton.impl.utils.NetconfTopologySetup) Test(org.junit.Test)

Example 4 with NetconfTopologySetup

use of org.opendaylight.netconf.topology.singleton.impl.utils.NetconfTopologySetup in project netconf by opendaylight.

the class NetconfNodeActorTest method testMissingSchemaSourceOnMissingProvider.

@Test(expected = MissingSchemaSourceException.class)
public void testMissingSchemaSourceOnMissingProvider() throws Exception {
    final SharedSchemaRepository repository = new SharedSchemaRepository("test");
    SchemaResourcesDTO schemaResourceDTO2 = mock(SchemaResourcesDTO.class);
    doReturn(repository).when(schemaResourceDTO2).getSchemaRegistry();
    doReturn(repository).when(schemaResourceDTO2).getSchemaRepository();
    final NetconfTopologySetup setup = NetconfTopologySetupBuilder.create().setActorSystem(system).setSchemaResourceDTO(schemaResourceDTO2).setIdleTimeout(Duration.apply(1, TimeUnit.SECONDS)).setBaseSchemas(BASE_SCHEMAS).build();
    final Props props = NetconfNodeActor.props(setup, remoteDeviceId, TIMEOUT, mockMountPointService);
    ActorRef actor = TestActorRef.create(system, props, "master_messages_2");
    final SourceIdentifier sourceIdentifier = RevisionSourceIdentifier.create("testID");
    final ProxyYangTextSourceProvider proxyYangProvider = new ProxyYangTextSourceProvider(actor, system.dispatcher(), TIMEOUT);
    final Future<YangTextSchemaSourceSerializationProxy> resolvedSchemaFuture = proxyYangProvider.getYangTextSchemaSource(sourceIdentifier);
    Await.result(resolvedSchemaFuture, TIMEOUT.duration());
}
Also used : ActorRef(akka.actor.ActorRef) TestActorRef(akka.testkit.TestActorRef) SourceIdentifier(org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier) RevisionSourceIdentifier(org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier) YangTextSchemaSourceSerializationProxy(org.opendaylight.controller.cluster.schema.provider.impl.YangTextSchemaSourceSerializationProxy) Props(akka.actor.Props) SharedSchemaRepository(org.opendaylight.yangtools.yang.parser.repo.SharedSchemaRepository) SchemaResourcesDTO(org.opendaylight.netconf.sal.connect.netconf.NetconfDevice.SchemaResourcesDTO) NetconfTopologySetup(org.opendaylight.netconf.topology.singleton.impl.utils.NetconfTopologySetup) Test(org.junit.Test)

Example 5 with NetconfTopologySetup

use of org.opendaylight.netconf.topology.singleton.impl.utils.NetconfTopologySetup in project netconf by opendaylight.

the class NetconfNodeActorTest method testInitializeAndRefreshMasterData.

@Test
public void testInitializeAndRefreshMasterData() {
    // Test CreateInitialMasterActorData.
    initializeMaster(new ArrayList<>());
    // Test RefreshSetupMasterActorData.
    final RemoteDeviceId newRemoteDeviceId = new RemoteDeviceId("netconf-topology2", new InetSocketAddress(InetAddresses.forString("127.0.0.2"), 9999));
    final NetconfTopologySetup newSetup = NetconfTopologySetupBuilder.create().setBaseSchemas(BASE_SCHEMAS).setSchemaResourceDTO(schemaResourceDTO).setActorSystem(system).build();
    masterRef.tell(new RefreshSetupMasterActorData(newSetup, newRemoteDeviceId), testKit.getRef());
    testKit.expectMsgClass(MasterActorDataInitialized.class);
}
Also used : RemoteDeviceId(org.opendaylight.netconf.sal.connect.util.RemoteDeviceId) InetSocketAddress(java.net.InetSocketAddress) RefreshSetupMasterActorData(org.opendaylight.netconf.topology.singleton.messages.RefreshSetupMasterActorData) NetconfTopologySetup(org.opendaylight.netconf.topology.singleton.impl.utils.NetconfTopologySetup) Test(org.junit.Test)

Aggregations

NetconfTopologySetup (org.opendaylight.netconf.topology.singleton.impl.utils.NetconfTopologySetup)9 Test (org.junit.Test)6 Timeout (akka.util.Timeout)4 Before (org.junit.Before)4 Props (akka.actor.Props)3 TestActorRef (akka.testkit.TestActorRef)3 InetSocketAddress (java.net.InetSocketAddress)3 DOMMountPointService (org.opendaylight.mdsal.dom.api.DOMMountPointService)3 SchemaResourcesDTO (org.opendaylight.netconf.sal.connect.netconf.NetconfDevice.SchemaResourcesDTO)3 RemoteDeviceId (org.opendaylight.netconf.sal.connect.util.RemoteDeviceId)3 RevisionSourceIdentifier (org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier)3 ActorRef (akka.actor.ActorRef)2 ActorSystem (akka.actor.ActorSystem)2 TestKit (akka.testkit.javadsl.TestKit)2 ImmutableList (com.google.common.collect.ImmutableList)2 Futures (com.google.common.util.concurrent.Futures)2 ConfigFactory (com.typesafe.config.ConfigFactory)2 EventExecutor (io.netty.util.concurrent.EventExecutor)2 Map (java.util.Map)2 ExecutionException (java.util.concurrent.ExecutionException)2