2 * Copyright (c) 2017 Ericsson India Global Services Pvt Ltd. 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
8 package org.opendaylight.netvirt.elan.internal;
10 import com.google.common.collect.Lists;
11 import com.google.common.util.concurrent.SettableFuture;
12 import javax.annotation.PreDestroy;
13 import javax.inject.Inject;
14 import javax.inject.Singleton;
15 import org.opendaylight.infrautils.jobcoordinator.JobCoordinator;
16 import org.opendaylight.infrautils.utils.concurrent.Executors;
17 import org.opendaylight.mdsal.binding.api.DataBroker;
18 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
19 import org.opendaylight.netvirt.elan.cache.ElanInstanceCache;
20 import org.opendaylight.netvirt.elan.l2gw.utils.ElanL2GatewayBcGroupUtils;
21 import org.opendaylight.netvirt.elan.l2gw.utils.ElanRefUtil;
22 import org.opendaylight.serviceutils.tools.listener.AbstractClusteredAsyncDataTreeChangeListener;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.ElanInstances;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.instances.ElanInstance;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.instances.elan.instance.ExternalTeps;
26 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
31 public class ElanExtnTepListener extends AbstractClusteredAsyncDataTreeChangeListener<ExternalTeps> {
33 private static final Logger LOG = LoggerFactory.getLogger(ElanExtnTepListener.class);
35 private final DataBroker broker;
36 private final ElanL2GatewayBcGroupUtils elanL2GatewayBcGroupUtils;
37 private final JobCoordinator jobCoordinator;
38 private final ElanInstanceCache elanInstanceCache;
39 private final ElanRefUtil elanRefUtil;
42 public ElanExtnTepListener(DataBroker dataBroker, ElanL2GatewayBcGroupUtils elanL2GatewayBcGroupUtils,
43 JobCoordinator jobCoordinator, ElanInstanceCache elanInstanceCache, ElanRefUtil elanRefUtil) {
44 super(dataBroker, LogicalDatastoreType.OPERATIONAL, InstanceIdentifier.create(ElanInstances.class)
45 .child(ElanInstance.class).child(ExternalTeps.class),
46 Executors.newListeningSingleThreadExecutor("ElanExtnTepListener", LOG));
47 this.broker = dataBroker;
48 this.elanL2GatewayBcGroupUtils = elanL2GatewayBcGroupUtils;
49 this.jobCoordinator = jobCoordinator;
50 this.elanInstanceCache = elanInstanceCache;
51 this.elanRefUtil = elanRefUtil;
55 LOG.info("{} registered", getClass().getSimpleName());
59 public void add(InstanceIdentifier<ExternalTeps> instanceIdentifier, ExternalTeps tep) {
60 LOG.trace("ExternalTeps add received {}", instanceIdentifier);
61 updateElanRemoteBroadCastGroup(instanceIdentifier);
65 public void update(InstanceIdentifier<ExternalTeps> instanceIdentifier, ExternalTeps tep, ExternalTeps t1) {
69 public void remove(InstanceIdentifier<ExternalTeps> instanceIdentifier, ExternalTeps tep) {
70 LOG.trace("ExternalTeps remove received {}", instanceIdentifier);
71 updateElanRemoteBroadCastGroup(instanceIdentifier);
74 @SuppressWarnings("checkstyle:IllegalCatch")
75 private void updateElanRemoteBroadCastGroup(final InstanceIdentifier<ExternalTeps> iid) {
76 String elanName = iid.firstKeyOf(ElanInstance.class).getElanInstanceName();
77 ElanInstance elanInfo = elanInstanceCache.get(elanName).orElseGet(null);
78 if (elanInfo == null) {
82 jobCoordinator.enqueueJob(elanName, () -> {
83 SettableFuture<Void> ft = SettableFuture.create();
85 //TODO make the following method return ft
86 elanL2GatewayBcGroupUtils.updateRemoteBroadcastGroupForAllElanDpns(elanInfo);
88 } catch (Exception e) {
89 //since the above method does a sync write , if it fails there was no retry
90 //by setting the above mdsal exception in ft, and returning the ft makes sures that job is retried
93 return Lists.newArrayList(ft);
101 Executors.shutdownAndAwaitTermination(getExecutorService());