Ocean/ICCC/InitDB.go
Thorsten Sommer 7120a729bd Bug fixing
+ DB access is now right and uses copied sessions
+ DB session is now specifying the safe state and the mode
+ Fixed the issue with too early ICCC messages regarding to late cache
+ Add the MIME type for Dart
+ Fixed the issuse with wrong order of shutdown handlers
- TODO: Testing of these changes
2014-06-04 21:41:18 +02:00

59 lines
2.1 KiB
Go

package ICCC
import "labix.org/v2/mgo"
import "github.com/SommerEngineering/Ocean/CustomerDB"
import "github.com/SommerEngineering/Ocean/Log"
import LM "github.com/SommerEngineering/Ocean/Log/Meta"
func initDB() {
Log.LogShort(senderName, LM.CategorySYSTEM, LM.LevelINFO, LM.MessageNameINIT, `Start init of the ICCC collections.`)
defer Log.LogShort(senderName, LM.CategorySYSTEM, LM.LevelINFO, LM.MessageNameINIT, `Done init the ICCC collection.`)
// Get the database:
dbSession, db = CustomerDB.DB()
if db == nil {
Log.LogFull(senderName, LM.CategorySYSTEM, LM.LevelERROR, LM.SeverityCritical, LM.ImpactCritical, LM.MessageNameDATABASE, `Was not able to get the customer database.`)
return
}
// Get my collections:
collectionListener = db.C(`ICCCListener`)
collectionHosts = db.C(`ICCCHosts`)
// Take care about the indexes for ICCCListener:
collectionListener.EnsureIndexKey(`Command`)
collectionListener.EnsureIndexKey(`Command`, `IsActive`)
collectionListener.EnsureIndexKey(`Command`, `Channel`)
collectionListener.EnsureIndexKey(`Command`, `Channel`, `IsActive`)
collectionListener.EnsureIndexKey(`Channel`)
collectionListener.EnsureIndexKey(`Channel`, `IsActive`)
collectionListener.EnsureIndexKey(`Channel`, `Command`, `IPAddressPort`, `IsActive`)
collectionListener.EnsureIndexKey(`Channel`, `Command`, `IsActive`)
collectionListener.EnsureIndexKey(`IsActive`)
collectionListener.EnsureIndexKey(`IsActive`, `IPAddressPort`)
collectionListener.EnsureIndexKey(`IPAddressPort`)
indexName1 := mgo.Index{}
indexName1.Key = []string{`Channel`, `Command`, `IPAddressPort`}
indexName1.Unique = true
collectionListener.EnsureIndex(indexName1)
// Index for hosts:
collectionHosts.EnsureIndexKey(`Hostname`, `IPAddressPort`)
indexName2 := mgo.Index{}
indexName2.Key = []string{`Hostname`}
indexName2.Unique = true
collectionHosts.EnsureIndex(indexName2)
indexName3 := mgo.Index{}
indexName3.Key = []string{`IPAddressPort`}
indexName3.Unique = true
collectionHosts.EnsureIndex(indexName3)
}