You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
124 lines
3.3 KiB
124 lines
3.3 KiB
syntax = "proto3";
|
|
|
|
package et_rpc;
|
|
option go_package = "/pb";
|
|
|
|
message NodeArgs{
|
|
string id = 1; // 节点ID
|
|
string addr = 2; // 节点地址
|
|
int32 load = 3; // 节点荷载
|
|
string resource_json = 4; // 资源使用情况JSON
|
|
int32 weight = 5; // 权重
|
|
NodeState status = 6; // 节点状态
|
|
RPCReplyCode err_code = 7; // 错误代码
|
|
string err_message = 8; // 错误信息
|
|
}
|
|
|
|
message NodeResponse {
|
|
string id = 1;
|
|
string addr = 2;
|
|
RPCReplyCode err_code = 3;
|
|
string err_message = 4;
|
|
}
|
|
|
|
message NodeRegistrationRequest {
|
|
string node_id = 1;
|
|
string node_addr = 2;
|
|
}
|
|
|
|
message NodeStatusRequest {
|
|
string node_id = 1;
|
|
}
|
|
|
|
message NodeStatusResponse {
|
|
string node_id = 1;
|
|
string status = 2; // 例如 "active", "inactive"
|
|
}
|
|
|
|
// 枚举定义
|
|
enum NodeState {
|
|
UNKNOWN = 0;
|
|
ACTIVE = 1;
|
|
INACTIVE = 2;
|
|
}
|
|
|
|
enum RPCReplyCode {
|
|
SUCCESS = 0;
|
|
FAILURE = 1;
|
|
}
|
|
|
|
// 定义键值对消息
|
|
message KeyValue {
|
|
string key = 1; // 键
|
|
double value = 2; // 值
|
|
}
|
|
|
|
// 定义AggData消息
|
|
message AggData {
|
|
string date = 1; // 使用protobuf的时间戳类型
|
|
int32 sensor_id = 2; // SensorId
|
|
int32 struct_id = 3; // StructId
|
|
int32 factor_id = 4; // FactorId
|
|
int32 agg_type_id = 5; // 聚集类型
|
|
int32 agg_method_id = 6; // 聚集方法
|
|
repeated KeyValue agg = 7; // 聚集数据
|
|
repeated KeyValue changed = 8; // 变化量
|
|
string thing_id = 9; // ThingId
|
|
}
|
|
|
|
|
|
|
|
message NodeRequest{
|
|
string id = 1;
|
|
string address = 2;
|
|
repeated string thing_ids = 3;
|
|
}
|
|
|
|
message RpcResponse {
|
|
enum Status {
|
|
SUCCESS = 0; // 请求成功
|
|
FAILURE = 1; // 请求失败
|
|
INVALID_ARGUMENT = 2; // 无效参数
|
|
NOT_FOUND = 3; // 未找到
|
|
INTERNAL_ERROR = 4; // 内部错误
|
|
// 可以根据需要添加更多状态
|
|
}
|
|
|
|
Status status = 1; // 请求状态
|
|
string error_message = 2; // 错误信息,如果请求失败则返回具体的错误信息
|
|
}
|
|
|
|
message HandleDataResponse{
|
|
enum Status {
|
|
SUCCESS = 0; // 请求成功
|
|
FAILURE = 1; // 请求失败
|
|
INVALID_ARGUMENT = 2; // 无效参数
|
|
INTERNAL_ERROR = 4; // 内部错误
|
|
// 可以根据需要添加更多状态
|
|
}
|
|
|
|
string addr = 1; // 节点地址
|
|
int32 load = 2; // 节点荷载
|
|
Status status = 3; // 请求状态
|
|
string error_message = 4; // 错误信息,如果请求失败则返回具体的错误信息
|
|
}
|
|
|
|
message HandleDataRequest {
|
|
string id = 1;
|
|
repeated string messages = 2;
|
|
}
|
|
|
|
// NodeService 定义
|
|
service NodeService {
|
|
// 处理 Iota 数据并返回节点响应
|
|
rpc HandleIotaData(HandleDataRequest) returns (HandleDataResponse);
|
|
// 处理聚集数据并返回节点响应
|
|
rpc HandleAggData(HandleDataRequest) returns (HandleDataResponse);
|
|
}
|
|
|
|
// MasterService 定义
|
|
service MasterService {
|
|
rpc RegisterNode(NodeRequest) returns (RpcResponse);
|
|
rpc HeartbeatNode(NodeRequest) returns (RpcResponse);
|
|
rpc UnregisterNode(NodeRequest) returns (RpcResponse);
|
|
}
|
|
|