NETVIRT-1630 migrate to md-sal APIs
[netvirt.git] / elanmanager / impl / src / main / java / org / opendaylight / netvirt / elan / internal / InterfaceAddWorkerOnElan.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 InterfaceAddWorkerOnElan implements Callable<List<? extends ListenableFuture<?>>> {
21
22     private static final Logger LOG = LoggerFactory.getLogger(InterfaceAddWorkerOnElan.class);
23
24     private final String key;
25     private final ElanInterface elanInterface;
26     private final ElanInstance elanInstance;
27     private final InterfaceInfo interfaceInfo;
28     private final ElanInterfaceManager dataChangeListener;
29
30     public InterfaceAddWorkerOnElan(String key, ElanInterface elanInterface, InterfaceInfo interfaceInfo,
31                                     ElanInstance elanInstance, ElanInterfaceManager dataChangeListener) {
32         this.key = key;
33         this.elanInterface = elanInterface;
34         this.interfaceInfo = interfaceInfo;
35         this.elanInstance = elanInstance;
36         this.dataChangeListener = dataChangeListener;
37     }
38
39     @Override
40     public String toString() {
41         return "InterfaceAddWorkerOnElan [key=" + key + ", elanInterface=" + elanInterface + ", elanInstance="
42             + elanInstance + ", interfaceInfo=" + interfaceInfo + "]";
43     }
44
45
46     @Override
47     @SuppressWarnings("checkstyle:IllegalCatch")
48     public List<ListenableFuture<Void>> call() {
49         LOG.info("InterfaceAddWorkerOnElan: Handling elan interface add for elan interface: {} and elan instance: {} ",
50                 elanInterface.getName(), elanInstance.getElanInstanceName());
51         try {
52             return dataChangeListener.addElanInterface(elanInterface, interfaceInfo, elanInstance);
53         } catch (RuntimeException e) {
54             return ElanUtils.returnFailedListenableFutureIfTransactionCommitFailedExceptionCauseOrElseThrow(e);
55         }
56     }
57 }