blob: 94e1c7e6f9ed44e611fdd74364fd83aedefaf6eb [file] [log] [blame]
utkarsh663d0eb2018-04-10 14:52:06 +09001/*
2 * Copyright 2018-present Open Networking Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package org.onosproject.clusterha.cli;
18
Ray Milkey86ad7bb2018-09-27 12:32:28 -070019import org.apache.karaf.shell.api.action.Argument;
20import org.apache.karaf.shell.api.action.Command;
utkarsh663d0eb2018-04-10 14:52:06 +090021import org.onosproject.cli.AbstractShellCommand;
22import org.onosproject.clusterha.ClusterHATest;
23
24@Command(scope = "onos", name = "cluster-ha-test",
25 description = "test addition & deletion on consistent map")
26public class ClusterHATestCommand extends AbstractShellCommand {
27
28 @Argument(index = 0, name = "operation", description = "add/del", required = true)
29 private String operation = null;
30
31 @Argument(index = 1, name = "strStartIdx", description = "start index", required = true)
32 private String strStartIdx = null;
33
34 @Argument(index = 2, name = "strEndIdx", description = "end index", required = true)
35 private String strEndIdx = null;
36
37 @Argument(index = 3, name = "strInterOpDelay", description = "inter operation delay(ms)", required = true)
38 private String strInterOpDelay = null;
39
40 private static final String OP_ADD = "add";
41 private static final String OP_DEL = "del";
42
43 private static final int COUNT = 100;
44 private static final String STR = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
45 private static final String CONSTANT = new String(new char[COUNT]).replace("\0", STR);
46
47 @Override
Ray Milkey86ad7bb2018-09-27 12:32:28 -070048 protected void doExecute() {
utkarsh663d0eb2018-04-10 14:52:06 +090049 ClusterHATest service = get(ClusterHATest.class);
50 int iStartIdx = 0, iEndIdx = 0;
51 long lInterOpDelay = 0L;
52
53 try {
54 iStartIdx = Integer.parseInt(strStartIdx);
55 iEndIdx = Integer.parseInt(strEndIdx);
56 lInterOpDelay = Long.parseLong(strInterOpDelay);
57 } catch (Exception e) {
58 print(e.getMessage());
59 return;
60 }
61
62 if (!OP_ADD.equals(operation) && !OP_DEL.equals(operation)) {
63 print("invalid operation " + operation);
64 return;
65 }
66
67 print("cluster-ha-test " + operation + " " + iStartIdx + " " + iEndIdx + " " + lInterOpDelay);
68
69 if (OP_ADD.equals(operation)) {
70 for (int i = iStartIdx; i <= iEndIdx; i++) {
71 service.addToStringStore(i, CONSTANT);
72 try {
73 Thread.sleep(lInterOpDelay);
74 } catch (Exception e) {
75 return;
76 }
77 }
78
79 } else if (OP_DEL.equals(operation)) {
80 for (int i = iStartIdx; i <= iEndIdx; i++) {
81 service.removeStringFromStore(i);
82 try {
83 Thread.sleep(lInterOpDelay);
84 } catch (Exception e) {
85
86 }
87 }
88 } else {
89 print("Invalid operation " + operation);
90 }
91 }
92}