Jordan Halterman | 980a8c1 | 2017-09-22 18:01:19 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017-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 | package org.onosproject.upgrade; |
| 17 | |
| 18 | import java.util.Objects; |
| 19 | |
| 20 | import com.google.common.annotations.Beta; |
| 21 | import com.google.common.base.MoreObjects; |
| 22 | import org.onosproject.event.AbstractEvent; |
| 23 | |
| 24 | /** |
| 25 | * Upgrade event. |
| 26 | */ |
| 27 | @Beta |
| 28 | public class UpgradeEvent extends AbstractEvent<UpgradeEvent.Type, Upgrade> { |
| 29 | |
| 30 | /** |
| 31 | * Type of upgrade-related events. |
| 32 | */ |
| 33 | @Beta |
| 34 | public enum Type { |
| 35 | |
| 36 | /** |
| 37 | * Indicates that a new upgrade was initialized. |
| 38 | */ |
| 39 | INITIALIZED, |
| 40 | |
| 41 | /** |
| 42 | * Indicates that mastership was reassigned to the upgraded cluster. |
| 43 | */ |
| 44 | UPGRADED, |
| 45 | |
| 46 | /** |
| 47 | * Indicates that an upgrade was committed. |
| 48 | */ |
| 49 | COMMITTED, |
| 50 | |
| 51 | /** |
| 52 | * Indicates that an upgrade was rolled back. |
| 53 | */ |
| 54 | ROLLED_BACK, |
| 55 | |
| 56 | /** |
| 57 | * Indicates that an upgrade was reset. |
| 58 | */ |
| 59 | RESET, |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * Creates an event of a given type and for the specified state and the |
| 64 | * current time. |
| 65 | * |
| 66 | * @param type upgrade event type |
| 67 | * @param state upgrade state |
| 68 | */ |
| 69 | public UpgradeEvent(UpgradeEvent.Type type, Upgrade state) { |
| 70 | super(type, state); |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * Creates an event of a given type and for the specified state and time. |
| 75 | * |
| 76 | * @param type upgrade event type |
| 77 | * @param state upgrade state |
| 78 | * @param time occurrence time |
| 79 | */ |
| 80 | public UpgradeEvent(UpgradeEvent.Type type, Upgrade state, long time) { |
| 81 | super(type, state, time); |
| 82 | } |
| 83 | |
| 84 | @Override |
| 85 | public int hashCode() { |
| 86 | return Objects.hash(type(), subject(), time()); |
| 87 | } |
| 88 | |
| 89 | @Override |
| 90 | public boolean equals(Object obj) { |
| 91 | if (this == obj) { |
| 92 | return true; |
| 93 | } |
| 94 | if (obj instanceof UpgradeEvent) { |
| 95 | final UpgradeEvent other = (UpgradeEvent) obj; |
| 96 | return Objects.equals(this.type(), other.type()) && |
| 97 | Objects.equals(this.subject(), other.subject()) && |
| 98 | Objects.equals(this.time(), other.time()); |
| 99 | } |
| 100 | return false; |
| 101 | } |
| 102 | |
| 103 | @Override |
| 104 | public String toString() { |
| 105 | return MoreObjects.toStringHelper(this.getClass()) |
| 106 | .add("type", type()) |
| 107 | .add("subject", subject()) |
| 108 | .add("time", time()) |
| 109 | .toString(); |
| 110 | } |
| 111 | |
| 112 | } |