Search in sources :

Example 1 with ClusterSingletonServiceRegistration

use of org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceRegistration in project bgpcep by opendaylight.

the class BgpTopologyDeployerImpl method registerService.

@Override
@SuppressWarnings("checkstyle:IllegalCatch")
public AbstractRegistration registerService(final TopologyReferenceSingletonService topologyProviderService) {
    final Dictionary<String, String> properties = new Hashtable<>();
    properties.put("topology-id", topologyProviderService.getInstanceIdentifier().firstKeyOf(Topology.class).getTopologyId().getValue());
    final ServiceRegistration<?> registerService = this.context.registerService(new String[] { TopologyReference.class.getName() }, topologyProviderService, properties);
    final ClusterSingletonServiceRegistration registerClusterSingletonService = registerSingletonService(topologyProviderService);
    return new AbstractRegistration() {

        @Override
        protected void removeRegistration() {
            try {
                registerClusterSingletonService.close();
            } catch (final Exception e) {
                LOG.warn("Failed to close ClusterSingletonServiceRegistration {} for TopologyBuilder {}", registerClusterSingletonService, topologyProviderService.getInstanceIdentifier(), e);
            } finally {
                registerService.unregister();
            }
        }
    };
}
Also used : Hashtable(java.util.Hashtable) TopologyReference(org.opendaylight.bgpcep.topology.TopologyReference) AbstractRegistration(org.opendaylight.yangtools.concepts.AbstractRegistration) ClusterSingletonServiceRegistration(org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceRegistration) NetworkTopology(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology) Topology(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology)

Example 2 with ClusterSingletonServiceRegistration

use of org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceRegistration in project bgpcep by opendaylight.

the class ClusterSingletonServiceRegistrationHelperTest method testRegisterSingletonServiceSuccessfulRetry.

@Test
public void testRegisterSingletonServiceSuccessfulRetry() {
    final ClusterSingletonServiceRegistration registerSingletonService = registerSingletonService(this.singletonProvider, this.clusterSingletonService, 1, 1);
    assertEquals(this.serviceRegistration, registerSingletonService);
    // first reg. attempt failed, second succeeded
    verify(this.singletonProvider, Mockito.times(2)).registerClusterSingletonService(any());
}
Also used : ClusterSingletonServiceRegistration(org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceRegistration) Test(org.junit.Test)

Example 3 with ClusterSingletonServiceRegistration

use of org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceRegistration in project bgpcep by opendaylight.

the class BgpDeployerImplTest method setUp.

@Before
public void setUp() throws Exception {
    super.setUp();
    doReturn("mapping").when(this.tableTypeRegistry).toString();
    doReturn(Optional.of(TABLE_TYPE)).when(this.tableTypeRegistry).getTableType(any());
    doReturn(Optional.of(TABLES_KEY)).when(this.tableTypeRegistry).getTableKey(any());
    doNothing().when(this.registration).unregister();
    doReturn(this.registration).when(this.bundleContext).registerService(eq(InstanceType.RIB.getServices()), any(), any(Dictionary.class));
    doReturn(this.registration).when(this.bundleContext).registerService(eq(InstanceType.PEER.getServices()), any(), any(Dictionary.class));
    doNothing().when(this.dataTreeRegistration).close();
    doReturn("bgpPeer").when(this.modification).toString();
    final RIBExtensionConsumerContext extension = mock(RIBExtensionConsumerContext.class);
    doReturn(GeneratedClassLoadingStrategy.getTCCLClassLoadingStrategy()).when(extension).getClassLoadingStrategy();
    final ClusterSingletonServiceRegistration serviceRegistration = mock(ClusterSingletonServiceRegistration.class);
    doReturn(serviceRegistration).when(this.singletonServiceProvider).registerClusterSingletonService(any());
    doNothing().when(serviceRegistration).close();
    final DOMSchemaService schemaService = mock(DOMSchemaService.class);
    doNothing().when(this.dataTreeRegistration).close();
    doReturn(this.dataTreeRegistration).when(schemaService).registerSchemaContextListener(any());
    final RibImpl ribImpl = new RibImpl(extension, mock(BGPDispatcher.class), this.policyProvider, mock(BindingCodecTreeFactory.class), getDomBroker(), getDataBroker(), schemaService);
    doReturn(ribImpl).when(this.blueprintContainer).getComponentInstance(eq("ribImpl"));
    doReturn(new BgpPeer(mock(RpcProviderRegistry.class))).when(this.blueprintContainer).getComponentInstance(eq("bgpPeer"));
    this.deployer = new BgpDeployerImpl(NETWORK_INSTANCE_NAME, this.singletonServiceProvider, this.blueprintContainer, this.bundleContext, getDataBroker(), this.tableTypeRegistry);
}
Also used : Dictionary(java.util.Dictionary) BGPDispatcher(org.opendaylight.protocol.bgp.rib.impl.spi.BGPDispatcher) RIBExtensionConsumerContext(org.opendaylight.protocol.bgp.rib.spi.RIBExtensionConsumerContext) BindingCodecTreeFactory(org.opendaylight.mdsal.binding.dom.codec.api.BindingCodecTreeFactory) ClusterSingletonServiceRegistration(org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceRegistration) DOMSchemaService(org.opendaylight.mdsal.dom.api.DOMSchemaService) Before(org.junit.Before)

Aggregations

ClusterSingletonServiceRegistration (org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceRegistration)3 Dictionary (java.util.Dictionary)1 Hashtable (java.util.Hashtable)1 Before (org.junit.Before)1 Test (org.junit.Test)1 TopologyReference (org.opendaylight.bgpcep.topology.TopologyReference)1 BindingCodecTreeFactory (org.opendaylight.mdsal.binding.dom.codec.api.BindingCodecTreeFactory)1 DOMSchemaService (org.opendaylight.mdsal.dom.api.DOMSchemaService)1 BGPDispatcher (org.opendaylight.protocol.bgp.rib.impl.spi.BGPDispatcher)1 RIBExtensionConsumerContext (org.opendaylight.protocol.bgp.rib.spi.RIBExtensionConsumerContext)1 NetworkTopology (org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology)1 Topology (org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology)1 AbstractRegistration (org.opendaylight.yangtools.concepts.AbstractRegistration)1