func updateStorageNodeToDB(storage_node models.Node, ctxt string) error { // Add the node details to the DB sessionCopy := db.GetDatastore().Copy() defer sessionCopy.Close() coll := sessionCopy.DB(conf.SystemConfig.DBConfig.Database).C(models.COLL_NAME_STORAGE_NODES) var node models.Node err := coll.Find(bson.M{"nodeid": storage_node.NodeId}).One(&node) if err == mgo.ErrNotFound { storage_node.State = models.NODE_STATE_ACTIVE if err := coll.Update(bson.M{"hostname": storage_node.Hostname}, storage_node); err != nil { logger.Get().Critical("%s-Error Updating the node: %s. error: %v", ctxt, storage_node.Hostname, err) return err } return nil } else { logger.Get().Critical(fmt.Sprintf("%s-Node with id: %v already exists", ctxt, storage_node.NodeId)) return errors.New(fmt.Sprintf("Node with id: %v already exists", storage_node.NodeId)) } }
func handle_UnManagedNode(hostname string, ctxt string) error { sessionCopy := db.GetDatastore().Copy() defer sessionCopy.Close() coll := sessionCopy.DB(conf.SystemConfig.DBConfig.Database).C(models.COLL_NAME_STORAGE_NODES) var node models.Node err := coll.Find(bson.M{"hostname": hostname}).One(&node) if err == mgo.ErrNotFound { node.Hostname = hostname node.State = models.NODE_STATE_UNACCEPTED if node.Fingerprint, err = skyring.GetCoreNodeManager().GetFingerPrint(node.Hostname, ctxt); err != nil { logger.Get().Error(fmt.Sprintf("%s-Faild to retrive fingerprint from : %s", ctxt, node.Hostname)) return err } if err := coll.Insert(node); err != nil { logger.Get().Error(fmt.Sprintf("%s-Error adding Unmanaged node : %s. error: %v", ctxt, node.Hostname, err)) return err } return nil } return errors.New(fmt.Sprintf("Node with hostname: %v already exists", hostname)) }