// @Title List // @Description find node by node_ID // @Param body body models.CommonRequestBody true "the nodes you want to get" // @Success 200 {object} models.ResponseNode // @Failure 400 invalid request message // @router /list [post] func (self *NodeController) List() { var body models.CommonRequestBody err := json.Unmarshal(self.Ctx.Input.CopyBody(beego.BConfig.MaxMemory), &body) if err != nil { self.Data["json"] = models.NewInternalError(400, err) self.Ctx.Output.SetStatus(400) self.ServeJSON() return } if body.All { list := make([]models.ResponseNode, 0, 100) nodes := models.GetAllNode() for _, node := range nodes { list = append(list, models.ResponseNode{ ID: node.ID, IPAddress: node.IPAddress, NCPU: node.NCPU, Mem_MB: node.Mem_MB, Status: node.Status, Runtime: node.Runtime, }) } self.Data["json"] = list self.ServeJSON() return } list := make([]models.ResponseNode, len(body.ID)) for i, id := range body.ID { if strings.TrimSpace(id) == "" { continue } if err, node := models.GetNode(id); err == nil { list[i] = models.ResponseNode{ ID: node.ID, IPAddress: node.IPAddress, NCPU: node.NCPU, Mem_MB: node.Mem_MB, Status: node.Status, Runtime: node.Runtime, } } else { list[i] = models.ResponseNode{ ID: id, Error: ErrNotFound.Error(), } } } self.Data["json"] = list self.ServeJSON() }
// @Title GetAll // @Description find all nodes // @Success 200 {object} models.ResponseNode // @router / [get] func (self *NodeController) GetAll() { nodes := models.GetAllNode() list := make([]models.ResponseNode, 0, 100) for _, node := range nodes { list = append(list, models.ResponseNode{ ID: node.ID, IPAddress: node.IPAddress, NCPU: node.NCPU, Mem_MB: node.Mem_MB, Status: node.Status, Runtime: node.Runtime, }) } self.Data["json"] = list self.ServeJSON() return }