V1.2
1、新增服务器资源添加 (新增数据表pp_task_server) 2、新增远程服务器任务执行 3、删除邮件通知功能(pp_task删除两个有关字段)
This commit is contained in:
@@ -13,6 +13,7 @@ import (
|
||||
"github.com/george518/PPGo_Job/models"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type GroupController struct {
|
||||
@@ -39,6 +40,7 @@ func (this *GroupController) Add() {
|
||||
group.GroupName = strings.TrimSpace(this.GetString("group_name"))
|
||||
group.UserId = this.userId
|
||||
group.Description = strings.TrimSpace(this.GetString("description"))
|
||||
group.CreateTime = time.Now().Unix()
|
||||
|
||||
_, err := models.TaskGroupAdd(group)
|
||||
if err != nil {
|
||||
|
||||
135
controllers/server.go
Normal file
135
controllers/server.go
Normal file
@@ -0,0 +1,135 @@
|
||||
/*
|
||||
* @Author: haodaquan
|
||||
* @Date: 2017-08-16 10:27:40
|
||||
* @Last Modified by: haodaquan
|
||||
* @Last Modified time: 2017-08-16 09:17:22
|
||||
*/
|
||||
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"github.com/astaxie/beego"
|
||||
"github.com/george518/PPGo_Job/libs"
|
||||
"github.com/george518/PPGo_Job/models"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type ServerController struct {
|
||||
BaseController
|
||||
}
|
||||
|
||||
func (this *ServerController) List() {
|
||||
page, _ := this.GetInt("page")
|
||||
if page < 1 {
|
||||
page = 1
|
||||
}
|
||||
|
||||
result, count := models.TaskServerGetList(page, this.pageSize)
|
||||
list := make([]map[string]interface{}, len(result))
|
||||
for k, v := range result {
|
||||
row := make(map[string]interface{})
|
||||
row["id"] = v.Id
|
||||
if(v.Type==0){
|
||||
row["type"] = "密码"
|
||||
}else {
|
||||
row["type"] = "密钥"
|
||||
}
|
||||
row["server_name"] = v.ServerName
|
||||
row["server_ip"] = v.ServerIp
|
||||
row["detail"] = v.Detail
|
||||
row["port"] = v.Port
|
||||
row["create_time"] = beego.Date(time.Unix(v.CreateTime, 0), "Y-m-d H:i:s")
|
||||
list[k] = row
|
||||
}
|
||||
this.Data["pageTitle"] = "服务器列表"
|
||||
this.Data["list"] = list
|
||||
this.Data["pageBar"] = libs.NewPager(page, int(count), this.pageSize, beego.URLFor("ServerController.List"), true).ToString()
|
||||
this.display()
|
||||
}
|
||||
|
||||
func (this *ServerController) Add() {
|
||||
if this.isPost() {
|
||||
server := new(models.TaskServer)
|
||||
server.ServerName = strings.TrimSpace(this.GetString("server_name"))
|
||||
server.ServerIp = strings.TrimSpace(this.GetString("server_ip"))
|
||||
server.Port,_= strconv.Atoi(this.GetString("port"))
|
||||
server.Type,_ = strconv.Atoi(this.GetString("type"))
|
||||
server.PrivateKeySrc = strings.TrimSpace(this.GetString("private_key_src"))
|
||||
server.PublicKeySrc = strings.TrimSpace(this.GetString("public_key_src"))
|
||||
server.Password = strings.TrimSpace(this.GetString("password"))
|
||||
server.Detail = strings.TrimSpace(this.GetString("detail"))
|
||||
server.CreateTime = time.Now().Unix()
|
||||
server.UpdateTime = time.Now().Unix()
|
||||
server.Status = 0
|
||||
_, err := models.TaskServerAdd(server)
|
||||
if err != nil {
|
||||
this.ajaxMsg(err.Error(), MSG_ERR)
|
||||
}
|
||||
this.ajaxMsg("", MSG_OK)
|
||||
}
|
||||
this.Data["pageTitle"] = "添加服务器"
|
||||
this.display()
|
||||
}
|
||||
|
||||
func (this *ServerController) Edit() {
|
||||
id, _ := this.GetInt("id")
|
||||
server, err := models.TaskServerGetById(id)
|
||||
if err != nil {
|
||||
this.showMsg(err.Error())
|
||||
}
|
||||
|
||||
if this.isPost() {
|
||||
server.ServerName = strings.TrimSpace(this.GetString("server_name"))
|
||||
server.ServerIp = strings.TrimSpace(this.GetString("server_ip"))
|
||||
server.Port,_ = strconv.Atoi(this.GetString("port"))
|
||||
server.Type,_ = strconv.Atoi(this.GetString("type"))
|
||||
server.Id,_ = strconv.Atoi(this.GetString("id"))
|
||||
server.PrivateKeySrc = strings.TrimSpace(this.GetString("private_key_src"))
|
||||
server.PublicKeySrc = strings.TrimSpace(this.GetString("public_key_src"))
|
||||
server.Password = strings.TrimSpace(this.GetString("password"))
|
||||
server.Detail = strings.TrimSpace(this.GetString("detail"))
|
||||
server.UpdateTime = time.Now().Unix()
|
||||
server.Status = 0
|
||||
err := server.Update()
|
||||
if err != nil {
|
||||
this.ajaxMsg(err.Error(), MSG_ERR)
|
||||
}
|
||||
this.ajaxMsg("", MSG_OK)
|
||||
}
|
||||
|
||||
this.Data["pageTitle"] = "编辑服务器"
|
||||
this.Data["server"] = server
|
||||
this.display()
|
||||
}
|
||||
|
||||
//TODO删除更新
|
||||
func (this *ServerController) Batch() {
|
||||
action := this.GetString("action")
|
||||
ids := this.GetStrings("ids")
|
||||
if len(ids) < 1 {
|
||||
this.ajaxMsg("请选择要操作的项目", MSG_ERR)
|
||||
}
|
||||
|
||||
for _, v := range ids {
|
||||
id, _ := strconv.Atoi(v)
|
||||
if id < 1 {
|
||||
continue
|
||||
}
|
||||
switch action {
|
||||
case "delete":
|
||||
//查询服务器是否被占用
|
||||
filters := make([]interface{}, 0)
|
||||
filters = append(filters, "server_id", id)
|
||||
_, count := models.TaskGetList(1, 1000, filters...)
|
||||
if count > 0 {
|
||||
this.ajaxMsg("请先解除该服务器的任务占用", MSG_ERR)
|
||||
}else{
|
||||
models.TaskServerDelById(id)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.ajaxMsg("", MSG_OK)
|
||||
}
|
||||
@@ -43,12 +43,23 @@ func (this *TaskController) List() {
|
||||
result, count := models.TaskGetList(page, this.pageSize, filters...)
|
||||
|
||||
list := make([]map[string]interface{}, len(result))
|
||||
|
||||
|
||||
// 分组列表
|
||||
groups, _ := models.TaskGroupGetList(1, 100)
|
||||
groups_map := make(map[int]string)
|
||||
for _, gname := range groups {
|
||||
groups_map[gname.Id] = gname.GroupName
|
||||
}
|
||||
|
||||
//服务器列表
|
||||
servers, _ := models.TaskServerGetList(1, 100)
|
||||
|
||||
server_map := make(map[int]string)
|
||||
for _, sname := range servers {
|
||||
server_map[sname.Id] = sname.ServerName
|
||||
}
|
||||
server_map[0] = "本地"
|
||||
for k, v := range result {
|
||||
row := make(map[string]interface{})
|
||||
row["id"] = v.Id
|
||||
@@ -58,6 +69,7 @@ func (this *TaskController) List() {
|
||||
row["description"] = v.Description
|
||||
row["group_id"] = v.GroupId
|
||||
row["group_name"] = groups_map[v.GroupId]
|
||||
row["server_name"] = server_map[v.ServerId]
|
||||
row["is_odd"] = k % 2
|
||||
|
||||
e := jobs.GetEntryById(v.Id)
|
||||
@@ -81,6 +93,7 @@ func (this *TaskController) List() {
|
||||
}
|
||||
list[k] = row
|
||||
}
|
||||
|
||||
this.Data["pageTitle"] = "任务列表"
|
||||
this.Data["list"] = list
|
||||
this.Data["groups"] = groups
|
||||
@@ -99,26 +112,11 @@ func (this *TaskController) Add() {
|
||||
task.TaskName = strings.TrimSpace(this.GetString("task_name"))
|
||||
task.Description = strings.TrimSpace(this.GetString("description"))
|
||||
task.Concurrent, _ = this.GetInt("concurrent")
|
||||
task.ServerId, _ = this.GetInt("server_id")
|
||||
task.CronSpec = strings.TrimSpace(this.GetString("cron_spec"))
|
||||
task.Command = strings.TrimSpace(this.GetString("command"))
|
||||
task.Notify, _ = this.GetInt("notify")
|
||||
task.Timeout, _ = this.GetInt("timeout")
|
||||
|
||||
notifyEmail := strings.TrimSpace(this.GetString("notify_email"))
|
||||
if notifyEmail != "" {
|
||||
emailList := make([]string, 0)
|
||||
tmp := strings.Split(notifyEmail, "\n")
|
||||
for _, v := range tmp {
|
||||
v = strings.TrimSpace(v)
|
||||
if !libs.IsEmail([]byte(v)) {
|
||||
this.ajaxMsg("无效的Email地址:"+v, MSG_ERR)
|
||||
} else {
|
||||
emailList = append(emailList, v)
|
||||
}
|
||||
}
|
||||
task.NotifyEmail = strings.Join(emailList, "\n")
|
||||
}
|
||||
|
||||
if task.TaskName == "" || task.CronSpec == "" || task.Command == "" {
|
||||
this.ajaxMsg("请填写完整信息", MSG_ERR)
|
||||
}
|
||||
@@ -135,6 +133,9 @@ func (this *TaskController) Add() {
|
||||
// 分组列表
|
||||
groups, _ := models.TaskGroupGetList(1, 100)
|
||||
this.Data["groups"] = groups
|
||||
//服务器分组
|
||||
servers, _ := models.TaskServerGetList(1, 100)
|
||||
this.Data["servers"] = servers
|
||||
this.Data["pageTitle"] = "添加任务"
|
||||
this.display()
|
||||
}
|
||||
@@ -153,26 +154,10 @@ func (this *TaskController) Edit() {
|
||||
task.Description = strings.TrimSpace(this.GetString("description"))
|
||||
task.GroupId, _ = this.GetInt("group_id")
|
||||
task.Concurrent, _ = this.GetInt("concurrent")
|
||||
task.ServerId, _ = this.GetInt("server_id")
|
||||
task.CronSpec = strings.TrimSpace(this.GetString("cron_spec"))
|
||||
task.Command = strings.TrimSpace(this.GetString("command"))
|
||||
task.Notify, _ = this.GetInt("notify")
|
||||
task.Timeout, _ = this.GetInt("timeout")
|
||||
|
||||
notifyEmail := strings.TrimSpace(this.GetString("notify_email"))
|
||||
if notifyEmail != "" {
|
||||
tmp := strings.Split(notifyEmail, "\n")
|
||||
emailList := make([]string, 0, len(tmp))
|
||||
for _, v := range tmp {
|
||||
v = strings.TrimSpace(v)
|
||||
if !libs.IsEmail([]byte(v)) {
|
||||
this.ajaxMsg("无效的Email地址:"+v, MSG_ERR)
|
||||
} else {
|
||||
emailList = append(emailList, v)
|
||||
}
|
||||
}
|
||||
task.NotifyEmail = strings.Join(emailList, "\n")
|
||||
}
|
||||
|
||||
if task.TaskName == "" || task.CronSpec == "" || task.Command == "" {
|
||||
this.ajaxMsg("请填写完整信息", MSG_ERR)
|
||||
}
|
||||
@@ -189,6 +174,10 @@ func (this *TaskController) Edit() {
|
||||
// 分组列表
|
||||
groups, _ := models.TaskGroupGetList(1, 100)
|
||||
this.Data["groups"] = groups
|
||||
//服务器分组
|
||||
servers, _ := models.TaskServerGetList(1, 100)
|
||||
this.Data["servers"] = servers
|
||||
|
||||
this.Data["task"] = task
|
||||
this.Data["pageTitle"] = "编辑任务"
|
||||
this.display()
|
||||
|
||||
Reference in New Issue
Block a user