Skip to content

Commit

Permalink
Remove unused nodeId (replaced by uniqueId) in register request
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Widdis <[email protected]>
  • Loading branch information
dbwiddis committed Aug 23, 2022
1 parent ca15c35 commit 254005b
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public void setClusterService(ClusterService clusterService) {

/**
* Initializes the {@link RestActionsRequestHandler} and {@link TransportService}. This is called during Node bootstrap.
* Lists/maps of extensions have already been initialized.
* Lists/maps of extensions have already been initialized but not yet populated.
*
* @param restController The RestController on which to register Rest Actions.
* @param transportService The Node's transport service.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,35 +23,27 @@
* @opensearch.internal
*/
public class RegisterRestActionsRequest extends TransportRequest {
private String nodeId;
private String uniqueId;
private List<String> restActions;

public RegisterRestActionsRequest(String nodeId, String uniqueId, List<String> restActions) {
this.nodeId = nodeId;
public RegisterRestActionsRequest(String uniqueId, List<String> restActions) {
this.uniqueId = uniqueId;
this.restActions = new ArrayList<>(restActions);
}

public RegisterRestActionsRequest(StreamInput in) throws IOException {
super(in);
nodeId = in.readString();
uniqueId = in.readString();
restActions = in.readStringList();
}

@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeString(nodeId);
out.writeString(uniqueId);
out.writeStringCollection(restActions);
}

public String getNodeId() {
return nodeId;
}

public String getUniqueId() {
return uniqueId;
}
Expand All @@ -62,21 +54,19 @@ public List<String> getRestActions() {

@Override
public String toString() {
return "RestActionsRequest{nodeId=" + nodeId + ", uniqueId=" + uniqueId + ", restActions=" + restActions + "}";
return "RestActionsRequest{uniqueId=" + uniqueId + ", restActions=" + restActions + "}";
}

@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null || getClass() != obj.getClass()) return false;
RegisterRestActionsRequest that = (RegisterRestActionsRequest) obj;
return Objects.equals(nodeId, that.nodeId)
&& Objects.equals(uniqueId, that.uniqueId)
&& Objects.equals(restActions, that.restActions);
return Objects.equals(uniqueId, that.uniqueId) && Objects.equals(restActions, that.restActions);
}

@Override
public int hashCode() {
return Objects.hash(nodeId, uniqueId, restActions);
return Objects.hash(uniqueId, restActions);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,10 @@ public RestActionsRequestHandler(
*/
public TransportResponse handleRegisterRestActionsRequest(RegisterRestActionsRequest restActionsRequest) throws Exception {
DiscoveryExtension discoveryExtension = extensionIdMap.get(restActionsRequest.getUniqueId());
// TODO multiple names/API lists?
// don't believe connectToNode is necessary as this was already done in EO
RestHandler handler = new RestSendToExtensionAction(restActionsRequest, discoveryExtension, transportService);
restController.registerHandler(handler);
return new RegisterRestActionsResponse(
"Registered node "
+ restActionsRequest.getNodeId()
+ ", extension "
+ restActionsRequest.getUniqueId()
+ " to handle REST Actions "
+ restActionsRequest.getRestActions()
"Registered extension " + restActionsRequest.getUniqueId() + " to handle REST Actions " + restActionsRequest.getRestActions()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -319,15 +319,14 @@ public void testHandleRegisterActionsRequest() throws Exception {
ExtensionsOrchestrator extensionsOrchestrator = new ExtensionsOrchestrator(settings, extensionDir);

extensionsOrchestrator.initializeRestActionsRequestHandler(restController, transportService);
String nodeIdStr = "uniqueid1";
String uniqueIdStr = "uniqueid1";
List<String> actionsList = List.of("GET /foo", "PUT /bar", "POST /baz");
RegisterRestActionsRequest registerActionsRequest = new RegisterRestActionsRequest(nodeIdStr, uniqueIdStr, actionsList);
RegisterRestActionsRequest registerActionsRequest = new RegisterRestActionsRequest(uniqueIdStr, actionsList);
TransportResponse response = extensionsOrchestrator.restActionsRequestHandler.handleRegisterRestActionsRequest(
registerActionsRequest
);
assertEquals(RegisterRestActionsResponse.class, response.getClass());
assertTrue(((RegisterRestActionsResponse) response).getResponse().contains(nodeIdStr));
assertTrue(((RegisterRestActionsResponse) response).getResponse().contains(uniqueIdStr));
assertTrue(((RegisterRestActionsResponse) response).getResponse().contains(actionsList.toString()));
}

Expand All @@ -338,10 +337,9 @@ public void testHandleRegisterActionsRequestWithInvalidMethod() throws Exception
ExtensionsOrchestrator extensionsOrchestrator = new ExtensionsOrchestrator(settings, extensionDir);

extensionsOrchestrator.initializeRestActionsRequestHandler(restController, transportService);
String nodeIdStr = "uniqueid1";
String uniqueIdStr = "uniqueid1";
List<String> actionsList = List.of("FOO /foo", "PUT /bar", "POST /baz");
RegisterRestActionsRequest registerActionsRequest = new RegisterRestActionsRequest(nodeIdStr, uniqueIdStr, actionsList);
RegisterRestActionsRequest registerActionsRequest = new RegisterRestActionsRequest(uniqueIdStr, actionsList);
expectThrows(
IllegalArgumentException.class,
() -> extensionsOrchestrator.restActionsRequestHandler.handleRegisterRestActionsRequest(registerActionsRequest)
Expand All @@ -355,10 +353,9 @@ public void testHandleRegisterActionsRequestWithInvalidUri() throws Exception {
ExtensionsOrchestrator extensionsOrchestrator = new ExtensionsOrchestrator(settings, extensionDir);

extensionsOrchestrator.initializeRestActionsRequestHandler(restController, transportService);
String nodeIdStr = "uniqueid1";
String uniqueIdStr = "uniqueid1";
List<String> actionsList = List.of("GET", "PUT /bar", "POST /baz");
RegisterRestActionsRequest registerActionsRequest = new RegisterRestActionsRequest(nodeIdStr, uniqueIdStr, actionsList);
RegisterRestActionsRequest registerActionsRequest = new RegisterRestActionsRequest(uniqueIdStr, actionsList);
expectThrows(
IllegalArgumentException.class,
() -> extensionsOrchestrator.restActionsRequestHandler.handleRegisterRestActionsRequest(registerActionsRequest)
Expand Down

0 comments on commit 254005b

Please sign in to comment.