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.groupbasedpolicy.neutron.ovsdb.NeutronOvsdb;
17 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonService;
18 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
19 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceRegistration;
20 import org.opendaylight.mdsal.singleton.common.api.ServiceGroupIdentifier;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.EndpointService;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.ovsdb.params.rev160812.IntegrationBridgeSetting;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
26 public class NeutronOvsdbInstance implements ClusterSingletonService, AutoCloseable {
28 private static final Logger LOG = LoggerFactory.getLogger(NeutronOvsdbInstance.class);
30 private static final ServiceGroupIdentifier IDENTIFIER =
31 ServiceGroupIdentifier.create(GroupbasedpolicyInstance.GBP_SERVICE_GROUP_IDENTIFIER);
32 private final DataBroker dataBroker;
33 private final EndpointService epService;
34 private final IntegrationBridgeSetting settings;
35 private final ClusterSingletonServiceProvider clusterSingletonService;
36 private ClusterSingletonServiceRegistration singletonServiceRegistration;
37 private NeutronOvsdb neutronOvsdb;
39 public NeutronOvsdbInstance(final DataBroker dataBroker,
40 final EndpointService epService,
41 final IntegrationBridgeSetting settings,
42 final ClusterSingletonServiceProvider clusterSingletonService) {
43 this.dataBroker = Preconditions.checkNotNull(dataBroker);
44 this.epService = Preconditions.checkNotNull(epService);
45 this.settings = Preconditions.checkNotNull(settings);
46 this.clusterSingletonService = Preconditions.checkNotNull(clusterSingletonService);
49 public void initialize() {
50 LOG.info("Clustering session initiated for {}", this.getClass().getSimpleName());
51 singletonServiceRegistration = clusterSingletonService.registerClusterSingletonService(this);
55 public void instantiateServiceInstance() {
56 LOG.info("Instantiating {}", this.getClass().getSimpleName());
57 neutronOvsdb = new NeutronOvsdb(dataBroker, epService, settings);
61 public ListenableFuture<Void> closeServiceInstance() {
62 LOG.info("Instance {} closed", this.getClass().getSimpleName());
65 } catch (Exception e) {
66 LOG.warn("Instance close failed to ... ", e);
68 return Futures.immediateFuture(null);
72 public void close() throws Exception {
73 LOG.info("Clustering provider closed for {}", this.getClass().getSimpleName());
74 if (singletonServiceRegistration != null) {
76 singletonServiceRegistration.close();
77 } catch (Exception e) {
78 LOG.warn("{} closed unexpectedly", this.getClass().getSimpleName(), e);
80 singletonServiceRegistration = null;
85 public ServiceGroupIdentifier getIdentifier() {