Skip to content

Commit

Permalink
feat: update rust polaris-spec (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
daheige authored May 7, 2023
1 parent f357a53 commit a102d6e
Show file tree
Hide file tree
Showing 8 changed files with 160 additions and 18 deletions.
8 changes: 4 additions & 4 deletions source/rust/polaris-specification/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "polaris-specification"
version = "0.1.1"
version = "0.1.2"
edition = "2021"
authors = ["https://github.com/polarismesh"]
license = "MIT OR Apache-2.0"
Expand All @@ -14,9 +14,9 @@ categories = ["config", "asynchronous", "development-tools"]

[dependencies]
bytes = "1.4.0"
prost = "0.11"
prost = "0.11.9"
# Only necessary if using Protobuf well-known types:
prost-types = "0.11"
prost-types = "0.11.9"

[build-dependencies]
prost-build = "0.11"
prost-build = "0.11.9"
1 change: 1 addition & 0 deletions source/rust/polaris-specification/proto/code.proto
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ enum Code {
InvalidWatchConfigFileFormat = 400806;
NotFoundResourceConfigFile = 400807;
InvalidConfigFileTemplateName = 400808;
EncryptConfigFileException = 400809;

// auth codes
InvalidUserOwners = 400410;
Expand Down
8 changes: 8 additions & 0 deletions source/rust/polaris-specification/proto/config_file.proto
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ message ConfigFile {
google.protobuf.StringValue modify_by = 13;
google.protobuf.StringValue release_time = 14;
google.protobuf.StringValue release_by = 15;
// 是否为加密配置文件
google.protobuf.BoolValue is_encrypted = 16;
}

message ConfigFileTag {
Expand Down Expand Up @@ -106,6 +108,12 @@ message ClientConfigFileInfo {
google.protobuf.StringValue content = 4;
google.protobuf.UInt64Value version = 5;
google.protobuf.StringValue md5 = 6;
// 是否为加密配置文件
google.protobuf.BoolValue is_encrypted = 7;
// 数据密钥,用于加密配置文件
google.protobuf.StringValue data_key = 8;
// 公钥,用于加密数据密钥
google.protobuf.StringValue public_key = 9;
}

message ClientWatchConfigFileRequest {
Expand Down
20 changes: 12 additions & 8 deletions source/rust/polaris-specification/proto/grpcapi.proto
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,27 @@ import "client.proto";
import "service.proto";
import "request.proto";
import "response.proto";
import "heartbeat.proto";

option go_package = "github.com/polarismesh/specification/source/go/api/v1/service_manage";
option java_package = "com.tencent.polaris.specification.api.v1.service.manage";
option java_outer_classname = "PolarisGRPCService";

service PolarisGRPC {
// 客户端上报
rpc ReportClient(Client) returns(Response) {}

rpc ReportClient(Client) returns (Response) {}
// 被调方注册服务实例
rpc RegisterInstance(Instance) returns(Response) {}
rpc RegisterInstance(Instance) returns (Response) {}
// 被调方反注册服务实例
rpc DeregisterInstance(Instance) returns(Response) {}

rpc DeregisterInstance(Instance) returns (Response) {}
// 统一发现接口
rpc Discover(stream DiscoverRequest) returns(stream DiscoverResponse) {}

rpc Discover(stream DiscoverRequest) returns (stream DiscoverResponse) {}
// 被调方上报心跳
rpc Heartbeat(Instance) returns(Response) {}
rpc Heartbeat(Instance) returns (Response) {}
// 被调方批量上报心跳
rpc BatchHeartbeat(stream HeartbeatsRequest) returns (stream HeartbeatsResponse) {}
// 批量获取心跳记录
rpc BatchGetHeartbeat(GetHeartbeatsRequest) returns (GetHeartbeatsResponse) {}
// 批量删除心跳记录
rpc BatchDelHeartbeat(DelHeartbeatsRequest) returns (DelHeartbeatsResponse) {}
}
47 changes: 47 additions & 0 deletions source/rust/polaris-specification/proto/heartbeat.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
syntax = "proto3";

package v1;

import "service.proto";

option go_package = "github.com/polarismesh/specification/source/go/api/v1/service_manage";
option java_package = "com.tencent.polaris.specification.api.v1.service.manage";

message HeartbeatRecord {
string instanceId = 1 [ json_name = "instance_id" ];
reserved 2 to 5;
int64 lastHeartbeatSec = 6 [ json_name = "last_heartbeat_sec" ];
bool exist = 7 [ json_name = "exist" ];
}

message InstanceHeartbeat {
string instanceId = 1 [ json_name = "instance_id" ];
string service = 2 [ json_name = "service" ];
string namespace = 3 [ json_name = "namespace" ];
string host = 4 [ json_name = "host" ];
uint32 port = 5 [ json_name = "port" ];
}

message HeartbeatsRequest {
repeated InstanceHeartbeat heartbeats = 1 [ json_name = "heartbeats" ];
}

message HeartbeatsResponse {
}

message GetHeartbeatsRequest {
repeated string instanceIds = 1 [ json_name = "instance_ids" ];
}

message GetHeartbeatsResponse {
repeated HeartbeatRecord records = 1 [ json_name = "records" ];
}

message DelHeartbeatsRequest {
repeated string instanceIds = 1 [ json_name = "instance_ids" ];
}

message DelHeartbeatsResponse {
uint32 code = 1;
string info = 2;
}
3 changes: 2 additions & 1 deletion source/rust/polaris-specification/proto/response.proto
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ message DiscoverResponse {
repeated Service services = 9;
repeated Namespace namespaces = 10;
FaultDetector faultDetector = 11;
Service aliasFor = 12;
reserved 12 to 20;
Service aliasFor = 21;
}


Expand Down
15 changes: 11 additions & 4 deletions source/rust/polaris-specification/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
pub mod v1 {
// The name "messages" corresponds with the `package` name in the `.proto`
// include!(concat!(env!("OUT_DIR"), "/v1.rs"));
include!("v1.rs");
pub mod v1;

#[test]
fn it_works() {
println!("ok");
let r = v1::ConfigSimpleResponse {
code: Some(0),
info: Some("success".to_string()),
};

println!("{:?}", r);
}
76 changes: 75 additions & 1 deletion source/rust/polaris-specification/src/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ pub struct ConfigFile {
pub release_time: ::core::option::Option<::prost::alloc::string::String>,
#[prost(message, optional, tag = "15")]
pub release_by: ::core::option::Option<::prost::alloc::string::String>,
/// 是否为加密配置文件
#[prost(message, optional, tag = "16")]
pub is_encrypted: ::core::option::Option<bool>,
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
Expand Down Expand Up @@ -177,6 +180,15 @@ pub struct ClientConfigFileInfo {
pub version: ::core::option::Option<u64>,
#[prost(message, optional, tag = "6")]
pub md5: ::core::option::Option<::prost::alloc::string::String>,
/// 是否为加密配置文件
#[prost(message, optional, tag = "7")]
pub is_encrypted: ::core::option::Option<bool>,
/// 数据密钥,用于加密配置文件
#[prost(message, optional, tag = "8")]
pub data_key: ::core::option::Option<::prost::alloc::string::String>,
/// 公钥,用于加密数据密钥
#[prost(message, optional, tag = "9")]
pub public_key: ::core::option::Option<::prost::alloc::string::String>,
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
Expand Down Expand Up @@ -865,6 +877,7 @@ pub enum Code {
InvalidWatchConfigFileFormat = 400806,
NotFoundResourceConfigFile = 400807,
InvalidConfigFileTemplateName = 400808,
EncryptConfigFileException = 400809,
/// auth codes
InvalidUserOwners = 400410,
InvalidUserId = 400411,
Expand Down Expand Up @@ -1040,6 +1053,7 @@ impl Code {
Code::InvalidWatchConfigFileFormat => "InvalidWatchConfigFileFormat",
Code::NotFoundResourceConfigFile => "NotFoundResourceConfigFile",
Code::InvalidConfigFileTemplateName => "InvalidConfigFileTemplateName",
Code::EncryptConfigFileException => "EncryptConfigFileException",
Code::InvalidUserOwners => "InvalidUserOwners",
Code::InvalidUserId => "InvalidUserID",
Code::InvalidUserPassword => "InvalidUserPassword",
Expand Down Expand Up @@ -1223,6 +1237,7 @@ impl Code {
"InvalidWatchConfigFileFormat" => Some(Self::InvalidWatchConfigFileFormat),
"NotFoundResourceConfigFile" => Some(Self::NotFoundResourceConfigFile),
"InvalidConfigFileTemplateName" => Some(Self::InvalidConfigFileTemplateName),
"EncryptConfigFileException" => Some(Self::EncryptConfigFileException),
"InvalidUserOwners" => Some(Self::InvalidUserOwners),
"InvalidUserID" => Some(Self::InvalidUserId),
"InvalidUserPassword" => Some(Self::InvalidUserPassword),
Expand Down Expand Up @@ -3490,7 +3505,7 @@ pub struct DiscoverResponse {
pub namespaces: ::prost::alloc::vec::Vec<Namespace>,
#[prost(message, optional, tag = "11")]
pub fault_detector: ::core::option::Option<FaultDetector>,
#[prost(message, optional, tag = "12")]
#[prost(message, optional, tag = "21")]
pub alias_for: ::core::option::Option<Service>,
}
/// Nested message and enum types in `DiscoverResponse`.
Expand Down Expand Up @@ -3568,3 +3583,62 @@ pub struct InstanceLabels {
#[prost(map = "string, message", tag = "1")]
pub labels: ::std::collections::HashMap<::prost::alloc::string::String, StringList>,
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct HeartbeatRecord {
#[prost(string, tag = "1")]
pub instance_id: ::prost::alloc::string::String,
#[prost(int64, tag = "6")]
pub last_heartbeat_sec: i64,
#[prost(bool, tag = "7")]
pub exist: bool,
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct InstanceHeartbeat {
#[prost(string, tag = "1")]
pub instance_id: ::prost::alloc::string::String,
#[prost(string, tag = "2")]
pub service: ::prost::alloc::string::String,
#[prost(string, tag = "3")]
pub namespace: ::prost::alloc::string::String,
#[prost(string, tag = "4")]
pub host: ::prost::alloc::string::String,
#[prost(uint32, tag = "5")]
pub port: u32,
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct HeartbeatsRequest {
#[prost(message, repeated, tag = "1")]
pub heartbeats: ::prost::alloc::vec::Vec<InstanceHeartbeat>,
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct HeartbeatsResponse {}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct GetHeartbeatsRequest {
#[prost(string, repeated, tag = "1")]
pub instance_ids: ::prost::alloc::vec::Vec<::prost::alloc::string::String>,
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct GetHeartbeatsResponse {
#[prost(message, repeated, tag = "1")]
pub records: ::prost::alloc::vec::Vec<HeartbeatRecord>,
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct DelHeartbeatsRequest {
#[prost(string, repeated, tag = "1")]
pub instance_ids: ::prost::alloc::vec::Vec<::prost::alloc::string::String>,
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct DelHeartbeatsResponse {
#[prost(uint32, tag = "1")]
pub code: u32,
#[prost(string, tag = "2")]
pub info: ::prost::alloc::string::String,
}

0 comments on commit a102d6e

Please sign in to comment.