github.com/jonaz/heapster@v1.3.0-beta.0.0.20170208112634-cd3c15ca3d29/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/elasticsearch" 23 "k8s.io/heapster/events/sinks/gcl" 24 "k8s.io/heapster/events/sinks/influxdb" 25 "k8s.io/heapster/events/sinks/kafka" 26 "k8s.io/heapster/events/sinks/log" 27 28 "github.com/golang/glog" 29 ) 30 31 type SinkFactory struct { 32 } 33 34 func (this *SinkFactory) Build(uri flags.Uri) (core.EventSink, error) { 35 switch uri.Key { 36 case "gcl": 37 return gcl.CreateGCLSink(&uri.Val) 38 case "log": 39 return logsink.CreateLogSink() 40 case "influxdb": 41 return influxdb.CreateInfluxdbSink(&uri.Val) 42 case "elasticsearch": 43 return elasticsearch.NewElasticSearchSink(&uri.Val) 44 case "kafka": 45 return kafka.NewKafkaSink(&uri.Val) 46 default: 47 return nil, fmt.Errorf("Sink not recognized: %s", uri.Key) 48 } 49 } 50 51 func (this *SinkFactory) BuildAll(uris flags.Uris) []core.EventSink { 52 result := make([]core.EventSink, 0, len(uris)) 53 for _, uri := range uris { 54 sink, err := this.Build(uri) 55 if err != nil { 56 glog.Errorf("Failed to create sink: %v", err) 57 continue 58 } 59 result = append(result, sink) 60 } 61 return result 62 } 63 64 func NewSinkFactory() *SinkFactory { 65 return &SinkFactory{} 66 }