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.groupbasedpolicy.sxp_integration.sxp_ise_adapter;
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.groupbasedpolicy.sxp.ep.provider.spi.SxpEpProviderProvider;
18 import org.opendaylight.groupbasedpolicy.sxp_ise_adapter.impl.GbpIseAdapterProvider;
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.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
26 public class SxpIseAdapterProviderInstance implements ClusterSingletonService, AutoCloseable {
28 private static final Logger LOG = LoggerFactory.getLogger(SxpIseAdapterProviderInstance.class);
30 private static final ServiceGroupIdentifier IDENTIFIER =
31 ServiceGroupIdentifier.create(GroupbasedpolicyInstance.GBP_SERVICE_GROUP_IDENTIFIER);
33 private final DataBroker dataBroker;
34 private final BindingAwareBroker bindingAwareBroker;
35 private final ClusterSingletonServiceProvider clusterSingletonService;
36 private final SxpEpProviderProvider sxpEpProvider;
37 private ClusterSingletonServiceRegistration singletonServiceRegistration;
38 private GbpIseAdapterProvider iseAdapterProvider;
40 public SxpIseAdapterProviderInstance(final DataBroker dataBroker,
41 final BindingAwareBroker bindingAwareBroker,
42 final ClusterSingletonServiceProvider clusterSingletonService,
43 final SxpEpProviderProvider sxpEpProvider) {
44 this.dataBroker = Preconditions.checkNotNull(dataBroker);
45 this.bindingAwareBroker = Preconditions.checkNotNull(bindingAwareBroker);
46 this.clusterSingletonService = Preconditions.checkNotNull(clusterSingletonService);
47 this.sxpEpProvider = Preconditions.checkNotNull(sxpEpProvider);
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 iseAdapterProvider = new GbpIseAdapterProvider(dataBroker, bindingAwareBroker, sxpEpProvider);
66 public ListenableFuture<Void> closeServiceInstance() {
67 LOG.info("Instance {} closed", this.getClass().getSimpleName());
69 iseAdapterProvider.close();
70 } catch (Exception e) {
71 LOG.warn("iseAdapterProvider closing failed: {}", e.getMessage());
73 return Futures.immediateFuture(null);
77 public void close() throws Exception {
78 LOG.info("Clustering provider closed for {}", this.getClass().getSimpleName());
79 if (singletonServiceRegistration != null) {
81 singletonServiceRegistration.close();
82 } catch (Exception e) {
83 LOG.warn("{} closed unexpectedly. Cause: {}", e.getMessage());
85 singletonServiceRegistration = null;
90 public ServiceGroupIdentifier getIdentifier() {