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 java.util.concurrent.Future;
12 import com.google.common.base.Preconditions;
13 import com.google.common.util.concurrent.Futures;
14 import com.google.common.util.concurrent.ListenableFuture;
15 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
16 import org.opendaylight.groupbasedpolicy.api.DomainSpecificRegistry;
17 import org.opendaylight.groupbasedpolicy.api.EndpointAugmentorRegistry;
18 import org.opendaylight.groupbasedpolicy.api.NetworkDomainAugmentorRegistry;
19 import org.opendaylight.groupbasedpolicy.base_endpoint.BaseEndpointServiceImpl;
20 import org.opendaylight.groupbasedpolicy.base_endpoint.EndpointAugmentorRegistryImpl;
21 import org.opendaylight.groupbasedpolicy.forwarding.NetworkDomainAugmentorRegistryImpl;
22 import org.opendaylight.groupbasedpolicy.renderer.RendererManager;
23 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonService;
24 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
25 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceRegistration;
26 import org.opendaylight.mdsal.singleton.common.api.ServiceGroupIdentifier;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.BaseEndpointService;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.RegisterEndpointInput;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.UnregisterEndpointInput;
30 import org.opendaylight.yangtools.yang.common.RpcResult;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
34 public class DomainSpecificRegistryInstance implements ClusterSingletonService, DomainSpecificRegistry, BaseEndpointService, AutoCloseable {
36 private static final Logger LOG = LoggerFactory.getLogger(DomainSpecificRegistryInstance.class);
38 private static final ServiceGroupIdentifier IDENTIFIER =
39 ServiceGroupIdentifier.create(GroupbasedpolicyInstance.GBP_SERVICE_GROUP_IDENTIFIER);
40 private final DataBroker dataBroker;
41 private ClusterSingletonServiceProvider clusterSingletonService;
42 private ClusterSingletonServiceRegistration singletonServiceRegistration;
43 private EndpointAugmentorRegistryImpl endpointAugmentorRegistryImpl;
44 private NetworkDomainAugmentorRegistryImpl netDomainAugmentorRegistryImpl;
45 private BaseEndpointServiceImpl baseEndpointServiceImpl;
46 private RendererManager rendererManager;
48 public DomainSpecificRegistryInstance(final DataBroker dataBroker,
49 final ClusterSingletonServiceProvider clusterSingletonService) {
50 this.dataBroker = Preconditions.checkNotNull(dataBroker);
51 this.clusterSingletonService = Preconditions.checkNotNull(clusterSingletonService);
55 public EndpointAugmentorRegistry getEndpointAugmentorRegistry() {
56 return endpointAugmentorRegistryImpl;
60 public NetworkDomainAugmentorRegistry getNetworkDomainAugmentorRegistry() {
61 return netDomainAugmentorRegistryImpl;
65 public Future<RpcResult<Void>> unregisterEndpoint(UnregisterEndpointInput input) {
66 return baseEndpointServiceImpl.unregisterEndpoint(input);
70 public Future<RpcResult<Void>> registerEndpoint(RegisterEndpointInput input) {
71 return baseEndpointServiceImpl.registerEndpoint(input);
74 public void initialize() {
75 LOG.info("Clustering session initiated for {}", this.getClass().getSimpleName());
76 singletonServiceRegistration = clusterSingletonService.registerClusterSingletonService(this);
80 public void instantiateServiceInstance() {
81 LOG.info("Instantiating {}", this.getClass().getSimpleName());
82 endpointAugmentorRegistryImpl = new EndpointAugmentorRegistryImpl();
83 netDomainAugmentorRegistryImpl = new NetworkDomainAugmentorRegistryImpl();
84 baseEndpointServiceImpl = new BaseEndpointServiceImpl(dataBroker, endpointAugmentorRegistryImpl);
85 rendererManager = new RendererManager(dataBroker, netDomainAugmentorRegistryImpl, endpointAugmentorRegistryImpl);
89 public ListenableFuture<Void> closeServiceInstance() {
90 LOG.info("Instance {} closed", this.getClass().getSimpleName());
91 baseEndpointServiceImpl.close();
92 rendererManager.close();
93 return Futures.immediateFuture(null);
97 public void close() throws Exception {
98 LOG.info("Clustering provider closed for {}", this.getClass().getSimpleName());
99 if (singletonServiceRegistration != null) {
101 singletonServiceRegistration.close();
102 } catch (Exception e) {
103 LOG.warn("{} closed unexpectedly", this.getClass().getSimpleName(), e);
105 singletonServiceRegistration = null;
110 public ServiceGroupIdentifier getIdentifier() {