Bump upstream SNAPSHOTS
[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 edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
11 import java.util.Random;
12 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.StartTestInput;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.StartTestInput.DataStore;
15 import org.slf4j.Logger;
16 import org.slf4j.LoggerFactory;
17
18 public abstract class DatastoreAbstractWriter {
19     private static final Logger LOG = LoggerFactory.getLogger(DatastoreAbstractWriter.class);
20
21     protected final int outerListElem;
22     protected final int innerListElem;
23     protected final long writesPerTx;
24     protected final StartTestInput.Operation oper;
25     protected final StartTestInput.DataStore dataStore;
26     protected final Random rn = new Random();
27
28     protected int txOk = 0;
29     protected int txError = 0;
30
31     @SuppressFBWarnings(value = "MC_OVERRIDABLE_METHOD_CALL_IN_CONSTRUCTOR", justification = "'this' passed to logging")
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) || (rn.nextBoolean() == true)) {
59             dsType = LogicalDatastoreType.OPERATIONAL;
60         } else {
61             dsType = LogicalDatastoreType.CONFIGURATION;
62         }
63         return dsType;
64     }
65 }