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 javax.annotation.Nonnull;
13 import com.google.common.base.Preconditions;
14 import com.google.common.util.concurrent.Futures;
15 import com.google.common.util.concurrent.ListenableFuture;
16 import org.opendaylight.controller.config.yang.config.groupbasedpolicy.GroupbasedpolicyInstance;
17 import org.opendaylight.groupbasedpolicy.api.DomainSpecificRegistry;
18 import org.opendaylight.groupbasedpolicy.domain_extension.l2_l3.L2L3NetworkDomainAugmentor;
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 L2L3DomainExtensionInstance implements ClusterSingletonService, AutoCloseable {
28 private static final Logger LOG = LoggerFactory.getLogger(L2L3DomainExtensionInstance.class);
30 private static final ServiceGroupIdentifier IDENTIFIER =
31 ServiceGroupIdentifier.create(GroupbasedpolicyInstance.GBP_SERVICE_GROUP_IDENTIFIER);
32 private final DomainSpecificRegistry domainSpecificRegistry;
33 private ClusterSingletonServiceProvider clusterSingletonService;
34 private ClusterSingletonServiceRegistration singletonServiceRegistration;
35 private L2L3NetworkDomainAugmentor l2l3NetworkDomainAugmentor;
37 public L2L3DomainExtensionInstance(final DomainSpecificRegistry domainSpecificRegistry,
38 final ClusterSingletonServiceProvider clusterSingletonService) {
39 this.domainSpecificRegistry = Preconditions.checkNotNull(domainSpecificRegistry);
40 this.clusterSingletonService = Preconditions.checkNotNull(clusterSingletonService);
43 public void initialize() {
44 LOG.info("Clustering session initiated for {}", this.getClass().getSimpleName());
46 singletonServiceRegistration = clusterSingletonService.registerClusterSingletonService(this);
49 LOG.warn("Exception while registering candidate ... ", e);
54 public void instantiateServiceInstance() {
55 LOG.info("Instantiating {}", this.getClass().getSimpleName());
56 l2l3NetworkDomainAugmentor =
57 new L2L3NetworkDomainAugmentor(domainSpecificRegistry.getNetworkDomainAugmentorRegistry());
61 public ListenableFuture<Void> closeServiceInstance() {
62 LOG.info("Instance {} closed", this.getClass().getSimpleName());
63 l2l3NetworkDomainAugmentor.close();
64 return Futures.immediateFuture(null);
69 LOG.info("Clustering provider closed for {}", this.getClass().getSimpleName());
70 if (singletonServiceRegistration != null) {
72 singletonServiceRegistration.close();
73 } catch (Exception e) {
74 LOG.warn("{} closed unexpectedly", this.getClass().getSimpleName(), e.getMessage());
76 singletonServiceRegistration = null;
82 public ServiceGroupIdentifier getIdentifier() {