// TODO
func GetBackupNodes(w rest.ResponseWriter, r *rest.Request) {
	dbConn, err := util.GetConnection(CLUSTERADMIN_DB)
	if err != nil {
		logit.Error.Println(err.Error())
		rest.Error(w, err.Error(), 400)
		return

	}

	err = secimpl.Authorize(dbConn, r.PathParam("Token"), "perm-read")
	if err != nil {
		logit.Error.Println("validate token error " + err.Error())
		rest.Error(w, err.Error(), http.StatusUnauthorized)
		return
	}

	results, err2 := admindb.GetAllContainers(dbConn)
	if err2 != nil {
		logit.Error.Println(err2.Error())
		rest.Error(w, err2.Error(), 400)
	}
	i := 0
	//nodes := make([]ClusterNode, found)
	nodes := []types.ClusterNode{}
	for i = range results {
		if results[i].Role == "unassigned" ||
			results[i].Role == "master" {
			n := types.ClusterNode{}
			n.ID = results[i].ID
			n.Name = results[i].Name
			n.ClusterID = results[i].ClusterID
			n.Role = results[i].Role
			n.Image = results[i].Image
			n.CreateDate = results[i].CreateDate
			n.ProjectName = results[i].ProjectName
			n.Status = "UNKNOWN"
			nodes = append(nodes, n)
		}
		i++
	}

	w.WriteJson(&nodes)

}
// TODO
func GetAllNodes(w rest.ResponseWriter, r *rest.Request) {
	dbConn, err := util.GetConnection(CLUSTERADMIN_DB)
	if err != nil {
		logit.Error.Println(err.Error())
		rest.Error(w, err.Error(), 400)
		return

	}
	defer dbConn.Close()

	err = secimpl.Authorize(dbConn, r.PathParam("Token"), "perm-read")
	if err != nil {
		logit.Error.Println(err.Error())
		rest.Error(w, err.Error(), http.StatusUnauthorized)
		return
	}

	results, err := admindb.GetAllContainers(dbConn)
	if err != nil {
		logit.Error.Println(err.Error())
		rest.Error(w, err.Error(), http.StatusBadRequest)
	}
	nodes := make([]types.ClusterNode, len(results))
	i := 0
	for i = range results {
		nodes[i].ID = results[i].ID
		nodes[i].Name = results[i].Name
		nodes[i].ClusterID = results[i].ClusterID
		nodes[i].Role = results[i].Role
		nodes[i].Image = results[i].Image
		nodes[i].CreateDate = results[i].CreateDate
		nodes[i].ProjectID = results[i].ProjectID
		nodes[i].ProjectName = results[i].ProjectName
		nodes[i].ClusterName = results[i].ClusterName
		//nodes[i].Status = "UNKNOWN"
		i++
	}

	w.WriteJson(&nodes)

}
Ejemplo n.º 3
0
// CollectDBSize collect and persist the database size metric into the prometheus db
func CollectDBSize(gauge *prometheus.GaugeVec) error {
	var dbConn *sql.DB
	var err error

	dbConn, err = util.GetConnection("clusteradmin")
	if err != nil {
		logit.Error.Println(err.Error())
	}
	defer dbConn.Close()

	//var domain string
	//domain, err = getDomain(dbConn)

	//get all containers
	var containers []types.Container
	containers, err = admindb.GetAllContainers(dbConn)
	if err != nil {
		logit.Error.Println(err.Error())
	}

	//for each container, collect db size metrics
	i := 0
	var credential types.Credential

	for i = range containers {
		//logit.Info.Println("dbsize processing " + containers[i].Name)
		credential, err = admindb.GetUserCredentials(dbConn, &containers[i])
		if err != nil {
			logit.Error.Println(err.Error())
		}
		err = process(&containers[i], &credential, gauge)
		if err != nil {
			logit.Error.Println(err.Error())
		}

		i++
	}

	return nil
}
// Collecthc perform a health check, this will persist metrics
func Collecthc() error {
	var err error

	logit.Info.Println("Collecthc called")

	var dbConn *sql.DB
	dbConn, err = util.GetConnection(CLUSTERADMIN_DB)
	if err != nil {
		logit.Error.Println(err.Error())
	}
	defer dbConn.Close()

	//get all containers
	var containers []types.Container
	containers, err = admindb.GetAllContainers(dbConn)
	if err != nil {
		logit.Error.Println(err.Error())
	}

	//for each container, do a health check
	i := 0
	var credential types.Credential
	var checks []types.HealthCheck
	checks = make([]types.HealthCheck, 0)

	var status string

	for i = range containers {
		hc := types.HealthCheck{}
		hc.ProjectID = containers[i].ProjectID
		hc.ProjectName = containers[i].ProjectName
		hc.ContainerName = containers[i].Name
		hc.ContainerID = containers[i].ID
		hc.ContainerRole = containers[i].Role
		hc.ContainerImage = containers[i].Image

		credential, err = admindb.GetUserCredentials(dbConn, &containers[i])
		if err != nil {
			logit.Error.Println(err.Error())
		} else {

			status, err = ping(&credential)
			hc.Status = status

			checks = append(checks, hc)
		}
		i++
	}

	//delete current health checks
	err = admindb.DeleteHealthCheck(dbConn)
	if err != nil {
		logit.Error.Println(err.Error())
		return err
	}

	//persist health checks
	i = 0
	for i = range checks {
		_, err = admindb.InsertHealthCheck(dbConn, checks[i])
		if err != nil {
			logit.Error.Println(err.Error())
		}
		i++
	}

	return nil
}