2 * Copyright (c) 2016 - 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
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 org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayCache;
16 import org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayDevice;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.TransportZone;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rpcs.rev160406.ItmRpcService;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
23 * The Class AddL2GwDevicesToTransportZoneJob.
25 public class AddL2GwDevicesToTransportZoneJob implements Callable<List<ListenableFuture<Void>>> {
27 private static final Logger LOG = LoggerFactory.getLogger(AddL2GwDevicesToTransportZoneJob.class);
28 private final ItmRpcService itmRpcService;
29 private final TransportZone transportZone;
30 private final L2GatewayCache l2GatewayCache;
33 * Instantiates a new adds the l2 gw devices to transport zone job.
35 * @param itmRpcService the itm rpc service
36 * @param transportZone the transport zone
38 public AddL2GwDevicesToTransportZoneJob(ItmRpcService itmRpcService, TransportZone transportZone,
39 L2GatewayCache l2GatewayCache) {
40 this.itmRpcService = itmRpcService;
41 this.transportZone = transportZone;
42 this.l2GatewayCache = l2GatewayCache;
43 LOG.debug("created AddL2GwDevicesToTransportZone Job for tZone {}", transportZone.getZoneName());
51 public String getJobKey() {
52 return "L2GW" + this.transportZone.getZoneName();
58 * @see java.util.concurrent.Callable#call()
61 @SuppressWarnings("checkstyle:IllegalCatch")
62 public List<ListenableFuture<Void>> call() throws Exception {
63 LOG.debug("Running AddL2GwDevicesToTransportZone job for {}", this.transportZone.getZoneName());
65 // When vxlan transport zone is added, add all l2gw devices to that
66 // transport zone. Doesn't matter if tz already has data or not.
67 for (L2GatewayDevice l2gwDevice : l2GatewayCache.getAll()) {
68 if (!l2gwDevice.getL2GatewayIds().isEmpty()) {
69 LOG.debug("Adding l2gw device [{}] to transport zone [{}]", l2gwDevice.getDeviceName(),
70 this.transportZone.getZoneName());
71 L2GatewayUtils.createItmTunnels(itmRpcService, l2gwDevice.getHwvtepNodeId(),
72 l2gwDevice.getDeviceName(), l2gwDevice.getTunnelIp());
75 } catch (Exception e) {
76 LOG.error("Failed during AddL2GwDevicesToTransportZone job ", e);
78 return Collections.emptyList();
84 * @see java.lang.Object#toString()
87 public String toString() {
88 return "AddL2GwDevicesToTransportZoneJob [transportZone=" + transportZone.getZoneName() + "]";