2 * Copyright (c) 2016 Cisco System. 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.iovisor_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.groupbasedpolicy.api.EpRendererAugmentationRegistry;
17 import org.opendaylight.groupbasedpolicy.api.PolicyValidatorRegistry;
18 import org.opendaylight.groupbasedpolicy.renderer.iovisor.IovisorRenderer;
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 IovisorProviderInstance implements ClusterSingletonService, AutoCloseable {
28 private static final Logger LOG = LoggerFactory.getLogger(IovisorProviderInstance.class);
30 private static final ServiceGroupIdentifier IDENTIFIER =
31 ServiceGroupIdentifier.create(GroupbasedpolicyInstance.GBP_SERVICE_GROUP_IDENTIFIER);
32 private final DataBroker dataBroker;
33 private final EpRendererAugmentationRegistry epRegistry;
34 private final PolicyValidatorRegistry policyValidator;
35 private final ClusterSingletonServiceProvider clusteringServiceProvider;
36 private ClusterSingletonServiceRegistration singletonServiceRegistration;
37 private IovisorRenderer renderer;
39 public IovisorProviderInstance(final DataBroker dataBroker,
40 final EpRendererAugmentationRegistry epRegistry,
41 final PolicyValidatorRegistry policyValidator,
42 final ClusterSingletonServiceProvider clusteringServiceProvider) {
43 this.dataBroker = Preconditions.checkNotNull(dataBroker);
44 this.epRegistry = Preconditions.checkNotNull(epRegistry);
45 this.policyValidator = Preconditions.checkNotNull(policyValidator);
46 this.clusteringServiceProvider = Preconditions.checkNotNull(clusteringServiceProvider);
49 public void initialize() {
50 LOG.info("Clustering session initiated for {}", this.getClass().getSimpleName());
52 singletonServiceRegistration = clusteringServiceProvider.registerClusterSingletonService(this);
53 } catch (Exception e) {
54 LOG.warn("Exception thrown while registering cluster singleton service in {}", this.getClass(), e.getMessage());
59 public void instantiateServiceInstance() {
60 LOG.info("Instantiating {}", this.getClass().getSimpleName());
61 renderer = new IovisorRenderer(dataBroker, epRegistry, policyValidator);
65 public ListenableFuture<Void> closeServiceInstance() {
68 } catch (Exception e) {
69 LOG.warn("Exception while closing ... ", e);
71 return Futures.immediateFuture(null);
76 LOG.info("Clustering provider closed for {}", this.getClass().getSimpleName());
77 if (singletonServiceRegistration != null) {
79 singletonServiceRegistration.close();
80 } catch (Exception e) {
81 LOG.warn("{} closed unexpectedly. Cause: {}", e.getMessage());
83 singletonServiceRegistration = null;
88 public ServiceGroupIdentifier getIdentifier() {