import static java.util.Objects.requireNonNull;
import static org.opendaylight.protocol.bmp.impl.app.KeyConstructorUtil.constructKeys;
-import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import com.google.common.net.InetAddresses;
import com.google.common.util.concurrent.ListenableFuture;
import java.net.InetSocketAddress;
import java.util.List;
import javax.annotation.Nonnull;
-import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonService;
-import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceRegistration;
-import org.opendaylight.mdsal.singleton.common.api.ServiceGroupIdentifier;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
+import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonService;
+import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceRegistration;
+import org.opendaylight.mdsal.singleton.common.api.ServiceGroupIdentifier;
import org.opendaylight.protocol.bmp.api.BmpDispatcher;
import org.opendaylight.protocol.bmp.impl.config.BmpDeployerDependencies;
import org.opendaylight.protocol.bmp.impl.spi.BmpMonitoringStation;
private static final QName MONITOR_ID_QNAME = QName.create(Monitor.QNAME, "monitor-id").intern();
private static final ServiceGroupIdentifier SERVICE_GROUP_IDENTIFIER =
- ServiceGroupIdentifier.create("bmp-monitors-service-group");
+ ServiceGroupIdentifier.create("bmp-monitors-service-group");
private final DOMDataBroker domDataBroker;
private final InetSocketAddress address;
private ClusterSingletonServiceRegistration singletonServiceRegistration;
public BmpMonitoringStationImpl(final BmpDeployerDependencies bmpDeployerDependencies,
- final BmpDispatcher dispatcher, final MonitorId monitorId, final InetSocketAddress address,
- final List<MonitoredRouter> mrs) {
+ final BmpDispatcher dispatcher, final MonitorId monitorId, final InetSocketAddress address,
+ final List<MonitoredRouter> mrs) {
this.domDataBroker = requireNonNull(bmpDeployerDependencies.getDomDataBroker());
this.dispatcher = requireNonNull(dispatcher);
this.monitorId = monitorId;
this.address = requireNonNull(address);
this.yangMonitorId = YangInstanceIdentifier.builder()
- .node(BmpMonitor.QNAME).node(Monitor.QNAME)
- .nodeWithKey(Monitor.QNAME, MONITOR_ID_QNAME, monitorId.getValue()).build();
+ .node(BmpMonitor.QNAME).node(Monitor.QNAME)
+ .nodeWithKey(Monitor.QNAME, MONITOR_ID_QNAME, monitorId.getValue()).build();
this.sessionManager = new RouterSessionManager(this.yangMonitorId, this.domDataBroker,
- bmpDeployerDependencies.getExtensions(), bmpDeployerDependencies.getTree());
+ bmpDeployerDependencies.getExtensions(), bmpDeployerDependencies.getTree());
LOG.info("BMP Monitor Singleton Service {} registered, Monitor Id {}",
- getIdentifier().getValue(), this.monitorId.getValue());
+ getIdentifier().getValue(), this.monitorId.getValue());
this.singletonServiceRegistration = bmpDeployerDependencies.getClusterSingletonProvider()
- .registerClusterSingletonService(this);
+ .registerClusterSingletonService(this);
}
@Override
public synchronized void instantiateServiceInstance() {
LOG.info("BMP Monitor Singleton Service {} instantiated, Monitor Id {}",
- getIdentifier().getValue(), this.monitorId.getValue());
+ getIdentifier().getValue(), this.monitorId.getValue());
final ChannelFuture channelFuture = this.dispatcher.createServer(this.address, this.sessionManager,
- constructKeys(this.monitoredRouters));
+ constructKeys(this.monitoredRouters));
try {
this.channel = channelFuture.sync().channel();
createEmptyMonitor();
@Override
public synchronized ListenableFuture<Void> closeServiceInstance() {
LOG.info("BMP Monitor Singleton Service {} instance closed, Monitor Id {}",
- getIdentifier().getValue(), this.monitorId.getValue());
+ getIdentifier().getValue(), this.monitorId.getValue());
this.channel.close().addListener((ChannelFutureListener) future -> {
Preconditions.checkArgument(future.isSuccess(), "Channel failed to close: %s", future.cause());
BmpMonitoringStationImpl.this.sessionManager.close();
final Rfc2385Key rfc2385KeyPassword = mr.getPassword();
ret = KeyMapping.getKeyMapping(addr, rfc2385KeyPassword.getValue());
dispatcher.createClient(Ipv4Util.toInetSocketAddress(mr.getAddress(), mr.getPort()),
- this.sessionManager, Optional.fromNullable(ret));
+ this.sessionManager, ret);
}
}
}
private synchronized void createEmptyMonitor() {
final DOMDataWriteTransaction wTx = this.domDataBroker.newWriteOnlyTransaction();
wTx.put(LogicalDatastoreType.OPERATIONAL,
- YangInstanceIdentifier.builder().node(BmpMonitor.QNAME).node(Monitor.QNAME)
- .nodeWithKey(Monitor.QNAME, MONITOR_ID_QNAME, this.monitorId.getValue()).build(),
- ImmutableNodes.mapEntryBuilder(Monitor.QNAME, MONITOR_ID_QNAME, this.monitorId.getValue())
- .addChild(ImmutableNodes.leafNode(MONITOR_ID_QNAME, this.monitorId.getValue()))
- .addChild(ImmutableNodes.mapNodeBuilder(Router.QNAME).build())
- .build());
+ YangInstanceIdentifier.builder().node(BmpMonitor.QNAME).node(Monitor.QNAME)
+ .nodeWithKey(Monitor.QNAME, MONITOR_ID_QNAME, this.monitorId.getValue()).build(),
+ ImmutableNodes.mapEntryBuilder(Monitor.QNAME, MONITOR_ID_QNAME, this.monitorId.getValue())
+ .addChild(ImmutableNodes.leafNode(MONITOR_ID_QNAME, this.monitorId.getValue()))
+ .addChild(ImmutableNodes.mapNodeBuilder(Router.QNAME).build())
+ .build());
try {
wTx.submit().checkedGet();
} catch (final TransactionCommitFailedException e) {
import static org.opendaylight.protocol.util.CheckUtil.checkEquals;
import static org.opendaylight.protocol.util.CheckUtil.waitFutureSuccess;
-import com.google.common.base.Optional;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelHandlerContext;
import org.opendaylight.protocol.bmp.parser.BmpActivator;
import org.opendaylight.protocol.bmp.spi.registry.BmpMessageRegistry;
import org.opendaylight.protocol.bmp.spi.registry.SimpleBmpExtensionProviderContext;
+import org.opendaylight.protocol.concepts.KeyMapping;
public class BmpDispatcherImplTest {
final BmpMessageRegistry messageRegistry = ctx.getBmpMessageRegistry();
this.dispatcher = new BmpDispatcherImpl(new NioEventLoopGroup(), new NioEventLoopGroup(),
- messageRegistry, (channel, sessionListenerFactory) -> BmpDispatcherImplTest.this.mockedSession);
+ messageRegistry, (channel, sessionListenerFactory) -> BmpDispatcherImplTest.this.mockedSession);
}
@After
@Test
public void testCreateServer() throws Exception {
final ChannelFuture futureServer = this.dispatcher.createServer(SERVER,
- this.mockedListenerFactory, Optional.absent());
+ this.mockedListenerFactory, KeyMapping.getKeyMapping());
waitFutureSuccess(futureServer);
final Channel serverChannel = futureServer.channel();
- checkEquals(()-> assertTrue(serverChannel.isActive()));
+ checkEquals(() -> assertTrue(serverChannel.isActive()));
final ChannelFuture futureClient = this.dispatcher.createClient(CLIENT_REMOTE,
- this.mockedListenerFactory, Optional.absent());
+ this.mockedListenerFactory, KeyMapping.getKeyMapping());
waitFutureSuccess(futureClient);
final Channel clientChannel = futureClient.channel();
- checkEquals(()-> assertTrue(clientChannel.isActive()));
+ checkEquals(() -> assertTrue(clientChannel.isActive()));
verify(this.mockedSession, timeout(500).times(2)).handlerAdded(any(ChannelHandlerContext.class));
verify(this.mockedSession, timeout(500).times(2)).channelRegistered(any(ChannelHandlerContext.class));
verify(this.mockedSession, timeout(500).times(2)).channelActive(any(ChannelHandlerContext.class));
package org.opendaylight.protocol.bmp.api;
-import com.google.common.base.Optional;
import io.netty.channel.ChannelFuture;
import java.net.InetSocketAddress;
+import javax.annotation.Nonnull;
import org.opendaylight.protocol.concepts.KeyMapping;
/**
* Dispatcher class for creating servers and clients.
*/
public interface BmpDispatcher extends AutoCloseable {
-
- /**
- * Creates server. Each server needs three factories to pass their instances to client sessions.
- *
- * @param address to be bound with the server
- * @param slf bmp session listener factory
- * @param keys RFC2385 key mapping
- * @return instance of BmpServer
- */
- @Deprecated
- default ChannelFuture createServer(InetSocketAddress address, BmpSessionListenerFactory slf, Optional<KeyMapping> keys) {
- if(keys.isPresent()) {
- return createServer(address, slf, keys.get());
- }
- return createServer(address, slf, KeyMapping.getKeyMapping());
- }
-
- /**
- * Creates reconnect clients. Make connection to all active monitored-routers.
- *
- * @param address bmp client to connect to
- * @param slf bmp session listener factory
- * @param keys RFC2385 key mapping
- * @return void
- */
- @Deprecated
- default ChannelFuture createClient(InetSocketAddress address, BmpSessionListenerFactory slf, Optional<KeyMapping> keys) {
- if(keys.isPresent()) {
- return createClient(address, slf, keys.get());
- }
- return createClient(address, slf, KeyMapping.getKeyMapping());
- }
-
/**
* Creates server. Each server needs three factories to pass their instances to client sessions.
*
* @param keys RFC2385 key mapping
* @return instance of BmpServer
*/
- ChannelFuture createServer(InetSocketAddress address, BmpSessionListenerFactory slf, KeyMapping keys);
+ ChannelFuture createServer(@Nonnull InetSocketAddress address, @Nonnull BmpSessionListenerFactory slf,
+ @Nonnull KeyMapping keys);
/**
* Creates reconnect clients. Make connection to all active monitored-routers.
* @param address bmp client to connect to
* @param slf bmp session listener factory
* @param keys RFC2385 key mapping
- * @return void
+ * @return void
*/
- ChannelFuture createClient(InetSocketAddress address, BmpSessionListenerFactory slf, KeyMapping keys) ;
+ ChannelFuture createClient(@Nonnull InetSocketAddress address, @Nonnull BmpSessionListenerFactory slf,
+ @Nonnull KeyMapping keys);
}