2 * Copyright (c) 2016 Cisco Systems, Inc. and others. 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.vpp_provider.impl;
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 org.opendaylight.controller.config.yang.config.groupbasedpolicy.GroupbasedpolicyInstance;
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.renderer.vpp.adapter.VppRpcServiceImpl;
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.vpp_adapter.rev161201.AddInterfaceToBridgeDomainInput;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_adapter.rev161201.CloneVirtualBridgeDomainOnNodesInput;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_adapter.rev161201.CreateInterfaceOnNodeInput;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_adapter.rev161201.CreateVirtualBridgeDomainOnNodesInput;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_adapter.rev161201.DelInterfaceFromBridgeDomainInput;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_adapter.rev161201.DeleteInterfaceFromNodeInput;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_adapter.rev161201.DeleteVirtualBridgeDomainFromNodesInput;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_adapter.rev161201.VppAdapterService;
31 import org.opendaylight.yangtools.yang.common.RpcResult;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
35 import javax.annotation.Nonnull;
36 import java.util.concurrent.Future;
38 public class GbpVppProviderInstance implements ClusterSingletonService, VppAdapterService, AutoCloseable {
40 private static final Logger LOG = LoggerFactory.getLogger(GbpVppProviderInstance.class);
42 private static final ServiceGroupIdentifier IDENTIFIER =
43 ServiceGroupIdentifier.create(GroupbasedpolicyInstance.GBP_SERVICE_GROUP_IDENTIFIER);
44 private final DataBroker dataBroker;
45 private final BindingAwareBroker bindingAwareBroker;
46 private final ClusterSingletonServiceProvider clusterSingletonService;
47 private final RpcProviderRegistry rpcProviderRegistry;
48 private final String publicInterfaces;
49 private ClusterSingletonServiceRegistration singletonServiceRegistration;
50 private VppRpcServiceImpl vppRpcService;
51 private VppRenderer renderer;
52 private BindingAwareBroker.RpcRegistration<VppAdapterService> vppRpcServiceRegistration;
54 public GbpVppProviderInstance(final DataBroker dataBroker,
55 final BindingAwareBroker bindingAwareBroker,
56 final ClusterSingletonServiceProvider clusterSingletonService,
57 final String publicInterfaces, final RpcProviderRegistry rpcProviderRegistry) {
58 this.dataBroker = Preconditions.checkNotNull(dataBroker);
59 this.bindingAwareBroker = Preconditions.checkNotNull(bindingAwareBroker);
60 this.clusterSingletonService = Preconditions.checkNotNull(clusterSingletonService);
61 this.publicInterfaces = publicInterfaces;
62 this.rpcProviderRegistry = Preconditions.checkNotNull(rpcProviderRegistry);
65 public void initialize() {
66 LOG.info("Clustering session initiated for {}", this.getClass().getSimpleName());
67 singletonServiceRegistration = clusterSingletonService.registerClusterSingletonService(this);
71 public void instantiateServiceInstance() {
72 LOG.info("Instantiating {}", this.getClass().getSimpleName());
73 renderer = new VppRenderer(dataBroker, bindingAwareBroker, publicInterfaces);
74 vppRpcService = new VppRpcServiceImpl(dataBroker, renderer);
75 vppRpcServiceRegistration = rpcProviderRegistry.addRpcImplementation(VppAdapterService.class, this);
79 public ListenableFuture<Void> closeServiceInstance() {
80 LOG.info("Instance {} closed", this.getClass().getSimpleName());
82 vppRpcServiceRegistration.close();
83 vppRpcService.close();
85 } catch (Exception e) {
86 LOG.warn("Exception while closing ... {}", e.getMessage());
88 return Futures.immediateFuture(null);
92 public void close() throws Exception {
94 LOG.info("Clustering provider closed for {}", this.getClass().getSimpleName());
95 if (singletonServiceRegistration != null) {
97 singletonServiceRegistration.close();
98 } catch (Exception e) {
99 LOG.warn("{} closed unexpectedly", this.getClass().getSimpleName(), e.getMessage());
101 singletonServiceRegistration = null;
107 public ServiceGroupIdentifier getIdentifier() {
112 public Future<RpcResult<Void>> deleteVirtualBridgeDomainFromNodes(DeleteVirtualBridgeDomainFromNodesInput input) {
113 return vppRpcService.deleteVirtualBridgeDomainFromNodes(input);
117 public Future<RpcResult<Void>> createVirtualBridgeDomainOnNodes(CreateVirtualBridgeDomainOnNodesInput input) {
118 return vppRpcService.createVirtualBridgeDomainOnNodes(input);
122 public Future<RpcResult<Void>> createInterfaceOnNode(CreateInterfaceOnNodeInput input) {
123 return vppRpcService.createInterfaceOnNode(input);
127 public Future<RpcResult<Void>> addInterfaceToBridgeDomain(AddInterfaceToBridgeDomainInput input) {
128 return vppRpcService.addInterfaceToBridgeDomain(input);
132 public Future<RpcResult<Void>> delInterfaceFromBridgeDomain(DelInterfaceFromBridgeDomainInput input) {
133 return vppRpcService.delInterfaceFromBridgeDomain(input);
137 public Future<RpcResult<Void>> cloneVirtualBridgeDomainOnNodes(CloneVirtualBridgeDomainOnNodesInput input) {
138 return vppRpcService.cloneVirtualBridgeDomainOnNodes(input);
142 public Future<RpcResult<Void>> deleteInterfaceFromNode(DeleteInterfaceFromNodeInput input) {
143 return vppRpcService.deleteInterfaceFromNode(input);