2017-04-10 16:54:12 +00:00
|
|
|
package all
|
|
|
|
|
|
|
|
import (
|
2017-12-31 04:26:17 +00:00
|
|
|
"log"
|
2017-04-10 16:54:12 +00:00
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/FreifunkBremen/yanic/database"
|
|
|
|
"github.com/FreifunkBremen/yanic/runtime"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Connection struct {
|
|
|
|
database.Connection
|
|
|
|
list []database.Connection
|
|
|
|
}
|
|
|
|
|
2017-12-31 04:26:17 +00:00
|
|
|
func Connect(allConnection map[string]interface{}) (database.Connection, error) {
|
2017-04-10 16:54:12 +00:00
|
|
|
var list []database.Connection
|
|
|
|
for dbType, conn := range database.Adapters {
|
2017-12-31 04:26:17 +00:00
|
|
|
configForType := allConnection[dbType]
|
|
|
|
if configForType == nil {
|
|
|
|
log.Printf("the output type '%s' has no configuration\n", dbType)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
dbConfigs, ok := configForType.([]map[string]interface{})
|
|
|
|
if !ok {
|
|
|
|
log.Panicf("the output type '%s' has the wrong format\n", dbType)
|
|
|
|
}
|
|
|
|
|
2017-04-10 16:54:12 +00:00
|
|
|
for _, config := range dbConfigs {
|
2017-12-31 04:26:17 +00:00
|
|
|
if c, ok := config["enable"].(bool); ok && !c {
|
|
|
|
continue
|
|
|
|
}
|
2017-04-10 16:54:12 +00:00
|
|
|
connected, err := conn(config)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if connected == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
list = append(list, connected)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return &Connection{list: list}, nil
|
|
|
|
}
|
2017-04-17 23:48:38 +00:00
|
|
|
|
|
|
|
func (conn *Connection) InsertNode(node *runtime.Node) {
|
2017-04-10 16:54:12 +00:00
|
|
|
for _, item := range conn.list {
|
2017-04-17 23:48:38 +00:00
|
|
|
item.InsertNode(node)
|
2017-04-10 16:54:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-27 11:55:02 +00:00
|
|
|
func (conn *Connection) InsertLink(link *runtime.Link, time time.Time) {
|
|
|
|
for _, item := range conn.list {
|
|
|
|
item.InsertLink(link, time)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-21 14:12:06 +00:00
|
|
|
func (conn *Connection) InsertGlobals(stats *runtime.GlobalStats, time time.Time, site string) {
|
2017-04-10 16:54:12 +00:00
|
|
|
for _, item := range conn.list {
|
2017-11-21 14:12:06 +00:00
|
|
|
item.InsertGlobals(stats, time, site)
|
2017-04-10 16:54:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-17 18:42:06 +00:00
|
|
|
func (conn *Connection) PruneNodes(deleteAfter time.Duration) {
|
2017-04-10 16:54:12 +00:00
|
|
|
for _, item := range conn.list {
|
2017-04-17 18:42:06 +00:00
|
|
|
item.PruneNodes(deleteAfter)
|
2017-04-10 16:54:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (conn *Connection) Close() {
|
|
|
|
for _, item := range conn.list {
|
|
|
|
item.Close()
|
|
|
|
}
|
|
|
|
}
|