Convert itm-impl to use mdsal-binding-util
[genius.git] / itm / itm-impl / src / main / java / org / opendaylight / genius / itm / confighelpers / ItmTepsNotHostedMoveWorker.java
1 /*
2  * Copyright (c) 2017 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.genius.itm.confighelpers;
9
10 import com.google.common.util.concurrent.ListenableFuture;
11 import java.util.Collections;
12 import java.util.List;
13 import java.util.concurrent.Callable;
14 import org.opendaylight.mdsal.binding.util.Datastore;
15 import org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunner;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.Vteps;
17 import org.opendaylight.yangtools.yang.common.Uint64;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
20
21 public class ItmTepsNotHostedMoveWorker implements Callable<List<? extends ListenableFuture<?>>> {
22
23     private static final Logger LOG = LoggerFactory.getLogger(ItmTepsNotHostedMoveWorker.class);
24
25     private final  List<Vteps> vtepsList;
26     private final  String tzName;
27     private final ManagedNewTransactionRunner txRunner;
28
29     public ItmTepsNotHostedMoveWorker(List<Vteps> vtepsList, String tzName, ManagedNewTransactionRunner txRunner) {
30         this.vtepsList = vtepsList;
31         this.tzName = tzName;
32         this.txRunner = txRunner;
33     }
34
35     @Override
36     public List<? extends ListenableFuture<?>> call() throws Exception {
37         LOG.trace("Move TEP from TepsNotHosted list to NBI configured TZ task is picked from "
38                 + "DataStoreJobCoordinator for execution.");
39
40         // Move TEP from TepsNotHosted list to NBI configured TZ.
41         return Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(Datastore
42             .CONFIGURATION, tx -> OvsdbTepAddConfigHelper.addVtepInITMConfigDS(
43             vtepsList, null /*tepIpAddress*/, tzName, Uint64.ZERO,
44             false, tx)));
45     }
46 }