2 * Copyright (c) 2015 China Telecom Beijing Research Institute and others. All rights reserved.
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
9 package org.opendaylight.ovsdb.hwvtepsouthbound.transact;
11 import static org.opendaylight.ovsdb.lib.operations.Operations.op;
13 import java.util.Collection;
14 import java.util.List;
15 import java.util.Objects;
16 import java.util.concurrent.TimeUnit;
17 import java.util.concurrent.atomic.AtomicInteger;
19 import org.opendaylight.mdsal.binding.api.DataTreeModification;
20 import org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepSouthboundConstants;
21 import org.opendaylight.ovsdb.lib.operations.TransactionBuilder;
22 import org.opendaylight.ovsdb.lib.schema.typed.TyperUtils;
23 import org.opendaylight.ovsdb.schema.hardwarevtep.LogicalSwitch;
24 import org.opendaylight.ovsdb.utils.mdsal.utils.Scheduler;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentation;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LogicalSwitches;
27 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
28 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
32 public class PlainLogicalSwitchRemoveCmd extends AbstractTransactCommand<LogicalSwitches, HwvtepGlobalAugmentation> {
33 private static final Logger LOG = LoggerFactory.getLogger(PlainLogicalSwitchRemoveCmd.class);
34 private AtomicInteger retryCount = new AtomicInteger(5);
35 private LogicalSwitches logicalSwitches;
36 private InstanceIdentifier<Node> nodeIid;
38 public PlainLogicalSwitchRemoveCmd(HwvtepOperationalState state,
39 Collection<DataTreeModification<Node>> changes,
40 LogicalSwitches logicalSwitches,
42 super(state, changes);
43 this.logicalSwitches = logicalSwitches;
44 this.retryCount = new AtomicInteger(retryCount);
45 this.nodeIid = getOperationalState().getConnectionInstance().getInstanceIdentifier();
49 public void execute(TransactionBuilder transaction) {
50 LogicalSwitch logicalSwitch = TyperUtils.getTypedRowWrapper(
51 transaction.getDatabaseSchema(), LogicalSwitch.class, null);
52 transaction.add(op.delete(logicalSwitch.getSchema())
53 .where(logicalSwitch.getNameColumn().getSchema().opEqual(
54 logicalSwitches.getHwvtepNodeName().getValue())).build());
58 protected List<LogicalSwitches> getData(HwvtepGlobalAugmentation augmentation) {
59 return augmentation.getLogicalSwitches();
63 protected boolean areEqual(LogicalSwitches logicalSwitches1 , LogicalSwitches logicalSwitches2) {
64 return logicalSwitches1.key().equals(logicalSwitches2.key())
65 && Objects.equals(logicalSwitches1.getTunnelKey(), logicalSwitches2.getTunnelKey());
68 public boolean retry() {
69 boolean ret = retryCount.decrementAndGet() > 0;
71 Scheduler.getScheduledExecutorService().schedule(() -> {
72 getOperationalState().getConnectionInstance().transact(this);
73 }, HwvtepSouthboundConstants.LS_REMOVE_DELAY_SECS, TimeUnit.SECONDS);
75 LOG.error("Failed in deletion of logical switch {}", logicalSwitches);
80 protected boolean isDeleteCmd() {