Added support for multiple data store types to DOM transaction chains and to simple...
[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.info("DatastoreAbstractWriter created: {}", this);
42     }
43
44     public abstract void createList();
45     public abstract void executeList();
46
47     public int getTxError() {
48         return txError;
49     }
50
51     public int getTxOk() {
52         return txOk;
53     }
54
55     protected LogicalDatastoreType getDataStoreType() {
56         final LogicalDatastoreType dsType;
57         if (dataStore == DataStore.CONFIG) {
58             dsType = LogicalDatastoreType.CONFIGURATION;
59         }
60         else if (dataStore == DataStore.OPERATIONAL) {
61             dsType = LogicalDatastoreType.OPERATIONAL;
62         }
63         else
64         {
65             if (rn.nextBoolean() == true) {
66                 dsType = LogicalDatastoreType.OPERATIONAL;
67             } else {
68                 dsType = LogicalDatastoreType.CONFIGURATION;
69             }
70         }
71         return dsType;
72     }
73 }