blob: a627292b262f71288b0b659a57514447afc60aeb [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;
Ray Milkey7a2dee52018-09-28 10:58:28 -070021import org.apache.karaf.shell.api.action.lifecycle.Service;
utkarsh663d0eb2018-04-10 14:52:06 +090022import org.onosproject.cli.AbstractShellCommand;
23import org.onosproject.clusterha.ClusterHATest;
24
Ray Milkey7a2dee52018-09-28 10:58:28 -070025@Service
utkarsh663d0eb2018-04-10 14:52:06 +090026@Command(scope = "onos", name = "cluster-ha-test",
27 description = "test addition & deletion on consistent map")
28public class ClusterHATestCommand extends AbstractShellCommand {
29
30 @Argument(index = 0, name = "operation", description = "add/del", required = true)
31 private String operation = null;
32
33 @Argument(index = 1, name = "strStartIdx", description = "start index", required = true)
34 private String strStartIdx = null;
35
36 @Argument(index = 2, name = "strEndIdx", description = "end index", required = true)
37 private String strEndIdx = null;
38
39 @Argument(index = 3, name = "strInterOpDelay", description = "inter operation delay(ms)", required = true)
40 private String strInterOpDelay = null;
41
42 private static final String OP_ADD = "add";
43 private static final String OP_DEL = "del";
44
45 private static final int COUNT = 100;
46 private static final String STR = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
47 private static final String CONSTANT = new String(new char[COUNT]).replace("\0", STR);
48
49 @Override
Ray Milkey86ad7bb2018-09-27 12:32:28 -070050 protected void doExecute() {
utkarsh663d0eb2018-04-10 14:52:06 +090051 ClusterHATest service = get(ClusterHATest.class);
52 int iStartIdx = 0, iEndIdx = 0;
53 long lInterOpDelay = 0L;
54
55 try {
56 iStartIdx = Integer.parseInt(strStartIdx);
57 iEndIdx = Integer.parseInt(strEndIdx);
58 lInterOpDelay = Long.parseLong(strInterOpDelay);
59 } catch (Exception e) {
60 print(e.getMessage());
61 return;
62 }
63
64 if (!OP_ADD.equals(operation) && !OP_DEL.equals(operation)) {
65 print("invalid operation " + operation);
66 return;
67 }
68
69 print("cluster-ha-test " + operation + " " + iStartIdx + " " + iEndIdx + " " + lInterOpDelay);
70
71 if (OP_ADD.equals(operation)) {
72 for (int i = iStartIdx; i <= iEndIdx; i++) {
73 service.addToStringStore(i, CONSTANT);
74 try {
75 Thread.sleep(lInterOpDelay);
76 } catch (Exception e) {
77 return;
78 }
79 }
80
81 } else if (OP_DEL.equals(operation)) {
82 for (int i = iStartIdx; i <= iEndIdx; i++) {
83 service.removeStringFromStore(i);
84 try {
85 Thread.sleep(lInterOpDelay);
86 } catch (Exception e) {
87
88 }
89 }
90 } else {
91 print("Invalid operation " + operation);
92 }
93 }
94}