Skip to content

Commit 7da4a1b

Browse files
Conforms to SPI model
Signed-off-by: Darshit Chanpura <dchanp@amazon.com>
1 parent 074d29a commit 7da4a1b

11 files changed

+9
-391
lines changed

build.gradle

+2-1
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ dependencies {
115115
implementation "org.opensearch:opensearch:${opensearch_version}"
116116
compileOnly "org.opensearch.plugin:opensearch-scripting-painless-spi:${opensearch_version}"
117117
compileOnly "org.opensearch:opensearch-job-scheduler-spi:${job_scheduler_version}"
118+
compileOnly "org.opensearch:opensearch-resource-sharing-spi:${opensearch_build}"
118119
implementation "org.opensearch:common-utils:${common_utils_version}"
119120
implementation "org.opensearch.client:opensearch-rest-client:${opensearch_version}"
120121
compileOnly group: 'com.google.guava', name: 'guava', version:'32.1.3-jre'
@@ -205,7 +206,7 @@ opensearchplugin {
205206
name 'opensearch-anomaly-detection'
206207
description 'OpenSearch anomaly detector plugin'
207208
classname 'org.opensearch.timeseries.TimeSeriesAnalyticsPlugin'
208-
extendedPlugins = ['lang-painless', 'opensearch-job-scheduler']
209+
extendedPlugins = ['lang-painless', 'opensearch-job-scheduler', 'opensearch-security;optional=true']
209210
}
210211

211212
// Handle case where older versions of esplugin doesn't expose the joda time version it uses

src/main/java/org/opensearch/ad/transport/IndexAnomalyDetectorTransportAction.java

+1-6
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import static org.opensearch.ad.constant.ADCommonMessages.FAIL_TO_CREATE_DETECTOR;
1515
import static org.opensearch.ad.constant.ADCommonMessages.FAIL_TO_UPDATE_DETECTOR;
1616
import static org.opensearch.ad.settings.AnomalyDetectorSettings.AD_FILTER_BY_BACKEND_ROLES;
17-
import static org.opensearch.timeseries.util.ParseUtils.*;
17+
import static org.opensearch.timeseries.util.ParseUtils.getConfig;
1818
import static org.opensearch.timeseries.util.RestHandlerUtils.wrapRestActionListener;
1919

2020
import java.util.List;
@@ -178,11 +178,6 @@ protected void adExecute(
178178
);
179179
indexAnomalyDetectorActionHandler.start(listener);
180180
}, listener);
181-
182-
// This call was added to ensure that existing functionality of sharing the resource via backend_role exists
183-
// TODO 3.0 and later the following must be removed and a new REST API where user must explicitly share the detector should be
184-
// exposed
185-
shareResourceWithBackendRoles(detectorId, user, listener);
186181
}
187182

