Skip to content

Commit

Permalink
Merge pull request #1268 from WeBankPartners/dev
Browse files Browse the repository at this point in the history
Release v2.0.3
  • Loading branch information
pobu168 authored Aug 20, 2021
2 parents 023f5d9 + d73c880 commit 22d0c7d
Show file tree
Hide file tree
Showing 32 changed files with 1,024 additions and 157 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM alpine
FROM ccr.ccs.tencentyun.com/webankpartners/alpine-base:v1.0

ENV BASE_HOME=/app/cmdb

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
current_dir=$(shell pwd)
version=$(PLUGIN_VERSION)
project_dir=$(shell basename "${current_dir}")
project_name=wecmdb-pro
project_name=wecmdb

clean:
rm -rf cmdb-server/cmdb-server
Expand Down
3 changes: 2 additions & 1 deletion build/register.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
<systemParameter name="WECMDB_RESOURCE_SET" scopeType="global" defaultValue="resource_set"/>
<systemParameter name="WECMDB_KEEP_DATA_MODEL_SYNC" scopeType="global" defaultValue="false"/>
<systemParameter name="WECMDB_LOG_LEVEL" scopeType="global" defaultValue="info"/>
<systemParameter name="WECMDB_PROCESS_TAGS" scopeType="global" defaultValue="cmdb"/>
</systemParameters>


