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 com.google.common.annotations.Beta; |
| 19 | import org.onosproject.core.Version; |
| 20 | |
| 21 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 22 | |
| 23 | /** |
| 24 | * Represents the state of an upgrade. |
| 25 | * <p> |
| 26 | * An upgrade consists of a {@link #source() source} and {@link #target() target} version and an upgrade |
| 27 | * {@link #status()}. |
| 28 | */ |
| 29 | @Beta |
| 30 | public class Upgrade { |
| 31 | |
| 32 | /** |
| 33 | * Represents the phase of the upgrade protocol. |
| 34 | */ |
| 35 | @Beta |
| 36 | public enum Status { |
| 37 | |
| 38 | /** |
| 39 | * Represents state in which no upgrade has been initialized. |
| 40 | */ |
| 41 | INACTIVE(false, false), |
| 42 | |
| 43 | /** |
| 44 | * Indicates that an upgrade is being initialized. |
| 45 | */ |
| 46 | INITIALIZING(true, false), |
| 47 | |
| 48 | /** |
| 49 | * Indicates that an upgrade has been initialized. |
| 50 | */ |
| 51 | INITIALIZED(true, false), |
| 52 | |
| 53 | /** |
| 54 | * Indicates that an upgrade is in progress. |
| 55 | */ |
| 56 | UPGRADING(true, true), |
| 57 | |
| 58 | /** |
| 59 | * Indicates that an upgrade is complete. |
| 60 | */ |
| 61 | UPGRADED(true, true), |
| 62 | |
| 63 | /**d |
| 64 | * Indicates that an upgrade is being committed. |
| 65 | */ |
| 66 | COMMITTING(true, true), |
| 67 | |
| 68 | /** |
| 69 | * Indicates that an upgrade has been committed. |
| 70 | */ |
| 71 | COMMITTED(false, true), |
| 72 | |
| 73 | /** |
| 74 | * Indicates that an upgrade is being rolled back. |
| 75 | */ |
| 76 | ROLLING_BACK(true, false), |
| 77 | |
| 78 | /** |
| 79 | * Indicates that an upgrade has been rolled back. |
| 80 | */ |
| 81 | ROLLED_BACK(true, false), |
| 82 | |
| 83 | /** |
| 84 | * Indicates that an upgrade is being reset. |
| 85 | */ |
| 86 | RESETTING(true, false), |
| 87 | |
| 88 | /** |
| 89 | * Indicates that an upgrade has been reset. |
| 90 | */ |
| 91 | RESET(false, false); |
| 92 | |
| 93 | private final boolean active; |
| 94 | private final boolean upgraded; |
| 95 | |
| 96 | Status(boolean active, boolean upgraded) { |
| 97 | this.active = active; |
| 98 | this.upgraded = upgraded; |
| 99 | } |
| 100 | |
| 101 | /** |
| 102 | * Returns whether the upgrade status is active. |
| 103 | * |
| 104 | * @return whether the upgrade status is active |
| 105 | */ |
| 106 | public boolean active() { |
| 107 | return active; |
| 108 | } |
| 109 | |
| 110 | /** |
| 111 | * Returns whether the upgraded version is active. |
| 112 | * |
| 113 | * @return whether the upgraded version is active |
| 114 | */ |
| 115 | public boolean upgraded() { |
| 116 | return upgraded; |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | private final Version source; |
| 121 | private final Version target; |
| 122 | private final Status status; |
| 123 | |
| 124 | public Upgrade(Version source, Version target, Status status) { |
| 125 | this.source = source; |
| 126 | this.target = target; |
| 127 | this.status = status; |
| 128 | } |
| 129 | |
| 130 | /** |
| 131 | * Returns the source version. |
| 132 | * |
| 133 | * @return the source version |
| 134 | */ |
| 135 | public Version source() { |
| 136 | return source; |
| 137 | } |
| 138 | |
| 139 | /** |
| 140 | * Returns the target version. |
| 141 | * |
| 142 | * @return the target version |
| 143 | */ |
| 144 | public Version target() { |
| 145 | return target; |
| 146 | } |
| 147 | |
| 148 | /** |
| 149 | * Returns the upgrade status. |
| 150 | * |
| 151 | * @return the upgrade status |
| 152 | */ |
| 153 | public Status status() { |
| 154 | return status; |
| 155 | } |
| 156 | |
| 157 | @Override |
| 158 | public String toString() { |
| 159 | return toStringHelper(this) |
| 160 | .add("source", source) |
| 161 | .add("target", target) |
| 162 | .add("status", status) |
| 163 | .toString(); |
| 164 | } |
| 165 | } |