예제 #1
0
파일: provider.go 프로젝트: skyrings/bigfin
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
0
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
0
파일: provider.go 프로젝트: skyrings/bigfin
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
0
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
0
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
0
파일: about.go 프로젝트: skyrings/skyring
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
0
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
0
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
0
파일: tasks.go 프로젝트: skyrings/skyring
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
0
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
0
파일: sync.go 프로젝트: skyrings/skyring
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
0
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
0
파일: sync.go 프로젝트: skyrings/skyring
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
0
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
0
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)
	}
}
예제 #16
0
파일: storage.go 프로젝트: skyrings/bigfin
// 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
}
예제 #17
0
파일: events.go 프로젝트: skyrings/skyring
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)
	}
}
예제 #18
0
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
}
예제 #19
0
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
}
예제 #20
0
파일: util.go 프로젝트: skyrings/skyring
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
}
예제 #21
0
파일: util.go 프로젝트: skyrings/skyring
func GetCluster(cluster_id *uuid.UUID) (cluster models.Cluster, err error) {
	sessionCopy := db.GetDatastore().Copy()
	defer sessionCopy.Close()
	collection := sessionCopy.DB(conf.SystemConfig.DBConfig.Database).C(models.COLL_NAME_STORAGE_CLUSTERS)
	if err := collection.Find(bson.M{"clusterid": *cluster_id}).One(&cluster); err != nil {
		return cluster, err
	}
	return cluster, nil
}
예제 #22
0
파일: skyring.go 프로젝트: skyrings/skyring
func FailStillCreatingClusters(ctxt string) {
	sessionCopy := db.GetDatastore().Copy()
	defer sessionCopy.Close()
	collection := sessionCopy.DB(conf.SystemConfig.DBConfig.Database).C(models.COLL_NAME_STORAGE_CLUSTERS)
	if _, err := collection.UpdateAll(bson.M{"state": models.CLUSTER_STATE_CREATING}, bson.M{"$set": bson.M{"state": models.CLUSTER_STATE_FAILED,
		"status": models.CLUSTER_STATUS_ERROR}}); err != nil {
		logger.Get().Debug("%s-%v", ctxt, err.Error())
	}
}
예제 #23
0
func getOsds(clusterId uuid.UUID) (slus []models.StorageLogicalUnit, err error) {
	sessionCopy := db.GetDatastore().Copy()
	defer sessionCopy.Close()
	coll := sessionCopy.DB(conf.SystemConfig.DBConfig.Database).C(models.COLL_NAME_STORAGE_LOGICAL_UNITS)
	if err := coll.Find(bson.M{"clusterid": clusterId}).Sort("name").All(&slus); err != nil {
		return nil, fmt.Errorf("Error getting the slus for cluster: %v. error: %v", clusterId, err)
	}
	return slus, nil
}
예제 #24
0
func getEntity(clusterId uuid.UUID, resourceName string, collectionName string, entity interface{}) error {
	sessionCopy := db.GetDatastore().Copy()
	defer sessionCopy.Close()
	collection := sessionCopy.DB(conf.SystemConfig.DBConfig.Database).C(collectionName)
	if err := collection.Find(bson.M{"clusterid": clusterId, "name": resourceName}).One(entity); err != nil {
		return err
	}
	return nil
}
예제 #25
0
func UpdateDb(selectCriteria bson.M, update bson.M, collectionName string, ctxt string) {
	sessionCopy := db.GetDatastore().Copy()
	defer sessionCopy.Close()

	coll := sessionCopy.DB(conf.SystemConfig.DBConfig.Database).C(collectionName)
	if err := coll.Update(selectCriteria, bson.M{"$set": update}); err != nil {
		logger.Get().Error("%s - Failed to perform the update for select criteria %v and update %v. Error %v", ctxt, selectCriteria, update, err)
	}
}
예제 #26
0
func getClustersByType(clusterType string) (clusters []models.Cluster, err error) {
	sessionCopy := db.GetDatastore().Copy()
	defer sessionCopy.Close()
	collection := sessionCopy.DB(conf.SystemConfig.DBConfig.Database).C(models.COLL_NAME_STORAGE_CLUSTERS)
	if err := collection.Find(bson.M{"type": clusterType}).All(&clusters); err != nil {
		return clusters, err
	}
	return clusters, nil
}
예제 #27
0
func GetClusterSummaries(selectCriteria bson.M) ([]models.ClusterSummary, error) {
	var clustersSummary []models.ClusterSummary

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

	collection := sessionCopy.DB(conf.SystemConfig.DBConfig.Database).C(models.COLL_NAME_CLUSTER_SUMMARY)
	err := collection.Find(selectCriteria).All(&clustersSummary)
	return clustersSummary, err
}
예제 #28
0
func GetClusters(selectCriteria bson.M) ([]models.Cluster, error) {
	var clusters []models.Cluster

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

	collection := sessionCopy.DB(conf.SystemConfig.DBConfig.Database).C(models.COLL_NAME_STORAGE_CLUSTERS)
	err := collection.Find(selectCriteria).All(&clusters)
	return clusters, err
}
예제 #29
0
파일: skyring.go 프로젝트: skyrings/skyring
func initializeAbout(ctxt string) {
	if len(conf.SystemConfig.SysCapabilities.StorageProviderDetails) != 0 {
		sessionCopy := db.GetDatastore().Copy()
		defer sessionCopy.Close()
		coll := sessionCopy.DB(conf.SystemConfig.DBConfig.Database).C(models.COLL_NAME_SYSTEM_CAPABILITIES)
		if _, err := coll.Upsert(bson.M{"productname": conf.SystemConfig.SysCapabilities.ProductName}, conf.SystemConfig.SysCapabilities); err != nil {
			logger.Get().Error(fmt.Sprintf("%s-Error adding System_capabilities details . error: %v", ctxt, err))
		}
	}
}
예제 #30
0
func Update_node_state_byId(ctxt string, nodeId uuid.UUID, state models.NodeState) 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": nodeId}, bson.M{"$set": bson.M{"state": state}}); err != nil {
		logger.Get().Error("%s-Error updating the node state: %s", ctxt, err)
		return err
	}
	return nil
}