github.com/cs3org/reva/v2@v2.27.7/pkg/mentix/exchangers/exporters/exporters.go (about) 1 // Copyright 2018-2021 CERN 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 // In applying this license, CERN does not waive the privileges and immunities 16 // granted to it by virtue of its status as an Intergovernmental Organization 17 // or submit itself to any jurisdiction. 18 19 package exporters 20 21 import ( 22 "github.com/rs/zerolog" 23 24 "github.com/cs3org/reva/v2/pkg/mentix/config" 25 "github.com/cs3org/reva/v2/pkg/mentix/entity" 26 "github.com/cs3org/reva/v2/pkg/mentix/exchangers" 27 ) 28 29 // Collection represents a collection of exporters. 30 type Collection struct { 31 Exporters []Exporter 32 } 33 34 var ( 35 registeredExporters = entity.NewRegistry() 36 ) 37 38 // Entities returns a vector of entities within the collection. 39 func (collection *Collection) Entities() []entity.Entity { 40 return exchangers.AsEntityCollection(collection).Entities() 41 } 42 43 // Exchangers returns a vector of exchangers within the collection. 44 func (collection *Collection) Exchangers() []exchangers.Exchanger { 45 exchngrs := make([]exchangers.Exchanger, 0, len(collection.Exporters)) 46 for _, connector := range collection.Exporters { 47 exchngrs = append(exchngrs, connector) 48 } 49 return exchngrs 50 } 51 52 // ActivateAll activates all exporters. 53 func (collection *Collection) ActivateAll(conf *config.Configuration, log *zerolog.Logger) error { 54 return entity.ActivateEntities(collection, conf, log) 55 } 56 57 // StartAll starts all exporters. 58 func (collection *Collection) StartAll() error { 59 return exchangers.StartExchangers(collection) 60 } 61 62 // StopAll stops all exporters. 63 func (collection *Collection) StopAll() { 64 exchangers.StopExchangers(collection) 65 } 66 67 // GetRequestExporters returns all exporters that implement the RequestExchanger interface. 68 func (collection *Collection) GetRequestExporters() []exchangers.RequestExchanger { 69 return exchangers.GetRequestExchangers(collection) 70 } 71 72 // AvailableExporters returns a list of all exporters that are enabled in the configuration. 73 func AvailableExporters(conf *config.Configuration) (*Collection, error) { 74 // Try to add all exporters configured in the environment 75 entries, err := registeredExporters.FindEntities(conf.EnabledExporters, true, false) 76 if err != nil { 77 return nil, err 78 } 79 80 exporters := make([]Exporter, 0, len(entries)) 81 for _, entry := range entries { 82 exporters = append(exporters, entry.(Exporter)) 83 } 84 85 return &Collection{Exporters: exporters}, nil 86 } 87 88 func registerExporter(exporter Exporter) { 89 registeredExporters.Register(exporter) 90 }