func (a *App) GET_Storages(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) cluster_id_str := vars["cluster-id"] cluster_id, err := uuid.Parse(cluster_id_str) if err != nil { logger.Get().Error("Error parsing the cluster id: %s. error: %v", cluster_id_str, err) util.HttpResponse(w, http.StatusBadRequest, fmt.Sprintf("Error parsing the cluster id: %s", cluster_id_str)) return } sessionCopy := db.GetDatastore().Copy() defer sessionCopy.Close() collection := sessionCopy.DB(conf.SystemConfig.DBConfig.Database).C(models.COLL_NAME_STORAGE) var storages models.Storages if err := collection.Find(bson.M{"clusterid": *cluster_id}).All(&storages); err != nil { util.HttpResponse(w, http.StatusInternalServerError, err.Error()) logger.Get().Error("Error getting the storage list for cluster: %v. error: %v", *cluster_id, err) return } if len(storages) == 0 { json.NewEncoder(w).Encode(models.Storages{}) } else { json.NewEncoder(w).Encode(storages) } }
func (a *App) SyncClusterDetails() { // Get the list of cluster sessionCopy := db.GetDatastore().Copy() defer sessionCopy.Close() coll := sessionCopy.DB(conf.SystemConfig.DBConfig.Database).C(models.COLL_NAME_STORAGE_CLUSTERS) var clusters models.Clusters if err := coll.Find(nil).All(&clusters); err != nil { logger.Get().Error("Error getting the clusters list. Unable to sync details. error: %v", err) return } for _, cluster := range clusters { provider := a.getProviderFromClusterId(cluster.ClusterId) if provider == nil { logger.Get().Error("Error getting provider for the cluster: %s", cluster.Name) continue } // Sync the cluster status if ok, err := sync_cluster_status(cluster, provider); err != nil || !ok { logger.Get().Error("Error updating status for cluster: %s", cluster.Name) } // TODO:: Sync the nodes status if ok, err := sync_cluster_nodes(cluster, provider); err != nil && !ok { logger.Get().Error("Error syncing node details for cluster: %s. error: %v", cluster.Name, err) } // TODO:: Sync the storage entities of the cluster if ok, err := sync_cluster_storage_entities(cluster, provider); err != nil && !ok { logger.Get().Error("Error syncing storage entities for cluster: %s. error: %v", cluster.Name, err) } } }
func AddStorageNodeToDB(hostname string, node_state int, node_status string) error { // Add the node details to the DB var storage_node models.Node storage_node.Hostname = hostname storage_node.State = node_state storage_node.Status = node_status 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": storage_node.Hostname}).One(&node) if err != mgo.ErrNotFound { logger.Get().Critical(fmt.Sprintf("Node with name: %v already exists", storage_node.Hostname)) return errors.New(fmt.Sprintf("Node with name: %v already exists", storage_node.Hostname)) } // Persist the node details if err := coll.Insert(storage_node); err != nil { logger.Get().Critical("Error adding the node: %s. error: %v", storage_node.Hostname, err) return err } return nil }
func (a *App) GET_Storage(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) cluster_id_str := vars["cluster-id"] cluster_id, err := uuid.Parse(cluster_id_str) if err != nil { logger.Get().Error("Error parsing the cluster id: %s. error: %v", cluster_id_str, err) util.HttpResponse(w, http.StatusBadRequest, fmt.Sprintf("Error parsing the cluster id: %s", cluster_id_str)) return } storage_id_str := vars["storage-id"] storage_id, err := uuid.Parse(storage_id_str) if err != nil { logger.Get().Error("Error parsing the storage id: %s. error: %v", storage_id_str, err) util.HttpResponse(w, http.StatusBadRequest, fmt.Sprintf("Error parsing the storage id: %s", storage_id_str)) return } sessionCopy := db.GetDatastore().Copy() defer sessionCopy.Close() collection := sessionCopy.DB(conf.SystemConfig.DBConfig.Database).C(models.COLL_NAME_STORAGE) var storage models.Storage if err := collection.Find(bson.M{"clusterid": *cluster_id, "storageid": *storage_id}).One(&storage); err != nil { util.HttpResponse(w, http.StatusInternalServerError, err.Error()) logger.Get().Error("Error getting the storage: %v on cluster: %v. error: %v", *storage_id, *cluster_id, err) return } if storage.Name == "" { util.HttpResponse(w, http.StatusBadRequest, "Storage not found") logger.Get().Error("Storage with id: %v not found for cluster: %v. error: %v", *storage_id, *cluster_id, err) return } else { json.NewEncoder(w).Encode(storage) } }
func (a *App) GET_Nodes(w http.ResponseWriter, r *http.Request) { sessionCopy := db.GetDatastore().Copy() defer sessionCopy.Close() params := r.URL.Query() admin_state_str := params.Get("state") collection := sessionCopy.DB(conf.SystemConfig.DBConfig.Database).C(models.COLL_NAME_STORAGE_NODES) var nodes models.Nodes if admin_state_str == "" { if err := collection.Find(nil).All(&nodes); err != nil { util.HttpResponse(w, http.StatusInternalServerError, err.Error()) logger.Get().Error("Error getting the nodes list. error: %v", err) return } } else { nodes, err = getNodesWithState(w, admin_state_str) if err != nil { util.HttpResponse(w, http.StatusInternalServerError, err.Error()) logger.Get().Error("Error getting the nodes list. error: %v", err) return } } if len(nodes) == 0 { json.NewEncoder(w).Encode([]models.Node{}) } else { json.NewEncoder(w).Encode(nodes) } }
func handle_node_start_event(node string) error { sessionCopy := db.GetDatastore().Copy() defer sessionCopy.Close() coll := sessionCopy.DB(conf.SystemConfig.DBConfig.Database).C(models.COLL_NAME_STORAGE_NODES) var storage_node models.Node _ = coll.Find(bson.M{"hostname": node}).One(&storage_node) if storage_node.State != models.NODE_STATE_INITIALIZING { logger.Get().Warning(fmt.Sprintf("Node with name: %s not in activating state to update other details", node)) return nil } asyncTask := func(t *task.Task) { t.UpdateStatus("started the task for InitializeNode: %s", t.ID) // Process the request if err := initializeStorageNode(node, t); err != nil { t.UpdateStatus("Failed") t.Done(models.TASK_STATUS_FAILURE) } else { t.UpdateStatus("Success") t.Done(models.TASK_STATUS_SUCCESS) } } if taskId, err := skyring.GetApp().GetTaskManager().Run(fmt.Sprintf("Initialize Node: %s", node), asyncTask, nil, nil, nil); err != nil { logger.Get().Error("Unable to create the task for Initialize Node: %s. error: %v", node, err) } else { logger.Get().Debug("Task created for initialize node. Task id: %s", taskId.String()) } return nil }
func (a *App) GET_Node(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) node_id_str := vars["node-id"] node_id, err := uuid.Parse(node_id_str) if err != nil { logger.Get().Error("Error parsing node id: %s", node_id_str) util.HttpResponse(w, http.StatusBadRequest, fmt.Sprintf("Error parsing node id: %s", node_id_str)) return } sessionCopy := db.GetDatastore().Copy() defer sessionCopy.Close() collection := sessionCopy.DB(conf.SystemConfig.DBConfig.Database).C(models.COLL_NAME_STORAGE_NODES) var node models.Node if err := collection.Find(bson.M{"nodeid": *node_id}).One(&node); err != nil { logger.Get().Error("Error getting the node detail for %v. error: %v", *node_id, err) } if node.Hostname == "" { util.HttpResponse(w, http.StatusBadRequest, "Node not found") logger.Get().Error("Node: %v not found. error: %v", *node_id, err) return } else { json.NewEncoder(w).Encode(node) } }
func removeNode(w http.ResponseWriter, nodeId uuid.UUID) (bool, error) { sessionCopy := db.GetDatastore().Copy() defer sessionCopy.Close() // Check if the node is free. If so remove the node collection := sessionCopy.DB(conf.SystemConfig.DBConfig.Database).C(models.COLL_NAME_STORAGE_NODES) var node models.Node if err := collection.Find(bson.M{"nodeid": nodeId}).One(&node); err != nil { return false, errors.New("Unable to get node") } if !node.ClusterId.IsZero() { return false, errors.New("Node(s) participating in a cluster. Cannot be removed") } appLock, err := lockNode(node.NodeId, node.Hostname, "addAndAcceptNode") if err != nil { return false, err } defer GetApp().GetLockManager().ReleaseLock(*appLock) ret_val, err := GetCoreNodeManager().RemoveNode(node.Hostname) if ret_val { if err := collection.Remove(bson.M{"nodeid": nodeId}); err != nil { return false, errors.New("Error deleting the node(s) from DB") } } else { return false, err } return true, nil }
func sync_cluster_status(cluster models.Cluster, provider *Provider) (bool, error) { var result models.RpcResponse vars := make(map[string]string) vars["cluster-id"] = cluster.ClusterId.String() err = provider.Client.Call(provider.Name+".GetClusterStatus", models.RpcRequest{RpcRequestVars: vars, RpcRequestData: []byte{}}, &result) if err != nil || result.Status.StatusCode != http.StatusOK { logger.Get().Error("Error getting status for cluster: %s. error:%v", cluster.Name, err) return false, err } else { statusMsg := result.Status.StatusMessage sessionCopy := db.GetDatastore().Copy() defer sessionCopy.Close() coll := sessionCopy.DB(conf.SystemConfig.DBConfig.Database).C(models.COLL_NAME_STORAGE_CLUSTERS) var clusterStatus int switch statusMsg { case models.STATUS_OK: clusterStatus = models.CLUSTER_STATUS_OK case models.STATUS_WARN: clusterStatus = models.CLUSTER_STATUS_WARN case models.STATUS_ERR: clusterStatus = models.CLUSTER_STATUS_ERROR } // Set the cluster status logger.Get().Info("Updating the status of the cluster: %s to %d", cluster.Name, clusterStatus) if err := coll.Update(bson.M{"clusterid": cluster.ClusterId}, bson.M{"$set": bson.M{"status": clusterStatus}}); err != nil { return false, err } } return true, nil }
func (a *App) getTask(rw http.ResponseWriter, req *http.Request) { vars := mux.Vars(req) taskId, err := uuid.Parse(vars["taskid"]) if err != nil { logger.Get().Error("Unable to Parse the Id: %s. error: %v", vars["taskId"], err) util.HandleHttpError(rw, err) return } sessionCopy := db.GetDatastore().Copy() defer sessionCopy.Close() coll := sessionCopy.DB(conf.SystemConfig.DBConfig.Database).C(models.COLL_NAME_TASKS) var task models.AppTask if err := coll.Find(bson.M{"id": *taskId}).One(&task); err != nil { logger.Get().Error("Unable to get task. error: %v", err) if err == mgo.ErrNotFound { util.HttpResponse(rw, http.StatusNotFound, err.Error()) return } else { util.HttpResponse(rw, http.StatusInternalServerError, err.Error()) return } } json.NewEncoder(rw).Encode(task) }
func (a SaltNodeManager) SyncStorageDisks(node string, sProfiles []models.StorageProfile) (bool, error) { disks, err := salt_backend.GetNodeDisk(node) if err != nil { return false, err } for _, disk := range disks { dId, err := uuid.New() if err != nil { logger.Get().Error(fmt.Sprintf("Unable to generate uuid for disk : %s. error: %v", disk.DevName, err)) return false, err } disk.DiskId = *dId applyStorageProfile(&disk, sProfiles) } sessionCopy := db.GetDatastore().Copy() defer sessionCopy.Close() coll := sessionCopy.DB(conf.SystemConfig.DBConfig.Database).C(models.COLL_NAME_STORAGE_NODES) if len(disks) != 0 { if err := coll.Update(bson.M{"hostname": node}, bson.M{"$set": bson.M{"storagedisks": disks}}); err != nil { logger.Get().Error("Error updating the disk details for node: %s. error: %v", node, err) return false, err } } return true, nil }
func (a *App) PATCH_Disk(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) node_id_str := vars["node-id"] node_id, err := uuid.Parse(node_id_str) if err != nil { util.HttpResponse(w, http.StatusBadRequest, fmt.Sprintf("Error parsing node id: %s. Error: %v", node_id_str, err)) return } disk_id_str := vars["disk-id"] disk_id, err := uuid.Parse(disk_id_str) if err != nil { util.HttpResponse(w, http.StatusBadRequest, fmt.Sprintf("Error parsing node id: %s. Error: %v", disk_id_str, err)) return } sessionCopy := db.GetDatastore().Copy() defer sessionCopy.Close() collection := sessionCopy.DB(conf.SystemConfig.DBConfig.Database).C(models.COLL_NAME_STORAGE_NODES) var node models.Node if err := collection.Find(bson.M{"nodeid": *node_id}).One(&node); err != nil { logger.Get().Error(fmt.Sprintf("Error getting the node detail for node: %s. error: %v", node_id_str, err)) util.HttpResponse(w, http.StatusInternalServerError, err.Error()) return } body, err := ioutil.ReadAll(r.Body) if err != nil { logger.Get().Error("Error parsing http request body:%s", err) util.HttpResponse(w, http.StatusInternalServerError, err.Error()) return } var m map[string]interface{} if err = json.Unmarshal(body, &m); err != nil { logger.Get().Error("Unable to Unmarshall the data:%s", err) util.HttpResponse(w, http.StatusInternalServerError, err.Error()) return } var disks []backend.Disk if val, ok := m["storageprofile"]; ok { //update the field for _, disk := range node.StorageDisks { if disk.DiskId == *disk_id { disk.StorageProfile = val.(string) } disks = append(disks, disk) } node.StorageDisks = disks } //Save err = collection.Update(bson.M{"nodeid": *node_id}, bson.M{"$set": node}) if err != nil { logger.Get().Error(fmt.Sprintf("Error updating record in DB for node: %s. error: %v", node_id_str, err)) util.HttpResponse(w, http.StatusInternalServerError, err.Error()) } }
func GetClusters() (models.Clusters, error) { sessionCopy := db.GetDatastore().Copy() defer sessionCopy.Close() collection := sessionCopy.DB(conf.SystemConfig.DBConfig.Database).C(models.COLL_NAME_STORAGE_CLUSTERS) var clusters models.Clusters err := collection.Find(nil).All(&clusters) return clusters, err }
func updateNodeState(node string, state int) error { sessionCopy := db.GetDatastore().Copy() defer sessionCopy.Close() coll := sessionCopy.DB(conf.SystemConfig.DBConfig.Database).C(models.COLL_NAME_STORAGE_NODES) if err := coll.Update(bson.M{"hostname": node}, bson.M{"$set": bson.M{"state": state}}); err != nil { logger.Get().Critical("Error updating the node state for node: %s. error: %v", node, err) return err } return nil }
func Persist_event(event models.Event) error { sessionCopy := db.GetDatastore().Copy() defer sessionCopy.Close() coll := sessionCopy.DB(conf.SystemConfig.DBConfig.Database).C(models.COLL_NAME_NODE_EVENTS) if err := coll.Insert(event); err != nil { logger.Get().Error("Error adding the node event: %v", err) return err } return nil }
func update_node_status(nodeStatus string, event models.Event) error { sessionCopy := db.GetDatastore().Copy() defer sessionCopy.Close() coll := sessionCopy.DB(conf.SystemConfig.DBConfig.Database).C(models.COLL_NAME_STORAGE_NODES) if err := coll.Update(bson.M{"nodeid": event.NodeId}, bson.M{"$set": bson.M{"status": nodeStatus}}); err != nil { logger.Get().Error("Error updating the node status: %s", err) return err } return nil }
func (t *Task) UpdateTaskCompleted(b bool, status models.TaskStatus) (bool, error) { sessionCopy := db.GetDatastore().Copy() defer sessionCopy.Close() coll := sessionCopy.DB(conf.SystemConfig.DBConfig.Database).C(models.COLL_NAME_TASKS) if err := coll.Update(bson.M{"id": t.ID}, bson.M{"$set": bson.M{"completed": b, "status": status}}); err != nil { //logger.Get().Error("Error updating status of task: %v. error: %v", t.ID, err) return false, err } return true, nil }
func GetNode(node_id uuid.UUID) models.Node { sessionCopy := db.GetDatastore().Copy() defer sessionCopy.Close() collection := sessionCopy.DB(conf.SystemConfig.DBConfig.Database).C(models.COLL_NAME_STORAGE_NODES) var node models.Node if err := collection.Find(bson.M{"nodeid": node_id}).One(&node); err != nil { logger.Get().Error("Error getting the detail of node: %v. error: %v", node_id, err) } return node }
func node_exists(key string, value string) (*models.Node, error) { sessionCopy := db.GetDatastore().Copy() defer sessionCopy.Close() collection := sessionCopy.DB(conf.SystemConfig.DBConfig.Database).C(models.COLL_NAME_STORAGE_NODES) var node models.Node if err := collection.Find(bson.M{key: value}).One(&node); err != nil { return nil, err } else { return &node, nil } }
func getClusterNodesById(cluster_id *uuid.UUID) (models.Nodes, error) { sessionCopy := db.GetDatastore().Copy() defer sessionCopy.Close() collection := sessionCopy.DB(conf.SystemConfig.DBConfig.Database).C(models.COLL_NAME_STORAGE_NODES) var nodes models.Nodes if err := collection.Find(bson.M{"clusterid": *cluster_id}).All(&nodes); err != nil { return nil, err } return nodes, nil }
func (manager *Manager) GetStatus(id uuid.UUID) (status []models.Status, err error) { sessionCopy := db.GetDatastore().Copy() defer sessionCopy.Close() coll := sessionCopy.DB(conf.SystemConfig.DBConfig.Database).C(models.COLL_NAME_TASKS) var task models.AppTask if err := coll.Find(bson.M{"id": id}).One(&task); err != nil { logger.Get().Error("task id %s not found", id) err = errors.New(fmt.Sprintf("task id %s not found", id)) } else { status = task.StatusList } return }
func updateStorageNodeToDB(storage_node models.Node) 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) storage_node.State = models.NODE_STATE_ACTIVE if err := coll.Update(bson.M{"hostname": storage_node.Hostname}, storage_node); err != nil { logger.Get().Critical("Error Updating the node: %s. error: %v", storage_node.Hostname, err) return err } return nil }
func getNodesWithState(w http.ResponseWriter, state string) (models.Nodes, error) { var validStates = [...]string{"free", "used", "unmanaged"} var found = false var foundIndex = -1 for index, value := range validStates { if state == value { found = true foundIndex = index break } } if !found { return models.Nodes{}, errors.New(fmt.Sprintf("Invalid state value: %s", state)) } else { sessionCopy := db.GetDatastore().Copy() defer sessionCopy.Close() coll := sessionCopy.DB(conf.SystemConfig.DBConfig.Database).C(models.COLL_NAME_STORAGE_NODES) var nodes models.Nodes switch foundIndex { case 0: if err := coll.Find(bson.M{}).All(&nodes); err != nil { return models.Nodes{}, err } var unusedNodes models.Nodes for _, node := range nodes { if node.ClusterId.IsZero() { unusedNodes = append(unusedNodes, node) } } return unusedNodes, nil case 1: if err := coll.Find(bson.M{}).All(&nodes); err != nil { return models.Nodes{}, err } var usedNodes models.Nodes for _, node := range nodes { if !node.ClusterId.IsZero() { usedNodes = append(usedNodes, node) } } return usedNodes, nil case 2: if err := coll.Find(bson.M{"enabled": false}).All(&nodes); err != nil { return models.Nodes{}, err } return nodes, nil } return models.Nodes{}, nil } }
func (manager *Manager) List() []uuid.UUID { sessionCopy := db.GetDatastore().Copy() defer sessionCopy.Close() coll := sessionCopy.DB(conf.SystemConfig.DBConfig.Database).C(models.COLL_NAME_TASKS) var tasks []models.AppTask if err := coll.Find(nil).All(&tasks); err != nil { return []uuid.UUID{} } ids := make([]uuid.UUID, 0, len(tasks)) for _, task := range tasks { ids = append(ids, task.Id) } return ids }
func (a *App) getTasks(rw http.ResponseWriter, req *http.Request) { sessionCopy := db.GetDatastore().Copy() defer sessionCopy.Close() var filter bson.M = make(map[string]interface{}) rootTask := req.URL.Query().Get("level") taskStatus := req.URL.Query().Get("state") if len(rootTask) != 0 { if strings.ToLower(rootTask) == "root" { filter["parentid"], err = uuid.Parse(rootTaskId) if err != nil { logger.Get().Error("Unable to Parse the Id: %s. error: %v", rootTaskId, err) util.HandleHttpError(rw, err) return } } else { logger.Get().Error("Un-supported query param: %v", rootTask) util.HttpResponse(rw, http.StatusInternalServerError, fmt.Sprintf("Un-supported query param: %s", rootTask)) return } } if len(taskStatus) != 0 { if strings.ToLower(taskStatus) == "inprogress" { filter["completed"] = false } else if strings.ToLower(taskStatus) == "completed" { filter["completed"] = true } else { logger.Get().Error("Un-supported query param: %v", taskStatus) util.HttpResponse(rw, http.StatusInternalServerError, fmt.Sprintf("Un-supported query param: %s", taskStatus)) return } } coll := sessionCopy.DB(conf.SystemConfig.DBConfig.Database).C(models.COLL_NAME_TASKS) var tasks []models.AppTask if err := coll.Find(filter).All(&tasks); err != nil { logger.Get().Error("Unable to get tasks. error: %v", err) util.HttpResponse(rw, http.StatusInternalServerError, err.Error()) return } if len(tasks) == 0 { json.NewEncoder(rw).Encode([]models.AppTask{}) } else { json.NewEncoder(rw).Encode(tasks) } }
func (a *App) getProviderFromClusterId(cluster_id uuid.UUID) *Provider { sessionCopy := db.GetDatastore().Copy() defer sessionCopy.Close() collection := sessionCopy.DB(conf.SystemConfig.DBConfig.Database).C(models.COLL_NAME_STORAGE_CLUSTERS) var cluster models.Cluster if err := collection.Find(bson.M{"clusterid": cluster_id}).One(&cluster); err != nil { logger.Get().Error("Error getting details for cluster: %v. error: %v", cluster_id, err) return nil } if provider, ok := a.providers[cluster.Type]; ok { return &provider } else { return nil } }
func (a SaltNodeManager) EnableNode(node string) (bool, error) { if ok, err := salt_backend.EnableService(node, "collectd", true); err != nil || !ok { logger.Get().Error("Error enabling services on node: %s. error: %v", node, err) return false, err } // Enable any POST actions for node sessionCopy := db.GetDatastore().Copy() defer sessionCopy.Close() coll := sessionCopy.DB(conf.SystemConfig.DBConfig.Database).C(models.COLL_NAME_STORAGE_NODES) if err := coll.Update(bson.M{"hostname": node}, bson.M{"$set": bson.M{"enabled": true}}); err != nil { logger.Get().Error("Error updating manage state of node: %s. error: %v", node, err) return false, err } return true, nil }
func (a *App) GET_AllStorages(w http.ResponseWriter, r *http.Request) { sessionCopy := db.GetDatastore().Copy() defer sessionCopy.Close() collection := sessionCopy.DB(conf.SystemConfig.DBConfig.Database).C(models.COLL_NAME_STORAGE) var storages models.Storages if err := collection.Find(nil).All(&storages); err != nil { util.HttpResponse(w, http.StatusInternalServerError, err.Error()) logger.Get().Error("Error getting the storage list. error: %v", err) return } if len(storages) == 0 { json.NewEncoder(w).Encode(models.Storages{}) } else { json.NewEncoder(w).Encode(storages) } }
func getClusterNodesFromRequest(clusterNodes []models.ClusterNode) (models.Nodes, error) { sessionCopy := db.GetDatastore().Copy() defer sessionCopy.Close() var nodes models.Nodes coll := sessionCopy.DB(conf.SystemConfig.DBConfig.Database).C(models.COLL_NAME_STORAGE_NODES) for _, clusterNode := range clusterNodes { uuid, err := uuid.Parse(clusterNode.NodeId) if err != nil { return nodes, err } var node models.Node if err := coll.Find(bson.M{"nodeid": *uuid}).One(&node); err != nil { return nodes, err } nodes = append(nodes, node) } return nodes, nil }
func (t *Task) Persist() (bool, error) { sessionCopy := db.GetDatastore().Copy() defer sessionCopy.Close() coll := sessionCopy.DB(conf.SystemConfig.DBConfig.Database).C(models.COLL_NAME_TASKS) // Populate the task details. The parent ID should always be updated by the parent task later. var appTask models.AppTask appTask.Id = t.ID appTask.Name = t.Name appTask.Started = t.Started appTask.Completed = t.Completed appTask.StatusList = t.StatusList appTask.Tag = t.Tag if err := coll.Insert(appTask); err != nil { //logger.Get().Error("Error persisting task: %v. error: %v", t.ID, err) return false, err } return true, nil }