github.com/timstclair/heapster@v0.20.0-alpha1/events/sinks/factory.go (about) 1 // Copyright 2015 Google Inc. All Rights Reserved. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package sinks 16 17 import ( 18 "fmt" 19 20 "k8s.io/heapster/common/flags" 21 "k8s.io/heapster/events/core" 22 "k8s.io/heapster/events/sinks/gcl" 23 "k8s.io/heapster/events/sinks/influxdb" 24 "k8s.io/heapster/events/sinks/log" 25 26 "github.com/golang/glog" 27 ) 28 29 type SinkFactory struct { 30 } 31 32 func (this *SinkFactory) Build(uri flags.Uri) (core.EventSink, error) { 33 switch uri.Key { 34 case "gcl": 35 return gcl.CreateGCLSink(&uri.Val) 36 case "log": 37 return logsink.CreateLogSink() 38 case "influxdb": 39 return influxdb.CreateInfluxdbSink(&uri.Val) 40 default: 41 return nil, fmt.Errorf("Sink not recognized: %s", uri.Key) 42 } 43 } 44 45 func (this *SinkFactory) BuildAll(uris flags.Uris) []core.EventSink { 46 result := make([]core.EventSink, 0, len(uris)) 47 for _, uri := range uris { 48 sink, err := this.Build(uri) 49 if err != nil { 50 glog.Errorf("Failed to create sink: %v", err) 51 continue 52 } 53 result = append(result, sink) 54 } 55 return result 56 } 57 58 func NewSinkFactory() *SinkFactory { 59 return &SinkFactory{} 60 }