volcano.sh/volcano@v1.9.0/pkg/controllers/job/plugins/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 plugins 18 19 import ( 20 "sync" 21 22 "volcano.sh/volcano/pkg/controllers/job/plugins/distributed-framework/mpi" 23 "volcano.sh/volcano/pkg/controllers/job/plugins/distributed-framework/pytorch" 24 "volcano.sh/volcano/pkg/controllers/job/plugins/distributed-framework/tensorflow" 25 "volcano.sh/volcano/pkg/controllers/job/plugins/env" 26 pluginsinterface "volcano.sh/volcano/pkg/controllers/job/plugins/interface" 27 "volcano.sh/volcano/pkg/controllers/job/plugins/ssh" 28 "volcano.sh/volcano/pkg/controllers/job/plugins/svc" 29 ) 30 31 func init() { 32 RegisterPluginBuilder("ssh", ssh.New) 33 RegisterPluginBuilder("env", env.New) 34 RegisterPluginBuilder("svc", svc.New) 35 RegisterPluginBuilder("tensorflow", tensorflow.New) 36 RegisterPluginBuilder("mpi", mpi.New) 37 RegisterPluginBuilder("pytorch", pytorch.New) 38 } 39 40 var pluginMutex sync.Mutex 41 42 // Plugin management. 43 var pluginBuilders = map[string]PluginBuilder{} 44 45 // PluginBuilder func prototype. 46 type PluginBuilder func(pluginsinterface.PluginClientset, []string) pluginsinterface.PluginInterface 47 48 // RegisterPluginBuilder register plugin builders. 49 func RegisterPluginBuilder(name string, pc PluginBuilder) { 50 pluginMutex.Lock() 51 defer pluginMutex.Unlock() 52 53 pluginBuilders[name] = pc 54 } 55 56 // GetPluginBuilder returns plugin builder for a given plugin name. 57 func GetPluginBuilder(name string) (PluginBuilder, bool) { 58 pluginMutex.Lock() 59 defer pluginMutex.Unlock() 60 61 pb, found := pluginBuilders[name] 62 return pb, found 63 }