Thomas Vachuska | 50ec1af | 2015-06-02 00:42:52 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 Open Networking Laboratory |
| 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 | package org.onlab.stc; |
| 17 | |
| 18 | import org.onlab.stc.Coordinator.Status; |
| 19 | |
| 20 | import static java.lang.Long.parseLong; |
| 21 | |
| 22 | /** |
| 23 | * Represents an event of execution of a scenario step or group. |
| 24 | */ |
| 25 | public class StepEvent { |
| 26 | |
| 27 | private final String name; |
| 28 | private final long time; |
| 29 | private final Status status; |
| 30 | |
| 31 | /** |
| 32 | * Creates a new step record. |
| 33 | * |
| 34 | * @param name test step or group name |
| 35 | * @param time time in millis since start of epoch |
| 36 | * @param status step completion status |
| 37 | */ |
| 38 | public StepEvent(String name, long time, Status status) { |
| 39 | this.name = name; |
| 40 | this.time = time; |
| 41 | this.status = status; |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * Creates a new step record for non-running status. |
| 46 | * |
| 47 | * @param name test step or group name |
| 48 | * @param status status |
| 49 | */ |
| 50 | public StepEvent(String name, Status status) { |
| 51 | this(name, System.currentTimeMillis(), status); |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * Returns the test step or test group name. |
| 56 | * |
| 57 | * @return step or group name |
| 58 | */ |
| 59 | public String name() { |
| 60 | return name; |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * Returns the step event time. |
| 65 | * |
| 66 | * @return time in millis since start of epoch |
| 67 | */ |
| 68 | public long time() { |
| 69 | return time; |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * Returns the step completion status. |
| 74 | * |
| 75 | * @return completion status |
| 76 | */ |
| 77 | public Status status() { |
| 78 | return status; |
| 79 | } |
| 80 | |
| 81 | |
| 82 | @Override |
| 83 | public String toString() { |
| 84 | return name + ":" + time + ":" + status; |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | * Returns a record parsed from the specified string. |
| 89 | * |
| 90 | * @param string string encoding |
| 91 | * @return step record |
| 92 | */ |
| 93 | public static StepEvent fromString(String string) { |
| 94 | String[] fields = string.split(":"); |
| 95 | return new StepEvent(fields[0], parseLong(fields[1]), Status.valueOf(fields[2])); |
| 96 | } |
| 97 | } |