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

Implement commands index template creation #82

Closed
wants to merge 32 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
f8ff61d
Adding POST endpoint
f-galland Sep 18, 2024
e44bfce
Merge branch 'master' into 69-create-command-manager-endpoint
AlexRuiz7 Sep 19, 2024
cb47c41
Revert guava dependency
AlexRuiz7 Sep 19, 2024
789fae1
Add required fields if not present in the request
f-galland Sep 19, 2024
05e1a0b
Adding PostCommandRequest class to validate input
f-galland Sep 19, 2024
117b5c0
Adding CommandDetails model class
f-galland Sep 19, 2024
b7b28d3
Adding CommandManagerService class to handle CRUD operations
f-galland Sep 19, 2024
49db3b7
Rewrite prepareRequest following opensearch's common practices
f-galland Sep 19, 2024
fbe7360
Remove unused imports
f-galland Sep 19, 2024
3491748
Change POST endpoint to /_plugins/_commandmanager
f-galland Sep 19, 2024
e5e9714
Instantiating commandManagerService from CommandManagerPlugin class
f-galland Sep 19, 2024
4755141
Removing update functionality
f-galland Sep 20, 2024
2675b9c
Generate order and request ids randomly
f-galland Sep 20, 2024
7b81541
Make the document _id be a concatenation of the orderId and requestId…
f-galland Sep 20, 2024
73328d1
Refactor
AlexRuiz7 Sep 23, 2024
4206794
Merge branch 'master' into 69-create-command-manager-endpoint
AlexRuiz7 Sep 23, 2024
434f4ba
Merge branch 'master' into 69-create-command-manager-endpoint
AlexRuiz7 Sep 24, 2024
5e597e8
More refactor
AlexRuiz7 Sep 25, 2024
64d3d45
Merge branch '69-create-command-manager-endpoint' of github.com:wazuh…
AlexRuiz7 Sep 25, 2024
698bb71
Remove unused imports
AlexRuiz7 Sep 25, 2024
e3dd5bb
Go back to using an ActionListener to create a document.
f-galland Sep 25, 2024
5505f70
Change Action.args to list of strings
AlexRuiz7 Sep 26, 2024
0d0901a
Return the operation's RestStatus
f-galland Sep 26, 2024
89bb6f5
Add logging
f-galland Sep 26, 2024
7b1988c
Add yaml REST tests
f-galland Sep 26, 2024
6379bee
Replace document's ID with UUID
AlexRuiz7 Sep 27, 2024
3408112
Make threadpool accessible to RestPostCommandAction
f-galland Sep 27, 2024
48630ab
Make document creation threaded
f-galland Sep 27, 2024
41ba7c3
Add a proper status reply
f-galland Sep 27, 2024
84f4f55
Rename old create() method
f-galland Sep 27, 2024
1278e38
Create index-template-commands on POST request
AlexRuiz7 Sep 30, 2024
01158d2
Merge branch 'master' into 42-implement-commands-index-template-creation
AlexRuiz7 Sep 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Change Action.args to list of strings
Improve endpoint response
  • Loading branch information
AlexRuiz7 committed Sep 26, 2024
commit 5505f70aa84b0a393221c77a95cd1da4df451e0e
Original file line number Diff line number Diff line change
@@ -39,7 +39,6 @@ public CommandIndex(
}

/**
*
* @param command: Command to persist to an index
* @return
*/
@@ -55,19 +54,19 @@ public RestStatus create(Command command) {
CompletableFuture<IndexResponse> inProgressFuture = new CompletableFuture<>();

client.index(
request,
new ActionListener<IndexResponse>() {
@Override
public void onResponse(IndexResponse indexResponse) {
inProgressFuture.complete(indexResponse);
}
request,
new ActionListener<>() {
@Override
public void onResponse(IndexResponse indexResponse) {
inProgressFuture.complete(indexResponse);
}

@Override
public void onFailure(Exception e) {
logger.info("Could not process command", e);
inProgressFuture.completeExceptionally(e);
@Override
public void onFailure(Exception e) {
logger.info("Could not process command", e);
inProgressFuture.completeExceptionally(e);
}
}
}
);
} catch (IOException e) {
logger.error("IOException occurred creating command details", e);
Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@
import org.opensearch.core.xcontent.XContentParser;

import java.io.IOException;
import java.util.List;

/**
* Command's action fields.
@@ -22,7 +23,7 @@ public class Action implements ToXContentObject {
public static final String ARGS = "args";
public static final String VERSION = "version";
private final String type;
private final String args;
private final List<String> args;
private final String version;

/**
@@ -32,7 +33,7 @@ public class Action implements ToXContentObject {
* @param args actual command.
* @param version version of the action.
*/
public Action(String type, String args, String version) {
public Action(String type, List<String> args, String version) {
this.type = type;
this.args = args;
this.version = version;
@@ -45,7 +46,7 @@ public Action(String type, String args, String version) {
*/
public static Action parse(XContentParser parser) throws IOException {
String type = "";
String args = "";
List<Object> args = List.of();
String version = "";

while (parser.nextToken() != XContentParser.Token.END_OBJECT) {
@@ -56,7 +57,7 @@ public static Action parse(XContentParser parser) throws IOException {
type = parser.text();
break;
case ARGS:
args = parser.text();
args = parser.list();
break;
case VERSION:
version = parser.text();
@@ -66,7 +67,10 @@ public static Action parse(XContentParser parser) throws IOException {
break;
}
}
return new Action(type, args, version);

// Cast args field Object list to String list
List<String> convertedArgsFields = (List<String>) (List<?>) (args);
return new Action(type, convertedArgsFields, version);
}

/**
@@ -83,7 +87,7 @@ public String getType() {
*
* @return args
*/
public String getArgs() {
public List<String> getArgs() {
return this.args;
}

Original file line number Diff line number Diff line change
@@ -96,7 +96,9 @@ protected RestChannelConsumer prepareRequest(
return channel -> {
try (XContentBuilder builder = channel.newBuilder()) {
builder.startObject();
builder.field("command", command.getId());
builder.field("_index", CommandManagerPlugin.COMMAND_MANAGER_INDEX_NAME);
builder.field("_id", command.getId());
builder.field("result", status.name());
builder.endObject();
channel.sendResponse(new BytesRestResponse(status, builder));
}