forked from erda-project/erda
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Rule engine set up, add expr ruleset executor, outgoing API, js…
…onnet … (erda-project#5253) * Rule engine set up, add expr ruleset executor, outgoing API, jsonnet parser. * Update table name and fix import. * Extract outgoing api, add dingTalk action. * Move to dop, code refactor. * Fix action output set.
- Loading branch information
Showing
15 changed files
with
1,340 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
CREATE TABLE IF NOT EXISTS `erda_rule` ( | ||
`id` varchar(36) NOT NULL COMMENT 'primary key', | ||
`created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'created time', | ||
`updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'updated time', | ||
`name` varchar(191) NOT NULL DEFAULT '' COMMENT 'name', | ||
`scope` varchar(191) NOT NULL DEFAULT '' COMMENT 'scope', | ||
`scope_id` varchar(191) NOT NULL DEFAULT '' COMMENT 'scope id', | ||
`event_type` varchar(191) NOT NULL DEFAULT '' COMMENT 'event type', | ||
`code` varchar(1024) NOT NULL DEFAULT '' COMMENT 'code', | ||
`params` varchar(2048) NOT NULL DEFAULT '' COMMENT 'actions', | ||
`enabled` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'enabled', | ||
`updator` varchar(191) NOT NULL DEFAULT '' COMMENT 'updator', | ||
`soft_deleted_at` bigint(20) NOT NULL DEFAULT '0' COMMENT 'deleted at', | ||
PRIMARY KEY (`id`), | ||
KEY `idx_scope` (`scope`,`scope_id`, `event_type`) | ||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='erda rule'; | ||
|
||
CREATE TABLE IF NOT EXISTS `erda_rule_exec_history` ( | ||
`id` varchar(36) NOT NULL COMMENT 'primary key', | ||
`created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'created time', | ||
`updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'updated time', | ||
`scope` varchar(191) NOT NULL DEFAULT '' COMMENT 'scope', | ||
`scope_id` varchar(191) NOT NULL DEFAULT '' COMMENT 'scope id', | ||
`rule_id` varchar(36) NOT NULL DEFAULT '' COMMENT 'rule_id', | ||
`code` varchar(1024) NOT NULL DEFAULT '' COMMENT 'code', | ||
`env` varchar(2048) NOT NULL DEFAULT '' COMMENT 'env', | ||
`succeed` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'succeed', | ||
`action_output` varchar(2048) NOT NULL DEFAULT '' COMMENT 'action output info', | ||
`soft_deleted_at` bigint(20) NOT NULL DEFAULT '0' COMMENT 'deleted at', | ||
PRIMARY KEY (`id`), | ||
KEY `idx_rule_id` (`rule_id`), | ||
KEY `idx_scope` (`scope`,`scope_id`) | ||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='erda rule execution history'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,219 @@ | ||
syntax = "proto3"; | ||
|
||
package erda.dop.rule; | ||
option go_package = "github.com/erda-project/erda-proto-go/dop/rule/pb"; | ||
import "google/api/annotations.proto"; | ||
import "google/protobuf/struct.proto"; | ||
import "google/protobuf/timestamp.proto"; | ||
import "common/openapi.proto"; | ||
|
||
service RuleService { | ||
option (erda.common.openapi_service) = { | ||
service: "dop", | ||
auth: { | ||
check_login: true, | ||
check_token: true, | ||
} | ||
}; | ||
|
||
rpc Fire(FireRequest) returns (FireResponse) { | ||
option (google.api.http) = { | ||
post: "/api/rules/actions/fire", | ||
}; | ||
option (erda.common.openapi) = { | ||
path: "/api/rules/actions/fire", | ||
}; | ||
}; | ||
|
||
rpc CreateRule(CreateRuleRequest) returns (CreateRuleResponse) { | ||
option (google.api.http) = { | ||
post: "/api/rules", | ||
}; | ||
option (erda.common.openapi) = { | ||
path: "/api/rules", | ||
}; | ||
}; | ||
|
||
rpc GetRule(GetRuleRequest) returns (GetRuleResponse) { | ||
option (google.api.http) = { | ||
get: "/api/rules/{id}", | ||
}; | ||
option (erda.common.openapi) = { | ||
path: "/api/rules/{id}", | ||
}; | ||
}; | ||
|
||
rpc UpdateRule(UpdateRuleRequest) returns (UpdateRuleResponse) { | ||
option (google.api.http) = { | ||
put: "/api/rules/{id}", | ||
}; | ||
option (erda.common.openapi) = { | ||
path: "/api/rules/{id}", | ||
}; | ||
}; | ||
|
||
rpc ListRules(ListRulesRequest) returns (ListRulesResponse) { | ||
option (google.api.http) = { | ||
get: "/api/rules", | ||
}; | ||
option (erda.common.openapi) = { | ||
path: "/api/rules", | ||
}; | ||
}; | ||
|
||
rpc DeleteRule(DeleteRuleRequest) returns (DeleteRuleResponse) { | ||
option (google.api.http) = { | ||
delete: "/api/rules/{id}", | ||
}; | ||
option (erda.common.openapi) = { | ||
path: "/api/rules/{id}", | ||
}; | ||
}; | ||
|
||
rpc ListRuleExecHistory(ListRuleExecHistoryRequest) returns (ListRuleExecHistoryResponse) { | ||
option (google.api.http) = { | ||
get: "/api/rules/actions/list-exec-history", | ||
}; | ||
option (erda.common.openapi) = { | ||
path: "/api/rules/actions/list-exec-history", | ||
}; | ||
}; | ||
} | ||
|
||
message FireRequest { | ||
string scope = 1; | ||
string scopeID = 2; | ||
string eventType = 3; | ||
map<string, google.protobuf.Value> env = 4; | ||
} | ||
|
||
message Config { | ||
optional string code = 2; | ||
map<string, google.protobuf.Value> env = 4; | ||
map<string, google.protobuf.Value> params = 5; | ||
} | ||
|
||
message FireResponse { | ||
repeated bool output = 1; | ||
} | ||
|
||
message CreateRuleRequest { | ||
string scope = 1; | ||
string scopeID = 2; | ||
string eventType = 3; | ||
optional string code = 4; | ||
string name = 5; | ||
ActionParams params = 6; | ||
bool enabled = 7; | ||
} | ||
|
||
message CreateRuleResponse {} | ||
|
||
message GetRuleRequest { | ||
string id = 1; | ||
} | ||
|
||
message GetRuleResponse { | ||
Rule data = 1; | ||
repeated string userIDs = 2; | ||
} | ||
|
||
message Rule { | ||
string id = 1; | ||
string name = 2; | ||
string scope = 3; | ||
string scopeID = 4; | ||
string eventType = 5; | ||
string code = 6; | ||
ActionParams params = 7; | ||
bool enabled = 8; | ||
string updator = 9; | ||
google.protobuf.Timestamp createdAt = 10; | ||
google.protobuf.Timestamp updatedAt = 11; | ||
} | ||
|
||
message ActionParams { | ||
repeated ActionNode nodes = 1; | ||
} | ||
|
||
message ActionNode { | ||
DingTalkConfig dingTalk = 1; | ||
string snippet = 2; | ||
} | ||
|
||
message DingTalkConfig { | ||
string webhook = 1; | ||
string signature = 2; | ||
} | ||
|
||
message UpdateRuleRequest { | ||
string id = 1; | ||
string scope = 2; | ||
string scopeID = 3; | ||
string code = 4; | ||
string eventType = 5; | ||
optional bool enabled = 6; | ||
string name = 7; | ||
ActionParams params = 8; | ||
} | ||
|
||
message UpdateRuleResponse {} | ||
|
||
message ListRulesRequest { | ||
string scope = 1; | ||
string scopeID = 2; | ||
string eventType = 3; | ||
optional bool enabled = 4; | ||
string name = 5; | ||
string updator = 6; | ||
int64 pageNo = 7; | ||
int64 pageSize = 8; | ||
} | ||
|
||
message ListRulesResponse { | ||
ListRulesResponseData data = 1; | ||
repeated string userIDs = 2; | ||
} | ||
|
||
message ListRulesResponseData { | ||
int64 total = 1; | ||
repeated Rule list = 2; | ||
} | ||
|
||
message DeleteRuleRequest { | ||
string id = 1; | ||
} | ||
|
||
message DeleteRuleResponse {} | ||
|
||
message ListRuleExecHistoryRequest { | ||
string scope = 1; | ||
string scopeID = 2; | ||
string eventType = 3; | ||
int64 pageNo = 4; | ||
int64 pageSize = 5; | ||
string ruleID = 6; | ||
optional bool succeed = 7; | ||
} | ||
|
||
message ListRuleExecHistoryResponse { | ||
ListRuleExecHistoryResponseData data = 1; | ||
repeated string userIDs = 2; | ||
} | ||
|
||
message ListRuleExecHistoryResponseData { | ||
int64 total = 1; | ||
repeated RuleExecHistory list = 2; | ||
} | ||
|
||
message RuleExecHistory { | ||
string id = 1; | ||
google.protobuf.Timestamp createdAt = 11; | ||
string scope = 3; | ||
string scopeID = 4; | ||
string ruleID = 5; | ||
string code = 6; | ||
google.protobuf.Value env = 7; | ||
bool succeed = 8; | ||
string actionOutput = 9; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.