syntax = "proto3";
option go_package = "./pb";

package pb;

import "models/model_node_cluster.proto";
import "models/model_api_node.proto";
import "models/model_node.proto";
import "models/rpc_messages.proto";
import "models/model_dns_domain.proto";
import "models/model_dns_provider.proto";

service NodeClusterService {
	// 创建集群
	rpc createNodeCluster (CreateNodeClusterRequest) returns (CreateNodeClusterResponse);

	// 修改集群
	rpc updateNodeCluster (UpdateNodeClusterRequest) returns (RPCSuccess);

	// 删除集群
	rpc deleteNodeCluster (DeleteNodeClusterRequest) returns (RPCSuccess);

	// 查找单个集群信息
	rpc findEnabledNodeCluster (FindEnabledNodeClusterRequest) returns (FindEnabledNodeClusterResponse);

	// 查找集群的API节点信息
	rpc findAPINodesWithNodeCluster (FindAPINodesWithNodeClusterRequest) returns (FindAPINodesWithNodeClusterResponse);

	// 获取所有可用集群
	rpc findAllEnabledNodeClusters (FindAllEnabledNodeClustersRequest) returns (FindAllEnabledNodeClustersResponse);

	// 计算所有集群数量
	rpc countAllEnabledNodeClusters (CountAllEnabledNodeClustersRequest) returns (RPCCountResponse);

	// 列出单页集群
	rpc listEnabledNodeClusters (ListEnabledNodeClustersRequest) returns (ListEnabledNodeClustersResponse);

	// 查找集群的健康检查配置
	rpc findNodeClusterHealthCheckConfig (FindNodeClusterHealthCheckConfigRequest) returns (FindNodeClusterHealthCheckConfigResponse);

	// 修改集群健康检查设置
	rpc updateNodeClusterHealthCheck (UpdateNodeClusterHealthCheckRequest) returns (RPCSuccess);

	// 执行健康检查
	rpc executeNodeClusterHealthCheck (ExecuteNodeClusterHealthCheckRequest) returns (ExecuteNodeClusterHealthCheckResponse);

	// 计算使用某个认证的集群数量
	rpc countAllEnabledNodeClustersWithNodeGrantId (CountAllEnabledNodeClustersWithNodeGrantIdRequest) returns (RPCCountResponse);

	// 查找使用某个认证的所有集群
	rpc findAllEnabledNodeClustersWithNodeGrantId (FindAllEnabledNodeClustersWithNodeGrantIdRequest) returns (FindAllEnabledNodeClustersWithNodeGrantIdResponse);

	// 查找集群的DNS配置
	rpc findEnabledNodeClusterDNS (FindEnabledNodeClusterDNSRequest) returns (FindEnabledNodeClusterDNSResponse);

	// 计算使用某个DNS服务商的集群数量
	rpc countAllEnabledNodeClustersWithDNSProviderId (CountAllEnabledNodeClustersWithDNSProviderIdRequest) returns (RPCCountResponse);

	// 计算使用某个DNS域名的集群数量
	rpc countAllEnabledNodeClustersWithDNSDomainId (CountAllEnabledNodeClustersWithDNSDomainIdRequest) returns (RPCCountResponse);

	// 查找使用某个域名的所有集群
	rpc findAllEnabledNodeClustersWithDNSDomainId (FindAllEnabledNodeClustersWithDNSDomainIdRequest) returns (FindAllEnabledNodeClustersWithDNSDomainIdResponse);

	// 检查集群域名是否已经被使用
	rpc checkNodeClusterDNSName (CheckNodeClusterDNSNameRequest) returns (CheckNodeClusterDNSNameResponse);

	// 修改集群的域名设置
	rpc updateNodeClusterDNS (UpdateNodeClusterDNSRequest) returns (RPCSuccess);

	// 检查集群的DNS是否有变化
	rpc checkNodeClusterDNSChanges (CheckNodeClusterDNSChangesRequest) returns (CheckNodeClusterDNSChangesResponse);

	// 查找集群的TOA配置
	rpc findEnabledNodeClusterTOA (FindEnabledNodeClusterTOARequest) returns (FindEnabledNodeClusterTOAResponse);

	// 修改集群的TOA设置
	rpc updateNodeClusterTOA (UpdateNodeClusterTOARequest) returns (RPCSuccess);

	// 计算使用某个缓存策略的集群数量
	rpc countAllEnabledNodeClustersWithHTTPCachePolicyId (CountAllEnabledNodeClustersWithHTTPCachePolicyIdRequest) returns (RPCCountResponse);

	// 查找使用缓存策略的所有集群
	rpc findAllEnabledNodeClustersWithHTTPCachePolicyId (FindAllEnabledNodeClustersWithHTTPCachePolicyIdRequest) returns (FindAllEnabledNodeClustersWithHTTPCachePolicyIdResponse);

	// 计算使用某个WAF策略的集群数量
	rpc countAllEnabledNodeClustersWithHTTPFirewallPolicyId (CountAllEnabledNodeClustersWithHTTPFirewallPolicyIdRequest) returns (RPCCountResponse);

	// 查找使用某个WAF策略的所有集群
	rpc findAllEnabledNodeClustersWithHTTPFirewallPolicyId (FindAllEnabledNodeClustersWithHTTPFirewallPolicyIdRequest) returns (FindAllEnabledNodeClustersWithHTTPFirewallPolicyIdResponse);

	// 修改集群的缓存策略
	rpc updateNodeClusterHTTPCachePolicyId (UpdateNodeClusterHTTPCachePolicyIdRequest) returns (RPCSuccess);

	// 修改集群的WAF策略
	rpc updateNodeClusterHTTPFirewallPolicyId (UpdateNodeClusterHTTPFirewallPolicyIdRequest) returns (RPCSuccess);

	// 修改集群的系统服务设置
	rpc updateNodeClusterSystemService (UpdateNodeClusterSystemServiceRequest) returns (RPCSuccess);

	// 查找集群的系统服务设置
	rpc findNodeClusterSystemService (FindNodeClusterSystemServiceRequest) returns (FindNodeClusterSystemServiceResponse);

	// 获取集群中可以使用的端口
	rpc findFreePortInNodeCluster (FindFreePortInNodeClusterRequest) returns (FindFreePortInNodeClusterResponse);

	// 检查端口是否已经被使用
	rpc checkPortIsUsingInNodeCluster (CheckPortIsUsingInNodeClusterRequest) returns (CheckPortIsUsingInNodeClusterResponse);

	// 查找最近访问的集群
	rpc findLatestNodeClusters (FindLatestNodeClustersRequest) returns (FindLatestNodeClustersResponse);

	// 取得集群的配置概要信息
	rpc findEnabledNodeClusterConfigInfo (FindEnabledNodeClusterConfigInfoRequest) returns (FindEnabledNodeClusterConfigInfoResponse);
}

