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.EpRendererAugmentation;
19 import org.opendaylight.groupbasedpolicy.api.EpRendererAugmentationRegistry;
20 import org.opendaylight.groupbasedpolicy.endpoint.EndpointRpcRegistry;
21 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonService;
22 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
23 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceRegistration;
24 import org.opendaylight.mdsal.singleton.common.api.ServiceGroupIdentifier;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.EndpointService;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.RegisterEndpointInput;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.RegisterL3PrefixEndpointInput;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.SetEndpointGroupConditionsInput;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.UnregisterEndpointInput;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.UnsetEndpointGroupConditionsInput;
31 import org.opendaylight.yangtools.yang.common.RpcResult;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
35 public class EpRendererAugmentationRegistryImplInstance implements ClusterSingletonService, EpRendererAugmentationRegistry, EndpointService, AutoCloseable {
37 private static final Logger LOG = LoggerFactory.getLogger(EpRendererAugmentationRegistryImplInstance.class);
39 private static final ServiceGroupIdentifier IDENTIFIER =
40 ServiceGroupIdentifier.create(GroupbasedpolicyInstance.GBP_SERVICE_GROUP_IDENTIFIER);
41 private final DataBroker dataBroker;
42 private ClusterSingletonServiceProvider clusterSingletonService;
43 private final RpcProviderRegistry rpcProviderRegistry;
44 private ClusterSingletonServiceRegistration singletonServiceRegistration;
45 private EndpointRpcRegistry endpointRpcRegistry;
46 private BindingAwareBroker.RpcRegistration<EndpointService> serviceRpcRegistration;
48 public EpRendererAugmentationRegistryImplInstance(final DataBroker dataBroker,
49 final ClusterSingletonServiceProvider clusterSingletonService,
50 final RpcProviderRegistry rpcProviderRegistry) {
51 this.dataBroker = Preconditions.checkNotNull(dataBroker);
52 this.clusterSingletonService = Preconditions.checkNotNull(clusterSingletonService);
53 this.rpcProviderRegistry = rpcProviderRegistry;
57 public void register(EpRendererAugmentation epRendererAugmentation) {
58 endpointRpcRegistry.register(epRendererAugmentation);
62 public void unregister(EpRendererAugmentation epRendererAugmentation) {
63 endpointRpcRegistry.unregister(epRendererAugmentation);
67 public Future<RpcResult<Void>> unsetEndpointGroupConditions(UnsetEndpointGroupConditionsInput input) {
68 return endpointRpcRegistry.unsetEndpointGroupConditions(input);
72 public Future<RpcResult<Void>> registerEndpoint(RegisterEndpointInput input) {
73 return endpointRpcRegistry.registerEndpoint(input);
77 public Future<RpcResult<Void>> setEndpointGroupConditions(SetEndpointGroupConditionsInput input) {
78 return endpointRpcRegistry.setEndpointGroupConditions(input);
82 public Future<RpcResult<Void>> registerL3PrefixEndpoint(RegisterL3PrefixEndpointInput input) {
83 return endpointRpcRegistry.registerL3PrefixEndpoint(input);
87 public Future<RpcResult<Void>> unregisterEndpoint(UnregisterEndpointInput input) {
88 return endpointRpcRegistry.unregisterEndpoint(input);
91 public void initialize() {
92 LOG.info("Clustering session initiated for {}", this.getClass().getSimpleName());
94 singletonServiceRegistration = clusterSingletonService.registerClusterSingletonService(this);
97 LOG.warn("Exception while registering candidate ... ", e);
102 public void instantiateServiceInstance() {
103 LOG.info("Instantiating {}", this.getClass().getSimpleName());
104 endpointRpcRegistry = new EndpointRpcRegistry(dataBroker);
106 serviceRpcRegistration = rpcProviderRegistry.addRpcImplementation(EndpointService.class, this);
110 public ListenableFuture<Void> closeServiceInstance() {
111 LOG.info("Instance {} closed", this.getClass().getSimpleName());
112 endpointRpcRegistry.close();
113 serviceRpcRegistration.close();
114 return Futures.immediateFuture(null);
118 public void close() {
119 LOG.info("Clustering provider closed for {}", this.getClass().getSimpleName());
120 if (singletonServiceRegistration != null) {
122 singletonServiceRegistration.close();
123 } catch (Exception e) {
124 LOG.warn("{} closed unexpectedly", this.getClass().getSimpleName(), e);
126 singletonServiceRegistration = null;
131 public ServiceGroupIdentifier getIdentifier() {