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_ep_provider;
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.DomainSpecificRegistry;
17 import org.opendaylight.groupbasedpolicy.sxp.ep.provider.api.EPPolicyTemplateProviderRegistry;
18 import org.opendaylight.groupbasedpolicy.sxp.ep.provider.api.EPToSgtMapper;
19 import org.opendaylight.groupbasedpolicy.sxp.ep.provider.impl.SxpEpProviderProviderImpl;
20 import org.opendaylight.groupbasedpolicy.sxp.ep.provider.spi.SxpEpProviderProvider;
21 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonService;
22 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
23 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceRegistration;
24 import org.opendaylight.mdsal.singleton.common.api.ServiceGroupIdentifier;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.BaseEndpointService;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.groupbasedpolicy.sxp.integration.sxp.ep.provider.rev160722.SgtGeneratorConfig;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
30 public class SxpEpProviderProviderInstance implements SxpEpProviderProvider, ClusterSingletonService, AutoCloseable {
32 private static final Logger LOG = LoggerFactory.getLogger(SxpEpProviderProviderInstance.class);
34 private static final ServiceGroupIdentifier IDENTIFIER =
35 ServiceGroupIdentifier.create(GroupbasedpolicyInstance.GBP_SERVICE_GROUP_IDENTIFIER);
37 private final DataBroker dataBroker;
38 private final BaseEndpointService endpointService;
39 private final DomainSpecificRegistry registry;
40 private final ClusterSingletonServiceProvider clusterSingletonService;
41 private final SgtGeneratorConfig sgtGeneratorConfig;
42 private ClusterSingletonServiceRegistration singletonServiceRegistration;
43 private SxpEpProviderProviderImpl sxpEpProviderProvider;
45 public SxpEpProviderProviderInstance(DataBroker dataBroker, BaseEndpointService endpointService,
46 DomainSpecificRegistry registry,
47 ClusterSingletonServiceProvider clusterSingletonService,
48 SgtGeneratorConfig sgtGeneratorConfig) {
49 this.dataBroker = Preconditions.checkNotNull(dataBroker);
50 this.endpointService = Preconditions.checkNotNull(endpointService);
51 this.registry = Preconditions.checkNotNull(registry);
52 this.clusterSingletonService = Preconditions.checkNotNull(clusterSingletonService);
53 this.sgtGeneratorConfig = Preconditions.checkNotNull(sgtGeneratorConfig);
56 public void initialize() {
57 LOG.info("Clustering session initiated for {}", this.getClass().getSimpleName());
59 singletonServiceRegistration = clusterSingletonService.registerClusterSingletonService(this);
60 } catch (Exception e) {
61 LOG.warn("Exception thrown while registering cluster singleton service in {}", this.getClass(), e.getMessage());
66 public void instantiateServiceInstance() {
67 LOG.info("Instantiating {}", this.getClass().getSimpleName());
68 sxpEpProviderProvider = new SxpEpProviderProviderImpl(dataBroker, endpointService, registry, sgtGeneratorConfig);
72 public ListenableFuture<Void> closeServiceInstance() {
73 LOG.info("Instance {} closed", this.getClass().getSimpleName());
75 sxpEpProviderProvider.close();
76 } catch (Exception e) {
77 LOG.warn("Exception while closing ... {}", e.getMessage());
79 return Futures.immediateFuture(null);
83 public void close() throws Exception {
84 LOG.info("Clustering provider closed for {}", this.getClass().getSimpleName());
85 if (singletonServiceRegistration != null) {
87 singletonServiceRegistration.close();
88 } catch (Exception e) {
89 LOG.warn("{} closed unexpectedly. Cause: {}", e.getMessage());
91 singletonServiceRegistration = null;
96 public ServiceGroupIdentifier getIdentifier() {
101 public EPToSgtMapper getEPToSgtMapper() {
102 return sxpEpProviderProvider.getEPToSgtMapper();
106 public EPPolicyTemplateProviderRegistry getEPPolicyTemplateProviderRegistry() {
107 return sxpEpProviderProvider.getEPPolicyTemplateProviderRegistry();