[REV]Update code foramt

This commit is contained in:
崔斌 2017-11-27 18:01:04 +08:00
parent 538acb4ead
commit f0103d3b8f
7 changed files with 97 additions and 99 deletions

View File

@ -1,20 +1,21 @@
package controller
import (
"github.com/bitly/go-simplejson"
"github.com/Sirupsen/logrus"
"net/http"
"io/ioutil"
"net/http"
"github.com/Sirupsen/logrus"
"github.com/bitly/go-simplejson"
"github.com/goodrain/rainbond/pkg/db"
dbmodel "github.com/goodrain/rainbond/pkg/db/model"
httputil "github.com/goodrain/rainbond/pkg/util/http"
"github.com/goodrain/rainbond/pkg/db"
)
//Events GetLogs
func (e *TenantStruct) Event(w http.ResponseWriter, r *http.Request) {
// swagger:operation GET /v2/tenants/{tenant_name}/event v2 get events
//
// 获取指定event_ids详细信息 **完成
// 获取指定event_ids详细信息
//
// get events
//
@ -28,28 +29,28 @@ func (e *TenantStruct) Event(w http.ResponseWriter, r *http.Request) {
// schema:
// "$ref": "#/responses/commandResponse"
// description: 统一返回格式
b,_:=ioutil.ReadAll(r.Body)
b, _ := ioutil.ReadAll(r.Body)
defer r.Body.Close()
j,err:=simplejson.NewJson(b)
j, err := simplejson.NewJson(b)
if err != nil {
logrus.Errorf("error decode json,details %s",err.Error())
httputil.ReturnError(r,w,400,"bad request")
logrus.Errorf("error decode json,details %s", err.Error())
httputil.ReturnError(r, w, 400, "bad request")
return
}
eventIDS,err:=j.Get("event_ids").StringArray()
eventIDS, err := j.Get("event_ids").StringArray()
if err != nil {
logrus.Errorf("error get event_id in json,details %s",err.Error())
httputil.ReturnError(r,w,400,"bad request")
logrus.Errorf("error get event_id in json,details %s", err.Error())
httputil.ReturnError(r, w, 400, "bad request")
return
}
result:=[]*dbmodel.ServiceEvent{}
for _,v:=range eventIDS{
serviceEvent,err:=db.GetManager().ServiceEventDao().GetEventByEventID(v)
result := []*dbmodel.ServiceEvent{}
for _, v := range eventIDS {
serviceEvent, err := db.GetManager().ServiceEventDao().GetEventByEventID(v)
if err != nil {
logrus.Warnf("can't find event by given id %s ,details %s",v,err.Error())
logrus.Warnf("can't find event by given id %s ,details %s", v, err.Error())
continue
}
result=append(result,serviceEvent)
result = append(result, serviceEvent)
}
httputil.ReturnSuccess(r, w, result)
}

View File

@ -1,30 +1,30 @@
// RAINBOND, Application Management Platform
// Copyright (C) 2014-2017 Goodrain Co., Ltd.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version. For any non-GPL usage of Rainbond,
// one or multiple Commercial Licenses authorized by Goodrain Co., Ltd.
// must be obtained first.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package controller
import (
httputil "github.com/goodrain/rainbond/pkg/util/http"
"net/http"
"os"
"strings"
httputil "github.com/goodrain/rainbond/pkg/util/http"
"github.com/Sirupsen/logrus"
"github.com/go-chi/chi"
@ -40,7 +40,7 @@ type EventLogStruct struct{}
func (e *EventLogStruct) Logs(w http.ResponseWriter, r *http.Request) {
// swagger:operation POST /v2/tenants/{tenant_name}/services/{service_alias}/log v2 lastLinesLogs
//
// 获取最新指定数量条日志 **完成
// 获取最新指定数量条日志
//
// get last x lines logs
//
@ -77,7 +77,7 @@ func (e *EventLogStruct) Logs(w http.ResponseWriter, r *http.Request) {
func (e *EventLogStruct) LogList(w http.ResponseWriter, r *http.Request) {
// swagger:operation GET /v2/tenants/{tenant_name}/services/{service_alias}/log-file v2 logList
//
// 获取应用日志列表 **完成
// 获取应用日志列表
//
// get log list
//
@ -109,7 +109,7 @@ func (e *EventLogStruct) LogList(w http.ResponseWriter, r *http.Request) {
func (e *EventLogStruct) LogFile(w http.ResponseWriter, r *http.Request) {
// swagger:operation GET /v2/tenants/{tenant_name}/services/{service_alias}/log-file/{file_name} v2 logFile
//
// 下载应用指定日志 **完成
// 下载应用指定日志
//
// get log file
//
@ -143,7 +143,7 @@ func (e *EventLogStruct) LogFile(w http.ResponseWriter, r *http.Request) {
func (e *EventLogStruct) LogSocket(w http.ResponseWriter, r *http.Request) {
// swagger:operation GET /v2/tenants/{tenant_name}/services/{service_alias}/log-instance v2 logSocket
//
// 获取应用日志web-socket实例 **完成
// 获取应用日志web-socket实例
//
// get log socket
//
@ -173,7 +173,7 @@ func (e *EventLogStruct) LogSocket(w http.ResponseWriter, r *http.Request) {
func (e *EventLogStruct) LogByAction(w http.ResponseWriter, r *http.Request) {
// swagger:operation POST /v2/tenants/{tenant_name}/services/{service_alias}/event-log v2 logByAction
//
// 获取指定操作的操作日志 **完成
// 获取指定操作的操作日志
//
// get log by level
//

View File

@ -104,7 +104,7 @@ func (t *TenantStruct) AllTenantResources(w http.ResponseWriter, r *http.Request
func (t *TenantStruct) TenantResources(w http.ResponseWriter, r *http.Request) {
// swagger:operation POST /v2/resources/tenants v2 tenantResources
//
// 租户资源使用情况 **完成
// 租户资源使用情况
//
// get tenant resources
//
@ -136,7 +136,7 @@ func (t *TenantStruct) TenantResources(w http.ResponseWriter, r *http.Request) {
func (t *TenantStruct) SumTenants(w http.ResponseWriter, r *http.Request) {
// swagger:operation GET /v2/resources/tenants/sum v2 sumTenants
//
// 获取租户数量 **完成
// 获取租户数量
//
// get tenant resources
//
@ -173,7 +173,7 @@ func (t *TenantStruct) Tenant(w http.ResponseWriter, r *http.Request) {
func (t *TenantStruct) AddTenant(w http.ResponseWriter, r *http.Request) {
// swagger:operation POST /v2/tenants v2 addTenant
//
// 添加租户信息 **完成
// 添加租户信息
//
// add tenant
//
@ -262,7 +262,7 @@ func (t *TenantStruct) ServicesInfo(w http.ResponseWriter, r *http.Request) {
//
// 获取租户所有应用信息
//
// get services info in tenant **完成
// get services info in tenant
//
// ---
// consumes:
@ -294,7 +294,7 @@ func (t *TenantStruct) CreateService(w http.ResponseWriter, r *http.Request) {
//
// 创建应用
//
// create service **完成
// create service
//
// ---
// consumes:
@ -341,7 +341,7 @@ func (t *TenantStruct) UpdateService(w http.ResponseWriter, r *http.Request) {
//
// 应用更新
//
// update service **完成
// update service
//
// ---
// consumes:
@ -387,7 +387,7 @@ func (t *TenantStruct) SetLanguage(w http.ResponseWriter, r *http.Request) {
//
// 设置应用语言
//
// set language **完成
// set language
//
// ---
// consumes:
@ -521,7 +521,7 @@ func (t *TenantStruct) AddServiceLabel(w http.ResponseWriter, r *http.Request) {
//
// 添加应用标签
//
// add service label **完成
// add service label
//
// ---
// consumes:
@ -560,7 +560,7 @@ func (t *TenantStruct) UpdateServiceLabel(w http.ResponseWriter, r *http.Request
//
// 更新应用标签
//
// delete service label **完成
// delete service label
//
// ---
// consumes:
@ -608,7 +608,7 @@ func (t *TenantStruct) AddNodeLabel(w http.ResponseWriter, r *http.Request) {
//
// 添加节点标签
//
// add node label **完成
// add node label
//
// ---
// consumes:
@ -646,7 +646,7 @@ func (t *TenantStruct) DeleteNodeLabel(w http.ResponseWriter, r *http.Request) {
//
// 删除节点标签
//
// delete node label **完成
// delete node label
//
// ---
// consumes:
@ -699,7 +699,7 @@ func (t *TenantStruct) GetSingleServiceInfo(w http.ResponseWriter, r *http.Reque
//
// 获取应用信息
//
// get service info **完成
// get service info
//
// ---
// consumes:
@ -777,7 +777,7 @@ func (t *TenantStruct) Dependency(w http.ResponseWriter, r *http.Request) {
//
// 增加应用依赖关系
//
// add dependency **完成
// add dependency
//
// ---
// consumes:
@ -821,7 +821,7 @@ func (t *TenantStruct) AddDependency(w http.ResponseWriter, r *http.Request) {
//
// 删除应用依赖关系
//
// delete dependency **完成
// delete dependency
//
// ---
// consumes:
@ -875,7 +875,7 @@ func (t *TenantStruct) Env(w http.ResponseWriter, r *http.Request) {
//
// 增加环境变量
//
// add env var **完成
// add env var
//
// ---
// consumes:
@ -920,7 +920,7 @@ func (t *TenantStruct) AddEnv(w http.ResponseWriter, r *http.Request) {
//
// 删除环境变量
//
// delete env var **完成
// delete env var
//
// ---
// consumes:
@ -983,7 +983,7 @@ func (t *TenantStruct) Ports(w http.ResponseWriter, r *http.Request) {
//
// 增加应用端口,默认关闭对内和对外选项,需要开启使用相应接口
//
// add port **完成
// add port
//
// ---
// consumes:
@ -1019,7 +1019,7 @@ func (t *TenantStruct) addPortController(w http.ResponseWriter, r *http.Request)
//
// 更新应用端口信息
//
// update port **完成
// update port
//
// ---
// consumes:
@ -1055,7 +1055,7 @@ func (t *TenantStruct) updatePortController(w http.ResponseWriter, r *http.Reque
//
// 开关端口对外服务,应用无需重启自动生效
//
// add port **完成
// add port
//
// ---
// Consumes:
@ -1119,7 +1119,7 @@ func (t *TenantStruct) PortOuterController(w http.ResponseWriter, r *http.Reques
//
// 开关对内服务,应用无需重启,自动生效
//
// add port **完成
// add port
//
// ---
// Consumes:
@ -1168,7 +1168,7 @@ func (t *TenantStruct) PortInnerController(w http.ResponseWriter, r *http.Reques
//
// 删除端口变量
//
// delete port **完成
// delete port
//
// ---
// Consumes:
@ -1216,7 +1216,7 @@ func (t *TenantStruct) deletePortController(w http.ResponseWriter, r *http.Reque
//
// 获取pods信息
//
// get pods info **完成
// get pods info
//
// ---
// consumes:
@ -1264,7 +1264,7 @@ func (t *TenantStruct) AddProbe(w http.ResponseWriter, r *http.Request) {
//
// 增加应用探针
//
// add probe **完成
// add probe
//
// ---
// consumes:
@ -1315,7 +1315,7 @@ func (t *TenantStruct) UpdateProbe(w http.ResponseWriter, r *http.Request) {
//
// 更新应用探针信息, *注意此处为全量更新
//
// update probe ** 完成
// update probe
//
// ---
// consumes:
@ -1371,7 +1371,7 @@ func (t *TenantStruct) DeleteProbe(w http.ResponseWriter, r *http.Request) {
//
// 删除应用探针
//
// delete probe **完成
// delete probe
//
// ---
// consumes:
@ -1436,7 +1436,7 @@ func (t *TenantStruct) UpdatePort(w http.ResponseWriter, r *http.Request) {
func (t *TenantStruct) SingleTenantResources(w http.ResponseWriter, r *http.Request) {
// swagger:operation GET /v2/tenants/{tenant_name}/resources v2 singletenantResources
//
// 指定租户资源使用情况 **完成
// 指定租户资源使用情况
//
// get tenant resources
//

View File

@ -79,7 +79,7 @@ func createEvent(eventID, serviceID, optType, tenantID, deployVersion string) (*
event.DeployVersion = version
event.OldDeployVersion = oldDeployVersion
status, err := checkCanAddEvent(serviceID,event.EventID)
status, err := checkCanAddEvent(serviceID, event.EventID)
if err != nil {
logrus.Errorf("error check event")
return nil, status, nil
@ -118,21 +118,21 @@ func autoTimeOut(event *dbmodel.ServiceEvent) {
}
}
}
func checkCanAddEvent(s ,eventID string) (int, error) {
func checkCanAddEvent(s, eventID string) (int, error) {
events, err := db.GetManager().ServiceEventDao().GetEventByServiceID(s)
if err != nil {
return 3, err
}
b,_:=json.Marshal(events)
logrus.Infof("get %d event from mysql by service %s,details is %s",len(events),s,string(b))
b, _ := json.Marshal(events)
logrus.Infof("get %d event from mysql by service %s,details is %s", len(events), s, string(b))
if len(events) == 0 {
//service 首个event
return 0, nil
}
latestEvent := events[0]
if latestEvent.EventID==eventID {
return 0,nil
if latestEvent.EventID == eventID {
return 0, nil
}
if latestEvent.FinalStatus == "" {
//未完成
@ -201,7 +201,7 @@ func handleStatus(status int, err error, w http.ResponseWriter, r *http.Request)
//
// 启动应用
//
// start service **完成
// start service
//
// ---
// consumes:
@ -259,7 +259,7 @@ func (t *TenantStruct) StartService(w http.ResponseWriter, r *http.Request) {
//
// 关闭应用
//
// stop service **完成
// stop service
//
// ---
// consumes:
@ -311,7 +311,7 @@ func (t *TenantStruct) StopService(w http.ResponseWriter, r *http.Request) {
//
// 重启应用
//
// restart service **完成
// restart service
//
// ---
// consumes:
@ -364,7 +364,7 @@ func (t *TenantStruct) RestartService(w http.ResponseWriter, r *http.Request) {
//
// 应用垂直伸缩
//
// service vertical **完成
// service vertical
//
// ---
// consumes:
@ -421,7 +421,7 @@ func (t *TenantStruct) VerticalService(w http.ResponseWriter, r *http.Request) {
//
// 应用水平伸缩
//
// service horizontal **完成
// service horizontal
//
// ---
// consumes:
@ -474,7 +474,7 @@ func (t *TenantStruct) HorizontalService(w http.ResponseWriter, r *http.Request)
//
// 应用构建
//
// service build **完成
// service build
//
// ---
// consumes:
@ -509,12 +509,12 @@ func (t *TenantStruct) BuildService(w http.ResponseWriter, r *http.Request) {
handleStatus(status, err, w, r)
//{\"tenant_name\":\"\",\"service_alias\":\"\",\"Body\":{\"event_id\":\"c19aa41c357a4d9e9ca38ab7f2a44961\",\"envs\":{},\"kind\":\"source\",\"action\":\"deploy\",\"image_url\":\"\",\"deploy_version\":\"20171122154417\",\"repo_url\":\"--branch master --depth 1 https://github.com/bay1ts/zk_cluster_mini.git\",\"operator\":\"bay1ts\",\"tenant_name\":\"bay1ts-test\",\"service_alias\":\"gr21ea6b\"}}
////createBuildInfo
version:=dbmodel.VersionInfo{}
version.EventID=sEvent.EventID
version.ServiceID=serviceID
version.RepoURL=build.Body.RepoURL
version.Kind=build.Body.Kind
version.BuildVersion=build.Body.DeployVersion
version := dbmodel.VersionInfo{}
version.EventID = sEvent.EventID
version.ServiceID = serviceID
version.RepoURL = build.Body.RepoURL
version.Kind = build.Body.Kind
version.BuildVersion = build.Body.DeployVersion
db.GetManager().VersionInfoDao().AddModel(&version)
//save
//version.DeliveredPath
@ -558,7 +558,7 @@ func (t *TenantStruct) DeployService(w http.ResponseWriter, r *http.Request) {
//
// 升级应用
//
// upgrade service **完成
// upgrade service
//
// ---
// consumes:
@ -613,7 +613,7 @@ func (t *TenantStruct) UpgradeService(w http.ResponseWriter, r *http.Request) {
//
// 应用代码检测
//
// check code **完成
// check code
//
// ---
// consumes:
@ -648,16 +648,13 @@ func (t *TenantStruct) CheckCode(w http.ResponseWriter, r *http.Request) {
httputil.ReturnSuccess(r, w, nil)
}
//ShareCloud 云市分享
func (t *TenantStruct) ShareCloud(w http.ResponseWriter, r *http.Request) {
// swagger:operation POST /v2/tenants/{tenant_name}/cloud-share v2 sharecloud
//
// 云市分享
//
// share cloud **完成
// share cloud
//
// ---
// consumes:
@ -695,7 +692,7 @@ func (t *TenantStruct) ShareCloud(w http.ResponseWriter, r *http.Request) {
//
// 应用版本回滚
//
// service rollback **完成
// service rollback
//
// ---
// consumes:

View File

@ -1,28 +1,28 @@
// RAINBOND, Application Management Platform
// Copyright (C) 2014-2017 Goodrain Co., Ltd.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version. For any non-GPL usage of Rainbond,
// one or multiple Commercial Licenses authorized by Goodrain Co., Ltd.
// must be obtained first.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package controller
import (
api_model "github.com/goodrain/rainbond/pkg/api/model"
"net/http"
api_model "github.com/goodrain/rainbond/pkg/api/model"
"github.com/Sirupsen/logrus"
"github.com/goodrain/rainbond/pkg/api/handler"
@ -36,7 +36,7 @@ type OpentsdbStruct struct{}
func (tsdb *OpentsdbStruct) TsdbQuery(w http.ResponseWriter, r *http.Request) {
// swagger:operation POST /v2/opentsdb/query v2 oentsdbquery
//
// 监控数据查询 **完成
// 监控数据查询
//
// query opentsdb
//

View File

@ -1,30 +1,30 @@
// RAINBOND, Application Management Platform
// Copyright (C) 2014-2017 Goodrain Co., Ltd.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version. For any non-GPL usage of Rainbond,
// one or multiple Commercial Licenses authorized by Goodrain Co., Ltd.
// must be obtained first.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package controller
import (
"github.com/goodrain/rainbond/pkg/api/handler"
"github.com/goodrain/rainbond/pkg/api/middleware"
"net/http"
"strings"
"github.com/goodrain/rainbond/pkg/api/handler"
"github.com/goodrain/rainbond/pkg/api/middleware"
api_model "github.com/goodrain/rainbond/pkg/api/model"
dbmodel "github.com/goodrain/rainbond/pkg/db/model"
httputil "github.com/goodrain/rainbond/pkg/util/http"
@ -49,7 +49,7 @@ func (t *TenantStruct) AddVolumeDependency(w http.ResponseWriter, r *http.Reques
//
// 增加应用持久化依赖
//
// add volume dependency **完成
// add volume dependency
//
// ---
// consumes:
@ -93,7 +93,7 @@ func (t *TenantStruct) DeleteVolumeDependency(w http.ResponseWriter, r *http.Req
//
// 删除应用持久化依赖
//
// delete volume dependency **完成
// delete volume dependency
//
// ---
// consumes:
@ -134,7 +134,7 @@ func (t *TenantStruct) AddVolume(w http.ResponseWriter, r *http.Request) {
//
// 增加应用持久化信息
//
// add volume **完成
// add volume
//
// ---
// consumes:
@ -181,7 +181,7 @@ func (t *TenantStruct) DeleteVolume(w http.ResponseWriter, r *http.Request) {
//
// 删除应用持久化信息
//
// delete volume **完成
// delete volume
//
// ---
// consumes:
@ -224,7 +224,7 @@ func AddVolumeDependency(w http.ResponseWriter, r *http.Request) {
//
// 增加应用持久化依赖(V2.1支持多种类型存储)
//
// add volume dependency **完成
// add volume dependency
//
// ---
// consumes:
@ -268,7 +268,7 @@ func DeleteVolumeDependency(w http.ResponseWriter, r *http.Request) {
//
// 删除应用持久化依赖(V2.1支持多种类型存储)
//
// delete volume dependency **完成
// delete volume dependency
//
// ---
// consumes:
@ -310,7 +310,7 @@ func AddVolume(w http.ResponseWriter, r *http.Request) {
//
// 增加应用持久化信息(V2.1支持多种类型存储)
//
// add volume **完成
// add volume
//
// ---
// consumes:
@ -357,7 +357,7 @@ func DeleteVolume(w http.ResponseWriter, r *http.Request) {
//
// 删除应用持久化信息(V2.1支持多种类型存储)
//
// delete volume **完成
// delete volume
//
// ---
// consumes:

View File

@ -322,7 +322,7 @@ type DeletePluginSetStruct struct {
}
//GetPluginEnvStruct GetPluginEnvStruct
//swagger:parameters getPluginEnv, getPluginDefaultEnv
//swagger:parameters getPluginEnv getPluginDefaultEnv
type GetPluginEnvStruct struct {
// in: path
// required: true