50eb0d4e8bbafab7c1723a6ba5a6234a862ef395
[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     protected int txOk = 0;
28     protected int txError = 0;
29
30     public DatastoreAbstractWriter(final StartTestInput.Operation oper,
31             final int outerListElem, final int innerListElem, final long writesPerTx, final DataStore dataStore) {
32         this.outerListElem = outerListElem;
33         this.innerListElem = innerListElem;
34         this.writesPerTx = writesPerTx;
35         this.oper = oper;
36         this.dataStore = dataStore;
37         LOG.debug("DatastoreAbstractWriter created: {}", this);
38     }
39
40     public abstract void createList();
41
42     public abstract void executeList();
43
44     public int getTxError() {
45         return txError;
46     }
47
48     public int getTxOk() {
49         return txOk;
50     }
51
52     protected LogicalDatastoreType getDataStoreType() {
53         final LogicalDatastoreType dsType;
54         if (dataStore == DataStore.CONFIG) {
55             dsType = LogicalDatastoreType.CONFIGURATION;
56         } else if (dataStore == DataStore.OPERATIONAL) {
57             dsType = LogicalDatastoreType.OPERATIONAL;
58         } else {
59             if (rn.nextBoolean() == true) {
60                 dsType = LogicalDatastoreType.OPERATIONAL;
61             } else {
62                 dsType = LogicalDatastoreType.CONFIGURATION;
63             }
64         }
65         return dsType;
66     }
67 }