2 * Copyright (c) 2016 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
9 package org.opendaylight.netvirt.neutronvpn.l2gw;
11 import com.google.common.util.concurrent.ListenableFuture;
12 import java.util.Collections;
13 import java.util.List;
14 import java.util.concurrent.Callable;
15 import java.util.concurrent.ConcurrentMap;
16 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
17 import org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayDevice;
18 import org.opendaylight.netvirt.neutronvpn.api.l2gw.utils.L2GatewayCacheUtils;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.TransportZone;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rpcs.rev160406.ItmRpcService;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
25 * The Class AddL2GwDevicesToTransportZoneJob.
27 public class AddL2GwDevicesToTransportZoneJob implements Callable<List<ListenableFuture<Void>>> {
29 /** The Constant LOG. */
30 private static final Logger LOG = LoggerFactory.getLogger(AddL2GwDevicesToTransportZoneJob.class);
32 /** The data broker. */
33 private DataBroker dataBroker;
35 /** The itm rpc service. */
36 private ItmRpcService itmRpcService;
38 /** The transport zone. */
39 private TransportZone transportZone;
42 * Instantiates a new adds the l2 gw devices to transport zone job.
44 * @param dataBroker the data broker
45 * @param itmRpcService the itm rpc service
46 * @param transportZone the transport zone
48 public AddL2GwDevicesToTransportZoneJob(DataBroker dataBroker, ItmRpcService itmRpcService,
49 TransportZone transportZone) {
50 this.dataBroker = dataBroker;
51 this.itmRpcService = itmRpcService;
52 this.transportZone = transportZone;
53 LOG.debug("created AddL2GwDevicesToTransportZone Job for tZone {}", transportZone.getZoneName());
61 public String getJobKey() {
62 return "L2GW" + this.transportZone.getZoneName();
68 * @see java.util.concurrent.Callable#call()
71 public List<ListenableFuture<Void>> call() throws Exception {
72 LOG.debug("Running AddL2GwDevicesToTransportZone job for {}", this.transportZone.getZoneName());
74 // When vxlan transport zone is added, add all l2gw devices to that
75 // transport zone. Doesn't matter if tz already has data or not.
76 ConcurrentMap<String, L2GatewayDevice> l2GwDevices = L2GatewayCacheUtils.getCache();
77 for (L2GatewayDevice l2gwDevice : l2GwDevices.values()) {
78 if (!l2gwDevice.getL2GatewayIds().isEmpty()) {
79 LOG.debug("Adding l2gw device [{}] to transport zone [{}]", l2gwDevice.getDeviceName(),
80 this.transportZone.getZoneName());
81 L2GatewayUtils.createItmTunnels(itmRpcService, l2gwDevice.getHwvtepNodeId(),
82 l2gwDevice.getDeviceName(), l2gwDevice.getTunnelIp());
85 } catch (Exception e) {
86 LOG.error("Failed during AddL2GwDevicesToTransportZone job ", e);
88 return Collections.emptyList();
94 * @see java.lang.Object#toString()
97 public String toString() {
98 return "AddL2GwDevicesToTransportZoneJob [transportZone=" + transportZone.getZoneName() + "]";