/* * Copyright (c) 2015 Cisco Systems and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ package org.opendaylight.dsbenchmark.simpletx; import java.util.concurrent.ExecutionException; import org.opendaylight.dsbenchmark.DatastoreAbstractWriter; import org.opendaylight.mdsal.common.api.LogicalDatastoreType; import org.opendaylight.mdsal.dom.api.DOMDataBroker; import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.StartTestInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.StartTestInput.DataStore; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.TestExec; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.test.exec.OuterList; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class SimpletxDomDelete extends DatastoreAbstractWriter { private static final Logger LOG = LoggerFactory.getLogger(SimpletxDomDelete.class); private final DOMDataBroker domDataBroker; public SimpletxDomDelete(final DOMDataBroker domDataBroker, final int outerListElem, final int innerListElem, final long writesPerTx, final DataStore dataStore) { super(StartTestInput.Operation.DELETE, outerListElem, innerListElem, writesPerTx, dataStore); this.domDataBroker = domDataBroker; LOG.debug("Created simpleTxDomDelete"); } @Override public void createList() { LOG.debug("SimpletxDomDelete: creating data in the data store"); // Dump the whole list into the data store in a single transaction // with PUTs on the transaction SimpletxDomWrite dd = new SimpletxDomWrite(domDataBroker, StartTestInput.Operation.PUT, outerListElem, innerListElem, outerListElem, dataStore); dd.createList(); dd.executeList(); } @Override public void executeList() { final LogicalDatastoreType dsType = getDataStoreType(); final org.opendaylight.yangtools.yang.common.QName olId = QName.create(OuterList.QNAME, "id"); final YangInstanceIdentifier pid = YangInstanceIdentifier.builder().node(TestExec.QNAME).node(OuterList.QNAME).build(); DOMDataTreeWriteTransaction tx = domDataBroker.newWriteOnlyTransaction(); long writeCnt = 0; for (int l = 0; l < outerListElem; l++) { YangInstanceIdentifier yid = pid.node(new NodeIdentifierWithPredicates(OuterList.QNAME, olId, l)); tx.delete(dsType, yid); writeCnt++; if (writeCnt == writesPerTx) { try { tx.commit().get(); txOk++; } catch (final InterruptedException | ExecutionException e) { LOG.error("Transaction failed: {}", e); txError++; } tx = domDataBroker.newWriteOnlyTransaction(); writeCnt = 0; } } if (writeCnt != 0) { try { tx.commit().get(); } catch (final InterruptedException | ExecutionException e) { LOG.error("Transaction failed: {}", e); } } } }