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);
}
});
}
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);
}
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();
}
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());
}
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);
}
Aggregations