本文整理汇总了Golang中github.com/skyrings/skyring/db.GetDatastore函数的典型用法代码示例。如果您正苦于以下问题:Golang GetDatastore函数的具体用法?Golang GetDatastore怎么用?Golang GetDatastore使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了GetDatastore函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: GET_Storages
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)
}
}
示例2: SyncClusterDetails
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)
}
}
}
示例3: AddStorageNodeToDB
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
}
示例4: GET_Storage
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)
}
}
示例5: GET_Nodes
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)
}
}
示例6: handle_node_start_event
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
}
示例7: GET_Node
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)
}
}
示例8: removeNode
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
}
示例9: sync_cluster_status
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
}
示例10: getTask
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)
}
示例11: SyncStorageDisks
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
}
示例12: PATCH_Disk
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())
}
}
示例13: GetClusters
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
}
示例14: updateNodeState
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
}
示例15: Persist_event
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
}