Clean up ITM impl *Worker: Use "final" where possible, avoid parameters
[genius.git] / itm / itm-impl / src / main / java / org / opendaylight / genius / itm / confighelpers / ItmTunnelStateRemoveHelper.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.ArrayList;
12 import java.util.List;
13 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
14 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
15 import org.opendaylight.genius.interfacemanager.interfaces.IInterfaceManager;
16 import org.opendaylight.genius.itm.impl.ITMBatchingUtils;
17 import org.opendaylight.genius.itm.impl.ItmUtils;
18 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.tunnels_state.StateTunnelList;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.tunnels_state.StateTunnelListKey;
21 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
24
25 public class ItmTunnelStateRemoveHelper {
26     private static final Logger LOG = LoggerFactory.getLogger(ItmTunnelStateRemoveHelper.class);
27
28     public static List<ListenableFuture<Void>> removeTunnel(Interface iface, IInterfaceManager ifaceManager,
29                                                             DataBroker broker) throws Exception {
30         LOG.debug("Invoking ItmTunnelStateRemoveHelper for Interface {} ", iface);
31         List<ListenableFuture<Void>> futures = new ArrayList<>();
32         WriteTransaction writeTransaction = broker.newWriteOnlyTransaction();
33
34         StateTunnelListKey tlKey = ItmUtils.getTunnelStateKey(iface);
35         InstanceIdentifier<StateTunnelList> stListId = ItmUtils.buildStateTunnelListId(tlKey);
36         LOG.trace("Deleting tunnel_state for Id: {}", stListId);
37         ITMBatchingUtils.delete(stListId, ITMBatchingUtils.EntityType.DEFAULT_OPERATIONAL);
38
39         futures.add(writeTransaction.submit());
40         return futures;
41     }
42 }