-
Notifications
You must be signed in to change notification settings - Fork 2k
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
[Extensions]Add query for initialized extensions #5658
Changes from all commits
0744111
063e79f
c98b98c
217fbaf
158c910
119b7c5
a58ae99
83b9e7f
b500a0f
3e52ba4
09d6137
65fe267
cc1f2d9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.extensions; | ||
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import org.opensearch.common.io.stream.StreamInput; | ||
import org.opensearch.common.io.stream.StreamOutput; | ||
import org.opensearch.transport.TransportResponse; | ||
|
||
/** | ||
* The response for getting the Extension Dependency. | ||
* | ||
* @opensearch.internal | ||
*/ | ||
public class ExtensionDependencyResponse extends TransportResponse { | ||
private List<DiscoveryExtensionNode> extensionDependencies; | ||
|
||
public ExtensionDependencyResponse(List<DiscoveryExtensionNode> extensionDependencies) { | ||
this.extensionDependencies = extensionDependencies; | ||
} | ||
|
||
public ExtensionDependencyResponse(StreamInput in) throws IOException { | ||
int size = in.readVInt(); | ||
extensionDependencies = new ArrayList<>(size); | ||
for (int i = 0; i < size; i++) { | ||
extensionDependencies.add(new DiscoveryExtensionNode(in)); | ||
} | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
out.writeVInt(extensionDependencies.size()); | ||
for (DiscoveryExtensionNode dependency : extensionDependencies) { | ||
dependency.writeTo(out); | ||
} | ||
} | ||
|
||
public List<DiscoveryExtensionNode> getExtensionDependency() { | ||
return extensionDependencies; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "ExtensionDependencyResponse{extensiondependency=" + extensionDependencies.toString() + '}'; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
ExtensionDependencyResponse that = (ExtensionDependencyResponse) o; | ||
return Objects.equals(extensionDependencies, that.extensionDependencies); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(extensionDependencies); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,12 +10,14 @@ | |
|
||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.opensearch.common.Nullable; | ||
import org.opensearch.common.io.stream.StreamInput; | ||
import org.opensearch.common.io.stream.StreamOutput; | ||
import org.opensearch.transport.TransportRequest; | ||
|
||
import java.io.IOException; | ||
import java.util.Objects; | ||
import java.util.Optional; | ||
|
||
/** | ||
* CLusterService Request for Extensibility | ||
|
@@ -24,41 +26,54 @@ | |
*/ | ||
public class ExtensionRequest extends TransportRequest { | ||
private static final Logger logger = LogManager.getLogger(ExtensionRequest.class); | ||
private ExtensionsManager.RequestType requestType; | ||
private final ExtensionsManager.RequestType requestType; | ||
private final Optional<String> uniqueId; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like there is no test class for |
||
|
||
public ExtensionRequest(ExtensionsManager.RequestType requestType) { | ||
this(requestType, null); | ||
} | ||
|
||
public ExtensionRequest(ExtensionsManager.RequestType requestType, @Nullable String uniqueId) { | ||
this.requestType = requestType; | ||
this.uniqueId = uniqueId == null ? Optional.empty() : Optional.of(uniqueId); | ||
} | ||
|
||
public ExtensionRequest(StreamInput in) throws IOException { | ||
super(in); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe Requests require the |
||
this.requestType = in.readEnum(ExtensionsManager.RequestType.class); | ||
String id = in.readOptionalString(); | ||
this.uniqueId = id == null ? Optional.empty() : Optional.of(id); | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
super.writeTo(out); | ||
out.writeEnum(requestType); | ||
out.writeOptionalString(uniqueId.orElse(null)); | ||
} | ||
|
||
public ExtensionsManager.RequestType getRequestType() { | ||
return this.requestType; | ||
} | ||
|
||
public Optional<String> getUniqueId() { | ||
return uniqueId; | ||
} | ||
|
||
public String toString() { | ||
return "ExtensionRequest{" + "requestType=" + requestType + '}'; | ||
return "ExtensionRequest{" + "requestType=" + requestType + "uniqueId=" + uniqueId + '}'; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
ExtensionRequest that = (ExtensionRequest) o; | ||
return Objects.equals(requestType, that.requestType); | ||
return Objects.equals(requestType, that.requestType) && Objects.equals(uniqueId, that.uniqueId); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(requestType); | ||
return Objects.hash(requestType, uniqueId); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,7 @@ | |
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.stream.Collectors; | ||
|
||
|
@@ -528,6 +529,88 @@ public void testHandleExtensionRequest() throws Exception { | |
assertEquals("Handler not present for the provided request", exception.getMessage()); | ||
} | ||
|
||
public void testExtensionRequest() throws Exception { | ||
ExtensionsManager.RequestType expectedRequestType = ExtensionsManager.RequestType.REQUEST_EXTENSION_DEPENDENCY_INFORMATION; | ||
|
||
// Test ExtensionRequest 2 arg constructor | ||
String expectedUniqueId = "test uniqueid"; | ||
ExtensionRequest extensionRequest = new ExtensionRequest(expectedRequestType, expectedUniqueId); | ||
assertEquals(expectedRequestType, extensionRequest.getRequestType()); | ||
assertEquals(Optional.of(expectedUniqueId), extensionRequest.getUniqueId()); | ||
|
||
// Test ExtensionRequest StreamInput constructor | ||
try (BytesStreamOutput out = new BytesStreamOutput()) { | ||
extensionRequest.writeTo(out); | ||
out.flush(); | ||
try (BytesStreamInput in = new BytesStreamInput(BytesReference.toBytes(out.bytes()))) { | ||
extensionRequest = new ExtensionRequest(in); | ||
assertEquals(expectedRequestType, extensionRequest.getRequestType()); | ||
assertEquals(Optional.of(expectedUniqueId), extensionRequest.getUniqueId()); | ||
} | ||
} | ||
|
||
// Test ExtensionRequest 1 arg constructor | ||
extensionRequest = new ExtensionRequest(expectedRequestType); | ||
assertEquals(expectedRequestType, extensionRequest.getRequestType()); | ||
assertEquals(Optional.empty(), extensionRequest.getUniqueId()); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a test to |
||
// Test ExtensionRequest StreamInput constructor | ||
try (BytesStreamOutput out = new BytesStreamOutput()) { | ||
extensionRequest.writeTo(out); | ||
out.flush(); | ||
try (BytesStreamInput in = new BytesStreamInput(BytesReference.toBytes(out.bytes()))) { | ||
extensionRequest = new ExtensionRequest(in); | ||
assertEquals(expectedRequestType, extensionRequest.getRequestType()); | ||
assertEquals(Optional.empty(), extensionRequest.getUniqueId()); | ||
} | ||
} | ||
} | ||
|
||
public void testExtensionDependencyResponse() throws Exception { | ||
String expectedUniqueId = "test uniqueid"; | ||
List<DiscoveryExtensionNode> expectedExtensionsList = new ArrayList<DiscoveryExtensionNode>(); | ||
Version expectedVersion = Version.fromString("2.0.0"); | ||
ExtensionDependency expectedDependency = new ExtensionDependency(expectedUniqueId, expectedVersion); | ||
|
||
expectedExtensionsList.add( | ||
new DiscoveryExtensionNode( | ||
"firstExtension", | ||
"uniqueid1", | ||
"uniqueid1", | ||
"myIndependentPluginHost1", | ||
"127.0.0.0", | ||
new TransportAddress(InetAddress.getByName("127.0.0.0"), 9300), | ||
new HashMap<String, String>(), | ||
Version.fromString("3.0.0"), | ||
new PluginInfo( | ||
"firstExtension", | ||
"Fake description 1", | ||
"0.0.7", | ||
Version.fromString("3.0.0"), | ||
"14", | ||
"fakeClass1", | ||
new ArrayList<String>(), | ||
false | ||
), | ||
List.of(expectedDependency) | ||
) | ||
); | ||
|
||
// Test ExtensionDependencyResponse arg constructor | ||
ExtensionDependencyResponse extensionDependencyResponse = new ExtensionDependencyResponse(expectedExtensionsList); | ||
assertEquals(expectedExtensionsList, extensionDependencyResponse.getExtensionDependency()); | ||
|
||
// Test ExtensionDependencyResponse StreamInput constructor | ||
try (BytesStreamOutput out = new BytesStreamOutput()) { | ||
extensionDependencyResponse.writeTo(out); | ||
out.flush(); | ||
try (BytesStreamInput in = new BytesStreamInput(BytesReference.toBytes(out.bytes()))) { | ||
extensionDependencyResponse = new ExtensionDependencyResponse(in); | ||
assertEquals(expectedExtensionsList, extensionDependencyResponse.getExtensionDependency()); | ||
} | ||
} | ||
} | ||
|
||
public void testEnvironmentSettingsResponse() throws Exception { | ||
|
||
// Test EnvironmentSettingsResponse arg constructor | ||
|
@@ -711,7 +794,7 @@ public void testRegisterHandler() throws Exception { | |
settings, | ||
client | ||
); | ||
verify(mockTransportService, times(8)).registerRequestHandler(anyString(), anyString(), anyBoolean(), anyBoolean(), any(), any()); | ||
verify(mockTransportService, times(9)).registerRequestHandler(anyString(), anyString(), anyBoolean(), anyBoolean(), any(), any()); | ||
|
||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@owaiskazi19 Just a heads up, but since this change was to be backported and released in 2.x, this changelog entry should have gone in the
[Unreleased 2.x]
section of this file. I'm working on cleaning up the changelog on main right now.