Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2014-present Open Networking Laboratory |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.mastership; |
Ayaka Koshibe | 8b3270f | 2014-09-22 13:44:42 -0700 | [diff] [blame] | 17 | |
Yuta HIGUCHI | b87ef95 | 2014-10-28 23:34:23 -0700 | [diff] [blame] | 18 | import org.joda.time.LocalDateTime; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 19 | import org.onosproject.cluster.RoleInfo; |
| 20 | import org.onosproject.event.AbstractEvent; |
| 21 | import org.onosproject.net.DeviceId; |
Ayaka Koshibe | 8b3270f | 2014-09-22 13:44:42 -0700 | [diff] [blame] | 22 | |
Yuta HIGUCHI | fd5cdf1 | 2014-10-26 13:28:48 -0700 | [diff] [blame] | 23 | import com.google.common.base.MoreObjects; |
| 24 | |
Ayaka Koshibe | 8b3270f | 2014-09-22 13:44:42 -0700 | [diff] [blame] | 25 | /** |
Ayaka Koshibe | 8d504a9 | 2014-09-22 17:07:36 -0700 | [diff] [blame] | 26 | * Describes a device mastership event. |
Ayaka Koshibe | 8b3270f | 2014-09-22 13:44:42 -0700 | [diff] [blame] | 27 | */ |
| 28 | public class MastershipEvent extends AbstractEvent<MastershipEvent.Type, DeviceId> { |
| 29 | |
Ayaka Koshibe | fc981cf | 2014-10-21 12:44:17 -0700 | [diff] [blame] | 30 | //Contains master and standby information. |
| 31 | RoleInfo roleInfo; |
Ayaka Koshibe | 8b3270f | 2014-09-22 13:44:42 -0700 | [diff] [blame] | 32 | |
| 33 | /** |
| 34 | * Type of mastership events. |
| 35 | */ |
| 36 | public enum Type { |
| 37 | /** |
| 38 | * Signifies that the master for a device has changed. |
| 39 | */ |
Ayaka Koshibe | 67af1f4 | 2014-10-20 15:26:37 -0700 | [diff] [blame] | 40 | MASTER_CHANGED, |
| 41 | |
| 42 | /** |
Ayaka Koshibe | 98bd12f | 2014-11-01 20:13:37 -0700 | [diff] [blame] | 43 | * Signifies that the list of backup nodes has changed. If |
| 44 | * the change in the backups list is accompanied by a change in |
| 45 | * master, the event is subsumed by MASTER_CHANGED. |
Ayaka Koshibe | 67af1f4 | 2014-10-20 15:26:37 -0700 | [diff] [blame] | 46 | */ |
Jon Hall | 7a8bfc6 | 2016-05-26 17:59:04 -0700 | [diff] [blame] | 47 | BACKUPS_CHANGED, |
| 48 | |
| 49 | /** |
| 50 | * Signifies that the underlying storage for the Mastership state |
| 51 | * of this device is unavailable. |
| 52 | */ |
| 53 | SUSPENDED |
Ayaka Koshibe | 8b3270f | 2014-09-22 13:44:42 -0700 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | /** |
Ayaka Koshibe | fc981cf | 2014-10-21 12:44:17 -0700 | [diff] [blame] | 57 | * Creates an event of a given type and for the specified device, |
| 58 | * role information, and the current time. |
Ayaka Koshibe | 8b3270f | 2014-09-22 13:44:42 -0700 | [diff] [blame] | 59 | * |
Yuta HIGUCHI | 8cc4378 | 2014-10-30 18:06:43 -0700 | [diff] [blame] | 60 | * @param type mastership event type |
Ayaka Koshibe | 8b3270f | 2014-09-22 13:44:42 -0700 | [diff] [blame] | 61 | * @param device event device subject |
Yuta HIGUCHI | 8cc4378 | 2014-10-30 18:06:43 -0700 | [diff] [blame] | 62 | * @param info mastership role information |
Ayaka Koshibe | 8b3270f | 2014-09-22 13:44:42 -0700 | [diff] [blame] | 63 | */ |
Ayaka Koshibe | fc981cf | 2014-10-21 12:44:17 -0700 | [diff] [blame] | 64 | public MastershipEvent(Type type, DeviceId device, RoleInfo info) { |
Ayaka Koshibe | 8b3270f | 2014-09-22 13:44:42 -0700 | [diff] [blame] | 65 | super(type, device); |
Ayaka Koshibe | fc981cf | 2014-10-21 12:44:17 -0700 | [diff] [blame] | 66 | this.roleInfo = info; |
Ayaka Koshibe | 8b3270f | 2014-09-22 13:44:42 -0700 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | /** |
| 70 | * Creates an event of a given type and for the specified device, master, |
| 71 | * and time. |
| 72 | * |
| 73 | * @param type mastership event type |
| 74 | * @param device event device subject |
Thomas Vachuska | 4b42077 | 2014-10-30 16:46:17 -0700 | [diff] [blame] | 75 | * @param info role information |
Ayaka Koshibe | 8b3270f | 2014-09-22 13:44:42 -0700 | [diff] [blame] | 76 | * @param time occurrence time |
| 77 | */ |
Ayaka Koshibe | fc981cf | 2014-10-21 12:44:17 -0700 | [diff] [blame] | 78 | public MastershipEvent(Type type, DeviceId device, RoleInfo info, long time) { |
Ayaka Koshibe | 8b3270f | 2014-09-22 13:44:42 -0700 | [diff] [blame] | 79 | super(type, device, time); |
Ayaka Koshibe | fc981cf | 2014-10-21 12:44:17 -0700 | [diff] [blame] | 80 | this.roleInfo = info; |
Ayaka Koshibe | 8b3270f | 2014-09-22 13:44:42 -0700 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | /** |
Ayaka Koshibe | fc981cf | 2014-10-21 12:44:17 -0700 | [diff] [blame] | 84 | * Returns the current role state for the subject. |
| 85 | * |
| 86 | * @return RoleInfo associated with Device ID subject |
| 87 | */ |
| 88 | public RoleInfo roleInfo() { |
| 89 | return roleInfo; |
Ayaka Koshibe | 8b3270f | 2014-09-22 13:44:42 -0700 | [diff] [blame] | 90 | } |
Yuta HIGUCHI | fd5cdf1 | 2014-10-26 13:28:48 -0700 | [diff] [blame] | 91 | |
| 92 | @Override |
| 93 | public String toString() { |
| 94 | return MoreObjects.toStringHelper(getClass()) |
Yuta HIGUCHI | b87ef95 | 2014-10-28 23:34:23 -0700 | [diff] [blame] | 95 | .add("time", new LocalDateTime(time())) |
Yuta HIGUCHI | fd5cdf1 | 2014-10-26 13:28:48 -0700 | [diff] [blame] | 96 | .add("type", type()) |
| 97 | .add("subject", subject()) |
| 98 | .add("roleInfo", roleInfo) |
| 99 | .toString(); |
| 100 | } |
Ayaka Koshibe | 8b3270f | 2014-09-22 13:44:42 -0700 | [diff] [blame] | 101 | } |