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.genius.infra.Datastore.CONFIGURATION;
12 import com.google.common.base.Optional;
13 import com.google.common.collect.Lists;
14 import com.google.common.util.concurrent.ListenableFuture;
16 import java.util.List;
17 import java.util.concurrent.Callable;
19 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
20 import org.opendaylight.genius.infra.ManagedNewTransactionRunner;
21 import org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl;
22 import org.opendaylight.netvirt.elan.l2gw.utils.ElanL2GatewayMulticastUtils;
23 import org.opendaylight.netvirt.elan.l2gw.utils.ElanRefUtil;
24 import org.opendaylight.netvirt.elan.utils.ElanUtils;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.instances.ElanInstance;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
29 public class BcGroupUpdateJob implements Callable<List<ListenableFuture<Void>>> {
31 private static final Logger LOG = LoggerFactory.getLogger("HwvtepEventLogger");
33 private final String elanName;
34 private final ElanL2GatewayMulticastUtils elanL2GatewayMulticastUtils;
35 private final ElanRefUtil elanRefUtil;
36 private final ManagedNewTransactionRunner txRunner;
37 protected String jobKey;
38 private final boolean createCase;
40 public BcGroupUpdateJob(String elanName,
41 ElanRefUtil elanRefUtil,
42 ElanL2GatewayMulticastUtils elanL2GatewayMulticastUtils,
43 DataBroker dataBroker, boolean createCase) {
44 this.jobKey = ElanUtils.getBcGroupUpdateKey(elanName);
45 this.txRunner = new ManagedNewTransactionRunnerImpl(dataBroker);
46 this.elanName = elanName;
47 this.elanRefUtil = elanRefUtil;
48 this.elanL2GatewayMulticastUtils = elanL2GatewayMulticastUtils;
49 this.createCase = createCase;
52 public void submit() {
53 elanRefUtil.getElanClusterUtils().runOnlyInOwnerNode(this.jobKey, "BC Group Update Job", this);
57 public List<ListenableFuture<Void>> call() throws Exception {
58 Optional<ElanInstance> elanInstanceOptional = elanRefUtil.getElanInstanceCache().get(elanName);
59 if (elanInstanceOptional.isPresent()) {
60 return Lists.newArrayList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION,
61 confTx -> elanL2GatewayMulticastUtils.updateRemoteBroadcastGroupForAllElanDpns(
62 elanInstanceOptional.get(), createCase, confTx)));
67 public static void updateAllBcGroups(String elanName,
68 ElanRefUtil elanRefUtil,
69 ElanL2GatewayMulticastUtils elanL2GatewayMulticastUtils,
70 DataBroker dataBroker, boolean createCase) {
71 new BcGroupUpdateJob(elanName, elanRefUtil, elanL2GatewayMulticastUtils, dataBroker, createCase).submit();