Jian Li | 9e43ec1 | 2019-01-21 23:04:23 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2019-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 stats of Kubernetes node. |
| 20 | */ |
| 21 | public enum K8sNodeState { |
| 22 | |
| 23 | /** |
Jian Li | 77af8f3 | 2019-12-18 11:35:05 +0900 | [diff] [blame] | 24 | * Indicates the node is in pre-on-board. |
| 25 | */ |
| 26 | PRE_ON_BOARD { |
| 27 | @Override |
| 28 | public void process(K8sNodeHandler handler, K8sNode node) { |
| 29 | handler.processPreOnBoardState(node); |
| 30 | } |
| 31 | |
| 32 | @Override |
| 33 | public K8sNodeState nextState() { |
| 34 | return ON_BOARDED; |
| 35 | } |
| 36 | }, |
| 37 | /** |
| 38 | * Indicates the node is on-boarded. |
| 39 | */ |
| 40 | ON_BOARDED { |
| 41 | @Override |
| 42 | public void process(K8sNodeHandler handler, K8sNode node) { |
| 43 | handler.processOnBoardedState(node); |
| 44 | } |
| 45 | |
| 46 | @Override |
| 47 | public K8sNodeState nextState() { |
| 48 | return ON_BOARDED; |
| 49 | } |
| 50 | }, |
| 51 | /** |
Jian Li | 9e43ec1 | 2019-01-21 23:04:23 +0900 | [diff] [blame] | 52 | * Indicates the node is newly added. |
| 53 | */ |
| 54 | INIT { |
| 55 | @Override |
| 56 | public void process(K8sNodeHandler handler, K8sNode node) { |
| 57 | handler.processInitState(node); |
| 58 | } |
| 59 | |
| 60 | @Override |
| 61 | public K8sNodeState nextState() { |
| 62 | return DEVICE_CREATED; |
| 63 | } |
| 64 | }, |
| 65 | /** |
| 66 | * Indicates bridge devices are added according to the node state. |
| 67 | */ |
| 68 | DEVICE_CREATED { |
| 69 | @Override |
| 70 | public void process(K8sNodeHandler handler, K8sNode node) { |
| 71 | handler.processDeviceCreatedState(node); |
| 72 | } |
| 73 | |
| 74 | @Override |
| 75 | public K8sNodeState nextState() { |
| 76 | return COMPLETE; |
| 77 | } |
| 78 | }, |
| 79 | /** |
| 80 | * Indicates node initialization is done. |
| 81 | */ |
| 82 | COMPLETE { |
| 83 | @Override |
| 84 | public void process(K8sNodeHandler handler, K8sNode node) { |
| 85 | handler.processCompleteState(node); |
| 86 | } |
| 87 | |
| 88 | @Override |
| 89 | public K8sNodeState nextState() { |
| 90 | return COMPLETE; |
| 91 | } |
| 92 | }, |
| 93 | /** |
| 94 | * Indicates node is broken. |
| 95 | */ |
| 96 | INCOMPLETE { |
| 97 | @Override |
| 98 | public void process(K8sNodeHandler handler, K8sNode node) { |
| 99 | handler.processIncompleteState(node); |
| 100 | } |
| 101 | |
| 102 | @Override |
| 103 | public K8sNodeState nextState() { |
| 104 | return INIT; |
| 105 | } |
| 106 | }; |
| 107 | |
| 108 | /** |
| 109 | * Processes the given node which is under a certain state. |
| 110 | * |
| 111 | * @param handler kubernetes node handler |
| 112 | * @param node kubernetes node |
| 113 | */ |
| 114 | public abstract void process(K8sNodeHandler handler, K8sNode node); |
| 115 | |
| 116 | /** |
| 117 | * Transits to the next state. |
| 118 | * |
| 119 | * @return the next kubernetes node state |
| 120 | */ |
| 121 | public abstract K8sNodeState nextState(); |
| 122 | } |