1a1ca12f1e4d03f496a7e92dcd0d628cfbf75c42
[netvirt.git] / elanmanager / impl / src / main / java / org / opendaylight / netvirt / elan / internal / InterfaceAddWorkerOnElanInterface.java
1 /*
2  * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.netvirt.elan.internal;
9
10 import com.google.common.util.concurrent.ListenableFuture;
11 import java.util.List;
12 import java.util.concurrent.Callable;
13 import org.opendaylight.genius.interfacemanager.globals.InterfaceInfo;
14 import org.opendaylight.netvirt.elan.utils.ElanUtils;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.instances.ElanInstance;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.interfaces.ElanInterface;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
19
20 public class InterfaceAddWorkerOnElanInterface implements Callable<List<? extends ListenableFuture<?>>> {
21
22     private final String key;
23     private final ElanInterface elanInterface;
24     private final ElanInstance elanInstance;
25     private final InterfaceInfo interfaceInfo;
26     private final ElanInterfaceManager dataChangeListener;
27     private final boolean isFirstInterfaceInDpn;
28     private static final Logger LOG = LoggerFactory.getLogger(InterfaceAddWorkerOnElanInterface.class);
29
30     public InterfaceAddWorkerOnElanInterface(String key, ElanInterface elanInterface, InterfaceInfo interfaceInfo,
31             ElanInstance elanInstance, boolean isFirstInterfaceInDpn, ElanInterfaceManager dataChangeListener) {
32         this.key = key;
33         this.elanInterface = elanInterface;
34         this.interfaceInfo = interfaceInfo;
35         this.elanInstance = elanInstance;
36         this.dataChangeListener = dataChangeListener;
37         this.isFirstInterfaceInDpn = isFirstInterfaceInDpn;
38     }
39
40     @Override
41     public String toString() {
42         return "InterfaceAddWorkerOnElanInterface [key=" + key + ", elanInterface=" + elanInterface + ", elanInstance="
43             + elanInstance + ", interfaceInfo=" + interfaceInfo + "]";
44     }
45
46
47     @Override
48     @SuppressWarnings("checkstyle:IllegalCatch")
49     public List<ListenableFuture<Void>> call() {
50         LOG.info("InterfaceAddWorkerOnElanInterface: Handling elan interface {} add for elan {} ",
51                 elanInterface.getName(), elanInstance.getElanInstanceName());
52         try {
53             return dataChangeListener.setupEntriesForElanInterface(elanInstance, elanInterface, interfaceInfo,
54                     isFirstInterfaceInDpn);
55         } catch (RuntimeException e) {
56             LOG.error("Error while processing key {} for elan interface {} ", key, elanInterface, e);
57             return ElanUtils.returnFailedListenableFutureIfTransactionCommitFailedExceptionCauseOrElseThrow(e);
58         }
59     }
60
61 }