188183
private void checkIndicesAndExecute(

src/main/java/org/opensearch/forecast/transport/IndexForecasterTransportAction.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
import static org.opensearch.forecast.constant.ForecastCommonMessages.FAIL_TO_CREATE_FORECASTER;
1515
import static org.opensearch.forecast.constant.ForecastCommonMessages.FAIL_TO_UPDATE_FORECASTER;
1616
import static org.opensearch.forecast.settings.ForecastSettings.FORECAST_FILTER_BY_BACKEND_ROLES;
17-
import static org.opensearch.timeseries.util.ParseUtils.*;
17+
import static org.opensearch.timeseries.util.ParseUtils.getConfig;
18+
import static org.opensearch.timeseries.util.ParseUtils.getUserContext;
1819
import static org.opensearch.timeseries.util.RestHandlerUtils.wrapRestActionListener;
1920

2021
import java.util.List;

src/main/java/org/opensearch/timeseries/TimeSeriesAnalyticsPlugin.java

+4-59
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
import org.apache.logging.log4j.LogManager;
4343
import org.apache.logging.log4j.Logger;
4444
import org.opensearch.SpecialPermission;
45-
import org.opensearch.accesscontrol.resources.ResourceService;
4645
import org.opensearch.action.ActionRequest;
4746
import org.opensearch.ad.ADJobProcessor;
4847
import org.opensearch.ad.ADTaskProfileRunner;
@@ -162,10 +161,6 @@
162161
import org.opensearch.cluster.metadata.IndexNameExpressionResolver;
163162
import org.opensearch.cluster.node.DiscoveryNodes;
164163
import org.opensearch.cluster.service.ClusterService;
165-
import org.opensearch.common.inject.Inject;
166-
import org.opensearch.common.lifecycle.Lifecycle;
167-
import org.opensearch.common.lifecycle.LifecycleComponent;
168-
import org.opensearch.common.lifecycle.LifecycleListener;
169164
import org.opensearch.common.settings.ClusterSettings;
170165
import org.opensearch.common.settings.IndexScopedSettings;
171166
import org.opensearch.common.settings.Setting;
@@ -277,6 +272,7 @@
277272
import org.opensearch.rest.RestController;
278273
import org.opensearch.rest.RestHandler;
279274
import org.opensearch.script.ScriptService;
275+
import org.opensearch.security.spi.resources.ResourceSharingExtension;
280276
import org.opensearch.threadpool.ExecutorBuilder;
281277
import org.opensearch.threadpool.ScalingExecutorBuilder;
282278
import org.opensearch.threadpool.ThreadPool;
@@ -293,7 +289,6 @@
293289
import org.opensearch.timeseries.function.ThrowingSupplierWrapper;
294290
import org.opensearch.timeseries.model.Job;
295291
import org.opensearch.timeseries.ratelimit.CheckPointMaintainRequestAdapter;
296-
import org.opensearch.timeseries.rest.RestShareConfigAction;
297292
import org.opensearch.timeseries.settings.TimeSeriesEnabledSetting;
298293
import org.opensearch.timeseries.settings.TimeSeriesSettings;
299294
import org.opensearch.timeseries.stats.StatNames;
@@ -303,8 +298,6 @@
303298
import org.opensearch.timeseries.stats.suppliers.SettableSupplier;
304299
import org.opensearch.timeseries.task.TaskCacheManager;
305300
import org.opensearch.timeseries.transport.CronTransportAction;
306-
import org.opensearch.timeseries.transport.ShareConfigAction;
307-
import org.opensearch.timeseries.transport.ShareConfigTransportAction;
308301
import org.opensearch.timeseries.transport.handler.ResultBulkIndexingHandler;
309302
import org.opensearch.timeseries.util.ClientUtil;
310303
import org.opensearch.timeseries.util.DiscoveryNodeFilterer;
@@ -338,7 +331,7 @@ public class TimeSeriesAnalyticsPlugin extends Plugin
338331
ScriptPlugin,
339332
SystemIndexPlugin,
340333
JobSchedulerExtension,
341-
ResourcePlugin {
334+
ResourceSharingExtension {
342335

343336
private static final Logger LOG = LogManager.getLogger(TimeSeriesAnalyticsPlugin.class);
344337

@@ -442,9 +435,6 @@ public List<RestHandler> getRestHandlers(
442435
RestValidateForecasterAction validateForecasterAction = new RestValidateForecasterAction(settings, clusterService);
443436
RestForecasterSuggestAction suggestForecasterParamAction = new RestForecasterSuggestAction(settings, clusterService);
444437

445-
// Config sharing and access control
446-
RestShareConfigAction restShareConfigAction = new RestShareConfigAction();
447-
448438
ForecastJobProcessor forecastJobRunner = ForecastJobProcessor.getInstance();
449439
forecastJobRunner.setClient(client);
450440
forecastJobRunner.setThreadPool(threadPool);
@@ -484,9 +474,7 @@ public List<RestHandler> getRestHandlers(
484474
statsForecasterAction,
485475
runOnceForecasterAction,
486476
validateForecasterAction,
487-
suggestForecasterParamAction,
488-
// Config sharing and access control
489-
restShareConfigAction
477+
suggestForecasterParamAction
490478
);
491479
}
492480

@@ -1719,8 +1707,7 @@ public List<NamedXContentRegistry.Entry> getNamedXContent() {
17191707
new ActionHandler<>(ForecastRunOnceAction.INSTANCE, ForecastRunOnceTransportAction.class),
17201708
new ActionHandler<>(ForecastRunOnceProfileAction.INSTANCE, ForecastRunOnceProfileTransportAction.class),
17211709
new ActionHandler<>(ValidateForecasterAction.INSTANCE, ValidateForecasterTransportAction.class),
1722-
new ActionHandler<>(SuggestForecasterParamAction.INSTANCE, SuggestForecasterParamTransportAction.class),
1723-
new ActionHandler<>(ShareConfigAction.INSTANCE, ShareConfigTransportAction.class)
1710+
new ActionHandler<>(SuggestForecasterParamAction.INSTANCE, SuggestForecasterParamTransportAction.class)
17241711
);
17251712
}
17261713

@@ -1785,46 +1772,4 @@ public String getResourceType() {
17851772
public String getResourceIndex() {
17861773
return CommonName.CONFIG_INDEX;
17871774
}
1788-
1789-
@Override
1790-
public Collection<Class<? extends LifecycleComponent>> getGuiceServiceClasses() {
1791-
final List<Class<? extends LifecycleComponent>> services = new ArrayList<>(1);
1792-
services.add(GuiceHolder.class);
1793-
return services;
1794-
}
1795-
1796-
public static class GuiceHolder implements LifecycleComponent {
1797-
1798-
private static ResourceService resourceService;
1799-
1800-
@Inject
1801-
public GuiceHolder(final ResourceService resourceService) {
1802-
GuiceHolder.resourceService = resourceService;
1803-
}
1804-
1805-
public static ResourceService getResourceService() {
1806-
return resourceService;
1807-
}
1808-
1809-
@Override
1810-
public void close() {}
1811-
1812-
@Override
1813-
public Lifecycle.State lifecycleState() {
1814-
return null;
1815-
}
1816-
1817-
@Override
1818-
public void addLifecycleListener(LifecycleListener listener) {}
1819-
1820-
@Override
1821-
public void removeLifecycleListener(LifecycleListener listener) {}
1822-
1823-
@Override
1824-
public void start() {}
1825-
1826-
@Override
1827-
public void stop() {}
1828-
1829-
}
18301775
}

src/main/java/org/opensearch/timeseries/rest/RestShareConfigAction.java

-89
This file was deleted.

src/main/java/org/opensearch/timeseries/transport/ShareConfigAction.java

-21
This file was deleted.

src/main/java/org/opensearch/timeseries/transport/ShareConfigRequest.java

-48
This file was deleted.

src/main/java/org/opensearch/timeseries/transport/ShareConfigResponse.java

-35
This file was deleted.

0 commit comments

Comments
 (0)