diff --git a/cmd.pb.go b/cmd.pb.go index c6206ae..265ff85 100644 --- a/cmd.pb.go +++ b/cmd.pb.go @@ -25,19 +25,22 @@ const ( type UserIdType int32 const ( - UserIdType_DEVICEID UserIdType = 0 // 设备号 - UserIdType_OPENID UserIdType = 1 // OpenId + UserIdType_DEVICEID UserIdType = 0 // 设备号 + UserIdType_OPENID UserIdType = 1 // OpenId + UserIdType_INNERID1 UserIdType = 10 // 内部ID1 ) // Enum value maps for UserIdType. var ( UserIdType_name = map[int32]string{ - 0: "DEVICEID", - 1: "OPENID", + 0: "DEVICEID", + 1: "OPENID", + 10: "INNERID1", } UserIdType_value = map[string]int32{ "DEVICEID": 0, "OPENID": 1, + "INNERID1": 10, } ) @@ -74,7 +77,7 @@ type ErrorCode int32 const ( ErrorCode_SUCC ErrorCode = 0 // 成功 ErrorCode_INVALID_ACCOUNT ErrorCode = 101 // Account不合法 - ErrorCode_INVALID_TIMESTAMP ErrorCode = 102 // 头信息缺少时间戳 + ErrorCode_INVALID_TIMESTAMP ErrorCode = 102 // 头信息缺少时间戳或不正确 ErrorCode_INVALID_SIGNATURE ErrorCode = 103 // 头信息缺少签名 ErrorCode_AUTH_FAIL ErrorCode = 104 // 签名较验失败 ErrorCode_DISABLED_ACCOUNT ErrorCode = 105 // 账号已禁用 @@ -84,6 +87,13 @@ const ( ErrorCode_QPS_LIMIT ErrorCode = 113 // 并发请求量超限 ErrorCode_CMDS_LIMIT ErrorCode = 114 // 命令数量超限 ErrorCode_CMDS_NULL ErrorCode = 115 // 命令为空 + ErrorCode_TASK_EXISTS ErrorCode = 120 // 任务已存在 + ErrorCode_TASK_IS_NOT_EXISTS ErrorCode = 121 // 任务不存在 + ErrorCode_TASK_NUM_LIMIT ErrorCode = 122 // 任务数达到上限 + ErrorCode_TASK_BLOCK_SIZE ErrorCode = 123 // 块大小超限 + ErrorCode_TASK_TOTAL_SIZE ErrorCode = 124 // 总文件大小超限 + ErrorCode_TASK_MARSHAL ErrorCode = 125 // 序列化 + ErrorCode_DATA_ERROR ErrorCode = 201 // 数据错误 ) // Enum value maps for ErrorCode. @@ -101,6 +111,13 @@ var ( 113: "QPS_LIMIT", 114: "CMDS_LIMIT", 115: "CMDS_NULL", + 120: "TASK_EXISTS", + 121: "TASK_IS_NOT_EXISTS", + 122: "TASK_NUM_LIMIT", + 123: "TASK_BLOCK_SIZE", + 124: "TASK_TOTAL_SIZE", + 125: "TASK_MARSHAL", + 201: "DATA_ERROR", } ErrorCode_value = map[string]int32{ "SUCC": 0, @@ -115,6 +132,13 @@ var ( "QPS_LIMIT": 113, "CMDS_LIMIT": 114, "CMDS_NULL": 115, + "TASK_EXISTS": 120, + "TASK_IS_NOT_EXISTS": 121, + "TASK_NUM_LIMIT": 122, + "TASK_BLOCK_SIZE": 123, + "TASK_TOTAL_SIZE": 124, + "TASK_MARSHAL": 125, + "DATA_ERROR": 201, } ) @@ -188,6 +212,64 @@ func (CmdErrorCode) EnumDescriptor() ([]byte, []int) { return file_cmd_proto_rawDescGZIP(), []int{2} } +type TaskStatus int32 + +const ( + TaskStatus_ALL TaskStatus = 0 // 全部 + TaskStatus_WAITING TaskStatus = 1 // 等待中 + TaskStatus_RUNNING TaskStatus = 2 // 运行中 + TaskStatus_SUCCESS TaskStatus = 3 // 成功 + TaskStatus_FAIL TaskStatus = 4 // 失败 + TaskStatus_DELETED TaskStatus = 5 // 已删除,仅在执行删除成功时返回 +) + +// Enum value maps for TaskStatus. +var ( + TaskStatus_name = map[int32]string{ + 0: "ALL", + 1: "WAITING", + 2: "RUNNING", + 3: "SUCCESS", + 4: "FAIL", + 5: "DELETED", + } + TaskStatus_value = map[string]int32{ + "ALL": 0, + "WAITING": 1, + "RUNNING": 2, + "SUCCESS": 3, + "FAIL": 4, + "DELETED": 5, + } +) + +func (x TaskStatus) Enum() *TaskStatus { + p := new(TaskStatus) + *p = x + return p +} + +func (x TaskStatus) String() string { + return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x)) +} + +func (TaskStatus) Descriptor() protoreflect.EnumDescriptor { + return file_cmd_proto_enumTypes[3].Descriptor() +} + +func (TaskStatus) Type() protoreflect.EnumType { + return &file_cmd_proto_enumTypes[3] +} + +func (x TaskStatus) Number() protoreflect.EnumNumber { + return protoreflect.EnumNumber(x) +} + +// Deprecated: Use TaskStatus.Descriptor instead. +func (TaskStatus) EnumDescriptor() ([]byte, []int) { + return file_cmd_proto_rawDescGZIP(), []int{3} +} + // SaasReq 命令请求 type SaasReq struct { state protoimpl.MessageState `protogen:"open.v1"` @@ -195,12 +277,14 @@ type SaasReq struct { Appid string `protobuf:"bytes,2,opt,name=appid,proto3" json:"appid,omitempty"` // 小程序/小游戏/公众号/视频号的appid // Types that are valid to be assigned to Cmd: // - // *SaasReq_Write // *SaasReq_Read + // *SaasReq_Write // *SaasReq_ColumnWrite + // *SaasReq_TaskCreate // *SaasReq_TaskList - // *SaasReq_TaskCancel - // *SaasReq_TaskDetail + // *SaasReq_TaskRun + // *SaasReq_TaskDelete + // *SaasReq_TaskInfo Cmd isSaasReq_Cmd `protobuf_oneof:"cmd"` unknownFields protoimpl.UnknownFields sizeCache protoimpl.SizeCache @@ -257,19 +341,19 @@ func (x *SaasReq) GetCmd() isSaasReq_Cmd { return nil } -func (x *SaasReq) GetWrite() *Write { +func (x *SaasReq) GetRead() *Read { if x != nil { - if x, ok := x.Cmd.(*SaasReq_Write); ok { - return x.Write + if x, ok := x.Cmd.(*SaasReq_Read); ok { + return x.Read } } return nil } -func (x *SaasReq) GetRead() *Read { +func (x *SaasReq) GetWrite() *Write { if x != nil { - if x, ok := x.Cmd.(*SaasReq_Read); ok { - return x.Read + if x, ok := x.Cmd.(*SaasReq_Write); ok { + return x.Write } } return nil @@ -284,6 +368,15 @@ func (x *SaasReq) GetColumnWrite() *ColumnWrite { return nil } +func (x *SaasReq) GetTaskCreate() *Task { + if x != nil { + if x, ok := x.Cmd.(*SaasReq_TaskCreate); ok { + return x.TaskCreate + } + } + return nil +} + func (x *SaasReq) GetTaskList() *TaskList { if x != nil { if x, ok := x.Cmd.(*SaasReq_TaskList); ok { @@ -293,19 +386,28 @@ func (x *SaasReq) GetTaskList() *TaskList { return nil } -func (x *SaasReq) GetTaskCancel() *TaskCancel { +func (x *SaasReq) GetTaskRun() *TaskRun { if x != nil { - if x, ok := x.Cmd.(*SaasReq_TaskCancel); ok { - return x.TaskCancel + if x, ok := x.Cmd.(*SaasReq_TaskRun); ok { + return x.TaskRun } } return nil } -func (x *SaasReq) GetTaskDetail() *TaskDetail { +func (x *SaasReq) GetTaskDelete() *TaskDelete { if x != nil { - if x, ok := x.Cmd.(*SaasReq_TaskDetail); ok { - return x.TaskDetail + if x, ok := x.Cmd.(*SaasReq_TaskDelete); ok { + return x.TaskDelete + } + } + return nil +} + +func (x *SaasReq) GetTaskInfo() *TaskInfo { + if x != nil { + if x, ok := x.Cmd.(*SaasReq_TaskInfo); ok { + return x.TaskInfo } } return nil @@ -315,55 +417,156 @@ type isSaasReq_Cmd interface { isSaasReq_Cmd() } -type SaasReq_Write struct { - Write *Write `protobuf:"bytes,10,opt,name=write,proto3,oneof"` // 批量写入 +type SaasReq_Read struct { + Read *Read `protobuf:"bytes,10,opt,name=read,proto3,oneof"` // 批量读取 } -type SaasReq_Read struct { - Read *Read `protobuf:"bytes,11,opt,name=read,proto3,oneof"` // 批量读取 +type SaasReq_Write struct { + Write *Write `protobuf:"bytes,11,opt,name=write,proto3,oneof"` // 批量写入 } type SaasReq_ColumnWrite struct { ColumnWrite *ColumnWrite `protobuf:"bytes,12,opt,name=column_write,json=columnWrite,proto3,oneof"` // 全量列式写入 } +type SaasReq_TaskCreate struct { + TaskCreate *Task `protobuf:"bytes,20,opt,name=task_create,json=taskCreate,proto3,oneof"` // 任务创建 +} + type SaasReq_TaskList struct { - TaskList *TaskList `protobuf:"bytes,20,opt,name=task_list,json=taskList,proto3,oneof"` // 任务列表 + TaskList *TaskList `protobuf:"bytes,21,opt,name=task_list,json=taskList,proto3,oneof"` // 列出任务 } -type SaasReq_TaskCancel struct { - TaskCancel *TaskCancel `protobuf:"bytes,21,opt,name=task_cancel,json=taskCancel,proto3,oneof"` // 取消任务 +type SaasReq_TaskRun struct { + TaskRun *TaskRun `protobuf:"bytes,22,opt,name=task_run,json=taskRun,proto3,oneof"` // 执行任务 } -type SaasReq_TaskDetail struct { - TaskDetail *TaskDetail `protobuf:"bytes,22,opt,name=task_detail,json=taskDetail,proto3,oneof"` // 任务详情 +type SaasReq_TaskDelete struct { + TaskDelete *TaskDelete `protobuf:"bytes,23,opt,name=task_delete,json=taskDelete,proto3,oneof"` // 删除任务 } -func (*SaasReq_Write) isSaasReq_Cmd() {} +type SaasReq_TaskInfo struct { + TaskInfo *TaskInfo `protobuf:"bytes,24,opt,name=task_info,json=taskInfo,proto3,oneof"` // 任务详情 +} func (*SaasReq_Read) isSaasReq_Cmd() {} +func (*SaasReq_Write) isSaasReq_Cmd() {} + func (*SaasReq_ColumnWrite) isSaasReq_Cmd() {} +func (*SaasReq_TaskCreate) isSaasReq_Cmd() {} + func (*SaasReq_TaskList) isSaasReq_Cmd() {} -func (*SaasReq_TaskCancel) isSaasReq_Cmd() {} +func (*SaasReq_TaskRun) isSaasReq_Cmd() {} -func (*SaasReq_TaskDetail) isSaasReq_Cmd() {} +func (*SaasReq_TaskDelete) isSaasReq_Cmd() {} + +func (*SaasReq_TaskInfo) isSaasReq_Cmd() {} + +// Read 批量读取命令 +type Read struct { + state protoimpl.MessageState `protogen:"open.v1"` + ReadItems []*ReadItem `protobuf:"bytes,1,rep,name=read_items,json=readItems,proto3" json:"read_items,omitempty"` // 批量获取命令 + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *Read) Reset() { + *x = Read{} + mi := &file_cmd_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *Read) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Read) ProtoMessage() {} + +func (x *Read) ProtoReflect() protoreflect.Message { + mi := &file_cmd_proto_msgTypes[1] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use Read.ProtoReflect.Descriptor instead. +func (*Read) Descriptor() ([]byte, []int) { + return file_cmd_proto_rawDescGZIP(), []int{1} +} + +func (x *Read) GetReadItems() []*ReadItem { + if x != nil { + return x.ReadItems + } + return nil +} + +// ReadItem 读取命令 +type ReadItem struct { + state protoimpl.MessageState `protogen:"open.v1"` + Userid string `protobuf:"bytes,1,opt,name=userid,proto3" json:"userid,omitempty"` // 用户ID + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *ReadItem) Reset() { + *x = ReadItem{} + mi := &file_cmd_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *ReadItem) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ReadItem) ProtoMessage() {} + +func (x *ReadItem) ProtoReflect() protoreflect.Message { + mi := &file_cmd_proto_msgTypes[2] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ReadItem.ProtoReflect.Descriptor instead. +func (*ReadItem) Descriptor() ([]byte, []int) { + return file_cmd_proto_rawDescGZIP(), []int{2} +} + +func (x *ReadItem) GetUserid() string { + if x != nil { + return x.Userid + } + return "" +} // Write 批量写入命令 type Write struct { state protoimpl.MessageState `protogen:"open.v1"` - Async bool `protobuf:"varint,1,opt,name=async,proto3" json:"async,omitempty"` // 是否异步执行 - IsClearAllFirst bool `protobuf:"varint,2,opt,name=is_clear_all_first,json=isClearAllFirst,proto3" json:"is_clear_all_first,omitempty"` // 是否先执行清空 - WriteCmds []*WriteCmd `protobuf:"bytes,3,rep,name=write_cmds,json=writeCmds,proto3" json:"write_cmds,omitempty"` // 批量写入命令 + IsClearAllFirst bool `protobuf:"varint,1,opt,name=is_clear_all_first,json=isClearAllFirst,proto3" json:"is_clear_all_first,omitempty"` // 是否先清空该用户所有数据 + WriteItems []*WriteItem `protobuf:"bytes,2,rep,name=write_items,json=writeItems,proto3" json:"write_items,omitempty"` // 批量写入命令 unknownFields protoimpl.UnknownFields sizeCache protoimpl.SizeCache } func (x *Write) Reset() { *x = Write{} - mi := &file_cmd_proto_msgTypes[1] + mi := &file_cmd_proto_msgTypes[3] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -375,7 +578,7 @@ func (x *Write) String() string { func (*Write) ProtoMessage() {} func (x *Write) ProtoReflect() protoreflect.Message { - mi := &file_cmd_proto_msgTypes[1] + mi := &file_cmd_proto_msgTypes[3] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -388,14 +591,7 @@ func (x *Write) ProtoReflect() protoreflect.Message { // Deprecated: Use Write.ProtoReflect.Descriptor instead. func (*Write) Descriptor() ([]byte, []int) { - return file_cmd_proto_rawDescGZIP(), []int{1} -} - -func (x *Write) GetAsync() bool { - if x != nil { - return x.Async - } - return false + return file_cmd_proto_rawDescGZIP(), []int{3} } func (x *Write) GetIsClearAllFirst() bool { @@ -405,15 +601,15 @@ func (x *Write) GetIsClearAllFirst() bool { return false } -func (x *Write) GetWriteCmds() []*WriteCmd { +func (x *Write) GetWriteItems() []*WriteItem { if x != nil { - return x.WriteCmds + return x.WriteItems } return nil } -// WriteCmd 写入命令 -type WriteCmd struct { +// WriteItem 写入命令 +type WriteItem struct { state protoimpl.MessageState `protogen:"open.v1"` Userid string `protobuf:"bytes,1,opt,name=userid,proto3" json:"userid,omitempty"` // 用户ID WriteBytes *Bytes `protobuf:"bytes,2,opt,name=write_bytes,json=writeBytes,proto3" json:"write_bytes,omitempty"` // byte区域 @@ -423,21 +619,21 @@ type WriteCmd struct { sizeCache protoimpl.SizeCache } -func (x *WriteCmd) Reset() { - *x = WriteCmd{} - mi := &file_cmd_proto_msgTypes[2] +func (x *WriteItem) Reset() { + *x = WriteItem{} + mi := &file_cmd_proto_msgTypes[4] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } -func (x *WriteCmd) String() string { +func (x *WriteItem) String() string { return protoimpl.X.MessageStringOf(x) } -func (*WriteCmd) ProtoMessage() {} +func (*WriteItem) ProtoMessage() {} -func (x *WriteCmd) ProtoReflect() protoreflect.Message { - mi := &file_cmd_proto_msgTypes[2] +func (x *WriteItem) ProtoReflect() protoreflect.Message { + mi := &file_cmd_proto_msgTypes[4] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -448,33 +644,33 @@ func (x *WriteCmd) ProtoReflect() protoreflect.Message { return mi.MessageOf(x) } -// Deprecated: Use WriteCmd.ProtoReflect.Descriptor instead. -func (*WriteCmd) Descriptor() ([]byte, []int) { - return file_cmd_proto_rawDescGZIP(), []int{2} +// Deprecated: Use WriteItem.ProtoReflect.Descriptor instead. +func (*WriteItem) Descriptor() ([]byte, []int) { + return file_cmd_proto_rawDescGZIP(), []int{4} } -func (x *WriteCmd) GetUserid() string { +func (x *WriteItem) GetUserid() string { if x != nil { return x.Userid } return "" } -func (x *WriteCmd) GetWriteBytes() *Bytes { +func (x *WriteItem) GetWriteBytes() *Bytes { if x != nil { return x.WriteBytes } return nil } -func (x *WriteCmd) GetWriteUint32S() *Uint32S { +func (x *WriteItem) GetWriteUint32S() *Uint32S { if x != nil { return x.WriteUint32S } return nil } -func (x *WriteCmd) GetWriteFlagsWithExpire() *FlagsWithExpire { +func (x *WriteItem) GetWriteFlagsWithExpire() *FlagsWithExpire { if x != nil { return x.WriteFlagsWithExpire } @@ -493,7 +689,7 @@ type Bytes struct { func (x *Bytes) Reset() { *x = Bytes{} - mi := &file_cmd_proto_msgTypes[3] + mi := &file_cmd_proto_msgTypes[5] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -505,7 +701,7 @@ func (x *Bytes) String() string { func (*Bytes) ProtoMessage() {} func (x *Bytes) ProtoReflect() protoreflect.Message { - mi := &file_cmd_proto_msgTypes[3] + mi := &file_cmd_proto_msgTypes[5] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -518,7 +714,7 @@ func (x *Bytes) ProtoReflect() protoreflect.Message { // Deprecated: Use Bytes.ProtoReflect.Descriptor instead. func (*Bytes) Descriptor() ([]byte, []int) { - return file_cmd_proto_rawDescGZIP(), []int{3} + return file_cmd_proto_rawDescGZIP(), []int{5} } func (x *Bytes) GetBytes() []byte { @@ -553,7 +749,7 @@ type Uint32S struct { func (x *Uint32S) Reset() { *x = Uint32S{} - mi := &file_cmd_proto_msgTypes[4] + mi := &file_cmd_proto_msgTypes[6] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -565,7 +761,7 @@ func (x *Uint32S) String() string { func (*Uint32S) ProtoMessage() {} func (x *Uint32S) ProtoReflect() protoreflect.Message { - mi := &file_cmd_proto_msgTypes[4] + mi := &file_cmd_proto_msgTypes[6] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -578,7 +774,7 @@ func (x *Uint32S) ProtoReflect() protoreflect.Message { // Deprecated: Use Uint32S.ProtoReflect.Descriptor instead. func (*Uint32S) Descriptor() ([]byte, []int) { - return file_cmd_proto_rawDescGZIP(), []int{4} + return file_cmd_proto_rawDescGZIP(), []int{6} } func (x *Uint32S) GetUint32S() []uint32 { @@ -606,7 +802,7 @@ type FlagsWithExpire struct { func (x *FlagsWithExpire) Reset() { *x = FlagsWithExpire{} - mi := &file_cmd_proto_msgTypes[5] + mi := &file_cmd_proto_msgTypes[7] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -618,7 +814,7 @@ func (x *FlagsWithExpire) String() string { func (*FlagsWithExpire) ProtoMessage() {} func (x *FlagsWithExpire) ProtoReflect() protoreflect.Message { - mi := &file_cmd_proto_msgTypes[5] + mi := &file_cmd_proto_msgTypes[7] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -631,7 +827,7 @@ func (x *FlagsWithExpire) ProtoReflect() protoreflect.Message { // Deprecated: Use FlagsWithExpire.ProtoReflect.Descriptor instead. func (*FlagsWithExpire) Descriptor() ([]byte, []int) { - return file_cmd_proto_rawDescGZIP(), []int{5} + return file_cmd_proto_rawDescGZIP(), []int{7} } func (x *FlagsWithExpire) GetFlagsWithExpire() []*FlagWithExpire { @@ -660,7 +856,7 @@ type FlagWithExpire struct { func (x *FlagWithExpire) Reset() { *x = FlagWithExpire{} - mi := &file_cmd_proto_msgTypes[6] + mi := &file_cmd_proto_msgTypes[8] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -672,7 +868,7 @@ func (x *FlagWithExpire) String() string { func (*FlagWithExpire) ProtoMessage() {} func (x *FlagWithExpire) ProtoReflect() protoreflect.Message { - mi := &file_cmd_proto_msgTypes[6] + mi := &file_cmd_proto_msgTypes[8] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -685,7 +881,7 @@ func (x *FlagWithExpire) ProtoReflect() protoreflect.Message { // Deprecated: Use FlagWithExpire.ProtoReflect.Descriptor instead. func (*FlagWithExpire) Descriptor() ([]byte, []int) { - return file_cmd_proto_rawDescGZIP(), []int{6} + return file_cmd_proto_rawDescGZIP(), []int{8} } func (x *FlagWithExpire) GetFlag() bool { @@ -709,96 +905,6 @@ func (x *FlagWithExpire) GetExpire() uint32 { return 0 } -// Write 批量读取命令 -type Read struct { - state protoimpl.MessageState `protogen:"open.v1"` - ReadCmds []*ReadCmd `protobuf:"bytes,1,rep,name=read_cmds,json=readCmds,proto3" json:"read_cmds,omitempty"` // 批量获取命令 - unknownFields protoimpl.UnknownFields - sizeCache protoimpl.SizeCache -} - -func (x *Read) Reset() { - *x = Read{} - mi := &file_cmd_proto_msgTypes[7] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) -} - -func (x *Read) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*Read) ProtoMessage() {} - -func (x *Read) ProtoReflect() protoreflect.Message { - mi := &file_cmd_proto_msgTypes[7] - if x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use Read.ProtoReflect.Descriptor instead. -func (*Read) Descriptor() ([]byte, []int) { - return file_cmd_proto_rawDescGZIP(), []int{7} -} - -func (x *Read) GetReadCmds() []*ReadCmd { - if x != nil { - return x.ReadCmds - } - return nil -} - -// WriteCmd 读取命令 -type ReadCmd struct { - state protoimpl.MessageState `protogen:"open.v1"` - Userid string `protobuf:"bytes,1,opt,name=userid,proto3" json:"userid,omitempty"` // 用户ID - unknownFields protoimpl.UnknownFields - sizeCache protoimpl.SizeCache -} - -func (x *ReadCmd) Reset() { - *x = ReadCmd{} - mi := &file_cmd_proto_msgTypes[8] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) -} - -func (x *ReadCmd) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*ReadCmd) ProtoMessage() {} - -func (x *ReadCmd) ProtoReflect() protoreflect.Message { - mi := &file_cmd_proto_msgTypes[8] - if x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use ReadCmd.ProtoReflect.Descriptor instead. -func (*ReadCmd) Descriptor() ([]byte, []int) { - return file_cmd_proto_rawDescGZIP(), []int{8} -} - -func (x *ReadCmd) GetUserid() string { - if x != nil { - return x.Userid - } - return "" -} - // ColumnWrite 全量列式写入命令 type ColumnWrite struct { state protoimpl.MessageState `protogen:"open.v1"` @@ -868,16 +974,118 @@ func (x *ColumnWrite) GetIsClearAllFirst() bool { return false } +type Task struct { + state protoimpl.MessageState `protogen:"open.v1"` + TaskSha256 string `protobuf:"bytes,1,opt,name=task_sha256,json=taskSha256,proto3" json:"task_sha256,omitempty"` // 任务sha256 + TaskDescription string `protobuf:"bytes,2,opt,name=task_description,json=taskDescription,proto3" json:"task_description,omitempty"` // 任务描述 + TaskFileInfos []*FileInfo `protobuf:"bytes,3,rep,name=task_file_infos,json=taskFileInfos,proto3" json:"task_file_infos,omitempty"` // 文件列表 + TaskBlockSize uint64 `protobuf:"varint,4,opt,name=task_block_size,json=taskBlockSize,proto3" json:"task_block_size,omitempty"` // 文件块字节大小(推荐50M) + // 以下字段只在返回时填写,用于提供服务端的任务状态。在请求时填写会被忽略 + CreateTime string `protobuf:"bytes,10,opt,name=create_time,json=createTime,proto3" json:"create_time,omitempty"` // 创建时间 + RunTime string `protobuf:"bytes,11,opt,name=run_time,json=runTime,proto3" json:"run_time,omitempty"` // 运行时间 + FinishTime string `protobuf:"bytes,12,opt,name=finish_time,json=finishTime,proto3" json:"finish_time,omitempty"` // 完成时间 + Status TaskStatus `protobuf:"varint,15,opt,name=status,proto3,enum=saasapi.TaskStatus" json:"status,omitempty"` // 任务状态 + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *Task) Reset() { + *x = Task{} + mi := &file_cmd_proto_msgTypes[10] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *Task) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Task) ProtoMessage() {} + +func (x *Task) ProtoReflect() protoreflect.Message { + mi := &file_cmd_proto_msgTypes[10] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use Task.ProtoReflect.Descriptor instead. +func (*Task) Descriptor() ([]byte, []int) { + return file_cmd_proto_rawDescGZIP(), []int{10} +} + +func (x *Task) GetTaskSha256() string { + if x != nil { + return x.TaskSha256 + } + return "" +} + +func (x *Task) GetTaskDescription() string { + if x != nil { + return x.TaskDescription + } + return "" +} + +func (x *Task) GetTaskFileInfos() []*FileInfo { + if x != nil { + return x.TaskFileInfos + } + return nil +} + +func (x *Task) GetTaskBlockSize() uint64 { + if x != nil { + return x.TaskBlockSize + } + return 0 +} + +func (x *Task) GetCreateTime() string { + if x != nil { + return x.CreateTime + } + return "" +} + +func (x *Task) GetRunTime() string { + if x != nil { + return x.RunTime + } + return "" +} + +func (x *Task) GetFinishTime() string { + if x != nil { + return x.FinishTime + } + return "" +} + +func (x *Task) GetStatus() TaskStatus { + if x != nil { + return x.Status + } + return TaskStatus_ALL +} + // TaskList 任务列表 type TaskList struct { state protoimpl.MessageState `protogen:"open.v1"` + StatusFilter TaskStatus `protobuf:"varint,1,opt,name=status_filter,json=statusFilter,proto3,enum=saasapi.TaskStatus" json:"status_filter,omitempty"` // 只显示指定状态的任务 unknownFields protoimpl.UnknownFields sizeCache protoimpl.SizeCache } func (x *TaskList) Reset() { *x = TaskList{} - mi := &file_cmd_proto_msgTypes[10] + mi := &file_cmd_proto_msgTypes[11] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -889,7 +1097,7 @@ func (x *TaskList) String() string { func (*TaskList) ProtoMessage() {} func (x *TaskList) ProtoReflect() protoreflect.Message { - mi := &file_cmd_proto_msgTypes[10] + mi := &file_cmd_proto_msgTypes[11] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -902,67 +1110,38 @@ func (x *TaskList) ProtoReflect() protoreflect.Message { // Deprecated: Use TaskList.ProtoReflect.Descriptor instead. func (*TaskList) Descriptor() ([]byte, []int) { - return file_cmd_proto_rawDescGZIP(), []int{10} -} - -// TaskCancel 取消任务 -type TaskCancel struct { - state protoimpl.MessageState `protogen:"open.v1"` - unknownFields protoimpl.UnknownFields - sizeCache protoimpl.SizeCache -} - -func (x *TaskCancel) Reset() { - *x = TaskCancel{} - mi := &file_cmd_proto_msgTypes[11] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) -} - -func (x *TaskCancel) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*TaskCancel) ProtoMessage() {} - -func (x *TaskCancel) ProtoReflect() protoreflect.Message { - mi := &file_cmd_proto_msgTypes[11] - if x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use TaskCancel.ProtoReflect.Descriptor instead. -func (*TaskCancel) Descriptor() ([]byte, []int) { return file_cmd_proto_rawDescGZIP(), []int{11} } -// TaskDetail 任务详情 -type TaskDetail struct { +func (x *TaskList) GetStatusFilter() TaskStatus { + if x != nil { + return x.StatusFilter + } + return TaskStatus_ALL +} + +// TaskRun 任务运行 +type TaskRun struct { state protoimpl.MessageState `protogen:"open.v1"` + TaskSha256 string `protobuf:"bytes,1,opt,name=task_sha256,json=taskSha256,proto3" json:"task_sha256,omitempty"` // 任务sha256 unknownFields protoimpl.UnknownFields sizeCache protoimpl.SizeCache } -func (x *TaskDetail) Reset() { - *x = TaskDetail{} +func (x *TaskRun) Reset() { + *x = TaskRun{} mi := &file_cmd_proto_msgTypes[12] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } -func (x *TaskDetail) String() string { +func (x *TaskRun) String() string { return protoimpl.X.MessageStringOf(x) } -func (*TaskDetail) ProtoMessage() {} +func (*TaskRun) ProtoMessage() {} -func (x *TaskDetail) ProtoReflect() protoreflect.Message { +func (x *TaskRun) ProtoReflect() protoreflect.Message { mi := &file_cmd_proto_msgTypes[12] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) @@ -974,26 +1153,250 @@ func (x *TaskDetail) ProtoReflect() protoreflect.Message { return mi.MessageOf(x) } -// Deprecated: Use TaskDetail.ProtoReflect.Descriptor instead. -func (*TaskDetail) Descriptor() ([]byte, []int) { +// Deprecated: Use TaskRun.ProtoReflect.Descriptor instead. +func (*TaskRun) Descriptor() ([]byte, []int) { return file_cmd_proto_rawDescGZIP(), []int{12} } +func (x *TaskRun) GetTaskSha256() string { + if x != nil { + return x.TaskSha256 + } + return "" +} + +// TaskDelete 取消任务 +type TaskDelete struct { + state protoimpl.MessageState `protogen:"open.v1"` + TaskSha256 string `protobuf:"bytes,1,opt,name=task_sha256,json=taskSha256,proto3" json:"task_sha256,omitempty"` // 任务sha256 + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *TaskDelete) Reset() { + *x = TaskDelete{} + mi := &file_cmd_proto_msgTypes[13] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *TaskDelete) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*TaskDelete) ProtoMessage() {} + +func (x *TaskDelete) ProtoReflect() protoreflect.Message { + mi := &file_cmd_proto_msgTypes[13] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use TaskDelete.ProtoReflect.Descriptor instead. +func (*TaskDelete) Descriptor() ([]byte, []int) { + return file_cmd_proto_rawDescGZIP(), []int{13} +} + +func (x *TaskDelete) GetTaskSha256() string { + if x != nil { + return x.TaskSha256 + } + return "" +} + +// TaskInfo 任务详情 +type TaskInfo struct { + state protoimpl.MessageState `protogen:"open.v1"` + TaskSha256 string `protobuf:"bytes,1,opt,name=task_sha256,json=taskSha256,proto3" json:"task_sha256,omitempty"` // 任务sha256 + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *TaskInfo) Reset() { + *x = TaskInfo{} + mi := &file_cmd_proto_msgTypes[14] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *TaskInfo) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*TaskInfo) ProtoMessage() {} + +func (x *TaskInfo) ProtoReflect() protoreflect.Message { + mi := &file_cmd_proto_msgTypes[14] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use TaskInfo.ProtoReflect.Descriptor instead. +func (*TaskInfo) Descriptor() ([]byte, []int) { + return file_cmd_proto_rawDescGZIP(), []int{14} +} + +func (x *TaskInfo) GetTaskSha256() string { + if x != nil { + return x.TaskSha256 + } + return "" +} + +type FileInfo struct { + state protoimpl.MessageState `protogen:"open.v1"` + FileName string `protobuf:"bytes,1,opt,name=file_name,json=fileName,proto3" json:"file_name,omitempty"` // 文件名 + FileSize uint64 `protobuf:"varint,2,opt,name=file_size,json=fileSize,proto3" json:"file_size,omitempty"` // 文件大小 + FileBlocks []*FileBlock `protobuf:"bytes,3,rep,name=file_blocks,json=fileBlocks,proto3" json:"file_blocks,omitempty"` // 文件块列表 + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *FileInfo) Reset() { + *x = FileInfo{} + mi := &file_cmd_proto_msgTypes[15] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *FileInfo) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*FileInfo) ProtoMessage() {} + +func (x *FileInfo) ProtoReflect() protoreflect.Message { + mi := &file_cmd_proto_msgTypes[15] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use FileInfo.ProtoReflect.Descriptor instead. +func (*FileInfo) Descriptor() ([]byte, []int) { + return file_cmd_proto_rawDescGZIP(), []int{15} +} + +func (x *FileInfo) GetFileName() string { + if x != nil { + return x.FileName + } + return "" +} + +func (x *FileInfo) GetFileSize() uint64 { + if x != nil { + return x.FileSize + } + return 0 +} + +func (x *FileInfo) GetFileBlocks() []*FileBlock { + if x != nil { + return x.FileBlocks + } + return nil +} + +type FileBlock struct { + state protoimpl.MessageState `protogen:"open.v1"` + BlockSha256 string `protobuf:"bytes,1,opt,name=block_sha256,json=blockSha256,proto3" json:"block_sha256,omitempty"` // 块的sha256 + BlockLength uint64 `protobuf:"varint,2,opt,name=block_length,json=blockLength,proto3" json:"block_length,omitempty"` // 块的字节长度 + Uploaded bool `protobuf:"varint,3,opt,name=uploaded,proto3" json:"uploaded,omitempty"` // 是否已上传(在TaskInfo请求返回) + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *FileBlock) Reset() { + *x = FileBlock{} + mi := &file_cmd_proto_msgTypes[16] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *FileBlock) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*FileBlock) ProtoMessage() {} + +func (x *FileBlock) ProtoReflect() protoreflect.Message { + mi := &file_cmd_proto_msgTypes[16] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use FileBlock.ProtoReflect.Descriptor instead. +func (*FileBlock) Descriptor() ([]byte, []int) { + return file_cmd_proto_rawDescGZIP(), []int{16} +} + +func (x *FileBlock) GetBlockSha256() string { + if x != nil { + return x.BlockSha256 + } + return "" +} + +func (x *FileBlock) GetBlockLength() uint64 { + if x != nil { + return x.BlockLength + } + return 0 +} + +func (x *FileBlock) GetUploaded() bool { + if x != nil { + return x.Uploaded + } + return false +} + // SaasRes 命令返回 type SaasRes struct { - state protoimpl.MessageState `protogen:"open.v1"` - Code ErrorCode `protobuf:"varint,1,opt,name=code,proto3,enum=saasapi.ErrorCode" json:"code,omitempty"` // 返回码 - Status string `protobuf:"bytes,2,opt,name=status,proto3" json:"status,omitempty"` // 返回信息的文本提示 - SuccCmdCount uint32 `protobuf:"varint,3,opt,name=succ_cmd_count,json=succCmdCount,proto3" json:"succ_cmd_count,omitempty"` // 成功的命令数量 - FailCmdCount uint32 `protobuf:"varint,4,opt,name=fail_cmd_count,json=failCmdCount,proto3" json:"fail_cmd_count,omitempty"` // 失败的命令数量 - CmdRes []*CmdsResItem `protobuf:"bytes,5,rep,name=cmd_res,json=cmdRes,proto3" json:"cmd_res,omitempty"` // 返回的命令 + state protoimpl.MessageState `protogen:"open.v1"` + Code ErrorCode `protobuf:"varint,1,opt,name=code,proto3,enum=saasapi.ErrorCode" json:"code,omitempty"` // 返回码 + Status string `protobuf:"bytes,2,opt,name=status,proto3" json:"status,omitempty"` // 返回信息的文本提示 + // Types that are valid to be assigned to Res: + // + // *SaasRes_ReadRes + // *SaasRes_WriteRes + // *SaasRes_TaskCreateRes + // *SaasRes_TaskListRes + // *SaasRes_TaskRunRes + // *SaasRes_TaskInfoRes + // *SaasRes_TaskDeleteRes + Res isSaasRes_Res `protobuf_oneof:"res"` unknownFields protoimpl.UnknownFields sizeCache protoimpl.SizeCache } func (x *SaasRes) Reset() { *x = SaasRes{} - mi := &file_cmd_proto_msgTypes[13] + mi := &file_cmd_proto_msgTypes[17] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1005,7 +1408,7 @@ func (x *SaasRes) String() string { func (*SaasRes) ProtoMessage() {} func (x *SaasRes) ProtoReflect() protoreflect.Message { - mi := &file_cmd_proto_msgTypes[13] + mi := &file_cmd_proto_msgTypes[17] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1018,7 +1421,7 @@ func (x *SaasRes) ProtoReflect() protoreflect.Message { // Deprecated: Use SaasRes.ProtoReflect.Descriptor instead. func (*SaasRes) Descriptor() ([]byte, []int) { - return file_cmd_proto_rawDescGZIP(), []int{13} + return file_cmd_proto_rawDescGZIP(), []int{17} } func (x *SaasRes) GetCode() ErrorCode { @@ -1035,29 +1438,244 @@ func (x *SaasRes) GetStatus() string { return "" } -func (x *SaasRes) GetSuccCmdCount() uint32 { +func (x *SaasRes) GetRes() isSaasRes_Res { + if x != nil { + return x.Res + } + return nil +} + +func (x *SaasRes) GetReadRes() *ReadRes { + if x != nil { + if x, ok := x.Res.(*SaasRes_ReadRes); ok { + return x.ReadRes + } + } + return nil +} + +func (x *SaasRes) GetWriteRes() *WriteRes { + if x != nil { + if x, ok := x.Res.(*SaasRes_WriteRes); ok { + return x.WriteRes + } + } + return nil +} + +func (x *SaasRes) GetTaskCreateRes() *Task { + if x != nil { + if x, ok := x.Res.(*SaasRes_TaskCreateRes); ok { + return x.TaskCreateRes + } + } + return nil +} + +func (x *SaasRes) GetTaskListRes() *TaskListRes { + if x != nil { + if x, ok := x.Res.(*SaasRes_TaskListRes); ok { + return x.TaskListRes + } + } + return nil +} + +func (x *SaasRes) GetTaskRunRes() *Task { + if x != nil { + if x, ok := x.Res.(*SaasRes_TaskRunRes); ok { + return x.TaskRunRes + } + } + return nil +} + +func (x *SaasRes) GetTaskInfoRes() *Task { + if x != nil { + if x, ok := x.Res.(*SaasRes_TaskInfoRes); ok { + return x.TaskInfoRes + } + } + return nil +} + +func (x *SaasRes) GetTaskDeleteRes() *Task { + if x != nil { + if x, ok := x.Res.(*SaasRes_TaskDeleteRes); ok { + return x.TaskDeleteRes + } + } + return nil +} + +type isSaasRes_Res interface { + isSaasRes_Res() +} + +type SaasRes_ReadRes struct { + ReadRes *ReadRes `protobuf:"bytes,10,opt,name=read_res,json=readRes,proto3,oneof"` // 读取命令返回 +} + +type SaasRes_WriteRes struct { + WriteRes *WriteRes `protobuf:"bytes,11,opt,name=write_res,json=writeRes,proto3,oneof"` // 写入命令返回 +} + +type SaasRes_TaskCreateRes struct { + TaskCreateRes *Task `protobuf:"bytes,20,opt,name=task_create_res,json=taskCreateRes,proto3,oneof"` // 创建任务返回状态 +} + +type SaasRes_TaskListRes struct { + TaskListRes *TaskListRes `protobuf:"bytes,21,opt,name=task_list_res,json=taskListRes,proto3,oneof"` // 任务列表返回状态 +} + +type SaasRes_TaskRunRes struct { + TaskRunRes *Task `protobuf:"bytes,22,opt,name=task_run_res,json=taskRunRes,proto3,oneof"` // 运行任务返回状态 +} + +type SaasRes_TaskInfoRes struct { + TaskInfoRes *Task `protobuf:"bytes,23,opt,name=task_info_res,json=taskInfoRes,proto3,oneof"` // 任务详情返回状态 +} + +type SaasRes_TaskDeleteRes struct { + TaskDeleteRes *Task `protobuf:"bytes,24,opt,name=task_delete_res,json=taskDeleteRes,proto3,oneof"` // 删除任务返回状态 +} + +func (*SaasRes_ReadRes) isSaasRes_Res() {} + +func (*SaasRes_WriteRes) isSaasRes_Res() {} + +func (*SaasRes_TaskCreateRes) isSaasRes_Res() {} + +func (*SaasRes_TaskListRes) isSaasRes_Res() {} + +func (*SaasRes_TaskRunRes) isSaasRes_Res() {} + +func (*SaasRes_TaskInfoRes) isSaasRes_Res() {} + +func (*SaasRes_TaskDeleteRes) isSaasRes_Res() {} + +type ReadRes struct { + state protoimpl.MessageState `protogen:"open.v1"` + SuccCmdCount uint32 `protobuf:"varint,1,opt,name=succ_cmd_count,json=succCmdCount,proto3" json:"succ_cmd_count,omitempty"` // 成功的命令数量 + FailCmdCount uint32 `protobuf:"varint,2,opt,name=fail_cmd_count,json=failCmdCount,proto3" json:"fail_cmd_count,omitempty"` // 失败的命令数量 + CmdRes []*ValueItem `protobuf:"bytes,3,rep,name=cmd_res,json=cmdRes,proto3" json:"cmd_res,omitempty"` // 返回的命令 + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *ReadRes) Reset() { + *x = ReadRes{} + mi := &file_cmd_proto_msgTypes[18] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *ReadRes) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ReadRes) ProtoMessage() {} + +func (x *ReadRes) ProtoReflect() protoreflect.Message { + mi := &file_cmd_proto_msgTypes[18] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ReadRes.ProtoReflect.Descriptor instead. +func (*ReadRes) Descriptor() ([]byte, []int) { + return file_cmd_proto_rawDescGZIP(), []int{18} +} + +func (x *ReadRes) GetSuccCmdCount() uint32 { if x != nil { return x.SuccCmdCount } return 0 } -func (x *SaasRes) GetFailCmdCount() uint32 { +func (x *ReadRes) GetFailCmdCount() uint32 { if x != nil { return x.FailCmdCount } return 0 } -func (x *SaasRes) GetCmdRes() []*CmdsResItem { +func (x *ReadRes) GetCmdRes() []*ValueItem { if x != nil { return x.CmdRes } return nil } -// CmdsResItem 读取命令返回内容 -type CmdsResItem struct { +type WriteRes struct { + state protoimpl.MessageState `protogen:"open.v1"` + SuccCmdCount uint32 `protobuf:"varint,1,opt,name=succ_cmd_count,json=succCmdCount,proto3" json:"succ_cmd_count,omitempty"` // 成功的命令数量 + FailCmdCount uint32 `protobuf:"varint,2,opt,name=fail_cmd_count,json=failCmdCount,proto3" json:"fail_cmd_count,omitempty"` // 失败的命令数量 + CmdRes []*ValueItem `protobuf:"bytes,3,rep,name=cmd_res,json=cmdRes,proto3" json:"cmd_res,omitempty"` // 返回的失败命令,仅填写cmd_index和cmd_code + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *WriteRes) Reset() { + *x = WriteRes{} + mi := &file_cmd_proto_msgTypes[19] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *WriteRes) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*WriteRes) ProtoMessage() {} + +func (x *WriteRes) ProtoReflect() protoreflect.Message { + mi := &file_cmd_proto_msgTypes[19] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use WriteRes.ProtoReflect.Descriptor instead. +func (*WriteRes) Descriptor() ([]byte, []int) { + return file_cmd_proto_rawDescGZIP(), []int{19} +} + +func (x *WriteRes) GetSuccCmdCount() uint32 { + if x != nil { + return x.SuccCmdCount + } + return 0 +} + +func (x *WriteRes) GetFailCmdCount() uint32 { + if x != nil { + return x.FailCmdCount + } + return 0 +} + +func (x *WriteRes) GetCmdRes() []*ValueItem { + if x != nil { + return x.CmdRes + } + return nil +} + +// ValueItem 读取命令返回内容 +type ValueItem struct { state protoimpl.MessageState `protogen:"open.v1"` CmdIndex uint32 `protobuf:"varint,1,opt,name=cmd_index,json=cmdIndex,proto3" json:"cmd_index,omitempty"` // 命令索引 CmdCode CmdErrorCode `protobuf:"varint,2,opt,name=cmd_code,json=cmdCode,proto3,enum=saasapi.CmdErrorCode" json:"cmd_code,omitempty"` // 状态 @@ -1069,21 +1687,21 @@ type CmdsResItem struct { sizeCache protoimpl.SizeCache } -func (x *CmdsResItem) Reset() { - *x = CmdsResItem{} - mi := &file_cmd_proto_msgTypes[14] +func (x *ValueItem) Reset() { + *x = ValueItem{} + mi := &file_cmd_proto_msgTypes[20] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } -func (x *CmdsResItem) String() string { +func (x *ValueItem) String() string { return protoimpl.X.MessageStringOf(x) } -func (*CmdsResItem) ProtoMessage() {} +func (*ValueItem) ProtoMessage() {} -func (x *CmdsResItem) ProtoReflect() protoreflect.Message { - mi := &file_cmd_proto_msgTypes[14] +func (x *ValueItem) ProtoReflect() protoreflect.Message { + mi := &file_cmd_proto_msgTypes[20] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1094,78 +1712,128 @@ func (x *CmdsResItem) ProtoReflect() protoreflect.Message { return mi.MessageOf(x) } -// Deprecated: Use CmdsResItem.ProtoReflect.Descriptor instead. -func (*CmdsResItem) Descriptor() ([]byte, []int) { - return file_cmd_proto_rawDescGZIP(), []int{14} +// Deprecated: Use ValueItem.ProtoReflect.Descriptor instead. +func (*ValueItem) Descriptor() ([]byte, []int) { + return file_cmd_proto_rawDescGZIP(), []int{20} } -func (x *CmdsResItem) GetCmdIndex() uint32 { +func (x *ValueItem) GetCmdIndex() uint32 { if x != nil { return x.CmdIndex } return 0 } -func (x *CmdsResItem) GetCmdCode() CmdErrorCode { +func (x *ValueItem) GetCmdCode() CmdErrorCode { if x != nil { return x.CmdCode } return CmdErrorCode_OK } -func (x *CmdsResItem) GetBytes() []byte { +func (x *ValueItem) GetBytes() []byte { if x != nil { return x.Bytes } return nil } -func (x *CmdsResItem) GetUint32S() []uint32 { +func (x *ValueItem) GetUint32S() []uint32 { if x != nil { return x.Uint32S } return nil } -func (x *CmdsResItem) GetFlagsWithExpire() []*FlagWithExpire { +func (x *ValueItem) GetFlagsWithExpire() []*FlagWithExpire { if x != nil { return x.FlagsWithExpire } return nil } -func (x *CmdsResItem) GetLastModifyTime() uint32 { +func (x *ValueItem) GetLastModifyTime() uint32 { if x != nil { return x.LastModifyTime } return 0 } +type TaskListRes struct { + state protoimpl.MessageState `protogen:"open.v1"` + Tasks []*Task `protobuf:"bytes,1,rep,name=tasks,proto3" json:"tasks,omitempty"` // 任务列表 + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *TaskListRes) Reset() { + *x = TaskListRes{} + mi := &file_cmd_proto_msgTypes[21] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *TaskListRes) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*TaskListRes) ProtoMessage() {} + +func (x *TaskListRes) ProtoReflect() protoreflect.Message { + mi := &file_cmd_proto_msgTypes[21] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use TaskListRes.ProtoReflect.Descriptor instead. +func (*TaskListRes) Descriptor() ([]byte, []int) { + return file_cmd_proto_rawDescGZIP(), []int{21} +} + +func (x *TaskListRes) GetTasks() []*Task { + if x != nil { + return x.Tasks + } + return nil +} + var File_cmd_proto protoreflect.FileDescriptor const file_cmd_proto_rawDesc = "" + "\n" + - "\tcmd.proto\x12\asaasapi\"\x86\x03\n" + + "\tcmd.proto\x12\asaasapi\"\xe1\x03\n" + "\aSaasReq\x124\n" + "\vuserid_type\x18\x01 \x01(\x0e2\x13.saasapi.UserIdTypeR\n" + "useridType\x12\x14\n" + - "\x05appid\x18\x02 \x01(\tR\x05appid\x12&\n" + - "\x05write\x18\n" + - " \x01(\v2\x0e.saasapi.WriteH\x00R\x05write\x12#\n" + - "\x04read\x18\v \x01(\v2\r.saasapi.ReadH\x00R\x04read\x129\n" + + "\x05appid\x18\x02 \x01(\tR\x05appid\x12#\n" + + "\x04read\x18\n" + + " \x01(\v2\r.saasapi.ReadH\x00R\x04read\x12&\n" + + "\x05write\x18\v \x01(\v2\x0e.saasapi.WriteH\x00R\x05write\x129\n" + "\fcolumn_write\x18\f \x01(\v2\x14.saasapi.ColumnWriteH\x00R\vcolumnWrite\x120\n" + - "\ttask_list\x18\x14 \x01(\v2\x11.saasapi.TaskListH\x00R\btaskList\x126\n" + - "\vtask_cancel\x18\x15 \x01(\v2\x13.saasapi.TaskCancelH\x00R\n" + - "taskCancel\x126\n" + - "\vtask_detail\x18\x16 \x01(\v2\x13.saasapi.TaskDetailH\x00R\n" + - "taskDetailB\x05\n" + - "\x03cmd\"|\n" + - "\x05Write\x12\x14\n" + - "\x05async\x18\x01 \x01(\bR\x05async\x12+\n" + - "\x12is_clear_all_first\x18\x02 \x01(\bR\x0fisClearAllFirst\x120\n" + + "\vtask_create\x18\x14 \x01(\v2\r.saasapi.TaskH\x00R\n" + + "taskCreate\x120\n" + + "\ttask_list\x18\x15 \x01(\v2\x11.saasapi.TaskListH\x00R\btaskList\x12-\n" + + "\btask_run\x18\x16 \x01(\v2\x10.saasapi.TaskRunH\x00R\ataskRun\x126\n" + + "\vtask_delete\x18\x17 \x01(\v2\x13.saasapi.TaskDeleteH\x00R\n" + + "taskDelete\x120\n" + + "\ttask_info\x18\x18 \x01(\v2\x11.saasapi.TaskInfoH\x00R\btaskInfoB\x05\n" + + "\x03cmd\"8\n" + + "\x04Read\x120\n" + "\n" + - "write_cmds\x18\x03 \x03(\v2\x11.saasapi.WriteCmdR\twriteCmds\"\xdb\x01\n" + - "\bWriteCmd\x12\x16\n" + + "read_items\x18\x01 \x03(\v2\x11.saasapi.ReadItemR\treadItems\"\"\n" + + "\bReadItem\x12\x16\n" + + "\x06userid\x18\x01 \x01(\tR\x06userid\"i\n" + + "\x05Write\x12+\n" + + "\x12is_clear_all_first\x18\x01 \x01(\bR\x0fisClearAllFirst\x123\n" + + "\vwrite_items\x18\x02 \x03(\v2\x12.saasapi.WriteItemR\n" + + "writeItems\"\xdc\x01\n" + + "\tWriteItem\x12\x16\n" + "\x06userid\x18\x01 \x01(\tR\x06userid\x12/\n" + "\vwrite_bytes\x18\x02 \x01(\v2\x0e.saasapi.BytesR\n" + "writeBytes\x125\n" + @@ -1184,41 +1852,84 @@ const file_cmd_proto_rawDesc = "" + "\x0eFlagWithExpire\x12\x12\n" + "\x04flag\x18\x01 \x01(\bR\x04flag\x12!\n" + "\fdefault_flag\x18\x02 \x01(\bR\vdefaultFlag\x12\x16\n" + - "\x06expire\x18\x03 \x01(\rR\x06expire\"5\n" + - "\x04Read\x12-\n" + - "\tread_cmds\x18\x01 \x03(\v2\x10.saasapi.ReadCmdR\breadCmds\"!\n" + - "\aReadCmd\x12\x16\n" + - "\x06userid\x18\x01 \x01(\tR\x06userid\"\xf3\x01\n" + + "\x06expire\x18\x03 \x01(\rR\x06expire\"\xf3\x01\n" + "\vColumnWrite\x12/\n" + "\vwrite_bytes\x18\x02 \x01(\v2\x0e.saasapi.BytesR\n" + "writeBytes\x125\n" + "\rwrite_uint32s\x18\x03 \x01(\v2\x10.saasapi.Uint32sR\fwriteUint32s\x12O\n" + "\x17write_flags_with_expire\x18\x04 \x01(\v2\x18.saasapi.FlagsWithExpireR\x14writeFlagsWithExpire\x12+\n" + - "\x12is_clear_all_first\x18\x05 \x01(\bR\x0fisClearAllFirst\"\n" + + "\x12is_clear_all_first\x18\x05 \x01(\bR\x0fisClearAllFirst\"\xbf\x02\n" + + "\x04Task\x12\x1f\n" + + "\vtask_sha256\x18\x01 \x01(\tR\n" + + "taskSha256\x12)\n" + + "\x10task_description\x18\x02 \x01(\tR\x0ftaskDescription\x129\n" + + "\x0ftask_file_infos\x18\x03 \x03(\v2\x11.saasapi.FileInfoR\rtaskFileInfos\x12&\n" + + "\x0ftask_block_size\x18\x04 \x01(\x04R\rtaskBlockSize\x12\x1f\n" + + "\vcreate_time\x18\n" + + " \x01(\tR\n" + + "createTime\x12\x19\n" + + "\brun_time\x18\v \x01(\tR\arunTime\x12\x1f\n" + + "\vfinish_time\x18\f \x01(\tR\n" + + "finishTime\x12+\n" + + "\x06status\x18\x0f \x01(\x0e2\x13.saasapi.TaskStatusR\x06status\"D\n" + + "\bTaskList\x128\n" + + "\rstatus_filter\x18\x01 \x01(\x0e2\x13.saasapi.TaskStatusR\fstatusFilter\"*\n" + + "\aTaskRun\x12\x1f\n" + + "\vtask_sha256\x18\x01 \x01(\tR\n" + + "taskSha256\"-\n" + "\n" + - "\bTaskList\"\f\n" + - "\n" + - "TaskCancel\"\f\n" + - "\n" + - "TaskDetail\"\xc4\x01\n" + + "TaskDelete\x12\x1f\n" + + "\vtask_sha256\x18\x01 \x01(\tR\n" + + "taskSha256\"+\n" + + "\bTaskInfo\x12\x1f\n" + + "\vtask_sha256\x18\x01 \x01(\tR\n" + + "taskSha256\"y\n" + + "\bFileInfo\x12\x1b\n" + + "\tfile_name\x18\x01 \x01(\tR\bfileName\x12\x1b\n" + + "\tfile_size\x18\x02 \x01(\x04R\bfileSize\x123\n" + + "\vfile_blocks\x18\x03 \x03(\v2\x12.saasapi.FileBlockR\n" + + "fileBlocks\"m\n" + + "\tFileBlock\x12!\n" + + "\fblock_sha256\x18\x01 \x01(\tR\vblockSha256\x12!\n" + + "\fblock_length\x18\x02 \x01(\x04R\vblockLength\x12\x1a\n" + + "\buploaded\x18\x03 \x01(\bR\buploaded\"\xc7\x03\n" + "\aSaasRes\x12&\n" + "\x04code\x18\x01 \x01(\x0e2\x12.saasapi.ErrorCodeR\x04code\x12\x16\n" + - "\x06status\x18\x02 \x01(\tR\x06status\x12$\n" + - "\x0esucc_cmd_count\x18\x03 \x01(\rR\fsuccCmdCount\x12$\n" + - "\x0efail_cmd_count\x18\x04 \x01(\rR\ffailCmdCount\x12-\n" + - "\acmd_res\x18\x05 \x03(\v2\x14.saasapi.CmdsResItemR\x06cmdRes\"\xfb\x01\n" + - "\vCmdsResItem\x12\x1b\n" + + "\x06status\x18\x02 \x01(\tR\x06status\x12-\n" + + "\bread_res\x18\n" + + " \x01(\v2\x10.saasapi.ReadResH\x00R\areadRes\x120\n" + + "\twrite_res\x18\v \x01(\v2\x11.saasapi.WriteResH\x00R\bwriteRes\x127\n" + + "\x0ftask_create_res\x18\x14 \x01(\v2\r.saasapi.TaskH\x00R\rtaskCreateRes\x12:\n" + + "\rtask_list_res\x18\x15 \x01(\v2\x14.saasapi.TaskListResH\x00R\vtaskListRes\x121\n" + + "\ftask_run_res\x18\x16 \x01(\v2\r.saasapi.TaskH\x00R\n" + + "taskRunRes\x123\n" + + "\rtask_info_res\x18\x17 \x01(\v2\r.saasapi.TaskH\x00R\vtaskInfoRes\x127\n" + + "\x0ftask_delete_res\x18\x18 \x01(\v2\r.saasapi.TaskH\x00R\rtaskDeleteResB\x05\n" + + "\x03res\"\x82\x01\n" + + "\aReadRes\x12$\n" + + "\x0esucc_cmd_count\x18\x01 \x01(\rR\fsuccCmdCount\x12$\n" + + "\x0efail_cmd_count\x18\x02 \x01(\rR\ffailCmdCount\x12+\n" + + "\acmd_res\x18\x03 \x03(\v2\x12.saasapi.ValueItemR\x06cmdRes\"\x83\x01\n" + + "\bWriteRes\x12$\n" + + "\x0esucc_cmd_count\x18\x01 \x01(\rR\fsuccCmdCount\x12$\n" + + "\x0efail_cmd_count\x18\x02 \x01(\rR\ffailCmdCount\x12+\n" + + "\acmd_res\x18\x03 \x03(\v2\x12.saasapi.ValueItemR\x06cmdRes\"\xf9\x01\n" + + "\tValueItem\x12\x1b\n" + "\tcmd_index\x18\x01 \x01(\rR\bcmdIndex\x120\n" + "\bcmd_code\x18\x02 \x01(\x0e2\x15.saasapi.CmdErrorCodeR\acmdCode\x12\x14\n" + "\x05bytes\x18\x03 \x01(\fR\x05bytes\x12\x18\n" + "\auint32s\x18\x04 \x03(\rR\auint32s\x12C\n" + "\x11flags_with_expire\x18\x05 \x03(\v2\x17.saasapi.FlagWithExpireR\x0fflagsWithExpire\x12(\n" + - "\x10last_modify_time\x18\x06 \x01(\rR\x0elastModifyTime*&\n" + + "\x10last_modify_time\x18\x06 \x01(\rR\x0elastModifyTime\"2\n" + + "\vTaskListRes\x12#\n" + + "\x05tasks\x18\x01 \x03(\v2\r.saasapi.TaskR\x05tasks*4\n" + "\n" + "UserIdType\x12\f\n" + "\bDEVICEID\x10\x00\x12\n" + "\n" + - "\x06OPENID\x10\x01*\xe5\x01\n" + + "\x06OPENID\x10\x01\x12\f\n" + + "\bINNERID1\x10\n" + + "*\xef\x02\n" + "\tErrorCode\x12\b\n" + "\x04SUCC\x10\x00\x12\x13\n" + "\x0fINVALID_ACCOUNT\x10e\x12\x15\n" + @@ -1232,9 +1943,25 @@ const file_cmd_proto_rawDesc = "" + "\tQPS_LIMIT\x10q\x12\x0e\n" + "\n" + "CMDS_LIMIT\x10r\x12\r\n" + - "\tCMDS_NULL\x10s*\x16\n" + + "\tCMDS_NULL\x10s\x12\x0f\n" + + "\vTASK_EXISTS\x10x\x12\x16\n" + + "\x12TASK_IS_NOT_EXISTS\x10y\x12\x12\n" + + "\x0eTASK_NUM_LIMIT\x10z\x12\x13\n" + + "\x0fTASK_BLOCK_SIZE\x10{\x12\x13\n" + + "\x0fTASK_TOTAL_SIZE\x10|\x12\x10\n" + + "\fTASK_MARSHAL\x10}\x12\x0f\n" + + "\n" + + "DATA_ERROR\x10\xc9\x01*\x16\n" + "\fCmdErrorCode\x12\x06\n" + - "\x02OK\x10\x00B!Z\x1fe.coding.net/rta/public/saasapib\x06proto3" + "\x02OK\x10\x00*S\n" + + "\n" + + "TaskStatus\x12\a\n" + + "\x03ALL\x10\x00\x12\v\n" + + "\aWAITING\x10\x01\x12\v\n" + + "\aRUNNING\x10\x02\x12\v\n" + + "\aSUCCESS\x10\x03\x12\b\n" + + "\x04FAIL\x10\x04\x12\v\n" + + "\aDELETED\x10\x05B!Z\x1fe.coding.net/rta/public/saasapib\x06proto3" var ( file_cmd_proto_rawDescOnce sync.Once @@ -1248,54 +1975,77 @@ func file_cmd_proto_rawDescGZIP() []byte { return file_cmd_proto_rawDescData } -var file_cmd_proto_enumTypes = make([]protoimpl.EnumInfo, 3) -var file_cmd_proto_msgTypes = make([]protoimpl.MessageInfo, 15) +var file_cmd_proto_enumTypes = make([]protoimpl.EnumInfo, 4) +var file_cmd_proto_msgTypes = make([]protoimpl.MessageInfo, 22) var file_cmd_proto_goTypes = []any{ (UserIdType)(0), // 0: saasapi.UserIdType (ErrorCode)(0), // 1: saasapi.ErrorCode (CmdErrorCode)(0), // 2: saasapi.CmdErrorCode - (*SaasReq)(nil), // 3: saasapi.SaasReq - (*Write)(nil), // 4: saasapi.Write - (*WriteCmd)(nil), // 5: saasapi.WriteCmd - (*Bytes)(nil), // 6: saasapi.Bytes - (*Uint32S)(nil), // 7: saasapi.Uint32s - (*FlagsWithExpire)(nil), // 8: saasapi.FlagsWithExpire - (*FlagWithExpire)(nil), // 9: saasapi.FlagWithExpire - (*Read)(nil), // 10: saasapi.Read - (*ReadCmd)(nil), // 11: saasapi.ReadCmd - (*ColumnWrite)(nil), // 12: saasapi.ColumnWrite - (*TaskList)(nil), // 13: saasapi.TaskList - (*TaskCancel)(nil), // 14: saasapi.TaskCancel - (*TaskDetail)(nil), // 15: saasapi.TaskDetail - (*SaasRes)(nil), // 16: saasapi.SaasRes - (*CmdsResItem)(nil), // 17: saasapi.CmdsResItem + (TaskStatus)(0), // 3: saasapi.TaskStatus + (*SaasReq)(nil), // 4: saasapi.SaasReq + (*Read)(nil), // 5: saasapi.Read + (*ReadItem)(nil), // 6: saasapi.ReadItem + (*Write)(nil), // 7: saasapi.Write + (*WriteItem)(nil), // 8: saasapi.WriteItem + (*Bytes)(nil), // 9: saasapi.Bytes + (*Uint32S)(nil), // 10: saasapi.Uint32s + (*FlagsWithExpire)(nil), // 11: saasapi.FlagsWithExpire + (*FlagWithExpire)(nil), // 12: saasapi.FlagWithExpire + (*ColumnWrite)(nil), // 13: saasapi.ColumnWrite + (*Task)(nil), // 14: saasapi.Task + (*TaskList)(nil), // 15: saasapi.TaskList + (*TaskRun)(nil), // 16: saasapi.TaskRun + (*TaskDelete)(nil), // 17: saasapi.TaskDelete + (*TaskInfo)(nil), // 18: saasapi.TaskInfo + (*FileInfo)(nil), // 19: saasapi.FileInfo + (*FileBlock)(nil), // 20: saasapi.FileBlock + (*SaasRes)(nil), // 21: saasapi.SaasRes + (*ReadRes)(nil), // 22: saasapi.ReadRes + (*WriteRes)(nil), // 23: saasapi.WriteRes + (*ValueItem)(nil), // 24: saasapi.ValueItem + (*TaskListRes)(nil), // 25: saasapi.TaskListRes } var file_cmd_proto_depIdxs = []int32{ 0, // 0: saasapi.SaasReq.userid_type:type_name -> saasapi.UserIdType - 4, // 1: saasapi.SaasReq.write:type_name -> saasapi.Write - 10, // 2: saasapi.SaasReq.read:type_name -> saasapi.Read - 12, // 3: saasapi.SaasReq.column_write:type_name -> saasapi.ColumnWrite - 13, // 4: saasapi.SaasReq.task_list:type_name -> saasapi.TaskList - 14, // 5: saasapi.SaasReq.task_cancel:type_name -> saasapi.TaskCancel - 15, // 6: saasapi.SaasReq.task_detail:type_name -> saasapi.TaskDetail - 5, // 7: saasapi.Write.write_cmds:type_name -> saasapi.WriteCmd - 6, // 8: saasapi.WriteCmd.write_bytes:type_name -> saasapi.Bytes - 7, // 9: saasapi.WriteCmd.write_uint32s:type_name -> saasapi.Uint32s - 8, // 10: saasapi.WriteCmd.write_flags_with_expire:type_name -> saasapi.FlagsWithExpire - 9, // 11: saasapi.FlagsWithExpire.flags_with_expire:type_name -> saasapi.FlagWithExpire - 11, // 12: saasapi.Read.read_cmds:type_name -> saasapi.ReadCmd - 6, // 13: saasapi.ColumnWrite.write_bytes:type_name -> saasapi.Bytes - 7, // 14: saasapi.ColumnWrite.write_uint32s:type_name -> saasapi.Uint32s - 8, // 15: saasapi.ColumnWrite.write_flags_with_expire:type_name -> saasapi.FlagsWithExpire - 1, // 16: saasapi.SaasRes.code:type_name -> saasapi.ErrorCode - 17, // 17: saasapi.SaasRes.cmd_res:type_name -> saasapi.CmdsResItem - 2, // 18: saasapi.CmdsResItem.cmd_code:type_name -> saasapi.CmdErrorCode - 9, // 19: saasapi.CmdsResItem.flags_with_expire:type_name -> saasapi.FlagWithExpire - 20, // [20:20] is the sub-list for method output_type - 20, // [20:20] is the sub-list for method input_type - 20, // [20:20] is the sub-list for extension type_name - 20, // [20:20] is the sub-list for extension extendee - 0, // [0:20] is the sub-list for field type_name + 5, // 1: saasapi.SaasReq.read:type_name -> saasapi.Read + 7, // 2: saasapi.SaasReq.write:type_name -> saasapi.Write + 13, // 3: saasapi.SaasReq.column_write:type_name -> saasapi.ColumnWrite + 14, // 4: saasapi.SaasReq.task_create:type_name -> saasapi.Task + 15, // 5: saasapi.SaasReq.task_list:type_name -> saasapi.TaskList + 16, // 6: saasapi.SaasReq.task_run:type_name -> saasapi.TaskRun + 17, // 7: saasapi.SaasReq.task_delete:type_name -> saasapi.TaskDelete + 18, // 8: saasapi.SaasReq.task_info:type_name -> saasapi.TaskInfo + 6, // 9: saasapi.Read.read_items:type_name -> saasapi.ReadItem + 8, // 10: saasapi.Write.write_items:type_name -> saasapi.WriteItem + 9, // 11: saasapi.WriteItem.write_bytes:type_name -> saasapi.Bytes + 10, // 12: saasapi.WriteItem.write_uint32s:type_name -> saasapi.Uint32s + 11, // 13: saasapi.WriteItem.write_flags_with_expire:type_name -> saasapi.FlagsWithExpire + 12, // 14: saasapi.FlagsWithExpire.flags_with_expire:type_name -> saasapi.FlagWithExpire + 9, // 15: saasapi.ColumnWrite.write_bytes:type_name -> saasapi.Bytes + 10, // 16: saasapi.ColumnWrite.write_uint32s:type_name -> saasapi.Uint32s + 11, // 17: saasapi.ColumnWrite.write_flags_with_expire:type_name -> saasapi.FlagsWithExpire + 19, // 18: saasapi.Task.task_file_infos:type_name -> saasapi.FileInfo + 3, // 19: saasapi.Task.status:type_name -> saasapi.TaskStatus + 3, // 20: saasapi.TaskList.status_filter:type_name -> saasapi.TaskStatus + 20, // 21: saasapi.FileInfo.file_blocks:type_name -> saasapi.FileBlock + 1, // 22: saasapi.SaasRes.code:type_name -> saasapi.ErrorCode + 22, // 23: saasapi.SaasRes.read_res:type_name -> saasapi.ReadRes + 23, // 24: saasapi.SaasRes.write_res:type_name -> saasapi.WriteRes + 14, // 25: saasapi.SaasRes.task_create_res:type_name -> saasapi.Task + 25, // 26: saasapi.SaasRes.task_list_res:type_name -> saasapi.TaskListRes + 14, // 27: saasapi.SaasRes.task_run_res:type_name -> saasapi.Task + 14, // 28: saasapi.SaasRes.task_info_res:type_name -> saasapi.Task + 14, // 29: saasapi.SaasRes.task_delete_res:type_name -> saasapi.Task + 24, // 30: saasapi.ReadRes.cmd_res:type_name -> saasapi.ValueItem + 24, // 31: saasapi.WriteRes.cmd_res:type_name -> saasapi.ValueItem + 2, // 32: saasapi.ValueItem.cmd_code:type_name -> saasapi.CmdErrorCode + 12, // 33: saasapi.ValueItem.flags_with_expire:type_name -> saasapi.FlagWithExpire + 14, // 34: saasapi.TaskListRes.tasks:type_name -> saasapi.Task + 35, // [35:35] is the sub-list for method output_type + 35, // [35:35] is the sub-list for method input_type + 35, // [35:35] is the sub-list for extension type_name + 35, // [35:35] is the sub-list for extension extendee + 0, // [0:35] is the sub-list for field type_name } func init() { file_cmd_proto_init() } @@ -1304,20 +2054,31 @@ func file_cmd_proto_init() { return } file_cmd_proto_msgTypes[0].OneofWrappers = []any{ - (*SaasReq_Write)(nil), (*SaasReq_Read)(nil), + (*SaasReq_Write)(nil), (*SaasReq_ColumnWrite)(nil), + (*SaasReq_TaskCreate)(nil), (*SaasReq_TaskList)(nil), - (*SaasReq_TaskCancel)(nil), - (*SaasReq_TaskDetail)(nil), + (*SaasReq_TaskRun)(nil), + (*SaasReq_TaskDelete)(nil), + (*SaasReq_TaskInfo)(nil), + } + file_cmd_proto_msgTypes[17].OneofWrappers = []any{ + (*SaasRes_ReadRes)(nil), + (*SaasRes_WriteRes)(nil), + (*SaasRes_TaskCreateRes)(nil), + (*SaasRes_TaskListRes)(nil), + (*SaasRes_TaskRunRes)(nil), + (*SaasRes_TaskInfoRes)(nil), + (*SaasRes_TaskDeleteRes)(nil), } type x struct{} out := protoimpl.TypeBuilder{ File: protoimpl.DescBuilder{ GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: unsafe.Slice(unsafe.StringData(file_cmd_proto_rawDesc), len(file_cmd_proto_rawDesc)), - NumEnums: 3, - NumMessages: 15, + NumEnums: 4, + NumMessages: 22, NumExtensions: 0, NumServices: 0, }, diff --git a/cmd.proto b/cmd.proto index fd1ff62..46bf0e9 100644 --- a/cmd.proto +++ b/cmd.proto @@ -6,76 +6,78 @@ option go_package = "e.coding.net/rta/public/saasapi"; // SaasReq 命令请求 message SaasReq { - UserIdType userid_type = 1; // 用户ID类型 - string appid = 2; // 小程序/小游戏/公众号/视频号的appid + UserIdType userid_type = 1; // 用户ID类型 + string appid = 2; // 小程序/小游戏/公众号/视频号的appid oneof cmd { - Write write = 10; // 批量写入 - Read read = 11; // 批量读取 - ColumnWrite column_write = 12; // 全量列式写入 + Read read = 10; // 批量读取 + Write write = 11; // 批量写入 + ColumnWrite column_write = 12; // 全量列式写入 - TaskList task_list = 20; // 任务列表 - TaskCancel task_cancel = 21; // 取消任务 - TaskDetail task_detail = 22; // 任务详情 + Task task_create = 20; // 任务创建 + TaskList task_list = 21; // 列出任务 + TaskRun task_run = 22; // 执行任务 + TaskDelete task_delete = 23; // 删除任务 + TaskInfo task_info = 24; // 任务详情 } } +// Read 批量读取命令 +message Read { + repeated ReadItem read_items = 1; // 批量获取命令 +} + +// ReadItem 读取命令 +message ReadItem { + string userid = 1; // 用户ID +} + // Write 批量写入命令 message Write { - bool async = 1; // 是否异步执行 - bool is_clear_all_first = 2; // 是否先执行清空 - repeated WriteCmd write_cmds = 3; // 批量写入命令 + bool is_clear_all_first = 1; // 是否先清空该用户所有数据 + repeated WriteItem write_items = 2; // 批量写入命令 } -// WriteCmd 写入命令 -message WriteCmd { - string userid = 1; // 用户ID - Bytes write_bytes = 2; // byte区域 - Uint32s write_uint32s = 3; // uint32区域 - FlagsWithExpire write_flags_with_expire = 4; // 标志位区域 +// WriteItem 写入命令 +message WriteItem { + string userid = 1; // 用户ID + Bytes write_bytes = 2; // byte区域 + Uint32s write_uint32s = 3; // uint32区域 + FlagsWithExpire write_flags_with_expire = 4; // 标志位区域 } // Bytes 写入byte区域 message Bytes { - bytes bytes = 1; // 写入的byte - uint64 index_1 = 2; // 写入byte的索引值(0..63) - uint64 index_2 = 3; // 写入byte的索引值(64..127) + bytes bytes = 1; // 写入的byte + uint64 index_1 = 2; // 写入byte的索引值(0..63) + uint64 index_2 = 3; // 写入byte的索引值(64..127) } // Uint32s 写入uint32区域 message Uint32s { - repeated uint32 uint32s = 1; // 写入的uint32 - uint64 index_1 = 2; // 写入uint32的索引值(0..15) 最多 16 个 - //uint64 index_2 = 3; // 写入uint32的索引值(64..127)(当前不支持) + repeated uint32 uint32s = 1; // 写入的uint32 + uint64 index_1 = 2; // 写入uint32的索引值(0..15) 最多 16 个 + //uint64 index_2 = 3; // 写入uint32的索引值(64..127)(当前不支持) } // FlagsWithExpire 写入标志位区域 message FlagsWithExpire { - repeated FlagWithExpire flags_with_expire = 1; // 写入的标志位 - uint64 index_1 = 2; // 写入标志位的索引值 + repeated FlagWithExpire flags_with_expire = 1; // 写入的标志位 + uint64 index_1 = 2; // 写入标志位的索引值 } // FlagWithExpire 标志位 message FlagWithExpire { - bool flag = 1; // 标志位 - bool default_flag = 2; // 默认值。超时后则回到默认值。 - uint32 expire = 3; // 过期时间,为 0 则永不过期 + bool flag = 1; // 标志位 + bool default_flag = 2; // 默认值。超时后则回到默认值。 + uint32 expire = 3; // 过期时间,为 0 则永不过期 } // UserIdType 用户 ID 类型 enum UserIdType { - DEVICEID = 0; // 设备号 - OPENID = 1; // OpenId -} - -// Write 批量读取命令 -message Read { - repeated ReadCmd read_cmds = 1; // 批量获取命令 -} - -// WriteCmd 读取命令 -message ReadCmd { - string userid = 1; // 用户ID + DEVICEID = 0; // 设备号 + OPENID = 1; // OpenId + INNERID1 = 10; // 内部ID1 } // ColumnWrite 全量列式写入命令 @@ -86,32 +88,82 @@ message ColumnWrite { bool is_clear_all_first = 5; // 是否先执行清空 } +message Task { + string task_sha256 = 1; // 任务sha256 + string task_description = 2; // 任务描述 + repeated FileInfo task_file_infos = 3; // 文件列表 + uint64 task_block_size = 4; // 文件块字节大小(推荐50M) + + // 以下字段只在返回时填写,用于提供服务端的任务状态。在请求时填写会被忽略 + string create_time = 10; // 创建时间 + string run_time = 11; // 运行时间 + string finish_time = 12; // 完成时间 + + TaskStatus status = 15; // 任务状态 +} + // TaskList 任务列表 message TaskList { - + TaskStatus status_filter = 1; // 只显示指定状态的任务 } -// TaskCancel 取消任务 -message TaskCancel { - +// TaskRun 任务运行 +message TaskRun { + string task_sha256 = 1; // 任务sha256 } -// TaskDetail 任务详情 -message TaskDetail { +// TaskDelete 取消任务 +message TaskDelete { + string task_sha256 = 1; // 任务sha256 +} +// TaskInfo 任务详情 +message TaskInfo { + string task_sha256 = 1; // 任务sha256 +} + +message FileInfo { + string file_name = 1; // 文件名 + uint64 file_size = 2; // 文件大小 + repeated FileBlock file_blocks = 3; // 文件块列表 +} + +message FileBlock { + string block_sha256 = 1; // 块的sha256 + uint64 block_length = 2; // 块的字节长度 + bool uploaded = 3; // 是否已上传(在TaskInfo请求返回) } // SaasRes 命令返回 message SaasRes { ErrorCode code = 1; // 返回码 string status = 2; // 返回信息的文本提示 - uint32 succ_cmd_count = 3; // 成功的命令数量 - uint32 fail_cmd_count = 4; // 失败的命令数量 - repeated CmdsResItem cmd_res = 5; // 返回的命令 + oneof res { + ReadRes read_res = 10; // 读取命令返回 + WriteRes write_res = 11; // 写入命令返回 + + Task task_create_res = 20; // 创建任务返回状态 + TaskListRes task_list_res = 21; // 任务列表返回状态 + Task task_run_res = 22; // 运行任务返回状态 + Task task_info_res = 23; // 任务详情返回状态 + Task task_delete_res = 24; // 删除任务返回状态 + } } -// CmdsResItem 读取命令返回内容 -message CmdsResItem { +message ReadRes { + uint32 succ_cmd_count = 1; // 成功的命令数量 + uint32 fail_cmd_count = 2; // 失败的命令数量 + repeated ValueItem cmd_res = 3; // 返回的命令 +} + +message WriteRes { + uint32 succ_cmd_count = 1; // 成功的命令数量 + uint32 fail_cmd_count = 2; // 失败的命令数量 + repeated ValueItem cmd_res = 3; // 返回的失败命令,仅填写cmd_index和cmd_code +} + +// ValueItem 读取命令返回内容 +message ValueItem { uint32 cmd_index = 1; // 命令索引 CmdErrorCode cmd_code = 2; // 状态 bytes bytes = 3; // byte区域 @@ -120,24 +172,46 @@ message CmdsResItem { uint32 last_modify_time = 6; // 最后修改时间 } +message TaskListRes { + repeated Task tasks = 1; // 任务列表 +} + // ErrorCode 返回码 enum ErrorCode { - SUCC = 0; // 成功 + SUCC = 0; // 成功 INVALID_ACCOUNT = 101; // Account不合法 - INVALID_TIMESTAMP = 102; // 头信息缺少时间戳 + INVALID_TIMESTAMP = 102; // 头信息缺少时间戳或不正确 INVALID_SIGNATURE = 103; // 头信息缺少签名 - AUTH_FAIL = 104; // 签名较验失败 - DISABLED_ACCOUNT = 105; // 账号已禁用 - INVALID_CONTENT_TYPE = 110; // 非法的Content-Type - READ_BODY = 111; // 读取 http body 失败 - DECODE_BODY = 112; // 解码 body 失败 - QPS_LIMIT = 113; // 并发请求量超限 - CMDS_LIMIT = 114; // 命令数量超限 + AUTH_FAIL = 104; // 签名较验失败 + DISABLED_ACCOUNT = 105; // 账号已禁用 + INVALID_CONTENT_TYPE = 110; // 非法的Content-Type + READ_BODY = 111; // 读取 http body 失败 + DECODE_BODY = 112; // 解码 body 失败 + QPS_LIMIT = 113; // 并发请求量超限 + CMDS_LIMIT = 114; // 命令数量超限 CMDS_NULL = 115; // 命令为空 + + TASK_EXISTS = 120; // 任务已存在 + TASK_IS_NOT_EXISTS = 121; // 任务不存在 + TASK_NUM_LIMIT = 122; // 任务数达到上限 + TASK_BLOCK_SIZE = 123; // 块大小超限 + TASK_TOTAL_SIZE = 124; // 总文件大小超限 + TASK_MARSHAL = 125; // 序列化 + + DATA_ERROR = 201; // 数据错误 } enum CmdErrorCode { OK = 0; // 成功 } +enum TaskStatus { + ALL = 0; // 全部 + WAITING = 1; // 等待中 + RUNNING = 2; // 运行中 + SUCCESS = 3; // 成功 + FAIL = 4; // 失败 + + DELETED = 5; // 已删除,仅在执行删除成功时返回 +} diff --git a/cmd/saastool/convert.go b/cmd/saastool/convert.go index 08bd065..1084fb7 100644 --- a/cmd/saastool/convert.go +++ b/cmd/saastool/convert.go @@ -2,27 +2,38 @@ package main import ( "bufio" + "bytes" "flag" "fmt" "os" "path" + "runtime" "strings" + "sync" "e.coding.net/rta/public/saasapi" "google.golang.org/protobuf/encoding/protojson" ) -// TODO 转换加速 +const ( + convertBatchSize = 100000 + convertedExt = ".converted" +) type convertParams struct { - targetCfg *TargetConfig + mapCfg *MapConfig sourcePath string destPath string } +type convertResult struct { + resultBuf bytes.Buffer + convertedLines int +} + func RunConvert(args ...string) error { fs := flag.NewFlagSet("convert", flag.ExitOnError) - targetCfgFile := paramTargets(fs) + mapCfgFile := paramMap(fs) sourcePath := paramSourcePath(fs) destPath := paramDestPath(fs) @@ -31,19 +42,19 @@ func RunConvert(args ...string) error { return err } - if fs.NArg() > 0 || *targetCfgFile == "" || len(*sourcePath) == 0 || len(*destPath) == 0 { + if fs.NArg() > 0 || *mapCfgFile == "" || len(*sourcePath) == 0 || len(*destPath) == 0 { fs.PrintDefaults() return nil } - targetCfg, err := LoadTargetFile(*targetCfgFile) + mapCfg, err := LoadMapFile(*mapCfgFile) if err != nil { fmt.Println("LoadConfigFile error", "err", err) return err } convertParams := convertParams{ - targetCfg: targetCfg, + mapCfg: mapCfg, sourcePath: *sourcePath, destPath: *destPath, } @@ -97,7 +108,7 @@ func doFileConvert(convertParams convertParams) error { os.MkdirAll(convertParams.destPath, os.ModePerm) } - destName := path.Join(convertParams.destPath, path.Base(convertParams.sourcePath)+".converted") + destName := path.Join(convertParams.destPath, path.Base(convertParams.sourcePath)+convertedExt) destFile, err := os.Create(destName) if err != nil { return err @@ -108,15 +119,92 @@ func doFileConvert(convertParams convertParams) error { destWriter := bufio.NewWriter(destFile) defer destWriter.Flush() - jasonMarshal := protojson.MarshalOptions{Multiline: false, Indent: ""} - + // 启动处理协程 + workers := []chan []string{} + results := []chan convertResult{} processedLine := 0 + + wg := sync.WaitGroup{} + convertMaxWorkers := runtime.GOMAXPROCS(0) + for range convertMaxWorkers { + workerChan := make(chan []string) + workers = append(workers, workerChan) + resultChan := make(chan convertResult) + results = append(results, resultChan) + + go func(workerChan <-chan []string, resultChan chan<- convertResult) { + for lines := range workerChan { + convertBatch(lines, convertParams, resultChan) + } + }(workerChan, resultChan) + } + + // 启动写入协程 + go func() { + i := 0 + + // TIP: 不要改成for range + for { + select { + case result, ok := <-results[i%convertMaxWorkers]: + if !ok { + return + } + destWriter.Write(result.resultBuf.Bytes()) + destWriter.Flush() + processedLine += result.convertedLines + fmt.Printf("\rconverted records: %v [%v]", processedLine, destName) + i++ + wg.Done() + } + + } + }() + + // 读取文件并塞给协程处理 + batch := []string{} + batchCount := 0 for scaner.Scan() { line := scaner.Text() if line == "" { continue } + batch = append(batch, line) + if len(batch) == convertBatchSize { + // 将batch写入协程 + wg.Add(1) + workers[batchCount%convertMaxWorkers] <- batch + batch = nil + batchCount++ + } + } + + if len(batch) > 0 { + wg.Add(1) + workers[batchCount%convertMaxWorkers] <- batch + } + + wg.Wait() + // 关闭所有工作协程的通道 + for _, workerChan := range workers { + close(workerChan) + } + for _, resultChan := range results { + close(resultChan) + } + fmt.Println("") + + return nil +} + +func convertBatch(lines []string, convertParams convertParams, resultChan chan<- convertResult) { + byteBuf := bytes.Buffer{} + byteBuf.Grow(1024 * 1024 * 10) + + jasonMarshal := protojson.MarshalOptions{Multiline: false, Indent: ""} + + for _, line := range lines { // 按\t分割为两列 parts := strings.Split(line, "\t") if len(parts) != 2 { @@ -125,65 +213,63 @@ func doFileConvert(convertParams convertParams) error { // 读取userid userid := parts[0] + if len(userid) == 0 { + continue + } + value := parts[1] value = strings.ReplaceAll(value, "[", "") value = strings.ReplaceAll(value, "]", "") // 第二列解析为string数组 targets := strings.Split(value, " ") - saasWriteCmd := &saasapi.WriteCmd{ + saasWriteItem := &saasapi.WriteItem{ Userid: userid, } - if len(userid) == 0 || len(targets) == 0 { - continue - } + + // 遍历targets,转换成saasapi.WriteCmd for _, target := range targets { - if targetinfo, ok := convertParams.targetCfg.Targets[target]; ok { + if targetinfo, ok := convertParams.mapCfg.Targets[target]; ok { if targetinfo.WriteByte != nil { - if saasWriteCmd.WriteBytes == nil { - saasWriteCmd.WriteBytes = &saasapi.Bytes{} + // 转换byte区 + if saasWriteItem.WriteBytes == nil { + saasWriteItem.WriteBytes = &saasapi.Bytes{} } - saasWriteCmd.WriteBytes.Bytes = append(saasWriteCmd.WriteBytes.Bytes, *targetinfo.WriteByte) + saasWriteItem.WriteBytes.Bytes = append(saasWriteItem.WriteBytes.Bytes, *targetinfo.WriteByte) if targetinfo.WriteBytePos < 64 { - saasWriteCmd.WriteBytes.Index_1 |= 1 << targetinfo.WriteBytePos + saasWriteItem.WriteBytes.Index_1 |= 1 << targetinfo.WriteBytePos } else if targetinfo.WriteBytePos < 128 { - saasWriteCmd.WriteBytes.Index_2 |= 1 << (targetinfo.WriteBytePos - 64) + saasWriteItem.WriteBytes.Index_2 |= 1 << (targetinfo.WriteBytePos - 64) } } if targetinfo.WriteUint32 != nil { - if saasWriteCmd.WriteUint32S == nil { - saasWriteCmd.WriteUint32S = &saasapi.Uint32S{} + // 转换uint32区 + if saasWriteItem.WriteUint32S == nil { + saasWriteItem.WriteUint32S = &saasapi.Uint32S{} } - saasWriteCmd.WriteUint32S.Uint32S = append(saasWriteCmd.WriteUint32S.Uint32S, *targetinfo.WriteUint32) - saasWriteCmd.WriteUint32S.Index_1 |= 1 << targetinfo.WriteUint32Pos + saasWriteItem.WriteUint32S.Uint32S = append(saasWriteItem.WriteUint32S.Uint32S, *targetinfo.WriteUint32) + saasWriteItem.WriteUint32S.Index_1 |= 1 << targetinfo.WriteUint32Pos } if targetinfo.WriteFlag != nil && targetinfo.WriteExpire != nil { - if saasWriteCmd.WriteFlagsWithExpire == nil { - saasWriteCmd.WriteFlagsWithExpire = &saasapi.FlagsWithExpire{} + // 转换flag区 + if saasWriteItem.WriteFlagsWithExpire == nil { + saasWriteItem.WriteFlagsWithExpire = &saasapi.FlagsWithExpire{} } - saasWriteCmd.WriteFlagsWithExpire.FlagsWithExpire = append( - saasWriteCmd.WriteFlagsWithExpire.FlagsWithExpire, &saasapi.FlagWithExpire{ + saasWriteItem.WriteFlagsWithExpire.FlagsWithExpire = append( + saasWriteItem.WriteFlagsWithExpire.FlagsWithExpire, &saasapi.FlagWithExpire{ Flag: *targetinfo.WriteFlag, Expire: *targetinfo.WriteExpire, }) - saasWriteCmd.WriteFlagsWithExpire.Index_1 |= 1 << targetinfo.WriteFlagWithExpirePos + saasWriteItem.WriteFlagsWithExpire.Index_1 |= 1 << targetinfo.WriteFlagWithExpirePos } } } - // 写入文件 - destWriter.WriteString(jasonMarshal.Format(saasWriteCmd)) - destWriter.WriteString("\n") - - processedLine++ - if processedLine%100000 == 0 { - fmt.Printf("\rconverted records: %v [%v]", processedLine, destName) - } - + byteBuf.WriteString(jasonMarshal.Format(saasWriteItem)) + byteBuf.WriteString("\n") } - fmt.Printf("\rconverted records: %v [%v]\n", processedLine, destName) - return nil + resultChan <- convertResult{byteBuf, len(lines)} } diff --git a/cmd/saastool/help.go b/cmd/saastool/help.go index 77f4638..4c19c2f 100644 --- a/cmd/saastool/help.go +++ b/cmd/saastool/help.go @@ -12,21 +12,19 @@ func RunHelp(args ...string) error { } const usage = ` -Usage: [[command] [arguments]] - -The commands are: +Usage: saastool COMMAND [OPTIONS] +Commands: write Write user's 'bytes / uint32s / flags' read Read user's 'bytes / uint32s / flags' - columnwrite Write columns for 'deviceid / openid' users + columnwrite Write columns for 'deviceid / openid' users - tasklist List tasks - taskcancel Cancel task - taskdetail Show task detail + convert Convert data to write format + makehash Make file hash for upload task + + task Task commands "help" is the default command. -Use "saastool [command] -help" for more information about a command. +Use "saastool COMMAND -help" for more information about a command. ` - -// strip Stripping redundant data from redis diff --git a/cmd/saastool/main.go b/cmd/saastool/main.go index 09edd3a..01f830c 100644 --- a/cmd/saastool/main.go +++ b/cmd/saastool/main.go @@ -29,14 +29,13 @@ func Run(args ...string) error { return RunColumnWrite(args...) case "convert": return RunConvert(args...) - case "tasklist": - return RunTaskList(args...) - case "taskcancel": - return RunTaskCancel(args...) - case "taskdetail": - return RunTaskDetail(args...) + case "makehash": + return RunMakeHash(args...) case "verify": return RunVerify(args...) + case "task": + return RunTask(args...) + default: err := fmt.Errorf(`unknown command "%s"`+"\n"+`Run 'saastool help' for usage`, name) slog.Warn(err.Error()) diff --git a/cmd/saastool/make_hash.go b/cmd/saastool/make_hash.go new file mode 100644 index 0000000..08e605a --- /dev/null +++ b/cmd/saastool/make_hash.go @@ -0,0 +1,215 @@ +package main + +import ( + "crypto/sha256" + "encoding/hex" + "flag" + "fmt" + "os" + "path" + "runtime" + "sort" + "sync" + + "e.coding.net/rta/public/saasapi" + "google.golang.org/protobuf/encoding/protojson" +) + +const ( + blockSizeMin = 10 * 1024 * 1024 + blockSizeMax = 200 * 1024 * 1024 +) + +type makeHashParams struct { + sourcePath string + destPath string + task *saasapi.Task +} + +// 计算任务 +type hashTask struct { + chunk []byte + index int +} + +// 计算结果 +type hashResult struct { + hash string + blockSize uint64 + index int +} + +func RunMakeHash(args ...string) error { + fs := flag.NewFlagSet("tasklocalmake", flag.ExitOnError) + sourcePath := paramSourcePath(fs) + destPath := paramDestPath(fs) + blockSize := paramBlockSize(fs) + + if err := fs.Parse(args); err != nil { + fmt.Println("command line parse error", "err", err) + return err + } + + if fs.NArg() > 0 || len(*sourcePath) == 0 || len(*destPath) == 0 { + fs.PrintDefaults() + return nil + } + + if blockSize < blockSizeMin || blockSize > blockSizeMax { + fmt.Println("block size error", "min", blockSizeMin, "max", blockSizeMax) + return nil + } + + makeHashParams := makeHashParams{ + sourcePath: *sourcePath, + destPath: *destPath, + task: &saasapi.Task{ + TaskBlockSize: blockSize, + }, + } + return doMakeHash(makeHashParams) +} + +func doMakeHash(makeHashParams makeHashParams) error { + fsInfo, err := os.Stat(makeHashParams.sourcePath) + if err != nil { + return err + } + + if !fsInfo.IsDir() { + // 如果是文件,直接计算 + return doFileHash(makeHashParams) + } + + // 读取目录下信息 + dirEntry, err := os.ReadDir(makeHashParams.sourcePath) + if err != nil { + return err + } + + // 遍历目录 + for _, dir := range dirEntry { + newParam := makeHashParams + newParam.sourcePath = path.Join(makeHashParams.sourcePath, dir.Name()) + + if dir.IsDir() { + newParam.destPath = path.Join(makeHashParams.destPath, dir.Name()) + } + + if err = doMakeHash(newParam); err != nil { + return err + } + } + + return saveTaskFile(makeHashParams) +} + +func doFileHash(makeHashParams makeHashParams) error { + sourceFile, err := os.Open(makeHashParams.sourcePath) + if err != nil { + return err + } + defer sourceFile.Close() + + fi, err := sourceFile.Stat() + if err != nil { + return err + } + + tasks := make(chan hashTask) + results := make(chan hashResult) + + // 启动工作协程 + hashMaxWorker := runtime.GOMAXPROCS(0) + for range hashMaxWorker { + go hashWorker(tasks, results) + } + + wg := sync.WaitGroup{} + wg.Add(1) + go func() { + index := 0 + buffer := make([]byte, makeHashParams.task.TaskBlockSize) + for { + n, err := sourceFile.Read(buffer) + if n > 0 { + wg.Add(1) + fmt.Printf("\rhashing file [%v], block [%v]", makeHashParams.sourcePath, index) + tasks <- hashTask{chunk: buffer[:n], index: index} + index++ + } + if err != nil { + break + } + } + close(tasks) + wg.Done() + }() + + var allResults []hashResult + go func() { + for r := range results { + allResults = append(allResults, r) + wg.Done() + } + }() + + wg.Wait() + close(results) + + // 按索引排序结果 + sort.Slice(allResults, func(i, j int) bool { + return allResults[i].index < allResults[j].index + }) + + // 输出结果 + fileInfo := &saasapi.FileInfo{ + FileName: makeHashParams.sourcePath, + FileSize: uint64(fi.Size()), + } + for _, r := range allResults { + fileInfo.FileBlocks = append(fileInfo.FileBlocks, &saasapi.FileBlock{ + BlockSha256: r.hash, + BlockLength: r.blockSize, + }) + } + makeHashParams.task.TaskFileInfos = append(makeHashParams.task.TaskFileInfos, fileInfo) + + fmt.Println("") + return nil +} + +// hash计算协程 +func hashWorker(tasks <-chan hashTask, results chan<- hashResult) { + for t := range tasks { + h := sha256.New() + h.Write(t.chunk) + hash := hex.EncodeToString(h.Sum(nil)) + results <- hashResult{hash: hash, index: t.index, blockSize: uint64(len(t.chunk))} + } +} + +func saveTaskFile(makeHashParams makeHashParams) error { + taskFile, err := os.Create(makeHashParams.destPath) + if err != nil { + return err + } + defer taskFile.Close() + + h := sha256.New() + + for _, fileInfo := range makeHashParams.task.TaskFileInfos { + for _, fileBlock := range fileInfo.FileBlocks { + h.Write([]byte(fileBlock.BlockSha256)) + } + } + + makeHashParams.task.TaskSha256 = hex.EncodeToString(h.Sum(nil)) + + _, err = taskFile.WriteString(protojson.Format(makeHashParams.task)) + if err != nil { + return err + } + + return nil +} diff --git a/cmd/saastool/params.go b/cmd/saastool/params.go index f799b81..30c95ee 100644 --- a/cmd/saastool/params.go +++ b/cmd/saastool/params.go @@ -2,31 +2,50 @@ package main import ( "flag" + "fmt" + "strconv" + "strings" ) func paramConfig(fs *flag.FlagSet) *string { return fs.String("config", "cfg.toml", "Config file.") } -func paramTargets(fs *flag.FlagSet) *string { - return fs.String("targets", "", "target setting") +func paramMap(fs *flag.FlagSet) *string { + return fs.String("map", "", "target map setting") } func paramSourcePath(fs *flag.FlagSet) *string { - return fs.String("source", "", "Data path source for write command.") + return fs.String("source", "", "Source path or filename") } func paramDestPath(fs *flag.FlagSet) *string { - return fs.String("dest", "", "Data path destination for write command.") + return fs.String("dest", "", "Destination path or filename") } func paramAppid(fs *flag.FlagSet) *string { return fs.String("appid", "", "Wechat appid") } +func paramUserids(fs *flag.FlagSet) *string { + return fs.String("userids", "", "Device ID or Wechat UserID, separated by comma") +} + func paramBatchSize(fs *flag.FlagSet) *uint { return fs.Uint("batchsize", 10000, "Batch size to sync") } +func paramBlockSize(fs *flag.FlagSet) uint64 { + bsize := fs.String("blocksize", "50M", "Block size to make hash. using size mode K, M, G, T") + num, err := ParseByteSize(*bsize) + if err != nil { + fmt.Println("Error parsing block size", "err", err) + fmt.Println("Using default 50M") + num = 50 * 1024 * 1024 + + } + return num +} + func paramAsync(fs *flag.FlagSet) *bool { return fs.Bool("async", false, "Async mode") } @@ -34,3 +53,55 @@ func paramAsync(fs *flag.FlagSet) *bool { func paramClear(fs *flag.FlagSet) *bool { return fs.Bool("clear", false, "Clear all data before write") } + +// ParseByteSize 解析字节大小字符串为字节数 +func ParseByteSize(sizeStr string) (uint64, error) { + sizeStr = strings.TrimSpace(sizeStr) + unit := "" + numStr := sizeStr + // 提取单位 + if len(sizeStr) > 1 && (sizeStr[len(sizeStr)-1] == 'B' || sizeStr[len(sizeStr)-1] == 'b') { + unit = string(sizeStr[len(sizeStr)-2:]) + numStr = sizeStr[:len(sizeStr)-2] + } else if len(sizeStr) > 0 && (sizeStr[len(sizeStr)-1] >= 'A' && sizeStr[len(sizeStr)-1] <= 'Z' || + sizeStr[len(sizeStr)-1] >= 'a' && sizeStr[len(sizeStr)-1] <= 'z') { + unit = string(sizeStr[len(sizeStr)-1]) + numStr = sizeStr[:len(sizeStr)-1] + } + + // 解析数字部分 + num, err := strconv.ParseFloat(numStr, 64) + if err != nil { + return 0, err + } + + // 根据单位计算字节数 + switch strings.ToUpper(unit) { + case "": + return uint64(num), nil + case "K", "KB": + return uint64(num * 1024), nil + case "M", "MB": + return uint64(num * 1024 * 1024), nil + case "G", "GB": + return uint64(num * 1024 * 1024 * 1024), nil + case "T", "TB": + return uint64(num * 1024 * 1024 * 1024 * 1024), nil + default: + return 0, fmt.Errorf("unknown unit: %s", unit) + } +} + +/* +func main() { + sizes := []string{"1K", "2M", "3G", "4T", "5"} + for _, sizeStr := range sizes { + size, err := ParseByteSize(sizeStr) + if err != nil { + fmt.Printf("Error parsing %s: %v\n", sizeStr, err) + } else { + fmt.Printf("%s = %d bytes\n", sizeStr, size) + } + } +} +*/ diff --git a/cmd/saastool/read.go b/cmd/saastool/read.go index d3e0474..f69ff96 100644 --- a/cmd/saastool/read.go +++ b/cmd/saastool/read.go @@ -1,5 +1,95 @@ package main +import ( + "flag" + "fmt" + "log/slog" + "net/http" + "strings" + + "e.coding.net/rta/public/saasapi" + "e.coding.net/rta/public/saasapi/pkg/saashttp" + "google.golang.org/protobuf/encoding/protojson" +) + +const ( + getIdsMax = 100 +) + +type readParams struct { + cfg *Config + appid string + userids []string + saasHttp *saashttp.SaasClient +} + func RunRead(args ...string) error { + fs := flag.NewFlagSet("read", flag.ExitOnError) + cfgFile := paramConfig(fs) + appid := paramAppid(fs) + userids := paramUserids(fs) + + if err := fs.Parse(args); err != nil { + fmt.Println("command line parse error", "err", err) + return err + } + + // 切割字符串 + idsSlice := strings.Split(*userids, ",") + + if fs.NArg() > 0 || len(idsSlice) == 0 || (len(idsSlice) == 1 && idsSlice[0] == "") || len(idsSlice) > getIdsMax { + fs.PrintDefaults() + return nil + } + + cfg, err := LoadConfigFile(*cfgFile) + if err != nil { + slog.Error("LoadConfigFile error", "err", err) + return err + } + + readParams := readParams{ + cfg: cfg, + userids: idsSlice, + appid: *appid, + saasHttp: &saashttp.SaasClient{ + Client: http.Client{}, + ApiUrls: cfg.ApiUrls, + Auth: cfg.Auth, + }, + } + + return doRead(readParams) +} + +func doRead(readParams readParams) error { + saasReq := &saasapi.SaasReq{ + Cmd: &saasapi.SaasReq_Read{ + Read: &saasapi.Read{}, + }, + } + + if readParams.appid != "" { + saasReq.UseridType = saasapi.UserIdType_OPENID + saasReq.Appid = readParams.appid + } + saasReadItems := []*saasapi.ReadItem{} + for _, userid := range readParams.userids { + saasReadItems = append(saasReadItems, &saasapi.ReadItem{ + Userid: userid, + }) + } + + saasReq.Cmd.(*saasapi.SaasReq_Read).Read.ReadItems = saasReadItems + + res, err := readParams.saasHttp.Read(saasReq) + + if err != nil { + slog.Error("submitRead error", "err", err) + return err + } + + fmt.Println(protojson.Format(res)) + return nil } diff --git a/cmd/saastool/target_cfg.go b/cmd/saastool/target_cfg.go index 55e3841..6172c38 100644 --- a/cmd/saastool/target_cfg.go +++ b/cmd/saastool/target_cfg.go @@ -5,8 +5,8 @@ import ( "os" ) -// TargetConfig 配置 -type TargetConfig struct { +// MapConfig 配置 +type MapConfig struct { Targets map[string]*Target `json:"targets"` } @@ -23,7 +23,7 @@ type Target struct { } // LoadConfigFile 加载配置文件 -func LoadTargetFile(filename string) (*TargetConfig, error) { +func LoadMapFile(filename string) (*MapConfig, error) { // 打开文件 f, err := os.Open(filename) if err != nil { @@ -31,7 +31,7 @@ func LoadTargetFile(filename string) (*TargetConfig, error) { } defer f.Close() - sc := &TargetConfig{} + sc := &MapConfig{} err = json.NewDecoder(f).Decode(sc) return sc, err diff --git a/cmd/saastool/task.go b/cmd/saastool/task.go new file mode 100644 index 0000000..d3c9330 --- /dev/null +++ b/cmd/saastool/task.go @@ -0,0 +1,49 @@ +package main + +import ( + "fmt" + "log/slog" + "strings" +) + +func RunTask(args ...string) error { + name, args := ParseCommandName(args) + + // 从参数中解析出命令 + switch name { + case "", "help": + return RunTaskHelp(args...) + case "create": + return RunTaskCreate(args...) + case "list": + return RunTaskList(args...) + case "delete": + return RunTaskDelete(args...) + case "info": + return RunTaskInfo(args...) + default: + err := fmt.Errorf(`unknown command "%s"`+"\n"+`Run 'saastool task help' for usage`, name) + slog.Warn(err.Error()) + return err + } +} + +func RunTaskHelp(args ...string) error { + fmt.Println(strings.TrimSpace(taskUsage)) + return nil +} + +const taskUsage = ` +Usage: saastoola task COMMAND [OPTIONS] + +Commands: + create + upload Read user's 'bytes / uint32s / flags' + run + delete + info + +"help" is the default command. + +Use "saastool task COMMAND -help" for more information about a command. +` diff --git a/cmd/saastool/task_cancel.go b/cmd/saastool/task_cancel.go deleted file mode 100644 index 99d5af9..0000000 --- a/cmd/saastool/task_cancel.go +++ /dev/null @@ -1,5 +0,0 @@ -package main - -func RunTaskCancel(args ...string) error { - return nil -} diff --git a/cmd/saastool/task_create.go b/cmd/saastool/task_create.go new file mode 100644 index 0000000..8a3790a --- /dev/null +++ b/cmd/saastool/task_create.go @@ -0,0 +1,5 @@ +package main + +func RunTaskCreate(args ...string) error { + return nil +} diff --git a/cmd/saastool/task_delete.go b/cmd/saastool/task_delete.go new file mode 100644 index 0000000..6cbe739 --- /dev/null +++ b/cmd/saastool/task_delete.go @@ -0,0 +1,5 @@ +package main + +func RunTaskDelete(args ...string) error { + return nil +} diff --git a/cmd/saastool/task_detail.go b/cmd/saastool/task_detail.go deleted file mode 100644 index be7d123..0000000 --- a/cmd/saastool/task_detail.go +++ /dev/null @@ -1,5 +0,0 @@ -package main - -func RunTaskDetail(args ...string) error { - return nil -} diff --git a/cmd/saastool/task_info.go b/cmd/saastool/task_info.go new file mode 100644 index 0000000..1f58b5f --- /dev/null +++ b/cmd/saastool/task_info.go @@ -0,0 +1,5 @@ +package main + +func RunTaskInfo(args ...string) error { + return nil +} diff --git a/cmd/saastool/task_run.go b/cmd/saastool/task_run.go new file mode 100644 index 0000000..709f8f9 --- /dev/null +++ b/cmd/saastool/task_run.go @@ -0,0 +1,5 @@ +package main + +func RunTaskRun(args ...string) error { + return nil +} diff --git a/cmd/saastool/write.go b/cmd/saastool/write.go index a1df702..84849a6 100644 --- a/cmd/saastool/write.go +++ b/cmd/saastool/write.go @@ -19,7 +19,6 @@ type writeParams struct { sourcePath string appid string batchSize uint - async bool clear bool saasHttp *saashttp.SaasClient } @@ -30,7 +29,6 @@ func RunWrite(args ...string) error { sourcePath := paramSourcePath(fs) appid := paramAppid(fs) batchSize := paramBatchSize(fs) - async := paramAsync(fs) clear := paramClear(fs) if err := fs.Parse(args); err != nil { @@ -53,7 +51,6 @@ func RunWrite(args ...string) error { sourcePath: *sourcePath, appid: *appid, batchSize: *batchSize, - async: *async, clear: *clear, saasHttp: &saashttp.SaasClient{ Client: http.Client{}, @@ -105,7 +102,7 @@ func doLoadFileToWrite(writeParams writeParams) error { scaner := bufio.NewScanner(file) - saasWriteCmds := []*saasapi.WriteCmd{} + saasWriteItems := []*saasapi.WriteItem{} succ := uint32(0) succTotal := uint32(0) @@ -115,29 +112,29 @@ func doLoadFileToWrite(writeParams writeParams) error { if line == "" { continue } - saasWriteCmd := &saasapi.WriteCmd{} - if err = protojson.Unmarshal([]byte(line), saasWriteCmd); err != nil { + saasWriteItem := &saasapi.WriteItem{} + if err = protojson.Unmarshal([]byte(line), saasWriteItem); err != nil { return err } - saasWriteCmds = append(saasWriteCmds, saasWriteCmd) + saasWriteItems = append(saasWriteItems, saasWriteItem) total++ - if len(saasWriteCmds) == int(writeParams.batchSize) { - if succ, _, err = submitWrite(writeParams, saasWriteCmds); err != nil { + if len(saasWriteItems) == int(writeParams.batchSize) { + if succ, _, err = submitWrite(writeParams, saasWriteItems); err != nil { return err } succTotal += succ fmt.Printf("[%v] batch_succ = %v, succ_total = %v, total_processed = %v\n", writeParams.sourcePath, succ, succTotal, total) - saasWriteCmds = saasWriteCmds[:0] + saasWriteItems = saasWriteItems[:0] } } - if len(saasWriteCmds) > 0 { - if succ, _, err = submitWrite(writeParams, saasWriteCmds); err != nil { + if len(saasWriteItems) > 0 { + if succ, _, err = submitWrite(writeParams, saasWriteItems); err != nil { return err } succTotal += succ @@ -147,12 +144,11 @@ func doLoadFileToWrite(writeParams writeParams) error { return nil } -func submitWrite(writeParams writeParams, saasWriteCmds []*saasapi.WriteCmd) (succ, total uint32, err error) { +func submitWrite(writeParams writeParams, saasWriteCmds []*saasapi.WriteItem) (succ, total uint32, err error) { saasReq := &saasapi.SaasReq{ Cmd: &saasapi.SaasReq_Write{ Write: &saasapi.Write{ IsClearAllFirst: writeParams.clear, - Async: writeParams.async, }, }, } @@ -162,10 +158,15 @@ func submitWrite(writeParams writeParams, saasWriteCmds []*saasapi.WriteCmd) (su saasReq.Appid = writeParams.appid } - saasReq.Cmd.(*saasapi.SaasReq_Write).Write.WriteCmds = saasWriteCmds + saasReq.Cmd.(*saasapi.SaasReq_Write).Write.WriteItems = saasWriteCmds total = uint32(len(saasWriteCmds)) - succ, err = writeParams.saasHttp.Write(saasReq) + res, err := writeParams.saasHttp.Write(saasReq) - return + if err != nil { + slog.Error("submitWrite error", "err", err) + return + } + + return res.GetWriteRes().GetSuccCmdCount(), total, nil } diff --git a/pkg/saashttp/httpcli.go b/pkg/saashttp/httpcli.go index 5e3e684..21500aa 100644 --- a/pkg/saashttp/httpcli.go +++ b/pkg/saashttp/httpcli.go @@ -30,32 +30,32 @@ type SaasClient struct { ResponseEncoder ResponseEncoder } -func (c *SaasClient) Write(saasReq *saasapi.SaasReq) (succ uint32, err error) { +func (c *SaasClient) Write(saasReq *saasapi.SaasReq) (saasRes *saasapi.SaasRes, err error) { postUrl := c.makeUrl(c.ApiUrls.BaseUrl, c.ApiUrls.WritePath) return c.post(postUrl, saasReq) } -func (c *SaasClient) Read(saasReq *saasapi.SaasReq) (succ uint32, err error) { +func (c *SaasClient) Read(saasReq *saasapi.SaasReq) (saasRes *saasapi.SaasRes, err error) { postUrl := c.makeUrl(c.ApiUrls.BaseUrl, c.ApiUrls.ReadPath) return c.post(postUrl, saasReq) } -func (c *SaasClient) ColumnWrite(saasReq *saasapi.SaasReq) (succ uint32, err error) { +func (c *SaasClient) ColumnWrite(saasReq *saasapi.SaasReq) (saasRes *saasapi.SaasRes, err error) { postUrl := c.makeUrl(c.ApiUrls.BaseUrl, c.ApiUrls.ColumnWritePath) return c.post(postUrl, saasReq) } -func (c *SaasClient) TaskList(saasReq *saasapi.SaasReq) (succ uint32, err error) { +func (c *SaasClient) TaskList(saasReq *saasapi.SaasReq) (saasRes *saasapi.SaasRes, err error) { postUrl := c.makeUrl(c.ApiUrls.BaseUrl, c.ApiUrls.TaskListPath) return c.post(postUrl, saasReq) } -func (c *SaasClient) TaskCancel(saasReq *saasapi.SaasReq) (succ uint32, err error) { +func (c *SaasClient) TaskCancel(saasReq *saasapi.SaasReq) (saasRes *saasapi.SaasRes, err error) { postUrl := c.makeUrl(c.ApiUrls.BaseUrl, c.ApiUrls.TaskCancelPath) return c.post(postUrl, saasReq) } -func (c *SaasClient) TaskDetail(saasReq *saasapi.SaasReq) (succ uint32, err error) { +func (c *SaasClient) TaskDetail(saasReq *saasapi.SaasReq) (saasRes *saasapi.SaasRes, err error) { postUrl := c.makeUrl(c.ApiUrls.BaseUrl, c.ApiUrls.TaskDetailPath) return c.post(postUrl, saasReq) @@ -82,17 +82,17 @@ func (c *SaasClient) makeUrl(baseUrl, path string) string { return url.String() } -func (c *SaasClient) post(url string, saasReq *saasapi.SaasReq) (succ uint32, err error) { +func (c *SaasClient) post(url string, saasReq *saasapi.SaasReq) (saasRes *saasapi.SaasRes, err error) { postBuf, err := proto.Marshal(saasReq) if err != nil { fmt.Println("marshal saas req error", err) - return 0, err + return nil, err } req, err := http.NewRequest("POST", url, bytes.NewBuffer(postBuf)) if err != nil { fmt.Println("http new request error", err) - return 0, err + return nil, err } timeStamp := strconv.FormatInt(time.Now().Unix(), 10) @@ -106,7 +106,7 @@ func (c *SaasClient) post(url string, saasReq *saasapi.SaasReq) (succ uint32, er res, err := c.Client.Do(req) if err != nil { fmt.Println("http send error", err) - return 0, err + return nil, err } defer res.Body.Close() @@ -114,27 +114,23 @@ func (c *SaasClient) post(url string, saasReq *saasapi.SaasReq) (succ uint32, er resBody, err := io.ReadAll(res.Body) if err != nil { fmt.Println("http read body error", err) - return 0, err + return nil, err } - saasRes := &saasapi.SaasRes{} + saasRes = &saasapi.SaasRes{} if c.ResponseEncoder == RESPONSE_ENCODER_PROTOBUF { err = proto.Unmarshal(resBody, saasRes) if err != nil { fmt.Println("unmarshal response body to protobuf error", err) - return 0, err + return nil, err } } else { err = json.Unmarshal(resBody, saasRes) if err != nil { fmt.Println("unmarshal response body to json error", err) - return 0, err + return nil, err } } - if saasRes.Code != saasapi.ErrorCode(saasapi.CmdErrorCode_OK) { - fmt.Println("saas api error", saasRes.Code, saasRes.Status) - return 0, err - } - return saasRes.GetSuccCmdCount(), nil + return saasRes, nil }