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.EpRendererAugmentation;
17 import org.opendaylight.groupbasedpolicy.api.EpRendererAugmentationRegistry;
18 import org.opendaylight.groupbasedpolicy.endpoint.EndpointRpcRegistry;
19 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonService;
20 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
21 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceRegistration;
22 import org.opendaylight.mdsal.singleton.common.api.ServiceGroupIdentifier;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.EndpointService;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.RegisterEndpointInput;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.RegisterL3PrefixEndpointInput;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.SetEndpointGroupConditionsInput;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.UnregisterEndpointInput;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.UnsetEndpointGroupConditionsInput;
29 import org.opendaylight.yangtools.yang.common.RpcResult;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
33 public class EpRendererAugmentationRegistryImplInstance implements ClusterSingletonService, EpRendererAugmentationRegistry, EndpointService, AutoCloseable {
35 private static final Logger LOG = LoggerFactory.getLogger(EpRendererAugmentationRegistryImplInstance.class);
37 private static final ServiceGroupIdentifier IDENTIFIER =
38 ServiceGroupIdentifier.create(GroupbasedpolicyInstance.GBP_SERVICE_GROUP_IDENTIFIER);
39 private final DataBroker dataBroker;
40 private ClusterSingletonServiceProvider clusterSingletonService;
41 private ClusterSingletonServiceRegistration singletonServiceRegistration;
42 private EndpointRpcRegistry endpointRpcRegistry;
44 public EpRendererAugmentationRegistryImplInstance(final DataBroker dataBroker,
45 final ClusterSingletonServiceProvider clusterSingletonService) {
46 this.dataBroker = Preconditions.checkNotNull(dataBroker);
47 this.clusterSingletonService = Preconditions.checkNotNull(clusterSingletonService);
51 public void register(EpRendererAugmentation epRendererAugmentation) {
52 endpointRpcRegistry.register(epRendererAugmentation);
56 public void unregister(EpRendererAugmentation epRendererAugmentation) {
57 endpointRpcRegistry.unregister(epRendererAugmentation);
61 public Future<RpcResult<Void>> unsetEndpointGroupConditions(UnsetEndpointGroupConditionsInput input) {
62 return endpointRpcRegistry.unsetEndpointGroupConditions(input);
66 public Future<RpcResult<Void>> registerEndpoint(RegisterEndpointInput input) {
67 return endpointRpcRegistry.registerEndpoint(input);
71 public Future<RpcResult<Void>> setEndpointGroupConditions(SetEndpointGroupConditionsInput input) {
72 return endpointRpcRegistry.setEndpointGroupConditions(input);
76 public Future<RpcResult<Void>> registerL3PrefixEndpoint(RegisterL3PrefixEndpointInput input) {
77 return endpointRpcRegistry.registerL3PrefixEndpoint(input);
81 public Future<RpcResult<Void>> unregisterEndpoint(UnregisterEndpointInput input) {
82 return endpointRpcRegistry.unregisterEndpoint(input);
85 public void initialize() {
86 LOG.info("Clustering session initiated for {}", this.getClass().getSimpleName());
87 singletonServiceRegistration = clusterSingletonService.registerClusterSingletonService(this);
91 public void instantiateServiceInstance() {
92 LOG.info("Instantiating {}", this.getClass().getSimpleName());
93 endpointRpcRegistry = new EndpointRpcRegistry(dataBroker);
97 public ListenableFuture<Void> closeServiceInstance() {
98 LOG.info("Instance {} closed", this.getClass().getSimpleName());
99 endpointRpcRegistry.close();
100 return Futures.immediateFuture(null);
104 public void close() {
105 LOG.info("Clustering provider closed for {}", this.getClass().getSimpleName());
106 if (singletonServiceRegistration != null) {
108 singletonServiceRegistration.close();
109 } catch (Exception e) {
110 LOG.warn("{} closed unexpectedly", this.getClass().getSimpleName(), e);
112 singletonServiceRegistration = null;
117 public ServiceGroupIdentifier getIdentifier() {