Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply rest type endpoint path #108

Merged
merged 9 commits into from
Oct 16, 2024
Merged

Conversation

AlexRuiz7
Copy link
Member

@AlexRuiz7 AlexRuiz7 commented Oct 16, 2024

Description

This PR includes several improvements to the Command Manager plugin:

  • Apply Restful conventions to the API endpoint. The endpoint now includes the resource in the path (/_plugins/_command-manager/commands).
  • Replace _commandmanager with _command-manager to improve readability.
  • Extract the handling of POST requests to a dedicated method.
  • Add API spec in OpenAPI format.
  • Rename logger to log for consistency and simplicity. log is a verb, while logger is a noun. Using log.[info|warn|error|debug]() is better as it explicitly implies the action being done.
  • Add timeout to the HttpRestClient.
  • More and better logging.
  • Implement a test cycle. Commands received through the API are sent back using the HttpRestClient.

image

2024-10-16T11:39:11.376+0200 [LIFECYCLE] [class org.gradle.internal.buildevents.TaskExecutionLogger] > Task :run
2024-10-16T11:39:23.171+0200 [LIFECYCLE] [org.opensearch.gradle.testclusters.RunTask] [2024-10-16T11:39:23,124][INFO ][c.w.c.r.a.RestPostCommandAction] [integTest-0] Received POST /_plugins/_command_manager/commands request id [1] from host [127.0.0.1:9200]
2024-10-16T11:39:23.171+0200 [LIFECYCLE] [org.opensearch.gradle.testclusters.RunTask] [2024-10-16T11:39:23,130][INFO ][c.w.c.u.h.HttpRestClient ] [integTest-0] Sending payload with id [Im6ylJIBRAPV3wyYQQ15] to [https://httpbin.org/post]
2024-10-16T11:39:23.272+0200 [LIFECYCLE] [org.opensearch.gradle.testclusters.RunTask] [2024-10-16T11:39:23,259][INFO ][c.w.c.r.a.RestPostCommandAction] [integTest-0] Received response to POST request with code [200]
2024-10-16T11:39:23.272+0200 [LIFECYCLE] [org.opensearch.gradle.testclusters.RunTask] [2024-10-16T11:39:23,259][INFO ][c.w.c.r.a.RestPostCommandAction] [integTest-0] Raw response:
2024-10-16T11:39:23.272+0200 [LIFECYCLE] [org.opensearch.gradle.testclusters.RunTask] {
2024-10-16T11:39:23.272+0200 [LIFECYCLE] [org.opensearch.gradle.testclusters.RunTask]   "args": {}, 
2024-10-16T11:39:23.272+0200 [LIFECYCLE] [org.opensearch.gradle.testclusters.RunTask]   "data": "{\"agent\":{\"groups\":[\"groups000\"]},\"command\":{\"source\":\"Engine\",\"user\":\"user53\",\"target\":{\"type\":\"agent\",\"id\":\"target4\"},\"action\":{\"name\":\"restart\",\"args\":[\"/path/to/executable/arg6\",\"/path/to/executable/arg6\"],\"version\":\"v4\"},\"timeout\":30,\"status\":\"PENDING\",\"order_id\":\"IW6ylJIBRAPV3wyYQQ14\",\"request_id\":\"IG6ylJIBRAPV3wyYQQ13\"}}", 
2024-10-16T11:39:23.272+0200 [LIFECYCLE] [org.opensearch.gradle.testclusters.RunTask]   "files": {}, 
2024-10-16T11:39:23.272+0200 [LIFECYCLE] [org.opensearch.gradle.testclusters.RunTask]   "form": {}, 
2024-10-16T11:39:23.272+0200 [LIFECYCLE] [org.opensearch.gradle.testclusters.RunTask]   "headers": {
2024-10-16T11:39:23.272+0200 [LIFECYCLE] [org.opensearch.gradle.testclusters.RunTask]     "Content-Type": "application/json; charset=UTF-8", 
2024-10-16T11:39:23.272+0200 [LIFECYCLE] [org.opensearch.gradle.testclusters.RunTask]     "Host": "httpbin.org", 
2024-10-16T11:39:23.272+0200 [LIFECYCLE] [org.opensearch.gradle.testclusters.RunTask]     "Transfer-Encoding": "chunked", 
2024-10-16T11:39:23.272+0200 [LIFECYCLE] [org.opensearch.gradle.testclusters.RunTask]     "User-Agent": "Apache-HttpAsyncClient/5.4 (Java/21.0.4)", 
2024-10-16T11:39:23.272+0200 [LIFECYCLE] [org.opensearch.gradle.testclusters.RunTask]     "X-Amzn-Trace-Id": "Root=1-670f89cb-5ef2aee502ba60465a48184b"
2024-10-16T11:39:23.272+0200 [LIFECYCLE] [org.opensearch.gradle.testclusters.RunTask]   }, 
2024-10-16T11:39:23.272+0200 [LIFECYCLE] [org.opensearch.gradle.testclusters.RunTask]   "json": {
2024-10-16T11:39:23.272+0200 [LIFECYCLE] [org.opensearch.gradle.testclusters.RunTask]     "agent": {
2024-10-16T11:39:23.272+0200 [LIFECYCLE] [org.opensearch.gradle.testclusters.RunTask]       "groups": [
2024-10-16T11:39:23.272+0200 [LIFECYCLE] [org.opensearch.gradle.testclusters.RunTask]         "groups000"
2024-10-16T11:39:23.272+0200 [LIFECYCLE] [org.opensearch.gradle.testclusters.RunTask]       ]
2024-10-16T11:39:23.272+0200 [LIFECYCLE] [org.opensearch.gradle.testclusters.RunTask]     }, 
2024-10-16T11:39:23.272+0200 [LIFECYCLE] [org.opensearch.gradle.testclusters.RunTask]     "command": {
2024-10-16T11:39:23.272+0200 [LIFECYCLE] [org.opensearch.gradle.testclusters.RunTask]       "action": {
2024-10-16T11:39:23.273+0200 [LIFECYCLE] [org.opensearch.gradle.testclusters.RunTask]         "args": [
2024-10-16T11:39:23.273+0200 [LIFECYCLE] [org.opensearch.gradle.testclusters.RunTask]           "/path/to/executable/arg6", 
2024-10-16T11:39:23.273+0200 [LIFECYCLE] [org.opensearch.gradle.testclusters.RunTask]           "/path/to/executable/arg6"
2024-10-16T11:39:23.273+0200 [LIFECYCLE] [org.opensearch.gradle.testclusters.RunTask]         ], 
2024-10-16T11:39:23.273+0200 [LIFECYCLE] [org.opensearch.gradle.testclusters.RunTask]         "name": "restart", 
2024-10-16T11:39:23.273+0200 [LIFECYCLE] [org.opensearch.gradle.testclusters.RunTask]         "version": "v4"
2024-10-16T11:39:23.273+0200 [LIFECYCLE] [org.opensearch.gradle.testclusters.RunTask]       }, 
2024-10-16T11:39:23.273+0200 [LIFECYCLE] [org.opensearch.gradle.testclusters.RunTask]       "order_id": "IW6ylJIBRAPV3wyYQQ14", 
2024-10-16T11:39:23.273+0200 [LIFECYCLE] [org.opensearch.gradle.testclusters.RunTask]       "request_id": "IG6ylJIBRAPV3wyYQQ13", 
2024-10-16T11:39:23.273+0200 [LIFECYCLE] [org.opensearch.gradle.testclusters.RunTask]       "source": "Engine", 
2024-10-16T11:39:23.273+0200 [LIFECYCLE] [org.opensearch.gradle.testclusters.RunTask]       "status": "PENDING", 
2024-10-16T11:39:23.273+0200 [LIFECYCLE] [org.opensearch.gradle.testclusters.RunTask]       "target": {
2024-10-16T11:39:23.273+0200 [LIFECYCLE] [org.opensearch.gradle.testclusters.RunTask]         "id": "target4", 
2024-10-16T11:39:23.273+0200 [LIFECYCLE] [org.opensearch.gradle.testclusters.RunTask]         "type": "agent"
2024-10-16T11:39:23.273+0200 [LIFECYCLE] [org.opensearch.gradle.testclusters.RunTask]       }, 
2024-10-16T11:39:23.273+0200 [LIFECYCLE] [org.opensearch.gradle.testclusters.RunTask]       "timeout": 30, 
2024-10-16T11:39:23.273+0200 [LIFECYCLE] [org.opensearch.gradle.testclusters.RunTask]       "user": "user53"
2024-10-16T11:39:23.273+0200 [LIFECYCLE] [org.opensearch.gradle.testclusters.RunTask]     }
2024-10-16T11:39:23.273+0200 [LIFECYCLE] [org.opensearch.gradle.testclusters.RunTask]   }, 
2024-10-16T11:39:23.273+0200 [LIFECYCLE] [org.opensearch.gradle.testclusters.RunTask]   "origin": "79.117.251.93", 
2024-10-16T11:39:23.273+0200 [LIFECYCLE] [org.opensearch.gradle.testclusters.RunTask]   "url": "https://httpbin.org/post"
2024-10-16T11:39:23.273+0200 [LIFECYCLE] [org.opensearch.gradle.testclusters.RunTask] }
2024-10-16T11:39:23.273+0200 [LIFECYCLE] [org.opensearch.gradle.testclusters.RunTask] 
2024-10-16T11:39:23.273+0200 [LIFECYCLE] [org.opensearch.gradle.testclusters.RunTask] [2024-10-16T11:39:23,263][INFO ][c.w.c.i.CommandIndex     ] [integTest-0] Indexing command with id [Im6ylJIBRAPV3wyYQQ15]
2024-10-16T11:39:23.373+0200 [LIFECYCLE] [org.opensearch.gradle.testclusters.RunTask] [2024-10-16T11:39:23,283][INFO ][o.o.p.PluginsService     ] [integTest-0] PluginService:onIndexModule index:[BMn5uviVSRWOptDJ72Sx8w/YoKeVJ3XTpyKX8saPaqEuA]
2024-10-16T11:39:23.474+0200 [LIFECYCLE] [org.opensearch.gradle.testclusters.RunTask] [2024-10-16T11:39:23,400][INFO ][o.o.c.m.MetadataIndexTemplateService] [integTest-0] adding template [index-template-commands] for index patterns [.commands*]
2024-10-16T11:39:23.474+0200 [LIFECYCLE] [org.opensearch.gradle.testclusters.RunTask] [2024-10-16T11:39:23,406][DEBUG][o.o.c.c.PublicationTransportHandler] [integTest-0] received diff cluster state version [3] with uuid [OcaebB72Qh2Ccl9qZdMYfA], diff size [580]
2024-10-16T11:39:23.474+0200 [LIFECYCLE] [org.opensearch.gradle.testclusters.RunTask] [2024-10-16T11:39:23,440][DEBUG][o.o.c.c.C.CoordinatorPublication] [integTest-0] publication ended successfully: Publication{term=1, version=3}
2024-10-16T11:39:23.474+0200 [LIFECYCLE] [org.opensearch.gradle.testclusters.RunTask] [2024-10-16T11:39:23,442][INFO ][c.w.c.i.CommandIndex     ] [integTest-0] Index template [index-template-commands] created successfully
2024-10-16T11:39:23.474+0200 [LIFECYCLE] [org.opensearch.gradle.testclusters.RunTask] [2024-10-16T11:39:23,447][INFO ][o.o.p.PluginsService     ] [integTest-0] PluginService:onIndexModule index:[.commands/Ph8V5qGfR_uDkQuAdqUBrA]
2024-10-16T11:39:23.474+0200 [LIFECYCLE] [org.opensearch.gradle.testclusters.RunTask] [2024-10-16T11:39:23,458][INFO ][o.o.c.m.MetadataCreateIndexService] [integTest-0] [.commands] creating index, cause [auto(bulk api)], templates [index-template-commands], shards [1]/[0]
2024-10-16T11:39:23.474+0200 [LIFECYCLE] [org.opensearch.gradle.testclusters.RunTask] [2024-10-16T11:39:23,463][WARN ][o.o.c.r.a.AllocationService] [integTest-0] Falling back to single shard assignment since batch mode disable or multiple custom allocators set
2024-10-16T11:39:23.574+0200 [LIFECYCLE] [org.opensearch.gradle.testclusters.RunTask] [2024-10-16T11:39:23,477][DEBUG][o.o.c.c.PublicationTransportHandler] [integTest-0] received diff cluster state version [4] with uuid [vn2XtNkqQuqWc1XrYV-CNw], diff size [754]
2024-10-16T11:39:23.574+0200 [LIFECYCLE] [org.opensearch.gradle.testclusters.RunTask] [2024-10-16T11:39:23,505][INFO ][o.o.p.PluginsService     ] [integTest-0] PluginService:onIndexModule index:[.commands/Ph8V5qGfR_uDkQuAdqUBrA]
2024-10-16T11:39:23.574+0200 [LIFECYCLE] [org.opensearch.gradle.testclusters.RunTask] [2024-10-16T11:39:23,562][DEBUG][o.o.c.c.C.CoordinatorPublication] [integTest-0] publication ended successfully: Publication{term=1, version=4}
2024-10-16T11:39:23.775+0200 [LIFECYCLE] [org.opensearch.gradle.testclusters.RunTask] [2024-10-16T11:39:23,719][INFO ][o.o.c.r.a.AllocationService] [integTest-0] Cluster health status changed from [YELLOW] to [GREEN] (reason: [shards started [[.commands][0]]]).
2024-10-16T11:39:23.775+0200 [LIFECYCLE] [org.opensearch.gradle.testclusters.RunTask] [2024-10-16T11:39:23,723][DEBUG][o.o.c.c.PublicationTransportHandler] [integTest-0] received diff cluster state version [5] with uuid [OmFPmkceS5CCyY-Rg1iwrA], diff size [437]
2024-10-16T11:39:23.775+0200 [LIFECYCLE] [org.opensearch.gradle.testclusters.RunTask] [2024-10-16T11:39:23,763][DEBUG][o.o.c.c.C.CoordinatorPublication] [integTest-0] publication ended successfully: Publication{term=1, version=5}
2024-10-16T11:39:23.775+0200 [LIFECYCLE] [org.opensearch.gradle.testclusters.RunTask] [2024-10-16T11:39:23,765][WARN ][o.o.c.r.a.AllocationService] [integTest-0] Falling back to single shard assignment since batch mode disable or multiple custom allocators set
2024-10-16T11:39:25.208+0200 [LIFECYCLE] [org.gradle.cache.internal.DefaultFileLockManager] 

Issues Resolved

Closes #107

@AlexRuiz7 AlexRuiz7 self-assigned this Oct 16, 2024
@AlexRuiz7 AlexRuiz7 requested a review from a team as a code owner October 16, 2024 09:06
@AlexRuiz7 AlexRuiz7 merged commit 0ecde29 into master Oct 16, 2024
1 check passed
@AlexRuiz7 AlexRuiz7 deleted the apply-rest-type-endpoint-path branch October 16, 2024 16:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Command Manager API is not Restful
2 participants