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