func getDomain(dbConn *sql.DB) (string, error) { var err error var domain string domain, err = admindb.GetDomain(dbConn) if err != nil { logit.Error.Println(err.Error()) return domain, err } return domain, nil }
func GetNode(w rest.ResponseWriter, r *rest.Request) { dbConn, err := util.GetConnection(CLUSTERADMIN_DB) if err != nil { logit.Error.Println("BackupNow: error " + 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("GetNode: validate token error " + err.Error()) rest.Error(w, err.Error(), http.StatusUnauthorized) return } ID := r.PathParam("ID") if ID == "" { logit.Error.Println("GetNode: error node ID required") rest.Error(w, "node ID required", http.StatusBadRequest) return } results, err2 := admindb.GetContainer(dbConn, ID) if results.ID == "" { rest.NotFound(w, r) return } if err2 != nil { logit.Error.Println("GetNode: " + err2.Error()) rest.Error(w, err2.Error(), http.StatusBadRequest) return } var currentStatus = "UNKNOWN" //go get the docker server IPAddress /** server := admindb.Server{} server, err = admindb.GetServer(dbConn, results.ServerID) if err != nil { logit.Error.Println("GetNode: " + err.Error()) rest.Error(w, err.Error(), http.StatusBadRequest) return } */ var domain string domain, err = admindb.GetDomain(dbConn) if err != nil { logit.Error.Println("GetNode: " + err.Error()) rest.Error(w, err.Error(), http.StatusBadRequest) return } /** request := &cpmserverapi.DockerInspectRequest{} request.ContainerName = results.Name var url = "http://" + server.IPAddress + ":10001" _, err = cpmserverapi.DockerInspectClient(url, request) if err != nil { logit.Error.Println("GetNode: " + err.Error()) currentStatus = CONTAINER_NOT_FOUND } */ //if currentStatus != "CONTAINER NOT FOUND" { //ping the db on that node to get current status var pinghost = results.Name logit.Info.Println("pinging db on " + pinghost + "." + domain) currentStatus, err = GetPGStatus2(dbConn, results.Name, pinghost) if err != nil { logit.Error.Println("GetNode:" + err.Error()) rest.Error(w, err.Error(), http.StatusBadRequest) return } logit.Info.Println("pinging db finished") //} node := ClusterNode{results.ID, results.ClusterID, results.ServerID, results.Name, results.Role, results.Image, results.CreateDate, currentStatus, results.ProjectID, results.ProjectName, results.ServerName, results.ClusterName} w.WriteJson(node) }