数据上链
This commit is contained in:
parent
0fc6084c42
commit
acb3f7c33a
|
@ -36,6 +36,13 @@ type Config struct {
|
||||||
OpenstackRpcConf zrpc.RpcClientConf
|
OpenstackRpcConf zrpc.RpcClientConf
|
||||||
OctopusRpcConf zrpc.RpcClientConf
|
OctopusRpcConf zrpc.RpcClientConf
|
||||||
PcmCoreRpcConf zrpc.RpcClientConf
|
PcmCoreRpcConf zrpc.RpcClientConf
|
||||||
|
BlockChain struct {
|
||||||
|
ContractAddress string
|
||||||
|
FunctionName string
|
||||||
|
Url string
|
||||||
|
Type string
|
||||||
|
MemberName string
|
||||||
|
}
|
||||||
|
|
||||||
MinioConf struct {
|
MinioConf struct {
|
||||||
Secret string
|
Secret string
|
||||||
|
|
|
@ -11,10 +11,12 @@ import (
|
||||||
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/models"
|
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/models"
|
||||||
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/models/cloud"
|
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/models/cloud"
|
||||||
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/utils"
|
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/utils"
|
||||||
|
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/utils/remoteUtil"
|
||||||
"io"
|
"io"
|
||||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
syaml "k8s.io/apimachinery/pkg/runtime/serializer/yaml"
|
syaml "k8s.io/apimachinery/pkg/runtime/serializer/yaml"
|
||||||
|
"k8s.io/apimachinery/pkg/util/json"
|
||||||
kyaml "k8s.io/apimachinery/pkg/util/yaml"
|
kyaml "k8s.io/apimachinery/pkg/util/yaml"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -55,7 +57,6 @@ func (l *CommitGeneralTaskLogic) CommitGeneralTask(req *types.GeneralTaskReq) er
|
||||||
logx.Info("commit success")
|
logx.Info("commit success")
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
//TODO adapter
|
|
||||||
adapterId, _ := strconv.ParseUint(req.AdapterIds[0], 10, 64)
|
adapterId, _ := strconv.ParseUint(req.AdapterIds[0], 10, 64)
|
||||||
var clusters []*models.CloudModel
|
var clusters []*models.CloudModel
|
||||||
err := tx.Raw("SELECT * FROM `t_cluster` where adapter_id in ? and id in ?", req.AdapterIds, req.ClusterIds).Scan(&clusters).Error
|
err := tx.Raw("SELECT * FROM `t_cluster` where adapter_id in ? and id in ?", req.AdapterIds, req.ClusterIds).Scan(&clusters).Error
|
||||||
|
@ -131,6 +132,19 @@ func (l *CommitGeneralTaskLogic) CommitGeneralTask(req *types.GeneralTaskReq) er
|
||||||
db := tx.Table("task").Create(&taskModel)
|
db := tx.Table("task").Create(&taskModel)
|
||||||
db = tx.Table("task_cloud").Create(&taskClouds)
|
db = tx.Table("task_cloud").Create(&taskClouds)
|
||||||
db = tx.Table("t_notice").Create(¬iceInfo)
|
db = tx.Table("t_notice").Create(¬iceInfo)
|
||||||
|
// 数据上链
|
||||||
|
bytes, err := json.Marshal(taskModel)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
remoteUtil.Evidence(remoteUtil.EvidenceParam{
|
||||||
|
Url: l.svcCtx.Config.BlockChain.Url,
|
||||||
|
ContractAddress: l.svcCtx.Config.BlockChain.ContractAddress,
|
||||||
|
FunctionName: l.svcCtx.Config.BlockChain.FunctionName,
|
||||||
|
MemberName: l.svcCtx.Config.BlockChain.MemberName,
|
||||||
|
Type: l.svcCtx.Config.BlockChain.Type,
|
||||||
|
Args: []string{strconv.FormatInt(taskModel.Id, 10), string(bytes)},
|
||||||
|
})
|
||||||
if db.Error != nil {
|
if db.Error != nil {
|
||||||
logx.Errorf("Task creation failure, err: %v", db.Error)
|
logx.Errorf("Task creation failure, err: %v", db.Error)
|
||||||
return errors.New("task creation failure")
|
return errors.New("task creation failure")
|
||||||
|
|
|
@ -6,7 +6,9 @@ import (
|
||||||
"github.com/go-resty/resty/v2"
|
"github.com/go-resty/resty/v2"
|
||||||
clientCore "gitlink.org.cn/JointCloud/pcm-coordinator/client"
|
clientCore "gitlink.org.cn/JointCloud/pcm-coordinator/client"
|
||||||
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/models"
|
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/models"
|
||||||
|
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/utils/remoteUtil"
|
||||||
v1 "gitlink.org.cn/JointCloud/pcm-hpc/routers/v1"
|
v1 "gitlink.org.cn/JointCloud/pcm-hpc/routers/v1"
|
||||||
|
"k8s.io/apimachinery/pkg/util/json"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -116,7 +118,16 @@ func (l *CommitHpcTaskLogic) CommitHpcTask(req *types.CommitHpcTaskReq) (resp *t
|
||||||
resp = &types.CommitHpcTaskResp{
|
resp = &types.CommitHpcTaskResp{
|
||||||
JobId: string(jobId),
|
JobId: string(jobId),
|
||||||
}
|
}
|
||||||
|
// 数据上链
|
||||||
|
bytes, _ := json.Marshal(taskModel)
|
||||||
|
remoteUtil.Evidence(remoteUtil.EvidenceParam{
|
||||||
|
Url: l.svcCtx.Config.BlockChain.Url,
|
||||||
|
ContractAddress: l.svcCtx.Config.BlockChain.ContractAddress,
|
||||||
|
FunctionName: l.svcCtx.Config.BlockChain.FunctionName,
|
||||||
|
MemberName: l.svcCtx.Config.BlockChain.MemberName,
|
||||||
|
Type: l.svcCtx.Config.BlockChain.Type,
|
||||||
|
Args: []string{strconv.FormatInt(taskModel.Id, 10), string(bytes)},
|
||||||
|
})
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,22 +35,22 @@ type (
|
||||||
}
|
}
|
||||||
|
|
||||||
Task struct {
|
Task struct {
|
||||||
Id int64 `db:"id"` // id
|
Id int64 `db:"id" json:"id"` // id
|
||||||
Name string `db:"name"` // 作业名称
|
Name string `db:"name" json:"name"` // 作业名称
|
||||||
Description string `db:"description"` // 作业描述
|
Description string `db:"description" json:"description"` // 作业描述
|
||||||
Status string `db:"status"` // 作业状态
|
Status string `db:"status" json:"status"` // 作业状态
|
||||||
Strategy int64 `db:"strategy"` // 策略
|
Strategy int64 `db:"strategy" json:"strategy"` // 策略
|
||||||
SynergyStatus int64 `db:"synergy_status"` // 协同状态(0-未协同、1-已协同)
|
SynergyStatus int64 `db:"synergy_status" json:"synergyStatus"` // 协同状态(0-未协同、1-已协同)
|
||||||
CommitTime time.Time `db:"commit_time"` // 提交时间
|
CommitTime time.Time `db:"commit_time" json:"commitTime"` // 提交时间
|
||||||
StartTime *time.Time `db:"start_time"` // 开始时间
|
StartTime *time.Time `db:"start_time" json:"startTime"` // 开始时间
|
||||||
EndTime *time.Time `db:"end_time"` // 结束运行时间
|
EndTime *time.Time `db:"end_time" json:"endTime"` // 结束运行时间
|
||||||
RunningTime int64 `db:"running_time"` // 已运行时间(单位秒)
|
RunningTime int64 `db:"running_time" json:"runningTime"` // 已运行时间(单位秒)
|
||||||
YamlString string `db:"yaml_string"`
|
YamlString string `db:"yaml_string" json:"yamlString"`
|
||||||
Result string `db:"result"` // 作业结果
|
Result string `db:"result" json:"result"` // 作业结果
|
||||||
DeletedAt gorm.DeletedAt `gorm:"index"`
|
DeletedAt gorm.DeletedAt `gorm:"index" json:"deletedAt"`
|
||||||
NsID string `db:"ns_id"`
|
NsID string `db:"ns_id" json:"nsID"`
|
||||||
AdapterTypeDict string `db:"adapter_type_dict"` //任务类型(对应字典表的值)
|
AdapterTypeDict string `db:"adapter_type_dict" json:"adapterTypeDict"` //任务类型(对应字典表的值)
|
||||||
TaskTypeDict string `db:"task_type_dict"`
|
TaskTypeDict string `db:"task_type_dict" json:"taskTypeDict"`
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
package remoteUtil
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/go-resty/resty/v2"
|
||||||
|
)
|
||||||
|
|
||||||
|
type EvidenceParam struct {
|
||||||
|
Url string `json:"url"`
|
||||||
|
Type string `json:"type"`
|
||||||
|
MemberName string `json:"memberName"`
|
||||||
|
ContractAddress string `json:"contractAddress"`
|
||||||
|
FunctionName string `json:"functionName"`
|
||||||
|
Args []string `json:"args"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func Evidence(EvidenceParam EvidenceParam) error {
|
||||||
|
httpClient := resty.New().R()
|
||||||
|
_, err := httpClient.SetHeader("Content-Type", "application/json").
|
||||||
|
SetBody(&EvidenceParam).
|
||||||
|
Post(EvidenceParam.Url)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
Loading…
Reference in New Issue