Expand All @@ -57,7 +58,7 @@
containerName="{{REPOSITORY}}-{{PLUGIN_VERSION}}"
portBindings="{{ALLOCATE_PORT}}:8096"
volumeBindings="{{BASE_MOUNT_PATH}}/wecmdb/log:/app/cmdb/logs,/etc/localtime:/etc/localtime,{{BASE_MOUNT_PATH}}/certs:/data/certs"
envVariables="CMDB_MYSQL_HOST={{DB_HOST}},CMDB_MYSQL_PORT={{DB_PORT}},CMDB_MYSQL_SCHEMA={{DB_SCHEMA}},CMDB_MYSQL_USER={{DB_USER}},CMDB_MYSQL_PWD={{DB_PWD}},JWT_SIGNING_KEY={{JWT_SIGNING_KEY}},GATEWAY_URL={{GATEWAY_URL}},SUB_SYSTEM_CODE={{SUB_SYSTEM_CODE}},SUB_SYSTEM_KEY={{SUB_SYSTEM_KEY}},CMDB_LOG_LEVEL={{WECMDB_LOG_LEVEL}},PLUGIN_MODE=yes"
envVariables="CMDB_MYSQL_HOST={{DB_HOST}},CMDB_MYSQL_PORT={{DB_PORT}},CMDB_MYSQL_SCHEMA={{DB_SCHEMA}},CMDB_MYSQL_USER={{DB_USER}},CMDB_MYSQL_PWD={{DB_PWD}},JWT_SIGNING_KEY={{JWT_SIGNING_KEY}},GATEWAY_URL={{GATEWAY_URL}},SUB_SYSTEM_CODE={{SUB_SYSTEM_CODE}},SUB_SYSTEM_KEY={{SUB_SYSTEM_KEY}},CMDB_LOG_LEVEL={{WECMDB_LOG_LEVEL}},PLUGIN_MODE=yes,WECMDB_PROCESS_TAGS={{WECMDB_PROCESS_TAGS}}"
/>
<mysql schema="wecmdb_pro" initFileName="init.sql" upgradeFileName="upgrade.sql"/>
</resourceDependencies>
Expand Down
2 changes: 2 additions & 0 deletions cmdb-server/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ func init() {
&handlerFuncObj{Url: "/ci-data/reference-data/query/:ciAttr", Method: "POST", HandlerFunc: ci.DataReferenceQuery},
&handlerFuncObj{Url: "/ci-data/rollback/query/:guid", Method: "GET", HandlerFunc: ci.DataRollbackList},
&handlerFuncObj{Url: "/ci-data/query-password/:ciType/:guid/:field", Method: "GET", HandlerFunc: ci.DataPasswordQuery},
&handlerFuncObj{Url: "/ci-data/callback/process/:ciType/:guid", Method: "GET", HandlerFunc: ci.GetCiDataVariableCallback},
&handlerFuncObj{Url: "/ci-data/action-query/:operation/:ciType/:guid", Method: "GET", HandlerFunc: ci.GetActionQueryData},
)
// log
httpHandlerFuncList = append(httpHandlerFuncList,
Expand Down
2 changes: 1 addition & 1 deletion cmdb-server/api/v1/ci/ci_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func DataReferenceQuery(c *gin.Context) {

func DataRollbackList(c *gin.Context) {
guid := c.Param("guid")
resultData, err := db.DataRollbackList(guid)
resultData, _, err := db.DataRollbackList(guid)
if err != nil {
middleware.ReturnServerHandleError(c, err)
} else {
Expand Down
54 changes: 54 additions & 0 deletions cmdb-server/api/v1/ci/ci_data_callback.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package ci

import (
"fmt"
"github.com/WeBankPartners/we-cmdb/cmdb-server/api/middleware"
"github.com/WeBankPartners/we-cmdb/cmdb-server/models"
"github.com/WeBankPartners/we-cmdb/cmdb-server/services/db"
"github.com/gin-gonic/gin"
"strings"
)

func GetCiDataVariableCallback(c *gin.Context) {
ciType := c.Param("ciType")
rowGuid := c.Param("guid")
if ciType == "" || rowGuid == "" {
middleware.ReturnParamValidateError(c, fmt.Errorf("Param ciType and guid can not empty "))
return
}
result, err := db.ListCiDataVariableCallback(ciType, rowGuid)
if err != nil {
middleware.ReturnServerHandleError(c, err)
} else {
middleware.ReturnData(c, result)
}
}

func GetActionQueryData(c *gin.Context) {
operation := c.Param("operation")
ciType := c.Param("ciType")
rowGuid := c.Param("guid")
if operation == "" || ciType == "" || rowGuid == "" {
middleware.ReturnParamValidateError(c, fmt.Errorf("Url param illegal "))
return
}
var err error
result := models.CiDataActionQuery{}
tmpOperation := strings.ToLower(operation)
if tmpOperation == "rollback" {
queryData, title, rollbackErr := db.DataRollbackList(rowGuid)
if rollbackErr != nil {
middleware.ReturnServerHandleError(c, rollbackErr)
return
}
result.Data = queryData
result.Title = title
} else {
result, err = db.GetCallbackQueryData(ciType, rowGuid)
if err != nil {
middleware.ReturnServerHandleError(c, err)
return
}
}
middleware.ReturnData(c, result)
}
87 changes: 87 additions & 0 deletions cmdb-server/models/ci_data_callback.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package models

import "time"

type SysWecubeProcessTable struct {
Guid string `json:"guid"`
CiDataGuid string `json:"ci_data_guid"`
WecubeProcInstanceTmp string `json:"wecube_proc_instance_tmp"`
WecubeProcInstance string `json:"wecube_proc_instance"`
WecubeProcDefine string `json:"wecube_proc_define"`
Status string `json:"status"`
UpdateTime time.Time `json:"update_time"`
}

type CoreProcessQueryResponse struct {
Status string `json:"status"`
Message string `json:"message"`
Data []*CodeProcessQueryObj `json:"data"`
}

type CodeProcessQueryObj struct {
ExcludeMode string `json:"excludeMode"`
ProcDefId string `json:"procDefId"`
ProcDefKey string `json:"procDefKey"`
ProcDefName string `json:"procDefName"`
ProcDefVersion string `json:"procDefVersion"`
RootEntity string `json:"rootEntity"`
Status string `json:"status"`
CreatedTime string `json:"createdTime"`
CreatedUnixTime int64 `json:"-"`
Tags string `json:"tags"`
}

type CoreProcessRequest struct {
EventSeqNo string `json:"eventSeqNo"`
EventType string `json:"eventType"`
SourceSubSystem string `json:"sourceSubSystem"`
OperationKey string `json:"operationKey"`
OperationData string `json:"operationData"`
NotifyRequired string `json:"notifyRequired"`
NotifyEndpoint string `json:"notifyEndpoint"`
OperationUser string `json:"operationUser"`
OperationMode string `json:"operationMode"`
}

type CoreStartProcess struct {
Status string `json:"status"`
Message string `json:"message"`
Data CoreStartProcessData `json:"data"`
}

type CoreStartProcessData struct {
ProcInstId string `json:"procInstId"`
Status string `json:"status"`
TaskNodeInstances []*CoreStartProcessData `json:"taskNodeInstances"`
}

type CoreProcessResult struct {
Status string `json:"status"`
Message string `json:"message"`
Data CoreProcessResultData `json:"data"`
}

type CoreProcessResultData struct {
ProcInstId int `json:"procInstId"`
Status string `json:"status"`
TaskNodeInstances []*CoreProcessResultData `json:"taskNodeInstances"`
}

type CiDataCallbackParam struct {
CiType string `json:"ciType"`
RowGuid string `json:"rowGuid"`
ProcessKey string `json:"processKey"`
ProcessName string `json:"processName"`
OperationUser string `json:"operationUser"`
}

type CiDataActionQuery struct {
Title []*CiDataActionQueryTitle `json:"title"`
Data []map[string]interface{} `json:"data"`
Selectable bool `json:"selectable"`
}

type CiDataActionQueryTitle struct {
Id string `json:"key"`
Name string `json:"title"`
}
2 changes: 2 additions & 0 deletions cmdb-server/models/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ var (
PluginRunningMode bool
CoreToken *token.CoreToken
MenuApiGlobalList []*MenuApiMapObj
ProcessFetchTabs string
)

func InitConfig(configFile string) (errMessage string) {
Expand Down Expand Up @@ -120,6 +121,7 @@ func InitConfig(configFile string) (errMessage string) {
tmpCoreToken.SubSystemKey = Config.Wecube.SubSystemKey
tmpCoreToken.InitCoreToken()
CoreToken = &tmpCoreToken
ProcessFetchTabs = os.Getenv("WECMDB_PROCESS_TAGS")
} else {
PluginRunningMode = false
}
Expand Down
39 changes: 32 additions & 7 deletions cmdb-server/services/db/ci_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,9 @@ func doActionFunc(param *models.ActionFuncParam) (result []*execAction, err erro
case "delete":
result, err = deleteActionFunc(param)
break
case "execute":
result, err = executeActionFunc(param)
break
default:
err = fmt.Errorf("Action:%s can not support ", param.Transition.Action)
}
Expand Down Expand Up @@ -455,7 +458,7 @@ func updateActionFunc(param *models.ActionFuncParam) (result []*execAction, err
for _, multiRefColumn := range multiRefColumnList {
delete(param.InputData, multiRefColumn)
}
if !rollbackFlag {
if !rollbackFlag && param.BareAction == "" {
columnList = append(columnList, &models.CiDataColumnObj{ColumnName: "confirm_time", ColumnValue: "reset_null^"})
param.InputData["confirm_time"] = "reset_null^"
} else if param.InputData["confirm_time"] != "" {
Expand All @@ -465,7 +468,7 @@ func updateActionFunc(param *models.ActionFuncParam) (result []*execAction, err
result = append(result, getUpdateActionByColumnList(columnList, param.CiType, param.InputData["guid"]))
result = append(result, getHistoryActionByData(param.InputData, param.CiType, param.NowTime, param.Transition))
}
if !rollbackFlag {
if !rollbackFlag && param.BareAction == "" {
param.InputData["confirm_time"] = ""
}
return
Expand Down Expand Up @@ -553,6 +556,22 @@ func deleteActionFunc(param *models.ActionFuncParam) (result []*execAction, err
return
}

func executeActionFunc(param *models.ActionFuncParam) (result []*execAction, err error) {
var columnList []*models.CiDataColumnObj
for _, ciAttr := range param.Attributes {
if ciAttr.Name == "state" {
param.NowData["state"] = param.Transition.TargetStateName
columnList = append(columnList, &models.CiDataColumnObj{ColumnName: "state", ColumnValue: param.Transition.TargetStateName})
break
}
}
param.NowData = cleanInputData(param.NowData, param.Attributes)
result = append(result, getUpdateActionByColumnList(columnList, param.CiType, param.InputData["guid"]))
result = append(result, getHistoryActionByData(param.NowData, param.CiType, param.NowTime, param.Transition))
err = StartCiDataCallback(models.CiDataCallbackParam{RowGuid: param.InputData["guid"], ProcessName: param.InputData["procDefName"], ProcessKey: param.InputData["procDefKey"], CiType: param.CiType})
return
}

func autofillAffectActionFunc(ciTypeId, guid, nowTime string) {
// get attribute
var attrTable []*models.SysCiTypeAttrTable
Expand Down Expand Up @@ -1448,7 +1467,6 @@ func buildMultiRefActions(param *models.BuildAttrValueParam) (actions []*execAct
}
valueList := []string{}
if strings.Contains(inputValue, "[") {
valueList := []string{}
err = json.Unmarshal([]byte(inputValue), &valueList)
if err != nil {
err = fmt.Errorf("Format multiRef value to []string fail,%s ", err.Error())
Expand Down Expand Up @@ -1590,7 +1608,7 @@ func recursiveAttrAutofill(afList []*models.AttrAutofillSortObj, af *models.Attr
return
}

func DataRollbackList(inputGuid string) (rowData []map[string]interface{}, err error) {
func DataRollbackList(inputGuid string) (rowData []map[string]interface{}, title []*models.CiDataActionQueryTitle, err error) {
ciTypeId := inputGuid[:len(inputGuid)-len(guid.CreateGuid())-1]
queryParam := models.QueryRequestParam{}
queryParam.Dialect = &models.QueryRequestDialect{QueryMode: "all"}
Expand All @@ -1601,7 +1619,8 @@ func DataRollbackList(inputGuid string) (rowData []map[string]interface{}, err e
return
}
if len(rowData) == 0 {
err = fmt.Errorf("Can not find any data with guid:%s ", inputGuid)
//err = fmt.Errorf("Can not find any data with guid:%s ", inputGuid)
rowData = []map[string]interface{}{}
return
}
if rowData[len(rowData)-1]["history_state_confirmed"].(string) == "1" {
Expand All @@ -1610,7 +1629,7 @@ func DataRollbackList(inputGuid string) (rowData []map[string]interface{}, err e
}
if len(rowData) < 2 {
//err = fmt.Errorf("Can not find any history data with guid:%s ", inputGuid)
return rowData, nil
return rowData, title, nil
}
var newRowData []map[string]interface{}
for i := len(rowData) - 2; i > 0; i-- {
Expand All @@ -1621,7 +1640,13 @@ func DataRollbackList(inputGuid string) (rowData []map[string]interface{}, err e
newRowData = append(newRowData, rowData[i])
}
}
return newRowData, nil
title = []*models.CiDataActionQueryTitle{}
var attrs []*models.SysCiTypeAttrTable
x.SQL("select name,display_name from sys_ci_type_attr where display_by_default='yes' and ci_type=? order by ui_form_order", ciTypeId).Find(&attrs)
for _, attr := range attrs {
title = append(title, &models.CiDataActionQueryTitle{Id: attr.Name, Name: attr.DisplayName})
}
return newRowData, title, nil
}

func cleanInputData(inputData models.CiDataMapObj, attrs []*models.SysCiTypeAttrTable) models.CiDataMapObj {
Expand Down
Loading

0 comments on commit 22d0c7d

Please sign in to comment.