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.elan.l2gw.jobs;
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.elan.l2gw.utils.L2GatewayUtils;
16 import org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayCache;
17 import org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayDevice;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.TransportZone;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rpcs.rev160406.ItmRpcService;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
24 * The Class AddL2GwDevicesToTransportZoneJob.
26 public class AddL2GwDevicesToTransportZoneJob implements Callable<List<? extends ListenableFuture<?>>> {
28 private static final Logger LOG = LoggerFactory.getLogger(AddL2GwDevicesToTransportZoneJob.class);
29 private final ItmRpcService itmRpcService;
30 private final TransportZone transportZone;
31 private final L2GatewayCache l2GatewayCache;
34 * Instantiates a new adds the l2 gw devices to transport zone job.
36 * @param itmRpcService the itm rpc service
37 * @param transportZone the transport zone
38 * @param l2GatewayCache the l2gateway cache
40 public AddL2GwDevicesToTransportZoneJob(ItmRpcService itmRpcService, TransportZone transportZone,
41 L2GatewayCache l2GatewayCache) {
42 this.itmRpcService = itmRpcService;
43 this.transportZone = transportZone;
44 this.l2GatewayCache = l2GatewayCache;
45 LOG.debug("created AddL2GwDevicesToTransportZone Job for tZone {}", transportZone.getZoneName());
53 public String getJobKey() {
54 return "L2GW" + this.transportZone.getZoneName();
60 * @see java.util.concurrent.Callable#call()
63 @SuppressWarnings("checkstyle:IllegalCatch")
64 public List<ListenableFuture<?>> call() {
65 LOG.debug("Running AddL2GwDevicesToTransportZone job for {}", this.transportZone.getZoneName());
67 // When vxlan transport zone is added, add all l2gw devices to that
68 // transport zone. Doesn't matter if tz already has data or not.
69 for (L2GatewayDevice l2gwDevice : l2GatewayCache.getAll()) {
70 if (!l2gwDevice.getL2GatewayIds().isEmpty()) {
71 LOG.debug("Adding l2gw device [{}] to transport zone [{}]", l2gwDevice.getDeviceName(),
72 this.transportZone.getZoneName());
73 L2GatewayUtils.createItmTunnels(itmRpcService, l2gwDevice.getHwvtepNodeId(),
74 l2gwDevice.getDeviceName(), l2gwDevice.getTunnelIp());
77 } catch (Exception e) {
78 LOG.error("Failed during AddL2GwDevicesToTransportZone job ", e);
80 return Collections.emptyList();
86 * @see java.lang.Object#toString()
89 public String toString() {
90 return "AddL2GwDevicesToTransportZoneJob [transportZone=" + transportZone.getZoneName() + "]";