本文整理汇总了Golang中github.com/skyrings/skyring-common/db.GetDatastore函数的典型用法代码示例。如果您正苦于以下问题:Golang GetDatastore函数的具体用法?Golang GetDatastore怎么用?Golang GetDatastore使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了GetDatastore函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: CreateDefaultECProfiles
func CreateDefaultECProfiles(ctxt string, mon string, clusterId uuid.UUID) (bool, error) {
sessionCopy := db.GetDatastore().Copy()
defer sessionCopy.Close()
var cluster models.Cluster
coll := sessionCopy.DB(conf.SystemConfig.DBConfig.Database).C(models.COLL_NAME_STORAGE_CLUSTERS)
if err := coll.Find(bson.M{"clusterid": clusterId}).One(&cluster); err != nil {
logger.Get().Error("%s-Error getting cluster details for %v. error: %v", ctxt, clusterId, err)
return false, err
}
var cmdMap map[string]string = map[string]string{
"4+2": fmt.Sprintf("ceph osd erasure-code-profile set k4m2 plugin=jerasure k=4 m=2 --cluster %s", cluster.Name),
"6+3": fmt.Sprintf("ceph osd erasure-code-profile set k6m3 plugin=jerasure k=6 m=3 --cluster %s", cluster.Name),
"8+4": fmt.Sprintf("ceph osd erasure-code-profile set k8m4 plugin=jerasure k=8 m=4 --cluster %s", cluster.Name),
}
for k, v := range cmdMap {
ok, _, err := cephapi_backend.ExecCmd(mon, clusterId, v, ctxt)
if err != nil || !ok {
logger.Get().Error("%s-Error creating EC profile for %s. error: %v", ctxt, k, err)
continue
} else {
logger.Get().Debug("%s-Added EC profile for %s", ctxt, k)
}
}
return true, nil
}
示例2: Remove
func (manager *Manager) Remove(id uuid.UUID) {
delete(manager.tasks, id)
sessionCopy := db.GetDatastore().Copy()
defer sessionCopy.Close()
coll := sessionCopy.DB(conf.SystemConfig.DBConfig.Database).C(models.COLL_NAME_TASKS)
_ = coll.Remove(bson.M{"id": id})
}
示例3: GetRandomMon
func GetRandomMon(clusterId uuid.UUID) (*models.Node, error) {
sessionCopy := db.GetDatastore().Copy()
defer sessionCopy.Close()
var mons models.Nodes
var clusterNodes models.Nodes
coll := sessionCopy.DB(conf.SystemConfig.DBConfig.Database).C(models.COLL_NAME_STORAGE_NODES)
if err := coll.Find(bson.M{"clusterid": clusterId}).All(&clusterNodes); err != nil {
return nil, err
}
for _, clusterNode := range clusterNodes {
for k, v := range clusterNode.Options {
if k == "mon" && v == "Y" {
mons = append(mons, clusterNode)
}
}
}
if len(mons) <= 0 {
return nil, errors.New(fmt.Sprintf("No mons available for cluster: %v", clusterId))
}
// Pick a random mon from the list
var monNodeId uuid.UUID
if len(mons) == 1 {
monNodeId = mons[0].NodeId
} else {
randomIndex := utils.RandomNum(0, len(mons)-1)
monNodeId = mons[randomIndex].NodeId
}
var monnode models.Node
coll = sessionCopy.DB(conf.SystemConfig.DBConfig.Database).C(models.COLL_NAME_STORAGE_NODES)
if err := coll.Find(bson.M{"nodeid": monNodeId}).One(&monnode); err != nil {
return nil, err
}
return &monnode, nil
}
示例4: updateRBDStats
func updateRBDStats(ctxt string, cluster models.Cluster, monName string) (map[string]map[string]string, []RBDStats, error) {
var err_str string
var rbdStats []RBDStats
sessionCopy := db.GetDatastore().Copy()
defer sessionCopy.Close()
collection := sessionCopy.DB(conf.SystemConfig.DBConfig.Database).C(models.COLL_NAME_STORAGE)
var pools []models.Storage
if err := collection.Find(bson.M{"clusterid": cluster.ClusterId}).All(&pools); err != nil {
logger.Get().Error("%s - Failed to fetch rbd stats for cluster %v.Error %v", ctxt, cluster.Name, err)
return nil, rbdStats, err
}
metrics := make(map[string]map[string]string)
currentTimeStamp := strconv.FormatInt(time.Now().Unix(), 10)
monitoringConfig := conf.SystemConfig.TimeSeriesDBConfig
for _, pool := range pools {
var statistics RBDStats
metric_name := fmt.Sprintf("%s.%s.%s.%s.", monitoringConfig.CollectionName, strings.Replace(cluster.Name, ".", "_", -1), strings.Replace(pool.Name, ".", "_", -1), models.COLL_NAME_BLOCK_DEVICES)
response, isSuccess := getStatsFromCalamariApi(ctxt,
monName,
cluster.ClusterId,
map[string]string{"clusterName": cluster.Name, "poolName": pool.Name},
skyring_monitoring.BLOCK_DEVICE_UTILIZATION)
if !isSuccess {
/*
Already generically handled in above getStatsFromCalamariApi function.
So just a process next item.
*/
continue
}
if err := json.Unmarshal([]byte(response), &statistics); err != nil {
err_str = fmt.Sprintf("%s. Failed to fetch rbd stats from pool %v, cluster %v.Could not unmarshal %v.Error %v", err_str, pool.Name, cluster.Name, response, err)
continue
}
rbdColl := sessionCopy.DB(conf.SystemConfig.DBConfig.Database).C(models.COLL_NAME_BLOCK_DEVICES)
for _, rbdStat := range statistics.RBDs {
metric_name = fmt.Sprintf("%s%s.", metric_name, strings.Replace(rbdStat.Name, ".", "_", -1))
var percent_used float64
if rbdStat.Total > 0 {
percent_used = float64(rbdStat.Used*100) / float64(rbdStat.Total)
}
if err := rbdColl.Update(bson.M{"clusterid": cluster.ClusterId, "name": rbdStat.Name, "storageid": pool.StorageId}, bson.M{"$set": bson.M{"usage": models.Utilization{
Used: int64(rbdStat.Used),
Total: int64(rbdStat.Total),
PercentUsed: percent_used,
UpdatedAt: time.Now().String()}}}); err != nil {
err_str = fmt.Sprintf("%s.Unable to update rbd stats of rbd %v from mon %v of pool %v, cluster %v.Error: %v",
err_str, rbdStat.Name, monName, pool.Name, cluster.Name, err)
}
metrics[metric_name+skyring_monitoring.USED_SPACE] = map[string]string{currentTimeStamp: fmt.Sprintf("%v", rbdStat.Used)}
metrics[metric_name+skyring_monitoring.TOTAL_SPACE] = map[string]string{currentTimeStamp: fmt.Sprintf("%v", rbdStat.Total)}
metrics[metric_name+skyring_monitoring.PERCENT_USED] = map[string]string{currentTimeStamp: fmt.Sprintf("%v", percent_used)}
}
rbdStats = append(rbdStats, statistics)
}
return metrics, rbdStats, fmt.Errorf("%v", err_str)
}
示例5: PopulateClusterStatus
func PopulateClusterStatus(bootstrapNode string, clusterId uuid.UUID, ctxt string) error {
out, err := cephapi_backend.GetClusterStatus(bootstrapNode, clusterId, "", ctxt)
if err != nil {
return fmt.Errorf(
"%s-Error getting status of cluster: %v. error: %v",
ctxt,
clusterId,
err)
}
var status models.ClusterStatus
if val, ok := cluster_status_map[out]; ok {
status = val
} else {
status = models.CLUSTER_STATUS_UNKNOWN
}
// Update the status of the cluster
sessionCopy := db.GetDatastore().Copy()
defer sessionCopy.Close()
coll := sessionCopy.DB(conf.SystemConfig.DBConfig.Database).C(models.COLL_NAME_STORAGE_CLUSTERS)
if err := coll.Update(
bson.M{"clusterid": clusterId},
bson.M{"$set": bson.M{"status": status}}); err != nil {
return fmt.Errorf(
"%s-Failed updating the status of cluster: %v. error: %v",
ctxt,
clusterId,
err)
}
return nil
}
示例6: About
func (a *App) About(w http.ResponseWriter, r *http.Request) {
ctxt, err := GetContext(r)
if err != nil {
logger.Get().Error("Error Getting the context. error: %v", err)
}
var syscapabilities conf.SystemCapabilities
sessionCopy := db.GetDatastore().Copy()
defer sessionCopy.Close()
coll := sessionCopy.DB(conf.SystemConfig.DBConfig.Database).C(models.COLL_NAME_SYSTEM_CAPABILITIES)
if err := coll.Find(nil).One(&syscapabilities); err != nil {
HttpResponse(w, http.StatusBadRequest, fmt.Sprintf("Error in retrieving System Capabilities detail. error: %v", err))
logger.Get().Error("%s-Error in retrieving System Capabilities detail. error: %v", ctxt, err)
return
}
storage_provider_details := make(map[string]string)
for key, val := range syscapabilities.StorageProviderDetails {
storage_provider_details[strings.Title(key)] = val
delete(syscapabilities.StorageProviderDetails, key)
}
syscapabilities.StorageProviderDetails = storage_provider_details
if err := json.NewEncoder(w).Encode(syscapabilities); err != nil {
logger.Get().Error("%s-Error encoding data: %v", ctxt, err)
HttpResponse(w, http.StatusInternalServerError, err.Error())
}
}
示例7: PopulateClusterDetails
func PopulateClusterDetails(bootstrapNode string, ctxt string) (*uuid.UUID, string, error) {
out, err := cephapi_backend.GetCluster(bootstrapNode, ctxt)
if err != nil {
return nil, "", fmt.Errorf("%s-Error getting cluster details. error: %v", ctxt, err)
}
var cluster models.Cluster = models.Cluster{
ClusterId: out.Id,
Name: out.Name,
Type: bigfin_conf.ProviderName,
}
cluster.MonitoringInterval = monitoring.DefaultClusterMonitoringInterval
cluster.Monitoring = models.MonitoringState{
Plugins: utils.GetProviderSpecificDefaultThresholdValues(),
StaleNodes: []string{},
}
cluster.CompatVersion = fmt.Sprintf("%f", bigfin_conf.ProviderConfig.Provider.CompatVersion)
cluster.AutoExpand = true
// Persist the cluster details
sessionCopy := db.GetDatastore().Copy()
defer sessionCopy.Close()
coll := sessionCopy.DB(conf.SystemConfig.DBConfig.Database).C(models.COLL_NAME_STORAGE_CLUSTERS)
if err := coll.Insert(cluster); err != nil {
return nil, "", fmt.Errorf("%s-Error persisting the cluster. error: %v", ctxt, err)
}
return &out.Id, out.Name, nil
}
示例8: NewLdapAuthProvider
func NewLdapAuthProvider(config io.Reader) (*Authorizer, error) {
if config == nil {
errStr := "missing configuration file for Ldap Auth provider"
logger.Get().Error(errStr)
return nil, fmt.Errorf(errStr)
}
userDao := skyring.GetDbProvider().UserInterface()
session := db.GetDatastore()
c := session.DB(conf.SystemConfig.DBConfig.Database).C(models.COLL_NAME_LDAP)
ldapDao := models.Directory{}
err := c.Find(bson.M{}).One(&ldapDao)
if err != nil {
logger.Get().Info("Failed to open ldap db collection:%s", err)
}
//Create the Provider
if provider, err := NewAuthorizer(userDao, ldapDao); err != nil {
logger.Get().Error("Unable to initialize the authorizer for Ldapauthprovider. error: %v", err)
panic(err)
} else {
return &provider, nil
}
}
示例9: getSubTasks
func (a *App) getSubTasks(rw http.ResponseWriter, req *http.Request) {
ctxt, err := GetContext(req)
if err != nil {
logger.Get().Error("Error Getting the context. error: %v", err)
}
vars := mux.Vars(req)
taskId, err := uuid.Parse(vars["taskid"])
if err != nil {
logger.Get().Error("%s-Unable to Parse the Id: %s. error: %v", ctxt, vars["taskId"], err)
rw.WriteHeader(http.StatusBadRequest)
bytes, _ := json.Marshal(APIError{Error: err.Error()})
rw.Write(bytes)
return
}
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(bson.M{"parentid": *taskId}).All(&tasks); err != nil {
logger.Get().Error("%s-Unable to get tasks. error: %v", ctxt, err)
if err == mgo.ErrNotFound {
HttpResponse(rw, http.StatusNotFound, err.Error())
} else {
HttpResponse(rw, http.StatusInternalServerError, err.Error())
}
return
}
if len(tasks) == 0 {
json.NewEncoder(rw).Encode([]models.AppTask{})
} else {
json.NewEncoder(rw).Encode(tasks)
}
}
示例10: PopulateClusterNetworkDetails
func PopulateClusterNetworkDetails(bootstrapNode string, clusterId uuid.UUID, ctxt string) error {
out, err := cephapi_backend.GetClusterNetworks(bootstrapNode, clusterId, ctxt)
if err != nil {
return fmt.Errorf(
"%s-Error getting network details of cluster: %v. error: %v",
ctxt,
clusterId,
err)
}
// Update the cluster network details
sessionCopy := db.GetDatastore().Copy()
defer sessionCopy.Close()
coll := sessionCopy.DB(conf.SystemConfig.DBConfig.Database).C(models.COLL_NAME_STORAGE_CLUSTERS)
if err := coll.Update(
bson.M{"clusterid": clusterId},
bson.M{"$set": bson.M{
"networks.public": out.Public,
"networks.cluster": out.Cluster}}); err != nil {
return fmt.Errorf(
"%s-Error updating network details for cluster: %v. error: %v",
ctxt,
clusterId,
err)
}
return nil
}
示例11: SyncNodeUtilizations
func SyncNodeUtilizations(params map[string]interface{}) {
ctxt, ctxtOk := params["ctxt"].(string)
if !ctxtOk {
logger.Get().Error("Failed to fetch context")
return
}
sessionCopy := db.GetDatastore().Copy()
defer sessionCopy.Close()
coll := sessionCopy.DB(conf.SystemConfig.DBConfig.Database).C(models.COLL_NAME_STORAGE_NODES)
var nodes []models.Node
if err := coll.Find(bson.M{"state": models.NODE_STATE_ACTIVE}).All(&nodes); err != nil {
if err == mgo.ErrNotFound {
return
}
logger.Get().Warning("%s - Failed to fetch nodes in active state.Error %v", ctxt, err)
}
time_stamp_str := strconv.FormatInt(time.Now().Unix(), 10)
var nodeNames []string
for _, node := range nodes {
if node.State == models.NODE_STATE_ACTIVE {
nodeNames = append(nodeNames, node.Hostname)
}
}
if len(nodeNames) == 0 {
return
}
for _, node := range nodes {
go SyncNodeUtilization(ctxt, node, time_stamp_str)
}
go ComputeSystemSummary(make(map[string]interface{}))
}
示例12: checkAndUpdateAutoExpand
func checkAndUpdateAutoExpand(t *task.Task, clusterId uuid.UUID, ctxt string) {
sessionCopy := db.GetDatastore().Copy()
defer sessionCopy.Close()
coll := sessionCopy.DB(conf.SystemConfig.DBConfig.Database).C(models.COLL_NAME_STORAGE_LOGICAL_UNITS)
var slus []models.StorageLogicalUnit
if err := coll.Find(bson.M{"clusterid": clusterId}).All(&slus); err != nil {
logger.Get().Error(
"%s-Error getting SLUs of cluster: %v for colocation check. error: %v",
ctxt,
clusterId,
err)
return
}
for _, slu := range slus {
journalDet := slu.Options["journal"].(map[string]interface{})
if slu.Options["device"] == journalDet["journaldisk"].(string) {
coll1 := sessionCopy.DB(conf.SystemConfig.DBConfig.Database).C(models.COLL_NAME_STORAGE_CLUSTERS)
if err := coll1.Update(
bson.M{"clusterid": clusterId},
bson.M{"$set": bson.M{"autoexpand": false}}); err != nil {
logger.Get().Error(
"%s-Error setting autoexpand flag for cluster: %v. error: %v",
ctxt,
clusterId,
err)
return
}
t.UpdateStatus("Disabled auto expand for cluster")
break
}
}
return
}
示例13: sync_cluster_status
func sync_cluster_status(ctxt string, 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(
fmt.Sprintf("%s.%s", provider.Name, sync_functions["cluster_status"]),
models.RpcRequest{RpcRequestVars: vars, RpcRequestData: []byte{}, RpcRequestContext: ctxt},
&result)
if err != nil || result.Status.StatusCode != http.StatusOK {
logger.Get().Error("%s-Error getting status for cluster: %s. error:%v", ctxt, cluster.Name, err)
return false, err
}
clusterStatus, err := strconv.Atoi(string(result.Data.Result))
if err != nil {
logger.Get().Error("%s-Error getting status for cluster: %s. error:%v", ctxt, cluster.Name, err)
return false, err
}
// Set the cluster status
sessionCopy := db.GetDatastore().Copy()
defer sessionCopy.Close()
coll := sessionCopy.DB(conf.SystemConfig.DBConfig.Database).C(models.COLL_NAME_STORAGE_CLUSTERS)
logger.Get().Info("%s-Updating the status of the cluster: %s to %d", ctxt, cluster.Name, clusterStatus)
if err := coll.Update(bson.M{"clusterid": cluster.ClusterId}, bson.M{"$set": bson.M{"status": clusterStatus}}); err != nil {
logger.Get().Error("%s-Error updating status for cluster: %s. error:%v", ctxt, cluster.Name, err)
return false, err
}
return true, nil
}
示例14: AuditLog
func AuditLog(ctxt string, event models.AppEvent, dbprovider dbprovider.DbInterface) error {
sessionCopy := db.GetDatastore().Copy()
defer sessionCopy.Close()
if event.ClusterName == "" {
coll := sessionCopy.DB(
conf.SystemConfig.DBConfig.Database).C(models.COLL_NAME_STORAGE_CLUSTERS)
var cluster models.Cluster
if err := coll.Find(bson.M{"clusterid": event.ClusterId}).One(&cluster); err == nil {
event.ClusterName = cluster.Name
}
}
event.Context = ctxt
if event.Notify {
subject, body, err := getMailDetails(event)
if err != nil {
logger.Get().Error("%s-Could not get mail details for event: %s", ctxt, event.Name)
} else {
if err = notifier.MailNotify(subject, body, dbprovider, ctxt); err == nil {
event.Notified = true
} else {
logger.Get().Error("%s-Could not send mail for event: %s", ctxt, event.Name)
}
}
}
coll := sessionCopy.DB(conf.SystemConfig.DBConfig.Database).C(models.COLL_NAME_APP_EVENTS)
if err := coll.Insert(event); err != nil {
logger.Get().Error("%s-Error adding the app event: %v", ctxt, err)
return err
}
return nil
}
示例15: GET_ClusterBlockDevices
func (a *App) GET_ClusterBlockDevices(w http.ResponseWriter, r *http.Request) {
ctxt, err := GetContext(r)
if err != nil {
logger.Get().Error("Error Getting the context. error: %v", err)
}
vars := mux.Vars(r)
cluster_id_str := vars["cluster-id"]
cluster_id, err := uuid.Parse(cluster_id_str)
if err != nil {
logger.Get().Error("%s - Error parsing the cluster id: %s. error: %v", ctxt, cluster_id_str, err)
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_BLOCK_DEVICES)
var blkDevices []models.BlockDevice
if err := collection.Find(bson.M{"clusterid": *cluster_id}).All(&blkDevices); err != nil {
if err == mgo.ErrNotFound {
HttpResponse(w, http.StatusNotFound, err.Error())
} else {
HttpResponse(w, http.StatusInternalServerError, err.Error())
}
logger.Get().Error("%s - Error getting the block devices list for cluster: %v. error: %v", ctxt, *cluster_id, err)
return
}
if len(blkDevices) == 0 {
json.NewEncoder(w).Encode([]models.BlockDevice{})
} else {
json.NewEncoder(w).Encode(blkDevices)
}
}