// 获取所有集群的信息
message FindAllEnabledNodeClustersRequest {

}

message FindAllEnabledNodeClustersResponse {
	repeated NodeCluster nodeClusters = 1;
}

// 创建集群
message CreateNodeClusterRequest {
	string name = 1;
	int64 nodeGrantId = 2;
	string installDir = 3;
	int64 dnsDomainId = 4;
	string dnsName = 5;
	int64 httpCachePolicyId = 6;
	int64 httpFirewallPolicyId = 7;
	bytes systemServicesJSON = 8; // 系统服务设置
}

message CreateNodeClusterResponse {
	int64 nodeClusterId = 1;
}

// 修改集群
message UpdateNodeClusterRequest {
	int64 nodeClusterId = 1;
	string name = 2;
	int64 nodeGrantId = 3;
	string installDir = 4;
	string timeZone = 5;
}

// 删除集群
message DeleteNodeClusterRequest {
	int64 nodeClusterId = 1;
}

// 查找单个集群信息
message FindEnabledNodeClusterRequest {
	int64 nodeClusterId = 1;
}

message FindEnabledNodeClusterResponse {
	NodeCluster nodeCluster = 1;
}

// 查找集群的API节点信息
message FindAPINodesWithNodeClusterRequest {
	int64 nodeClusterId = 1;
}

message FindAPINodesWithNodeClusterResponse {
	bool useAllAPINodes = 1;
	repeated APINode apiNodes = 2;
}

// 计算所有集群数量
message CountAllEnabledNodeClustersRequest {
	string keyword = 1;
}

// 列出单页集群
message ListEnabledNodeClustersRequest {
	int64 offset = 1;
	int64 size = 2;
	string keyword = 3;
}

message ListEnabledNodeClustersResponse {
	repeated NodeCluster nodeClusters = 1;
}

// 查找集群的健康检查配置
message FindNodeClusterHealthCheckConfigRequest {
	int64 nodeClusterId = 1;
}

message FindNodeClusterHealthCheckConfigResponse {
	bytes healthCheckJSON = 1;
}

// 修改集群健康检查设置
message UpdateNodeClusterHealthCheckRequest {
	int64 nodeClusterId = 1;
	bytes healthCheckJSON = 2;
}

// 执行健康检查
message ExecuteNodeClusterHealthCheckRequest {
	int64 nodeClusterId = 1;
}

message ExecuteNodeClusterHealthCheckResponse {
	repeated Result results = 1;

	message Result {
		Node node = 1;
		string nodeAddr = 2;
		bool isOk = 3;
		string error = 4;
		float costMs = 5;
	}
}

// 计算使用某个认证的集群数量
message CountAllEnabledNodeClustersWithNodeGrantIdRequest {
	int64 nodeGrantId = 1;
}

// 查找使用某个认证的所有集群
message FindAllEnabledNodeClustersWithNodeGrantIdRequest {
	int64 nodeGrantId = 1;
}

message FindAllEnabledNodeClustersWithNodeGrantIdResponse {
	repeated NodeCluster nodeClusters = 1;
}

// 查找集群的DNS配置
message FindEnabledNodeClusterDNSRequest {
	int64 nodeClusterId = 1;
}

