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