• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang db.GetDatastore函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/skyrings/skyring-common/db.GetDatastore函数的典型用法代码示例。如果您正苦于以下问题:Golang GetDatastore函数的具体用法?Golang GetDatastore怎么用?Golang GetDatastore使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了GetDatastore函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
}
开发者ID:skyrings,项目名称:bigfin,代码行数:26,代码来源:provider.go


示例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})
}
开发者ID:skyrings,项目名称:skyring-common,代码行数:7,代码来源:manager.go


示例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
}
开发者ID:skyrings,项目名称:bigfin,代码行数:35,代码来源:provider.go


示例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)
}
开发者ID:skyrings,项目名称:bigfin,代码行数:60,代码来源:monitoring.go


示例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
}
开发者ID:skyrings,项目名称:bigfin,代码行数:31,代码来源:import_cluster.go


示例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())
	}
}
开发者ID:skyrings,项目名称:skyring,代码行数:25,代码来源:about.go


示例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
}
开发者ID:skyrings,项目名称:bigfin,代码行数:29,代码来源:import_cluster.go


示例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
	}

}
开发者ID:skyrings,项目名称:skyring,代码行数:25,代码来源:ldapauth.go


示例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)
	}
}
开发者ID:skyrings,项目名称:skyring,代码行数:34,代码来源:tasks.go


示例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
}
开发者ID:skyrings,项目名称:bigfin,代码行数:27,代码来源:import_cluster.go


示例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{}))
}
开发者ID:skyrings,项目名称:skyring,代码行数:35,代码来源:sync.go


示例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
}
开发者ID:skyrings,项目名称:bigfin,代码行数:34,代码来源:import_cluster.go


示例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
}
开发者ID:skyrings,项目名称:skyring,代码行数:30,代码来源:sync.go


示例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
}
开发者ID:skyrings,项目名称:skyring-common,代码行数:32,代码来源:audit_logger.go


示例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)
	}
}
开发者ID:skyrings,项目名称:skyring,代码行数:35,代码来源:block_devices.go


示例16: DerivePgNum

// RULES FOR DERIVING THE PG NUM
// if no of osds <= 5 then
//   no of PGs = 128
// if no of osds > 5 and <= 10 then
//   no of PGs = 512
// if no of osds > 10 and <= 50 then
//   no of PGs = 4096
// if no of osds > 50 then
//   no of PGs = (Avg Target PGs per OSD * No of OSDs * Data Percentage) / Replica Count
//   -- where
//      Data Percentage = Target Allocation Size / Max Allocation Size
//      -- where
//         Target Allocation Size - provided in request
//         Max Allocation Size = ((Average OSD Size * No of OSDs) / Replica Count) * Max Utilization Factor
//         -- where Max Utilization Factor is set as 0.8
//  Finally round this value of next 2's power
func DerivePgNum(clusterId uuid.UUID, size string, replicaCount int, profile string) uint {
	// Get the no of OSDs in the cluster
	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, "type": models.CEPH_OSD, "storageprofile": profile}).All(&slus); err != nil {
		return uint(DEFAULT_PG_NUM)
	}
	osdsNum := len(slus)

	// Calculate the pgnum value
	if osdsNum <= 5 {
		return uint(DEFAULT_PG_NUM)
	}
	if osdsNum <= 10 {
		return uint(512)
	}
	if osdsNum <= 50 {
		return uint(4096)
	}
	avgOsdSize := avg_osd_size(slus) / 1024
	maxAllocSize := (avgOsdSize * float64(len(slus)) / float64(replicaCount)) * float64(MAX_UTILIZATION_PCNT) / 100
	pcntData := float64(utils.SizeFromStr(size)) / float64(maxAllocSize)
	pgnum := float64(float64(TARGET_PGS_PER_OSD)*float64(len(slus))*pcntData) / float64(replicaCount)
	derivedPgNum := utils.NextTwosPower(uint(pgnum))
	if derivedPgNum < uint(osdsNum) {
		// Consider next 2's power value
		newPgNum := osdsNum / replicaCount
		derivedPgNum = utils.NextTwosPower(uint(newPgNum))
	}
	return derivedPgNum
}
开发者ID:skyrings,项目名称:bigfin,代码行数:49,代码来源:storage.go


示例17: GetEventById

func GetEventById(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)
	event_id_str := vars["event-id"]
	event_id, err := uuid.Parse(event_id_str)
	if err != nil {
		logger.Get().Error("%s-Error parsing event id: %s", ctxt, event_id_str)
		HttpResponse(w, http.StatusBadRequest, fmt.Sprintf("Error parsing event id: %s", event_id_str))
		return
	}

	sessionCopy := db.GetDatastore().Copy()
	defer sessionCopy.Close()

	collection := sessionCopy.DB(conf.SystemConfig.DBConfig.Database).C(models.COLL_NAME_APP_EVENTS)
	var event models.AppEvent
	if err := collection.Find(bson.M{"eventid": *event_id}).One(&event); err == mgo.ErrNotFound {
		HttpResponse(w, http.StatusNotFound, "Event not found")
		logger.Get().Error("%s-Event: %v not found. error: %v", ctxt, *event_id, err)
		return
	} else if err != nil {
		logger.Get().Error("%s-Error getting the event detail for %v. error: %v", ctxt, *event_id, err)
		HttpResponse(w, http.StatusBadRequest, "Event finding the record")
		return
	} else {
		json.NewEncoder(w).Encode(event)
	}
}
开发者ID:skyrings,项目名称:skyring,代码行数:32,代码来源:events.go


示例18: GetSystem

func GetSystem() (system models.System, err error) {
	sessionCopy := db.GetDatastore().Copy()
	defer sessionCopy.Close()

	collection := sessionCopy.DB(conf.SystemConfig.DBConfig.Database).C(models.COLL_NAME_SKYRING_UTILIZATION)
	err = collection.Find(nil).One(&system)
	return system, err
}
开发者ID:skyrings,项目名称:skyring-common,代码行数:8,代码来源:monitoring.go


示例19: fetchThresholdEvents

func fetchThresholdEvents(selectCriteria bson.M, utilizationType string) ([]models.ThresholdEvent, error) {
	var tEventsInDb []models.ThresholdEvent
	sessionCopy := db.GetDatastore().Copy()
	defer sessionCopy.Close()
	coll := sessionCopy.DB(conf.SystemConfig.DBConfig.Database).C(models.COLL_NAME_THRESHOLD_BREACHES)
	err := coll.Find(selectCriteria).All(&tEventsInDb)
	return tEventsInDb, err
}
开发者ID:skyrings,项目名称:skyring-common,代码行数:8,代码来源:monitoring.go


示例20: 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
}
开发者ID:skyrings,项目名称:skyring,代码行数:9,代码来源:util.go



注:本文中的github.com/skyrings/skyring-common/db.GetDatastore函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang models.AppEvent类代码示例发布时间:2022-05-28
下一篇:
Golang date.NowInPdt函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap