From f17afdf4084c893208c7c538bbad99c8a0009597 Mon Sep 17 00:00:00 2001 From: simonzhangsz Date: Fri, 18 Aug 2023 09:40:01 +0800 Subject: [PATCH] MML --- config/mml/omc/omc_mml_config.yaml | 138 +++++++++++++++++++++++++++- config/mml_map/http_mml_map.json | 35 ++++++- lib/dborm/dborm.go | 39 ++++++++ lib/mmlp/parse.go | 143 ++++++++++++++++++++++------- 4 files changed, 316 insertions(+), 39 deletions(-) diff --git a/config/mml/omc/omc_mml_config.yaml b/config/mml/omc/omc_mml_config.yaml index 308f2646..238061be 100644 --- a/config/mml/omc/omc_mml_config.yaml +++ b/config/mml/omc/omc_mml_config.yaml @@ -52,6 +52,9 @@ omc: filter: "" display: "NE ID" comment: "" + licenseManagement: + display: "License Management" + mml: - operation: "dsp" object: "licenseinfo" display: "Display NE License Information" @@ -127,11 +130,142 @@ omc: comment: "" - name: "number" alias: "dep_number" - type: "string" + type: "int" optional: "false" filter: "" display: "Deployment number" - comment: "" + comment: "" + - operation: "rel" + object: "license" + display: "Batch Release NE License" + params: + - name: "netype" + alias: "ne_type" + type: "string" + optional: "true" + apostr: "true" + loc: "true" + filter: "" + display: "NE type" + comment: "" + - name: "neid" + alias: "ne_id" + type: "string" + optional: "true" + apostr: "true" + loc: "true" + filter: "" + display: "NE ID" + comment: "" + - name: "capcity" + alias: "capcity" + type: "int" + optional: "false" + apostr: "false" + loc: "false" + filter: "" + display: "Release number" + comment: "" + - operation: "ins" + object: "license" + display: "Install NE License" + params: + - name: "netype" + alias: "ne_type" + type: "string" + optional: "false" + apostr: "true" + loc: "true" + filter: "" + display: "NE type" + comment: "" + - name: "neid" + alias: "ne_id" + type: "string" + optional: "false" + apostr: "true" + loc: "true" + filter: "" + display: "NE ID" + comment: "" + - name: "capcity" + alias: "capcity" + type: "int" + optional: "false" + loc: "false" + filter: "" + display: "Install number" + comment: "" + - operation: "adj" + object: "license" + display: "Adjustment NE License" + params: + - name: "netype" + alias: "ne_type" + type: "string" + optional: "true" + apostr: "true" + loc: "true" + filter: "" + display: "NE type" + comment: "" + - name: "neid" + alias: "ne_id" + type: "string" + optional: "true" + apostr: "true" + loc: "true" + filter: "" + display: "NE ID" + comment: "" + - name: "number" + alias: "number" + type: "int" + optional: "false" + loc: "false" + filter: "" + display: "Adjustment number" + comment: "" + - operation: "exp" + object: "license" + display: "Export NE License" + params: + - name: "netype" + alias: "ne_type" + type: "string" + optional: "true" + apostr: "true" + filter: "" + display: "NE type" + comment: "" + - name: "neid" + alias: "ne_id" + type: "string" + optional: "true" + apostr: "true" + filter: "" + display: "NE ID" + comment: "" + - operation: "uni" + object: "license" + display: "Uninstall NE License" + params: + - name: "netype" + alias: "ne_type" + type: "string" + optional: "false" + apostr: "true" + filter: "" + display: "NE type" + comment: "" + - name: "neid" + alias: "ne_id" + type: "string" + optional: "false" + apostr: "true" + filter: "" + display: "NE ID" + comment: "" - operation: "dsp" object: "nelink" display: "Display NE Interface Link Status" diff --git a/config/mml_map/http_mml_map.json b/config/mml_map/http_mml_map.json index 9d1d2e05..4882ddb4 100644 --- a/config/mml_map/http_mml_map.json +++ b/config/mml_map/http_mml_map.json @@ -783,8 +783,8 @@ "length": 12 }, { - "name": "capability", - "display": "License capability", + "name": "capcity", + "display": "License capcity", "length": 11 }, { @@ -941,4 +941,35 @@ "bodyFmt": "PutDB", "bodyKey": "ne_license", "callFunc": "DeploymentLicense" +} + +{ + "bodyFmt": "PutDB", + "bodyKey": "ne_license", + "callFunc": "AdjustmentLicense" +} + +{ + "bodyFmt": "PutDB", + "bodyKey": "ne_license", + "callFunc": "InstallLicense" +} + +{ + "bodyFmt": "PutDB", + "bodyKey": "ne_license", + "cols": [ + { + "name": "updated_at", + "alias": "updated_at", + "type": "string", + "length": 20, + "value": "2023-08-17 23:38:53" + } + ] +} + +{ + "bodyFmt": "PutDB", + "bodyKey": "ne_license" } \ No newline at end of file diff --git a/lib/dborm/dborm.go b/lib/dborm/dborm.go index 07509f57..8fef7730 100644 --- a/lib/dborm/dborm.go +++ b/lib/dborm/dborm.go @@ -1499,3 +1499,42 @@ func IsPermissionAllowed(token, method, dbname, tbname string) (bool, error) { return exist, nil } + +type NeLicense struct { + NeType string `json:"neType" xorm:"ne_type"` + NeID string `json:"neID" xorm:"ne_id"` + Capability int `json:"capability"` +} + +func XormAdjustmentNeLicense(neType, neID string, value int) (int64, error) { + //neLicense := NeLicense{NeType: neType, NeID: neID, Capability: value} + // session.LogoutTime.Valid = true + // session.LogoutTime.Time = time.Now() + res, err := xEngine.Exec("update ne_license set capcity=capcity+? where IFNULL(ne_type, '')=? and IFNULL(ne_id, '')=?", value, neType, neID) + // defer xSession.Close() + + //affected, err := xSession.Table("ne_license").Where("ne_type=? and ne_id=?", neType, neID).Update(&neLicense) + + // //affected, err := xSession.Table("ne_license").SQL("ne_tye=? and ne_id=?", neType, neID).Update(session) + // err := xSession.SQL("update ne_license set capability=capability+? where ne_type=? and ne_id=?", value, neType, neID) + //xSession.Commit() + affected, err := res.RowsAffected() + return affected, err +} + +func XormUpdateNeLicense(neType, neID string, capcity int) (int64, error) { + var err error + var res sql.Result + if neType != "" && neID != "" { + res, err = xEngine.Exec("update ne_license set capcity=? where ne_type=? and ne_id=?", capcity, neType, neID) + } else if neType != "" && neID == "" { + res, err = xEngine.Exec("update ne_license set capcity=? where ne_type=?", capcity, neType) + } else if neType == "" && neID != "" { + res, err = xEngine.Exec("update ne_license set capcity=? where ne_id=?", capcity, neID) + } else { + res, err = xEngine.Exec("update ne_license set capcity=?", capcity) + } + + affected, err := res.RowsAffected() + return affected, err +} diff --git a/lib/mmlp/parse.go b/lib/mmlp/parse.go index 760da94a..b9f18d3e 100644 --- a/lib/mmlp/parse.go +++ b/lib/mmlp/parse.go @@ -330,31 +330,100 @@ func parseRequestUri(httpUri string, mmlMap *dborm.MmlHttpMap, mml *MmlCommand) return requestURI } -// func DeploymentLicense(mml *MmlCommand, requestURI, token, agent string) { -// client := resty.New() -// srcLicDep := &struct { -// NeType string `json:"ne_type"` -// NeID string `json:"ne_id"` -// Capability string `json:"capability"` -// }{ -// NeType: fmt.Sprintf("%v", mml.NaMap["srcnetype"]), -// NeID: fmt.Sprintf("%v", mml.NaMap["srcneid"]), -// Capability: capability - strconv.Atoi(fmt.Sprintf("%v", mml.NaMap["number"])), -// } -// response, err := client.R(). -// EnableTrace(). -// SetHeaders(map[string]string{"accessToken": token}). -// SetHeaders(map[string]string{"User-Agent": agent}). -// SetHeaders(map[string]string{"Content-Type": "application/json;charset=UTF-8"}). -// SetBody(*body). -// Put(requestURI) -// if err != nil { -// log.Error("Failed to Put:", err) -// output = ParseErrorOutput(err) -// } else { -// output = ParseOutputResponse(omcMmlVar, outputJson, response) -// } -// } +func DeploymentLicense(mml *MmlCommand, omcMmlVar *MmlVar, outputJson *dborm.MmlOutput) *[]byte { + var output []byte + log.Debug("mml:", mml) + var srcNeType, srcNeid, dstNeType, dstNeId, value string + for _, Param := range mml.Params { + switch Param.Name { + case "srcnetype": + srcNeType = Param.Value + case "srcneid": + srcNeid = Param.Value + case "dstnetype": + dstNeType = Param.Value + case "dstneid": + dstNeId = Param.Value + case "number": + value = Param.Value + } + } + intValue, _ := strconv.Atoi(value) + log.Debugf("srcNeType:%s, srcNeid:%s dstNeType:%s dstNeId:%s intValue:%d", srcNeType, srcNeid, dstNeType, dstNeId, intValue) + a1, err := dborm.XormAdjustmentNeLicense(srcNeType, srcNeid, intValue) + if err != nil { + log.Error("Failed to Put:", err) + } + + a2, err := dborm.XormAdjustmentNeLicense(dstNeType, dstNeId, -intValue) + if err != nil { + log.Error("Failed to Put:", err) + output = *ParseErrorOutput(err) + } else { + //response := &resty.Response{StatusCode: http.StatusOK} + //output = ParseOutputResponse(omcMmlVar, outputJson, response.) + str := fmt.Sprintf("RetCode = 0 operation succeeded\n\nAffected rows = %d \n\n", a1+a2) + output = []byte(str) + } + + return &output +} + +func AdjustmentLicense(mml *MmlCommand, omcMmlVar *MmlVar, outputJson *dborm.MmlOutput) *[]byte { + var output []byte + log.Debug("mml:", mml) + var neType, neid, number string + for _, Param := range mml.Params { + switch Param.Name { + case "netype": + neType = Param.Value + case "neid": + neid = Param.Value + case "number": + number = Param.Value + } + } + intValue, _ := strconv.Atoi(number) + log.Debugf("neType:%s, neid:%s intValue:%d", neType, neid, intValue) + affected, err := dborm.XormAdjustmentNeLicense(neType, neid, intValue) + if err != nil { + log.Error("Failed to XormAdjustmentNeLicense:", err) + output = *ParseErrorOutput(err) + } else { + str := fmt.Sprintf("RetCode = 0 operation succeeded\n\nAffected rows = %d \n\n", affected) + output = []byte(str) + } + + return &output +} + +func InstallLicense(mml *MmlCommand, omcMmlVar *MmlVar, outputJson *dborm.MmlOutput) *[]byte { + var output []byte + log.Debug("mml:", mml) + var neType, neid, number string + for _, Param := range mml.Params { + switch Param.Name { + case "netype": + neType = Param.Value + case "neid": + neid = Param.Value + case "number": + number = Param.Value + } + } + intValue, _ := strconv.Atoi(number) + log.Debugf("neType:%s, neid:%s intValue:%d", neType, neid, intValue) + affected, err := dborm.XormUpdateNeLicense(neType, neid, intValue) + if err != nil { + log.Error("Failed to XormUpdateNeLicense:", err) + output = *ParseErrorOutput(err) + } else { + str := fmt.Sprintf("RetCode = 0 operation succeeded\n\nAffected rows = %d \n\n", affected) + output = []byte(str) + } + + return &output +} func TransMml2HttpReq(omcMmlVar *MmlVar, mml *MmlCommand) (*[]byte, error) { log.Info("TransMml2HttpReq processing ...") @@ -431,18 +500,22 @@ func TransMml2HttpReq(omcMmlVar *MmlVar, mml *MmlCommand) (*[]byte, error) { output = ParseOutputResponse(omcMmlVar, outputJson, response) } case "put": + switch inputJson.CallFunc { + case "DeploymentLicense": + output = DeploymentLicense(mml, omcMmlVar, outputJson) + return output, nil + case "AdjustmentLicense": + output = AdjustmentLicense(mml, omcMmlVar, outputJson) + return output, nil + case "InstallLicense": + output = InstallLicense(mml, omcMmlVar, outputJson) + return output, nil + default: + } + requestURI = parseRequestUri(omcMmlVar.HttpUri, mmlMap, mml) - body := ParseInputBody(inputJson, mml) log.Debugf("method: Put requestURI: %s", requestURI) - - // switch inputJson.CallFunc { - // case "DeploymentLicense": - // DeploymentLicense(inputJson, requestURI, omcMmlVar) - // //output = ParseOutputResponse(inputJson, outputJson, response) - // return output, nil - // default: - // } - + body := ParseInputBody(inputJson, mml) response, err := client.R(). EnableTrace(). SetHeaders(map[string]string{"accessToken": omcMmlVar.SessionToken}).