9fe2a1c6e5c0256ea230e6ee692ea1b3d3b63030
[genius.git] / itm / itm-impl / src / main / java / org / opendaylight / genius / itm / confighelpers / ItmTepsNotHostedAddWorker.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.Map;
14 import java.util.concurrent.Callable;
15 import org.opendaylight.genius.infra.Datastore;
16 import org.opendaylight.genius.infra.ManagedNewTransactionRunner;
17 import org.opendaylight.mdsal.binding.api.DataBroker;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.not.hosted.transport.zones.tepsinnothostedtransportzone.UnknownVteps;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.not.hosted.transport.zones.tepsinnothostedtransportzone.UnknownVtepsKey;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
22
23 public class ItmTepsNotHostedAddWorker implements Callable<List<? extends ListenableFuture<?>>> {
24
25     private static final Logger LOG = LoggerFactory.getLogger(ItmTepsNotHostedAddWorker.class);
26     private final Map<UnknownVtepsKey, UnknownVteps> vtepsList;
27     private final  String tzName;
28     private final ManagedNewTransactionRunner txRunner;
29
30     public ItmTepsNotHostedAddWorker(Map<UnknownVtepsKey, UnknownVteps> vtepsList, String tzName, DataBroker broker,
31                                      ManagedNewTransactionRunner txRunner) {
32         this.vtepsList = vtepsList;
33         this.tzName = tzName;
34         this.txRunner = txRunner;
35     }
36
37     @Override
38     public List<ListenableFuture<Void>> call() throws Exception {
39         LOG.trace("Add TEP into TepsNotHosted list task is picked from DataStoreJobCoordinator for execution.");
40
41         // Add TEP to TepsNotHosted list.
42         return Collections.singletonList(txRunner.callWithNewReadWriteTransactionAndSubmit(Datastore.OPERATIONAL,
43             tx -> OvsdbTepAddConfigHelper
44                     .addVtepIntoTepsNotHosted(vtepsList, tzName, tx)));
45     }
46 }