Convert dsbenchmark to mdsal APIs
[controller.git] / benchmark / dsbenchmark / src / main / java / org / opendaylight / dsbenchmark / DatastoreAbstractWriter.java
1 /*
2  * Copyright (c) 2015 Cisco Systems 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.dsbenchmark;
9
10 import java.util.Random;
11 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.StartTestInput;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.StartTestInput.DataStore;
14 import org.slf4j.Logger;
15 import org.slf4j.LoggerFactory;
16
17 public abstract class DatastoreAbstractWriter {
18     private static final Logger LOG = LoggerFactory.getLogger(DatastoreAbstractWriter.class);
19
20     protected final int outerListElem;
21     protected final int innerListElem;
22     protected final long writesPerTx;
23     protected final StartTestInput.Operation oper;
24     protected final StartTestInput.DataStore dataStore;
25     protected final Random rn = new Random();
26
27
28     protected int txOk = 0;
29     protected int txError = 0;
30
31
32     public DatastoreAbstractWriter(final StartTestInput.Operation oper,
33                                    final int outerListElem, final int innerListElem, final long writesPerTx, final DataStore dataStore) {
34         this.outerListElem = outerListElem;
35         this.innerListElem = innerListElem;
36         this.writesPerTx = writesPerTx;
37         this.oper = oper;
38         this.dataStore = dataStore;
39         LOG.debug("DatastoreAbstractWriter created: {}", this);
40     }
41
42     public abstract void createList();
43
44     public abstract void executeList();
45
46     public int getTxError() {
47         return txError;
48     }
49
50     public int getTxOk() {
51         return txOk;
52     }
53
54     protected LogicalDatastoreType getDataStoreType() {
55         final LogicalDatastoreType dsType;
56         if (dataStore == DataStore.CONFIG) {
57             dsType = LogicalDatastoreType.CONFIGURATION;
58         } else if (dataStore == DataStore.OPERATIONAL) {
59             dsType = LogicalDatastoreType.OPERATIONAL;
60         } else {
61             if (rn.nextBoolean() == true) {
62                 dsType = LogicalDatastoreType.OPERATIONAL;
63             } else {
64                 dsType = LogicalDatastoreType.CONFIGURATION;
65             }
66         }
67         return dsType;
68     }
69 }