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.domain_extension.l2_l3.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.groupbasedpolicy.api.DomainSpecificRegistry;
16 import org.opendaylight.groupbasedpolicy.domain_extension.l2_l3.L2L3NetworkDomainAugmentor;
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.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
24 public class L2L3DomainExtensionInstance implements ClusterSingletonService, AutoCloseable {
26 private static final Logger LOG = LoggerFactory.getLogger(L2L3DomainExtensionInstance.class);
28 private static final ServiceGroupIdentifier IDENTIFIER =
29 ServiceGroupIdentifier.create(GroupbasedpolicyInstance.GBP_SERVICE_GROUP_IDENTIFIER);
30 private final DomainSpecificRegistry domainSpecificRegistry;
31 private ClusterSingletonServiceProvider clusterSingletonService;
32 private ClusterSingletonServiceRegistration singletonServiceRegistration;
33 private L2L3NetworkDomainAugmentor l2l3NetworkDomainAugmentor;
35 public L2L3DomainExtensionInstance(final DomainSpecificRegistry domainSpecificRegistry,
36 final ClusterSingletonServiceProvider clusterSingletonService) {
37 this.domainSpecificRegistry = Preconditions.checkNotNull(domainSpecificRegistry);
38 this.clusterSingletonService = Preconditions.checkNotNull(clusterSingletonService);
41 public void initialize() {
42 LOG.info("Clustering session initiated for {}", this.getClass().getSimpleName());
44 singletonServiceRegistration = clusterSingletonService.registerClusterSingletonService(this);
47 LOG.warn("Exception while registering candidate ... ", e);
52 public void instantiateServiceInstance() {
53 LOG.info("Instantiating {}", this.getClass().getSimpleName());
54 l2l3NetworkDomainAugmentor = new L2L3NetworkDomainAugmentor(domainSpecificRegistry.getNetworkDomainAugmentorRegistry());
58 public ListenableFuture<Void> closeServiceInstance() {
59 LOG.info("Instance {} closed", this.getClass().getSimpleName());
60 l2l3NetworkDomainAugmentor.close();
61 return Futures.immediateFuture(null);
66 LOG.info("Clustering provider closed for {}", this.getClass().getSimpleName());
67 if (singletonServiceRegistration != null) {
69 singletonServiceRegistration.close();
70 } catch (Exception e) {
71 LOG.warn("{} closed unexpectedly", this.getClass().getSimpleName(), e.getMessage());
73 singletonServiceRegistration = null;
78 public ServiceGroupIdentifier getIdentifier() {