func initializeStorageNode(node string, t *task.Task) error { sProfiles, err := skyring.GetDbProvider().StorageProfileInterface().StorageProfiles(nil, models.QueryOps{}) if err != nil { logger.Get().Error("Unable to get the storage profiles. May not be able to apply storage profiles for node: %v err:%v", node, err) } if storage_node, ok := saltnodemanager.GetStorageNodeInstance(node, sProfiles); ok { if err := updateStorageNodeToDB(*storage_node); err != nil { logger.Get().Error("Unable to add details of node: %s to DB. error: %v", node, err) t.UpdateStatus("Unable to add details of node: %s to DB. error: %v", node, err) updateNodeState(node, models.NODE_STATE_FAILED) return err } if nodeErrorMap, configureError := skyring.GetCoreNodeManager().SetUpMonitoring(node, curr_hostname); configureError != nil && len(nodeErrorMap) != 0 { if len(nodeErrorMap) != 0 { logger.Get().Error("Unable to setup collectd on %s because of %v", node, nodeErrorMap) t.UpdateStatus("Unable to setup collectd on %s because of %v", node, nodeErrorMap) updateNodeState(node, models.NODE_STATE_FAILED) return err } else { logger.Get().Error("Config Error during monitoring setup for node:%s Error:%v", node, configureError) t.UpdateStatus("Config Error during monitoring setup for node:%s Error:%v", node, configureError) updateNodeState(node, models.NODE_STATE_FAILED) return err } } return nil } else { logger.Get().Critical("Error getting the details for node: %s", node) t.UpdateStatus("Error getting the details for node: %s", node) updateNodeState(node, models.NODE_STATE_FAILED) return fmt.Errorf("Error getting the details for node: %s", node) } }
func initializeStorageNode(node string, t *task.Task, ctxt string) error { sProfiles, err := GetDbProvider().StorageProfileInterface().StorageProfiles(ctxt, nil, models.QueryOps{}) if err != nil { logger.Get().Error("%s-Unable to get the storage profiles. May not be able to apply storage profiles for node: %v err:%v", ctxt, node, err) } if storage_node, ok := saltnodemanager.GetStorageNodeInstance(node, sProfiles, ctxt); ok { if nodeErrorMap, configureError := GetCoreNodeManager().SetUpMonitoring( node, curr_hostname, ctxt); configureError != nil && len(nodeErrorMap) != 0 { if len(nodeErrorMap) != 0 { logger.Get().Error("%s-Unable to setup collectd on %s because of %v", ctxt, node, nodeErrorMap) t.UpdateStatus("Unable to setup collectd on %s because of %v", node, nodeErrorMap) skyringutils.UpdateNodeState(ctxt, node, models.NODE_STATE_FAILED) skyringutils.UpdateNodeStatus(ctxt, node, models.NODE_STATUS_UNKNOWN) return err } else { logger.Get().Error("%s-Config Error during monitoring setup for node:%s Error:%v", ctxt, node, configureError) t.UpdateStatus("Config Error during monitoring setup for node:%s Error:%v", node, configureError) skyringutils.UpdateNodeState(ctxt, node, models.NODE_STATE_FAILED) skyringutils.UpdateNodeStatus(ctxt, node, models.NODE_STATUS_UNKNOWN) return err } } util.AppendServiceToNode(bson.M{"hostname": node}, models.SkyringServices[0], models.STATUS_UP, ctxt) if ok, err := GetCoreNodeManager().SyncModules(node, ctxt); !ok || err != nil { logger.Get().Error("%s-Failed to sync modules on the node: %s. error: %v", ctxt, node, err) t.UpdateStatus("Failed to sync modules") skyringutils.UpdateNodeState(ctxt, node, models.NODE_STATE_FAILED) skyringutils.UpdateNodeStatus(ctxt, node, models.NODE_STATUS_UNKNOWN) return err } if err := saltnodemanager.SetupSkynetService(node, ctxt); err != nil { logger.Get().Error("%s-Failed to setup skynet service on the node: %s. error: %v", ctxt, node, err) t.UpdateStatus("Failed to setup skynet service") skyringutils.UpdateNodeState(ctxt, node, models.NODE_STATE_FAILED) skyringutils.UpdateNodeStatus(ctxt, node, models.NODE_STATUS_UNKNOWN) return err } if err := updateStorageNodeToDB(*storage_node, ctxt); err != nil { logger.Get().Error("%s-Unable to add details of node: %s to DB. error: %v", ctxt, node, err) t.UpdateStatus("Unable to add details of node: %s to DB. error: %v", node, err) skyringutils.UpdateNodeState(ctxt, node, models.NODE_STATE_FAILED) skyringutils.UpdateNodeStatus(ctxt, node, models.NODE_STATUS_UNKNOWN) return err } if ok, err := GetCoreNodeManager().EnableNode(node, ctxt); !ok || err != nil { logger.Get().Error("%s- Failed to enable the node. Error: %v", ctxt, err) } return nil } else { logger.Get().Critical("%s-Error getting the details for node: %s", ctxt, node) t.UpdateStatus("Error getting the details for node: %s", node) skyringutils.UpdateNodeState(ctxt, node, models.NODE_STATE_FAILED) skyringutils.UpdateNodeStatus(ctxt, node, models.NODE_STATUS_UNKNOWN) return fmt.Errorf("Error getting the details for node: %s", node) } }