2 * Copyright (c) 2015 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.neutron_ovsdb.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.RpcProviderRegistry;
17 import org.opendaylight.groupbasedpolicy.neutron.ovsdb.NeutronOvsdb;
18 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonService;
19 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
20 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceRegistration;
21 import org.opendaylight.mdsal.singleton.common.api.ServiceGroupIdentifier;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.EndpointService;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.ovsdb.params.rev160812.IntegrationBridgeSetting;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
27 public class NeutronOvsdbInstance implements ClusterSingletonService, AutoCloseable {
29 private static final Logger LOG = LoggerFactory.getLogger(NeutronOvsdbInstance.class);
31 private static final ServiceGroupIdentifier IDENTIFIER =
32 ServiceGroupIdentifier.create(GroupbasedpolicyInstance.GBP_SERVICE_GROUP_IDENTIFIER);
33 private final DataBroker dataBroker;
34 private final IntegrationBridgeSetting settings;
35 private final ClusterSingletonServiceProvider clusterSingletonService;
36 private final RpcProviderRegistry rpcBroker;
37 private ClusterSingletonServiceRegistration singletonServiceRegistration;
38 private NeutronOvsdb neutronOvsdb;
40 public NeutronOvsdbInstance(final DataBroker dataBroker,
41 final RpcProviderRegistry rpcBroker,
42 final IntegrationBridgeSetting settings,
43 final ClusterSingletonServiceProvider clusterSingletonService) {
44 this.dataBroker = Preconditions.checkNotNull(dataBroker);
45 this.rpcBroker = Preconditions.checkNotNull(rpcBroker);
46 this.settings = Preconditions.checkNotNull(settings);
47 this.clusterSingletonService = Preconditions.checkNotNull(clusterSingletonService);
50 public void initialize() {
51 LOG.info("Clustering session initiated for {}", this.getClass().getSimpleName());
53 singletonServiceRegistration = clusterSingletonService.registerClusterSingletonService(this);
54 } catch (Exception e) {
55 LOG.warn("Exception thrown while registering cluster singleton service in {}", this.getClass(), e.getMessage());
60 public void instantiateServiceInstance() {
61 LOG.info("Instantiating {}", this.getClass().getSimpleName());
62 final EndpointService epService = rpcBroker.getRpcService(EndpointService.class);
63 neutronOvsdb = new NeutronOvsdb(dataBroker, epService, settings);
67 public ListenableFuture<Void> closeServiceInstance() {
68 LOG.info("Instance {} closed", this.getClass().getSimpleName());
71 } catch (Exception e) {
72 LOG.warn("Instance close failed to ... ", e);
74 return Futures.immediateFuture(null);
78 public void close() throws Exception {
79 LOG.info("Clustering provider closed for {}", this.getClass().getSimpleName());
80 if (singletonServiceRegistration != null) {
82 singletonServiceRegistration.close();
83 } catch (Exception e) {
84 LOG.warn("{} closed unexpectedly", this.getClass().getSimpleName(), e);
86 singletonServiceRegistration = null;
91 public ServiceGroupIdentifier getIdentifier() {