InfraUtil JobCordinator Changes.
[genius.git] / itm / itm-impl / src / main / java / org / opendaylight / genius / itm / confighelpers / ItmTepsNotHostedRemoveWorker.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.genius.infra.Datastore;
15 import org.opendaylight.genius.infra.ManagedNewTransactionRunner;
16 import org.opendaylight.mdsal.binding.api.DataBroker;
17 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
18 import org.opendaylight.yangtools.yang.common.Uint64;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
21
22 public class ItmTepsNotHostedRemoveWorker implements Callable<List<? extends ListenableFuture<?>>> {
23
24     private static final Logger LOG = LoggerFactory.getLogger(ItmTepsNotHostedRemoveWorker.class);
25
26     private final IpAddress tepIpAddress;
27     private final String tzName;
28     private final Uint64 dpnId;
29     private final DataBroker dataBroker;
30     private final ManagedNewTransactionRunner txRunner;
31
32     public ItmTepsNotHostedRemoveWorker(String tzName, IpAddress tepIpAddress, Uint64 dpnId, DataBroker broker,
33                                         ManagedNewTransactionRunner txRunner) {
34         this.tepIpAddress = tepIpAddress;
35         this.tzName = tzName;
36         this.dpnId = dpnId;
37         this.dataBroker = broker;
38         this.txRunner = txRunner;
39     }
40
41     @Override
42     public List<ListenableFuture<Void>> call() throws Exception {
43         LOG.trace("Remove TEP from TepsNotHosted list task is picked from DataStoreJobCoordinator for execution.");
44
45         // Remove TEP from TepsNotHosted list.
46         return Collections.singletonList(txRunner.callWithNewReadWriteTransactionAndSubmit(Datastore.OPERATIONAL,
47             tx -> OvsdbTepRemoveConfigHelper
48                     .removeUnknownTzTepFromTepsNotHosted(tzName, tepIpAddress, dpnId, dataBroker, tx)));
49     }
50 }