From d01f73304f5d244d938004668c98739133b5f5bf Mon Sep 17 00:00:00 2001 From: Joshua Palis Date: Wed, 7 Jun 2023 15:41:58 -0700 Subject: [PATCH] [Extensions] Retrieve transport service from SDKTransportService rather than ExtensionsRunner (#923) * Retrieving transport service from sdkTransportService rather than from extensionrunner Signed-off-by: Joshua Palis * Fixing affected tests Signed-off-by: Joshua Palis --------- Signed-off-by: Joshua Palis --- .../opensearch/ad/rest/RestAnomalyDetectorJobAction.java | 2 +- .../opensearch/ad/rest/RestIndexAnomalyDetectorAction.java | 2 +- .../ad/transport/ADBatchAnomalyResultTransportAction.java | 2 +- .../ad/transport/AnomalyDetectorJobTransportAction.java | 2 +- .../ad/transport/AnomalyResultTransportAction.java | 2 +- .../ad/transport/DeleteAnomalyDetectorTransportAction.java | 2 +- .../ad/transport/ForwardADTaskTransportAction.java | 2 +- .../ad/transport/GetAnomalyDetectorTransportAction.java | 2 +- .../ad/transport/IndexAnomalyDetectorTransportAction.java | 2 +- .../ad/transport/ForwardADTaskTransportActionTests.java | 6 +++++- .../transport/GetAnomalyDetectorTransportActionTests.java | 7 +++++++ .../IndexAnomalyDetectorTransportActionTests.java | 7 +++++++ 12 files changed, 28 insertions(+), 10 deletions(-) diff --git a/src/main/java/org/opensearch/ad/rest/RestAnomalyDetectorJobAction.java b/src/main/java/org/opensearch/ad/rest/RestAnomalyDetectorJobAction.java index 95ccddde1..3f6505609 100644 --- a/src/main/java/org/opensearch/ad/rest/RestAnomalyDetectorJobAction.java +++ b/src/main/java/org/opensearch/ad/rest/RestAnomalyDetectorJobAction.java @@ -191,7 +191,7 @@ private void registerJobDetailsIfNecessary(RestRequest request) throws IOExcepti requestBody.field(GetJobDetailsRequest.JOB_TYPE, AnomalyDetectorExtension.AD_JOB_TYPE); requestBody.field(GetJobDetailsRequest.JOB_PARAMETER_ACTION, ADJobParameterAction.class.getName()); requestBody.field(GetJobDetailsRequest.JOB_RUNNER_ACTION, ADJobRunnerAction.class.getName()); - requestBody.field(GetJobDetailsRequest.EXTENSION_UNIQUE_ID, extensionsRunner.getUniqueId()); + requestBody.field(GetJobDetailsRequest.EXTENSION_UNIQUE_ID, extensionsRunner.getSdkTransportService().getUniqueId()); requestBody.endObject(); Request registerJobDetailsRequest = new Request( diff --git a/src/main/java/org/opensearch/ad/rest/RestIndexAnomalyDetectorAction.java b/src/main/java/org/opensearch/ad/rest/RestIndexAnomalyDetectorAction.java index ef4591fa3..66369b0e4 100644 --- a/src/main/java/org/opensearch/ad/rest/RestIndexAnomalyDetectorAction.java +++ b/src/main/java/org/opensearch/ad/rest/RestIndexAnomalyDetectorAction.java @@ -68,7 +68,7 @@ public RestIndexAnomalyDetectorAction(ExtensionsRunner extensionsRunner, SDKRest super(extensionsRunner); this.namedXContentRegistry = extensionsRunner.getNamedXContentRegistry(); this.environmentSettings = extensionsRunner.getEnvironmentSettings(); - this.transportService = extensionsRunner.getExtensionTransportService(); + this.transportService = extensionsRunner.getSdkTransportService().getTransportService(); this.sdkRestClient = sdkRestClient; } diff --git a/src/main/java/org/opensearch/ad/transport/ADBatchAnomalyResultTransportAction.java b/src/main/java/org/opensearch/ad/transport/ADBatchAnomalyResultTransportAction.java index dc7200586..5547c8d68 100644 --- a/src/main/java/org/opensearch/ad/transport/ADBatchAnomalyResultTransportAction.java +++ b/src/main/java/org/opensearch/ad/transport/ADBatchAnomalyResultTransportAction.java @@ -35,7 +35,7 @@ public ADBatchAnomalyResultTransportAction( ADBatchTaskRunner adBatchTaskRunner ) { super(ADBatchAnomalyResultAction.NAME, actionFilters, taskManager); - this.transportService = extensionsRunner.getExtensionTransportService(); + this.transportService = extensionsRunner.getSdkTransportService().getTransportService(); this.adBatchTaskRunner = adBatchTaskRunner; } diff --git a/src/main/java/org/opensearch/ad/transport/AnomalyDetectorJobTransportAction.java b/src/main/java/org/opensearch/ad/transport/AnomalyDetectorJobTransportAction.java index 5db7d311e..5048716ef 100644 --- a/src/main/java/org/opensearch/ad/transport/AnomalyDetectorJobTransportAction.java +++ b/src/main/java/org/opensearch/ad/transport/AnomalyDetectorJobTransportAction.java @@ -66,7 +66,7 @@ public AnomalyDetectorJobTransportAction( ADTaskManager adTaskManager ) { super(AnomalyDetectorJobAction.NAME, actionFilters, taskManager); - this.transportService = extensionsRunner.getExtensionTransportService(); + this.transportService = extensionsRunner.getSdkTransportService().getTransportService(); this.client = client; this.clusterService = clusterService; this.settings = extensionsRunner.getEnvironmentSettings(); diff --git a/src/main/java/org/opensearch/ad/transport/AnomalyResultTransportAction.java b/src/main/java/org/opensearch/ad/transport/AnomalyResultTransportAction.java index d2a5fa63d..6a2e972de 100644 --- a/src/main/java/org/opensearch/ad/transport/AnomalyResultTransportAction.java +++ b/src/main/java/org/opensearch/ad/transport/AnomalyResultTransportAction.java @@ -164,7 +164,7 @@ public AnomalyResultTransportAction( ) { super(AnomalyResultAction.NAME, actionFilters, taskManager); this.extensionsRunner = extensionsRunner; - this.transportService = extensionsRunner.getExtensionTransportService(); + this.transportService = extensionsRunner.getSdkTransportService().getTransportService(); this.settings = extensionsRunner.getEnvironmentSettings(); this.sdkRestClient = sdkRestClient; this.stateManager = manager; diff --git a/src/main/java/org/opensearch/ad/transport/DeleteAnomalyDetectorTransportAction.java b/src/main/java/org/opensearch/ad/transport/DeleteAnomalyDetectorTransportAction.java index 301064c0e..91b350d65 100644 --- a/src/main/java/org/opensearch/ad/transport/DeleteAnomalyDetectorTransportAction.java +++ b/src/main/java/org/opensearch/ad/transport/DeleteAnomalyDetectorTransportAction.java @@ -80,7 +80,7 @@ public DeleteAnomalyDetectorTransportAction( ADTaskManager adTaskManager ) { super(DeleteAnomalyDetectorAction.NAME, actionFilters, taskManager); - this.transportService = extensionsRunner.getExtensionTransportService(); + this.transportService = extensionsRunner.getSdkTransportService().getTransportService(); this.client = client; this.clusterService = clusterService; this.xContentRegistry = xContentRegistry; diff --git a/src/main/java/org/opensearch/ad/transport/ForwardADTaskTransportAction.java b/src/main/java/org/opensearch/ad/transport/ForwardADTaskTransportAction.java index cbb70debb..18a510f1e 100644 --- a/src/main/java/org/opensearch/ad/transport/ForwardADTaskTransportAction.java +++ b/src/main/java/org/opensearch/ad/transport/ForwardADTaskTransportAction.java @@ -71,7 +71,7 @@ public ForwardADTaskTransportAction( ) { super(ForwardADTaskAction.NAME, actionFilters, taskManager); this.adTaskManager = adTaskManager; - this.transportService = extensionsRunner.getExtensionTransportService(); + this.transportService = extensionsRunner.getSdkTransportService().getTransportService(); this.adTaskCacheManager = adTaskCacheManager; this.featureManager = featureManager; this.stateManager = stateManager; diff --git a/src/main/java/org/opensearch/ad/transport/GetAnomalyDetectorTransportAction.java b/src/main/java/org/opensearch/ad/transport/GetAnomalyDetectorTransportAction.java index b17f3910a..d07e7d834 100644 --- a/src/main/java/org/opensearch/ad/transport/GetAnomalyDetectorTransportAction.java +++ b/src/main/java/org/opensearch/ad/transport/GetAnomalyDetectorTransportAction.java @@ -127,7 +127,7 @@ public GetAnomalyDetectorTransportAction( this.nodeFilter = nodeFilter; filterByEnabled = AnomalyDetectorSettings.FILTER_BY_BACKEND_ROLES.get(settings); clusterService.getClusterSettings().addSettingsUpdateConsumer(FILTER_BY_BACKEND_ROLES, it -> filterByEnabled = it); - this.transportService = extensionsRunner.getExtensionTransportService(); + this.transportService = extensionsRunner.getSdkTransportService().getTransportService(); this.adTaskManager = adTaskManager; } diff --git a/src/main/java/org/opensearch/ad/transport/IndexAnomalyDetectorTransportAction.java b/src/main/java/org/opensearch/ad/transport/IndexAnomalyDetectorTransportAction.java index bd7dba487..3abb16342 100644 --- a/src/main/java/org/opensearch/ad/transport/IndexAnomalyDetectorTransportAction.java +++ b/src/main/java/org/opensearch/ad/transport/IndexAnomalyDetectorTransportAction.java @@ -78,7 +78,7 @@ public IndexAnomalyDetectorTransportAction( ) { super(IndexAnomalyDetectorAction.NAME, actionFilters, taskManager); this.client = restClient; - this.transportService = extensionsRunner.getExtensionTransportService(); + this.transportService = extensionsRunner.getSdkTransportService().getTransportService(); this.clusterService = sdkClusterService; this.anomalyDetectionIndices = anomalyDetectionIndices; this.xContentRegistry = namedXContentRegistry; diff --git a/src/test/java/org/opensearch/ad/transport/ForwardADTaskTransportActionTests.java b/src/test/java/org/opensearch/ad/transport/ForwardADTaskTransportActionTests.java index 81186632a..8c97ba6af 100644 --- a/src/test/java/org/opensearch/ad/transport/ForwardADTaskTransportActionTests.java +++ b/src/test/java/org/opensearch/ad/transport/ForwardADTaskTransportActionTests.java @@ -40,6 +40,7 @@ import org.opensearch.ad.task.ADTaskCacheManager; import org.opensearch.ad.task.ADTaskManager; import org.opensearch.sdk.ExtensionsRunner; +import org.opensearch.sdk.SDKTransportService; import org.opensearch.tasks.Task; import org.opensearch.tasks.TaskManager; import org.opensearch.transport.TransportService; @@ -50,6 +51,7 @@ public class ForwardADTaskTransportActionTests extends ADUnitTestCase { private ExtensionsRunner extensionsRunner; private TaskManager taskManager; private ActionFilters actionFilters; + private SDKTransportService sdkTransportService; private TransportService transportService; private ADTaskManager adTaskManager; private ADTaskCacheManager adTaskCacheManager; @@ -66,12 +68,14 @@ public void setUp() throws Exception { extensionsRunner = mock(ExtensionsRunner.class); taskManager = mock(TaskManager.class); actionFilters = mock(ActionFilters.class); + sdkTransportService = mock(SDKTransportService.class); transportService = mock(TransportService.class); adTaskManager = mock(ADTaskManager.class); adTaskCacheManager = mock(ADTaskCacheManager.class); featureManager = mock(FeatureManager.class); stateManager = mock(NodeStateManager.class); - when(extensionsRunner.getExtensionTransportService()).thenReturn(transportService); + when(extensionsRunner.getSdkTransportService()).thenReturn(sdkTransportService); + when(sdkTransportService.getTransportService()).thenReturn(transportService); forwardADTaskTransportAction = new ForwardADTaskTransportAction( extensionsRunner, taskManager, diff --git a/src/test/java/org/opensearch/ad/transport/GetAnomalyDetectorTransportActionTests.java b/src/test/java/org/opensearch/ad/transport/GetAnomalyDetectorTransportActionTests.java index 0c3ea7e43..98c3d2c97 100644 --- a/src/test/java/org/opensearch/ad/transport/GetAnomalyDetectorTransportActionTests.java +++ b/src/test/java/org/opensearch/ad/transport/GetAnomalyDetectorTransportActionTests.java @@ -52,9 +52,11 @@ import org.opensearch.sdk.SDKClient.SDKRestClient; import org.opensearch.sdk.SDKClusterService; import org.opensearch.sdk.SDKNamedXContentRegistry; +import org.opensearch.sdk.SDKTransportService; import org.opensearch.tasks.Task; import org.opensearch.tasks.TaskManager; import org.opensearch.test.OpenSearchSingleNodeTestCase; +import org.opensearch.transport.TransportService; import com.google.common.collect.ImmutableMap; @@ -94,6 +96,11 @@ public void setUp() throws Exception { when(mockRunner.getNamedXContentRegistry()).thenReturn(sdkNamedXContentRegistry); when(sdkNamedXContentRegistry.getRegistry()).thenReturn(xContentRegistry()); + SDKTransportService mockSdkTransportService = mock(SDKTransportService.class); + TransportService mockTransportService = mock(TransportService.class); + when(mockRunner.getSdkTransportService()).thenReturn(mockSdkTransportService); + when(mockSdkTransportService.getTransportService()).thenReturn(mockTransportService); + action = new GetAnomalyDetectorTransportAction( mockRunner, mock(TaskManager.class), diff --git a/src/test/java/org/opensearch/ad/transport/IndexAnomalyDetectorTransportActionTests.java b/src/test/java/org/opensearch/ad/transport/IndexAnomalyDetectorTransportActionTests.java index 1cae8b7d0..df717f3a6 100644 --- a/src/test/java/org/opensearch/ad/transport/IndexAnomalyDetectorTransportActionTests.java +++ b/src/test/java/org/opensearch/ad/transport/IndexAnomalyDetectorTransportActionTests.java @@ -56,11 +56,13 @@ import org.opensearch.sdk.SDKClusterService; import org.opensearch.sdk.SDKClusterService.SDKClusterSettings; import org.opensearch.sdk.SDKNamedXContentRegistry; +import org.opensearch.sdk.SDKTransportService; import org.opensearch.search.SearchHit; import org.opensearch.search.SearchHits; import org.opensearch.tasks.Task; import org.opensearch.tasks.TaskManager; import org.opensearch.test.OpenSearchIntegTestCase; +import org.opensearch.transport.TransportService; import com.google.common.collect.ImmutableMap; @@ -122,6 +124,11 @@ public void setUp() throws Exception { this.mockSdkXContentRegistry = mock(SDKNamedXContentRegistry.class); when(mockSdkXContentRegistry.getRegistry()).thenReturn(xContentRegistry()); + SDKTransportService mockSdkTransportService = mock(SDKTransportService.class); + TransportService mockTransportService = mock(TransportService.class); + when(mockRunner.getSdkTransportService()).thenReturn(mockSdkTransportService); + when(mockSdkTransportService.getTransportService()).thenReturn(mockTransportService); + action = new IndexAnomalyDetectorTransportAction( mockRunner, mock(TaskManager.class),