Jian Li | 58b3398 | 2020-07-01 19:07:02 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2020-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.k8snode.api; |
| 17 | |
| 18 | /** |
| 19 | * Defines the initialization state of Kubernetes host. |
| 20 | */ |
| 21 | public enum K8sHostState { |
| 22 | |
| 23 | /** |
| 24 | * Indicates the host is newly added. |
| 25 | */ |
| 26 | INIT { |
| 27 | @Override |
| 28 | public void process(K8sHostHandler handler, K8sHost host) { |
| 29 | handler.processInitState(host); |
| 30 | } |
| 31 | |
| 32 | @Override |
| 33 | public K8sHostState nextState() { |
Jian Li | 8685dd3 | 2020-09-01 16:55:25 +0900 | [diff] [blame] | 34 | return DEVICE_CREATED; |
| 35 | } |
| 36 | }, |
| 37 | /** |
| 38 | * Indicates bridge devices are added according to the host state. |
| 39 | */ |
| 40 | DEVICE_CREATED { |
| 41 | @Override |
| 42 | public void process(K8sHostHandler handler, K8sHost host) { |
| 43 | handler.processDeviceCreatedState(host); |
| 44 | } |
| 45 | |
| 46 | @Override |
| 47 | public K8sHostState nextState() { |
Jian Li | 58b3398 | 2020-07-01 19:07:02 +0900 | [diff] [blame] | 48 | return COMPLETE; |
| 49 | } |
| 50 | }, |
| 51 | /** |
| 52 | * Indicates the host initialization is done. |
| 53 | */ |
| 54 | COMPLETE { |
| 55 | @Override |
| 56 | public void process(K8sHostHandler handler, K8sHost host) { |
| 57 | handler.processCompleteState(host); |
| 58 | } |
| 59 | |
| 60 | @Override |
| 61 | public K8sHostState nextState() { |
| 62 | return COMPLETE; |
| 63 | } |
| 64 | }, |
| 65 | /** |
| 66 | * Indicates host is broken. |
| 67 | */ |
| 68 | INCOMPLETE { |
| 69 | @Override |
| 70 | public void process(K8sHostHandler handler, K8sHost host) { |
| 71 | handler.processIncompleteState(host); |
| 72 | } |
| 73 | |
| 74 | @Override |
| 75 | public K8sHostState nextState() { |
| 76 | return INIT; |
| 77 | } |
| 78 | }; |
| 79 | |
| 80 | /** |
| 81 | * Processes the given host which is under a certain state. |
| 82 | * |
| 83 | * @param handler kubernetes host handler |
| 84 | * @param host kubernetes host |
| 85 | */ |
| 86 | public abstract void process(K8sHostHandler handler, K8sHost host); |
| 87 | |
| 88 | /** |
| 89 | * Transits to the next state. |
| 90 | * |
| 91 | * @return the next kubernetes host state |
| 92 | */ |
| 93 | public abstract K8sHostState nextState(); |
| 94 | } |