message FindEnabledNodeClusterDNSResponse {
	string name = 1;
	DNSDomain domain = 2;
	DNSProvider provider = 3;
	string defaultRoute = 6;
	bool nodesAutoSync = 4;
	bool serversAutoSync = 5;
	repeated string cnameRecords = 7;
	int32 ttl = 8;
}

// 计算使用某个DNS服务商的集群数量
message CountAllEnabledNodeClustersWithDNSProviderIdRequest {
	int64 dnsProviderId = 1;
}

// 计算使用某个DNS域名的集群数量
message CountAllEnabledNodeClustersWithDNSDomainIdRequest {
	int64 dnsDomainId = 1;
}

// 查找使用某个域名的所有集群
message FindAllEnabledNodeClustersWithDNSDomainIdRequest {
	int64 dnsDomainId = 1;
}

message FindAllEnabledNodeClustersWithDNSDomainIdResponse {
	repeated NodeCluster nodeClusters = 1;
}

// 检查集群域名是否已经被使用
message CheckNodeClusterDNSNameRequest {
	int64 nodeClusterId = 1;
	string dnsName = 2;
}

message CheckNodeClusterDNSNameResponse {
	bool isUsed = 1;
}

// 修改集群的域名设置
message UpdateNodeClusterDNSRequest {
	int64 nodeClusterId = 1;
	string dnsName = 2;
	int64 dnsDomainId = 3;
	bool nodesAutoSync = 4;
	bool serversAutoSync = 5;
	repeated string cnameRecords = 6;
	int32 ttl = 7;
}

// 检查集群的DNS是否有变化
message CheckNodeClusterDNSChangesRequest {
	int64 nodeClusterId = 1;
}

message CheckNodeClusterDNSChangesResponse {
	bool isChanged = 1;
}

// 查找集群的TOA配置
message FindEnabledNodeClusterTOARequest {
	int64 nodeClusterId = 1;
}

message FindEnabledNodeClusterTOAResponse {
	bytes toaJSON = 1;
}

// 修改集群的TOA设置
message UpdateNodeClusterTOARequest {
	int64 nodeClusterId = 1;
	bytes toaJSON = 2;
}

// 计算使用某个缓存策略的集群数量
message CountAllEnabledNodeClustersWithHTTPCachePolicyIdRequest {
	int64 httpCachePolicyId = 1;
}

// 查找使用缓存策略的所有集群
message FindAllEnabledNodeClustersWithHTTPCachePolicyIdRequest {
	int64 httpCachePolicyId = 1;
}

message FindAllEnabledNodeClustersWithHTTPCachePolicyIdResponse {
	repeated NodeCluster nodeClusters = 1;
}

// 计算使用某个WAF策略的集群数量
message CountAllEnabledNodeClustersWithHTTPFirewallPolicyIdRequest {
	int64 httpFirewallPolicyId = 1;
}

// 查找使用某个WAF策略的所有集群
message FindAllEnabledNodeClustersWithHTTPFirewallPolicyIdRequest {
	int64 httpFirewallPolicyId = 1;
}

message FindAllEnabledNodeClustersWithHTTPFirewallPolicyIdResponse {
	repeated NodeCluster nodeClusters = 1;
}

// 修改集群的缓存策略
message UpdateNodeClusterHTTPCachePolicyIdRequest {
	int64 nodeClusterId = 1;
	int64 httpCachePolicyId = 2;
}

// 修改集群的WAF策略
message UpdateNodeClusterHTTPFirewallPolicyIdRequest {
	int64 nodeClusterId = 1;
	int64 httpFirewallPolicyId = 2;
}

// 修改集群的系统服务设置
message UpdateNodeClusterSystemServiceRequest {
	int64 nodeClusterId = 1;
	string type = 2;
	bytes paramsJSON = 3;
}

// 查找集群的系统服务设置
message FindNodeClusterSystemServiceRequest {
	int64 nodeClusterId = 1;
	string type = 2;
}

message FindNodeClusterSystemServiceResponse {
	bytes paramsJSON = 1;
}

// 获取集群中可以使用的端口
message FindFreePortInNodeClusterRequest {
	int64 nodeClusterId = 1;
}

message FindFreePortInNodeClusterResponse {
	int32 port = 1;
}

// 检查端口是否已经被使用
message CheckPortIsUsingInNodeClusterRequest {
	int32 port = 1;
	int64 nodeClusterId = 2;
	int64 excludeServerId = 3;
	string excludeProtocol = 4;
}

message CheckPortIsUsingInNodeClusterResponse {
	bool isUsing = 1;
}

// 查找最近访问的集群
message FindLatestNodeClustersRequest {
	int64 size = 1;
}

message FindLatestNodeClustersResponse {
	repeated NodeCluster nodeClusters = 1;
}

// 取得集群的配置概要信息
message FindEnabledNodeClusterConfigInfoRequest {
	int64 nodeClusterId = 1;
}

message FindEnabledNodeClusterConfigInfoResponse {
	bool healthCheckIsOn = 1;
	bool hasFirewallActions = 2;
	bool hasThresholds = 3;
	bool hasMessageReceivers = 4;
	bool isTOAEnabled = 5;
	bool hasMetricItems = 6;
}