utkarsh | 663d0eb | 2018-04-10 14:52:06 +0900 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package org.onosproject.clusterha.cli; |
| 18 | |
Ray Milkey | 86ad7bb | 2018-09-27 12:32:28 -0700 | [diff] [blame] | 19 | import org.apache.karaf.shell.api.action.Argument; |
| 20 | import org.apache.karaf.shell.api.action.Command; |
Ray Milkey | 7a2dee5 | 2018-09-28 10:58:28 -0700 | [diff] [blame] | 21 | import org.apache.karaf.shell.api.action.lifecycle.Service; |
utkarsh | 663d0eb | 2018-04-10 14:52:06 +0900 | [diff] [blame] | 22 | import org.onosproject.cli.AbstractShellCommand; |
| 23 | import org.onosproject.clusterha.ClusterHATest; |
| 24 | |
Ray Milkey | 7a2dee5 | 2018-09-28 10:58:28 -0700 | [diff] [blame] | 25 | @Service |
utkarsh | 663d0eb | 2018-04-10 14:52:06 +0900 | [diff] [blame] | 26 | @Command(scope = "onos", name = "cluster-ha-test", |
| 27 | description = "test addition & deletion on consistent map") |
| 28 | public 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 Milkey | 86ad7bb | 2018-09-27 12:32:28 -0700 | [diff] [blame] | 50 | protected void doExecute() { |
utkarsh | 663d0eb | 2018-04-10 14:52:06 +0900 | [diff] [blame] | 51 | 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 | } |