volcano.sh/volcano@v1.9.0/pkg/controllers/queue/state/factory.go (about) 1 /* 2 Copyright 2019 The Volcano Authors. 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 17 package state 18 19 import ( 20 "volcano.sh/apis/pkg/apis/bus/v1alpha1" 21 "volcano.sh/apis/pkg/apis/scheduling/v1beta1" 22 ) 23 24 // State interface. 25 type State interface { 26 // Execute executes the actions based on current state. 27 Execute(action v1alpha1.Action) error 28 } 29 30 // UpdateQueueStatusFn updates the queue status. 31 type UpdateQueueStatusFn func(status *v1beta1.QueueStatus, podGroupList []string) 32 33 // QueueActionFn will open, close or sync queue. 34 type QueueActionFn func(queue *v1beta1.Queue, fn UpdateQueueStatusFn) error 35 36 var ( 37 // SyncQueue will sync queue status. 38 SyncQueue QueueActionFn 39 // OpenQueue will set state of queue to open 40 OpenQueue QueueActionFn 41 // CloseQueue will set state of queue to close 42 CloseQueue QueueActionFn 43 ) 44 45 // NewState gets the state from queue status. 46 func NewState(queue *v1beta1.Queue) State { 47 switch queue.Status.State { 48 case "", v1beta1.QueueStateOpen: 49 return &openState{queue: queue} 50 case v1beta1.QueueStateClosed: 51 return &closedState{queue: queue} 52 case v1beta1.QueueStateClosing: 53 return &closingState{queue: queue} 54 case v1beta1.QueueStateUnknown: 55 return &unknownState{queue: queue} 56 } 57 58 return nil 59 }