2014-04-26 09:18:56 +00:00
package ICCC
2014-10-19 17:19:11 +00:00
import (
"github.com/SommerEngineering/Ocean/CustomerDB"
"github.com/SommerEngineering/Ocean/Log"
LM "github.com/SommerEngineering/Ocean/Log/Meta"
"gopkg.in/mgo.v2"
)
2014-04-26 09:18:56 +00:00
2015-06-17 15:44:52 +00:00
// Init the database.
2014-04-26 09:18:56 +00:00
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:
2014-06-04 19:41:18 +00:00
dbSession , db = CustomerDB . DB ( )
2014-04-26 09:18:56 +00:00
2015-06-17 15:44:52 +00:00
// Case: Error?
2014-04-26 09:18:56 +00:00
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 ` )
2015-06-17 15:44:52 +00:00
//
2014-04-26 09:18:56 +00:00
// Take care about the indexes for ICCCListener:
2015-06-17 15:44:52 +00:00
//
2015-07-13 08:44:03 +00:00
collectionListener . EnsureIndexKey ( ` Kind ` )
2014-04-26 09:18:56 +00:00
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 )
2015-06-17 15:44:52 +00:00
//
2014-04-26 09:18:56 +00:00
// Index for hosts:
2015-06-17 15:44:52 +00:00
//
2015-07-13 08:44:03 +00:00
collectionHosts . EnsureIndexKey ( ` Kind ` )
2015-07-10 12:36:47 +00:00
collectionHosts . EnsureIndexKey ( ` Hostname ` )
collectionHosts . EnsureIndexKey ( ` IPAddressPort ` )
2014-04-26 09:18:56 +00:00
indexName2 := mgo . Index { }
2015-07-10 12:36:47 +00:00
indexName2 . Key = [ ] string { ` Hostname ` , ` IPAddressPort ` }
2014-04-26 09:18:56 +00:00
indexName2 . Unique = true
collectionHosts . EnsureIndex ( indexName2 )
}