2 * Copyright (c) 2019 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.l2gw.jobs;
10 import static org.opendaylight.mdsal.binding.util.Datastore.CONFIGURATION;
12 import com.google.common.collect.Lists;
13 import com.google.common.util.concurrent.ListenableFuture;
14 import java.util.List;
15 import java.util.Optional;
16 import java.util.concurrent.Callable;
17 import org.opendaylight.mdsal.binding.api.DataBroker;
18 import org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunner;
19 import org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunnerImpl;
20 import org.opendaylight.netvirt.elan.l2gw.utils.ElanL2GatewayMulticastUtils;
21 import org.opendaylight.netvirt.elan.l2gw.utils.ElanRefUtil;
22 import org.opendaylight.netvirt.elan.utils.ElanUtils;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.instances.ElanInstance;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
27 public class BcGroupUpdateJob implements Callable<List<? extends ListenableFuture<?>>> {
29 private static final Logger LOG = LoggerFactory.getLogger("HwvtepEventLogger");
31 private final String elanName;
32 private final ElanL2GatewayMulticastUtils elanL2GatewayMulticastUtils;
33 private final ElanRefUtil elanRefUtil;
34 private final ManagedNewTransactionRunner txRunner;
35 protected String jobKey;
36 private final boolean createCase;
38 public BcGroupUpdateJob(String elanName,
39 ElanRefUtil elanRefUtil,
40 ElanL2GatewayMulticastUtils elanL2GatewayMulticastUtils,
41 DataBroker dataBroker, boolean createCase) {
42 this.jobKey = ElanUtils.getBcGroupUpdateKey(elanName);
43 this.txRunner = new ManagedNewTransactionRunnerImpl(dataBroker);
44 this.elanName = elanName;
45 this.elanRefUtil = elanRefUtil;
46 this.elanL2GatewayMulticastUtils = elanL2GatewayMulticastUtils;
47 this.createCase = createCase;
50 public void submit() {
51 elanRefUtil.getElanClusterUtils().runOnlyInOwnerNode(this.jobKey, "BC Group Update Job", this);
55 public List<ListenableFuture<?>> call() throws Exception {
56 Optional<ElanInstance> elanInstanceOptional = elanRefUtil.getElanInstanceCache().get(elanName);
57 if (elanInstanceOptional.isPresent()) {
58 return Lists.newArrayList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION,
59 confTx -> elanL2GatewayMulticastUtils.updateRemoteBroadcastGroupForAllElanDpns(
60 elanInstanceOptional.get(), createCase, confTx)));
65 public static void updateAllBcGroups(String elanName,
66 ElanRefUtil elanRefUtil,
67 ElanL2GatewayMulticastUtils elanL2GatewayMulticastUtils,
68 DataBroker dataBroker, boolean createCase) {
69 new BcGroupUpdateJob(elanName, elanRefUtil, elanL2GatewayMulticastUtils, dataBroker, createCase).submit();