2 * Copyright (c) 2016 Cisco Systems, Inc. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.controller.config.yang.config.groupbasedpolicy;
11 import com.google.common.base.Preconditions;
12 import com.google.common.util.concurrent.Futures;
13 import com.google.common.util.concurrent.ListenableFuture;
14 import java.util.concurrent.Future;
15 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
16 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
17 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
18 import org.opendaylight.groupbasedpolicy.api.DomainSpecificRegistry;
19 import org.opendaylight.groupbasedpolicy.api.EndpointAugmentorRegistry;
20 import org.opendaylight.groupbasedpolicy.api.NetworkDomainAugmentorRegistry;
21 import org.opendaylight.groupbasedpolicy.base_endpoint.BaseEndpointServiceImpl;
22 import org.opendaylight.groupbasedpolicy.base_endpoint.EndpointAugmentorRegistryImpl;
23 import org.opendaylight.groupbasedpolicy.forwarding.NetworkDomainAugmentorRegistryImpl;
24 import org.opendaylight.groupbasedpolicy.renderer.RendererManager;
25 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonService;
26 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
27 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceRegistration;
28 import org.opendaylight.mdsal.singleton.common.api.ServiceGroupIdentifier;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.BaseEndpointService;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.RegisterEndpointInput;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.UnregisterEndpointInput;
32 import org.opendaylight.yangtools.yang.common.RpcResult;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
36 public class DomainSpecificRegistryInstance implements ClusterSingletonService, DomainSpecificRegistry, BaseEndpointService, AutoCloseable {
38 private static final Logger LOG = LoggerFactory.getLogger(DomainSpecificRegistryInstance.class);
40 private static final ServiceGroupIdentifier IDENTIFIER =
41 ServiceGroupIdentifier.create(GroupbasedpolicyInstance.GBP_SERVICE_GROUP_IDENTIFIER);
42 private final DataBroker dataBroker;
43 private ClusterSingletonServiceProvider clusterSingletonService;
44 private final RpcProviderRegistry rpcProviderRegistry;
45 private ClusterSingletonServiceRegistration singletonServiceRegistration;
46 private EndpointAugmentorRegistryImpl endpointAugmentorRegistryImpl;
47 private NetworkDomainAugmentorRegistryImpl netDomainAugmentorRegistryImpl;
48 private BaseEndpointServiceImpl baseEndpointServiceImpl;
49 private RendererManager rendererManager;
50 private BindingAwareBroker.RpcRegistration<BaseEndpointService> baseEndpointServiceRpcRegistration;
52 public DomainSpecificRegistryInstance(final DataBroker dataBroker,
53 final ClusterSingletonServiceProvider clusterSingletonService,
54 final RpcProviderRegistry rpcProviderRegistry) {
55 this.dataBroker = Preconditions.checkNotNull(dataBroker);
56 this.clusterSingletonService = Preconditions.checkNotNull(clusterSingletonService);
57 this.rpcProviderRegistry = Preconditions.checkNotNull(rpcProviderRegistry);
61 public EndpointAugmentorRegistry getEndpointAugmentorRegistry() {
62 return endpointAugmentorRegistryImpl;
66 public NetworkDomainAugmentorRegistry getNetworkDomainAugmentorRegistry() {
67 return netDomainAugmentorRegistryImpl;
71 public Future<RpcResult<Void>> unregisterEndpoint(UnregisterEndpointInput input) {
72 return baseEndpointServiceImpl.unregisterEndpoint(input);
76 public Future<RpcResult<Void>> registerEndpoint(RegisterEndpointInput input) {
77 return baseEndpointServiceImpl.registerEndpoint(input);
80 public void initialize() {
81 LOG.info("Clustering session initiated for {}", this.getClass().getSimpleName());
83 singletonServiceRegistration = clusterSingletonService.registerClusterSingletonService(this);
86 LOG.warn("Exception while registering candidate ... ", e);
91 public void instantiateServiceInstance() {
92 LOG.info("Instantiating {}", this.getClass().getSimpleName());
93 endpointAugmentorRegistryImpl = new EndpointAugmentorRegistryImpl();
94 netDomainAugmentorRegistryImpl = new NetworkDomainAugmentorRegistryImpl();
95 baseEndpointServiceImpl = new BaseEndpointServiceImpl(dataBroker, endpointAugmentorRegistryImpl);
96 rendererManager = new RendererManager(dataBroker, netDomainAugmentorRegistryImpl, endpointAugmentorRegistryImpl);
98 baseEndpointServiceRpcRegistration = rpcProviderRegistry.addRpcImplementation(BaseEndpointService.class, this);
102 public ListenableFuture<Void> closeServiceInstance() {
103 LOG.info("Instance {} closed", this.getClass().getSimpleName());
104 baseEndpointServiceImpl.close();
105 baseEndpointServiceRpcRegistration.close();
106 rendererManager.close();
108 return Futures.immediateFuture(null);
112 public void close() throws Exception {
113 LOG.info("Clustering provider closed for {}", this.getClass().getSimpleName());
114 if (singletonServiceRegistration != null) {
116 singletonServiceRegistration.close();
117 } catch (Exception e) {
118 LOG.warn("{} closed unexpectedly", this.getClass().getSimpleName(), e);
120 singletonServiceRegistration = null;
125 public ServiceGroupIdentifier getIdentifier() {