From 3edadfefd0954d3a531d8307a05354d2f4468952 Mon Sep 17 00:00:00 2001 From: Jay Modi Date: Sun, 9 Feb 2020 22:48:32 -0700 Subject: [PATCH] RestHandlers declare handled routes (#52123) This commit changes how RestHandlers are registered with the RestController so that a RestHandler no longer needs to register itself with the RestController. Instead the RestHandler interface has new methods which when called provide information about the routes (method and path combinations) that are handled by the handler including any deprecated and/or replaced combinations. This change also makes the publication of RestHandlers safe since they no longer publish a reference to themselves within their constructors. Closes #51622 Co-authored-by: Jason Tedor Backport of #51950 --- .../elasticsearch/plugin/noop/NoopPlugin.java | 4 +- .../noop/action/bulk/RestNoopBulkAction.java | 20 +- .../action/search/RestNoopSearchAction.java | 21 +- .../ingest/common/GrokProcessorGetAction.java | 9 +- .../ingest/common/IngestCommonPlugin.java | 2 +- .../script/mustache/MustachePlugin.java | 6 +- .../RestMultiSearchTemplateAction.java | 28 +- .../RestRenderSearchTemplateAction.java | 16 +- .../mustache/RestSearchTemplateAction.java | 23 +- .../RestMultiSearchTemplateActionTests.java | 2 +- .../RestSearchTemplateActionTests.java | 2 +- .../painless/PainlessPlugin.java | 4 +- .../action/PainlessContextAction.java | 7 +- .../action/PainlessExecuteAction.java | 12 +- .../index/rankeval/RankEvalPlugin.java | 3 +- .../index/rankeval/RestRankEvalAction.java | 16 +- .../index/reindex/ReindexPlugin.java | 8 +- .../reindex/RestDeleteByQueryAction.java | 15 +- .../index/reindex/RestReindexAction.java | 11 +- .../index/reindex/RestRethrottleAction.java | 17 +- .../reindex/RestUpdateByQueryAction.java | 16 +- .../reindex/RestDeleteByQueryActionTests.java | 3 +- .../index/reindex/RestReindexActionTests.java | 3 +- .../reindex/RestUpdateByQueryActionTests.java | 3 +- .../example/resthandler/ExampleCatAction.java | 13 +- .../resthandler/ExampleRestHandlerPlugin.java | 2 +- .../s3/RepositoryCredentialsTests.java | 7 +- .../elasticsearch/DieWithDignityPlugin.java | 2 +- .../RestDieWithDignityAction.java | 13 +- .../http/TestDeprecationHeaderRestAction.java | 18 +- .../http/TestDeprecationPlugin.java | 2 +- .../http/TestResponseHeaderPlugin.java | 2 +- .../http/TestResponseHeaderRestAction.java | 11 +- .../elasticsearch/action/ActionModule.java | 251 +++++++++--------- .../common/collect/MapBuilder.java | 2 +- .../elasticsearch/rest/BaseRestHandler.java | 7 + .../elasticsearch/rest/RestController.java | 18 +- .../org/elasticsearch/rest/RestHandler.java | 102 +++++++ .../action/RestFieldCapabilitiesAction.java | 16 +- .../rest/action/RestMainAction.java | 13 +- .../RestAddVotingConfigExclusionAction.java | 14 +- .../admin/cluster/RestCancelTasksAction.java | 14 +- .../cluster/RestCleanupRepositoryAction.java | 8 +- ...RestClearVotingConfigExclusionsAction.java | 10 +- .../RestClusterAllocationExplainAction.java | 15 +- .../cluster/RestClusterGetSettingsAction.java | 13 +- .../cluster/RestClusterHealthAction.java | 12 +- .../cluster/RestClusterRerouteAction.java | 13 +- .../RestClusterSearchShardsAction.java | 16 +- .../admin/cluster/RestClusterStateAction.java | 20 +- .../admin/cluster/RestClusterStatsAction.java | 14 +- .../RestClusterUpdateSettingsAction.java | 10 +- .../cluster/RestCreateSnapshotAction.java | 12 +- .../cluster/RestDeleteRepositoryAction.java | 8 +- .../cluster/RestDeleteSnapshotAction.java | 8 +- .../cluster/RestDeleteStoredScriptAction.java | 8 +- .../cluster/RestGetRepositoriesAction.java | 15 +- .../cluster/RestGetScriptContextAction.java | 11 +- .../cluster/RestGetScriptLanguageAction.java | 11 +- .../admin/cluster/RestGetSnapshotsAction.java | 8 +- .../cluster/RestGetStoredScriptAction.java | 8 +- .../admin/cluster/RestGetTaskAction.java | 8 +- .../admin/cluster/RestListTasksAction.java | 11 +- .../cluster/RestNodesHotThreadsAction.java | 27 +- .../admin/cluster/RestNodesInfoAction.java | 24 +- .../admin/cluster/RestNodesStatsAction.java | 23 +- .../admin/cluster/RestNodesUsageAction.java | 19 +- .../RestPendingClusterTasksAction.java | 10 +- .../cluster/RestPutRepositoryAction.java | 12 +- .../cluster/RestPutStoredScriptAction.java | 16 +- .../RestReloadSecureSettingsAction.java | 16 +- .../cluster/RestRemoteClusterInfoAction.java | 9 +- .../cluster/RestRestoreSnapshotAction.java | 8 +- .../cluster/RestSnapshotsStatusAction.java | 14 +- .../cluster/RestVerifyRepositoryAction.java | 8 +- .../admin/indices/RestAnalyzeAction.java | 16 +- .../indices/RestClearIndicesCacheAction.java | 12 +- .../admin/indices/RestCloseIndexAction.java | 14 +- .../admin/indices/RestCreateIndexAction.java | 14 +- .../admin/indices/RestDeleteIndexAction.java | 14 +- .../RestDeleteIndexTemplateAction.java | 10 +- .../action/admin/indices/RestFlushAction.java | 17 +- .../admin/indices/RestForceMergeAction.java | 12 +- .../admin/indices/RestGetAliasesAction.java | 23 +- .../indices/RestGetFieldMappingAction.java | 18 +- .../indices/RestGetIndexTemplateAction.java | 14 +- .../admin/indices/RestGetIndicesAction.java | 12 +- .../admin/indices/RestGetMappingAction.java | 25 +- .../admin/indices/RestGetSettingsAction.java | 18 +- .../indices/RestIndexDeleteAliasesAction.java | 12 +- .../indices/RestIndexPutAliasAction.java | 32 +-- .../indices/RestIndicesAliasesAction.java | 8 +- .../indices/RestIndicesSegmentsAction.java | 12 +- .../indices/RestIndicesShardStoresAction.java | 12 +- .../admin/indices/RestIndicesStatsAction.java | 16 +- .../admin/indices/RestOpenIndexAction.java | 14 +- .../indices/RestPutIndexTemplateAction.java | 15 +- .../admin/indices/RestPutMappingAction.java | 44 +-- .../admin/indices/RestRecoveryAction.java | 12 +- .../admin/indices/RestRefreshAction.java | 17 +- .../admin/indices/RestResizeHandler.java | 31 ++- .../indices/RestRolloverIndexAction.java | 15 +- .../admin/indices/RestSyncedFlushAction.java | 17 +- .../indices/RestUpdateSettingsAction.java | 13 +- .../admin/indices/RestUpgradeAction.java | 12 +- .../indices/RestUpgradeStatusAction.java | 12 +- .../indices/RestValidateQueryAction.java | 20 +- .../rest/action/cat/RestAliasAction.java | 11 +- .../rest/action/cat/RestAllocationAction.java | 13 +- .../rest/action/cat/RestCatAction.java | 12 +- .../action/cat/RestCatRecoveryAction.java | 11 +- .../rest/action/cat/RestCountAction.java | 13 +- .../rest/action/cat/RestFielddataAction.java | 13 +- .../rest/action/cat/RestHealthAction.java | 8 +- .../rest/action/cat/RestIndicesAction.java | 15 +- .../rest/action/cat/RestMasterAction.java | 9 +- .../rest/action/cat/RestNodeAttrsAction.java | 8 +- .../rest/action/cat/RestNodesAction.java | 8 +- .../cat/RestPendingClusterTasksAction.java | 9 +- .../rest/action/cat/RestPluginsAction.java | 9 +- .../action/cat/RestRepositoriesAction.java | 9 +- .../rest/action/cat/RestSegmentsAction.java | 11 +- .../rest/action/cat/RestShardsAction.java | 11 +- .../rest/action/cat/RestSnapshotAction.java | 12 +- .../rest/action/cat/RestTasksAction.java | 10 +- .../rest/action/cat/RestTemplatesAction.java | 13 +- .../rest/action/cat/RestThreadPoolAction.java | 12 +- .../rest/action/document/RestBulkAction.java | 27 +- .../action/document/RestDeleteAction.java | 15 +- .../rest/action/document/RestGetAction.java | 23 +- .../action/document/RestGetSourceAction.java | 16 +- .../rest/action/document/RestIndexAction.java | 63 +++-- .../action/document/RestMultiGetAction.java | 27 +- .../document/RestMultiTermVectorsAction.java | 23 +- .../document/RestTermVectorsAction.java | 27 +- .../action/document/RestUpdateAction.java | 15 +- .../ingest/RestDeletePipelineAction.java | 10 +- .../action/ingest/RestGetPipelineAction.java | 14 +- .../action/ingest/RestPutPipelineAction.java | 10 +- .../ingest/RestSimulatePipelineAction.java | 19 +- .../action/search/RestClearScrollAction.java | 16 +- .../rest/action/search/RestCountAction.java | 23 +- .../rest/action/search/RestExplainAction.java | 19 +- .../action/search/RestMultiSearchAction.java | 26 +- .../rest/action/search/RestSearchAction.java | 27 +- .../action/search/RestSearchScrollAction.java | 20 +- .../action/ActionModuleTests.java | 32 ++- .../forcemerge/RestForceMergeActionTests.java | 5 +- .../rest/BaseRestHandlerTests.java | 43 +++ .../rest/RestControllerTests.java | 21 -- ...stAddVotingConfigExclusionActionTests.java | 3 +- .../cluster/RestNodesStatsActionTests.java | 7 +- .../admin/indices/RestAnalyzeActionTests.java | 4 +- .../indices/RestCreateIndexActionTests.java | 3 +- .../RestGetFieldMappingActionTests.java | 2 +- .../indices/RestGetIndicesActionTests.java | 5 +- .../indices/RestGetMappingActionTests.java | 5 +- .../indices/RestIndicesStatsActionTests.java | 7 +- .../RestPutIndexTemplateActionTests.java | 3 +- .../indices/RestPutMappingActionTests.java | 2 +- .../admin/indices/RestResizeHandlerTests.java | 5 +- .../indices/RestValidateQueryActionTests.java | 3 +- .../action/cat/RestIndicesActionTests.java | 3 +- .../rest/action/cat/RestNodesActionTests.java | 6 +- .../action/cat/RestRecoveryActionTests.java | 3 +- .../action/document/RestBulkActionTests.java | 8 +- .../document/RestDeleteActionTests.java | 2 +- .../action/document/RestGetActionTests.java | 2 +- .../document/RestGetSourceActionTests.java | 2 +- .../action/document/RestIndexActionTests.java | 11 +- .../document/RestMultiGetActionTests.java | 2 +- .../RestMultiTermVectorsActionTests.java | 2 +- .../document/RestTermVectorsActionTests.java | 2 +- .../document/RestUpdateActionTests.java | 3 +- .../action/search/RestCountActionTests.java | 2 +- .../action/search/RestExplainActionTests.java | 2 +- .../search/RestMultiSearchActionTests.java | 2 +- .../action/search/RestSearchActionTests.java | 2 +- .../scroll/RestClearScrollActionTests.java | 5 +- .../scroll/RestSearchScrollActionTests.java | 5 +- .../DedicatedClusterSnapshotRestoreIT.java | 8 +- .../usage/UsageServiceTests.java | 7 + .../xpack/autoscaling/Autoscaling.java | 2 +- .../RestGetAutoscalingDecisionHandler.java | 11 +- .../java/org/elasticsearch/xpack/ccr/Ccr.java | 26 +- .../xpack/ccr/rest/RestCcrStatsAction.java | 11 +- .../RestDeleteAutoFollowPatternAction.java | 10 +- .../xpack/ccr/rest/RestFollowInfoAction.java | 11 +- .../xpack/ccr/rest/RestFollowStatsAction.java | 11 +- .../ccr/rest/RestForgetFollowerAction.java | 12 +- .../rest/RestGetAutoFollowPatternAction.java | 14 +- .../RestPauseAutoFollowPatternAction.java | 10 +- .../xpack/ccr/rest/RestPauseFollowAction.java | 10 +- .../rest/RestPutAutoFollowPatternAction.java | 9 +- .../xpack/ccr/rest/RestPutFollowAction.java | 9 +- .../RestResumeAutoFollowPatternAction.java | 10 +- .../ccr/rest/RestResumeFollowAction.java | 9 +- .../xpack/ccr/rest/RestUnfollowAction.java | 10 +- .../org/elasticsearch/license/Licensing.java | 14 +- .../license/RestDeleteLicenseAction.java | 19 +- .../license/RestGetBasicStatus.java | 20 +- .../license/RestGetLicenseAction.java | 19 +- .../license/RestGetTrialStatus.java | 20 +- .../license/RestPostStartBasicLicense.java | 19 +- .../license/RestPostStartTrialLicense.java | 19 +- .../license/RestPutLicenseAction.java | 28 +- .../elasticsearch/xpack/core/XPackPlugin.java | 6 +- .../action/RestReloadAnalyzersAction.java | 16 +- .../core/rest/action/RestXPackInfoAction.java | 13 +- .../rest/action/RestXPackUsageAction.java | 9 +- .../rest/RestGetCertificateInfoAction.java | 18 +- .../xpack/deprecation/Deprecation.java | 2 +- .../RestDeprecationInfoAction.java | 30 ++- .../xpack/enrich/EnrichPlugin.java | 10 +- .../rest/RestDeleteEnrichPolicyAction.java | 10 +- .../enrich/rest/RestEnrichStatsAction.java | 10 +- .../rest/RestExecuteEnrichPolicyAction.java | 15 +- .../rest/RestGetEnrichPolicyAction.java | 12 +- .../rest/RestPutEnrichPolicyAction.java | 10 +- .../xpack/eql/plugin/EqlPlugin.java | 2 +- .../xpack/eql/plugin/RestEqlSearchAction.java | 21 +- .../xpack/frozen/FrozenIndices.java | 2 +- .../rest/action/RestFreezeIndexAction.java | 15 +- .../org/elasticsearch/xpack/graph/Graph.java | 2 +- .../graph/rest/action/RestGraphAction.java | 38 +-- .../rest/action/RestGraphActionTests.java | 2 +- .../xpack/ilm/IndexLifecycle.java | 38 +-- .../ilm/action/RestDeleteLifecycleAction.java | 11 +- .../action/RestExplainLifecycleAction.java | 11 +- .../ilm/action/RestGetLifecycleAction.java | 15 +- .../xpack/ilm/action/RestGetStatusAction.java | 11 +- .../ilm/action/RestMoveToStepAction.java | 10 +- .../ilm/action/RestPutLifecycleAction.java | 10 +- .../RestRemoveIndexLifecyclePolicyAction.java | 11 +- .../xpack/ilm/action/RestRetryAction.java | 11 +- .../xpack/ilm/action/RestStartILMAction.java | 11 +- .../xpack/ilm/action/RestStopAction.java | 11 +- .../RestDeleteSnapshotLifecycleAction.java | 11 +- .../RestExecuteSnapshotLifecycleAction.java | 16 +- .../RestExecuteSnapshotRetentionAction.java | 11 +- .../slm/action/RestGetSLMStatusAction.java | 11 +- .../RestGetSnapshotLifecycleAction.java | 15 +- .../RestGetSnapshotLifecycleStatsAction.java | 11 +- .../RestPutSnapshotLifecycleAction.java | 10 +- .../xpack/slm/action/RestStartSLMAction.java | 11 +- .../xpack/slm/action/RestStopSLMAction.java | 11 +- .../xpack/ml/MachineLearning.java | 122 ++++----- .../ml/rest/RestDeleteExpiredDataAction.java | 19 +- .../ml/rest/RestFindFileStructureAction.java | 18 +- .../xpack/ml/rest/RestMlInfoAction.java | 19 +- .../ml/rest/RestSetUpgradeModeAction.java | 19 +- .../calendar/RestDeleteCalendarAction.java | 18 +- .../RestDeleteCalendarEventAction.java | 22 +- .../calendar/RestDeleteCalendarJobAction.java | 22 +- .../calendar/RestGetCalendarEventsAction.java | 18 +- .../rest/calendar/RestGetCalendarsAction.java | 36 +-- .../calendar/RestPostCalendarEventAction.java | 18 +- .../rest/calendar/RestPutCalendarAction.java | 19 +- .../calendar/RestPutCalendarJobAction.java | 24 +- .../ml/rest/cat/RestCatDatafeedsAction.java | 13 +- .../xpack/ml/rest/cat/RestCatJobsAction.java | 13 +- .../rest/cat/RestCatTrainedModelsAction.java | 11 +- .../datafeeds/RestDeleteDatafeedAction.java | 18 +- .../datafeeds/RestGetDatafeedStatsAction.java | 25 +- .../datafeeds/RestGetDatafeedsAction.java | 24 +- .../datafeeds/RestPreviewDatafeedAction.java | 19 +- .../rest/datafeeds/RestPutDatafeedAction.java | 19 +- .../datafeeds/RestStartDatafeedAction.java | 19 +- .../datafeeds/RestStopDatafeedAction.java | 19 +- .../datafeeds/RestUpdateDatafeedAction.java | 19 +- .../RestDeleteDataFrameAnalyticsAction.java | 12 +- .../RestEvaluateDataFrameAction.java | 10 +- .../RestExplainDataFrameAnalyticsAction.java | 22 +- .../RestGetDataFrameAnalyticsAction.java | 15 +- .../RestGetDataFrameAnalyticsStatsAction.java | 16 +- .../RestPutDataFrameAnalyticsAction.java | 12 +- .../RestStartDataFrameAnalyticsAction.java | 13 +- .../RestStopDataFrameAnalyticsAction.java | 13 +- .../rest/filter/RestDeleteFilterAction.java | 19 +- .../ml/rest/filter/RestGetFiltersAction.java | 26 +- .../ml/rest/filter/RestPutFilterAction.java | 19 +- .../rest/filter/RestUpdateFilterAction.java | 19 +- .../RestDeleteTrainedModelAction.java | 10 +- .../inference/RestGetTrainedModelsAction.java | 15 +- .../RestGetTrainedModelsStatsAction.java | 13 +- .../inference/RestPutTrainedModelAction.java | 13 +- .../xpack/ml/rest/job/RestCloseJobAction.java | 18 +- .../ml/rest/job/RestDeleteForecastAction.java | 26 +- .../ml/rest/job/RestDeleteJobAction.java | 18 +- .../xpack/ml/rest/job/RestFlushJobAction.java | 19 +- .../ml/rest/job/RestForecastJobAction.java | 19 +- .../ml/rest/job/RestGetJobStatsAction.java | 25 +- .../xpack/ml/rest/job/RestGetJobsAction.java | 25 +- .../xpack/ml/rest/job/RestOpenJobAction.java | 19 +- .../xpack/ml/rest/job/RestPostDataAction.java | 19 +- .../ml/rest/job/RestPostJobUpdateAction.java | 19 +- .../xpack/ml/rest/job/RestPutJobAction.java | 19 +- .../RestDeleteModelSnapshotAction.java | 25 +- .../RestGetModelSnapshotsAction.java | 57 ++-- .../RestRevertModelSnapshotAction.java | 24 +- .../RestUpdateModelSnapshotAction.java | 23 +- .../ml/rest/results/RestGetBucketsAction.java | 55 ++-- .../rest/results/RestGetCategoriesAction.java | 54 ++-- .../results/RestGetInfluencersAction.java | 33 ++- .../results/RestGetOverallBucketsAction.java | 32 ++- .../ml/rest/results/RestGetRecordsAction.java | 34 ++- .../validate/RestValidateDetectorAction.java | 18 +- .../validate/RestValidateJobConfigAction.java | 18 +- .../RestStartDatafeedActionTests.java | 4 +- .../xpack/monitoring/Monitoring.java | 2 +- .../rest/action/RestMonitoringBulkAction.java | 54 ++-- .../action/RestMonitoringBulkActionTests.java | 5 +- .../elasticsearch/xpack/rollup/Rollup.java | 16 +- .../rest/RestDeleteRollupJobAction.java | 18 +- .../rollup/rest/RestGetRollupCapsAction.java | 18 +- .../rest/RestGetRollupIndexCapsAction.java | 18 +- .../rollup/rest/RestGetRollupJobsAction.java | 18 +- .../rollup/rest/RestPutRollupJobAction.java | 17 +- .../rollup/rest/RestRollupSearchAction.java | 19 +- .../rollup/rest/RestStartRollupJobAction.java | 19 +- .../rollup/rest/RestStopRollupJobAction.java | 19 +- .../xpack/security/Security.java | 68 ++--- .../security/rest/SecurityRestFilter.java | 16 ++ .../rest/action/RestAuthenticateAction.java | 20 +- .../RestDelegatePkiAuthenticationAction.java | 19 +- .../action/apikey/RestCreateApiKeyAction.java | 18 +- .../action/apikey/RestGetApiKeyAction.java | 13 +- .../apikey/RestInvalidateApiKeyAction.java | 13 +- .../action/oauth2/RestGetTokenAction.java | 21 +- .../oauth2/RestInvalidateTokenAction.java | 20 +- .../RestOpenIdConnectAuthenticateAction.java | 11 +- .../oidc/RestOpenIdConnectLogoutAction.java | 11 +- ...nIdConnectPrepareAuthenticationAction.java | 11 +- .../privilege/RestDeletePrivilegesAction.java | 18 +- .../RestGetBuiltinPrivilegesAction.java | 12 +- .../privilege/RestGetPrivilegesAction.java | 29 +- .../privilege/RestPutPrivilegesAction.java | 23 +- .../realm/RestClearRealmCacheAction.java | 21 +- .../role/RestClearRolesCacheAction.java | 19 +- .../action/role/RestDeleteRoleAction.java | 19 +- .../rest/action/role/RestGetRolesAction.java | 25 +- .../rest/action/role/RestPutRoleAction.java | 25 +- .../RestDeleteRoleMappingAction.java | 20 +- .../RestGetRoleMappingsAction.java | 25 +- .../rolemapping/RestPutRoleMappingAction.java | 25 +- .../saml/RestSamlAuthenticateAction.java | 24 +- .../saml/RestSamlInvalidateSessionAction.java | 25 +- .../action/saml/RestSamlLogoutAction.java | 25 +- .../RestSamlPrepareAuthenticationAction.java | 25 +- .../action/user/RestChangePasswordAction.java | 37 +-- .../action/user/RestDeleteUserAction.java | 20 +- .../user/RestGetUserPrivilegesAction.java | 20 +- .../rest/action/user/RestGetUsersAction.java | 25 +- .../action/user/RestHasPrivilegesAction.java | 38 +-- .../rest/action/user/RestPutUserAction.java | 26 +- .../action/user/RestSetEnabledAction.java | 38 ++- .../action/SecurityBaseRestHandlerTests.java | 7 + .../apikey/RestCreateApiKeyActionTests.java | 7 +- .../apikey/RestGetApiKeyActionTests.java | 6 +- .../RestInvalidateApiKeyActionTests.java | 8 +- .../action/saml/SamlBaseRestHandlerTests.java | 8 + .../RestGetUserPrivilegesActionTests.java | 5 +- .../user/RestHasPrivilegesActionTests.java | 7 +- .../sql/plugin/RestSqlClearCursorAction.java | 19 +- .../xpack/sql/plugin/RestSqlQueryAction.java | 30 ++- .../xpack/sql/plugin/RestSqlStatsAction.java | 20 +- .../sql/plugin/RestSqlTranslateAction.java | 28 +- .../xpack/sql/plugin/SqlPlugin.java | 8 +- .../xpack/transform/Transform.java | 32 +-- .../action/RestDeleteTransformAction.java | 11 +- .../rest/action/RestGetTransformAction.java | 14 +- .../action/RestGetTransformStatsAction.java | 14 +- .../action/RestPreviewTransformAction.java | 10 +- .../rest/action/RestPutTransformAction.java | 10 +- .../rest/action/RestStartTransformAction.java | 11 +- .../rest/action/RestStopTransformAction.java | 11 +- .../action/RestUpdateTransformAction.java | 10 +- .../RestDeleteTransformActionDeprecated.java | 19 +- .../RestGetTransformActionDeprecated.java | 24 +- ...RestGetTransformStatsActionDeprecated.java | 25 +- .../RestPreviewTransformActionDeprecated.java | 18 +- .../RestPutTransformActionDeprecated.java | 18 +- .../RestStartTransformActionDeprecated.java | 20 +- .../RestStopTransformActionDeprecated.java | 19 +- .../RestUpdateTransformActionDeprecated.java | 19 +- .../RestDeleteTransformActionTests.java | 4 +- .../elasticsearch/xpack/watcher/Watcher.java | 19 +- .../rest/action/RestAckWatchAction.java | 36 +-- .../rest/action/RestActivateWatchAction.java | 49 ++-- .../rest/action/RestDeleteWatchAction.java | 19 +- .../rest/action/RestExecuteWatchAction.java | 33 ++- .../rest/action/RestGetWatchAction.java | 18 +- .../rest/action/RestPutWatchAction.java | 23 +- .../rest/action/RestWatchServiceAction.java | 32 ++- .../rest/action/RestWatcherStatsAction.java | 23 +- .../action/RestExecuteWatchActionTests.java | 4 +- 396 files changed, 4251 insertions(+), 2313 deletions(-) diff --git a/client/client-benchmark-noop-api-plugin/src/main/java/org/elasticsearch/plugin/noop/NoopPlugin.java b/client/client-benchmark-noop-api-plugin/src/main/java/org/elasticsearch/plugin/noop/NoopPlugin.java index 0eceed67c4f73..2013b0d6680a8 100644 --- a/client/client-benchmark-noop-api-plugin/src/main/java/org/elasticsearch/plugin/noop/NoopPlugin.java +++ b/client/client-benchmark-noop-api-plugin/src/main/java/org/elasticsearch/plugin/noop/NoopPlugin.java @@ -55,7 +55,7 @@ public List getRestHandlers(Settings settings, RestController restC IndexScopedSettings indexScopedSettings, SettingsFilter settingsFilter, IndexNameExpressionResolver indexNameExpressionResolver, Supplier nodesInCluster) { return Arrays.asList( - new RestNoopBulkAction(restController), - new RestNoopSearchAction(restController)); + new RestNoopBulkAction(), + new RestNoopSearchAction()); } } diff --git a/client/client-benchmark-noop-api-plugin/src/main/java/org/elasticsearch/plugin/noop/action/bulk/RestNoopBulkAction.java b/client/client-benchmark-noop-api-plugin/src/main/java/org/elasticsearch/plugin/noop/action/bulk/RestNoopBulkAction.java index a6609d7af4215..9eb4af6600ad5 100644 --- a/client/client-benchmark-noop-api-plugin/src/main/java/org/elasticsearch/plugin/noop/action/bulk/RestNoopBulkAction.java +++ b/client/client-benchmark-noop-api-plugin/src/main/java/org/elasticsearch/plugin/noop/action/bulk/RestNoopBulkAction.java @@ -32,26 +32,30 @@ import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.BytesRestResponse; import org.elasticsearch.rest.RestChannel; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.action.RestBuilderListener; import java.io.IOException; +import java.util.List; +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.rest.RestRequest.Method.POST; import static org.elasticsearch.rest.RestRequest.Method.PUT; import static org.elasticsearch.rest.RestStatus.OK; public class RestNoopBulkAction extends BaseRestHandler { - public RestNoopBulkAction(RestController controller) { - controller.registerHandler(POST, "/_noop_bulk", this); - controller.registerHandler(PUT, "/_noop_bulk", this); - controller.registerHandler(POST, "/{index}/_noop_bulk", this); - controller.registerHandler(PUT, "/{index}/_noop_bulk", this); - controller.registerHandler(POST, "/{index}/{type}/_noop_bulk", this); - controller.registerHandler(PUT, "/{index}/{type}/_noop_bulk", this); + @Override + public List routes() { + return unmodifiableList(asList( + new Route(POST, "/_noop_bulk"), + new Route(PUT, "/_noop_bulk"), + new Route(POST, "/{index}/_noop_bulk"), + new Route(PUT, "/{index}/_noop_bulk"), + new Route(POST, "/{index}/{type}/_noop_bulk"), + new Route(PUT, "/{index}/{type}/_noop_bulk"))); } @Override diff --git a/client/client-benchmark-noop-api-plugin/src/main/java/org/elasticsearch/plugin/noop/action/search/RestNoopSearchAction.java b/client/client-benchmark-noop-api-plugin/src/main/java/org/elasticsearch/plugin/noop/action/search/RestNoopSearchAction.java index bc9fbe0025766..72762d143166d 100644 --- a/client/client-benchmark-noop-api-plugin/src/main/java/org/elasticsearch/plugin/noop/action/search/RestNoopSearchAction.java +++ b/client/client-benchmark-noop-api-plugin/src/main/java/org/elasticsearch/plugin/noop/action/search/RestNoopSearchAction.java @@ -21,22 +21,27 @@ import org.elasticsearch.action.search.SearchRequest; import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestStatusToXContentListener; +import java.util.List; + +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.rest.RestRequest.Method.GET; import static org.elasticsearch.rest.RestRequest.Method.POST; public class RestNoopSearchAction extends BaseRestHandler { - public RestNoopSearchAction(RestController controller) { - controller.registerHandler(GET, "/_noop_search", this); - controller.registerHandler(POST, "/_noop_search", this); - controller.registerHandler(GET, "/{index}/_noop_search", this); - controller.registerHandler(POST, "/{index}/_noop_search", this); - controller.registerHandler(GET, "/{index}/{type}/_noop_search", this); - controller.registerHandler(POST, "/{index}/{type}/_noop_search", this); + @Override + public List routes() { + return unmodifiableList(asList( + new Route(GET, "/_noop_search"), + new Route(POST, "/_noop_search"), + new Route(GET, "/{index}/_noop_search"), + new Route(POST, "/{index}/_noop_search"), + new Route(GET, "/{index}/{type}/_noop_search"), + new Route(POST, "/{index}/{type}/_noop_search"))); } @Override diff --git a/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/GrokProcessorGetAction.java b/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/GrokProcessorGetAction.java index 2458c5eb40a53..28e07880e9df4 100644 --- a/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/GrokProcessorGetAction.java +++ b/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/GrokProcessorGetAction.java @@ -32,15 +32,16 @@ import org.elasticsearch.common.xcontent.ToXContentObject; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.tasks.Task; import org.elasticsearch.transport.TransportService; import java.io.IOException; +import java.util.List; import java.util.Map; +import static java.util.Collections.singletonList; import static org.elasticsearch.ingest.common.IngestCommonPlugin.GROK_PATTERNS; import static org.elasticsearch.rest.RestRequest.Method.GET; @@ -116,8 +117,10 @@ protected void doExecute(Task task, Request request, ActionListener li } public static class RestAction extends BaseRestHandler { - RestAction(RestController controller) { - controller.registerHandler(GET, "/_ingest/processor/grok", this); + + @Override + public List routes() { + return singletonList(new Route(GET, "/_ingest/processor/grok")); } @Override diff --git a/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/IngestCommonPlugin.java b/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/IngestCommonPlugin.java index a29756b2e1cb1..4b1e0d62ac423 100644 --- a/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/IngestCommonPlugin.java +++ b/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/IngestCommonPlugin.java @@ -102,7 +102,7 @@ public List getRestHandlers(Settings settings, RestController restC IndexScopedSettings indexScopedSettings, SettingsFilter settingsFilter, IndexNameExpressionResolver indexNameExpressionResolver, Supplier nodesInCluster) { - return Arrays.asList(new GrokProcessorGetAction.RestAction(restController)); + return Collections.singletonList(new GrokProcessorGetAction.RestAction()); } @Override diff --git a/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/MustachePlugin.java b/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/MustachePlugin.java index 42c140cada0a3..edbff8eb8b799 100644 --- a/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/MustachePlugin.java +++ b/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/MustachePlugin.java @@ -59,8 +59,8 @@ public List getRestHandlers(Settings settings, RestController restC IndexScopedSettings indexScopedSettings, SettingsFilter settingsFilter, IndexNameExpressionResolver indexNameExpressionResolver, Supplier nodesInCluster) { return Arrays.asList( - new RestSearchTemplateAction(restController), - new RestMultiSearchTemplateAction(settings, restController), - new RestRenderSearchTemplateAction(restController)); + new RestSearchTemplateAction(), + new RestMultiSearchTemplateAction(settings), + new RestRenderSearchTemplateAction()); } } diff --git a/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/RestMultiSearchTemplateAction.java b/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/RestMultiSearchTemplateAction.java index 5eccdef8afca0..76f20bbeef91c 100644 --- a/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/RestMultiSearchTemplateAction.java +++ b/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/RestMultiSearchTemplateAction.java @@ -24,18 +24,19 @@ import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.rest.action.search.RestMultiSearchAction; import org.elasticsearch.rest.action.search.RestSearchAction; import java.io.IOException; -import java.util.Arrays; import java.util.Collections; import java.util.HashSet; +import java.util.List; import java.util.Set; +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.rest.RestRequest.Method.GET; import static org.elasticsearch.rest.RestRequest.Method.POST; @@ -49,7 +50,7 @@ public class RestMultiSearchTemplateAction extends BaseRestHandler { static { final Set responseParams = new HashSet<>( - Arrays.asList(RestSearchAction.TYPED_KEYS_PARAM, RestSearchAction.TOTAL_HITS_AS_INT_PARAM) + asList(RestSearchAction.TYPED_KEYS_PARAM, RestSearchAction.TOTAL_HITS_AS_INT_PARAM) ); RESPONSE_PARAMS = Collections.unmodifiableSet(responseParams); } @@ -57,17 +58,20 @@ public class RestMultiSearchTemplateAction extends BaseRestHandler { private final boolean allowExplicitIndex; - public RestMultiSearchTemplateAction(Settings settings, RestController controller) { + public RestMultiSearchTemplateAction(Settings settings) { this.allowExplicitIndex = MULTI_ALLOW_EXPLICIT_INDEX.get(settings); + } - controller.registerHandler(GET, "/_msearch/template", this); - controller.registerHandler(POST, "/_msearch/template", this); - controller.registerHandler(GET, "/{index}/_msearch/template", this); - controller.registerHandler(POST, "/{index}/_msearch/template", this); - - // Deprecated typed endpoints. - controller.registerHandler(GET, "/{index}/{type}/_msearch/template", this); - controller.registerHandler(POST, "/{index}/{type}/_msearch/template", this); + @Override + public List routes() { + return unmodifiableList(asList( + new Route(GET, "/_msearch/template"), + new Route(POST, "/_msearch/template"), + new Route(GET, "/{index}/_msearch/template"), + new Route(POST, "/{index}/_msearch/template"), + // Deprecated typed endpoints. + new Route(GET, "/{index}/{type}/_msearch/template"), + new Route(POST, "/{index}/{type}/_msearch/template"))); } @Override diff --git a/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/RestRenderSearchTemplateAction.java b/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/RestRenderSearchTemplateAction.java index 767f6e95c1f78..320c6c582c8fb 100644 --- a/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/RestRenderSearchTemplateAction.java +++ b/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/RestRenderSearchTemplateAction.java @@ -22,23 +22,27 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.script.ScriptType; import java.io.IOException; +import java.util.List; +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.rest.RestRequest.Method.GET; import static org.elasticsearch.rest.RestRequest.Method.POST; public class RestRenderSearchTemplateAction extends BaseRestHandler { - public RestRenderSearchTemplateAction(RestController controller) { - controller.registerHandler(GET, "/_render/template", this); - controller.registerHandler(POST, "/_render/template", this); - controller.registerHandler(GET, "/_render/template/{id}", this); - controller.registerHandler(POST, "/_render/template/{id}", this); + @Override + public List routes() { + return unmodifiableList(asList( + new Route(GET, "/_render/template"), + new Route(POST, "/_render/template"), + new Route(GET, "/_render/template/{id}"), + new Route(POST, "/_render/template/{id}"))); } @Override diff --git a/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/RestSearchTemplateAction.java b/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/RestSearchTemplateAction.java index 8ec85295b9385..f8694138dcba7 100644 --- a/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/RestSearchTemplateAction.java +++ b/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/RestSearchTemplateAction.java @@ -23,7 +23,6 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestStatusToXContentListener; import org.elasticsearch.rest.action.search.RestSearchAction; @@ -32,8 +31,11 @@ import java.util.Arrays; import java.util.Collections; import java.util.HashSet; +import java.util.List; import java.util.Set; +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.rest.RestRequest.Method.GET; import static org.elasticsearch.rest.RestRequest.Method.POST; @@ -46,15 +48,16 @@ public class RestSearchTemplateAction extends BaseRestHandler { RESPONSE_PARAMS = Collections.unmodifiableSet(responseParams); } - public RestSearchTemplateAction(RestController controller) { - controller.registerHandler(GET, "/_search/template", this); - controller.registerHandler(POST, "/_search/template", this); - controller.registerHandler(GET, "/{index}/_search/template", this); - controller.registerHandler(POST, "/{index}/_search/template", this); - - // Deprecated typed endpoints. - controller.registerHandler(GET, "/{index}/{type}/_search/template", this); - controller.registerHandler(POST, "/{index}/{type}/_search/template", this); + @Override + public List routes() { + return unmodifiableList(asList( + new Route(GET, "/_search/template"), + new Route(POST, "/_search/template"), + new Route(GET, "/{index}/_search/template"), + new Route(POST, "/{index}/_search/template"), + // Deprecated typed endpoints. + new Route(GET, "/{index}/{type}/_search/template"), + new Route(POST, "/{index}/{type}/_search/template"))); } @Override diff --git a/modules/lang-mustache/src/test/java/org/elasticsearch/script/mustache/RestMultiSearchTemplateActionTests.java b/modules/lang-mustache/src/test/java/org/elasticsearch/script/mustache/RestMultiSearchTemplateActionTests.java index eacb1e3c4e803..8dfe0815f407b 100644 --- a/modules/lang-mustache/src/test/java/org/elasticsearch/script/mustache/RestMultiSearchTemplateActionTests.java +++ b/modules/lang-mustache/src/test/java/org/elasticsearch/script/mustache/RestMultiSearchTemplateActionTests.java @@ -32,7 +32,7 @@ public class RestMultiSearchTemplateActionTests extends RestActionTestCase { @Before public void setUpAction() { - new RestMultiSearchTemplateAction(Settings.EMPTY, controller()); + controller().registerHandler(new RestMultiSearchTemplateAction(Settings.EMPTY)); } public void testTypeInPath() { diff --git a/modules/lang-mustache/src/test/java/org/elasticsearch/script/mustache/RestSearchTemplateActionTests.java b/modules/lang-mustache/src/test/java/org/elasticsearch/script/mustache/RestSearchTemplateActionTests.java index 562ffaf8e1f5a..8b6f6612924c4 100644 --- a/modules/lang-mustache/src/test/java/org/elasticsearch/script/mustache/RestSearchTemplateActionTests.java +++ b/modules/lang-mustache/src/test/java/org/elasticsearch/script/mustache/RestSearchTemplateActionTests.java @@ -31,7 +31,7 @@ public class RestSearchTemplateActionTests extends RestActionTestCase { @Before public void setUpAction() { - new RestSearchTemplateAction(controller()); + controller().registerHandler(new RestSearchTemplateAction()); } public void testTypeInPath() { diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/PainlessPlugin.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/PainlessPlugin.java index 6239d33f10e36..fc4ddfa3ecae7 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/PainlessPlugin.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/PainlessPlugin.java @@ -142,8 +142,8 @@ public List getRestHandlers(Settings settings, RestController restC IndexNameExpressionResolver indexNameExpressionResolver, Supplier nodesInCluster) { List handlers = new ArrayList<>(); - handlers.add(new PainlessExecuteAction.RestAction(restController)); - handlers.add(new PainlessContextAction.RestAction(restController)); + handlers.add(new PainlessExecuteAction.RestAction()); + handlers.add(new PainlessContextAction.RestAction()); return handlers; } } diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/action/PainlessContextAction.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/action/PainlessContextAction.java index 9075b9e030df8..d670d9e35aaab 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/action/PainlessContextAction.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/action/PainlessContextAction.java @@ -37,7 +37,6 @@ import org.elasticsearch.painless.PainlessScriptEngine; import org.elasticsearch.painless.lookup.PainlessLookup; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.script.ScriptContext; @@ -52,6 +51,7 @@ import java.util.Objects; import java.util.stream.Collectors; +import static java.util.Collections.singletonList; import static org.elasticsearch.rest.RestRequest.Method.GET; /** @@ -194,8 +194,9 @@ protected void doExecute(Task task, Request request, ActionListener li public static class RestAction extends BaseRestHandler { - public RestAction(RestController controller) { - controller.registerHandler(GET, "/_scripts/painless/_context", this); + @Override + public List routes() { + return singletonList(new Route(GET, "/_scripts/painless/_context")); } @Override diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/action/PainlessExecuteAction.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/action/PainlessExecuteAction.java index a1825d2d4093e..a29c39bd6c5c7 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/action/PainlessExecuteAction.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/action/PainlessExecuteAction.java @@ -69,7 +69,6 @@ import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.indices.IndicesService; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.script.FilterScript; @@ -84,9 +83,12 @@ import java.io.IOException; import java.util.Collections; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.Objects; +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.action.ValidateActions.addValidationError; import static org.elasticsearch.rest.RestRequest.Method.GET; import static org.elasticsearch.rest.RestRequest.Method.POST; @@ -584,9 +586,11 @@ private static Response prepareRamIndex(Request request, public static class RestAction extends BaseRestHandler { - public RestAction(RestController controller) { - controller.registerHandler(GET, "/_scripts/painless/_execute", this); - controller.registerHandler(POST, "/_scripts/painless/_execute", this); + @Override + public List routes() { + return unmodifiableList(asList( + new Route(GET, "/_scripts/painless/_execute"), + new Route(POST, "/_scripts/painless/_execute"))); } @Override diff --git a/modules/rank-eval/src/main/java/org/elasticsearch/index/rankeval/RankEvalPlugin.java b/modules/rank-eval/src/main/java/org/elasticsearch/index/rankeval/RankEvalPlugin.java index 48b4297378108..9f21a6065900e 100644 --- a/modules/rank-eval/src/main/java/org/elasticsearch/index/rankeval/RankEvalPlugin.java +++ b/modules/rank-eval/src/main/java/org/elasticsearch/index/rankeval/RankEvalPlugin.java @@ -36,6 +36,7 @@ import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.List; import java.util.function.Supplier; @@ -50,7 +51,7 @@ public class RankEvalPlugin extends Plugin implements ActionPlugin { public List getRestHandlers(Settings settings, RestController restController, ClusterSettings clusterSettings, IndexScopedSettings indexScopedSettings, SettingsFilter settingsFilter, IndexNameExpressionResolver indexNameExpressionResolver, Supplier nodesInCluster) { - return Arrays.asList(new RestRankEvalAction(restController)); + return Collections.singletonList(new RestRankEvalAction()); } @Override diff --git a/modules/rank-eval/src/main/java/org/elasticsearch/index/rankeval/RestRankEvalAction.java b/modules/rank-eval/src/main/java/org/elasticsearch/index/rankeval/RestRankEvalAction.java index 85e9e656808e8..fc1f9f9f53cdb 100644 --- a/modules/rank-eval/src/main/java/org/elasticsearch/index/rankeval/RestRankEvalAction.java +++ b/modules/rank-eval/src/main/java/org/elasticsearch/index/rankeval/RestRankEvalAction.java @@ -25,12 +25,14 @@ import org.elasticsearch.common.Strings; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import java.io.IOException; +import java.util.List; +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.rest.RestRequest.Method.GET; import static org.elasticsearch.rest.RestRequest.Method.POST; @@ -90,11 +92,13 @@ public class RestRankEvalAction extends BaseRestHandler { public static String ENDPOINT = "_rank_eval"; - public RestRankEvalAction(RestController controller) { - controller.registerHandler(GET, "/" + ENDPOINT, this); - controller.registerHandler(POST, "/" + ENDPOINT, this); - controller.registerHandler(GET, "/{index}/" + ENDPOINT, this); - controller.registerHandler(POST, "/{index}/" + ENDPOINT, this); + @Override + public List routes() { + return unmodifiableList(asList( + new Route(GET, "/" + ENDPOINT), + new Route(POST, "/" + ENDPOINT), + new Route(GET, "/{index}/" + ENDPOINT), + new Route(POST, "/{index}/" + ENDPOINT))); } @Override diff --git a/modules/reindex/src/main/java/org/elasticsearch/index/reindex/ReindexPlugin.java b/modules/reindex/src/main/java/org/elasticsearch/index/reindex/ReindexPlugin.java index fefee4f348b3e..c0e6a55ec9c13 100644 --- a/modules/reindex/src/main/java/org/elasticsearch/index/reindex/ReindexPlugin.java +++ b/modules/reindex/src/main/java/org/elasticsearch/index/reindex/ReindexPlugin.java @@ -74,10 +74,10 @@ public List getRestHandlers(Settings settings, RestController restC IndexScopedSettings indexScopedSettings, SettingsFilter settingsFilter, IndexNameExpressionResolver indexNameExpressionResolver, Supplier nodesInCluster) { return Arrays.asList( - new RestReindexAction(restController), - new RestUpdateByQueryAction(restController), - new RestDeleteByQueryAction(restController), - new RestRethrottleAction(restController, nodesInCluster)); + new RestReindexAction(), + new RestUpdateByQueryAction(), + new RestDeleteByQueryAction(), + new RestRethrottleAction(nodesInCluster)); } @Override diff --git a/modules/reindex/src/main/java/org/elasticsearch/index/reindex/RestDeleteByQueryAction.java b/modules/reindex/src/main/java/org/elasticsearch/index/reindex/RestDeleteByQueryAction.java index 2618d9af2b587..bc820604158aa 100644 --- a/modules/reindex/src/main/java/org/elasticsearch/index/reindex/RestDeleteByQueryAction.java +++ b/modules/reindex/src/main/java/org/elasticsearch/index/reindex/RestDeleteByQueryAction.java @@ -20,22 +20,29 @@ package org.elasticsearch.index.reindex; import org.elasticsearch.client.node.NodeClient; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import java.io.IOException; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.function.Consumer; +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.rest.RestRequest.Method.POST; public class RestDeleteByQueryAction extends AbstractBulkByQueryRestHandler { - public RestDeleteByQueryAction(RestController controller) { + public RestDeleteByQueryAction() { super(DeleteByQueryAction.INSTANCE); - controller.registerHandler(POST, "/{index}/_delete_by_query", this); - controller.registerHandler(POST, "/{index}/{type}/_delete_by_query", this); + } + + @Override + public List routes() { + return unmodifiableList(asList( + new Route(POST, "/{index}/_delete_by_query"), + new Route(POST, "/{index}/{type}/_delete_by_query"))); } @Override diff --git a/modules/reindex/src/main/java/org/elasticsearch/index/reindex/RestReindexAction.java b/modules/reindex/src/main/java/org/elasticsearch/index/reindex/RestReindexAction.java index 516d47b835803..1677fbd7c6127 100644 --- a/modules/reindex/src/main/java/org/elasticsearch/index/reindex/RestReindexAction.java +++ b/modules/reindex/src/main/java/org/elasticsearch/index/reindex/RestReindexAction.java @@ -21,11 +21,12 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import java.io.IOException; +import java.util.List; +import static java.util.Collections.singletonList; import static org.elasticsearch.common.unit.TimeValue.parseTimeValue; import static org.elasticsearch.rest.RestRequest.Method.POST; @@ -34,9 +35,13 @@ */ public class RestReindexAction extends AbstractBaseReindexRestHandler { - public RestReindexAction(RestController controller) { + public RestReindexAction() { super(ReindexAction.INSTANCE); - controller.registerHandler(POST, "/_reindex", this); + } + + @Override + public List routes() { + return singletonList(new Route(POST, "/_reindex")); } @Override diff --git a/modules/reindex/src/main/java/org/elasticsearch/index/reindex/RestRethrottleAction.java b/modules/reindex/src/main/java/org/elasticsearch/index/reindex/RestRethrottleAction.java index cdd29a89b92c8..a89546efc27de 100644 --- a/modules/reindex/src/main/java/org/elasticsearch/index/reindex/RestRethrottleAction.java +++ b/modules/reindex/src/main/java/org/elasticsearch/index/reindex/RestRethrottleAction.java @@ -22,23 +22,30 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.cluster.node.DiscoveryNodes; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.tasks.TaskId; +import java.util.List; import java.util.function.Supplier; +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.rest.RestRequest.Method.POST; import static org.elasticsearch.rest.action.admin.cluster.RestListTasksAction.listTasksResponseListener; public class RestRethrottleAction extends BaseRestHandler { private final Supplier nodesInCluster; - public RestRethrottleAction(RestController controller, Supplier nodesInCluster) { + public RestRethrottleAction(Supplier nodesInCluster) { this.nodesInCluster = nodesInCluster; - controller.registerHandler(POST, "/_update_by_query/{taskId}/_rethrottle", this); - controller.registerHandler(POST, "/_delete_by_query/{taskId}/_rethrottle", this); - controller.registerHandler(POST, "/_reindex/{taskId}/_rethrottle", this); + } + + @Override + public List routes() { + return unmodifiableList(asList( + new Route(POST, "/_update_by_query/{taskId}/_rethrottle"), + new Route(POST, "/_delete_by_query/{taskId}/_rethrottle"), + new Route(POST, "/_reindex/{taskId}/_rethrottle"))); } @Override diff --git a/modules/reindex/src/main/java/org/elasticsearch/index/reindex/RestUpdateByQueryAction.java b/modules/reindex/src/main/java/org/elasticsearch/index/reindex/RestUpdateByQueryAction.java index 49626c4a3fad3..3119033a59f0c 100644 --- a/modules/reindex/src/main/java/org/elasticsearch/index/reindex/RestUpdateByQueryAction.java +++ b/modules/reindex/src/main/java/org/elasticsearch/index/reindex/RestUpdateByQueryAction.java @@ -22,7 +22,6 @@ import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.xcontent.LoggingDeprecationHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.script.Script; import org.elasticsearch.script.ScriptType; @@ -31,17 +30,26 @@ import java.util.Collections; import java.util.HashMap; import java.util.Iterator; +import java.util.List; import java.util.Map; import java.util.function.Consumer; +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.rest.RestRequest.Method.POST; import static org.elasticsearch.script.Script.DEFAULT_SCRIPT_LANG; public class RestUpdateByQueryAction extends AbstractBulkByQueryRestHandler { - public RestUpdateByQueryAction(RestController controller) { + + public RestUpdateByQueryAction() { super(UpdateByQueryAction.INSTANCE); - controller.registerHandler(POST, "/{index}/_update_by_query", this); - controller.registerHandler(POST, "/{index}/{type}/_update_by_query", this); + } + + @Override + public List routes() { + return unmodifiableList(asList( + new Route(POST, "/{index}/_update_by_query"), + new Route(POST, "/{index}/{type}/_update_by_query"))); } @Override diff --git a/modules/reindex/src/test/java/org/elasticsearch/index/reindex/RestDeleteByQueryActionTests.java b/modules/reindex/src/test/java/org/elasticsearch/index/reindex/RestDeleteByQueryActionTests.java index 069b85afeb437..13e00503d08fa 100644 --- a/modules/reindex/src/test/java/org/elasticsearch/index/reindex/RestDeleteByQueryActionTests.java +++ b/modules/reindex/src/test/java/org/elasticsearch/index/reindex/RestDeleteByQueryActionTests.java @@ -35,7 +35,8 @@ public class RestDeleteByQueryActionTests extends RestActionTestCase { @Before public void setUpAction() { - action = new RestDeleteByQueryAction(controller()); + action = new RestDeleteByQueryAction(); + controller().registerHandler(action); } public void testTypeInPath() throws IOException { diff --git a/modules/reindex/src/test/java/org/elasticsearch/index/reindex/RestReindexActionTests.java b/modules/reindex/src/test/java/org/elasticsearch/index/reindex/RestReindexActionTests.java index fd0a6fde01de6..312a07ee13f82 100644 --- a/modules/reindex/src/test/java/org/elasticsearch/index/reindex/RestReindexActionTests.java +++ b/modules/reindex/src/test/java/org/elasticsearch/index/reindex/RestReindexActionTests.java @@ -40,7 +40,8 @@ public class RestReindexActionTests extends RestActionTestCase { @Before public void setUpAction() { - action = new RestReindexAction(controller()); + action = new RestReindexAction(); + controller().registerHandler(action); } public void testPipelineQueryParameterIsError() throws IOException { diff --git a/modules/reindex/src/test/java/org/elasticsearch/index/reindex/RestUpdateByQueryActionTests.java b/modules/reindex/src/test/java/org/elasticsearch/index/reindex/RestUpdateByQueryActionTests.java index f7a273644bbf8..d22082d09cbde 100644 --- a/modules/reindex/src/test/java/org/elasticsearch/index/reindex/RestUpdateByQueryActionTests.java +++ b/modules/reindex/src/test/java/org/elasticsearch/index/reindex/RestUpdateByQueryActionTests.java @@ -36,7 +36,8 @@ public class RestUpdateByQueryActionTests extends RestActionTestCase { @Before public void setUpAction() { - action = new RestUpdateByQueryAction(controller()); + action = new RestUpdateByQueryAction(); + controller().registerHandler(action); } public void testTypeInPath() throws IOException { diff --git a/plugins/examples/rest-handler/src/main/java/org/elasticsearch/example/resthandler/ExampleCatAction.java b/plugins/examples/rest-handler/src/main/java/org/elasticsearch/example/resthandler/ExampleCatAction.java index 79cb1a6f76ded..1a8e2485529f0 100644 --- a/plugins/examples/rest-handler/src/main/java/org/elasticsearch/example/resthandler/ExampleCatAction.java +++ b/plugins/examples/rest-handler/src/main/java/org/elasticsearch/example/resthandler/ExampleCatAction.java @@ -21,11 +21,14 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.Table; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.cat.AbstractCatAction; import org.elasticsearch.rest.action.cat.RestTable; +import java.util.List; + +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.rest.RestRequest.Method.GET; import static org.elasticsearch.rest.RestRequest.Method.POST; @@ -34,9 +37,11 @@ */ public class ExampleCatAction extends AbstractCatAction { - ExampleCatAction(final RestController controller) { - controller.registerHandler(GET, "/_cat/example", this); - controller.registerHandler(POST, "/_cat/example", this); + @Override + public List routes() { + return unmodifiableList(asList( + new Route(GET, "/_cat/example"), + new Route(POST, "/_cat/example"))); } @Override diff --git a/plugins/examples/rest-handler/src/main/java/org/elasticsearch/example/resthandler/ExampleRestHandlerPlugin.java b/plugins/examples/rest-handler/src/main/java/org/elasticsearch/example/resthandler/ExampleRestHandlerPlugin.java index 725049c797e15..420a58302f35c 100644 --- a/plugins/examples/rest-handler/src/main/java/org/elasticsearch/example/resthandler/ExampleRestHandlerPlugin.java +++ b/plugins/examples/rest-handler/src/main/java/org/elasticsearch/example/resthandler/ExampleRestHandlerPlugin.java @@ -46,6 +46,6 @@ public List getRestHandlers(final Settings settings, final IndexNameExpressionResolver indexNameExpressionResolver, final Supplier nodesInCluster) { - return singletonList(new ExampleCatAction(restController)); + return singletonList(new ExampleCatAction()); } } diff --git a/plugins/repository-s3/src/test/java/org/elasticsearch/repositories/s3/RepositoryCredentialsTests.java b/plugins/repository-s3/src/test/java/org/elasticsearch/repositories/s3/RepositoryCredentialsTests.java index f5be4f32e316d..a063c2f1c1f1d 100644 --- a/plugins/repository-s3/src/test/java/org/elasticsearch/repositories/s3/RepositoryCredentialsTests.java +++ b/plugins/repository-s3/src/test/java/org/elasticsearch/repositories/s3/RepositoryCredentialsTests.java @@ -26,8 +26,8 @@ import org.apache.logging.log4j.Logger; import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.cluster.metadata.RepositoryMetaData; -import org.elasticsearch.common.SuppressForbidden; import org.elasticsearch.cluster.service.ClusterService; +import org.elasticsearch.common.SuppressForbidden; import org.elasticsearch.common.settings.MockSecureSettings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.SettingsFilter; @@ -36,7 +36,6 @@ import org.elasticsearch.plugins.PluginsService; import org.elasticsearch.repositories.RepositoriesService; import org.elasticsearch.rest.AbstractRestChannel; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.action.admin.cluster.RestGetRepositoriesAction; @@ -58,7 +57,6 @@ import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.notNullValue; -import static org.mockito.Mockito.mock; @SuppressForbidden(reason = "test requires to set a System property to allow insecure settings when running in IDE") public class RepositoryCredentialsTests extends ESSingleNodeTestCase { @@ -224,8 +222,7 @@ public void testInsecureRepositoryCredentials() throws Exception { final RestRequest fakeRestRequest = new FakeRestRequest(); fakeRestRequest.params().put("repository", repositoryName); - final RestGetRepositoriesAction action = - new RestGetRepositoriesAction(mock(RestController.class), getInstanceFromNode(SettingsFilter.class)); + final RestGetRepositoriesAction action = new RestGetRepositoriesAction(getInstanceFromNode(SettingsFilter.class)); final CountDownLatch latch = new CountDownLatch(1); final AtomicReference error = new AtomicReference<>(); diff --git a/qa/die-with-dignity/src/main/java/org/elasticsearch/DieWithDignityPlugin.java b/qa/die-with-dignity/src/main/java/org/elasticsearch/DieWithDignityPlugin.java index 8b7093515cd71..29c81c1a39c0a 100644 --- a/qa/die-with-dignity/src/main/java/org/elasticsearch/DieWithDignityPlugin.java +++ b/qa/die-with-dignity/src/main/java/org/elasticsearch/DieWithDignityPlugin.java @@ -49,7 +49,7 @@ public List getRestHandlers( final SettingsFilter settingsFilter, final IndexNameExpressionResolver indexNameExpressionResolver, final Supplier nodesInCluster) { - return Collections.singletonList(new RestDieWithDignityAction(restController)); + return Collections.singletonList(new RestDieWithDignityAction()); } } diff --git a/qa/die-with-dignity/src/main/java/org/elasticsearch/RestDieWithDignityAction.java b/qa/die-with-dignity/src/main/java/org/elasticsearch/RestDieWithDignityAction.java index 8f43d67908432..190a6929b1c31 100644 --- a/qa/die-with-dignity/src/main/java/org/elasticsearch/RestDieWithDignityAction.java +++ b/qa/die-with-dignity/src/main/java/org/elasticsearch/RestDieWithDignityAction.java @@ -21,13 +21,20 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.GET; + public class RestDieWithDignityAction extends BaseRestHandler { - RestDieWithDignityAction(final RestController restController) { - restController.registerHandler(RestRequest.Method.GET, "/_die_with_dignity", this); + RestDieWithDignityAction() {} + + @Override + public List routes() { + return singletonList(new Route(GET, "/_die_with_dignity")); } @Override diff --git a/qa/smoke-test-http/src/test/java/org/elasticsearch/http/TestDeprecationHeaderRestAction.java b/qa/smoke-test-http/src/test/java/org/elasticsearch/http/TestDeprecationHeaderRestAction.java index 57cdd8dcd8bb6..6c96175488e6b 100644 --- a/qa/smoke-test-http/src/test/java/org/elasticsearch/http/TestDeprecationHeaderRestAction.java +++ b/qa/smoke-test-http/src/test/java/org/elasticsearch/http/TestDeprecationHeaderRestAction.java @@ -28,7 +28,6 @@ import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestStatus; @@ -38,6 +37,9 @@ import java.util.List; import java.util.Map; +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.GET; + /** * Enables testing {@code DeprecationRestHandler} via integration tests by guaranteeing a deprecated REST endpoint. *

@@ -75,11 +77,14 @@ public class TestDeprecationHeaderRestAction extends BaseRestHandler { private final Settings settings; - public TestDeprecationHeaderRestAction(Settings settings, RestController controller) { + public TestDeprecationHeaderRestAction(Settings settings) { this.settings = settings; + } - controller.registerAsDeprecatedHandler(RestRequest.Method.GET, "/_test_cluster/deprecated_settings", this, - DEPRECATED_ENDPOINT, deprecationLogger); + @Override + public List deprecatedRoutes() { + return singletonList( + new DeprecatedRoute(GET, "/_test_cluster/deprecated_settings", DEPRECATED_ENDPOINT, deprecationLogger)); } @Override @@ -87,6 +92,11 @@ public String getName() { return "test_deprecation_header_action"; } + @Override + public List routes() { + return Collections.emptyList(); + } + @SuppressWarnings("unchecked") // List casts @Override public RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException { diff --git a/qa/smoke-test-http/src/test/java/org/elasticsearch/http/TestDeprecationPlugin.java b/qa/smoke-test-http/src/test/java/org/elasticsearch/http/TestDeprecationPlugin.java index a264227999eda..81faab8289301 100644 --- a/qa/smoke-test-http/src/test/java/org/elasticsearch/http/TestDeprecationPlugin.java +++ b/qa/smoke-test-http/src/test/java/org/elasticsearch/http/TestDeprecationPlugin.java @@ -47,7 +47,7 @@ public class TestDeprecationPlugin extends Plugin implements ActionPlugin, Searc public List getRestHandlers(Settings settings, RestController restController, ClusterSettings clusterSettings, IndexScopedSettings indexScopedSettings, SettingsFilter settingsFilter, IndexNameExpressionResolver indexNameExpressionResolver, Supplier nodesInCluster) { - return Collections.singletonList(new TestDeprecationHeaderRestAction(settings, restController)); + return Collections.singletonList(new TestDeprecationHeaderRestAction(settings)); } @Override diff --git a/qa/smoke-test-http/src/test/java/org/elasticsearch/http/TestResponseHeaderPlugin.java b/qa/smoke-test-http/src/test/java/org/elasticsearch/http/TestResponseHeaderPlugin.java index 0f9b6f4db19dd..a869276fdac1e 100644 --- a/qa/smoke-test-http/src/test/java/org/elasticsearch/http/TestResponseHeaderPlugin.java +++ b/qa/smoke-test-http/src/test/java/org/elasticsearch/http/TestResponseHeaderPlugin.java @@ -40,6 +40,6 @@ public class TestResponseHeaderPlugin extends Plugin implements ActionPlugin { public List getRestHandlers(Settings settings, RestController restController, ClusterSettings clusterSettings, IndexScopedSettings indexScopedSettings, SettingsFilter settingsFilter, IndexNameExpressionResolver indexNameExpressionResolver, Supplier nodesInCluster) { - return singletonList(new TestResponseHeaderRestAction(restController)); + return singletonList(new TestResponseHeaderRestAction()); } } diff --git a/qa/smoke-test-http/src/test/java/org/elasticsearch/http/TestResponseHeaderRestAction.java b/qa/smoke-test-http/src/test/java/org/elasticsearch/http/TestResponseHeaderRestAction.java index c51947f7328cb..d69beb337438b 100644 --- a/qa/smoke-test-http/src/test/java/org/elasticsearch/http/TestResponseHeaderRestAction.java +++ b/qa/smoke-test-http/src/test/java/org/elasticsearch/http/TestResponseHeaderRestAction.java @@ -21,15 +21,20 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.GET; + public class TestResponseHeaderRestAction extends BaseRestHandler { - public TestResponseHeaderRestAction(RestController controller) { - controller.registerHandler(RestRequest.Method.GET, "/_protected", this); + @Override + public List routes() { + return singletonList(new Route(GET, "/_protected")); } @Override diff --git a/server/src/main/java/org/elasticsearch/action/ActionModule.java b/server/src/main/java/org/elasticsearch/action/ActionModule.java index a1aff25171ec2..4ec1481811fd5 100644 --- a/server/src/main/java/org/elasticsearch/action/ActionModule.java +++ b/server/src/main/java/org/elasticsearch/action/ActionModule.java @@ -323,6 +323,8 @@ import org.elasticsearch.rest.action.document.RestGetAction; import org.elasticsearch.rest.action.document.RestGetSourceAction; import org.elasticsearch.rest.action.document.RestIndexAction; +import org.elasticsearch.rest.action.document.RestIndexAction.AutoIdHandler; +import org.elasticsearch.rest.action.document.RestIndexAction.CreateHandler; import org.elasticsearch.rest.action.document.RestMultiGetAction; import org.elasticsearch.rest.action.document.RestMultiTermVectorsAction; import org.elasticsearch.rest.action.document.RestTermVectorsAction; @@ -567,148 +569,151 @@ private ActionFilters setupActionFilters(List actionPlugins) { public void initRestHandlers(Supplier nodesInCluster) { List catActions = new ArrayList<>(); - Consumer registerHandler = a -> { - if (a instanceof AbstractCatAction) { - catActions.add((AbstractCatAction) a); + Consumer registerHandler = handler -> { + if (handler instanceof AbstractCatAction) { + catActions.add((AbstractCatAction) handler); } + restController.registerHandler(handler); }; - registerHandler.accept(new RestAddVotingConfigExclusionAction(restController)); - registerHandler.accept(new RestClearVotingConfigExclusionsAction(restController)); - registerHandler.accept(new RestMainAction(restController)); - registerHandler.accept(new RestNodesInfoAction(restController, settingsFilter)); - registerHandler.accept(new RestRemoteClusterInfoAction(restController)); - registerHandler.accept(new RestNodesStatsAction(restController)); - registerHandler.accept(new RestNodesUsageAction(restController)); - registerHandler.accept(new RestNodesHotThreadsAction(restController)); - registerHandler.accept(new RestClusterAllocationExplainAction(restController)); - registerHandler.accept(new RestClusterStatsAction(restController)); - registerHandler.accept(new RestClusterStateAction(restController, settingsFilter)); - registerHandler.accept(new RestClusterHealthAction(restController)); - registerHandler.accept(new RestClusterUpdateSettingsAction(restController)); - registerHandler.accept(new RestClusterGetSettingsAction(settings, restController, clusterSettings, settingsFilter)); - registerHandler.accept(new RestClusterRerouteAction(restController, settingsFilter)); - registerHandler.accept(new RestClusterSearchShardsAction(restController)); - registerHandler.accept(new RestPendingClusterTasksAction(restController)); - registerHandler.accept(new RestPutRepositoryAction(restController)); - registerHandler.accept(new RestGetRepositoriesAction(restController, settingsFilter)); - registerHandler.accept(new RestDeleteRepositoryAction(restController)); - registerHandler.accept(new RestVerifyRepositoryAction(restController)); - registerHandler.accept(new RestCleanupRepositoryAction(restController)); - registerHandler.accept(new RestGetSnapshotsAction(restController)); - registerHandler.accept(new RestCreateSnapshotAction(restController)); - registerHandler.accept(new RestRestoreSnapshotAction(restController)); - registerHandler.accept(new RestDeleteSnapshotAction(restController)); - registerHandler.accept(new RestSnapshotsStatusAction(restController)); - registerHandler.accept(new RestGetIndicesAction(restController)); - registerHandler.accept(new RestIndicesStatsAction(restController)); - registerHandler.accept(new RestIndicesSegmentsAction(restController)); - registerHandler.accept(new RestIndicesShardStoresAction(restController)); - registerHandler.accept(new RestGetAliasesAction(restController)); - registerHandler.accept(new RestIndexDeleteAliasesAction(restController)); - registerHandler.accept(new RestIndexPutAliasAction(restController)); - registerHandler.accept(new RestIndicesAliasesAction(restController)); - registerHandler.accept(new RestCreateIndexAction(restController)); - registerHandler.accept(new RestResizeHandler.RestShrinkIndexAction(restController)); - registerHandler.accept(new RestResizeHandler.RestSplitIndexAction(restController)); - registerHandler.accept(new RestResizeHandler.RestCloneIndexAction(restController)); - registerHandler.accept(new RestRolloverIndexAction(restController)); - registerHandler.accept(new RestDeleteIndexAction(restController)); - registerHandler.accept(new RestCloseIndexAction(restController)); - registerHandler.accept(new RestOpenIndexAction(restController)); - - registerHandler.accept(new RestUpdateSettingsAction(restController)); - registerHandler.accept(new RestGetSettingsAction(restController)); - - registerHandler.accept(new RestAnalyzeAction(restController)); - registerHandler.accept(new RestGetIndexTemplateAction(restController)); - registerHandler.accept(new RestPutIndexTemplateAction(restController)); - registerHandler.accept(new RestDeleteIndexTemplateAction(restController)); - - registerHandler.accept(new RestPutMappingAction(restController)); - registerHandler.accept(new RestGetMappingAction(restController)); - registerHandler.accept(new RestGetFieldMappingAction(restController)); - - registerHandler.accept(new RestRefreshAction(restController)); - registerHandler.accept(new RestFlushAction(restController)); - registerHandler.accept(new RestSyncedFlushAction(restController)); - registerHandler.accept(new RestForceMergeAction(restController)); - registerHandler.accept(new RestUpgradeAction(restController)); - registerHandler.accept(new RestUpgradeStatusAction(restController)); - registerHandler.accept(new RestClearIndicesCacheAction(restController)); - - registerHandler.accept(new RestIndexAction(restController, clusterService)); - registerHandler.accept(new RestGetAction(restController)); - registerHandler.accept(new RestGetSourceAction(restController)); - registerHandler.accept(new RestMultiGetAction(settings, restController)); - registerHandler.accept(new RestDeleteAction(restController)); - registerHandler.accept(new RestCountAction(restController)); - registerHandler.accept(new RestTermVectorsAction(restController)); - registerHandler.accept(new RestMultiTermVectorsAction(restController)); - registerHandler.accept(new RestBulkAction(settings, restController)); - registerHandler.accept(new RestUpdateAction(restController)); - - registerHandler.accept(new RestSearchAction(restController)); - registerHandler.accept(new RestSearchScrollAction(restController)); - registerHandler.accept(new RestClearScrollAction(restController)); - registerHandler.accept(new RestMultiSearchAction(settings, restController)); - - registerHandler.accept(new RestValidateQueryAction(restController)); - - registerHandler.accept(new RestExplainAction(restController)); - - registerHandler.accept(new RestRecoveryAction(restController)); - - registerHandler.accept(new RestReloadSecureSettingsAction(restController)); + registerHandler.accept(new RestAddVotingConfigExclusionAction()); + registerHandler.accept(new RestClearVotingConfigExclusionsAction()); + registerHandler.accept(new RestMainAction()); + registerHandler.accept(new RestNodesInfoAction(settingsFilter)); + registerHandler.accept(new RestRemoteClusterInfoAction()); + registerHandler.accept(new RestNodesStatsAction()); + registerHandler.accept(new RestNodesUsageAction()); + registerHandler.accept(new RestNodesHotThreadsAction()); + registerHandler.accept(new RestClusterAllocationExplainAction()); + registerHandler.accept(new RestClusterStatsAction()); + registerHandler.accept(new RestClusterStateAction(settingsFilter)); + registerHandler.accept(new RestClusterHealthAction()); + registerHandler.accept(new RestClusterUpdateSettingsAction()); + registerHandler.accept(new RestClusterGetSettingsAction(settings, clusterSettings, settingsFilter)); + registerHandler.accept(new RestClusterRerouteAction(settingsFilter)); + registerHandler.accept(new RestClusterSearchShardsAction()); + registerHandler.accept(new RestPendingClusterTasksAction()); + registerHandler.accept(new RestPutRepositoryAction()); + registerHandler.accept(new RestGetRepositoriesAction(settingsFilter)); + registerHandler.accept(new RestDeleteRepositoryAction()); + registerHandler.accept(new RestVerifyRepositoryAction()); + registerHandler.accept(new RestCleanupRepositoryAction()); + registerHandler.accept(new RestGetSnapshotsAction()); + registerHandler.accept(new RestCreateSnapshotAction()); + registerHandler.accept(new RestRestoreSnapshotAction()); + registerHandler.accept(new RestDeleteSnapshotAction()); + registerHandler.accept(new RestSnapshotsStatusAction()); + registerHandler.accept(new RestGetIndicesAction()); + registerHandler.accept(new RestIndicesStatsAction()); + registerHandler.accept(new RestIndicesSegmentsAction()); + registerHandler.accept(new RestIndicesShardStoresAction()); + registerHandler.accept(new RestGetAliasesAction()); + registerHandler.accept(new RestIndexDeleteAliasesAction()); + registerHandler.accept(new RestIndexPutAliasAction()); + registerHandler.accept(new RestIndicesAliasesAction()); + registerHandler.accept(new RestCreateIndexAction()); + registerHandler.accept(new RestResizeHandler.RestShrinkIndexAction()); + registerHandler.accept(new RestResizeHandler.RestSplitIndexAction()); + registerHandler.accept(new RestResizeHandler.RestCloneIndexAction()); + registerHandler.accept(new RestRolloverIndexAction()); + registerHandler.accept(new RestDeleteIndexAction()); + registerHandler.accept(new RestCloseIndexAction()); + registerHandler.accept(new RestOpenIndexAction()); + + registerHandler.accept(new RestUpdateSettingsAction()); + registerHandler.accept(new RestGetSettingsAction()); + + registerHandler.accept(new RestAnalyzeAction()); + registerHandler.accept(new RestGetIndexTemplateAction()); + registerHandler.accept(new RestPutIndexTemplateAction()); + registerHandler.accept(new RestDeleteIndexTemplateAction()); + + registerHandler.accept(new RestPutMappingAction()); + registerHandler.accept(new RestGetMappingAction()); + registerHandler.accept(new RestGetFieldMappingAction()); + + registerHandler.accept(new RestRefreshAction()); + registerHandler.accept(new RestFlushAction()); + registerHandler.accept(new RestSyncedFlushAction()); + registerHandler.accept(new RestForceMergeAction()); + registerHandler.accept(new RestUpgradeAction()); + registerHandler.accept(new RestUpgradeStatusAction()); + registerHandler.accept(new RestClearIndicesCacheAction()); + + registerHandler.accept(new RestIndexAction()); + registerHandler.accept(new CreateHandler()); + registerHandler.accept(new AutoIdHandler(clusterService)); + registerHandler.accept(new RestGetAction()); + registerHandler.accept(new RestGetSourceAction()); + registerHandler.accept(new RestMultiGetAction(settings)); + registerHandler.accept(new RestDeleteAction()); + registerHandler.accept(new RestCountAction()); + registerHandler.accept(new RestTermVectorsAction()); + registerHandler.accept(new RestMultiTermVectorsAction()); + registerHandler.accept(new RestBulkAction(settings)); + registerHandler.accept(new RestUpdateAction()); + + registerHandler.accept(new RestSearchAction()); + registerHandler.accept(new RestSearchScrollAction()); + registerHandler.accept(new RestClearScrollAction()); + registerHandler.accept(new RestMultiSearchAction(settings)); + + registerHandler.accept(new RestValidateQueryAction()); + + registerHandler.accept(new RestExplainAction()); + + registerHandler.accept(new RestRecoveryAction()); + + registerHandler.accept(new RestReloadSecureSettingsAction()); // Scripts API - registerHandler.accept(new RestGetStoredScriptAction(restController)); - registerHandler.accept(new RestPutStoredScriptAction(restController)); - registerHandler.accept(new RestDeleteStoredScriptAction(restController)); - registerHandler.accept(new RestGetScriptContextAction(restController)); - registerHandler.accept(new RestGetScriptLanguageAction(restController)); + registerHandler.accept(new RestGetStoredScriptAction()); + registerHandler.accept(new RestPutStoredScriptAction()); + registerHandler.accept(new RestDeleteStoredScriptAction()); + registerHandler.accept(new RestGetScriptContextAction()); + registerHandler.accept(new RestGetScriptLanguageAction()); - registerHandler.accept(new RestFieldCapabilitiesAction(restController)); + registerHandler.accept(new RestFieldCapabilitiesAction()); // Tasks API - registerHandler.accept(new RestListTasksAction(restController, nodesInCluster)); - registerHandler.accept(new RestGetTaskAction(restController)); - registerHandler.accept(new RestCancelTasksAction(restController, nodesInCluster)); + registerHandler.accept(new RestListTasksAction(nodesInCluster)); + registerHandler.accept(new RestGetTaskAction()); + registerHandler.accept(new RestCancelTasksAction(nodesInCluster)); // Ingest API - registerHandler.accept(new RestPutPipelineAction(restController)); - registerHandler.accept(new RestGetPipelineAction(restController)); - registerHandler.accept(new RestDeletePipelineAction(restController)); - registerHandler.accept(new RestSimulatePipelineAction(restController)); + registerHandler.accept(new RestPutPipelineAction()); + registerHandler.accept(new RestGetPipelineAction()); + registerHandler.accept(new RestDeletePipelineAction()); + registerHandler.accept(new RestSimulatePipelineAction()); // CAT API - registerHandler.accept(new RestAllocationAction(restController)); - registerHandler.accept(new RestShardsAction(restController)); - registerHandler.accept(new RestMasterAction(restController)); - registerHandler.accept(new RestNodesAction(restController)); - registerHandler.accept(new RestTasksAction(restController, nodesInCluster)); - registerHandler.accept(new RestIndicesAction(restController)); - registerHandler.accept(new RestSegmentsAction(restController)); + registerHandler.accept(new RestAllocationAction()); + registerHandler.accept(new RestShardsAction()); + registerHandler.accept(new RestMasterAction()); + registerHandler.accept(new RestNodesAction()); + registerHandler.accept(new RestTasksAction(nodesInCluster)); + registerHandler.accept(new RestIndicesAction()); + registerHandler.accept(new RestSegmentsAction()); // Fully qualified to prevent interference with rest.action.count.RestCountAction - registerHandler.accept(new org.elasticsearch.rest.action.cat.RestCountAction(restController)); + registerHandler.accept(new org.elasticsearch.rest.action.cat.RestCountAction()); // Fully qualified to prevent interference with rest.action.indices.RestRecoveryAction - registerHandler.accept(new RestCatRecoveryAction(restController)); - registerHandler.accept(new RestHealthAction(restController)); - registerHandler.accept(new org.elasticsearch.rest.action.cat.RestPendingClusterTasksAction(restController)); - registerHandler.accept(new RestAliasAction(restController)); - registerHandler.accept(new RestThreadPoolAction(restController)); - registerHandler.accept(new RestPluginsAction(restController)); - registerHandler.accept(new RestFielddataAction(restController)); - registerHandler.accept(new RestNodeAttrsAction(restController)); - registerHandler.accept(new RestRepositoriesAction(restController)); - registerHandler.accept(new RestSnapshotAction(restController)); - registerHandler.accept(new RestTemplatesAction(restController)); + registerHandler.accept(new RestCatRecoveryAction()); + registerHandler.accept(new RestHealthAction()); + registerHandler.accept(new org.elasticsearch.rest.action.cat.RestPendingClusterTasksAction()); + registerHandler.accept(new RestAliasAction()); + registerHandler.accept(new RestThreadPoolAction()); + registerHandler.accept(new RestPluginsAction()); + registerHandler.accept(new RestFielddataAction()); + registerHandler.accept(new RestNodeAttrsAction()); + registerHandler.accept(new RestRepositoriesAction()); + registerHandler.accept(new RestSnapshotAction()); + registerHandler.accept(new RestTemplatesAction()); for (ActionPlugin plugin : actionPlugins) { for (RestHandler handler : plugin.getRestHandlers(settings, restController, clusterSettings, indexScopedSettings, settingsFilter, indexNameExpressionResolver, nodesInCluster)) { registerHandler.accept(handler); } } - registerHandler.accept(new RestCatAction(restController, catActions)); + registerHandler.accept(new RestCatAction(catActions)); } @Override diff --git a/server/src/main/java/org/elasticsearch/common/collect/MapBuilder.java b/server/src/main/java/org/elasticsearch/common/collect/MapBuilder.java index a840ee037f80e..5ebe87aae6ce9 100644 --- a/server/src/main/java/org/elasticsearch/common/collect/MapBuilder.java +++ b/server/src/main/java/org/elasticsearch/common/collect/MapBuilder.java @@ -34,7 +34,7 @@ public static MapBuilder newMapBuilder(Map map) { return new MapBuilder<>(map); } - private Map map = new HashMap<>(); + private final Map map; public MapBuilder() { this.map = new HashMap<>(); diff --git a/server/src/main/java/org/elasticsearch/rest/BaseRestHandler.java b/server/src/main/java/org/elasticsearch/rest/BaseRestHandler.java index c99deebc5c700..93c40bfee43b3 100644 --- a/server/src/main/java/org/elasticsearch/rest/BaseRestHandler.java +++ b/server/src/main/java/org/elasticsearch/rest/BaseRestHandler.java @@ -18,6 +18,7 @@ */ package org.elasticsearch.rest; + import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.lucene.search.spell.LevenshteinDistance; @@ -81,6 +82,12 @@ public final long getUsageCount() { */ public abstract String getName(); + /** + * {@inheritDoc} + */ + @Override + public abstract List routes(); + @Override public final void handleRequest(RestRequest request, RestChannel channel, NodeClient client) throws Exception { // prepare the request for execution; has the side effect of touching the request parameters diff --git a/server/src/main/java/org/elasticsearch/rest/RestController.java b/server/src/main/java/org/elasticsearch/rest/RestController.java index 3eb4c0df05ed7..f517c3028277b 100644 --- a/server/src/main/java/org/elasticsearch/rest/RestController.java +++ b/server/src/main/java/org/elasticsearch/rest/RestController.java @@ -98,7 +98,7 @@ public RestController(Set headersToCopy, UnaryOperatorDeprecated path to handle (e.g., "/_optimize") * @param logger The existing deprecation logger to use */ - public void registerWithDeprecatedHandler(RestRequest.Method method, String path, RestHandler handler, + protected void registerWithDeprecatedHandler(RestRequest.Method method, String path, RestHandler handler, RestRequest.Method deprecatedMethod, String deprecatedPath, DeprecationLogger logger) { // e.g., [POST /_optimize] is deprecated! Use [POST /_forcemerge] instead. @@ -148,7 +148,7 @@ public void registerWithDeprecatedHandler(RestRequest.Method method, String path * @param handler The handler to actually execute * @param method GET, POST, etc. */ - public void registerHandler(RestRequest.Method method, String path, RestHandler handler) { + protected void registerHandler(RestRequest.Method method, String path, RestHandler handler) { if (handler instanceof BaseRestHandler) { usageService.addRestHandler((BaseRestHandler) handler); } @@ -157,6 +157,18 @@ public void registerHandler(RestRequest.Method method, String path, RestHandler (mHandlers, newMHandler) -> mHandlers.addMethods(maybeWrappedHandler, method)); } + /** + * Registers a REST handler with the controller. The REST handler declares the {@code method} + * and {@code path} combinations. + */ + public void registerHandler(final RestHandler restHandler) { + restHandler.routes().forEach(route -> registerHandler(route.getMethod(), route.getPath(), restHandler)); + restHandler.deprecatedRoutes().forEach(route -> + registerAsDeprecatedHandler(route.getMethod(), route.getPath(), restHandler, route.getDeprecationMessage(), route.getLogger())); + restHandler.replacedRoutes().forEach(route -> registerWithDeprecatedHandler(route.getMethod(), route.getPath(), + restHandler, route.getDeprecatedMethod(), route.getDeprecatedPath(), route.getLogger())); + } + @Override public void dispatchRequest(RestRequest request, RestChannel channel, ThreadContext threadContext) { if (request.rawPath().equals("/favicon.ico")) { diff --git a/server/src/main/java/org/elasticsearch/rest/RestHandler.java b/server/src/main/java/org/elasticsearch/rest/RestHandler.java index 605dd41078a54..ab7b468f7576d 100644 --- a/server/src/main/java/org/elasticsearch/rest/RestHandler.java +++ b/server/src/main/java/org/elasticsearch/rest/RestHandler.java @@ -20,7 +20,12 @@ package org.elasticsearch.rest; import org.elasticsearch.client.node.NodeClient; +import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.common.xcontent.XContent; +import org.elasticsearch.rest.RestRequest.Method; + +import java.util.Collections; +import java.util.List; /** * Handler for REST requests @@ -59,4 +64,101 @@ default boolean supportsContentStream() { default boolean allowsUnsafeBuffers() { return false; } + + /** + * The list of {@link Route}s that this RestHandler is responsible for handling. + */ + default List routes() { + return Collections.emptyList(); + } + + /** + * A list of routes handled by this RestHandler that are deprecated and do not have a direct + * replacement. If changing the {@code path} or {@code method} of a route, + * use {@link #replacedRoutes()}. + */ + default List deprecatedRoutes() { + return Collections.emptyList(); + } + + /** + * A list of routes handled by this RestHandler that have had their {@code path} and/or + * {@code method} changed. The pre-existing {@code route} will be registered + * as deprecated alongside the updated {@code route}. + */ + default List replacedRoutes() { + return Collections.emptyList(); + } + + class Route { + + private final String path; + private final Method method; + + public Route(Method method, String path) { + this.path = path; + this.method = method; + } + + public String getPath() { + return path; + } + + public Method getMethod() { + return method; + } + } + + /** + * Represents an API that has been deprecated and is slated for removal. + */ + class DeprecatedRoute extends Route { + + private final String deprecationMessage; + private final DeprecationLogger logger; + + public DeprecatedRoute(Method method, String path, String deprecationMessage, DeprecationLogger logger) { + super(method, path); + this.deprecationMessage = deprecationMessage; + this.logger = logger; + } + + public String getDeprecationMessage() { + return deprecationMessage; + } + + public DeprecationLogger getLogger() { + return logger; + } + } + + /** + * Represents an API that has had its {@code path} or {@code method} changed. Holds both the + * new and previous {@code path} and {@code method} combination. + */ + class ReplacedRoute extends Route { + + private final String deprecatedPath; + private final Method deprecatedMethod; + private final DeprecationLogger logger; + + public ReplacedRoute(Method method, String path, Method deprecatedMethod, String deprecatedPath, DeprecationLogger logger) { + super(method, path); + this.deprecatedMethod = deprecatedMethod; + this.deprecatedPath = deprecatedPath; + this.logger = logger; + } + + public String getDeprecatedPath() { + return deprecatedPath; + } + + public Method getDeprecatedMethod() { + return deprecatedMethod; + } + + public DeprecationLogger getLogger() { + return logger; + } + } } diff --git a/server/src/main/java/org/elasticsearch/rest/action/RestFieldCapabilitiesAction.java b/server/src/main/java/org/elasticsearch/rest/action/RestFieldCapabilitiesAction.java index 613729f8904af..6d868dd0d1bce 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/RestFieldCapabilitiesAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/RestFieldCapabilitiesAction.java @@ -24,21 +24,25 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.Strings; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import java.io.IOException; +import java.util.List; +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.rest.RestRequest.Method.GET; import static org.elasticsearch.rest.RestRequest.Method.POST; public class RestFieldCapabilitiesAction extends BaseRestHandler { - public RestFieldCapabilitiesAction(RestController controller) { - controller.registerHandler(GET, "/_field_caps", this); - controller.registerHandler(POST, "/_field_caps", this); - controller.registerHandler(GET, "/{index}/_field_caps", this); - controller.registerHandler(POST, "/{index}/_field_caps", this); + @Override + public List routes() { + return unmodifiableList(asList( + new Route(GET, "/_field_caps"), + new Route(POST, "/_field_caps"), + new Route(GET, "/{index}/_field_caps"), + new Route(POST, "/{index}/_field_caps"))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/RestMainAction.java b/server/src/main/java/org/elasticsearch/rest/action/RestMainAction.java index e776a6ad08a7b..f5a433cd57e73 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/RestMainAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/RestMainAction.java @@ -26,20 +26,25 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; import java.io.IOException; +import java.util.List; +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.rest.RestRequest.Method.GET; import static org.elasticsearch.rest.RestRequest.Method.HEAD; public class RestMainAction extends BaseRestHandler { - public RestMainAction(RestController controller) { - controller.registerHandler(GET, "/", this); - controller.registerHandler(HEAD, "/", this); + + @Override + public List routes() { + return unmodifiableList(asList( + new Route(GET, "/"), + new Route(HEAD, "/"))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestAddVotingConfigExclusionAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestAddVotingConfigExclusionAction.java index 018392bb05ad8..4384d0d9dadff 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestAddVotingConfigExclusionAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestAddVotingConfigExclusionAction.java @@ -25,25 +25,29 @@ import org.elasticsearch.common.Strings; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import java.io.IOException; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.POST; public class RestAddVotingConfigExclusionAction extends BaseRestHandler { private static final TimeValue DEFAULT_TIMEOUT = TimeValue.timeValueSeconds(30L); - public RestAddVotingConfigExclusionAction(RestController controller) { - controller.registerHandler(RestRequest.Method.POST, "/_cluster/voting_config_exclusions/{node_name}", this); - } - @Override public String getName() { return "add_voting_config_exclusions_action"; } + @Override + public List routes() { + return singletonList(new Route(POST, "/_cluster/voting_config_exclusions/{node_name}")); + } + @Override protected RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException { AddVotingConfigExclusionsRequest votingConfigExclusionsRequest = resolveVotingConfigExclusionsRequest(request); diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestCancelTasksAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestCancelTasksAction.java index 2dd98bfb9a506..99321627cf7fb 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestCancelTasksAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestCancelTasksAction.java @@ -24,13 +24,15 @@ import org.elasticsearch.cluster.node.DiscoveryNodes; import org.elasticsearch.common.Strings; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.tasks.TaskId; import java.io.IOException; +import java.util.List; import java.util.function.Supplier; +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.rest.RestRequest.Method.POST; import static org.elasticsearch.rest.action.admin.cluster.RestListTasksAction.listTasksResponseListener; @@ -38,10 +40,8 @@ public class RestCancelTasksAction extends BaseRestHandler { private final Supplier nodesInCluster; - public RestCancelTasksAction(RestController controller, Supplier nodesInCluster) { + public RestCancelTasksAction(Supplier nodesInCluster) { this.nodesInCluster = nodesInCluster; - controller.registerHandler(POST, "/_tasks/_cancel", this); - controller.registerHandler(POST, "/_tasks/{task_id}/_cancel", this); } @Override @@ -49,6 +49,12 @@ public String getName() { return "cancel_tasks_action"; } + @Override + public List routes() { + return unmodifiableList(asList(new Route(POST, "/_tasks/_cancel"), + new Route(POST, "/_tasks/{task_id}/_cancel"))); + } + @Override public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException { final String[] nodesIds = Strings.splitStringByCommaToArray(request.param("nodes")); diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestCleanupRepositoryAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestCleanupRepositoryAction.java index 3eca34ff2d3d5..3e9d8e46022a2 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestCleanupRepositoryAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestCleanupRepositoryAction.java @@ -22,12 +22,13 @@ import org.elasticsearch.action.admin.cluster.repositories.cleanup.CleanupRepositoryRequest; import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import java.io.IOException; +import java.util.List; +import static java.util.Collections.singletonList; import static org.elasticsearch.client.Requests.cleanupRepositoryRequest; import static org.elasticsearch.rest.RestRequest.Method.POST; @@ -36,8 +37,9 @@ */ public class RestCleanupRepositoryAction extends BaseRestHandler { - public RestCleanupRepositoryAction(RestController controller) { - controller.registerHandler(POST, "/_snapshot/{repository}/_cleanup", this); + @Override + public List routes() { + return singletonList(new Route(POST, "/_snapshot/{repository}/_cleanup")); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestClearVotingConfigExclusionsAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestClearVotingConfigExclusionsAction.java index 8d9a2121b8149..67c6a4e5d988c 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestClearVotingConfigExclusionsAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestClearVotingConfigExclusionsAction.java @@ -23,16 +23,20 @@ import org.elasticsearch.action.admin.cluster.configuration.ClearVotingConfigExclusionsRequest; import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import java.io.IOException; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.DELETE; public class RestClearVotingConfigExclusionsAction extends BaseRestHandler { - public RestClearVotingConfigExclusionsAction(RestController controller) { - controller.registerHandler(RestRequest.Method.DELETE, "/_cluster/voting_config_exclusions", this); + @Override + public List routes() { + return singletonList(new Route(DELETE, "/_cluster/voting_config_exclusions")); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestClusterAllocationExplainAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestClusterAllocationExplainAction.java index 99d0f00d0967d..d8a3b81d8c2fe 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestClusterAllocationExplainAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestClusterAllocationExplainAction.java @@ -27,22 +27,29 @@ import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; import org.elasticsearch.rest.action.RestBuilderListener; import java.io.IOException; +import java.util.List; + +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; +import static org.elasticsearch.rest.RestRequest.Method.GET; +import static org.elasticsearch.rest.RestRequest.Method.POST; /** * Class handling cluster allocation explanation at the REST level */ public class RestClusterAllocationExplainAction extends BaseRestHandler { - public RestClusterAllocationExplainAction(RestController controller) { - controller.registerHandler(RestRequest.Method.GET, "/_cluster/allocation/explain", this); - controller.registerHandler(RestRequest.Method.POST, "/_cluster/allocation/explain", this); + @Override + public List routes() { + return unmodifiableList(asList( + new Route(GET, "/_cluster/allocation/explain"), + new Route(POST, "/_cluster/allocation/explain"))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestClusterGetSettingsAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestClusterGetSettingsAction.java index 0a4d5b4e897f0..03064337b3930 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestClusterGetSettingsAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestClusterGetSettingsAction.java @@ -32,29 +32,34 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; import org.elasticsearch.rest.action.RestBuilderListener; import java.io.IOException; +import java.util.List; import java.util.Set; +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.GET; + public class RestClusterGetSettingsAction extends BaseRestHandler { private final Settings settings; private final ClusterSettings clusterSettings; private final SettingsFilter settingsFilter; - public RestClusterGetSettingsAction(Settings settings, RestController controller, ClusterSettings clusterSettings, - SettingsFilter settingsFilter) { + public RestClusterGetSettingsAction(Settings settings, ClusterSettings clusterSettings, SettingsFilter settingsFilter) { this.settings = settings; this.clusterSettings = clusterSettings; - controller.registerHandler(RestRequest.Method.GET, "/_cluster/settings", this); this.settingsFilter = settingsFilter; } + @Override + public List routes() { + return singletonList(new Route(GET, "/_cluster/settings")); + } @Override public String getName() { return "cluster_get_settings_action"; diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestClusterHealthAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestClusterHealthAction.java index 63c6bc4c92c0b..99ac7d440815c 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestClusterHealthAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestClusterHealthAction.java @@ -27,22 +27,26 @@ import org.elasticsearch.common.Priority; import org.elasticsearch.common.Strings; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestStatusToXContentListener; import java.io.IOException; import java.util.Collections; +import java.util.List; import java.util.Locale; import java.util.Set; +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.client.Requests.clusterHealthRequest; +import static org.elasticsearch.rest.RestRequest.Method.GET; public class RestClusterHealthAction extends BaseRestHandler { - public RestClusterHealthAction(RestController controller) { - controller.registerHandler(RestRequest.Method.GET, "/_cluster/health", this); - controller.registerHandler(RestRequest.Method.GET, "/_cluster/health/{index}", this); + @Override + public List routes() { + return unmodifiableList(asList(new Route(GET, "/_cluster/health"), + new Route(GET, "/_cluster/health/{index}"))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestClusterRerouteAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestClusterRerouteAction.java index 30799cb0552c0..c5a60cf7b6b55 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestClusterRerouteAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestClusterRerouteAction.java @@ -31,7 +31,6 @@ import org.elasticsearch.common.xcontent.ObjectParser; import org.elasticsearch.common.xcontent.ObjectParser.ValueType; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; @@ -39,8 +38,12 @@ import java.util.Collections; import java.util.EnumSet; import java.util.HashSet; +import java.util.List; import java.util.Set; +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.POST; + public class RestClusterRerouteAction extends BaseRestHandler { private static final ObjectParser PARSER = new ObjectParser<>("cluster_reroute"); static { @@ -54,9 +57,13 @@ public class RestClusterRerouteAction extends BaseRestHandler { private final SettingsFilter settingsFilter; - public RestClusterRerouteAction(RestController controller, SettingsFilter settingsFilter) { + public RestClusterRerouteAction(SettingsFilter settingsFilter) { this.settingsFilter = settingsFilter; - controller.registerHandler(RestRequest.Method.POST, "/_cluster/reroute", this); + } + + @Override + public List routes() { + return singletonList(new Route(POST, "/_cluster/reroute")); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestClusterSearchShardsAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestClusterSearchShardsAction.java index 188691dacf5e2..3660450457cb8 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestClusterSearchShardsAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestClusterSearchShardsAction.java @@ -25,22 +25,26 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.Strings; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import java.io.IOException; +import java.util.List; +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.rest.RestRequest.Method.GET; import static org.elasticsearch.rest.RestRequest.Method.POST; public class RestClusterSearchShardsAction extends BaseRestHandler { - public RestClusterSearchShardsAction(RestController controller) { - controller.registerHandler(GET, "/_search_shards", this); - controller.registerHandler(POST, "/_search_shards", this); - controller.registerHandler(GET, "/{index}/_search_shards", this); - controller.registerHandler(POST, "/{index}/_search_shards", this); + @Override + public List routes() { + return unmodifiableList(asList( + new Route(GET, "/_search_shards"), + new Route(POST, "/_search_shards"), + new Route(GET, "/{index}/_search_shards"), + new Route(POST, "/{index}/_search_shards"))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestClusterStateAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestClusterStateAction.java index 9838cc26625fa..1c68d2d5147d3 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestClusterStateAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestClusterStateAction.java @@ -31,7 +31,6 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; @@ -41,17 +40,18 @@ import java.util.Collections; import java.util.EnumSet; import java.util.HashSet; +import java.util.List; import java.util.Set; +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; +import static org.elasticsearch.rest.RestRequest.Method.GET; + public class RestClusterStateAction extends BaseRestHandler { private final SettingsFilter settingsFilter; - public RestClusterStateAction(RestController controller, SettingsFilter settingsFilter) { - controller.registerHandler(RestRequest.Method.GET, "/_cluster/state", this); - controller.registerHandler(RestRequest.Method.GET, "/_cluster/state/{metric}", this); - controller.registerHandler(RestRequest.Method.GET, "/_cluster/state/{metric}/{indices}", this); - + public RestClusterStateAction(SettingsFilter settingsFilter) { this.settingsFilter = settingsFilter; } @@ -60,6 +60,14 @@ public String getName() { return "cluster_state_action"; } + @Override + public List routes() { + return unmodifiableList(asList( + new Route(GET, "/_cluster/state"), + new Route(GET, "/_cluster/state/{metric}"), + new Route(GET, "/_cluster/state/{metric}/{indices}"))); + } + @Override public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException { final ClusterStateRequest clusterStateRequest = Requests.clusterStateRequest(); diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestClusterStatsAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestClusterStatsAction.java index c7bfc640e76b4..9edaa4b2f1be1 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestClusterStatsAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestClusterStatsAction.java @@ -22,17 +22,23 @@ import org.elasticsearch.action.admin.cluster.stats.ClusterStatsRequest; import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestActions.NodesResponseRestListener; import java.io.IOException; +import java.util.List; + +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; +import static org.elasticsearch.rest.RestRequest.Method.GET; public class RestClusterStatsAction extends BaseRestHandler { - public RestClusterStatsAction(RestController controller) { - controller.registerHandler(RestRequest.Method.GET, "/_cluster/stats", this); - controller.registerHandler(RestRequest.Method.GET, "/_cluster/stats/nodes/{nodeId}", this); + @Override + public List routes() { + return unmodifiableList(asList( + new Route(GET, "/_cluster/stats"), + new Route(GET, "/_cluster/stats/nodes/{nodeId}"))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestClusterUpdateSettingsAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestClusterUpdateSettingsAction.java index 35874f12d5fe1..3558da8ee0819 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestClusterUpdateSettingsAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestClusterUpdateSettingsAction.java @@ -25,21 +25,25 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import java.io.IOException; +import java.util.List; import java.util.Map; import java.util.Set; +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.PUT; + public class RestClusterUpdateSettingsAction extends BaseRestHandler { private static final String PERSISTENT = "persistent"; private static final String TRANSIENT = "transient"; - public RestClusterUpdateSettingsAction(RestController controller) { - controller.registerHandler(RestRequest.Method.PUT, "/_cluster/settings", this); + @Override + public List routes() { + return singletonList(new Route(PUT, "/_cluster/settings")); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestCreateSnapshotAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestCreateSnapshotAction.java index 185a1659738ff..2f56b0b10e2ec 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestCreateSnapshotAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestCreateSnapshotAction.java @@ -22,12 +22,14 @@ import org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotRequest; import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import java.io.IOException; +import java.util.List; +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.client.Requests.createSnapshotRequest; import static org.elasticsearch.rest.RestRequest.Method.POST; import static org.elasticsearch.rest.RestRequest.Method.PUT; @@ -37,9 +39,11 @@ */ public class RestCreateSnapshotAction extends BaseRestHandler { - public RestCreateSnapshotAction(RestController controller) { - controller.registerHandler(PUT, "/_snapshot/{repository}/{snapshot}", this); - controller.registerHandler(POST, "/_snapshot/{repository}/{snapshot}", this); + @Override + public List routes() { + return unmodifiableList(asList( + new Route(PUT, "/_snapshot/{repository}/{snapshot}"), + new Route(POST, "/_snapshot/{repository}/{snapshot}"))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestDeleteRepositoryAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestDeleteRepositoryAction.java index 81914718b07df..95f635d1728a2 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestDeleteRepositoryAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestDeleteRepositoryAction.java @@ -22,12 +22,13 @@ import org.elasticsearch.action.admin.cluster.repositories.delete.DeleteRepositoryRequest; import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import java.io.IOException; +import java.util.List; +import static java.util.Collections.singletonList; import static org.elasticsearch.client.Requests.deleteRepositoryRequest; import static org.elasticsearch.rest.RestRequest.Method.DELETE; @@ -36,8 +37,9 @@ */ public class RestDeleteRepositoryAction extends BaseRestHandler { - public RestDeleteRepositoryAction(RestController controller) { - controller.registerHandler(DELETE, "/_snapshot/{repository}", this); + @Override + public List routes() { + return singletonList(new Route(DELETE, "/_snapshot/{repository}")); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestDeleteSnapshotAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestDeleteSnapshotAction.java index 81a3ddd31c59a..f74fc73c1f326 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestDeleteSnapshotAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestDeleteSnapshotAction.java @@ -22,12 +22,13 @@ import org.elasticsearch.action.admin.cluster.snapshots.delete.DeleteSnapshotRequest; import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import java.io.IOException; +import java.util.List; +import static java.util.Collections.singletonList; import static org.elasticsearch.client.Requests.deleteSnapshotRequest; import static org.elasticsearch.rest.RestRequest.Method.DELETE; @@ -36,8 +37,9 @@ */ public class RestDeleteSnapshotAction extends BaseRestHandler { - public RestDeleteSnapshotAction(RestController controller) { - controller.registerHandler(DELETE, "/_snapshot/{repository}/{snapshot}", this); + @Override + public List routes() { + return singletonList(new Route(DELETE, "/_snapshot/{repository}/{snapshot}")); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestDeleteStoredScriptAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestDeleteStoredScriptAction.java index a0258974cfc41..efd18f6415530 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestDeleteStoredScriptAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestDeleteStoredScriptAction.java @@ -21,18 +21,20 @@ import org.elasticsearch.action.admin.cluster.storedscripts.DeleteStoredScriptRequest; import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import java.io.IOException; +import java.util.List; +import static java.util.Collections.singletonList; import static org.elasticsearch.rest.RestRequest.Method.DELETE; public class RestDeleteStoredScriptAction extends BaseRestHandler { - public RestDeleteStoredScriptAction(RestController controller) { - controller.registerHandler(DELETE, "/_scripts/{id}", this); + @Override + public List routes() { + return singletonList(new Route(DELETE, "/_scripts/{id}")); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestGetRepositoriesAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestGetRepositoriesAction.java index 5b39a7e6df34f..572cb96cc0960 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestGetRepositoriesAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestGetRepositoriesAction.java @@ -25,13 +25,15 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.SettingsFilter; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import java.io.IOException; +import java.util.List; import java.util.Set; +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.client.Requests.getRepositoryRequest; import static org.elasticsearch.rest.RestRequest.Method.GET; @@ -42,9 +44,7 @@ public class RestGetRepositoriesAction extends BaseRestHandler { private final SettingsFilter settingsFilter; - public RestGetRepositoriesAction(RestController controller, SettingsFilter settingsFilter) { - controller.registerHandler(GET, "/_snapshot", this); - controller.registerHandler(GET, "/_snapshot/{repository}", this); + public RestGetRepositoriesAction(SettingsFilter settingsFilter) { this.settingsFilter = settingsFilter; } @@ -53,6 +53,13 @@ public String getName() { return "get_repositories_action"; } + @Override + public List routes() { + return unmodifiableList(asList( + new Route(GET, "/_snapshot"), + new Route(GET, "/_snapshot/{repository}"))); + } + @Override public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException { final String[] repositories = request.paramAsStringArray("repository", Strings.EMPTY_ARRAY); diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestGetScriptContextAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestGetScriptContextAction.java index 9a40225b769ba..e7c0b65e3b587 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestGetScriptContextAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestGetScriptContextAction.java @@ -22,20 +22,21 @@ import org.elasticsearch.action.admin.cluster.storedscripts.GetScriptContextAction; import org.elasticsearch.action.admin.cluster.storedscripts.GetScriptContextRequest; import org.elasticsearch.client.node.NodeClient; -import org.elasticsearch.common.inject.Inject; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import java.io.IOException; +import java.util.List; +import static java.util.Collections.singletonList; import static org.elasticsearch.rest.RestRequest.Method.GET; public class RestGetScriptContextAction extends BaseRestHandler { - @Inject - public RestGetScriptContextAction(RestController controller) { - controller.registerHandler(GET, "/_script_context", this); + + @Override + public List routes() { + return singletonList(new Route(GET, "/_script_context")); } @Override public String getName() { diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestGetScriptLanguageAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestGetScriptLanguageAction.java index c9246b910cf4f..d40bbeb0b8df7 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestGetScriptLanguageAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestGetScriptLanguageAction.java @@ -22,20 +22,21 @@ import org.elasticsearch.action.admin.cluster.storedscripts.GetScriptLanguageAction; import org.elasticsearch.action.admin.cluster.storedscripts.GetScriptLanguageRequest; import org.elasticsearch.client.node.NodeClient; -import org.elasticsearch.common.inject.Inject; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import java.io.IOException; +import java.util.List; +import static java.util.Collections.singletonList; import static org.elasticsearch.rest.RestRequest.Method.GET; public class RestGetScriptLanguageAction extends BaseRestHandler { - @Inject - public RestGetScriptLanguageAction(RestController controller) { - controller.registerHandler(GET, "/_script_language", this); + + @Override + public List routes() { + return singletonList(new Route(GET, "/_script_language")); } @Override public String getName() { diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestGetSnapshotsAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestGetSnapshotsAction.java index b873bce0238ba..2e4e8829adc72 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestGetSnapshotsAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestGetSnapshotsAction.java @@ -23,12 +23,13 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.Strings; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import java.io.IOException; +import java.util.List; +import static java.util.Collections.singletonList; import static org.elasticsearch.client.Requests.getSnapshotsRequest; import static org.elasticsearch.rest.RestRequest.Method.GET; @@ -37,8 +38,9 @@ */ public class RestGetSnapshotsAction extends BaseRestHandler { - public RestGetSnapshotsAction(RestController controller) { - controller.registerHandler(GET, "/_snapshot/{repository}/{snapshot}", this); + @Override + public List routes() { + return singletonList(new Route(GET, "/_snapshot/{repository}/{snapshot}")); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestGetStoredScriptAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestGetStoredScriptAction.java index f87c6f513b79c..48407c7b5d534 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestGetStoredScriptAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestGetStoredScriptAction.java @@ -21,18 +21,20 @@ import org.elasticsearch.action.admin.cluster.storedscripts.GetStoredScriptRequest; import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestStatusToXContentListener; import java.io.IOException; +import java.util.List; +import static java.util.Collections.singletonList; import static org.elasticsearch.rest.RestRequest.Method.GET; public class RestGetStoredScriptAction extends BaseRestHandler { - public RestGetStoredScriptAction(RestController controller) { - controller.registerHandler(GET, "/_scripts/{id}", this); + @Override + public List routes() { + return singletonList(new Route(GET, "/_scripts/{id}")); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestGetTaskAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestGetTaskAction.java index f0ca02f43bc35..6eded15a253bf 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestGetTaskAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestGetTaskAction.java @@ -23,19 +23,21 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.tasks.TaskId; import java.io.IOException; +import java.util.List; +import static java.util.Collections.singletonList; import static org.elasticsearch.rest.RestRequest.Method.GET; public class RestGetTaskAction extends BaseRestHandler { - public RestGetTaskAction(RestController controller) { - controller.registerHandler(GET, "/_tasks/{task_id}", this); + @Override + public List routes() { + return singletonList(new Route(GET, "/_tasks/{task_id}")); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestListTasksAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestListTasksAction.java index 4627b853ac714..b6c9fad9fdef2 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestListTasksAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestListTasksAction.java @@ -30,7 +30,6 @@ import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.BytesRestResponse; import org.elasticsearch.rest.RestChannel; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; @@ -39,8 +38,10 @@ import org.elasticsearch.tasks.TaskId; import java.io.IOException; +import java.util.List; import java.util.function.Supplier; +import static java.util.Collections.singletonList; import static org.elasticsearch.rest.RestRequest.Method.GET; @@ -48,9 +49,13 @@ public class RestListTasksAction extends BaseRestHandler { private final Supplier nodesInCluster; - public RestListTasksAction(RestController controller, Supplier nodesInCluster) { + public RestListTasksAction(Supplier nodesInCluster) { this.nodesInCluster = nodesInCluster; - controller.registerHandler(GET, "/_tasks", this); + } + + @Override + public List routes() { + return singletonList(new Route(GET, "/_tasks")); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestNodesHotThreadsAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestNodesHotThreadsAction.java index 07b85266d9d8c..5aeefa934d02e 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestNodesHotThreadsAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestNodesHotThreadsAction.java @@ -27,27 +27,32 @@ import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; import org.elasticsearch.rest.action.RestResponseListener; import java.io.IOException; +import java.util.List; +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; +import static org.elasticsearch.rest.RestRequest.Method.GET; -public class RestNodesHotThreadsAction extends BaseRestHandler { - public RestNodesHotThreadsAction(RestController controller) { - controller.registerHandler(RestRequest.Method.GET, "/_cluster/nodes/hotthreads", this); - controller.registerHandler(RestRequest.Method.GET, "/_cluster/nodes/hot_threads", this); - controller.registerHandler(RestRequest.Method.GET, "/_cluster/nodes/{nodeId}/hotthreads", this); - controller.registerHandler(RestRequest.Method.GET, "/_cluster/nodes/{nodeId}/hot_threads", this); +public class RestNodesHotThreadsAction extends BaseRestHandler { - controller.registerHandler(RestRequest.Method.GET, "/_nodes/hotthreads", this); - controller.registerHandler(RestRequest.Method.GET, "/_nodes/hot_threads", this); - controller.registerHandler(RestRequest.Method.GET, "/_nodes/{nodeId}/hotthreads", this); - controller.registerHandler(RestRequest.Method.GET, "/_nodes/{nodeId}/hot_threads", this); + @Override + public List routes() { + return unmodifiableList(asList( + new Route(GET, "/_cluster/nodes/hotthreads"), + new Route(GET, "/_cluster/nodes/hot_threads"), + new Route(GET, "/_cluster/nodes/{nodeId}/hotthreads"), + new Route(GET, "/_cluster/nodes/{nodeId}/hot_threads"), + new Route(GET, "/_nodes/hotthreads"), + new Route(GET, "/_nodes/hot_threads"), + new Route(GET, "/_nodes/{nodeId}/hotthreads"), + new Route(GET, "/_nodes/{nodeId}/hot_threads"))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestNodesInfoAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestNodesInfoAction.java index ab39c4408f212..4b42516ef06b9 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestNodesInfoAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestNodesInfoAction.java @@ -26,13 +26,15 @@ import org.elasticsearch.common.settings.SettingsFilter; import org.elasticsearch.common.util.set.Sets; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestActions.NodesResponseRestListener; import java.io.IOException; +import java.util.List; import java.util.Set; +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.rest.RestRequest.Method.GET; public class RestNodesInfoAction extends BaseRestHandler { @@ -50,17 +52,21 @@ public class RestNodesInfoAction extends BaseRestHandler { private final SettingsFilter settingsFilter; - public RestNodesInfoAction(RestController controller, SettingsFilter settingsFilter) { - controller.registerHandler(GET, "/_nodes", this); - // this endpoint is used for metrics, not for node IDs, like /_nodes/fs - controller.registerHandler(GET, "/_nodes/{nodeId}", this); - controller.registerHandler(GET, "/_nodes/{nodeId}/{metrics}", this); - // added this endpoint to be aligned with stats - controller.registerHandler(GET, "/_nodes/{nodeId}/info/{metrics}", this); - + public RestNodesInfoAction(SettingsFilter settingsFilter) { this.settingsFilter = settingsFilter; } + @Override + public List routes() { + return unmodifiableList(asList( + new Route(GET, "/_nodes"), + // this endpoint is used for metrics, not for node IDs, like /_nodes/fs + new Route(GET, "/_nodes/{nodeId}"), + new Route(GET, "/_nodes/{nodeId}/{metrics}"), + // added this endpoint to be aligned with stats + new Route(GET, "/_nodes/{nodeId}/info/{metrics}"))); + } + @Override public String getName() { return "nodes_info_action"; diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestNodesStatsAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestNodesStatsAction.java index f3ef2a55d259d..73a3e735eadad 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestNodesStatsAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestNodesStatsAction.java @@ -25,33 +25,34 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.Strings; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestActions.NodesResponseRestListener; import java.io.IOException; import java.util.Collections; import java.util.HashMap; +import java.util.List; import java.util.Locale; import java.util.Map; import java.util.Set; import java.util.TreeSet; import java.util.function.Consumer; +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.rest.RestRequest.Method.GET; public class RestNodesStatsAction extends BaseRestHandler { - public RestNodesStatsAction(RestController controller) { - controller.registerHandler(GET, "/_nodes/stats", this); - controller.registerHandler(GET, "/_nodes/{nodeId}/stats", this); - - controller.registerHandler(GET, "/_nodes/stats/{metric}", this); - controller.registerHandler(GET, "/_nodes/{nodeId}/stats/{metric}", this); - - controller.registerHandler(GET, "/_nodes/stats/{metric}/{index_metric}", this); - - controller.registerHandler(GET, "/_nodes/{nodeId}/stats/{metric}/{index_metric}", this); + @Override + public List routes() { + return unmodifiableList(asList( + new Route(GET, "/_nodes/stats"), + new Route(GET, "/_nodes/{nodeId}/stats"), + new Route(GET, "/_nodes/stats/{metric}"), + new Route(GET, "/_nodes/{nodeId}/stats/{metric}"), + new Route(GET, "/_nodes/stats/{metric}/{index_metric}"), + new Route(GET, "/_nodes/{nodeId}/stats/{metric}/{index_metric}"))); } static final Map> METRICS; diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestNodesUsageAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestNodesUsageAction.java index f1a3b15d8b654..0e8b6370f9a12 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestNodesUsageAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestNodesUsageAction.java @@ -23,11 +23,9 @@ import org.elasticsearch.action.admin.cluster.node.usage.NodesUsageResponse; import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.Strings; -import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; @@ -35,20 +33,23 @@ import org.elasticsearch.rest.action.RestBuilderListener; import java.io.IOException; +import java.util.List; import java.util.Locale; import java.util.Set; +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.rest.RestRequest.Method.GET; public class RestNodesUsageAction extends BaseRestHandler { - @Inject - public RestNodesUsageAction(RestController controller) { - controller.registerHandler(GET, "/_nodes/usage", this); - controller.registerHandler(GET, "/_nodes/{nodeId}/usage", this); - - controller.registerHandler(GET, "/_nodes/usage/{metric}", this); - controller.registerHandler(GET, "/_nodes/{nodeId}/usage/{metric}", this); + @Override + public List routes() { + return unmodifiableList(asList( + new Route(GET, "/_nodes/usage"), + new Route(GET, "/_nodes/{nodeId}/usage"), + new Route(GET, "/_nodes/usage/{metric}"), + new Route(GET, "/_nodes/{nodeId}/usage/{metric}"))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestPendingClusterTasksAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestPendingClusterTasksAction.java index dbf03e35130c6..05265f77f85a9 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestPendingClusterTasksAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestPendingClusterTasksAction.java @@ -22,16 +22,20 @@ import org.elasticsearch.action.admin.cluster.tasks.PendingClusterTasksRequest; import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import java.io.IOException; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.GET; public class RestPendingClusterTasksAction extends BaseRestHandler { - public RestPendingClusterTasksAction(RestController controller) { - controller.registerHandler(RestRequest.Method.GET, "/_cluster/pending_tasks", this); + @Override + public List routes() { + return singletonList(new Route(GET, "/_cluster/pending_tasks")); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestPutRepositoryAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestPutRepositoryAction.java index 150296d65aea9..f76d97e0296bb 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestPutRepositoryAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestPutRepositoryAction.java @@ -23,12 +23,14 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import java.io.IOException; +import java.util.List; +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.client.Requests.putRepositoryRequest; import static org.elasticsearch.rest.RestRequest.Method.POST; import static org.elasticsearch.rest.RestRequest.Method.PUT; @@ -38,9 +40,11 @@ */ public class RestPutRepositoryAction extends BaseRestHandler { - public RestPutRepositoryAction(RestController controller) { - controller.registerHandler(PUT, "/_snapshot/{repository}", this); - controller.registerHandler(POST, "/_snapshot/{repository}", this); + @Override + public List routes() { + return unmodifiableList(asList( + new Route(POST, "/_snapshot/{repository}"), + new Route(PUT, "/_snapshot/{repository}"))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestPutStoredScriptAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestPutStoredScriptAction.java index 2e316abc14296..499fd1b91f290 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestPutStoredScriptAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestPutStoredScriptAction.java @@ -23,23 +23,27 @@ import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.script.StoredScriptSource; import java.io.IOException; +import java.util.List; +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.rest.RestRequest.Method.POST; import static org.elasticsearch.rest.RestRequest.Method.PUT; public class RestPutStoredScriptAction extends BaseRestHandler { - public RestPutStoredScriptAction(RestController controller) { - controller.registerHandler(POST, "/_scripts/{id}", this); - controller.registerHandler(PUT, "/_scripts/{id}", this); - controller.registerHandler(POST, "/_scripts/{id}/{context}", this); - controller.registerHandler(PUT, "/_scripts/{id}/{context}", this); + @Override + public List routes() { + return unmodifiableList(asList( + new Route(POST, "/_scripts/{id}"), + new Route(PUT, "/_scripts/{id}"), + new Route(POST, "/_scripts/{id}/{context}"), + new Route(PUT, "/_scripts/{id}/{context}"))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestReloadSecureSettingsAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestReloadSecureSettingsAction.java index e5f85c569ee6b..209e0ef7d3357 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestReloadSecureSettingsAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestReloadSecureSettingsAction.java @@ -30,7 +30,6 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; @@ -38,7 +37,10 @@ import org.elasticsearch.rest.action.RestBuilderListener; import java.io.IOException; +import java.util.List; +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.rest.RestRequest.Method.POST; public final class RestReloadSecureSettingsAction extends BaseRestHandler { @@ -51,16 +53,18 @@ public final class RestReloadSecureSettingsAction extends BaseRestHandler { new ParseField("secure_settings_password")); } - public RestReloadSecureSettingsAction(RestController controller) { - controller.registerHandler(POST, "/_nodes/reload_secure_settings", this); - controller.registerHandler(POST, "/_nodes/{nodeId}/reload_secure_settings", this); - } - @Override public String getName() { return "nodes_reload_action"; } + @Override + public List routes() { + return unmodifiableList(asList( + new Route(POST, "/_nodes/reload_secure_settings"), + new Route(POST, "/_nodes/{nodeId}/reload_secure_settings"))); + } + @Override public RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException { final String[] nodesIds = Strings.splitStringByCommaToArray(request.param("nodeId")); diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestRemoteClusterInfoAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestRemoteClusterInfoAction.java index a49f6d1319ba2..e12d930c5bf28 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestRemoteClusterInfoAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestRemoteClusterInfoAction.java @@ -23,16 +23,19 @@ import org.elasticsearch.action.admin.cluster.remote.RemoteInfoRequest; import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; +import java.util.List; + +import static java.util.Collections.singletonList; import static org.elasticsearch.rest.RestRequest.Method.GET; public final class RestRemoteClusterInfoAction extends BaseRestHandler { - public RestRemoteClusterInfoAction(RestController controller) { - controller.registerHandler(GET, "_remote/info", this); + @Override + public List routes() { + return singletonList(new Route(GET, "_remote/info")); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestRestoreSnapshotAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestRestoreSnapshotAction.java index fb47e928ab87e..d94c2e0285cd7 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestRestoreSnapshotAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestRestoreSnapshotAction.java @@ -22,12 +22,13 @@ import org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotRequest; import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import java.io.IOException; +import java.util.List; +import static java.util.Collections.singletonList; import static org.elasticsearch.client.Requests.restoreSnapshotRequest; import static org.elasticsearch.rest.RestRequest.Method.POST; @@ -36,8 +37,9 @@ */ public class RestRestoreSnapshotAction extends BaseRestHandler { - public RestRestoreSnapshotAction(RestController controller) { - controller.registerHandler(POST, "/_snapshot/{repository}/{snapshot}/_restore", this); + @Override + public List routes() { + return singletonList(new Route(POST, "/_snapshot/{repository}/{snapshot}/_restore")); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestSnapshotsStatusAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestSnapshotsStatusAction.java index f8347d38cd576..19328f2eff2c0 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestSnapshotsStatusAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestSnapshotsStatusAction.java @@ -23,12 +23,14 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.Strings; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import java.io.IOException; +import java.util.List; +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.client.Requests.snapshotsStatusRequest; import static org.elasticsearch.rest.RestRequest.Method.GET; @@ -37,10 +39,12 @@ */ public class RestSnapshotsStatusAction extends BaseRestHandler { - public RestSnapshotsStatusAction(RestController controller) { - controller.registerHandler(GET, "/_snapshot/{repository}/{snapshot}/_status", this); - controller.registerHandler(GET, "/_snapshot/{repository}/_status", this); - controller.registerHandler(GET, "/_snapshot/_status", this); + @Override + public List routes() { + return unmodifiableList(asList( + new Route(GET, "/_snapshot/{repository}/{snapshot}/_status"), + new Route(GET, "/_snapshot/{repository}/_status"), + new Route(GET, "/_snapshot/_status"))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestVerifyRepositoryAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestVerifyRepositoryAction.java index be69e73275c81..ad796897c8a87 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestVerifyRepositoryAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestVerifyRepositoryAction.java @@ -22,19 +22,21 @@ import org.elasticsearch.action.admin.cluster.repositories.verify.VerifyRepositoryRequest; import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import java.io.IOException; +import java.util.List; +import static java.util.Collections.singletonList; import static org.elasticsearch.client.Requests.verifyRepositoryRequest; import static org.elasticsearch.rest.RestRequest.Method.POST; public class RestVerifyRepositoryAction extends BaseRestHandler { - public RestVerifyRepositoryAction(RestController controller) { - controller.registerHandler(POST, "/_snapshot/{repository}/_verify", this); + @Override + public List routes() { + return singletonList(new Route(POST, "/_snapshot/{repository}/_verify")); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestAnalyzeAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestAnalyzeAction.java index af9bfbfe595dd..15d34a91d9d17 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestAnalyzeAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestAnalyzeAction.java @@ -23,12 +23,14 @@ import org.elasticsearch.common.ParseField; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import java.io.IOException; +import java.util.List; +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.rest.RestRequest.Method.GET; import static org.elasticsearch.rest.RestRequest.Method.POST; @@ -46,11 +48,13 @@ public static class Fields { public static final ParseField NORMALIZER = new ParseField("normalizer"); } - public RestAnalyzeAction(RestController controller) { - controller.registerHandler(GET, "/_analyze", this); - controller.registerHandler(GET, "/{index}/_analyze", this); - controller.registerHandler(POST, "/_analyze", this); - controller.registerHandler(POST, "/{index}/_analyze", this); + @Override + public List routes() { + return unmodifiableList(asList( + new Route(GET, "/_analyze"), + new Route(POST, "/_analyze"), + new Route(GET, "/{index}/_analyze"), + new Route(POST, "/{index}/_analyze"))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestClearIndicesCacheAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestClearIndicesCacheAction.java index bc2fed911b3ac..fd6979c92e29c 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestClearIndicesCacheAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestClearIndicesCacheAction.java @@ -24,19 +24,23 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.Strings; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import java.io.IOException; +import java.util.List; +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.rest.RestRequest.Method.POST; public class RestClearIndicesCacheAction extends BaseRestHandler { - public RestClearIndicesCacheAction(RestController controller) { - controller.registerHandler(POST, "/_cache/clear", this); - controller.registerHandler(POST, "/{index}/_cache/clear", this); + @Override + public List routes() { + return unmodifiableList(asList( + new Route(POST, "/_cache/clear"), + new Route(POST, "/{index}/_cache/clear"))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestCloseIndexAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestCloseIndexAction.java index 3f26b1978372d..5d3a186b8cb4b 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestCloseIndexAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestCloseIndexAction.java @@ -25,17 +25,23 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.Strings; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import java.io.IOException; +import java.util.List; + +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; +import static org.elasticsearch.rest.RestRequest.Method.POST; public class RestCloseIndexAction extends BaseRestHandler { - public RestCloseIndexAction(RestController controller) { - controller.registerHandler(RestRequest.Method.POST, "/_close", this); - controller.registerHandler(RestRequest.Method.POST, "/{index}/_close", this); + @Override + public List routes() { + return unmodifiableList(asList( + new Route(POST, "/_close"), + new Route(POST, "/{index}/_close"))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestCreateIndexAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestCreateIndexAction.java index 4b5ca382e08a9..b7ca1ae35d462 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestCreateIndexAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestCreateIndexAction.java @@ -28,23 +28,27 @@ import org.elasticsearch.common.xcontent.XContentHelper; import org.elasticsearch.index.mapper.MapperService; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import java.io.IOException; -import java.util.Collections; import java.util.HashMap; +import java.util.List; import java.util.Map; +import static java.util.Collections.singletonList; +import static java.util.Collections.singletonMap; +import static org.elasticsearch.rest.RestRequest.Method.PUT; + public class RestCreateIndexAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger( LogManager.getLogger(RestCreateIndexAction.class)); public static final String TYPES_DEPRECATION_MESSAGE = "[types removal] Using include_type_name in create " + "index requests is deprecated. The parameter will be removed in the next major version."; - public RestCreateIndexAction(RestController controller) { - controller.registerHandler(RestRequest.Method.PUT, "/{index}", this); + @Override + public List routes() { + return singletonList(new Route(PUT, "/{index}")); } @Override @@ -93,7 +97,7 @@ static Map prepareMappings(Map source, boolean i "[" + MapperService.SINGLE_MAPPING_NAME + "] unless include_type_name is set to true."); } - newSource.put("mappings", Collections.singletonMap(MapperService.SINGLE_MAPPING_NAME, mappings)); + newSource.put("mappings", singletonMap(MapperService.SINGLE_MAPPING_NAME, mappings)); return newSource; } } diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestDeleteIndexAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestDeleteIndexAction.java index b0d02cd19b7eb..a82370e89af82 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestDeleteIndexAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestDeleteIndexAction.java @@ -24,17 +24,23 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.Strings; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import java.io.IOException; +import java.util.List; + +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; +import static org.elasticsearch.rest.RestRequest.Method.DELETE; public class RestDeleteIndexAction extends BaseRestHandler { - public RestDeleteIndexAction(RestController controller) { - controller.registerHandler(RestRequest.Method.DELETE, "/", this); - controller.registerHandler(RestRequest.Method.DELETE, "/{index}", this); + @Override + public List routes() { + return unmodifiableList(asList( + new Route(DELETE, "/"), + new Route(DELETE, "/{index}"))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestDeleteIndexTemplateAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestDeleteIndexTemplateAction.java index c0679bb356249..a92bee023452a 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestDeleteIndexTemplateAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestDeleteIndexTemplateAction.java @@ -21,16 +21,20 @@ import org.elasticsearch.action.admin.indices.template.delete.DeleteIndexTemplateRequest; import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import java.io.IOException; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.DELETE; public class RestDeleteIndexTemplateAction extends BaseRestHandler { - public RestDeleteIndexTemplateAction(RestController controller) { - controller.registerHandler(RestRequest.Method.DELETE, "/_template/{name}", this); + @Override + public List routes() { + return singletonList(new Route(DELETE, "/_template/{name}")); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestFlushAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestFlushAction.java index f9d614e9b9912..d22dcb91d1a94 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestFlushAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestFlushAction.java @@ -24,23 +24,26 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.Strings; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import java.io.IOException; +import java.util.List; +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.rest.RestRequest.Method.GET; import static org.elasticsearch.rest.RestRequest.Method.POST; public class RestFlushAction extends BaseRestHandler { - public RestFlushAction(RestController controller) { - controller.registerHandler(POST, "/_flush", this); - controller.registerHandler(POST, "/{index}/_flush", this); - - controller.registerHandler(GET, "/_flush", this); - controller.registerHandler(GET, "/{index}/_flush", this); + @Override + public List routes() { + return unmodifiableList(asList( + new Route(GET, "/_flush"), + new Route(POST, "/_flush"), + new Route(GET, "/{index}/_flush"), + new Route(POST, "/{index}/_flush"))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestForceMergeAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestForceMergeAction.java index e2876e7cf0214..4bda5ce12e521 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestForceMergeAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestForceMergeAction.java @@ -26,21 +26,25 @@ import org.elasticsearch.common.Strings; import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import java.io.IOException; +import java.util.List; +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.rest.RestRequest.Method.POST; public class RestForceMergeAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestForceMergeAction.class)); - public RestForceMergeAction(final RestController controller) { - controller.registerHandler(POST, "/_forcemerge", this); - controller.registerHandler(POST, "/{index}/_forcemerge", this); + @Override + public List routes() { + return unmodifiableList(asList( + new Route(POST, "/_forcemerge"), + new Route(POST, "/{index}/_forcemerge"))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestGetAliasesAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestGetAliasesAction.java index 3379ab009573f..f05554322aa7c 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestGetAliasesAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestGetAliasesAction.java @@ -33,7 +33,6 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; @@ -47,6 +46,8 @@ import java.util.SortedSet; import java.util.TreeSet; +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.rest.RestRequest.Method.GET; import static org.elasticsearch.rest.RestRequest.Method.HEAD; @@ -55,15 +56,17 @@ */ public class RestGetAliasesAction extends BaseRestHandler { - public RestGetAliasesAction(final RestController controller) { - controller.registerHandler(GET, "/_alias", this); - controller.registerHandler(GET, "/_aliases", this); - controller.registerHandler(GET, "/_alias/{name}", this); - controller.registerHandler(HEAD, "/_alias/{name}", this); - controller.registerHandler(GET, "/{index}/_alias", this); - controller.registerHandler(HEAD, "/{index}/_alias", this); - controller.registerHandler(GET, "/{index}/_alias/{name}", this); - controller.registerHandler(HEAD, "/{index}/_alias/{name}", this); + @Override + public List routes() { + return unmodifiableList(asList( + new Route(GET, "/_alias"), + new Route(GET, "/_aliases"), + new Route(GET, "/_alias/{name}"), + new Route(HEAD, "/_alias/{name}"), + new Route(GET, "/{index}/_alias"), + new Route(HEAD, "/{index}/_alias"), + new Route(GET, "/{index}/_alias/{name}"), + new Route(HEAD, "/{index}/_alias/{name}"))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestGetFieldMappingAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestGetFieldMappingAction.java index 27d8c2f8a8c01..0edd3a741da51 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestGetFieldMappingAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestGetFieldMappingAction.java @@ -30,15 +30,17 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; import org.elasticsearch.rest.action.RestBuilderListener; import java.io.IOException; +import java.util.List; import java.util.Map; +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.rest.RestRequest.Method.GET; import static org.elasticsearch.rest.RestStatus.NOT_FOUND; import static org.elasticsearch.rest.RestStatus.OK; @@ -50,12 +52,14 @@ public class RestGetFieldMappingAction extends BaseRestHandler { public static final String TYPES_DEPRECATION_MESSAGE = "[types removal] Using include_type_name in get " + "field mapping requests is deprecated. The parameter will be removed in the next major version."; - public RestGetFieldMappingAction(RestController controller) { - controller.registerHandler(GET, "/_mapping/field/{fields}", this); - controller.registerHandler(GET, "/_mapping/{type}/field/{fields}", this); - controller.registerHandler(GET, "/{index}/_mapping/field/{fields}", this); - controller.registerHandler(GET, "/{index}/{type}/_mapping/field/{fields}", this); - controller.registerHandler(GET, "/{index}/_mapping/{type}/field/{fields}", this); + @Override + public List routes() { + return unmodifiableList(asList( + new Route(GET, "/_mapping/field/{fields}"), + new Route(GET, "/_mapping/{type}/field/{fields}"), + new Route(GET, "/{index}/_mapping/field/{fields}"), + new Route(GET, "/{index}/{type}/_mapping/field/{fields}"), + new Route(GET, "/{index}/_mapping/{type}/field/{fields}"))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestGetIndexTemplateAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestGetIndexTemplateAction.java index 3a66d7a0129d8..1f6cbe104f9d2 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestGetIndexTemplateAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestGetIndexTemplateAction.java @@ -28,15 +28,17 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.util.set.Sets; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestStatus; import org.elasticsearch.rest.action.RestToXContentListener; import java.io.IOException; import java.util.Collections; +import java.util.List; import java.util.Set; +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.rest.RestRequest.Method.GET; import static org.elasticsearch.rest.RestRequest.Method.HEAD; import static org.elasticsearch.rest.RestStatus.NOT_FOUND; @@ -54,10 +56,12 @@ public class RestGetIndexTemplateAction extends BaseRestHandler { public static final String TYPES_DEPRECATION_MESSAGE = "[types removal]" + " Specifying include_type_name in get index template requests is deprecated."; - public RestGetIndexTemplateAction(final RestController controller) { - controller.registerHandler(GET, "/_template", this); - controller.registerHandler(GET, "/_template/{name}", this); - controller.registerHandler(HEAD, "/_template/{name}", this); + @Override + public List routes() { + return unmodifiableList(asList( + new Route(GET, "/_template"), + new Route(GET, "/_template/{name}"), + new Route(HEAD, "/_template/{name}"))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestGetIndicesAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestGetIndicesAction.java index 64754260ebf0a..40a5c05678e26 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestGetIndicesAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestGetIndicesAction.java @@ -28,16 +28,18 @@ import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import java.io.IOException; import java.util.Collections; +import java.util.List; import java.util.Set; import java.util.stream.Collectors; import java.util.stream.Stream; +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.rest.RestRequest.Method.GET; import static org.elasticsearch.rest.RestRequest.Method.HEAD; @@ -54,9 +56,11 @@ public class RestGetIndicesAction extends BaseRestHandler { .unmodifiableSet(Stream.concat(Collections.singleton(INCLUDE_TYPE_NAME_PARAMETER).stream(), Settings.FORMAT_PARAMS.stream()) .collect(Collectors.toSet())); - public RestGetIndicesAction(final RestController controller) { - controller.registerHandler(GET, "/{index}", this); - controller.registerHandler(HEAD, "/{index}", this); + @Override + public List routes() { + return unmodifiableList(asList( + new Route(GET, "/{index}"), + new Route(HEAD, "/{index}"))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestGetMappingAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestGetMappingAction.java index 051a1199e74cd..bd432cc55e11a 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestGetMappingAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestGetMappingAction.java @@ -37,7 +37,6 @@ import org.elasticsearch.indices.TypeMissingException; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; @@ -53,6 +52,8 @@ import java.util.SortedSet; import java.util.stream.Collectors; +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.rest.RestRequest.Method.GET; import static org.elasticsearch.rest.RestRequest.Method.HEAD; @@ -62,16 +63,18 @@ public class RestGetMappingAction extends BaseRestHandler { public static final String TYPES_DEPRECATION_MESSAGE = "[types removal] Using include_type_name in get" + " mapping requests is deprecated. The parameter will be removed in the next major version."; - public RestGetMappingAction(final RestController controller) { - controller.registerHandler(GET, "/_mapping", this); - controller.registerHandler(GET, "/_mappings", this); - controller.registerHandler(GET, "/{index}/{type}/_mapping", this); - controller.registerHandler(GET, "/{index}/_mappings", this); - controller.registerHandler(GET, "/{index}/_mapping", this); - controller.registerHandler(GET, "/{index}/_mappings/{type}", this); - controller.registerHandler(GET, "/{index}/_mapping/{type}", this); - controller.registerHandler(HEAD, "/{index}/_mapping/{type}", this); - controller.registerHandler(GET, "/_mapping/{type}", this); + @Override + public List routes() { + return unmodifiableList(asList( + new Route(GET, "/_mapping"), + new Route(GET, "/_mappings"), + new Route(GET, "/{index}/{type}/_mapping"), + new Route(GET, "/{index}/_mapping"), + new Route(GET, "/{index}/_mappings"), + new Route(GET, "/{index}/_mappings/{type}"), + new Route(GET, "/{index}/_mapping/{type}"), + new Route(HEAD, "/{index}/_mapping/{type}"), + new Route(GET, "/_mapping/{type}"))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestGetSettingsAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestGetSettingsAction.java index c7b9cc485d3ce..20058c812b94e 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestGetSettingsAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestGetSettingsAction.java @@ -24,22 +24,26 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.Strings; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import java.io.IOException; +import java.util.List; +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.rest.RestRequest.Method.GET; public class RestGetSettingsAction extends BaseRestHandler { - public RestGetSettingsAction(RestController controller) { - controller.registerHandler(GET, "/_settings", this); - controller.registerHandler(GET, "/_settings/{name}", this); - controller.registerHandler(GET, "/{index}/_settings", this); - controller.registerHandler(GET, "/{index}/_settings/{name}", this); - controller.registerHandler(GET, "/{index}/_setting/{name}", this); + @Override + public List routes() { + return unmodifiableList(asList( + new Route(GET, "/_settings"), + new Route(GET, "/_settings/{name}"), + new Route(GET, "/{index}/_settings"), + new Route(GET, "/{index}/_settings/{name}"), + new Route(GET, "/{index}/_setting/{name}"))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestIndexDeleteAliasesAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestIndexDeleteAliasesAction.java index 91442bb2fb9e1..ff454ee5354cd 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestIndexDeleteAliasesAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestIndexDeleteAliasesAction.java @@ -23,19 +23,23 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.Strings; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import java.io.IOException; +import java.util.List; +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.rest.RestRequest.Method.DELETE; public class RestIndexDeleteAliasesAction extends BaseRestHandler { - public RestIndexDeleteAliasesAction(RestController controller) { - controller.registerHandler(DELETE, "/{index}/_alias/{name}", this); - controller.registerHandler(DELETE, "/{index}/_aliases/{name}", this); + @Override + public List routes() { + return unmodifiableList(asList( + new Route(DELETE, "/{index}/_alias/{name}"), + new Route(DELETE, "/{index}/_aliases/{name}"))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestIndexPutAliasAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestIndexPutAliasAction.java index 3c51c9111f2ae..fb6bede4e0ae3 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestIndexPutAliasAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestIndexPutAliasAction.java @@ -24,32 +24,34 @@ import org.elasticsearch.common.Strings; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import java.io.IOException; +import java.util.List; import java.util.Map; +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.rest.RestRequest.Method.POST; import static org.elasticsearch.rest.RestRequest.Method.PUT; public class RestIndexPutAliasAction extends BaseRestHandler { - public RestIndexPutAliasAction(RestController controller) { - controller.registerHandler(PUT, "/{index}/_alias/{name}", this); - controller.registerHandler(PUT, "/_alias/{name}", this); - controller.registerHandler(PUT, "/{index}/_aliases/{name}", this); - controller.registerHandler(PUT, "/_aliases/{name}", this); - controller.registerHandler(PUT, "/{index}/_alias", this); - controller.registerHandler(PUT, "/_alias", this); - - controller.registerHandler(POST, "/{index}/_alias/{name}", this); - controller.registerHandler(POST, "/_alias/{name}", this); - controller.registerHandler(POST, "/{index}/_aliases/{name}", this); - controller.registerHandler(POST, "/_aliases/{name}", this); - controller.registerHandler(PUT, "/{index}/_aliases", this); - //we cannot add POST for "/_aliases" because this is the _aliases api already defined in RestIndicesAliasesAction + @Override + public List routes() { + return unmodifiableList(asList( + new Route(POST, "/{index}/_alias/{name}"), + new Route(PUT, "/{index}/_alias/{name}"), + new Route(POST, "/_alias/{name}"), + new Route(PUT, "/_alias/{name}"), + new Route(POST, "/{index}/_aliases/{name}"), + new Route(PUT, "/{index}/_aliases/{name}"), + new Route(POST, "/_aliases/{name}"), + new Route(PUT, "/_aliases/{name}"), + new Route(PUT, "/{index}/_alias"), + new Route(PUT, "/{index}/_aliases"), + new Route(PUT, "/_alias"))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestIndicesAliasesAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestIndicesAliasesAction.java index d305c5ad3ca46..e492857747955 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestIndicesAliasesAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestIndicesAliasesAction.java @@ -23,12 +23,13 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import java.io.IOException; +import java.util.List; +import static java.util.Collections.singletonList; import static org.elasticsearch.rest.RestRequest.Method.POST; public class RestIndicesAliasesAction extends BaseRestHandler { @@ -38,8 +39,9 @@ public String getName() { return "indices_aliases_action"; } - public RestIndicesAliasesAction(RestController controller) { - controller.registerHandler(POST, "/_aliases", this); + @Override + public List routes() { + return singletonList(new Route(POST, "/_aliases")); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestIndicesSegmentsAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestIndicesSegmentsAction.java index ed76c36dac34c..e14a83bd3084c 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestIndicesSegmentsAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestIndicesSegmentsAction.java @@ -24,19 +24,23 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.Strings; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import java.io.IOException; +import java.util.List; +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.rest.RestRequest.Method.GET; public class RestIndicesSegmentsAction extends BaseRestHandler { - public RestIndicesSegmentsAction(RestController controller) { - controller.registerHandler(GET, "/_segments", this); - controller.registerHandler(GET, "/{index}/_segments", this); + @Override + public List routes() { + return unmodifiableList(asList( + new Route(GET, "/_segments"), + new Route(GET, "/{index}/_segments"))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestIndicesShardStoresAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestIndicesShardStoresAction.java index e214e7bbb3411..39ff18cade947 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestIndicesShardStoresAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestIndicesShardStoresAction.java @@ -28,13 +28,15 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.action.RestBuilderListener; import java.io.IOException; +import java.util.List; +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.rest.RestRequest.Method.GET; import static org.elasticsearch.rest.RestStatus.OK; @@ -43,9 +45,11 @@ */ public class RestIndicesShardStoresAction extends BaseRestHandler { - public RestIndicesShardStoresAction(RestController controller) { - controller.registerHandler(GET, "/_shard_stores", this); - controller.registerHandler(GET, "/{index}/_shard_stores", this); + @Override + public List routes() { + return unmodifiableList(asList( + new Route(GET, "/_shard_stores"), + new Route(GET, "/{index}/_shard_stores"))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestIndicesStatsAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestIndicesStatsAction.java index 6ef806a43a5c5..57510c71fd15b 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestIndicesStatsAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestIndicesStatsAction.java @@ -26,28 +26,32 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.Strings; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import java.io.IOException; import java.util.Collections; import java.util.HashMap; +import java.util.List; import java.util.Locale; import java.util.Map; import java.util.Set; import java.util.TreeSet; import java.util.function.Consumer; +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.rest.RestRequest.Method.GET; public class RestIndicesStatsAction extends BaseRestHandler { - public RestIndicesStatsAction(RestController controller) { - controller.registerHandler(GET, "/_stats", this); - controller.registerHandler(GET, "/_stats/{metric}", this); - controller.registerHandler(GET, "/{index}/_stats", this); - controller.registerHandler(GET, "/{index}/_stats/{metric}", this); + @Override + public List routes() { + return unmodifiableList(asList( + new Route(GET, "/_stats"), + new Route(GET, "/_stats/{metric}"), + new Route(GET, "/{index}/_stats"), + new Route(GET, "/{index}/_stats/{metric}"))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestOpenIndexAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestOpenIndexAction.java index 8eb5c3a74bd73..5ffc29e26e11b 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestOpenIndexAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestOpenIndexAction.java @@ -25,17 +25,23 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.Strings; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import java.io.IOException; +import java.util.List; + +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; +import static org.elasticsearch.rest.RestRequest.Method.POST; public class RestOpenIndexAction extends BaseRestHandler { - public RestOpenIndexAction(RestController controller) { - controller.registerHandler(RestRequest.Method.POST, "/_open", this); - controller.registerHandler(RestRequest.Method.POST, "/{index}/_open", this); + @Override + public List routes() { + return unmodifiableList(asList( + new Route(POST, "/_open"), + new Route(POST, "/{index}/_open"))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestPutIndexTemplateAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestPutIndexTemplateAction.java index f539b85b5565f..36458cf7ce36d 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestPutIndexTemplateAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestPutIndexTemplateAction.java @@ -26,15 +26,20 @@ import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.common.xcontent.XContentHelper; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import java.io.IOException; import java.util.Arrays; import java.util.Collections; +import java.util.List; import java.util.Map; +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; +import static org.elasticsearch.rest.RestRequest.Method.POST; +import static org.elasticsearch.rest.RestRequest.Method.PUT; + public class RestPutIndexTemplateAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger( @@ -43,9 +48,11 @@ public class RestPutIndexTemplateAction extends BaseRestHandler { " Specifying include_type_name in put index template requests is deprecated."+ " The parameter will be removed in the next major version."; - public RestPutIndexTemplateAction(RestController controller) { - controller.registerHandler(RestRequest.Method.PUT, "/_template/{name}", this); - controller.registerHandler(RestRequest.Method.POST, "/_template/{name}", this); + @Override + public List routes() { + return unmodifiableList(asList( + new Route(POST, "/_template/{name}"), + new Route(PUT, "/_template/{name}"))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestPutMappingAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestPutMappingAction.java index 149758c60b4bc..eb722a8130729 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestPutMappingAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestPutMappingAction.java @@ -28,13 +28,15 @@ import org.elasticsearch.common.xcontent.XContentHelper; import org.elasticsearch.index.mapper.MapperService; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import java.io.IOException; +import java.util.List; import java.util.Map; +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.client.Requests.putMappingRequest; import static org.elasticsearch.index.mapper.MapperService.isMappingSourceTyped; import static org.elasticsearch.rest.RestRequest.Method.POST; @@ -46,27 +48,25 @@ public class RestPutMappingAction extends BaseRestHandler { public static final String TYPES_DEPRECATION_MESSAGE = "[types removal] Using include_type_name in put " + "mapping requests is deprecated. The parameter will be removed in the next major version."; - public RestPutMappingAction(RestController controller) { - controller.registerHandler(PUT, "/{index}/_mapping/", this); - controller.registerHandler(PUT, "/{index}/{type}/_mapping", this); - controller.registerHandler(PUT, "/{index}/_mapping/{type}", this); - controller.registerHandler(PUT, "/_mapping/{type}", this); - - controller.registerHandler(POST, "/{index}/_mapping/", this); - controller.registerHandler(POST, "/{index}/{type}/_mapping", this); - controller.registerHandler(POST, "/{index}/_mapping/{type}", this); - controller.registerHandler(POST, "/_mapping/{type}", this); - - //register the same paths, but with plural form _mappings - controller.registerHandler(PUT, "/{index}/_mappings/", this); - controller.registerHandler(PUT, "/{index}/{type}/_mappings", this); - controller.registerHandler(PUT, "/{index}/_mappings/{type}", this); - controller.registerHandler(PUT, "/_mappings/{type}", this); - - controller.registerHandler(POST, "/{index}/_mappings/", this); - controller.registerHandler(POST, "/{index}/{type}/_mappings", this); - controller.registerHandler(POST, "/{index}/_mappings/{type}", this); - controller.registerHandler(POST, "/_mappings/{type}", this); + @Override + public List routes() { + return unmodifiableList(asList( + new Route(POST, "/{index}/_mapping/"), + new Route(PUT, "/{index}/_mapping/"), + new Route(POST, "/{index}/{type}/_mapping"), + new Route(PUT, "/{index}/{type}/_mapping"), + new Route(POST, "/{index}/_mapping/{type}"), + new Route(PUT, "/{index}/_mapping/{type}"), + new Route(POST, "/_mapping/{type}"), + new Route(PUT, "/_mapping/{type}"), + new Route(POST, "/{index}/_mappings/"), + new Route(PUT, "/{index}/_mappings/"), + new Route(POST, "/{index}/{type}/_mappings"), + new Route(PUT, "/{index}/{type}/_mappings"), + new Route(POST, "/{index}/_mappings/{type}"), + new Route(PUT, "/{index}/_mappings/{type}"), + new Route(POST, "/_mappings/{type}"), + new Route(PUT, "/_mappings/{type}"))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestRecoveryAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestRecoveryAction.java index 38325a17f489d..ac8744f39c70e 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestRecoveryAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestRecoveryAction.java @@ -24,12 +24,14 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.Strings; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import java.io.IOException; +import java.util.List; +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.rest.RestRequest.Method.GET; /** @@ -37,9 +39,11 @@ */ public class RestRecoveryAction extends BaseRestHandler { - public RestRecoveryAction(RestController controller) { - controller.registerHandler(GET, "/_recovery", this); - controller.registerHandler(GET, "/{index}/_recovery", this); + @Override + public List routes() { + return unmodifiableList(asList( + new Route(GET, "/_recovery"), + new Route(GET, "/{index}/_recovery"))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestRefreshAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestRefreshAction.java index 5e89e16d068fa..cae120e50bb46 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestRefreshAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestRefreshAction.java @@ -25,24 +25,27 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.Strings; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestStatus; import org.elasticsearch.rest.action.RestToXContentListener; import java.io.IOException; +import java.util.List; +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.rest.RestRequest.Method.GET; import static org.elasticsearch.rest.RestRequest.Method.POST; public class RestRefreshAction extends BaseRestHandler { - public RestRefreshAction(RestController controller) { - controller.registerHandler(POST, "/_refresh", this); - controller.registerHandler(POST, "/{index}/_refresh", this); - - controller.registerHandler(GET, "/_refresh", this); - controller.registerHandler(GET, "/{index}/_refresh", this); + @Override + public List routes() { + return unmodifiableList(asList( + new Route(GET, "/_refresh"), + new Route(POST, "/_refresh"), + new Route(GET, "/{index}/_refresh"), + new Route(POST, "/{index}/_refresh"))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestResizeHandler.java b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestResizeHandler.java index ad7e169b007a8..7d708b440ca49 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestResizeHandler.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestResizeHandler.java @@ -29,11 +29,16 @@ import org.elasticsearch.common.Booleans; import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import java.io.IOException; +import java.util.List; + +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; +import static org.elasticsearch.rest.RestRequest.Method.POST; +import static org.elasticsearch.rest.RestRequest.Method.PUT; public abstract class RestResizeHandler extends BaseRestHandler { private static final Logger logger = LogManager.getLogger(RestResizeHandler.class); @@ -78,9 +83,11 @@ public final RestChannelConsumer prepareRequest(final RestRequest request, final public static class RestShrinkIndexAction extends RestResizeHandler { - public RestShrinkIndexAction(final RestController controller) { - controller.registerHandler(RestRequest.Method.PUT, "/{index}/_shrink/{target}", this); - controller.registerHandler(RestRequest.Method.POST, "/{index}/_shrink/{target}", this); + @Override + public List routes() { + return unmodifiableList(asList( + new Route(POST, "/{index}/_shrink/{target}"), + new Route(PUT, "/{index}/_shrink/{target}"))); } @Override @@ -97,9 +104,11 @@ protected ResizeType getResizeType() { public static class RestSplitIndexAction extends RestResizeHandler { - public RestSplitIndexAction(final RestController controller) { - controller.registerHandler(RestRequest.Method.PUT, "/{index}/_split/{target}", this); - controller.registerHandler(RestRequest.Method.POST, "/{index}/_split/{target}", this); + @Override + public List routes() { + return unmodifiableList(asList( + new Route(POST, "/{index}/_split/{target}"), + new Route(PUT, "/{index}/_split/{target}"))); } @Override @@ -116,9 +125,11 @@ protected ResizeType getResizeType() { public static class RestCloneIndexAction extends RestResizeHandler { - public RestCloneIndexAction(final RestController controller) { - controller.registerHandler(RestRequest.Method.PUT, "/{index}/_clone/{target}", this); - controller.registerHandler(RestRequest.Method.POST, "/{index}/_clone/{target}", this); + @Override + public List routes() { + return unmodifiableList(asList( + new Route(POST, "/{index}/_clone/{target}"), + new Route(PUT, "/{index}/_clone/{target}"))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestRolloverIndexAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestRolloverIndexAction.java index 13ec16b7e54e7..c09bde69eb931 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestRolloverIndexAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestRolloverIndexAction.java @@ -25,21 +25,28 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import java.io.IOException; +import java.util.List; + +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; +import static org.elasticsearch.rest.RestRequest.Method.POST; public class RestRolloverIndexAction extends BaseRestHandler { + private static final DeprecationLogger deprecationLogger = new DeprecationLogger( LogManager.getLogger(RestRolloverIndexAction.class)); public static final String TYPES_DEPRECATION_MESSAGE = "[types removal] Using include_type_name in rollover " + "index requests is deprecated. The parameter will be removed in the next major version."; - public RestRolloverIndexAction(RestController controller) { - controller.registerHandler(RestRequest.Method.POST, "/{index}/_rollover", this); - controller.registerHandler(RestRequest.Method.POST, "/{index}/_rollover/{new_index}", this); + @Override + public List routes() { + return unmodifiableList(asList( + new Route(POST, "/{index}/_rollover"), + new Route(POST, "/{index}/_rollover/{new_index}"))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestSyncedFlushAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestSyncedFlushAction.java index 53cbb5c6d10dd..f83fc294fa29f 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestSyncedFlushAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestSyncedFlushAction.java @@ -27,24 +27,27 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.action.RestBuilderListener; import java.io.IOException; +import java.util.List; +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.rest.RestRequest.Method.GET; import static org.elasticsearch.rest.RestRequest.Method.POST; public class RestSyncedFlushAction extends BaseRestHandler { - public RestSyncedFlushAction(RestController controller) { - controller.registerHandler(POST, "/_flush/synced", this); - controller.registerHandler(POST, "/{index}/_flush/synced", this); - - controller.registerHandler(GET, "/_flush/synced", this); - controller.registerHandler(GET, "/{index}/_flush/synced", this); + @Override + public List routes() { + return unmodifiableList(asList( + new Route(GET, "/_flush/synced"), + new Route(POST, "/_flush/synced"), + new Route(GET, "/{index}/_flush/synced"), + new Route(POST, "/{index}/_flush/synced"))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestUpdateSettingsAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestUpdateSettingsAction.java index e26bf9f318e5e..4db7539850567 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestUpdateSettingsAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestUpdateSettingsAction.java @@ -25,20 +25,25 @@ import org.elasticsearch.common.Strings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import java.io.IOException; +import java.util.List; import java.util.Set; +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.client.Requests.updateSettingsRequest; +import static org.elasticsearch.rest.RestRequest.Method.PUT; public class RestUpdateSettingsAction extends BaseRestHandler { - public RestUpdateSettingsAction(RestController controller) { - controller.registerHandler(RestRequest.Method.PUT, "/{index}/_settings", this); - controller.registerHandler(RestRequest.Method.PUT, "/_settings", this); + @Override + public List routes() { + return unmodifiableList(asList( + new Route(PUT, "/{index}/_settings"), + new Route(PUT, "/_settings"))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestUpgradeAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestUpgradeAction.java index 77f2d4f7b86c8..0cb353a14c1e5 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestUpgradeAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestUpgradeAction.java @@ -24,19 +24,23 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.Strings; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import java.io.IOException; +import java.util.List; +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.rest.RestRequest.Method.POST; public class RestUpgradeAction extends BaseRestHandler { - public RestUpgradeAction(RestController controller) { - controller.registerHandler(POST, "/_upgrade", this); - controller.registerHandler(POST, "/{index}/_upgrade", this); + @Override + public List routes() { + return unmodifiableList(asList( + new Route(POST, "/_upgrade"), + new Route(POST, "/{index}/_upgrade"))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestUpgradeStatusAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestUpgradeStatusAction.java index a560c19daf77f..27968797fc525 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestUpgradeStatusAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestUpgradeStatusAction.java @@ -24,19 +24,23 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.Strings; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import java.io.IOException; +import java.util.List; +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.rest.RestRequest.Method.GET; public class RestUpgradeStatusAction extends BaseRestHandler { - public RestUpgradeStatusAction(RestController controller) { - controller.registerHandler(GET, "/_upgrade", this); - controller.registerHandler(GET, "/{index}/_upgrade", this); + @Override + public List routes() { + return unmodifiableList(asList( + new Route(GET, "/_upgrade"), + new Route(GET, "/{index}/_upgrade"))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestValidateQueryAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestValidateQueryAction.java index 39e9b3fa852d0..75ed0d6a46a58 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestValidateQueryAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestValidateQueryAction.java @@ -32,13 +32,15 @@ import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.BytesRestResponse; import org.elasticsearch.rest.RestChannel; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestActions; import org.elasticsearch.rest.action.RestToXContentListener; import java.io.IOException; +import java.util.List; +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.rest.RestRequest.Method.GET; import static org.elasticsearch.rest.RestRequest.Method.POST; import static org.elasticsearch.rest.RestStatus.OK; @@ -49,13 +51,15 @@ public class RestValidateQueryAction extends BaseRestHandler { static final String TYPES_DEPRECATION_MESSAGE = "[types removal]" + " Specifying types in validate query requests is deprecated."; - public RestValidateQueryAction(RestController controller) { - controller.registerHandler(GET, "/_validate/query", this); - controller.registerHandler(POST, "/_validate/query", this); - controller.registerHandler(GET, "/{index}/_validate/query", this); - controller.registerHandler(POST, "/{index}/_validate/query", this); - controller.registerHandler(GET, "/{index}/{type}/_validate/query", this); - controller.registerHandler(POST, "/{index}/{type}/_validate/query", this); + @Override + public List routes() { + return unmodifiableList(asList( + new Route(GET, "/_validate/query"), + new Route(POST, "/_validate/query"), + new Route(GET, "/{index}/_validate/query"), + new Route(POST, "/{index}/_validate/query"), + new Route(GET, "/{index}/{type}/_validate/query"), + new Route(POST, "/{index}/{type}/_validate/query"))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/cat/RestAliasAction.java b/server/src/main/java/org/elasticsearch/rest/action/cat/RestAliasAction.java index 4fd43becf431b..cc96487fd45dc 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/cat/RestAliasAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/cat/RestAliasAction.java @@ -25,20 +25,23 @@ import org.elasticsearch.cluster.metadata.AliasMetaData; import org.elasticsearch.common.Strings; import org.elasticsearch.common.Table; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.action.RestResponseListener; import java.util.List; +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.rest.RestRequest.Method.GET; public class RestAliasAction extends AbstractCatAction { - public RestAliasAction(RestController controller) { - controller.registerHandler(GET, "/_cat/aliases", this); - controller.registerHandler(GET, "/_cat/aliases/{alias}", this); + @Override + public List routes() { + return unmodifiableList(asList( + new Route(GET, "/_cat/aliases"), + new Route(GET, "/_cat/aliases/{alias}"))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/cat/RestAllocationAction.java b/server/src/main/java/org/elasticsearch/rest/action/cat/RestAllocationAction.java index 1f30fb917ea24..1c81d24c21e21 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/cat/RestAllocationAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/cat/RestAllocationAction.java @@ -32,20 +32,25 @@ import org.elasticsearch.common.Strings; import org.elasticsearch.common.Table; import org.elasticsearch.common.unit.ByteSizeValue; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.action.RestActionListener; import org.elasticsearch.rest.action.RestResponseListener; +import java.util.List; + +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.rest.RestRequest.Method.GET; public class RestAllocationAction extends AbstractCatAction { - public RestAllocationAction(RestController controller) { - controller.registerHandler(GET, "/_cat/allocation", this); - controller.registerHandler(GET, "/_cat/allocation/{nodes}", this); + @Override + public List routes() { + return unmodifiableList(asList( + new Route(GET, "/_cat/allocation"), + new Route(GET, "/_cat/allocation/{nodes}"))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/cat/RestCatAction.java b/server/src/main/java/org/elasticsearch/rest/action/cat/RestCatAction.java index fe5f7b8127c5d..c545a1bd2f384 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/cat/RestCatAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/cat/RestCatAction.java @@ -20,16 +20,15 @@ package org.elasticsearch.rest.action.cat; import org.elasticsearch.client.node.NodeClient; -import org.elasticsearch.common.inject.Inject; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestStatus; import java.io.IOException; import java.util.List; +import static java.util.Collections.singletonList; import static org.elasticsearch.rest.RestRequest.Method.GET; public class RestCatAction extends BaseRestHandler { @@ -38,9 +37,7 @@ public class RestCatAction extends BaseRestHandler { private static final String CAT_NL = CAT + "\n"; private final String HELP; - @Inject - public RestCatAction(RestController controller, List catActions) { - controller.registerHandler(GET, "/_cat", this); + public RestCatAction(List catActions) { StringBuilder sb = new StringBuilder(); sb.append(CAT_NL); for (AbstractCatAction catAction : catActions) { @@ -49,6 +46,11 @@ public RestCatAction(RestController controller, List catActio HELP = sb.toString(); } + @Override + public List routes() { + return singletonList(new Route(GET, "/_cat")); + } + @Override public String getName() { return "cat_action"; diff --git a/server/src/main/java/org/elasticsearch/rest/action/cat/RestCatRecoveryAction.java b/server/src/main/java/org/elasticsearch/rest/action/cat/RestCatRecoveryAction.java index 0f3e88123005d..04fc533a2cd78 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/cat/RestCatRecoveryAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/cat/RestCatRecoveryAction.java @@ -31,7 +31,6 @@ import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.xcontent.XContentElasticsearchExtension; import org.elasticsearch.indices.recovery.RecoveryState; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.action.RestResponseListener; @@ -40,6 +39,8 @@ import java.util.List; import java.util.Locale; +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.rest.RestRequest.Method.GET; /** @@ -49,9 +50,11 @@ */ public class RestCatRecoveryAction extends AbstractCatAction { - public RestCatRecoveryAction(RestController restController) { - restController.registerHandler(GET, "/_cat/recovery", this); - restController.registerHandler(GET, "/_cat/recovery/{index}", this); + @Override + public List routes() { + return unmodifiableList(asList( + new Route(GET, "/_cat/recovery"), + new Route(GET, "/_cat/recovery/{index}"))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/cat/RestCountAction.java b/server/src/main/java/org/elasticsearch/rest/action/cat/RestCountAction.java index 7b7742972eac4..fada1e5d35645 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/cat/RestCountAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/cat/RestCountAction.java @@ -27,7 +27,6 @@ import org.elasticsearch.common.Strings; import org.elasticsearch.common.Table; import org.elasticsearch.index.query.QueryBuilder; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.action.RestActions; @@ -35,13 +34,19 @@ import org.elasticsearch.search.builder.SearchSourceBuilder; import java.io.IOException; +import java.util.List; +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.rest.RestRequest.Method.GET; public class RestCountAction extends AbstractCatAction { - public RestCountAction(RestController restController) { - restController.registerHandler(GET, "/_cat/count", this); - restController.registerHandler(GET, "/_cat/count/{index}", this); + + @Override + public List routes() { + return unmodifiableList(asList( + new Route(GET, "/_cat/count"), + new Route(GET, "/_cat/count/{index}"))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/cat/RestFielddataAction.java b/server/src/main/java/org/elasticsearch/rest/action/cat/RestFielddataAction.java index 2eb83151953fc..cc7e16b2ea39f 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/cat/RestFielddataAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/cat/RestFielddataAction.java @@ -26,11 +26,14 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.Table; import org.elasticsearch.common.unit.ByteSizeValue; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.action.RestResponseListener; +import java.util.List; + +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.rest.RestRequest.Method.GET; /** @@ -38,9 +41,11 @@ */ public class RestFielddataAction extends AbstractCatAction { - public RestFielddataAction(RestController controller) { - controller.registerHandler(GET, "/_cat/fielddata", this); - controller.registerHandler(GET, "/_cat/fielddata/{fields}", this); + @Override + public List routes() { + return unmodifiableList(asList( + new Route(GET, "/_cat/fielddata"), + new Route(GET, "/_cat/fielddata/{fields}"))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/cat/RestHealthAction.java b/server/src/main/java/org/elasticsearch/rest/action/cat/RestHealthAction.java index 5e896f210f665..7e859ac0f21a1 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/cat/RestHealthAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/cat/RestHealthAction.java @@ -23,19 +23,21 @@ import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.Table; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.action.RestResponseListener; +import java.util.List; import java.util.Locale; +import static java.util.Collections.singletonList; import static org.elasticsearch.rest.RestRequest.Method.GET; public class RestHealthAction extends AbstractCatAction { - public RestHealthAction(RestController controller) { - controller.registerHandler(GET, "/_cat/health", this); + @Override + public List routes() { + return singletonList(new Route(GET, "/_cat/health")); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/cat/RestIndicesAction.java b/server/src/main/java/org/elasticsearch/rest/action/cat/RestIndicesAction.java index e452eef2c3104..e0f0e7f1f793f 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/cat/RestIndicesAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/cat/RestIndicesAction.java @@ -43,7 +43,6 @@ import org.elasticsearch.common.time.DateFormatter; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.index.IndexSettings; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.action.RestResponseListener; @@ -51,10 +50,10 @@ import java.time.Instant; import java.time.ZoneOffset; import java.time.ZonedDateTime; -import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.HashSet; +import java.util.List; import java.util.Locale; import java.util.Map; import java.util.Set; @@ -62,6 +61,8 @@ import java.util.stream.Collectors; import java.util.stream.StreamSupport; +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.action.support.master.MasterNodeRequest.DEFAULT_MASTER_NODE_TIMEOUT; import static org.elasticsearch.rest.RestRequest.Method.GET; @@ -69,9 +70,11 @@ public class RestIndicesAction extends AbstractCatAction { private static final DateFormatter STRICT_DATE_TIME_FORMATTER = DateFormatter.forPattern("strict_date_time"); - public RestIndicesAction(RestController controller) { - controller.registerHandler(GET, "/_cat/indices", this); - controller.registerHandler(GET, "/_cat/indices/{index}", this); + @Override + public List routes() { + return unmodifiableList(asList( + new Route(GET, "/_cat/indices"), + new Route(GET, "/_cat/indices/{index}"))); } @Override @@ -234,7 +237,7 @@ public void onFailure(final Exception e) { private static final Set RESPONSE_PARAMS; static { - final Set responseParams = new HashSet<>(Arrays.asList("local", "health")); + final Set responseParams = new HashSet<>(asList("local", "health")); responseParams.addAll(AbstractCatAction.RESPONSE_PARAMS); RESPONSE_PARAMS = Collections.unmodifiableSet(responseParams); } diff --git a/server/src/main/java/org/elasticsearch/rest/action/cat/RestMasterAction.java b/server/src/main/java/org/elasticsearch/rest/action/cat/RestMasterAction.java index e50865af019c6..18dea4625b6fe 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/cat/RestMasterAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/cat/RestMasterAction.java @@ -25,17 +25,20 @@ import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodes; import org.elasticsearch.common.Table; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.action.RestResponseListener; +import java.util.List; + +import static java.util.Collections.singletonList; import static org.elasticsearch.rest.RestRequest.Method.GET; public class RestMasterAction extends AbstractCatAction { - public RestMasterAction(RestController controller) { - controller.registerHandler(GET, "/_cat/master", this); + @Override + public List routes() { + return singletonList(new Route(GET, "/_cat/master")); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/cat/RestNodeAttrsAction.java b/server/src/main/java/org/elasticsearch/rest/action/cat/RestNodeAttrsAction.java index efae10a6aa256..dcb75b22e647f 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/cat/RestNodeAttrsAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/cat/RestNodeAttrsAction.java @@ -29,20 +29,22 @@ import org.elasticsearch.cluster.node.DiscoveryNodes; import org.elasticsearch.common.Strings; import org.elasticsearch.common.Table; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.action.RestActionListener; import org.elasticsearch.rest.action.RestResponseListener; +import java.util.List; import java.util.Map; +import static java.util.Collections.singletonList; import static org.elasticsearch.rest.RestRequest.Method.GET; public class RestNodeAttrsAction extends AbstractCatAction { - public RestNodeAttrsAction(RestController controller) { - controller.registerHandler(GET, "/_cat/nodeattrs", this); + @Override + public List routes() { + return singletonList(new Route(GET, "/_cat/nodeattrs")); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/cat/RestNodesAction.java b/server/src/main/java/org/elasticsearch/rest/action/cat/RestNodesAction.java index 849fbdac49224..7f16476d1c15c 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/cat/RestNodesAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/cat/RestNodesAction.java @@ -55,7 +55,6 @@ import org.elasticsearch.monitor.jvm.JvmStats; import org.elasticsearch.monitor.os.OsStats; import org.elasticsearch.monitor.process.ProcessStats; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.action.RestActionListener; @@ -63,9 +62,11 @@ import org.elasticsearch.script.ScriptStats; import org.elasticsearch.search.suggest.completion.CompletionStats; +import java.util.List; import java.util.Locale; import java.util.stream.Collectors; +import static java.util.Collections.singletonList; import static org.elasticsearch.rest.RestRequest.Method.GET; public class RestNodesAction extends AbstractCatAction { @@ -74,8 +75,9 @@ public class RestNodesAction extends AbstractCatAction { static final String LOCAL_DEPRECATED_MESSAGE = "Deprecated parameter [local] used. This parameter does not cause this API to act " + "locally, and should not be used. It will be unsupported in version 8.0."; - public RestNodesAction(RestController controller) { - controller.registerHandler(GET, "/_cat/nodes", this); + @Override + public List routes() { + return singletonList(new Route(GET, "/_cat/nodes")); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/cat/RestPendingClusterTasksAction.java b/server/src/main/java/org/elasticsearch/rest/action/cat/RestPendingClusterTasksAction.java index 84bd87981536b..f3071839612e2 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/cat/RestPendingClusterTasksAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/cat/RestPendingClusterTasksAction.java @@ -24,17 +24,20 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.cluster.service.PendingClusterTask; import org.elasticsearch.common.Table; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.action.RestResponseListener; +import java.util.List; + +import static java.util.Collections.singletonList; import static org.elasticsearch.rest.RestRequest.Method.GET; public class RestPendingClusterTasksAction extends AbstractCatAction { - public RestPendingClusterTasksAction(RestController controller) { - controller.registerHandler(GET, "/_cat/pending_tasks", this); + @Override + public List routes() { + return singletonList(new Route(GET, "/_cat/pending_tasks")); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/cat/RestPluginsAction.java b/server/src/main/java/org/elasticsearch/rest/action/cat/RestPluginsAction.java index eb6a6fc4b8ff8..9a50deee98c8e 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/cat/RestPluginsAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/cat/RestPluginsAction.java @@ -29,18 +29,21 @@ import org.elasticsearch.cluster.node.DiscoveryNodes; import org.elasticsearch.common.Table; import org.elasticsearch.plugins.PluginInfo; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.action.RestActionListener; import org.elasticsearch.rest.action.RestResponseListener; +import java.util.List; + +import static java.util.Collections.singletonList; import static org.elasticsearch.rest.RestRequest.Method.GET; public class RestPluginsAction extends AbstractCatAction { - public RestPluginsAction(RestController controller) { - controller.registerHandler(GET, "/_cat/plugins", this); + @Override + public List routes() { + return singletonList(new Route(GET, "/_cat/plugins")); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/cat/RestRepositoriesAction.java b/server/src/main/java/org/elasticsearch/rest/action/cat/RestRepositoriesAction.java index f77f9bf100bda..e9a5bd6b3aac9 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/cat/RestRepositoriesAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/cat/RestRepositoriesAction.java @@ -24,11 +24,13 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.cluster.metadata.RepositoryMetaData; import org.elasticsearch.common.Table; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.action.RestResponseListener; +import java.util.List; + +import static java.util.Collections.singletonList; import static org.elasticsearch.rest.RestRequest.Method.GET; /** @@ -36,8 +38,9 @@ */ public class RestRepositoriesAction extends AbstractCatAction { - public RestRepositoriesAction(RestController controller) { - controller.registerHandler(GET, "/_cat/repositories", this); + @Override + public List routes() { + return singletonList(new Route(GET, "/_cat/repositories")); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/cat/RestSegmentsAction.java b/server/src/main/java/org/elasticsearch/rest/action/cat/RestSegmentsAction.java index c51fa593f3b5f..3c63f7bbdbf30 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/cat/RestSegmentsAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/cat/RestSegmentsAction.java @@ -31,7 +31,6 @@ import org.elasticsearch.common.Strings; import org.elasticsearch.common.Table; import org.elasticsearch.index.engine.Segment; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.action.RestActionListener; @@ -40,13 +39,17 @@ import java.util.List; import java.util.Map; +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.rest.RestRequest.Method.GET; public class RestSegmentsAction extends AbstractCatAction { - public RestSegmentsAction(RestController controller) { - controller.registerHandler(GET, "/_cat/segments", this); - controller.registerHandler(GET, "/_cat/segments/{index}", this); + @Override + public List routes() { + return unmodifiableList(asList( + new Route(GET, "/_cat/segments"), + new Route(GET, "/_cat/segments/{index}"))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/cat/RestShardsAction.java b/server/src/main/java/org/elasticsearch/rest/action/cat/RestShardsAction.java index 847b1a773e52a..9a321476efda7 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/cat/RestShardsAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/cat/RestShardsAction.java @@ -45,7 +45,6 @@ import org.elasticsearch.index.shard.DocsStats; import org.elasticsearch.index.store.StoreStats; import org.elasticsearch.index.warmer.WarmerStats; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.action.RestActionListener; @@ -53,16 +52,20 @@ import org.elasticsearch.search.suggest.completion.CompletionStats; import java.time.Instant; +import java.util.List; import java.util.Locale; import java.util.function.Function; +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.rest.RestRequest.Method.GET; public class RestShardsAction extends AbstractCatAction { - public RestShardsAction(RestController controller) { - controller.registerHandler(GET, "/_cat/shards", this); - controller.registerHandler(GET, "/_cat/shards/{index}", this); + @Override + public List routes() { + return unmodifiableList(asList(new Route(GET, "/_cat/shards"), + new Route(GET, "/_cat/shards/{index}"))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/cat/RestSnapshotAction.java b/server/src/main/java/org/elasticsearch/rest/action/cat/RestSnapshotAction.java index 2e28665fa93af..9237fb33cc9e7 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/cat/RestSnapshotAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/cat/RestSnapshotAction.java @@ -26,7 +26,6 @@ import org.elasticsearch.common.Table; import org.elasticsearch.common.time.DateFormatter; import org.elasticsearch.common.unit.TimeValue; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.action.RestResponseListener; @@ -35,8 +34,11 @@ import java.time.Instant; import java.time.ZoneOffset; +import java.util.List; import java.util.concurrent.TimeUnit; +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.rest.RestRequest.Method.GET; /** @@ -44,9 +46,11 @@ */ public class RestSnapshotAction extends AbstractCatAction { - public RestSnapshotAction(RestController controller) { - controller.registerHandler(GET, "/_cat/snapshots", this); - controller.registerHandler(GET, "/_cat/snapshots/{repository}", this); + @Override + public List routes() { + return unmodifiableList(asList( + new Route(GET, "/_cat/snapshots"), + new Route(GET, "/_cat/snapshots/{repository}"))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/cat/RestTasksAction.java b/server/src/main/java/org/elasticsearch/rest/action/cat/RestTasksAction.java index b6d5eb549bfa4..2868d16d682fa 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/cat/RestTasksAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/cat/RestTasksAction.java @@ -28,7 +28,6 @@ import org.elasticsearch.common.Table; import org.elasticsearch.common.time.DateFormatter; import org.elasticsearch.common.unit.TimeValue; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.action.RestResponseListener; @@ -44,17 +43,22 @@ import java.util.Set; import java.util.function.Supplier; +import static java.util.Collections.singletonList; import static org.elasticsearch.rest.RestRequest.Method.GET; import static org.elasticsearch.rest.action.admin.cluster.RestListTasksAction.generateListTasksRequest; public class RestTasksAction extends AbstractCatAction { private final Supplier nodesInCluster; - public RestTasksAction(RestController controller, Supplier nodesInCluster) { - controller.registerHandler(GET, "/_cat/tasks", this); + public RestTasksAction(Supplier nodesInCluster) { this.nodesInCluster = nodesInCluster; } + @Override + public List routes() { + return singletonList(new Route(GET, "/_cat/tasks")); + } + @Override public String getName() { return "cat_tasks_action"; diff --git a/server/src/main/java/org/elasticsearch/rest/action/cat/RestTemplatesAction.java b/server/src/main/java/org/elasticsearch/rest/action/cat/RestTemplatesAction.java index c8da4648e2ac0..fb9946d5acfe0 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/cat/RestTemplatesAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/cat/RestTemplatesAction.java @@ -27,18 +27,23 @@ import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.common.Table; import org.elasticsearch.common.regex.Regex; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.action.RestResponseListener; +import java.util.List; + +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.rest.RestRequest.Method.GET; public class RestTemplatesAction extends AbstractCatAction { - public RestTemplatesAction(RestController controller) { - controller.registerHandler(GET, "/_cat/templates", this); - controller.registerHandler(GET, "/_cat/templates/{name}", this); + @Override + public List routes() { + return unmodifiableList(asList( + new Route(GET, "/_cat/templates"), + new Route(GET, "/_cat/templates/{name}"))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/cat/RestThreadPoolAction.java b/server/src/main/java/org/elasticsearch/rest/action/cat/RestThreadPoolAction.java index 571767affd0c0..caaaeba07b964 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/cat/RestThreadPoolAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/cat/RestThreadPoolAction.java @@ -32,7 +32,6 @@ import org.elasticsearch.cluster.node.DiscoveryNodes; import org.elasticsearch.common.Table; import org.elasticsearch.common.regex.Regex; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.action.RestActionListener; @@ -43,17 +42,22 @@ import java.util.Collections; import java.util.HashMap; import java.util.HashSet; +import java.util.List; import java.util.Map; import java.util.Set; import java.util.TreeMap; +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.rest.RestRequest.Method.GET; public class RestThreadPoolAction extends AbstractCatAction { - public RestThreadPoolAction(RestController controller) { - controller.registerHandler(GET, "/_cat/thread_pool", this); - controller.registerHandler(GET, "/_cat/thread_pool/{thread_pool_patterns}", this); + @Override + public List routes() { + return unmodifiableList(asList( + new Route(GET, "/_cat/thread_pool"), + new Route(GET, "/_cat/thread_pool/{thread_pool_patterns}"))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/document/RestBulkAction.java b/server/src/main/java/org/elasticsearch/rest/action/document/RestBulkAction.java index 4eb2a49884f04..24ee7208b8e33 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/document/RestBulkAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/document/RestBulkAction.java @@ -29,14 +29,16 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.mapper.MapperService; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestStatusToXContentListener; import org.elasticsearch.rest.action.search.RestSearchAction; import org.elasticsearch.search.fetch.subphase.FetchSourceContext; import java.io.IOException; +import java.util.List; +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.rest.RestRequest.Method.POST; import static org.elasticsearch.rest.RestRequest.Method.PUT; @@ -56,19 +58,22 @@ public class RestBulkAction extends BaseRestHandler { public static final String TYPES_DEPRECATION_MESSAGE = "[types removal]" + " Specifying types in bulk requests is deprecated."; - public RestBulkAction(Settings settings, RestController controller) { - controller.registerHandler(POST, "/_bulk", this); - controller.registerHandler(PUT, "/_bulk", this); - controller.registerHandler(POST, "/{index}/_bulk", this); - controller.registerHandler(PUT, "/{index}/_bulk", this); - - // Deprecated typed endpoints. - controller.registerHandler(POST, "/{index}/{type}/_bulk", this); - controller.registerHandler(PUT, "/{index}/{type}/_bulk", this); - + public RestBulkAction(Settings settings) { this.allowExplicitIndex = MULTI_ALLOW_EXPLICIT_INDEX.get(settings); } + @Override + public List routes() { + return unmodifiableList(asList( + new Route(POST, "/_bulk"), + new Route(PUT, "/_bulk"), + new Route(POST, "/{index}/_bulk"), + new Route(PUT, "/{index}/_bulk"), + // Deprecated typed endpoints. + new Route(POST, "/{index}/{type}/_bulk"), + new Route(PUT, "/{index}/{type}/_bulk"))); + } + @Override public String getName() { return "bulk_action"; diff --git a/server/src/main/java/org/elasticsearch/rest/action/document/RestDeleteAction.java b/server/src/main/java/org/elasticsearch/rest/action/document/RestDeleteAction.java index 479e1eb73dc44..e5e5c78ebe223 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/document/RestDeleteAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/document/RestDeleteAction.java @@ -26,13 +26,15 @@ import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.index.VersionType; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestActions; import org.elasticsearch.rest.action.RestStatusToXContentListener; import java.io.IOException; +import java.util.List; +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.rest.RestRequest.Method.DELETE; public class RestDeleteAction extends BaseRestHandler { @@ -41,11 +43,12 @@ public class RestDeleteAction extends BaseRestHandler { public static final String TYPES_DEPRECATION_MESSAGE = "[types removal] Specifying types in " + "document index requests is deprecated, use the /{index}/_doc/{id} endpoint instead."; - public RestDeleteAction(RestController controller) { - controller.registerHandler(DELETE, "/{index}/_doc/{id}", this); - - // Deprecated typed endpoint. - controller.registerHandler(DELETE, "/{index}/{type}/{id}", this); + @Override + public List routes() { + return unmodifiableList(asList( + new Route(DELETE, "/{index}/_doc/{id}"), + // Deprecated typed endpoint. + new Route(DELETE, "/{index}/{type}/{id}"))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/document/RestGetAction.java b/server/src/main/java/org/elasticsearch/rest/action/document/RestGetAction.java index 100d4cc653118..4699d5d8d4bda 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/document/RestGetAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/document/RestGetAction.java @@ -27,7 +27,6 @@ import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.index.VersionType; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestStatus; import org.elasticsearch.rest.action.RestActions; @@ -35,7 +34,10 @@ import org.elasticsearch.search.fetch.subphase.FetchSourceContext; import java.io.IOException; +import java.util.List; +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.rest.RestRequest.Method.GET; import static org.elasticsearch.rest.RestRequest.Method.HEAD; import static org.elasticsearch.rest.RestStatus.NOT_FOUND; @@ -47,20 +49,21 @@ public class RestGetAction extends BaseRestHandler { public static final String TYPES_DEPRECATION_MESSAGE = "[types removal] Specifying types in " + "document get requests is deprecated, use the /{index}/_doc/{id} endpoint instead."; - public RestGetAction(final RestController controller) { - controller.registerHandler(GET, "/{index}/_doc/{id}", this); - controller.registerHandler(HEAD, "/{index}/_doc/{id}", this); - - // Deprecated typed endpoints. - controller.registerHandler(GET, "/{index}/{type}/{id}", this); - controller.registerHandler(HEAD, "/{index}/{type}/{id}", this); - } - @Override public String getName() { return "document_get_action"; } + @Override + public List routes() { + return unmodifiableList(asList( + new Route(GET, "/{index}/_doc/{id}"), + new Route(HEAD, "/{index}/_doc/{id}"), + // Deprecated typed endpoints. + new Route(GET, "/{index}/{type}/{id}"), + new Route(HEAD, "/{index}/{type}/{id}"))); + } + @Override public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException { GetRequest getRequest; diff --git a/server/src/main/java/org/elasticsearch/rest/action/document/RestGetSourceAction.java b/server/src/main/java/org/elasticsearch/rest/action/document/RestGetSourceAction.java index a45c30d0ad1bb..1fe760e50d115 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/document/RestGetSourceAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/document/RestGetSourceAction.java @@ -32,7 +32,6 @@ import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.BytesRestResponse; import org.elasticsearch.rest.RestChannel; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.action.RestResponseListener; @@ -40,7 +39,10 @@ import java.io.IOException; import java.io.InputStream; +import java.util.List; +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.rest.RestRequest.Method.GET; import static org.elasticsearch.rest.RestRequest.Method.HEAD; import static org.elasticsearch.rest.RestStatus.OK; @@ -54,11 +56,13 @@ public class RestGetSourceAction extends BaseRestHandler { static final String TYPES_DEPRECATION_MESSAGE = "[types removal] Specifying types in get_source and exist_source" + "requests is deprecated."; - public RestGetSourceAction(final RestController controller) { - controller.registerHandler(GET, "/{index}/_source/{id}", this); - controller.registerHandler(HEAD, "/{index}/_source/{id}", this); - controller.registerHandler(GET, "/{index}/{type}/{id}/_source", this); - controller.registerHandler(HEAD, "/{index}/{type}/{id}/_source", this); + @Override + public List routes() { + return unmodifiableList(asList( + new Route(GET, "/{index}/_source/{id}"), + new Route(HEAD, "/{index}/_source/{id}"), + new Route(GET, "/{index}/{type}/{id}/_source"), + new Route(HEAD, "/{index}/{type}/{id}/_source"))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/document/RestIndexAction.java b/server/src/main/java/org/elasticsearch/rest/action/document/RestIndexAction.java index 4f9838a105836..bfd9e1f231731 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/document/RestIndexAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/document/RestIndexAction.java @@ -29,14 +29,16 @@ import org.elasticsearch.index.VersionType; import org.elasticsearch.index.mapper.MapperService; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestActions; import org.elasticsearch.rest.action.RestStatusToXContentListener; import java.io.IOException; +import java.util.List; import java.util.Locale; +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.rest.RestRequest.Method.POST; import static org.elasticsearch.rest.RestRequest.Method.PUT; @@ -47,26 +49,13 @@ public class RestIndexAction extends BaseRestHandler { "index requests is deprecated, use the typeless endpoints instead (/{index}/_doc/{id}, /{index}/_doc, " + "or /{index}/_create/{id})."; - private final ClusterService clusterService; - - public RestIndexAction(RestController controller, ClusterService clusterService) { - this.clusterService = clusterService; - - AutoIdHandler autoIdHandler = new AutoIdHandler(); - controller.registerHandler(POST, "/{index}/_doc", autoIdHandler); // auto id creation - controller.registerHandler(PUT, "/{index}/_doc/{id}", this); - controller.registerHandler(POST, "/{index}/_doc/{id}", this); - - CreateHandler createHandler = new CreateHandler(); - controller.registerHandler(PUT, "/{index}/_create/{id}", createHandler); - controller.registerHandler(POST, "/{index}/_create/{id}/", createHandler); - - // Deprecated typed endpoints. - controller.registerHandler(POST, "/{index}/{type}", autoIdHandler); // auto id creation - controller.registerHandler(PUT, "/{index}/{type}/{id}", this); - controller.registerHandler(POST, "/{index}/{type}/{id}", this); - controller.registerHandler(PUT, "/{index}/{type}/{id}/_create", createHandler); - controller.registerHandler(POST, "/{index}/{type}/{id}/_create", createHandler); + @Override + public List routes() { + return unmodifiableList(asList( + new Route(POST, "/{index}/_doc/{id}"), + new Route(PUT, "/{index}/_doc/{id}"), + new Route(POST, "/{index}/{type}/{id}"), + new Route(PUT, "/{index}/{type}/{id}"))); } @Override @@ -74,20 +63,27 @@ public String getName() { return "document_index_action"; } - final class CreateHandler extends BaseRestHandler { - protected CreateHandler() { - } + public static final class CreateHandler extends RestIndexAction { @Override public String getName() { return "document_create_action"; } + @Override + public List routes() { + return unmodifiableList(asList( + new Route(POST, "/{index}/_create/{id}"), + new Route(PUT, "/{index}/_create/{id}"), + new Route(POST, "/{index}/{type}/{id}/_create"), + new Route(PUT, "/{index}/{type}/{id}/_create"))); + } + @Override public RestChannelConsumer prepareRequest(RestRequest request, final NodeClient client) throws IOException { validateOpType(request.params().get("op_type")); request.params().put("op_type", "create"); - return RestIndexAction.this.prepareRequest(request, client); + return super.prepareRequest(request, client); } void validateOpType(String opType) { @@ -97,8 +93,12 @@ void validateOpType(String opType) { } } - final class AutoIdHandler extends BaseRestHandler { - protected AutoIdHandler() { + public static final class AutoIdHandler extends RestIndexAction { + + private final ClusterService clusterService; + + public AutoIdHandler(ClusterService clusterService) { + this.clusterService = clusterService; } @Override @@ -106,6 +106,13 @@ public String getName() { return "document_create_action"; } + @Override + public List routes() { + return unmodifiableList(asList( + new Route(POST, "/{index}/_doc"), + new Route(POST, "/{index}/{type}"))); + } + @Override public RestChannelConsumer prepareRequest(RestRequest request, final NodeClient client) throws IOException { assert request.params().get("id") == null : "non-null id: " + request.params().get("id"); @@ -113,7 +120,7 @@ public RestChannelConsumer prepareRequest(RestRequest request, final NodeClient // default to op_type create request.params().put("op_type", "create"); } - return RestIndexAction.this.prepareRequest(request, client); + return super.prepareRequest(request, client); } } diff --git a/server/src/main/java/org/elasticsearch/rest/action/document/RestMultiGetAction.java b/server/src/main/java/org/elasticsearch/rest/action/document/RestMultiGetAction.java index a7ef8e60fb0c3..5eabf37e20618 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/document/RestMultiGetAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/document/RestMultiGetAction.java @@ -27,13 +27,15 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.search.fetch.subphase.FetchSourceContext; import java.io.IOException; +import java.util.List; +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.rest.RestRequest.Method.GET; import static org.elasticsearch.rest.RestRequest.Method.POST; @@ -45,19 +47,22 @@ public class RestMultiGetAction extends BaseRestHandler { private final boolean allowExplicitIndex; - public RestMultiGetAction(Settings settings, RestController controller) { - controller.registerHandler(GET, "/_mget", this); - controller.registerHandler(POST, "/_mget", this); - controller.registerHandler(GET, "/{index}/_mget", this); - controller.registerHandler(POST, "/{index}/_mget", this); - - // Deprecated typed endpoints. - controller.registerHandler(GET, "/{index}/{type}/_mget", this); - controller.registerHandler(POST, "/{index}/{type}/_mget", this); - + public RestMultiGetAction(Settings settings) { this.allowExplicitIndex = MULTI_ALLOW_EXPLICIT_INDEX.get(settings); } + @Override + public List routes() { + return unmodifiableList(asList( + new Route(GET, "/_mget"), + new Route(POST, "/_mget"), + new Route(GET, "/{index}/_mget"), + new Route(POST, "/{index}/_mget"), + // Deprecated typed endpoints. + new Route(GET, "/{index}/{type}/_mget"), + new Route(POST, "/{index}/{type}/_mget"))); + } + @Override public String getName() { return "document_mget_action"; diff --git a/server/src/main/java/org/elasticsearch/rest/action/document/RestMultiTermVectorsAction.java b/server/src/main/java/org/elasticsearch/rest/action/document/RestMultiTermVectorsAction.java index 5322973d50e56..be9bca6e5665c 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/document/RestMultiTermVectorsAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/document/RestMultiTermVectorsAction.java @@ -27,12 +27,14 @@ import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.index.mapper.MapperService; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import java.io.IOException; +import java.util.List; +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.rest.RestRequest.Method.GET; import static org.elasticsearch.rest.RestRequest.Method.POST; @@ -42,15 +44,16 @@ public class RestMultiTermVectorsAction extends BaseRestHandler { static final String TYPES_DEPRECATION_MESSAGE = "[types removal] " + "Specifying types in multi term vector requests is deprecated."; - public RestMultiTermVectorsAction(RestController controller) { - controller.registerHandler(GET, "/_mtermvectors", this); - controller.registerHandler(POST, "/_mtermvectors", this); - controller.registerHandler(GET, "/{index}/_mtermvectors", this); - controller.registerHandler(POST, "/{index}/_mtermvectors", this); - - // Deprecated typed endpoints. - controller.registerHandler(GET, "/{index}/{type}/_mtermvectors", this); - controller.registerHandler(POST, "/{index}/{type}/_mtermvectors", this); + @Override + public List routes() { + return unmodifiableList(asList( + new Route(GET, "/_mtermvectors"), + new Route(POST, "/_mtermvectors"), + new Route(GET, "/{index}/_mtermvectors"), + new Route(POST, "/{index}/_mtermvectors"), + // Deprecated typed endpoints. + new Route(GET, "/{index}/{type}/_mtermvectors"), + new Route(POST, "/{index}/{type}/_mtermvectors"))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/document/RestTermVectorsAction.java b/server/src/main/java/org/elasticsearch/rest/action/document/RestTermVectorsAction.java index 70455116de940..cb70636d942ba 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/document/RestTermVectorsAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/document/RestTermVectorsAction.java @@ -28,15 +28,17 @@ import org.elasticsearch.index.VersionType; import org.elasticsearch.index.mapper.MapperService; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestActions; import org.elasticsearch.rest.action.RestToXContentListener; import java.io.IOException; import java.util.HashSet; +import java.util.List; import java.util.Set; +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.rest.RestRequest.Method.GET; import static org.elasticsearch.rest.RestRequest.Method.POST; @@ -50,17 +52,18 @@ public class RestTermVectorsAction extends BaseRestHandler { public static final String TYPES_DEPRECATION_MESSAGE = "[types removal] " + "Specifying types in term vector requests is deprecated."; - public RestTermVectorsAction(RestController controller) { - controller.registerHandler(GET, "/{index}/_termvectors", this); - controller.registerHandler(POST, "/{index}/_termvectors", this); - controller.registerHandler(GET, "/{index}/_termvectors/{id}", this); - controller.registerHandler(POST, "/{index}/_termvectors/{id}", this); - - // Deprecated typed endpoints. - controller.registerHandler(GET, "/{index}/{type}/_termvectors", this); - controller.registerHandler(POST, "/{index}/{type}/_termvectors", this); - controller.registerHandler(GET, "/{index}/{type}/{id}/_termvectors", this); - controller.registerHandler(POST, "/{index}/{type}/{id}/_termvectors", this); + @Override + public List routes() { + return unmodifiableList(asList( + new Route(GET, "/{index}/_termvectors"), + new Route(POST, "/{index}/_termvectors"), + new Route(GET, "/{index}/_termvectors/{id}"), + new Route(POST, "/{index}/_termvectors/{id}"), + // Deprecated typed endpoints. + new Route(GET, "/{index}/{type}/_termvectors"), + new Route(POST, "/{index}/{type}/_termvectors"), + new Route(GET, "/{index}/{type}/{id}/_termvectors"), + new Route(POST, "/{index}/{type}/{id}/_termvectors"))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/document/RestUpdateAction.java b/server/src/main/java/org/elasticsearch/rest/action/document/RestUpdateAction.java index 1409d7c3efaf3..c652e097f037e 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/document/RestUpdateAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/document/RestUpdateAction.java @@ -28,14 +28,16 @@ import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.index.VersionType; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestActions; import org.elasticsearch.rest.action.RestStatusToXContentListener; import org.elasticsearch.search.fetch.subphase.FetchSourceContext; import java.io.IOException; +import java.util.List; +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.rest.RestRequest.Method.POST; public class RestUpdateAction extends BaseRestHandler { @@ -44,11 +46,12 @@ public class RestUpdateAction extends BaseRestHandler { public static final String TYPES_DEPRECATION_MESSAGE = "[types removal] Specifying types in " + "document update requests is deprecated, use the endpoint /{index}/_update/{id} instead."; - public RestUpdateAction(RestController controller) { - controller.registerHandler(POST, "/{index}/_update/{id}", this); - - // Deprecated typed endpoint. - controller.registerHandler(POST, "/{index}/{type}/{id}/_update", this); + @Override + public List routes() { + return unmodifiableList(asList( + new Route(POST, "/{index}/_update/{id}"), + // Deprecated typed endpoint. + new Route(POST, "/{index}/{type}/{id}/_update"))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/ingest/RestDeletePipelineAction.java b/server/src/main/java/org/elasticsearch/rest/action/ingest/RestDeletePipelineAction.java index dea61df609a92..2956811e26fed 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/ingest/RestDeletePipelineAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/ingest/RestDeletePipelineAction.java @@ -22,15 +22,19 @@ import org.elasticsearch.action.ingest.DeletePipelineRequest; import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import java.io.IOException; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.DELETE; public class RestDeletePipelineAction extends BaseRestHandler { - public RestDeletePipelineAction(RestController controller) { - controller.registerHandler(RestRequest.Method.DELETE, "/_ingest/pipeline/{id}", this); + @Override + public List routes() { + return singletonList(new Route(DELETE, "/_ingest/pipeline/{id}")); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/ingest/RestGetPipelineAction.java b/server/src/main/java/org/elasticsearch/rest/action/ingest/RestGetPipelineAction.java index 751b9ee68894a..1e4e016027b8e 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/ingest/RestGetPipelineAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/ingest/RestGetPipelineAction.java @@ -23,17 +23,23 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.Strings; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestStatusToXContentListener; import java.io.IOException; +import java.util.List; + +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; +import static org.elasticsearch.rest.RestRequest.Method.GET; public class RestGetPipelineAction extends BaseRestHandler { - public RestGetPipelineAction(RestController controller) { - controller.registerHandler(RestRequest.Method.GET, "/_ingest/pipeline", this); - controller.registerHandler(RestRequest.Method.GET, "/_ingest/pipeline/{id}", this); + @Override + public List routes() { + return unmodifiableList(asList( + new Route(GET, "/_ingest/pipeline"), + new Route(GET, "/_ingest/pipeline/{id}"))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/ingest/RestPutPipelineAction.java b/server/src/main/java/org/elasticsearch/rest/action/ingest/RestPutPipelineAction.java index 3b1861c14f591..b1fb8086e0653 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/ingest/RestPutPipelineAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/ingest/RestPutPipelineAction.java @@ -25,17 +25,21 @@ import org.elasticsearch.common.collect.Tuple; import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import java.io.IOException; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.PUT; public class RestPutPipelineAction extends BaseRestHandler { - public RestPutPipelineAction(RestController controller) { - controller.registerHandler(RestRequest.Method.PUT, "/_ingest/pipeline/{id}", this); + @Override + public List routes() { + return singletonList(new Route(PUT, "/_ingest/pipeline/{id}")); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/ingest/RestSimulatePipelineAction.java b/server/src/main/java/org/elasticsearch/rest/action/ingest/RestSimulatePipelineAction.java index 6b8d6c3ccc4cd..1ac0bdd6fcd5a 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/ingest/RestSimulatePipelineAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/ingest/RestSimulatePipelineAction.java @@ -25,19 +25,26 @@ import org.elasticsearch.common.collect.Tuple; import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import java.io.IOException; +import java.util.List; + +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; +import static org.elasticsearch.rest.RestRequest.Method.GET; +import static org.elasticsearch.rest.RestRequest.Method.POST; public class RestSimulatePipelineAction extends BaseRestHandler { - public RestSimulatePipelineAction(RestController controller) { - controller.registerHandler(RestRequest.Method.POST, "/_ingest/pipeline/{id}/_simulate", this); - controller.registerHandler(RestRequest.Method.GET, "/_ingest/pipeline/{id}/_simulate", this); - controller.registerHandler(RestRequest.Method.POST, "/_ingest/pipeline/_simulate", this); - controller.registerHandler(RestRequest.Method.GET, "/_ingest/pipeline/_simulate", this); + @Override + public List routes() { + return unmodifiableList(asList( + new Route(GET, "/_ingest/pipeline/{id}/_simulate"), + new Route(POST, "/_ingest/pipeline/{id}/_simulate"), + new Route(GET, "/_ingest/pipeline/_simulate"), + new Route(POST, "/_ingest/pipeline/_simulate"))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/search/RestClearScrollAction.java b/server/src/main/java/org/elasticsearch/rest/action/search/RestClearScrollAction.java index a8c69867a57fd..90e8f95227ceb 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/search/RestClearScrollAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/search/RestClearScrollAction.java @@ -23,19 +23,23 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.Strings; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestStatusToXContentListener; import java.io.IOException; -import java.util.Arrays; +import java.util.List; +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.rest.RestRequest.Method.DELETE; public class RestClearScrollAction extends BaseRestHandler { - public RestClearScrollAction(RestController controller) { - controller.registerHandler(DELETE, "/_search/scroll", this); - controller.registerHandler(DELETE, "/_search/scroll/{scroll_id}", this); + + @Override + public List routes() { + return unmodifiableList(asList( + new Route(DELETE, "/_search/scroll"), + new Route(DELETE, "/_search/scroll/{scroll_id}"))); } @Override @@ -47,7 +51,7 @@ public String getName() { public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException { String scrollIds = request.param("scroll_id"); ClearScrollRequest clearRequest = new ClearScrollRequest(); - clearRequest.setScrollIds(Arrays.asList(Strings.splitStringByCommaToArray(scrollIds))); + clearRequest.setScrollIds(asList(Strings.splitStringByCommaToArray(scrollIds))); request.withContentOrSourceParamParserOrNull((xContentParser -> { if (xContentParser != null) { // NOTE: if rest request with xcontent body has request parameters, values parsed from request body have the precedence diff --git a/server/src/main/java/org/elasticsearch/rest/action/search/RestCountAction.java b/server/src/main/java/org/elasticsearch/rest/action/search/RestCountAction.java index 912d2f531ae85..760360dc3c119 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/search/RestCountAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/search/RestCountAction.java @@ -30,7 +30,6 @@ import org.elasticsearch.index.query.QueryBuilder; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.action.RestActions; @@ -38,7 +37,10 @@ import org.elasticsearch.search.builder.SearchSourceBuilder; import java.io.IOException; +import java.util.List; +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.rest.RestRequest.Method.GET; import static org.elasticsearch.rest.RestRequest.Method.POST; import static org.elasticsearch.rest.action.RestActions.buildBroadcastShardsHeader; @@ -50,15 +52,16 @@ public class RestCountAction extends BaseRestHandler { static final String TYPES_DEPRECATION_MESSAGE = "[types removal]" + " Specifying types in count requests is deprecated."; - public RestCountAction(RestController controller) { - controller.registerHandler(POST, "/_count", this); - controller.registerHandler(GET, "/_count", this); - controller.registerHandler(POST, "/{index}/_count", this); - controller.registerHandler(GET, "/{index}/_count", this); - - // Deprecated typed endpoints. - controller.registerHandler(POST, "/{index}/{type}/_count", this); - controller.registerHandler(GET, "/{index}/{type}/_count", this); + @Override + public List routes() { + return unmodifiableList(asList( + new Route(GET, "/_count"), + new Route(POST, "/_count"), + new Route(GET, "/{index}/_count"), + new Route(POST, "/{index}/_count"), + // Deprecated typed endpoints. + new Route(GET, "/{index}/{type}/_count"), + new Route(POST, "/{index}/{type}/_count"))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/search/RestExplainAction.java b/server/src/main/java/org/elasticsearch/rest/action/search/RestExplainAction.java index bcaea4e65f0b5..95f5519c8e714 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/search/RestExplainAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/search/RestExplainAction.java @@ -26,14 +26,16 @@ import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.index.query.QueryBuilder; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestActions; import org.elasticsearch.rest.action.RestStatusToXContentListener; import org.elasticsearch.search.fetch.subphase.FetchSourceContext; import java.io.IOException; +import java.util.List; +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.rest.RestRequest.Method.GET; import static org.elasticsearch.rest.RestRequest.Method.POST; @@ -46,13 +48,14 @@ public class RestExplainAction extends BaseRestHandler { public static final String TYPES_DEPRECATION_MESSAGE = "[types removal] " + "Specifying a type in explain requests is deprecated."; - public RestExplainAction(RestController controller) { - controller.registerHandler(GET, "/{index}/_explain/{id}", this); - controller.registerHandler(POST, "/{index}/_explain/{id}", this); - - // Deprecated typed endpoints. - controller.registerHandler(GET, "/{index}/{type}/{id}/_explain", this); - controller.registerHandler(POST, "/{index}/{type}/{id}/_explain", this); + @Override + public List routes() { + return unmodifiableList(asList( + new Route(GET, "/{index}/_explain/{id}"), + new Route(POST, "/{index}/_explain/{id}"), + // Deprecated typed endpoints. + new Route(GET, "/{index}/{type}/{id}/_explain"), + new Route(POST, "/{index}/{type}/{id}/_explain"))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/search/RestMultiSearchAction.java b/server/src/main/java/org/elasticsearch/rest/action/search/RestMultiSearchAction.java index adc9c31aafc7f..e74ac69f8799a 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/search/RestMultiSearchAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/search/RestMultiSearchAction.java @@ -34,7 +34,6 @@ import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.search.builder.SearchSourceBuilder; @@ -46,6 +45,8 @@ import java.util.List; import java.util.Set; +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.rest.RestRequest.Method.GET; import static org.elasticsearch.rest.RestRequest.Method.POST; @@ -66,19 +67,22 @@ public class RestMultiSearchAction extends BaseRestHandler { private final boolean allowExplicitIndex; - public RestMultiSearchAction(Settings settings, RestController controller) { - controller.registerHandler(GET, "/_msearch", this); - controller.registerHandler(POST, "/_msearch", this); - controller.registerHandler(GET, "/{index}/_msearch", this); - controller.registerHandler(POST, "/{index}/_msearch", this); - - // Deprecated typed endpoints. - controller.registerHandler(GET, "/{index}/{type}/_msearch", this); - controller.registerHandler(POST, "/{index}/{type}/_msearch", this); - + public RestMultiSearchAction(Settings settings) { this.allowExplicitIndex = MULTI_ALLOW_EXPLICIT_INDEX.get(settings); } + @Override + public List routes() { + return unmodifiableList(asList( + new Route(GET, "/_msearch"), + new Route(POST, "/_msearch"), + new Route(GET, "/{index}/_msearch"), + new Route(POST, "/{index}/_msearch"), + // Deprecated typed endpoints. + new Route(GET, "/{index}/{type}/_msearch"), + new Route(POST, "/{index}/{type}/_msearch"))); + } + @Override public String getName() { return "msearch_action"; diff --git a/server/src/main/java/org/elasticsearch/rest/action/search/RestSearchAction.java b/server/src/main/java/org/elasticsearch/rest/action/search/RestSearchAction.java index 8f4e052e8d3da..494c171a93de0 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/search/RestSearchAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/search/RestSearchAction.java @@ -30,7 +30,6 @@ import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.index.query.QueryBuilder; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestActions; import org.elasticsearch.rest.action.RestCancellableNodeClient; @@ -48,9 +47,12 @@ import java.util.Arrays; import java.util.Collections; import java.util.HashSet; +import java.util.List; import java.util.Set; import java.util.function.IntConsumer; +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.common.unit.TimeValue.parseTimeValue; import static org.elasticsearch.rest.RestRequest.Method.GET; import static org.elasticsearch.rest.RestRequest.Method.POST; @@ -74,22 +76,23 @@ public class RestSearchAction extends BaseRestHandler { public static final String TYPES_DEPRECATION_MESSAGE = "[types removal]" + " Specifying types in search requests is deprecated."; - public RestSearchAction(RestController controller) { - controller.registerHandler(GET, "/_search", this); - controller.registerHandler(POST, "/_search", this); - controller.registerHandler(GET, "/{index}/_search", this); - controller.registerHandler(POST, "/{index}/_search", this); - - // Deprecated typed endpoints. - controller.registerHandler(GET, "/{index}/{type}/_search", this); - controller.registerHandler(POST, "/{index}/{type}/_search", this); - } - @Override public String getName() { return "search_action"; } + @Override + public List routes() { + return unmodifiableList(asList( + new Route(GET, "/_search"), + new Route(POST, "/_search"), + new Route(GET, "/{index}/_search"), + new Route(POST, "/{index}/_search"), + // Deprecated typed endpoints. + new Route(GET, "/{index}/{type}/_search"), + new Route(POST, "/{index}/{type}/_search"))); + } + @Override public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException { SearchRequest searchRequest = new SearchRequest(); diff --git a/server/src/main/java/org/elasticsearch/rest/action/search/RestSearchScrollAction.java b/server/src/main/java/org/elasticsearch/rest/action/search/RestSearchScrollAction.java index 0b49048dee906..6060574a7dbc7 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/search/RestSearchScrollAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/search/RestSearchScrollAction.java @@ -22,15 +22,17 @@ import org.elasticsearch.action.search.SearchScrollRequest; import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestStatusToXContentListener; import org.elasticsearch.search.Scroll; import java.io.IOException; import java.util.Collections; +import java.util.List; import java.util.Set; +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.common.unit.TimeValue.parseTimeValue; import static org.elasticsearch.rest.RestRequest.Method.GET; import static org.elasticsearch.rest.RestRequest.Method.POST; @@ -38,18 +40,20 @@ public class RestSearchScrollAction extends BaseRestHandler { private static final Set RESPONSE_PARAMS = Collections.singleton(RestSearchAction.TOTAL_HITS_AS_INT_PARAM); - public RestSearchScrollAction(RestController controller) { - controller.registerHandler(GET, "/_search/scroll", this); - controller.registerHandler(POST, "/_search/scroll", this); - controller.registerHandler(GET, "/_search/scroll/{scroll_id}", this); - controller.registerHandler(POST, "/_search/scroll/{scroll_id}", this); - } - @Override public String getName() { return "search_scroll_action"; } + @Override + public List routes() { + return unmodifiableList(asList( + new Route(GET, "/_search/scroll"), + new Route(POST, "/_search/scroll"), + new Route(GET, "/_search/scroll/{scroll_id}"), + new Route(POST, "/_search/scroll/{scroll_id}"))); + } + @Override public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException { String scrollId = request.param("scroll_id"); diff --git a/server/src/test/java/org/elasticsearch/action/ActionModuleTests.java b/server/src/test/java/org/elasticsearch/action/ActionModuleTests.java index 7ee6d1f024c4d..d5299410e8357 100644 --- a/server/src/test/java/org/elasticsearch/action/ActionModuleTests.java +++ b/server/src/test/java/org/elasticsearch/action/ActionModuleTests.java @@ -113,7 +113,16 @@ public void testSetupRestHandlerContainsKnownBuiltin() { actionModule.initRestHandlers(null); // At this point the easiest way to confirm that a handler is loaded is to try to register another one on top of it and to fail Exception e = expectThrows(IllegalArgumentException.class, () -> - actionModule.getRestController().registerHandler(Method.GET, "/", null)); + actionModule.getRestController().registerHandler(new RestHandler() { + @Override + public void handleRequest(RestRequest request, RestChannel channel, NodeClient client) throws Exception { + } + + @Override + public List routes() { + return singletonList(new Route(Method.GET, "/")); + } + })); assertThat(e.getMessage(), startsWith("Cannot replace existing handler for [/] for method: GET")); } @@ -123,7 +132,7 @@ public void testPluginCantOverwriteBuiltinRestHandler() throws IOException { public List getRestHandlers(Settings settings, RestController restController, ClusterSettings clusterSettings, IndexScopedSettings indexScopedSettings, SettingsFilter settingsFilter, IndexNameExpressionResolver indexNameExpressionResolver, Supplier nodesInCluster) { - return singletonList(new RestMainAction(restController)); + return singletonList(new RestMainAction()); } }; SettingsModule settings = new SettingsModule(Settings.EMPTY); @@ -142,9 +151,11 @@ public List getRestHandlers(Settings settings, RestController restC public void testPluginCanRegisterRestHandler() { class FakeHandler implements RestHandler { - FakeHandler(RestController restController) { - restController.registerHandler(Method.GET, "/_dummy", this); + @Override + public List routes() { + return singletonList(new Route(Method.GET, "/_dummy")); } + @Override public void handleRequest(RestRequest request, RestChannel channel, NodeClient client) throws Exception { } @@ -154,7 +165,7 @@ public void handleRequest(RestRequest request, RestChannel channel, NodeClient c public List getRestHandlers(Settings settings, RestController restController, ClusterSettings clusterSettings, IndexScopedSettings indexScopedSettings, SettingsFilter settingsFilter, IndexNameExpressionResolver indexNameExpressionResolver, Supplier nodesInCluster) { - return singletonList(new FakeHandler(restController)); + return singletonList(new FakeHandler()); } }; @@ -168,7 +179,16 @@ public List getRestHandlers(Settings settings, RestController restC actionModule.initRestHandlers(null); // At this point the easiest way to confirm that a handler is loaded is to try to register another one on top of it and to fail Exception e = expectThrows(IllegalArgumentException.class, () -> - actionModule.getRestController().registerHandler(Method.GET, "/_dummy", null)); + actionModule.getRestController().registerHandler(new RestHandler() { + @Override + public void handleRequest(RestRequest request, RestChannel channel, NodeClient client) throws Exception { + } + + @Override + public List routes() { + return singletonList(new Route(Method.GET, "/_dummy")); + } + })); assertThat(e.getMessage(), startsWith("Cannot replace existing handler for [/_dummy] for method: GET")); } finally { threadPool.shutdown(); diff --git a/server/src/test/java/org/elasticsearch/action/admin/indices/forcemerge/RestForceMergeActionTests.java b/server/src/test/java/org/elasticsearch/action/admin/indices/forcemerge/RestForceMergeActionTests.java index a80ca1a83b2ce..0c596c1063468 100644 --- a/server/src/test/java/org/elasticsearch/action/admin/indices/forcemerge/RestForceMergeActionTests.java +++ b/server/src/test/java/org/elasticsearch/action/admin/indices/forcemerge/RestForceMergeActionTests.java @@ -24,7 +24,6 @@ import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.common.xcontent.json.JsonXContent; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.admin.indices.RestForceMergeAction; import org.elasticsearch.test.rest.FakeRestChannel; @@ -42,11 +41,11 @@ public class RestForceMergeActionTests extends RestActionTestCase { @Before public void setUpAction() { - new RestForceMergeAction(controller()); + controller().registerHandler(new RestForceMergeAction()); } public void testBodyRejection() throws Exception { - final RestForceMergeAction handler = new RestForceMergeAction(mock(RestController.class)); + final RestForceMergeAction handler = new RestForceMergeAction(); String json = JsonXContent.contentBuilder().startObject().field("max_num_segments", 1).endObject().toString(); final FakeRestRequest request = new FakeRestRequest.Builder(NamedXContentRegistry.EMPTY) .withContent(new BytesArray(json), XContentType.JSON) diff --git a/server/src/test/java/org/elasticsearch/rest/BaseRestHandlerTests.java b/server/src/test/java/org/elasticsearch/rest/BaseRestHandlerTests.java index 66badef0cefc5..c412af527507f 100644 --- a/server/src/test/java/org/elasticsearch/rest/BaseRestHandlerTests.java +++ b/server/src/test/java/org/elasticsearch/rest/BaseRestHandlerTests.java @@ -33,6 +33,7 @@ import java.io.IOException; import java.util.Collections; import java.util.HashMap; +import java.util.List; import java.util.Set; import java.util.concurrent.atomic.AtomicBoolean; @@ -55,6 +56,11 @@ protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient cli public String getName() { return "test_one_unconsumed_response_action"; } + + @Override + public List routes() { + return Collections.emptyList(); + } }; final HashMap params = new HashMap<>(); @@ -81,6 +87,11 @@ protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient cli public String getName() { return "test_multiple_unconsumed_response_action"; } + + @Override + public List routes() { + return Collections.emptyList(); + } }; final HashMap params = new HashMap<>(); @@ -117,6 +128,11 @@ protected Set responseParams() { public String getName() { return "test_unconsumed_did_you_mean_response_action"; } + + @Override + public List routes() { + return Collections.emptyList(); + } }; final HashMap params = new HashMap<>(); @@ -160,6 +176,11 @@ protected Set responseParams() { public String getName() { return "test_unconsumed_response_action"; } + + @Override + public List routes() { + return Collections.emptyList(); + } }; final HashMap params = new HashMap<>(); @@ -183,6 +204,11 @@ protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient cli public String getName() { return "test_default_response_action"; } + + @Override + public List routes() { + return Collections.emptyList(); + } }; final HashMap params = new HashMap<>(); @@ -218,6 +244,11 @@ protected Table getTableWithHeader(RestRequest request) { public String getName() { return "test_cat_response_action"; } + + @Override + public List routes() { + return Collections.emptyList(); + } }; final HashMap params = new HashMap<>(); @@ -249,6 +280,10 @@ public String getName() { return "test_consumed_body"; } + @Override + public List routes() { + return Collections.emptyList(); + } }; try (XContentBuilder builder = JsonXContent.contentBuilder().startObject().endObject()) { @@ -274,6 +309,10 @@ public String getName() { return "test_unconsumed_body"; } + @Override + public List routes() { + return Collections.emptyList(); + } }; final RestRequest request = new FakeRestRequest.Builder(xContentRegistry()).build(); @@ -295,6 +334,10 @@ public String getName() { return "test_unconsumed_body"; } + @Override + public List routes() { + return Collections.emptyList(); + } }; try (XContentBuilder builder = JsonXContent.contentBuilder().startObject().endObject()) { diff --git a/server/src/test/java/org/elasticsearch/rest/RestControllerTests.java b/server/src/test/java/org/elasticsearch/rest/RestControllerTests.java index 4495a057e4df5..fb7c9dfcc5327 100644 --- a/server/src/test/java/org/elasticsearch/rest/RestControllerTests.java +++ b/server/src/test/java/org/elasticsearch/rest/RestControllerTests.java @@ -249,27 +249,6 @@ public void testRestHandlerWrapper() throws Exception { assertFalse(handlerCalled.get()); } - /** - * Useful for testing with deprecation handler. - */ - private static class FakeRestHandler implements RestHandler { - private final boolean canTripCircuitBreaker; - - private FakeRestHandler(boolean canTripCircuitBreaker) { - this.canTripCircuitBreaker = canTripCircuitBreaker; - } - - @Override - public void handleRequest(RestRequest request, RestChannel channel, NodeClient client) throws Exception { - //no op - } - - @Override - public boolean canTripCircuitBreaker() { - return canTripCircuitBreaker; - } - } - public void testDispatchRequestAddsAndFreesBytesOnSuccess() { int contentLength = BREAKER_LIMIT.bytesAsInt(); String content = randomAlphaOfLength((int) Math.round(contentLength / inFlightRequestsBreaker.getOverhead())); diff --git a/server/src/test/java/org/elasticsearch/rest/action/admin/cluster/RestAddVotingConfigExclusionActionTests.java b/server/src/test/java/org/elasticsearch/rest/action/admin/cluster/RestAddVotingConfigExclusionActionTests.java index c686497922346..538c57b035e01 100644 --- a/server/src/test/java/org/elasticsearch/rest/action/admin/cluster/RestAddVotingConfigExclusionActionTests.java +++ b/server/src/test/java/org/elasticsearch/rest/action/admin/cluster/RestAddVotingConfigExclusionActionTests.java @@ -34,7 +34,8 @@ public class RestAddVotingConfigExclusionActionTests extends RestActionTestCase @Before public void setupAction() { - action = new RestAddVotingConfigExclusionAction(controller()); + action = new RestAddVotingConfigExclusionAction(); + controller().registerHandler(action); } public void testResolveVotingConfigExclusionsRequest() { diff --git a/server/src/test/java/org/elasticsearch/rest/action/admin/cluster/RestNodesStatsActionTests.java b/server/src/test/java/org/elasticsearch/rest/action/admin/cluster/RestNodesStatsActionTests.java index 93203b774ec36..aa4fe725e0e03 100644 --- a/server/src/test/java/org/elasticsearch/rest/action/admin/cluster/RestNodesStatsActionTests.java +++ b/server/src/test/java/org/elasticsearch/rest/action/admin/cluster/RestNodesStatsActionTests.java @@ -20,14 +20,11 @@ package org.elasticsearch.rest.action.admin.cluster; import org.elasticsearch.client.node.NodeClient; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.rest.FakeRestRequest; -import org.elasticsearch.usage.UsageService; import java.io.IOException; -import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.Set; @@ -43,9 +40,7 @@ public class RestNodesStatsActionTests extends ESTestCase { @Override public void setUp() throws Exception { super.setUp(); - UsageService usageService = new UsageService(); - action = new RestNodesStatsAction( - new RestController(Collections.emptySet(), null, null, null, usageService)); + action = new RestNodesStatsAction(); } public void testUnrecognizedMetric() throws IOException { diff --git a/server/src/test/java/org/elasticsearch/rest/action/admin/indices/RestAnalyzeActionTests.java b/server/src/test/java/org/elasticsearch/rest/action/admin/indices/RestAnalyzeActionTests.java index 3956178587dd0..8c3c9ae03cb2b 100644 --- a/server/src/test/java/org/elasticsearch/rest/action/admin/indices/RestAnalyzeActionTests.java +++ b/server/src/test/java/org/elasticsearch/rest/action/admin/indices/RestAnalyzeActionTests.java @@ -24,7 +24,6 @@ import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.index.analysis.NameOrDefinition; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.rest.FakeRestRequest; @@ -34,7 +33,6 @@ import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.notNullValue; -import static org.mockito.Mockito.mock; public class RestAnalyzeActionTests extends ESTestCase { @@ -94,7 +92,7 @@ public void testParseXContentForAnalyzeRequestWithCustomFilters() throws Excepti } public void testParseXContentForAnalyzeRequestWithInvalidJsonThrowsException() { - RestAnalyzeAction action = new RestAnalyzeAction(mock(RestController.class)); + RestAnalyzeAction action = new RestAnalyzeAction(); RestRequest request = new FakeRestRequest.Builder(xContentRegistry()) .withContent(new BytesArray("{invalid_json}"), XContentType.JSON).build(); IOException e = expectThrows(IOException.class, () -> action.handleRequest(request, null, null)); diff --git a/server/src/test/java/org/elasticsearch/rest/action/admin/indices/RestCreateIndexActionTests.java b/server/src/test/java/org/elasticsearch/rest/action/admin/indices/RestCreateIndexActionTests.java index 7e63f36862ffd..eb15d0601b7bd 100644 --- a/server/src/test/java/org/elasticsearch/rest/action/admin/indices/RestCreateIndexActionTests.java +++ b/server/src/test/java/org/elasticsearch/rest/action/admin/indices/RestCreateIndexActionTests.java @@ -41,7 +41,8 @@ public class RestCreateIndexActionTests extends RestActionTestCase { @Before public void setupAction() { - action = new RestCreateIndexAction(controller()); + action = new RestCreateIndexAction(); + controller().registerHandler(action); } public void testIncludeTypeName() throws IOException { diff --git a/server/src/test/java/org/elasticsearch/rest/action/admin/indices/RestGetFieldMappingActionTests.java b/server/src/test/java/org/elasticsearch/rest/action/admin/indices/RestGetFieldMappingActionTests.java index fab3f2a8a7ead..31366654dd396 100644 --- a/server/src/test/java/org/elasticsearch/rest/action/admin/indices/RestGetFieldMappingActionTests.java +++ b/server/src/test/java/org/elasticsearch/rest/action/admin/indices/RestGetFieldMappingActionTests.java @@ -37,7 +37,7 @@ public class RestGetFieldMappingActionTests extends RestActionTestCase { @Before public void setUpAction() { - new RestGetFieldMappingAction(controller()); + controller().registerHandler(new RestGetFieldMappingAction()); } public void testIncludeTypeName() { diff --git a/server/src/test/java/org/elasticsearch/rest/action/admin/indices/RestGetIndicesActionTests.java b/server/src/test/java/org/elasticsearch/rest/action/admin/indices/RestGetIndicesActionTests.java index f35425332f388..271e1044237a8 100644 --- a/server/src/test/java/org/elasticsearch/rest/action/admin/indices/RestGetIndicesActionTests.java +++ b/server/src/test/java/org/elasticsearch/rest/action/admin/indices/RestGetIndicesActionTests.java @@ -20,7 +20,6 @@ package org.elasticsearch.rest.action.admin.indices; import org.elasticsearch.client.node.NodeClient; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.test.rest.FakeRestRequest; import org.elasticsearch.test.rest.RestActionTestCase; @@ -46,7 +45,7 @@ public void testIncludeTypeNamesWarning() throws IOException { .withParams(params) .build(); - RestGetIndicesAction handler = new RestGetIndicesAction(mock(RestController.class)); + RestGetIndicesAction handler = new RestGetIndicesAction(); handler.prepareRequest(request, mock(NodeClient.class)); assertWarnings(RestGetIndicesAction.TYPES_DEPRECATION_MESSAGE); @@ -70,7 +69,7 @@ public void testIncludeTypeNamesWarningExists() throws IOException { .withParams(params) .build(); - RestGetIndicesAction handler = new RestGetIndicesAction(mock(RestController.class)); + RestGetIndicesAction handler = new RestGetIndicesAction(); handler.prepareRequest(request, mock(NodeClient.class)); } } diff --git a/server/src/test/java/org/elasticsearch/rest/action/admin/indices/RestGetMappingActionTests.java b/server/src/test/java/org/elasticsearch/rest/action/admin/indices/RestGetMappingActionTests.java index 624491b2e42d7..ba8f35630fbd4 100644 --- a/server/src/test/java/org/elasticsearch/rest/action/admin/indices/RestGetMappingActionTests.java +++ b/server/src/test/java/org/elasticsearch/rest/action/admin/indices/RestGetMappingActionTests.java @@ -22,7 +22,6 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.util.concurrent.ThreadContext; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestStatus; import org.elasticsearch.test.rest.FakeRestChannel; @@ -40,7 +39,7 @@ public class RestGetMappingActionTests extends RestActionTestCase { @Before public void setUpAction() { - new RestGetMappingAction(controller()); + controller().registerHandler(new RestGetMappingAction()); } public void testTypeExistsDeprecation() throws Exception { @@ -51,7 +50,7 @@ public void testTypeExistsDeprecation() throws Exception { .withParams(params) .build(); - RestGetMappingAction handler = new RestGetMappingAction(mock(RestController.class)); + RestGetMappingAction handler = new RestGetMappingAction(); handler.prepareRequest(request, mock(NodeClient.class)); assertWarnings("Type exists requests are deprecated, as types have been deprecated."); diff --git a/server/src/test/java/org/elasticsearch/rest/action/admin/indices/RestIndicesStatsActionTests.java b/server/src/test/java/org/elasticsearch/rest/action/admin/indices/RestIndicesStatsActionTests.java index bdd3892e38131..6c6e2c3d4b1f0 100644 --- a/server/src/test/java/org/elasticsearch/rest/action/admin/indices/RestIndicesStatsActionTests.java +++ b/server/src/test/java/org/elasticsearch/rest/action/admin/indices/RestIndicesStatsActionTests.java @@ -20,14 +20,11 @@ package org.elasticsearch.rest.action.admin.indices; import org.elasticsearch.client.node.NodeClient; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.rest.FakeRestRequest; -import org.elasticsearch.usage.UsageService; import java.io.IOException; -import java.util.Collections; import java.util.HashMap; import static org.hamcrest.CoreMatchers.containsString; @@ -41,9 +38,7 @@ public class RestIndicesStatsActionTests extends ESTestCase { @Override public void setUp() throws Exception { super.setUp(); - UsageService usageService = new UsageService(); - action = new RestIndicesStatsAction( - new RestController(Collections.emptySet(), null, null, null, usageService)); + action = new RestIndicesStatsAction(); } public void testUnrecognizedMetric() throws IOException { diff --git a/server/src/test/java/org/elasticsearch/rest/action/admin/indices/RestPutIndexTemplateActionTests.java b/server/src/test/java/org/elasticsearch/rest/action/admin/indices/RestPutIndexTemplateActionTests.java index c81a0a53b4b18..8e18c78828a1f 100644 --- a/server/src/test/java/org/elasticsearch/rest/action/admin/indices/RestPutIndexTemplateActionTests.java +++ b/server/src/test/java/org/elasticsearch/rest/action/admin/indices/RestPutIndexTemplateActionTests.java @@ -41,7 +41,8 @@ public class RestPutIndexTemplateActionTests extends RestActionTestCase { @Before public void setUpAction() { - action = new RestPutIndexTemplateAction(controller()); + action = new RestPutIndexTemplateAction(); + controller().registerHandler(action); } public void testIncludeTypeName() throws IOException { diff --git a/server/src/test/java/org/elasticsearch/rest/action/admin/indices/RestPutMappingActionTests.java b/server/src/test/java/org/elasticsearch/rest/action/admin/indices/RestPutMappingActionTests.java index 8df69145c2fac..54492ac9c4892 100644 --- a/server/src/test/java/org/elasticsearch/rest/action/admin/indices/RestPutMappingActionTests.java +++ b/server/src/test/java/org/elasticsearch/rest/action/admin/indices/RestPutMappingActionTests.java @@ -37,7 +37,7 @@ public class RestPutMappingActionTests extends RestActionTestCase { @Before public void setUpAction() { - new RestPutMappingAction(controller()); + controller().registerHandler(new RestPutMappingAction()); } public void testIncludeTypeName() { diff --git a/server/src/test/java/org/elasticsearch/rest/action/admin/indices/RestResizeHandlerTests.java b/server/src/test/java/org/elasticsearch/rest/action/admin/indices/RestResizeHandlerTests.java index c989ee0d2f452..b277cb7d8fd72 100644 --- a/server/src/test/java/org/elasticsearch/rest/action/admin/indices/RestResizeHandlerTests.java +++ b/server/src/test/java/org/elasticsearch/rest/action/admin/indices/RestResizeHandlerTests.java @@ -21,7 +21,6 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.xcontent.NamedXContentRegistry; -import org.elasticsearch.rest.RestController; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.rest.FakeRestRequest; @@ -37,7 +36,7 @@ public class RestResizeHandlerTests extends ESTestCase { public void testShrinkCopySettingsDeprecated() throws IOException { final RestResizeHandler.RestShrinkIndexAction handler = - new RestResizeHandler.RestShrinkIndexAction(mock(RestController.class)); + new RestResizeHandler.RestShrinkIndexAction(); for (final String copySettings : new String[]{null, "", "true", "false"}) { runTestResizeCopySettingsDeprecated(handler, "shrink", copySettings); } @@ -45,7 +44,7 @@ public void testShrinkCopySettingsDeprecated() throws IOException { public void testSplitCopySettingsDeprecated() throws IOException { final RestResizeHandler.RestSplitIndexAction handler = - new RestResizeHandler.RestSplitIndexAction(mock(RestController.class)); + new RestResizeHandler.RestSplitIndexAction(); for (final String copySettings : new String[]{null, "", "true", "false"}) { runTestResizeCopySettingsDeprecated(handler, "split", copySettings); } diff --git a/server/src/test/java/org/elasticsearch/rest/action/admin/indices/RestValidateQueryActionTests.java b/server/src/test/java/org/elasticsearch/rest/action/admin/indices/RestValidateQueryActionTests.java index e1e66b503e791..63e6884a09343 100644 --- a/server/src/test/java/org/elasticsearch/rest/action/admin/indices/RestValidateQueryActionTests.java +++ b/server/src/test/java/org/elasticsearch/rest/action/admin/indices/RestValidateQueryActionTests.java @@ -61,7 +61,7 @@ public class RestValidateQueryActionTests extends AbstractSearchTestCase { private static UsageService usageService = new UsageService(); private static RestController controller = new RestController(emptySet(), null, client, new NoneCircuitBreakerService(), usageService); - private static RestValidateQueryAction action = new RestValidateQueryAction(controller); + private static RestValidateQueryAction action = new RestValidateQueryAction(); /** * Configures {@link NodeClient} to stub {@link ValidateQueryAction} transport action. @@ -83,6 +83,7 @@ protected void doExecute(Task task, ActionRequest request, ActionListener listen actions.put(ValidateQueryAction.INSTANCE, transportAction); client.initialize(actions, taskManager, () -> "local", null); + controller.registerHandler(action); } @AfterClass diff --git a/server/src/test/java/org/elasticsearch/rest/action/cat/RestIndicesActionTests.java b/server/src/test/java/org/elasticsearch/rest/action/cat/RestIndicesActionTests.java index 776129eb1d56a..aad58e50d69c9 100644 --- a/server/src/test/java/org/elasticsearch/rest/action/cat/RestIndicesActionTests.java +++ b/server/src/test/java/org/elasticsearch/rest/action/cat/RestIndicesActionTests.java @@ -128,7 +128,8 @@ public void testBuildTable() { } final RestController restController = new RestController(Collections.emptySet(), null, null, null, new UsageService()); - final RestIndicesAction action = new RestIndicesAction(restController); + final RestIndicesAction action = new RestIndicesAction(); + restController.registerHandler(action); final Table table = action.buildTable(new FakeRestRequest(), indicesSettings, indicesHealths, indicesStats, indicesMetaDatas); // now, verify the table is correct diff --git a/server/src/test/java/org/elasticsearch/rest/action/cat/RestNodesActionTests.java b/server/src/test/java/org/elasticsearch/rest/action/cat/RestNodesActionTests.java index 05b14d6b1cfc4..43b9bb4168324 100644 --- a/server/src/test/java/org/elasticsearch/rest/action/cat/RestNodesActionTests.java +++ b/server/src/test/java/org/elasticsearch/rest/action/cat/RestNodesActionTests.java @@ -29,11 +29,9 @@ import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodes; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.rest.RestController; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.rest.FakeRestRequest; import org.elasticsearch.threadpool.TestThreadPool; -import org.elasticsearch.usage.UsageService; import org.junit.Before; import java.util.Collections; @@ -49,9 +47,7 @@ public class RestNodesActionTests extends ESTestCase { @Before public void setUpAction() { - UsageService usageService = new UsageService(); - action = new RestNodesAction( - new RestController(Collections.emptySet(), null, null, null, usageService)); + action = new RestNodesAction(); } public void testBuildTableDoesNotThrowGivenNullNodeInfoAndStats() { diff --git a/server/src/test/java/org/elasticsearch/rest/action/cat/RestRecoveryActionTests.java b/server/src/test/java/org/elasticsearch/rest/action/cat/RestRecoveryActionTests.java index 30e85230a4f68..9f8ab08ed0def 100644 --- a/server/src/test/java/org/elasticsearch/rest/action/cat/RestRecoveryActionTests.java +++ b/server/src/test/java/org/elasticsearch/rest/action/cat/RestRecoveryActionTests.java @@ -56,7 +56,8 @@ public void testRestRecoveryAction() { final Settings settings = Settings.EMPTY; UsageService usageService = new UsageService(); final RestController restController = new RestController(Collections.emptySet(), null, null, null, usageService); - final RestCatRecoveryAction action = new RestCatRecoveryAction(restController); + final RestCatRecoveryAction action = new RestCatRecoveryAction(); + restController.registerHandler(action); final int totalShards = randomIntBetween(1, 32); final int successfulShards = Math.max(0, totalShards - randomIntBetween(1, 2)); final int failedShards = totalShards - successfulShards; diff --git a/server/src/test/java/org/elasticsearch/rest/action/document/RestBulkActionTests.java b/server/src/test/java/org/elasticsearch/rest/action/document/RestBulkActionTests.java index b19c8c6412abc..fabd9e36051f8 100644 --- a/server/src/test/java/org/elasticsearch/rest/action/document/RestBulkActionTests.java +++ b/server/src/test/java/org/elasticsearch/rest/action/document/RestBulkActionTests.java @@ -19,8 +19,6 @@ package org.elasticsearch.rest.action.document; -import java.util.HashMap; -import java.util.Map; import org.elasticsearch.Version; import org.elasticsearch.action.bulk.BulkRequest; import org.elasticsearch.action.update.UpdateRequest; @@ -28,13 +26,15 @@ import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.rest.RestChannel; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.rest.FakeRestRequest; import org.hamcrest.CustomMatcher; import org.mockito.Mockito; +import java.util.HashMap; +import java.util.Map; + import static org.mockito.Matchers.any; import static org.mockito.Matchers.argThat; import static org.mockito.Mockito.mock; @@ -48,7 +48,7 @@ public void testBulkPipelineUpsert() throws Exception { final NodeClient mockClient = mock(NodeClient.class); final Map params = new HashMap<>(); params.put("pipeline", "timestamps"); - new RestBulkAction(settings(Version.CURRENT).build(), mock(RestController.class)) + new RestBulkAction(settings(Version.CURRENT).build()) .handleRequest( new FakeRestRequest.Builder( xContentRegistry()).withPath("my_index/_bulk").withParams(params) diff --git a/server/src/test/java/org/elasticsearch/rest/action/document/RestDeleteActionTests.java b/server/src/test/java/org/elasticsearch/rest/action/document/RestDeleteActionTests.java index d95af547e8da1..4c1c1a81e50c4 100644 --- a/server/src/test/java/org/elasticsearch/rest/action/document/RestDeleteActionTests.java +++ b/server/src/test/java/org/elasticsearch/rest/action/document/RestDeleteActionTests.java @@ -29,7 +29,7 @@ public class RestDeleteActionTests extends RestActionTestCase { @Before public void setUpAction() { - new RestDeleteAction(controller()); + controller().registerHandler(new RestDeleteAction()); } public void testTypeInPath() { diff --git a/server/src/test/java/org/elasticsearch/rest/action/document/RestGetActionTests.java b/server/src/test/java/org/elasticsearch/rest/action/document/RestGetActionTests.java index 494e5cf9fb2d6..98a7adc839b44 100644 --- a/server/src/test/java/org/elasticsearch/rest/action/document/RestGetActionTests.java +++ b/server/src/test/java/org/elasticsearch/rest/action/document/RestGetActionTests.java @@ -28,7 +28,7 @@ public class RestGetActionTests extends RestActionTestCase { @Before public void setUpAction() { - new RestGetAction(controller()); + controller().registerHandler(new RestGetAction()); } public void testTypeInPathWithGet() { diff --git a/server/src/test/java/org/elasticsearch/rest/action/document/RestGetSourceActionTests.java b/server/src/test/java/org/elasticsearch/rest/action/document/RestGetSourceActionTests.java index a42cfce31b5c9..7867348cb423d 100644 --- a/server/src/test/java/org/elasticsearch/rest/action/document/RestGetSourceActionTests.java +++ b/server/src/test/java/org/elasticsearch/rest/action/document/RestGetSourceActionTests.java @@ -51,7 +51,7 @@ public class RestGetSourceActionTests extends RestActionTestCase { @Before public void setUpAction() { - new RestGetSourceAction(controller()); + controller().registerHandler(new RestGetSourceAction()); } @AfterClass diff --git a/server/src/test/java/org/elasticsearch/rest/action/document/RestIndexActionTests.java b/server/src/test/java/org/elasticsearch/rest/action/document/RestIndexActionTests.java index 71e30dcfa0c86..9e0781aa66208 100644 --- a/server/src/test/java/org/elasticsearch/rest/action/document/RestIndexActionTests.java +++ b/server/src/test/java/org/elasticsearch/rest/action/document/RestIndexActionTests.java @@ -31,6 +31,8 @@ import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.rest.RestRequest; +import org.elasticsearch.rest.action.document.RestIndexAction.AutoIdHandler; +import org.elasticsearch.rest.action.document.RestIndexAction.CreateHandler; import org.elasticsearch.test.VersionUtils; import org.elasticsearch.test.rest.FakeRestRequest; import org.elasticsearch.test.rest.RestActionTestCase; @@ -47,14 +49,15 @@ public class RestIndexActionTests extends RestActionTestCase { - private RestIndexAction action; - private final AtomicReference clusterStateSupplier = new AtomicReference(); + private final AtomicReference clusterStateSupplier = new AtomicReference<>(); @Before public void setUpAction() { ClusterService clusterService = mock(ClusterService.class); when(clusterService.state()).thenAnswer(invocationOnMock -> clusterStateSupplier.get()); - action = new RestIndexAction(controller(), clusterService); + controller().registerHandler(new RestIndexAction()); + controller().registerHandler(new CreateHandler()); + controller().registerHandler(new AutoIdHandler(clusterService)); } public void testTypeInPath() { @@ -88,7 +91,7 @@ public void testCreateWithTypeInPath() { } public void testCreateOpTypeValidation() { - RestIndexAction.CreateHandler create = action.new CreateHandler(); + RestIndexAction.CreateHandler create = new CreateHandler(); String opType = randomFrom("CREATE", null); create.validateOpType(opType); diff --git a/server/src/test/java/org/elasticsearch/rest/action/document/RestMultiGetActionTests.java b/server/src/test/java/org/elasticsearch/rest/action/document/RestMultiGetActionTests.java index da5c7e1fdfd6d..2e4dcf96f96ef 100644 --- a/server/src/test/java/org/elasticsearch/rest/action/document/RestMultiGetActionTests.java +++ b/server/src/test/java/org/elasticsearch/rest/action/document/RestMultiGetActionTests.java @@ -34,7 +34,7 @@ public class RestMultiGetActionTests extends RestActionTestCase { @Before public void setUpAction() { - new RestMultiGetAction(Settings.EMPTY, controller()); + controller().registerHandler(new RestMultiGetAction(Settings.EMPTY)); } public void testTypeInPath() { diff --git a/server/src/test/java/org/elasticsearch/rest/action/document/RestMultiTermVectorsActionTests.java b/server/src/test/java/org/elasticsearch/rest/action/document/RestMultiTermVectorsActionTests.java index ed9756e406789..10858ab6b6896 100644 --- a/server/src/test/java/org/elasticsearch/rest/action/document/RestMultiTermVectorsActionTests.java +++ b/server/src/test/java/org/elasticsearch/rest/action/document/RestMultiTermVectorsActionTests.java @@ -37,7 +37,7 @@ public class RestMultiTermVectorsActionTests extends RestActionTestCase { @Before public void setUpAction() { - new RestMultiTermVectorsAction(controller()); + controller().registerHandler(new RestMultiTermVectorsAction()); } public void testTypeInPath() { diff --git a/server/src/test/java/org/elasticsearch/rest/action/document/RestTermVectorsActionTests.java b/server/src/test/java/org/elasticsearch/rest/action/document/RestTermVectorsActionTests.java index fbe1ace7383d3..94dac907b673a 100644 --- a/server/src/test/java/org/elasticsearch/rest/action/document/RestTermVectorsActionTests.java +++ b/server/src/test/java/org/elasticsearch/rest/action/document/RestTermVectorsActionTests.java @@ -35,7 +35,7 @@ public class RestTermVectorsActionTests extends RestActionTestCase { @Before public void setUpAction() { - new RestTermVectorsAction(controller()); + controller().registerHandler(new RestTermVectorsAction()); } public void testTypeInPath() { diff --git a/server/src/test/java/org/elasticsearch/rest/action/document/RestUpdateActionTests.java b/server/src/test/java/org/elasticsearch/rest/action/document/RestUpdateActionTests.java index 639cbcde5621a..c9bda4e76a2d9 100644 --- a/server/src/test/java/org/elasticsearch/rest/action/document/RestUpdateActionTests.java +++ b/server/src/test/java/org/elasticsearch/rest/action/document/RestUpdateActionTests.java @@ -42,7 +42,8 @@ public class RestUpdateActionTests extends RestActionTestCase { @Before public void setUpAction() { - action = new RestUpdateAction(controller()); + action = new RestUpdateAction(); + controller().registerHandler(action); } public void testTypeInPath() { diff --git a/server/src/test/java/org/elasticsearch/rest/action/search/RestCountActionTests.java b/server/src/test/java/org/elasticsearch/rest/action/search/RestCountActionTests.java index 26679c143406d..679a604041443 100644 --- a/server/src/test/java/org/elasticsearch/rest/action/search/RestCountActionTests.java +++ b/server/src/test/java/org/elasticsearch/rest/action/search/RestCountActionTests.java @@ -32,7 +32,7 @@ public class RestCountActionTests extends RestActionTestCase { @Before public void setUpAction() { - new RestCountAction(controller()); + controller().registerHandler(new RestCountAction()); } public void testTypeInPath() { diff --git a/server/src/test/java/org/elasticsearch/rest/action/search/RestExplainActionTests.java b/server/src/test/java/org/elasticsearch/rest/action/search/RestExplainActionTests.java index c2f5acd1e1fa6..182a566ee0a74 100644 --- a/server/src/test/java/org/elasticsearch/rest/action/search/RestExplainActionTests.java +++ b/server/src/test/java/org/elasticsearch/rest/action/search/RestExplainActionTests.java @@ -28,7 +28,7 @@ public class RestExplainActionTests extends RestActionTestCase { @Before public void setUpAction() { - new RestExplainAction(controller()); + controller().registerHandler(new RestExplainAction()); } public void testTypeInPath() { diff --git a/server/src/test/java/org/elasticsearch/rest/action/search/RestMultiSearchActionTests.java b/server/src/test/java/org/elasticsearch/rest/action/search/RestMultiSearchActionTests.java index 3b80d2002c5c5..65c78c6e63429 100644 --- a/server/src/test/java/org/elasticsearch/rest/action/search/RestMultiSearchActionTests.java +++ b/server/src/test/java/org/elasticsearch/rest/action/search/RestMultiSearchActionTests.java @@ -33,7 +33,7 @@ public class RestMultiSearchActionTests extends RestActionTestCase { @Before public void setUpAction() { - new RestMultiSearchAction(Settings.EMPTY, controller()); + controller().registerHandler(new RestMultiSearchAction(Settings.EMPTY)); } public void testTypeInPath() { diff --git a/server/src/test/java/org/elasticsearch/rest/action/search/RestSearchActionTests.java b/server/src/test/java/org/elasticsearch/rest/action/search/RestSearchActionTests.java index 0448ed666addf..a875fd410fabd 100644 --- a/server/src/test/java/org/elasticsearch/rest/action/search/RestSearchActionTests.java +++ b/server/src/test/java/org/elasticsearch/rest/action/search/RestSearchActionTests.java @@ -31,7 +31,7 @@ public class RestSearchActionTests extends RestActionTestCase { @Before public void setUpAction() { - new RestSearchAction(controller()); + controller().registerHandler(new RestSearchAction()); } public void testTypeInPath() { diff --git a/server/src/test/java/org/elasticsearch/search/scroll/RestClearScrollActionTests.java b/server/src/test/java/org/elasticsearch/search/scroll/RestClearScrollActionTests.java index 8642b2648146e..03e9a242d35c0 100644 --- a/server/src/test/java/org/elasticsearch/search/scroll/RestClearScrollActionTests.java +++ b/server/src/test/java/org/elasticsearch/search/scroll/RestClearScrollActionTests.java @@ -23,7 +23,6 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.xcontent.XContentType; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.search.RestClearScrollAction; import org.elasticsearch.test.ESTestCase; @@ -44,7 +43,7 @@ public class RestClearScrollActionTests extends ESTestCase { public void testParseClearScrollRequestWithInvalidJsonThrowsException() throws Exception { - RestClearScrollAction action = new RestClearScrollAction(mock(RestController.class)); + RestClearScrollAction action = new RestClearScrollAction(); RestRequest request = new FakeRestRequest.Builder(xContentRegistry()) .withContent(new BytesArray("{invalid_json}"), XContentType.JSON).build(); Exception e = expectThrows(IllegalArgumentException.class, () -> action.prepareRequest(request, null)); @@ -55,7 +54,7 @@ public void testBodyParamsOverrideQueryStringParams() throws Exception { NodeClient nodeClient = mock(NodeClient.class); doNothing().when(nodeClient).searchScroll(any(), any()); - RestClearScrollAction action = new RestClearScrollAction(mock(RestController.class)); + RestClearScrollAction action = new RestClearScrollAction(); RestRequest request = new FakeRestRequest.Builder(xContentRegistry()) .withParams(Collections.singletonMap("scroll_id", "QUERY_STRING")) .withContent(new BytesArray("{\"scroll_id\": [\"BODY\"]}"), XContentType.JSON).build(); diff --git a/server/src/test/java/org/elasticsearch/search/scroll/RestSearchScrollActionTests.java b/server/src/test/java/org/elasticsearch/search/scroll/RestSearchScrollActionTests.java index b90b01d4b7b02..6c58d32b8b8bb 100644 --- a/server/src/test/java/org/elasticsearch/search/scroll/RestSearchScrollActionTests.java +++ b/server/src/test/java/org/elasticsearch/search/scroll/RestSearchScrollActionTests.java @@ -23,7 +23,6 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.xcontent.XContentType; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.search.RestSearchScrollAction; import org.elasticsearch.test.ESTestCase; @@ -44,7 +43,7 @@ public class RestSearchScrollActionTests extends ESTestCase { public void testParseSearchScrollRequestWithInvalidJsonThrowsException() throws Exception { - RestSearchScrollAction action = new RestSearchScrollAction(mock(RestController.class)); + RestSearchScrollAction action = new RestSearchScrollAction(); RestRequest request = new FakeRestRequest.Builder(xContentRegistry()) .withContent(new BytesArray("{invalid_json}"), XContentType.JSON).build(); Exception e = expectThrows(IllegalArgumentException.class, () -> action.prepareRequest(request, null)); @@ -55,7 +54,7 @@ public void testBodyParamsOverrideQueryStringParams() throws Exception { NodeClient nodeClient = mock(NodeClient.class); doNothing().when(nodeClient).searchScroll(any(), any()); - RestSearchScrollAction action = new RestSearchScrollAction(mock(RestController.class)); + RestSearchScrollAction action = new RestSearchScrollAction(); Map params = new HashMap<>(); params.put("scroll_id", "QUERY_STRING"); params.put("scroll", "1000m"); diff --git a/server/src/test/java/org/elasticsearch/snapshots/DedicatedClusterSnapshotRestoreIT.java b/server/src/test/java/org/elasticsearch/snapshots/DedicatedClusterSnapshotRestoreIT.java index da9a960991b1e..777363cfcf509 100644 --- a/server/src/test/java/org/elasticsearch/snapshots/DedicatedClusterSnapshotRestoreIT.java +++ b/server/src/test/java/org/elasticsearch/snapshots/DedicatedClusterSnapshotRestoreIT.java @@ -72,7 +72,6 @@ import org.elasticsearch.plugins.Plugin; import org.elasticsearch.repositories.RepositoryMissingException; import org.elasticsearch.rest.AbstractRestChannel; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; @@ -121,7 +120,6 @@ import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.Matchers.nullValue; -import static org.mockito.Mockito.mock; @ClusterScope(scope = Scope.TEST, numDataNodes = 0, transportClientRatio = 0) public class DedicatedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTestCase { @@ -768,8 +766,7 @@ public void testThatSensitiveRepositorySettingsAreNotExposed() throws Exception ).get(); NodeClient nodeClient = internalCluster().getInstance(NodeClient.class); - RestGetRepositoriesAction getRepoAction = new RestGetRepositoriesAction(mock(RestController.class), - internalCluster().getInstance(SettingsFilter.class)); + RestGetRepositoriesAction getRepoAction = new RestGetRepositoriesAction(internalCluster().getInstance(SettingsFilter.class)); RestRequest getRepoRequest = new FakeRestRequest(); getRepoRequest.params().put("repository", "test-repo"); final CountDownLatch getRepoLatch = new CountDownLatch(1); @@ -791,8 +788,7 @@ public void sendResponse(RestResponse response) { throw getRepoError.get(); } - RestClusterStateAction clusterStateAction = new RestClusterStateAction(mock(RestController.class), - internalCluster().getInstance(SettingsFilter.class)); + RestClusterStateAction clusterStateAction = new RestClusterStateAction(internalCluster().getInstance(SettingsFilter.class)); RestRequest clusterStateRequest = new FakeRestRequest(); final CountDownLatch clusterStateLatch = new CountDownLatch(1); final AtomicReference clusterStateError = new AtomicReference<>(); diff --git a/server/src/test/java/org/elasticsearch/usage/UsageServiceTests.java b/server/src/test/java/org/elasticsearch/usage/UsageServiceTests.java index 5a38ca8ca4ebd..cfba6390bfb07 100644 --- a/server/src/test/java/org/elasticsearch/usage/UsageServiceTests.java +++ b/server/src/test/java/org/elasticsearch/usage/UsageServiceTests.java @@ -30,6 +30,8 @@ import org.elasticsearch.test.rest.FakeRestRequest; import java.net.InetAddress; +import java.util.Collections; +import java.util.List; import java.util.Map; import static org.hamcrest.Matchers.equalTo; @@ -100,6 +102,11 @@ public String getName() { return name; } + @Override + public List routes() { + return Collections.emptyList(); + } + @Override protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) { return channel -> { diff --git a/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/Autoscaling.java b/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/Autoscaling.java index e14e734b93a73..6c342c0c85cee 100644 --- a/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/Autoscaling.java +++ b/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/Autoscaling.java @@ -99,7 +99,7 @@ public List getRestHandlers( final Supplier nodesInCluster ) { if (enabled) { - return Collections.singletonList(new RestGetAutoscalingDecisionHandler(controller)); + return Collections.singletonList(new RestGetAutoscalingDecisionHandler()); } else { return Collections.emptyList(); } diff --git a/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/rest/RestGetAutoscalingDecisionHandler.java b/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/rest/RestGetAutoscalingDecisionHandler.java index e8f9674ae6d53..72532091a89a7 100644 --- a/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/rest/RestGetAutoscalingDecisionHandler.java +++ b/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/rest/RestGetAutoscalingDecisionHandler.java @@ -8,15 +8,20 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.autoscaling.action.GetAutoscalingDecisionAction; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.GET; + public class RestGetAutoscalingDecisionHandler extends BaseRestHandler { - public RestGetAutoscalingDecisionHandler(final RestController controller) { - controller.registerHandler(RestRequest.Method.GET, "/_autoscaling/decision", this); + @Override + public List routes() { + return singletonList(new Route(GET, "/_autoscaling/decision")); } @Override diff --git a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/Ccr.java b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/Ccr.java index 7f26f8b39d2d4..9ead0127c9294 100644 --- a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/Ccr.java +++ b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/Ccr.java @@ -255,22 +255,22 @@ public List getRestHandlers(Settings settings, RestController restC return Arrays.asList( // stats API - new RestFollowStatsAction(restController), - new RestCcrStatsAction(restController), - new RestFollowInfoAction(restController), + new RestFollowStatsAction(), + new RestCcrStatsAction(), + new RestFollowInfoAction(), // follow APIs - new RestPutFollowAction(restController), - new RestResumeFollowAction(restController), - new RestPauseFollowAction(restController), - new RestUnfollowAction(restController), + new RestPutFollowAction(), + new RestResumeFollowAction(), + new RestPauseFollowAction(), + new RestUnfollowAction(), // auto-follow APIs - new RestDeleteAutoFollowPatternAction(restController), - new RestPutAutoFollowPatternAction(restController), - new RestGetAutoFollowPatternAction(restController), - new RestPauseAutoFollowPatternAction(restController), - new RestResumeAutoFollowPatternAction(restController), + new RestDeleteAutoFollowPatternAction(), + new RestPutAutoFollowPatternAction(), + new RestGetAutoFollowPatternAction(), + new RestPauseAutoFollowPatternAction(), + new RestResumeAutoFollowPatternAction(), // forget follower API - new RestForgetFollowerAction(restController)); + new RestForgetFollowerAction()); } public List getNamedWriteables() { diff --git a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestCcrStatsAction.java b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestCcrStatsAction.java index 08353212c2bf7..e320595690a25 100644 --- a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestCcrStatsAction.java +++ b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestCcrStatsAction.java @@ -8,15 +8,20 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.ccr.action.CcrStatsAction; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.GET; + public class RestCcrStatsAction extends BaseRestHandler { - public RestCcrStatsAction(final RestController controller) { - controller.registerHandler(RestRequest.Method.GET, "/_ccr/stats", this); + @Override + public List routes() { + return singletonList(new Route(GET, "/_ccr/stats")); } @Override diff --git a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestDeleteAutoFollowPatternAction.java b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestDeleteAutoFollowPatternAction.java index ae63d2004a616..853b8f7d6da15 100644 --- a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestDeleteAutoFollowPatternAction.java +++ b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestDeleteAutoFollowPatternAction.java @@ -7,17 +7,21 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.ccr.action.DeleteAutoFollowPatternAction.Request; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.DELETE; import static org.elasticsearch.xpack.core.ccr.action.DeleteAutoFollowPatternAction.INSTANCE; public class RestDeleteAutoFollowPatternAction extends BaseRestHandler { - public RestDeleteAutoFollowPatternAction(RestController controller) { - controller.registerHandler(RestRequest.Method.DELETE, "/_ccr/auto_follow/{name}", this); + @Override + public List routes() { + return singletonList(new Route(DELETE, "/_ccr/auto_follow/{name}")); } @Override diff --git a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestFollowInfoAction.java b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestFollowInfoAction.java index 86aba9d31a33b..e9763a43a7b07 100644 --- a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestFollowInfoAction.java +++ b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestFollowInfoAction.java @@ -9,15 +9,20 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.Strings; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.ccr.action.FollowInfoAction; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.GET; + public class RestFollowInfoAction extends BaseRestHandler { - public RestFollowInfoAction(final RestController controller) { - controller.registerHandler(RestRequest.Method.GET, "/{index}/_ccr/info", this); + @Override + public List routes() { + return singletonList(new Route(GET, "/{index}/_ccr/info")); } @Override diff --git a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestFollowStatsAction.java b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestFollowStatsAction.java index 31c2f5daac8e6..2eed47b0a7abc 100644 --- a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestFollowStatsAction.java +++ b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestFollowStatsAction.java @@ -9,15 +9,20 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.Strings; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.ccr.action.FollowStatsAction; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.GET; + public class RestFollowStatsAction extends BaseRestHandler { - public RestFollowStatsAction(final RestController controller) { - controller.registerHandler(RestRequest.Method.GET, "/{index}/_ccr/stats", this); + @Override + public List routes() { + return singletonList(new Route(GET, "/{index}/_ccr/stats")); } @Override diff --git a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestForgetFollowerAction.java b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestForgetFollowerAction.java index a79ec34a652c0..2b3e71917decd 100644 --- a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestForgetFollowerAction.java +++ b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestForgetFollowerAction.java @@ -10,20 +10,22 @@ import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestStatus; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.ccr.action.ForgetFollowerAction; import java.io.IOException; -import java.util.Objects; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.POST; public class RestForgetFollowerAction extends BaseRestHandler { - public RestForgetFollowerAction(final RestController restController) { - Objects.requireNonNull(restController); - restController.registerHandler(RestRequest.Method.POST, "/{index}/_ccr/forget_follower", this); + @Override + public List routes() { + return singletonList(new Route(POST, "/{index}/_ccr/forget_follower")); } @Override diff --git a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestGetAutoFollowPatternAction.java b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestGetAutoFollowPatternAction.java index 0a7393dc8fcba..7a7454c02fe18 100644 --- a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestGetAutoFollowPatternAction.java +++ b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestGetAutoFollowPatternAction.java @@ -7,18 +7,24 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.ccr.action.GetAutoFollowPatternAction.Request; +import java.util.List; + +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; +import static org.elasticsearch.rest.RestRequest.Method.GET; import static org.elasticsearch.xpack.core.ccr.action.GetAutoFollowPatternAction.INSTANCE; public class RestGetAutoFollowPatternAction extends BaseRestHandler { - public RestGetAutoFollowPatternAction(RestController controller) { - controller.registerHandler(RestRequest.Method.GET, "/_ccr/auto_follow/{name}", this); - controller.registerHandler(RestRequest.Method.GET, "/_ccr/auto_follow", this); + @Override + public List routes() { + return unmodifiableList(asList( + new Route(GET, "/_ccr/auto_follow/{name}"), + new Route(GET, "/_ccr/auto_follow"))); } @Override diff --git a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestPauseAutoFollowPatternAction.java b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestPauseAutoFollowPatternAction.java index abfca00da5cb1..04d6747a78aaf 100644 --- a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestPauseAutoFollowPatternAction.java +++ b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestPauseAutoFollowPatternAction.java @@ -7,17 +7,21 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.ccr.action.ActivateAutoFollowPatternAction.Request; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.POST; import static org.elasticsearch.xpack.core.ccr.action.ActivateAutoFollowPatternAction.INSTANCE; public class RestPauseAutoFollowPatternAction extends BaseRestHandler { - public RestPauseAutoFollowPatternAction(final RestController controller) { - controller.registerHandler(RestRequest.Method.POST, "/_ccr/auto_follow/{name}/pause", this); + @Override + public List routes() { + return singletonList(new Route(POST, "/_ccr/auto_follow/{name}/pause")); } @Override diff --git a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestPauseFollowAction.java b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestPauseFollowAction.java index ef80fe1d36523..2bfec8f87e28b 100644 --- a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestPauseFollowAction.java +++ b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestPauseFollowAction.java @@ -7,17 +7,21 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.POST; import static org.elasticsearch.xpack.core.ccr.action.PauseFollowAction.INSTANCE; import static org.elasticsearch.xpack.core.ccr.action.PauseFollowAction.Request; public class RestPauseFollowAction extends BaseRestHandler { - public RestPauseFollowAction(RestController controller) { - controller.registerHandler(RestRequest.Method.POST, "/{index}/_ccr/pause_follow", this); + @Override + public List routes() { + return singletonList(new Route(POST, "/{index}/_ccr/pause_follow")); } @Override diff --git a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestPutAutoFollowPatternAction.java b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestPutAutoFollowPatternAction.java index 076c3cfb18ee7..5593aa7ac6155 100644 --- a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestPutAutoFollowPatternAction.java +++ b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestPutAutoFollowPatternAction.java @@ -8,19 +8,22 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.ccr.action.PutAutoFollowPatternAction.Request; import java.io.IOException; +import java.util.List; +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.PUT; import static org.elasticsearch.xpack.core.ccr.action.PutAutoFollowPatternAction.INSTANCE; public class RestPutAutoFollowPatternAction extends BaseRestHandler { - public RestPutAutoFollowPatternAction(RestController controller) { - controller.registerHandler(RestRequest.Method.PUT, "/_ccr/auto_follow/{name}", this); + @Override + public List routes() { + return singletonList(new Route(PUT, "/_ccr/auto_follow/{name}")); } @Override diff --git a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestPutFollowAction.java b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestPutFollowAction.java index 8ad2002a0c4b4..9ee161555bdca 100644 --- a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestPutFollowAction.java +++ b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestPutFollowAction.java @@ -9,19 +9,22 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import java.io.IOException; +import java.util.List; +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.PUT; import static org.elasticsearch.xpack.core.ccr.action.PutFollowAction.INSTANCE; import static org.elasticsearch.xpack.core.ccr.action.PutFollowAction.Request; public class RestPutFollowAction extends BaseRestHandler { - public RestPutFollowAction(RestController controller) { - controller.registerHandler(RestRequest.Method.PUT, "/{index}/_ccr/follow", this); + @Override + public List routes() { + return singletonList(new Route(PUT, "/{index}/_ccr/follow")); } @Override diff --git a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestResumeAutoFollowPatternAction.java b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestResumeAutoFollowPatternAction.java index 89f3f65fca7d3..e20c038dff1e0 100644 --- a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestResumeAutoFollowPatternAction.java +++ b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestResumeAutoFollowPatternAction.java @@ -7,17 +7,21 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.ccr.action.ActivateAutoFollowPatternAction.Request; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.POST; import static org.elasticsearch.xpack.core.ccr.action.ActivateAutoFollowPatternAction.INSTANCE; public class RestResumeAutoFollowPatternAction extends BaseRestHandler { - public RestResumeAutoFollowPatternAction(final RestController controller) { - controller.registerHandler(RestRequest.Method.POST, "/_ccr/auto_follow/{name}/resume", this); + @Override + public List routes() { + return singletonList(new Route(POST, "/_ccr/auto_follow/{name}/resume")); } @Override diff --git a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestResumeFollowAction.java b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestResumeFollowAction.java index 29dcd029e990e..146700888cfc8 100644 --- a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestResumeFollowAction.java +++ b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestResumeFollowAction.java @@ -8,19 +8,22 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import java.io.IOException; +import java.util.List; +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.POST; import static org.elasticsearch.xpack.core.ccr.action.ResumeFollowAction.INSTANCE; import static org.elasticsearch.xpack.core.ccr.action.ResumeFollowAction.Request; public class RestResumeFollowAction extends BaseRestHandler { - public RestResumeFollowAction(RestController controller) { - controller.registerHandler(RestRequest.Method.POST, "/{index}/_ccr/resume_follow", this); + @Override + public List routes() { + return singletonList(new Route(POST, "/{index}/_ccr/resume_follow")); } @Override diff --git a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestUnfollowAction.java b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestUnfollowAction.java index 99a7ddac0da7b..0effd10b7f196 100644 --- a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestUnfollowAction.java +++ b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestUnfollowAction.java @@ -8,17 +8,21 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.ccr.action.UnfollowAction; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.POST; import static org.elasticsearch.xpack.core.ccr.action.UnfollowAction.INSTANCE; public class RestUnfollowAction extends BaseRestHandler { - public RestUnfollowAction(RestController controller) { - controller.registerHandler(RestRequest.Method.POST, "/{index}/_ccr/unfollow", this); + @Override + public List routes() { + return singletonList(new Route(POST, "/{index}/_ccr/unfollow")); } @Override diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/license/Licensing.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/license/Licensing.java index 3ff79251cafe8..3ac7cfff9490e 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/license/Licensing.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/license/Licensing.java @@ -74,13 +74,13 @@ public List getRestHandlers(Settings settings, RestController restC IndexScopedSettings indexScopedSettings, SettingsFilter settingsFilter, IndexNameExpressionResolver indexNameExpressionResolver, Supplier nodesInCluster) { List handlers = new ArrayList<>(); - handlers.add(new RestGetLicenseAction(restController)); - handlers.add(new RestPutLicenseAction(restController)); - handlers.add(new RestDeleteLicenseAction(restController)); - handlers.add(new RestGetTrialStatus(restController)); - handlers.add(new RestGetBasicStatus(restController)); - handlers.add(new RestPostStartTrialLicense(restController)); - handlers.add(new RestPostStartBasicLicense(restController)); + handlers.add(new RestGetLicenseAction()); + handlers.add(new RestPutLicenseAction()); + handlers.add(new RestDeleteLicenseAction()); + handlers.add(new RestGetTrialStatus()); + handlers.add(new RestGetBasicStatus()); + handlers.add(new RestPostStartTrialLicense()); + handlers.add(new RestPostStartBasicLicense()); return handlers; } diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/license/RestDeleteLicenseAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/license/RestDeleteLicenseAction.java index 6dbbea2dbaa28..683f4a7479a02 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/license/RestDeleteLicenseAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/license/RestDeleteLicenseAction.java @@ -9,25 +9,32 @@ import org.apache.logging.log4j.LogManager; import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.protocol.xpack.license.DeleteLicenseRequest; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.XPackClient; import org.elasticsearch.xpack.core.rest.XPackRestHandler; import java.io.IOException; +import java.util.List; +import static java.util.Collections.emptyList; +import static java.util.Collections.singletonList; import static org.elasticsearch.rest.RestRequest.Method.DELETE; public class RestDeleteLicenseAction extends XPackRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestDeleteLicenseAction.class)); - RestDeleteLicenseAction(RestController controller) { - // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - DELETE, "/_license", this, - DELETE, URI_BASE + "/license", deprecationLogger); + RestDeleteLicenseAction() {} + + @Override + public List routes() { + return emptyList(); + } + + @Override + public List replacedRoutes() { + return singletonList(new ReplacedRoute(DELETE, "/_license", DELETE, URI_BASE + "/license", deprecationLogger)); } @Override diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/license/RestGetBasicStatus.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/license/RestGetBasicStatus.java index 74355d83a28e3..68da868670801 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/license/RestGetBasicStatus.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/license/RestGetBasicStatus.java @@ -8,23 +8,31 @@ import org.apache.logging.log4j.LogManager; import org.elasticsearch.common.logging.DeprecationLogger; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.XPackClient; import org.elasticsearch.xpack.core.rest.XPackRestHandler; +import java.util.List; + +import static java.util.Collections.emptyList; +import static java.util.Collections.singletonList; import static org.elasticsearch.rest.RestRequest.Method.GET; public class RestGetBasicStatus extends XPackRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestGetBasicStatus.class)); - RestGetBasicStatus(RestController controller) { - // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - GET, "/_license/basic_status", this, - GET, URI_BASE + "/license/basic_status", deprecationLogger); + RestGetBasicStatus() {} + + @Override + public List routes() { + return emptyList(); + } + + @Override + public List replacedRoutes() { + return singletonList(new ReplacedRoute(GET, "/_license/basic_status", GET, URI_BASE + "/license/basic_status", deprecationLogger)); } @Override diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/license/RestGetLicenseAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/license/RestGetLicenseAction.java index d2b96846131fd..29978cc41b22c 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/license/RestGetLicenseAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/license/RestGetLicenseAction.java @@ -12,7 +12,6 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.protocol.xpack.license.GetLicenseRequest; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.action.RestBuilderListener; @@ -21,8 +20,11 @@ import java.io.IOException; import java.util.HashMap; +import java.util.List; import java.util.Map; +import static java.util.Collections.emptyList; +import static java.util.Collections.singletonList; import static org.elasticsearch.rest.RestRequest.Method.GET; import static org.elasticsearch.rest.RestStatus.NOT_FOUND; import static org.elasticsearch.rest.RestStatus.OK; @@ -31,11 +33,16 @@ public class RestGetLicenseAction extends XPackRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestGetLicenseAction.class)); - RestGetLicenseAction(RestController controller) { - // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - GET, "/_license", this, - GET, URI_BASE + "/license", deprecationLogger); + RestGetLicenseAction() {} + + @Override + public List routes() { + return emptyList(); + } + + @Override + public List replacedRoutes() { + return singletonList(new ReplacedRoute(GET, "/_license", GET, URI_BASE + "/license", deprecationLogger)); } @Override diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/license/RestGetTrialStatus.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/license/RestGetTrialStatus.java index 2215ab7f8bf9c..1d8aa0ed689ca 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/license/RestGetTrialStatus.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/license/RestGetTrialStatus.java @@ -8,23 +8,31 @@ import org.apache.logging.log4j.LogManager; import org.elasticsearch.common.logging.DeprecationLogger; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.XPackClient; import org.elasticsearch.xpack.core.rest.XPackRestHandler; +import java.util.List; + +import static java.util.Collections.emptyList; +import static java.util.Collections.singletonList; import static org.elasticsearch.rest.RestRequest.Method.GET; public class RestGetTrialStatus extends XPackRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestGetTrialStatus.class)); - RestGetTrialStatus(RestController controller) { - // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - GET, "/_license/trial_status", this, - GET, URI_BASE + "/license/trial_status", deprecationLogger); + RestGetTrialStatus() {} + + @Override + public List routes() { + return emptyList(); + } + + @Override + public List replacedRoutes() { + return singletonList(new ReplacedRoute(GET, "/_license/trial_status", GET, URI_BASE + "/license/trial_status", deprecationLogger)); } @Override diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/license/RestPostStartBasicLicense.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/license/RestPostStartBasicLicense.java index 18a9b7cdfc79b..e56e95dc450f9 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/license/RestPostStartBasicLicense.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/license/RestPostStartBasicLicense.java @@ -8,25 +8,32 @@ import org.apache.logging.log4j.LogManager; import org.elasticsearch.common.logging.DeprecationLogger; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestStatusToXContentListener; import org.elasticsearch.xpack.core.XPackClient; import org.elasticsearch.xpack.core.rest.XPackRestHandler; import java.io.IOException; +import java.util.List; +import static java.util.Collections.emptyList; +import static java.util.Collections.singletonList; import static org.elasticsearch.rest.RestRequest.Method.POST; public class RestPostStartBasicLicense extends XPackRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestPostStartBasicLicense.class)); - RestPostStartBasicLicense(RestController controller) { - // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - POST, "/_license/start_basic", this, - POST, URI_BASE + "/license/start_basic", deprecationLogger); + RestPostStartBasicLicense() {} + + @Override + public List routes() { + return emptyList(); + } + + @Override + public List replacedRoutes() { + return singletonList(new ReplacedRoute(POST, "/_license/start_basic", POST, URI_BASE + "/license/start_basic", deprecationLogger)); } @Override diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/license/RestPostStartTrialLicense.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/license/RestPostStartTrialLicense.java index 499158631d75b..c326162392b53 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/license/RestPostStartTrialLicense.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/license/RestPostStartTrialLicense.java @@ -10,7 +10,6 @@ import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.action.RestBuilderListener; @@ -18,19 +17,27 @@ import org.elasticsearch.xpack.core.rest.XPackRestHandler; import java.io.IOException; +import java.util.List; import java.util.Map; +import static java.util.Collections.emptyList; +import static java.util.Collections.singletonList; import static org.elasticsearch.rest.RestRequest.Method.POST; public class RestPostStartTrialLicense extends XPackRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestPostStartTrialLicense.class)); - RestPostStartTrialLicense(RestController controller) { - // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - POST, "/_license/start_trial", this, - POST, URI_BASE + "/license/start_trial", deprecationLogger); + RestPostStartTrialLicense() {} + + @Override + public List routes() { + return emptyList(); + } + + @Override + public List replacedRoutes() { + return singletonList(new ReplacedRoute(POST, "/_license/start_trial", POST, URI_BASE + "/license/start_trial", deprecationLogger)); } @Override diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/license/RestPutLicenseAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/license/RestPutLicenseAction.java index 0068daad01fac..1d7896f75dda2 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/license/RestPutLicenseAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/license/RestPutLicenseAction.java @@ -8,12 +8,15 @@ import org.apache.logging.log4j.LogManager; import org.elasticsearch.common.logging.DeprecationLogger; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.XPackClient; import org.elasticsearch.xpack.core.rest.XPackRestHandler; +import java.util.List; +import static java.util.Arrays.asList; +import static java.util.Collections.emptyList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.rest.RestRequest.Method.POST; import static org.elasticsearch.rest.RestRequest.Method.PUT; @@ -21,16 +24,19 @@ public class RestPutLicenseAction extends XPackRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestPutLicenseAction.class)); - RestPutLicenseAction(RestController controller) { - // TODO: remove POST endpoint? - // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - POST, "/_license", this, - POST, URI_BASE + "/license", deprecationLogger); - // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - PUT, "/_license", this, - PUT, URI_BASE + "/license", deprecationLogger); + RestPutLicenseAction() {} + + @Override + public List routes() { + return emptyList(); + } + + @Override + public List replacedRoutes() { + return unmodifiableList(asList( + // TODO: remove POST endpoint? + new ReplacedRoute(POST, "/_license", POST, URI_BASE + "/license", deprecationLogger), + new ReplacedRoute(PUT, "/_license", PUT, URI_BASE + "/license", deprecationLogger))); } @Override diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/XPackPlugin.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/XPackPlugin.java index 23424a4ed39db..b549e8b0a9a94 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/XPackPlugin.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/XPackPlugin.java @@ -302,9 +302,9 @@ public List getRestHandlers(Settings settings, RestController restC IndexScopedSettings indexScopedSettings, SettingsFilter settingsFilter, IndexNameExpressionResolver indexNameExpressionResolver, Supplier nodesInCluster) { List handlers = new ArrayList<>(); - handlers.add(new RestXPackInfoAction(restController)); - handlers.add(new RestXPackUsageAction(restController)); - handlers.add(new RestReloadAnalyzersAction(restController)); + handlers.add(new RestXPackInfoAction()); + handlers.add(new RestXPackUsageAction()); + handlers.add(new RestReloadAnalyzersAction()); handlers.addAll(licensing.getRestHandlers(settings, restController, clusterSettings, indexScopedSettings, settingsFilter, indexNameExpressionResolver, nodesInCluster)); return handlers; diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rest/action/RestReloadAnalyzersAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rest/action/RestReloadAnalyzersAction.java index e3641f079f321..8d118960ed1f2 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rest/action/RestReloadAnalyzersAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rest/action/RestReloadAnalyzersAction.java @@ -9,18 +9,26 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.Strings; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.action.ReloadAnalyzerAction; import org.elasticsearch.xpack.core.action.ReloadAnalyzersRequest; import java.io.IOException; +import java.util.List; + +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; +import static org.elasticsearch.rest.RestRequest.Method.GET; +import static org.elasticsearch.rest.RestRequest.Method.POST; + public class RestReloadAnalyzersAction extends BaseRestHandler { - public RestReloadAnalyzersAction(RestController controller) { - controller.registerHandler(RestRequest.Method.GET, "/{index}/_reload_search_analyzers", this); - controller.registerHandler(RestRequest.Method.POST, "/{index}/_reload_search_analyzers", this); + @Override + public List routes() { + return unmodifiableList(asList( + new Route(GET, "/{index}/_reload_search_analyzers"), + new Route(POST, "/{index}/_reload_search_analyzers"))); } @Override diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rest/action/RestXPackInfoAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rest/action/RestXPackInfoAction.java index e70d1a5444354..48bec03531781 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rest/action/RestXPackInfoAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rest/action/RestXPackInfoAction.java @@ -6,7 +6,6 @@ package org.elasticsearch.xpack.core.rest.action; import org.elasticsearch.protocol.xpack.XPackInfoRequest; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.XPackClient; @@ -14,14 +13,20 @@ import java.io.IOException; import java.util.EnumSet; +import java.util.List; +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.rest.RestRequest.Method.GET; import static org.elasticsearch.rest.RestRequest.Method.HEAD; public class RestXPackInfoAction extends XPackRestHandler { - public RestXPackInfoAction(RestController controller) { ; - controller.registerHandler(HEAD, URI_BASE, this); - controller.registerHandler(GET, URI_BASE, this); + + @Override + public List routes() { + return unmodifiableList(asList( + new Route(GET, "/_xpack"), + new Route(HEAD, "/_xpack"))); } @Override diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rest/action/RestXPackUsageAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rest/action/RestXPackUsageAction.java index 8bdb5cb5ee188..376050624fb20 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rest/action/RestXPackUsageAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rest/action/RestXPackUsageAction.java @@ -9,7 +9,6 @@ import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.action.RestBuilderListener; @@ -19,13 +18,17 @@ import org.elasticsearch.xpack.core.action.XPackUsageResponse; import org.elasticsearch.xpack.core.rest.XPackRestHandler; +import java.util.List; + +import static java.util.Collections.singletonList; import static org.elasticsearch.rest.RestRequest.Method.GET; import static org.elasticsearch.rest.RestStatus.OK; public class RestXPackUsageAction extends XPackRestHandler { - public RestXPackUsageAction(RestController controller) { - controller.registerHandler(GET, URI_BASE + "/usage", this); + @Override + public List routes() { + return singletonList(new Route(GET, "/_xpack/usage")); } @Override diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ssl/rest/RestGetCertificateInfoAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ssl/rest/RestGetCertificateInfoAction.java index 569a392c0349b..6d1c7f087f980 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ssl/rest/RestGetCertificateInfoAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ssl/rest/RestGetCertificateInfoAction.java @@ -11,7 +11,6 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; @@ -19,6 +18,10 @@ import org.elasticsearch.xpack.core.ssl.action.GetCertificateInfoAction; import org.elasticsearch.xpack.core.ssl.action.GetCertificateInfoAction.Response; +import java.util.Collections; +import java.util.List; + +import static java.util.Collections.singletonList; import static org.elasticsearch.rest.RestRequest.Method.GET; /** @@ -30,11 +33,14 @@ public class RestGetCertificateInfoAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestGetCertificateInfoAction.class)); - public RestGetCertificateInfoAction(RestController controller) { - // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - GET, "/_ssl/certificates", this, - GET, "/_xpack/ssl/certificates", deprecationLogger); + @Override + public List routes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { + return singletonList(new ReplacedRoute(GET, "/_ssl/certificates", GET, "/_xpack/ssl/certificates", deprecationLogger)); } @Override diff --git a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/Deprecation.java b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/Deprecation.java index a131ffd62f9ca..837bd33f7a2eb 100644 --- a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/Deprecation.java +++ b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/Deprecation.java @@ -45,6 +45,6 @@ public List getRestHandlers(Settings settings, RestController restC Supplier nodesInCluster) { - return Collections.singletonList(new RestDeprecationInfoAction(restController)); + return Collections.singletonList(new RestDeprecationInfoAction()); } } diff --git a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/RestDeprecationInfoAction.java b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/RestDeprecationInfoAction.java index 1ffd19c46b4cb..76fada7fbd2a2 100644 --- a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/RestDeprecationInfoAction.java +++ b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/RestDeprecationInfoAction.java @@ -5,31 +5,41 @@ */ package org.elasticsearch.xpack.deprecation; -import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.Strings; import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.deprecation.DeprecationInfoAction; import org.elasticsearch.xpack.core.deprecation.DeprecationInfoAction.Request; import java.io.IOException; +import java.util.List; + +import static java.util.Arrays.asList; +import static java.util.Collections.emptyList; +import static java.util.Collections.unmodifiableList; +import static org.elasticsearch.rest.RestRequest.Method.GET; public class RestDeprecationInfoAction extends BaseRestHandler { + private static final Logger logger = LogManager.getLogger(RestDeprecationInfoAction.class); private static final DeprecationLogger deprecationLogger = new DeprecationLogger(logger); - public RestDeprecationInfoAction(RestController controller) { - controller.registerWithDeprecatedHandler( - RestRequest.Method.GET, "/_migration/deprecations", this, - RestRequest.Method.GET, "/_xpack/migration/deprecations", deprecationLogger); - controller.registerWithDeprecatedHandler( - RestRequest.Method.GET, "/{index}/_migration/deprecations", this, - RestRequest.Method.GET, "/{index}/_xpack/migration/deprecations", deprecationLogger); + @Override + public List routes() { + return emptyList(); + } + + @Override + public List replacedRoutes() { + return unmodifiableList(asList( + new ReplacedRoute(GET, "/_migration/deprecations", GET, "/_xpack/migration/deprecations", deprecationLogger), + new ReplacedRoute( + GET, "/{index}/_migration/deprecations", GET, "/{index}/_xpack/migration/deprecations", deprecationLogger))); } @Override @@ -39,7 +49,7 @@ public String getName() { @Override public RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException { - if (request.method().equals(RestRequest.Method.GET)) { + if (request.method().equals(GET)) { return handleGet(request, client); } else { throw new IllegalArgumentException("illegal method [" + request.method() + "] for request [" + request.path() + "]"); diff --git a/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/EnrichPlugin.java b/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/EnrichPlugin.java index 148965accbe47..f67351f436ad8 100644 --- a/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/EnrichPlugin.java +++ b/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/EnrichPlugin.java @@ -180,11 +180,11 @@ public List getRestHandlers( } return Arrays.asList( - new RestGetEnrichPolicyAction(restController), - new RestDeleteEnrichPolicyAction(restController), - new RestPutEnrichPolicyAction(restController), - new RestExecuteEnrichPolicyAction(restController), - new RestEnrichStatsAction(restController) + new RestGetEnrichPolicyAction(), + new RestDeleteEnrichPolicyAction(), + new RestPutEnrichPolicyAction(), + new RestExecuteEnrichPolicyAction(), + new RestEnrichStatsAction() ); } diff --git a/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/rest/RestDeleteEnrichPolicyAction.java b/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/rest/RestDeleteEnrichPolicyAction.java index 01c23d91fed24..c8ff6fa5337de 100644 --- a/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/rest/RestDeleteEnrichPolicyAction.java +++ b/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/rest/RestDeleteEnrichPolicyAction.java @@ -7,17 +7,21 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.enrich.action.DeleteEnrichPolicyAction; import java.io.IOException; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.DELETE; public class RestDeleteEnrichPolicyAction extends BaseRestHandler { - public RestDeleteEnrichPolicyAction(final RestController controller) { - controller.registerHandler(RestRequest.Method.DELETE, "/_enrich/policy/{name}", this); + @Override + public List routes() { + return singletonList(new Route(DELETE, "/_enrich/policy/{name}")); } @Override diff --git a/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/rest/RestEnrichStatsAction.java b/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/rest/RestEnrichStatsAction.java index 586e1c255dd7c..4b74bcd3a64c0 100644 --- a/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/rest/RestEnrichStatsAction.java +++ b/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/rest/RestEnrichStatsAction.java @@ -7,17 +7,21 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.enrich.action.EnrichStatsAction; import java.io.IOException; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.GET; public class RestEnrichStatsAction extends BaseRestHandler { - public RestEnrichStatsAction(final RestController controller) { - controller.registerHandler(RestRequest.Method.GET, "/_enrich/_stats", this); + @Override + public List routes() { + return singletonList(new Route(GET, "/_enrich/_stats")); } @Override diff --git a/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/rest/RestExecuteEnrichPolicyAction.java b/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/rest/RestExecuteEnrichPolicyAction.java index 087117a6c1a45..c6515876a7615 100644 --- a/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/rest/RestExecuteEnrichPolicyAction.java +++ b/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/rest/RestExecuteEnrichPolicyAction.java @@ -7,18 +7,25 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.enrich.action.ExecuteEnrichPolicyAction; import java.io.IOException; +import java.util.List; + +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; +import static org.elasticsearch.rest.RestRequest.Method.POST; +import static org.elasticsearch.rest.RestRequest.Method.PUT; public class RestExecuteEnrichPolicyAction extends BaseRestHandler { - public RestExecuteEnrichPolicyAction(final RestController controller) { - controller.registerHandler(RestRequest.Method.PUT, "/_enrich/policy/{name}/_execute", this); - controller.registerHandler(RestRequest.Method.POST, "/_enrich/policy/{name}/_execute", this); + @Override + public List routes() { + return unmodifiableList( + asList(new Route(POST, "/_enrich/policy/{name}/_execute"), new Route(PUT, "/_enrich/policy/{name}/_execute")) + ); } @Override diff --git a/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/rest/RestGetEnrichPolicyAction.java b/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/rest/RestGetEnrichPolicyAction.java index 3a279a49fa49c..06e516592f7f6 100644 --- a/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/rest/RestGetEnrichPolicyAction.java +++ b/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/rest/RestGetEnrichPolicyAction.java @@ -8,18 +8,22 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.Strings; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.enrich.action.GetEnrichPolicyAction; import java.io.IOException; +import java.util.List; + +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; +import static org.elasticsearch.rest.RestRequest.Method.GET; public class RestGetEnrichPolicyAction extends BaseRestHandler { - public RestGetEnrichPolicyAction(final RestController controller) { - controller.registerHandler(RestRequest.Method.GET, "/_enrich/policy/{name}", this); - controller.registerHandler(RestRequest.Method.GET, "/_enrich/policy", this); + @Override + public List routes() { + return unmodifiableList(asList(new Route(GET, "/_enrich/policy/{name}"), new Route(GET, "/_enrich/policy"))); } @Override diff --git a/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/rest/RestPutEnrichPolicyAction.java b/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/rest/RestPutEnrichPolicyAction.java index 38d36447d8ee1..8750891d34db0 100644 --- a/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/rest/RestPutEnrichPolicyAction.java +++ b/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/rest/RestPutEnrichPolicyAction.java @@ -8,17 +8,21 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.enrich.action.PutEnrichPolicyAction; import java.io.IOException; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.PUT; public class RestPutEnrichPolicyAction extends BaseRestHandler { - public RestPutEnrichPolicyAction(final RestController controller) { - controller.registerHandler(RestRequest.Method.PUT, "/_enrich/policy/{name}", this); + @Override + public List routes() { + return singletonList(new Route(PUT, "/_enrich/policy/{name}")); } @Override diff --git a/x-pack/plugin/eql/src/main/java/org/elasticsearch/xpack/eql/plugin/EqlPlugin.java b/x-pack/plugin/eql/src/main/java/org/elasticsearch/xpack/eql/plugin/EqlPlugin.java index c6f4142776878..14cbae5e1a346 100644 --- a/x-pack/plugin/eql/src/main/java/org/elasticsearch/xpack/eql/plugin/EqlPlugin.java +++ b/x-pack/plugin/eql/src/main/java/org/elasticsearch/xpack/eql/plugin/EqlPlugin.java @@ -104,6 +104,6 @@ public List getRestHandlers(Settings settings, if (isEnabled(settings) == false) { return Collections.emptyList(); } - return Arrays.asList(new RestEqlSearchAction(restController)); + return Collections.singletonList(new RestEqlSearchAction()); } } \ No newline at end of file diff --git a/x-pack/plugin/eql/src/main/java/org/elasticsearch/xpack/eql/plugin/RestEqlSearchAction.java b/x-pack/plugin/eql/src/main/java/org/elasticsearch/xpack/eql/plugin/RestEqlSearchAction.java index bf777fd031ff5..9da71b13a5d6c 100644 --- a/x-pack/plugin/eql/src/main/java/org/elasticsearch/xpack/eql/plugin/RestEqlSearchAction.java +++ b/x-pack/plugin/eql/src/main/java/org/elasticsearch/xpack/eql/plugin/RestEqlSearchAction.java @@ -5,34 +5,37 @@ */ package org.elasticsearch.xpack.eql.plugin; +import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.Strings; +import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.common.xcontent.XContentParser; +import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; - -import org.elasticsearch.client.node.NodeClient; -import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.rest.action.RestResponseListener; import org.elasticsearch.xpack.eql.action.EqlSearchAction; import org.elasticsearch.xpack.eql.action.EqlSearchRequest; import org.elasticsearch.xpack.eql.action.EqlSearchResponse; import java.io.IOException; +import java.util.List; +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.rest.RestRequest.Method.GET; import static org.elasticsearch.rest.RestRequest.Method.POST; public class RestEqlSearchAction extends BaseRestHandler { private static final String SEARCH_PATH = "/{index}/_eql/search"; - public RestEqlSearchAction(RestController controller) { - controller.registerHandler(GET, SEARCH_PATH, this); - controller.registerHandler(POST, SEARCH_PATH, this); + @Override + public List routes() { + return unmodifiableList(asList( + new Route(GET, SEARCH_PATH), + new Route(POST, SEARCH_PATH))); } @Override diff --git a/x-pack/plugin/frozen-indices/src/main/java/org/elasticsearch/xpack/frozen/FrozenIndices.java b/x-pack/plugin/frozen-indices/src/main/java/org/elasticsearch/xpack/frozen/FrozenIndices.java index 1953889df5da0..f8c0e0845b835 100644 --- a/x-pack/plugin/frozen-indices/src/main/java/org/elasticsearch/xpack/frozen/FrozenIndices.java +++ b/x-pack/plugin/frozen-indices/src/main/java/org/elasticsearch/xpack/frozen/FrozenIndices.java @@ -92,6 +92,6 @@ public List getRestHandlers(Settings settings, RestController restC IndexScopedSettings indexScopedSettings, SettingsFilter settingsFilter, IndexNameExpressionResolver indexNameExpressionResolver, Supplier nodesInCluster) { - return Collections.singletonList(new RestFreezeIndexAction(restController)); + return Collections.singletonList(new RestFreezeIndexAction()); } } diff --git a/x-pack/plugin/frozen-indices/src/main/java/org/elasticsearch/xpack/frozen/rest/action/RestFreezeIndexAction.java b/x-pack/plugin/frozen-indices/src/main/java/org/elasticsearch/xpack/frozen/rest/action/RestFreezeIndexAction.java index 43429a98aaf2a..848832e6231be 100644 --- a/x-pack/plugin/frozen-indices/src/main/java/org/elasticsearch/xpack/frozen/rest/action/RestFreezeIndexAction.java +++ b/x-pack/plugin/frozen-indices/src/main/java/org/elasticsearch/xpack/frozen/rest/action/RestFreezeIndexAction.java @@ -9,17 +9,24 @@ import org.elasticsearch.action.support.IndicesOptions; import org.elasticsearch.common.Strings; import org.elasticsearch.protocol.xpack.frozen.FreezeRequest; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.XPackClient; import org.elasticsearch.xpack.core.rest.XPackRestHandler; +import java.util.List; + +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; +import static org.elasticsearch.rest.RestRequest.Method.POST; + public final class RestFreezeIndexAction extends XPackRestHandler { - public RestFreezeIndexAction(RestController controller) { - controller.registerHandler(RestRequest.Method.POST, "/{index}/_freeze", this); - controller.registerHandler(RestRequest.Method.POST, "/{index}/_unfreeze", this); + @Override + public List routes() { + return unmodifiableList(asList( + new Route(POST, "/{index}/_freeze"), + new Route(POST, "/{index}/_unfreeze"))); } @Override diff --git a/x-pack/plugin/graph/src/main/java/org/elasticsearch/xpack/graph/Graph.java b/x-pack/plugin/graph/src/main/java/org/elasticsearch/xpack/graph/Graph.java index f273d25d63087..c18098c8f80c2 100644 --- a/x-pack/plugin/graph/src/main/java/org/elasticsearch/xpack/graph/Graph.java +++ b/x-pack/plugin/graph/src/main/java/org/elasticsearch/xpack/graph/Graph.java @@ -64,6 +64,6 @@ public List getRestHandlers(Settings settings, RestController restC if (false == enabled) { return emptyList(); } - return singletonList(new RestGraphAction(restController)); + return singletonList(new RestGraphAction()); } } diff --git a/x-pack/plugin/graph/src/main/java/org/elasticsearch/xpack/graph/rest/action/RestGraphAction.java b/x-pack/plugin/graph/src/main/java/org/elasticsearch/xpack/graph/rest/action/RestGraphAction.java index 39a293a6cf6df..8b50b69ae0d66 100644 --- a/x-pack/plugin/graph/src/main/java/org/elasticsearch/xpack/graph/rest/action/RestGraphAction.java +++ b/x-pack/plugin/graph/src/main/java/org/elasticsearch/xpack/graph/rest/action/RestGraphAction.java @@ -18,7 +18,6 @@ import org.elasticsearch.protocol.xpack.graph.GraphExploreRequest.TermBoost; import org.elasticsearch.protocol.xpack.graph.Hop; import org.elasticsearch.protocol.xpack.graph.VertexRequest; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.XPackClient; @@ -27,8 +26,12 @@ import java.io.IOException; import java.util.HashMap; import java.util.HashSet; +import java.util.List; import java.util.Map; +import static java.util.Arrays.asList; +import static java.util.Collections.emptyList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.index.query.AbstractQueryBuilder.parseInnerQueryBuilder; import static org.elasticsearch.rest.RestRequest.Method.GET; import static org.elasticsearch.rest.RestRequest.Method.POST; @@ -62,23 +65,22 @@ public class RestGraphAction extends XPackRestHandler { public static final ParseField BOOST_FIELD = new ParseField("boost"); public static final ParseField TERM_FIELD = new ParseField("term"); - public RestGraphAction(RestController controller) { - // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - GET, "/{index}/_graph/explore", this, - GET, "/{index}" + URI_BASE + "/graph/_explore", deprecationLogger); - // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - POST, "/{index}/_graph/explore", this, - POST, "/{index}" + URI_BASE + "/graph/_explore", deprecationLogger); - // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - GET, "/{index}/{type}/_graph/explore", this, - GET, "/{index}/{type}" + URI_BASE + "/graph/_explore", deprecationLogger); - // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - POST, "/{index}/{type}/_graph/explore", this, - POST, "/{index}/{type}" + URI_BASE + "/graph/_explore", deprecationLogger); + @Override + public List routes() { + return emptyList(); + } + + @Override + public List replacedRoutes() { + return unmodifiableList(asList( + new ReplacedRoute(GET, "/{index}/_graph/explore", GET, "/{index}" + URI_BASE + "/graph/_explore", deprecationLogger), + new ReplacedRoute(POST, "/{index}/_graph/explore", POST, "/{index}" + URI_BASE + "/graph/_explore", deprecationLogger), + new ReplacedRoute( + GET, "/{index}/{type}/_graph/explore", + GET, "/{index}/{type}" + URI_BASE + "/graph/_explore", deprecationLogger), + new ReplacedRoute( + POST, "/{index}/{type}_graph/explore", + POST, "/{index}/{type}" + URI_BASE + "/graph/_explore", deprecationLogger))); } @Override diff --git a/x-pack/plugin/graph/src/test/java/org/elasticsearch/xpack/graph/rest/action/RestGraphActionTests.java b/x-pack/plugin/graph/src/test/java/org/elasticsearch/xpack/graph/rest/action/RestGraphActionTests.java index fb91e6fc5ee8a..b457f536eb24c 100644 --- a/x-pack/plugin/graph/src/test/java/org/elasticsearch/xpack/graph/rest/action/RestGraphActionTests.java +++ b/x-pack/plugin/graph/src/test/java/org/elasticsearch/xpack/graph/rest/action/RestGraphActionTests.java @@ -17,7 +17,7 @@ public class RestGraphActionTests extends RestActionTestCase { @Before public void setUpAction() { - new RestGraphAction(controller()); + controller().registerHandler(new RestGraphAction()); } public void testTypeInPath() { diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IndexLifecycle.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IndexLifecycle.java index 6b479c4b2b570..ca92b70644c47 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IndexLifecycle.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IndexLifecycle.java @@ -258,29 +258,29 @@ public List getRestHandlers(Settings settings, RestController restC List handlers = new ArrayList<>(); if (ilmEnabled) { handlers.addAll(Arrays.asList( - new RestPutLifecycleAction(restController), - new RestGetLifecycleAction(restController), - new RestDeleteLifecycleAction(restController), - new RestExplainLifecycleAction(restController), - new RestRemoveIndexLifecyclePolicyAction(restController), - new RestMoveToStepAction(restController), - new RestRetryAction(restController), - new RestStopAction(restController), - new RestStartILMAction(restController), - new RestGetStatusAction(restController) + new RestPutLifecycleAction(), + new RestGetLifecycleAction(), + new RestDeleteLifecycleAction(), + new RestExplainLifecycleAction(), + new RestRemoveIndexLifecyclePolicyAction(), + new RestMoveToStepAction(), + new RestRetryAction(), + new RestStopAction(), + new RestStartILMAction(), + new RestGetStatusAction() )); } if (slmEnabled) { handlers.addAll(Arrays.asList( - new RestPutSnapshotLifecycleAction(restController), - new RestDeleteSnapshotLifecycleAction(restController), - new RestGetSnapshotLifecycleAction(restController), - new RestExecuteSnapshotLifecycleAction(restController), - new RestGetSnapshotLifecycleStatsAction(restController), - new RestExecuteSnapshotRetentionAction(restController), - new RestStopSLMAction(restController), - new RestStartSLMAction(restController), - new RestGetSLMStatusAction(restController) + new RestPutSnapshotLifecycleAction(), + new RestDeleteSnapshotLifecycleAction(), + new RestGetSnapshotLifecycleAction(), + new RestExecuteSnapshotLifecycleAction(), + new RestGetSnapshotLifecycleStatsAction(), + new RestExecuteSnapshotRetentionAction(), + new RestStopSLMAction(), + new RestStartSLMAction(), + new RestGetSLMStatusAction() )); } return handlers; diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/RestDeleteLifecycleAction.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/RestDeleteLifecycleAction.java index 999eaafdb03bf..e2155b0b1698b 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/RestDeleteLifecycleAction.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/RestDeleteLifecycleAction.java @@ -8,15 +8,20 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.ilm.action.DeleteLifecycleAction; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.DELETE; + public class RestDeleteLifecycleAction extends BaseRestHandler { - public RestDeleteLifecycleAction(RestController controller) { - controller.registerHandler(RestRequest.Method.DELETE, "/_ilm/policy/{name}", this); + @Override + public List routes() { + return singletonList(new Route(DELETE, "/_ilm/policy/{name}")); } @Override diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/RestExplainLifecycleAction.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/RestExplainLifecycleAction.java index d8fb127755208..68b843794274a 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/RestExplainLifecycleAction.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/RestExplainLifecycleAction.java @@ -10,16 +10,21 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.Strings; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.ilm.ExplainLifecycleRequest; import org.elasticsearch.xpack.core.ilm.action.ExplainLifecycleAction; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.GET; + public class RestExplainLifecycleAction extends BaseRestHandler { - public RestExplainLifecycleAction(RestController controller) { - controller.registerHandler(RestRequest.Method.GET, "/{index}/_ilm/explain", this); + @Override + public List routes() { + return singletonList(new Route(GET, "/{index}/_ilm/explain")); } @Override diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/RestGetLifecycleAction.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/RestGetLifecycleAction.java index 794de5d576347..df4af5ff58957 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/RestGetLifecycleAction.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/RestGetLifecycleAction.java @@ -9,16 +9,23 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.Strings; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.ilm.action.GetLifecycleAction; +import java.util.List; + +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; +import static org.elasticsearch.rest.RestRequest.Method.GET; + public class RestGetLifecycleAction extends BaseRestHandler { - public RestGetLifecycleAction(RestController controller) { - controller.registerHandler(RestRequest.Method.GET, "/_ilm/policy", this); - controller.registerHandler(RestRequest.Method.GET, "/_ilm/policy/{name}", this); + @Override + public List routes() { + return unmodifiableList(asList( + new Route(GET, "/_ilm/policy"), + new Route(GET, "/_ilm/policy/{name}"))); } @Override diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/RestGetStatusAction.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/RestGetStatusAction.java index 5ff3c046321e7..1eb822ba765c3 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/RestGetStatusAction.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/RestGetStatusAction.java @@ -8,15 +8,20 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.ilm.action.GetStatusAction; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.GET; + public class RestGetStatusAction extends BaseRestHandler { - public RestGetStatusAction(RestController controller) { - controller.registerHandler(RestRequest.Method.GET, "/_ilm/status", this); + @Override + public List routes() { + return singletonList(new Route(GET, "/_ilm/status")); } @Override diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/RestMoveToStepAction.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/RestMoveToStepAction.java index 44a765b0c6aa8..0f072787d3f5f 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/RestMoveToStepAction.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/RestMoveToStepAction.java @@ -10,17 +10,21 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.ilm.action.MoveToStepAction; import java.io.IOException; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.POST; public class RestMoveToStepAction extends BaseRestHandler { - public RestMoveToStepAction(RestController controller) { - controller.registerHandler(RestRequest.Method.POST,"/_ilm/move/{name}", this); + @Override + public List routes() { + return singletonList(new Route(POST, "/_ilm/move/{name}")); } @Override diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/RestPutLifecycleAction.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/RestPutLifecycleAction.java index 5e357c9535efd..9f2f199ca6025 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/RestPutLifecycleAction.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/RestPutLifecycleAction.java @@ -9,17 +9,21 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.ilm.action.PutLifecycleAction; import java.io.IOException; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.PUT; public class RestPutLifecycleAction extends BaseRestHandler { - public RestPutLifecycleAction(RestController controller) { - controller.registerHandler(RestRequest.Method.PUT, "/_ilm/policy/{name}", this); + @Override + public List routes() { + return singletonList(new Route(PUT, "/_ilm/policy/{name}")); } @Override diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/RestRemoveIndexLifecyclePolicyAction.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/RestRemoveIndexLifecyclePolicyAction.java index 7bca784878b49..b10b2e4e282f8 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/RestRemoveIndexLifecyclePolicyAction.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/RestRemoveIndexLifecyclePolicyAction.java @@ -10,15 +10,20 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.Strings; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.ilm.action.RemoveIndexLifecyclePolicyAction; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.POST; + public class RestRemoveIndexLifecyclePolicyAction extends BaseRestHandler { - public RestRemoveIndexLifecyclePolicyAction(RestController controller) { - controller.registerHandler(RestRequest.Method.POST, "/{index}/_ilm/remove", this); + @Override + public List routes() { + return singletonList(new Route(POST, "/{index}/_ilm/remove")); } @Override diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/RestRetryAction.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/RestRetryAction.java index e14e1dac049b2..765ba44d1ffd3 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/RestRetryAction.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/RestRetryAction.java @@ -11,15 +11,20 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.Strings; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.ilm.action.RetryAction; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.POST; + public class RestRetryAction extends BaseRestHandler { - public RestRetryAction(RestController controller) { - controller.registerHandler(RestRequest.Method.POST, "/{index}/_ilm/retry", this); + @Override + public List routes() { + return singletonList(new Route(POST, "/{index}/_ilm/retry")); } @Override diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/RestStartILMAction.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/RestStartILMAction.java index b240a5e274e05..f60ae2297d7fe 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/RestStartILMAction.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/RestStartILMAction.java @@ -8,16 +8,21 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.ilm.StartILMRequest; import org.elasticsearch.xpack.core.ilm.action.StartILMAction; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.POST; + public class RestStartILMAction extends BaseRestHandler { - public RestStartILMAction(RestController controller) { - controller.registerHandler(RestRequest.Method.POST, "/_ilm/start", this); + @Override + public List routes() { + return singletonList(new Route(POST, "/_ilm/start")); } @Override diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/RestStopAction.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/RestStopAction.java index 3843d4da773a6..8b748ee677ffe 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/RestStopAction.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/RestStopAction.java @@ -8,16 +8,21 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.ilm.StopILMRequest; import org.elasticsearch.xpack.core.ilm.action.StopILMAction; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.POST; + public class RestStopAction extends BaseRestHandler { - public RestStopAction(RestController controller) { - controller.registerHandler(RestRequest.Method.POST, "/_ilm/stop", this); + @Override + public List routes() { + return singletonList(new Route(POST, "/_ilm/stop")); } @Override diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/action/RestDeleteSnapshotLifecycleAction.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/action/RestDeleteSnapshotLifecycleAction.java index 658816d2bab82..fad46639bcc0f 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/action/RestDeleteSnapshotLifecycleAction.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/action/RestDeleteSnapshotLifecycleAction.java @@ -8,15 +8,20 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.slm.action.DeleteSnapshotLifecycleAction; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.DELETE; + public class RestDeleteSnapshotLifecycleAction extends BaseRestHandler { - public RestDeleteSnapshotLifecycleAction(RestController controller) { - controller.registerHandler(RestRequest.Method.DELETE, "/_slm/policy/{name}", this); + @Override + public List routes() { + return singletonList(new Route(DELETE, "/_slm/policy/{name}")); } @Override diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/action/RestExecuteSnapshotLifecycleAction.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/action/RestExecuteSnapshotLifecycleAction.java index 72eceee0f8ecc..093c52ffbe3ce 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/action/RestExecuteSnapshotLifecycleAction.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/action/RestExecuteSnapshotLifecycleAction.java @@ -8,16 +8,24 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.slm.action.ExecuteSnapshotLifecycleAction; +import java.util.List; + +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; +import static org.elasticsearch.rest.RestRequest.Method.POST; +import static org.elasticsearch.rest.RestRequest.Method.PUT; + public class RestExecuteSnapshotLifecycleAction extends BaseRestHandler { - public RestExecuteSnapshotLifecycleAction(RestController controller) { - controller.registerHandler(RestRequest.Method.PUT, "/_slm/policy/{name}/_execute", this); - controller.registerHandler(RestRequest.Method.POST, "/_slm/policy/{name}/_execute", this); + @Override + public List routes() { + return unmodifiableList(asList( + new Route(POST, "/_slm/policy/{name}/_execute"), + new Route(PUT, "/_slm/policy/{name}/_execute"))); } @Override diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/action/RestExecuteSnapshotRetentionAction.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/action/RestExecuteSnapshotRetentionAction.java index 8bf2e3e870e1d..326ee5294e52c 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/action/RestExecuteSnapshotRetentionAction.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/action/RestExecuteSnapshotRetentionAction.java @@ -8,15 +8,20 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.slm.action.ExecuteSnapshotRetentionAction; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.POST; + public class RestExecuteSnapshotRetentionAction extends BaseRestHandler { - public RestExecuteSnapshotRetentionAction(RestController controller) { - controller.registerHandler(RestRequest.Method.POST, "/_slm/_execute_retention", this); + @Override + public List routes() { + return singletonList(new Route(POST, "/_slm/_execute_retention")); } @Override diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/action/RestGetSLMStatusAction.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/action/RestGetSLMStatusAction.java index 26f3197a76125..f728fb314ddce 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/action/RestGetSLMStatusAction.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/action/RestGetSLMStatusAction.java @@ -8,15 +8,20 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.slm.action.GetSLMStatusAction; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.GET; + public class RestGetSLMStatusAction extends BaseRestHandler { - public RestGetSLMStatusAction(RestController controller) { - controller.registerHandler(RestRequest.Method.GET, "/_slm/status", this); + @Override + public List routes() { + return singletonList(new Route(GET, "/_slm/status")); } @Override diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/action/RestGetSnapshotLifecycleAction.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/action/RestGetSnapshotLifecycleAction.java index cd2e67bb732a1..6b7841802599a 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/action/RestGetSnapshotLifecycleAction.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/action/RestGetSnapshotLifecycleAction.java @@ -9,16 +9,23 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.Strings; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.slm.action.GetSnapshotLifecycleAction; +import java.util.List; + +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; +import static org.elasticsearch.rest.RestRequest.Method.GET; + public class RestGetSnapshotLifecycleAction extends BaseRestHandler { - public RestGetSnapshotLifecycleAction(RestController controller) { - controller.registerHandler(RestRequest.Method.GET, "/_slm/policy", this); - controller.registerHandler(RestRequest.Method.GET, "/_slm/policy/{name}", this); + @Override + public List routes() { + return unmodifiableList(asList( + new Route(GET, "/_slm/policy"), + new Route(GET, "/_slm/policy/{name}"))); } @Override diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/action/RestGetSnapshotLifecycleStatsAction.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/action/RestGetSnapshotLifecycleStatsAction.java index b8629c2db5760..688c271a16544 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/action/RestGetSnapshotLifecycleStatsAction.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/action/RestGetSnapshotLifecycleStatsAction.java @@ -8,15 +8,20 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.slm.action.GetSnapshotLifecycleStatsAction; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.GET; + public class RestGetSnapshotLifecycleStatsAction extends BaseRestHandler { - public RestGetSnapshotLifecycleStatsAction(RestController controller) { - controller.registerHandler(RestRequest.Method.GET, "/_slm/stats", this); + @Override + public List routes() { + return singletonList(new Route(GET, "/_slm/stats")); } @Override diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/action/RestPutSnapshotLifecycleAction.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/action/RestPutSnapshotLifecycleAction.java index a5183739f3f5b..c4416c2eb6d6c 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/action/RestPutSnapshotLifecycleAction.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/action/RestPutSnapshotLifecycleAction.java @@ -9,17 +9,21 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.slm.action.PutSnapshotLifecycleAction; import java.io.IOException; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.PUT; public class RestPutSnapshotLifecycleAction extends BaseRestHandler { - public RestPutSnapshotLifecycleAction(RestController controller) { - controller.registerHandler(RestRequest.Method.PUT, "/_slm/policy/{name}", this); + @Override + public List routes() { + return singletonList(new Route(PUT, "/_slm/policy/{name}")); } @Override diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/action/RestStartSLMAction.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/action/RestStartSLMAction.java index 87dc7d2bb2279..da71efbe504b2 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/action/RestStartSLMAction.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/action/RestStartSLMAction.java @@ -8,15 +8,20 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.slm.action.StartSLMAction; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.POST; + public class RestStartSLMAction extends BaseRestHandler { - public RestStartSLMAction(RestController controller) { - controller.registerHandler(RestRequest.Method.POST, "/_slm/start", this); + @Override + public List routes() { + return singletonList(new Route(POST, "/_slm/start")); } @Override diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/action/RestStopSLMAction.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/action/RestStopSLMAction.java index ac74b37d58751..1a0af84c31f74 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/action/RestStopSLMAction.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/action/RestStopSLMAction.java @@ -8,15 +8,20 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.slm.action.StopSLMAction; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.POST; + public class RestStopSLMAction extends BaseRestHandler { - public RestStopSLMAction(RestController controller) { - controller.registerHandler(RestRequest.Method.POST, "/_slm/stop", this); + @Override + public List routes() { + return singletonList(new Route(POST, "/_slm/stop")); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/MachineLearning.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/MachineLearning.java index 0ad37eac88436..7a0b23eded78a 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/MachineLearning.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/MachineLearning.java @@ -727,68 +727,68 @@ public List getRestHandlers(Settings settings, RestController restC return emptyList(); } return Arrays.asList( - new RestGetJobsAction(restController), - new RestGetJobStatsAction(restController), - new RestMlInfoAction(restController), - new RestPutJobAction(restController), - new RestPostJobUpdateAction(restController), - new RestDeleteJobAction(restController), - new RestOpenJobAction(restController), - new RestGetFiltersAction(restController), - new RestPutFilterAction(restController), - new RestUpdateFilterAction(restController), - new RestDeleteFilterAction(restController), - new RestGetInfluencersAction(restController), - new RestGetRecordsAction(restController), - new RestGetBucketsAction(restController), - new RestGetOverallBucketsAction(restController), - new RestPostDataAction(restController), - new RestCloseJobAction(restController), - new RestFlushJobAction(restController), - new RestValidateDetectorAction(restController), - new RestValidateJobConfigAction(restController), - new RestGetCategoriesAction(restController), - new RestGetModelSnapshotsAction(restController), - new RestRevertModelSnapshotAction(restController), - new RestUpdateModelSnapshotAction(restController), - new RestGetDatafeedsAction(restController), - new RestGetDatafeedStatsAction(restController), - new RestPutDatafeedAction(restController), - new RestUpdateDatafeedAction(restController), - new RestDeleteDatafeedAction(restController), - new RestPreviewDatafeedAction(restController), - new RestStartDatafeedAction(restController), - new RestStopDatafeedAction(restController), - new RestDeleteModelSnapshotAction(restController), - new RestDeleteExpiredDataAction(restController), - new RestForecastJobAction(restController), - new RestDeleteForecastAction(restController), - new RestGetCalendarsAction(restController), - new RestPutCalendarAction(restController), - new RestDeleteCalendarAction(restController), - new RestDeleteCalendarEventAction(restController), - new RestDeleteCalendarJobAction(restController), - new RestPutCalendarJobAction(restController), - new RestGetCalendarEventsAction(restController), - new RestPostCalendarEventAction(restController), - new RestFindFileStructureAction(restController), - new RestSetUpgradeModeAction(restController), - new RestGetDataFrameAnalyticsAction(restController), - new RestGetDataFrameAnalyticsStatsAction(restController), - new RestPutDataFrameAnalyticsAction(restController), - new RestDeleteDataFrameAnalyticsAction(restController), - new RestStartDataFrameAnalyticsAction(restController), - new RestStopDataFrameAnalyticsAction(restController), - new RestEvaluateDataFrameAction(restController), - new RestExplainDataFrameAnalyticsAction(restController), - new RestGetTrainedModelsAction(restController), - new RestDeleteTrainedModelAction(restController), - new RestGetTrainedModelsStatsAction(restController), - new RestPutTrainedModelAction(restController), + new RestGetJobsAction(), + new RestGetJobStatsAction(), + new RestMlInfoAction(), + new RestPutJobAction(), + new RestPostJobUpdateAction(), + new RestDeleteJobAction(), + new RestOpenJobAction(), + new RestGetFiltersAction(), + new RestPutFilterAction(), + new RestUpdateFilterAction(), + new RestDeleteFilterAction(), + new RestGetInfluencersAction(), + new RestGetRecordsAction(), + new RestGetBucketsAction(), + new RestGetOverallBucketsAction(), + new RestPostDataAction(), + new RestCloseJobAction(), + new RestFlushJobAction(), + new RestValidateDetectorAction(), + new RestValidateJobConfigAction(), + new RestGetCategoriesAction(), + new RestGetModelSnapshotsAction(), + new RestRevertModelSnapshotAction(), + new RestUpdateModelSnapshotAction(), + new RestGetDatafeedsAction(), + new RestGetDatafeedStatsAction(), + new RestPutDatafeedAction(), + new RestUpdateDatafeedAction(), + new RestDeleteDatafeedAction(), + new RestPreviewDatafeedAction(), + new RestStartDatafeedAction(), + new RestStopDatafeedAction(), + new RestDeleteModelSnapshotAction(), + new RestDeleteExpiredDataAction(), + new RestForecastJobAction(), + new RestDeleteForecastAction(), + new RestGetCalendarsAction(), + new RestPutCalendarAction(), + new RestDeleteCalendarAction(), + new RestDeleteCalendarEventAction(), + new RestDeleteCalendarJobAction(), + new RestPutCalendarJobAction(), + new RestGetCalendarEventsAction(), + new RestPostCalendarEventAction(), + new RestFindFileStructureAction(), + new RestSetUpgradeModeAction(), + new RestGetDataFrameAnalyticsAction(), + new RestGetDataFrameAnalyticsStatsAction(), + new RestPutDataFrameAnalyticsAction(), + new RestDeleteDataFrameAnalyticsAction(), + new RestStartDataFrameAnalyticsAction(), + new RestStopDataFrameAnalyticsAction(), + new RestEvaluateDataFrameAction(), + new RestExplainDataFrameAnalyticsAction(), + new RestGetTrainedModelsAction(), + new RestDeleteTrainedModelAction(), + new RestGetTrainedModelsStatsAction(), + new RestPutTrainedModelAction(), // CAT Handlers - new RestCatJobsAction(restController), - new RestCatTrainedModelsAction(restController), - new RestCatDatafeedsAction(restController) + new RestCatJobsAction(), + new RestCatTrainedModelsAction(), + new RestCatDatafeedsAction() ); } diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/RestDeleteExpiredDataAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/RestDeleteExpiredDataAction.java index d3f024e27e854..11ca99d9d3a5c 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/RestDeleteExpiredDataAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/RestDeleteExpiredDataAction.java @@ -9,13 +9,14 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.ml.action.DeleteExpiredDataAction; import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.DELETE; @@ -24,11 +25,19 @@ public class RestDeleteExpiredDataAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestDeleteExpiredDataAction.class)); - public RestDeleteExpiredDataAction(RestController controller) { + @Override + public List routes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - DELETE, MachineLearning.BASE_PATH + "_delete_expired_data", this, - DELETE, MachineLearning.PRE_V7_BASE_PATH + "_delete_expired_data", deprecationLogger); + return Collections.singletonList( + new ReplacedRoute(DELETE, MachineLearning.BASE_PATH + "_delete_expired_data", + DELETE, MachineLearning.PRE_V7_BASE_PATH + "_delete_expired_data", + deprecationLogger) + ); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/RestFindFileStructureAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/RestFindFileStructureAction.java index b0e564095ec46..94e7ffc15c668 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/RestFindFileStructureAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/RestFindFileStructureAction.java @@ -11,7 +11,6 @@ import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.ml.action.FindFileStructureAction; @@ -21,6 +20,7 @@ import java.io.IOException; import java.util.Collections; +import java.util.List; import java.util.Set; import java.util.concurrent.TimeUnit; @@ -33,11 +33,19 @@ public class RestFindFileStructureAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestFindFileStructureAction.class)); - public RestFindFileStructureAction(RestController controller) { + @Override + public List routes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - POST, MachineLearning.BASE_PATH + "find_file_structure", this, - POST, MachineLearning.PRE_V7_BASE_PATH + "find_file_structure", deprecationLogger); + return Collections.singletonList( + new ReplacedRoute(POST, MachineLearning.BASE_PATH + "find_file_structure", + POST, MachineLearning.PRE_V7_BASE_PATH + "find_file_structure", + deprecationLogger) + ); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/RestMlInfoAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/RestMlInfoAction.java index 1d775d156edea..c29b3ad685015 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/RestMlInfoAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/RestMlInfoAction.java @@ -9,13 +9,14 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.ml.action.MlInfoAction; import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.GET; @@ -24,11 +25,19 @@ public class RestMlInfoAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestMlInfoAction.class)); - public RestMlInfoAction(RestController controller) { + @Override + public List routes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - GET, MachineLearning.BASE_PATH + "info", this, - GET, MachineLearning.PRE_V7_BASE_PATH + "info", deprecationLogger); + return Collections.singletonList( + new ReplacedRoute(GET, MachineLearning.BASE_PATH + "info", + GET, MachineLearning.PRE_V7_BASE_PATH + "info", + deprecationLogger) + ); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/RestSetUpgradeModeAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/RestSetUpgradeModeAction.java index 1d8d28a4d448b..31bc22e99c403 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/RestSetUpgradeModeAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/RestSetUpgradeModeAction.java @@ -9,13 +9,14 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.ml.action.SetUpgradeModeAction; import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.POST; @@ -24,11 +25,19 @@ public class RestSetUpgradeModeAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestSetUpgradeModeAction.class)); - public RestSetUpgradeModeAction(RestController controller) { + @Override + public List routes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - POST, MachineLearning.BASE_PATH + "set_upgrade_mode", this, - POST, MachineLearning.PRE_V7_BASE_PATH + "set_upgrade_mode", deprecationLogger); + return Collections.singletonList( + new ReplacedRoute(POST, MachineLearning.BASE_PATH + "set_upgrade_mode", + POST, MachineLearning.PRE_V7_BASE_PATH + "set_upgrade_mode", + deprecationLogger) + ); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/calendar/RestDeleteCalendarAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/calendar/RestDeleteCalendarAction.java index 95ec620e0177a..58f5fff7b44a6 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/calendar/RestDeleteCalendarAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/calendar/RestDeleteCalendarAction.java @@ -9,7 +9,6 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.ml.action.DeleteCalendarAction; @@ -17,6 +16,8 @@ import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.DELETE; @@ -25,11 +26,18 @@ public class RestDeleteCalendarAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestDeleteCalendarAction.class)); - public RestDeleteCalendarAction(RestController controller) { + @Override + public List routes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - DELETE, MachineLearning.BASE_PATH + "calendars/{" + Calendar.ID.getPreferredName() + "}", this, - DELETE, MachineLearning.PRE_V7_BASE_PATH + "calendars/{" + Calendar.ID.getPreferredName() + "}", deprecationLogger); + return Collections.singletonList( + new ReplacedRoute(DELETE, MachineLearning.BASE_PATH + "calendars/{" + Calendar.ID.getPreferredName() + "}", + DELETE, MachineLearning.PRE_V7_BASE_PATH + "calendars/{" + Calendar.ID.getPreferredName() + "}", deprecationLogger) + ); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/calendar/RestDeleteCalendarEventAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/calendar/RestDeleteCalendarEventAction.java index da30978461d9b..9fbc3b3ba50fb 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/calendar/RestDeleteCalendarEventAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/calendar/RestDeleteCalendarEventAction.java @@ -9,7 +9,6 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.ml.action.DeleteCalendarEventAction; @@ -18,6 +17,8 @@ import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.DELETE; @@ -26,13 +27,20 @@ public class RestDeleteCalendarEventAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestDeleteCalendarEventAction.class)); - public RestDeleteCalendarEventAction(RestController controller) { + @Override + public List routes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - DELETE, MachineLearning.BASE_PATH + "calendars/{" + Calendar.ID.getPreferredName() + "}/events/{" + - ScheduledEvent.EVENT_ID.getPreferredName() + "}", this, - DELETE, MachineLearning.PRE_V7_BASE_PATH + "calendars/{" + Calendar.ID.getPreferredName() + "}/events/{" + - ScheduledEvent.EVENT_ID.getPreferredName() + "}", deprecationLogger); + return Collections.singletonList( + new ReplacedRoute(DELETE, MachineLearning.BASE_PATH + "calendars/{" + Calendar.ID.getPreferredName() + "}/events/{" + + ScheduledEvent.EVENT_ID.getPreferredName() + "}", + DELETE, MachineLearning.PRE_V7_BASE_PATH + "calendars/{" + Calendar.ID.getPreferredName() + "}/events/{" + + ScheduledEvent.EVENT_ID.getPreferredName() + "}", deprecationLogger) + ); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/calendar/RestDeleteCalendarJobAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/calendar/RestDeleteCalendarJobAction.java index 213d3f712f961..61fbda4f3f2a3 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/calendar/RestDeleteCalendarJobAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/calendar/RestDeleteCalendarJobAction.java @@ -9,7 +9,6 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.ml.action.UpdateCalendarJobAction; @@ -18,6 +17,8 @@ import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.DELETE; @@ -26,13 +27,20 @@ public class RestDeleteCalendarJobAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestDeleteCalendarJobAction.class)); - public RestDeleteCalendarJobAction(RestController controller) { + @Override + public List routes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - DELETE, MachineLearning.BASE_PATH + "calendars/{" + Calendar.ID.getPreferredName() + "}/jobs/{" + - Job.ID.getPreferredName() + "}", this, - DELETE, MachineLearning.PRE_V7_BASE_PATH + "calendars/{" + Calendar.ID.getPreferredName() + "}/jobs/{" + - Job.ID.getPreferredName() + "}", deprecationLogger); + return Collections.singletonList( + new ReplacedRoute(DELETE, MachineLearning.BASE_PATH + "calendars/{" + Calendar.ID.getPreferredName() + "}/jobs/{" + + Job.ID.getPreferredName() + "}", + DELETE, MachineLearning.PRE_V7_BASE_PATH + "calendars/{" + Calendar.ID.getPreferredName() + "}/jobs/{" + + Job.ID.getPreferredName() + "}", deprecationLogger) + ); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/calendar/RestGetCalendarEventsAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/calendar/RestGetCalendarEventsAction.java index c299d23ac58fe..c3baeebfbee9c 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/calendar/RestGetCalendarEventsAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/calendar/RestGetCalendarEventsAction.java @@ -10,7 +10,6 @@ import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.action.util.PageParams; @@ -20,6 +19,8 @@ import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.GET; @@ -28,11 +29,18 @@ public class RestGetCalendarEventsAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestGetCalendarEventsAction.class)); - public RestGetCalendarEventsAction(RestController controller) { + @Override + public List routes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - GET, MachineLearning.BASE_PATH + "calendars/{" + Calendar.ID.getPreferredName() + "}/events", this, - GET, MachineLearning.PRE_V7_BASE_PATH + "calendars/{" + Calendar.ID.getPreferredName() + "}/events", deprecationLogger); + return Collections.singletonList( + new ReplacedRoute(GET, MachineLearning.BASE_PATH + "calendars/{" + Calendar.ID.getPreferredName() + "}/events", + GET, MachineLearning.PRE_V7_BASE_PATH + "calendars/{" + Calendar.ID.getPreferredName() + "}/events", deprecationLogger) + ); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/calendar/RestGetCalendarsAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/calendar/RestGetCalendarsAction.java index 46e4d23cd6846..eb2e74b309b15 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/calendar/RestGetCalendarsAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/calendar/RestGetCalendarsAction.java @@ -11,7 +11,6 @@ import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestStatusToXContentListener; import org.elasticsearch.xpack.core.action.util.PageParams; @@ -20,6 +19,9 @@ import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.GET; import static org.elasticsearch.rest.RestRequest.Method.POST; @@ -29,22 +31,24 @@ public class RestGetCalendarsAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestGetCalendarsAction.class)); - public RestGetCalendarsAction(RestController controller) { - // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - GET, MachineLearning.BASE_PATH + "calendars/{" + Calendar.ID.getPreferredName() + "}", this, - GET, MachineLearning.PRE_V7_BASE_PATH + "calendars/{" + Calendar.ID.getPreferredName() + "}", deprecationLogger); - controller.registerWithDeprecatedHandler( - GET, MachineLearning.BASE_PATH + "calendars/", this, - GET, MachineLearning.PRE_V7_BASE_PATH + "calendars/", deprecationLogger); + @Override + public List routes() { + return Collections.emptyList(); + } - // endpoints that support body parameters must also accept POST - controller.registerWithDeprecatedHandler( - POST, MachineLearning.BASE_PATH + "calendars/{" + Calendar.ID.getPreferredName() + "}", this, - POST, MachineLearning.PRE_V7_BASE_PATH + "calendars/{" + Calendar.ID.getPreferredName() + "}", deprecationLogger); - controller.registerWithDeprecatedHandler( - POST, MachineLearning.BASE_PATH + "calendars/", this, - POST, MachineLearning.PRE_V7_BASE_PATH + "calendars/", deprecationLogger); + @Override + public List replacedRoutes() { + // TODO: remove deprecated endpoint in 8.0.0 + return Collections.unmodifiableList(Arrays.asList( + new ReplacedRoute(GET, MachineLearning.BASE_PATH + "calendars/{" + Calendar.ID.getPreferredName() + "}", + GET, MachineLearning.PRE_V7_BASE_PATH + "calendars/{" + Calendar.ID.getPreferredName() + "}", deprecationLogger), + new ReplacedRoute(GET, MachineLearning.BASE_PATH + "calendars/", + GET, MachineLearning.PRE_V7_BASE_PATH + "calendars/", deprecationLogger), + new ReplacedRoute(POST, MachineLearning.BASE_PATH + "calendars/{" + Calendar.ID.getPreferredName() + "}", + POST, MachineLearning.PRE_V7_BASE_PATH + "calendars/{" + Calendar.ID.getPreferredName() + "}", deprecationLogger), + new ReplacedRoute(POST, MachineLearning.BASE_PATH + "calendars/", + POST, MachineLearning.PRE_V7_BASE_PATH + "calendars/", deprecationLogger) + )); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/calendar/RestPostCalendarEventAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/calendar/RestPostCalendarEventAction.java index 5ad91ffd92fc2..dfab91e85cb8c 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/calendar/RestPostCalendarEventAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/calendar/RestPostCalendarEventAction.java @@ -10,7 +10,6 @@ import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.ml.action.PostCalendarEventsAction; @@ -18,6 +17,8 @@ import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.POST; @@ -26,11 +27,18 @@ public class RestPostCalendarEventAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestPostCalendarEventAction.class)); - public RestPostCalendarEventAction(RestController controller) { + @Override + public List routes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - POST, MachineLearning.BASE_PATH + "calendars/{" + Calendar.ID.getPreferredName() + "}/events", this, - POST, MachineLearning.PRE_V7_BASE_PATH + "calendars/{" + Calendar.ID.getPreferredName() + "}/events", deprecationLogger); + return Collections.singletonList( + new ReplacedRoute(POST, MachineLearning.BASE_PATH + "calendars/{" + Calendar.ID.getPreferredName() + "}/events", + POST, MachineLearning.PRE_V7_BASE_PATH + "calendars/{" + Calendar.ID.getPreferredName() + "}/events", deprecationLogger) + ); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/calendar/RestPutCalendarAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/calendar/RestPutCalendarAction.java index 553bb81cbf900..caba1a115cf75 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/calendar/RestPutCalendarAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/calendar/RestPutCalendarAction.java @@ -10,15 +10,15 @@ import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; -import org.elasticsearch.xpack.ml.MachineLearning; import org.elasticsearch.xpack.core.ml.action.PutCalendarAction; import org.elasticsearch.xpack.core.ml.calendars.Calendar; +import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.PUT; @@ -27,11 +27,18 @@ public class RestPutCalendarAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestPutCalendarAction.class)); - public RestPutCalendarAction(RestController controller) { + @Override + public List routes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - PUT, MachineLearning.BASE_PATH + "calendars/{" + Calendar.ID.getPreferredName() + "}", this, - PUT, MachineLearning.PRE_V7_BASE_PATH + "calendars/{" + Calendar.ID.getPreferredName() + "}", deprecationLogger); + return Collections.singletonList( + new ReplacedRoute(PUT, MachineLearning.BASE_PATH + "calendars/{" + Calendar.ID.getPreferredName() + "}", + PUT, MachineLearning.PRE_V7_BASE_PATH + "calendars/{" + Calendar.ID.getPreferredName() + "}", deprecationLogger) + ); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/calendar/RestPutCalendarJobAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/calendar/RestPutCalendarJobAction.java index ce47bc3a53a1d..4c8709742aa5c 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/calendar/RestPutCalendarJobAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/calendar/RestPutCalendarJobAction.java @@ -9,7 +9,6 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.ml.action.UpdateCalendarJobAction; @@ -18,6 +17,8 @@ import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.PUT; @@ -26,13 +27,22 @@ public class RestPutCalendarJobAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestPutCalendarJobAction.class)); - public RestPutCalendarJobAction(RestController controller) { + @Override + public List routes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - PUT, MachineLearning.BASE_PATH + "calendars/{" + Calendar.ID.getPreferredName() + "}/jobs/{" + - Job.ID.getPreferredName() + "}", this, - PUT, MachineLearning.PRE_V7_BASE_PATH + "calendars/{" + Calendar.ID.getPreferredName() + "}/jobs/{" + - Job.ID.getPreferredName() + "}", deprecationLogger); + return Collections.singletonList( + new ReplacedRoute(PUT, + MachineLearning.BASE_PATH + "calendars/{" + Calendar.ID.getPreferredName() + "}/jobs/{" + Job.ID.getPreferredName() + "}", + PUT, + MachineLearning.PRE_V7_BASE_PATH + "calendars/{" + Calendar.ID.getPreferredName() + "}/jobs/{" + + Job.ID.getPreferredName() + "}", + deprecationLogger) + ); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/cat/RestCatDatafeedsAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/cat/RestCatDatafeedsAction.java index 3410531ecef81..00114f4d30d66 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/cat/RestCatDatafeedsAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/cat/RestCatDatafeedsAction.java @@ -10,7 +10,6 @@ import org.elasticsearch.common.Strings; import org.elasticsearch.common.Table; import org.elasticsearch.common.unit.TimeValue; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.action.RestResponseListener; @@ -20,13 +19,19 @@ import org.elasticsearch.xpack.core.ml.datafeed.DatafeedConfig; import org.elasticsearch.xpack.core.ml.datafeed.DatafeedTimingStats; +import java.util.List; + +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.rest.RestRequest.Method.GET; public class RestCatDatafeedsAction extends AbstractCatAction { - public RestCatDatafeedsAction(RestController controller) { - controller.registerHandler(GET, "_cat/ml/datafeeds/{" + DatafeedConfig.ID.getPreferredName() + "}", this); - controller.registerHandler(GET, "_cat/ml/datafeeds", this); + @Override + public List routes() { + return unmodifiableList(asList( + new Route(GET, "_cat/ml/datafeeds/{" + DatafeedConfig.ID.getPreferredName() + "}"), + new Route(GET, "_cat/ml/datafeeds"))); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/cat/RestCatJobsAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/cat/RestCatJobsAction.java index 352e87afd476f..2595ab8d34cbf 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/cat/RestCatJobsAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/cat/RestCatJobsAction.java @@ -12,7 +12,6 @@ import org.elasticsearch.common.Table; import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.common.unit.TimeValue; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.action.RestResponseListener; @@ -25,13 +24,19 @@ import org.elasticsearch.xpack.core.ml.job.process.autodetect.state.TimingStats; import org.elasticsearch.xpack.core.ml.stats.ForecastStats; +import java.util.List; + +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.rest.RestRequest.Method.GET; public class RestCatJobsAction extends AbstractCatAction { - public RestCatJobsAction(RestController controller) { - controller.registerHandler(GET, "_cat/ml/anomaly_detectors/{" + Job.ID.getPreferredName() + "}", this); - controller.registerHandler(GET, "_cat/ml/anomaly_detectors", this); + @Override + public List routes() { + return unmodifiableList(asList( + new Route(GET, "_cat/ml/anomaly_detectors/{" + Job.ID.getPreferredName() + "}"), + new Route(GET, "_cat/ml/anomaly_detectors"))); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/cat/RestCatTrainedModelsAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/cat/RestCatTrainedModelsAction.java index 9f62a3bba786c..8a45b462ad0ba 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/cat/RestCatTrainedModelsAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/cat/RestCatTrainedModelsAction.java @@ -14,7 +14,6 @@ import org.elasticsearch.common.Table; import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.common.unit.TimeValue; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.action.RestResponseListener; @@ -38,14 +37,18 @@ import java.util.function.Function; import java.util.stream.Collectors; +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.rest.RestRequest.Method.GET; import static org.elasticsearch.xpack.core.ml.action.GetTrainedModelsAction.Request.ALLOW_NO_MATCH; public class RestCatTrainedModelsAction extends AbstractCatAction { - public RestCatTrainedModelsAction(RestController controller) { - controller.registerHandler(GET, "_cat/ml/trained_models/{" + TrainedModelConfig.MODEL_ID.getPreferredName() + "}", this); - controller.registerHandler(GET, "_cat/ml/trained_models", this); + @Override + public List routes() { + return unmodifiableList(asList( + new Route(GET, "_cat/ml/trained_models"), + new Route(GET, "_cat/ml/trained_models/{" + TrainedModelConfig.MODEL_ID.getPreferredName() + "}"))); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/datafeeds/RestDeleteDatafeedAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/datafeeds/RestDeleteDatafeedAction.java index 000b92426d887..e692688e30c90 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/datafeeds/RestDeleteDatafeedAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/datafeeds/RestDeleteDatafeedAction.java @@ -9,7 +9,6 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.ml.action.CloseJobAction; @@ -18,6 +17,8 @@ import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.DELETE; @@ -26,11 +27,18 @@ public class RestDeleteDatafeedAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestDeleteDatafeedAction.class)); - public RestDeleteDatafeedAction(RestController controller) { + @Override + public List routes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - DELETE, MachineLearning.BASE_PATH + "datafeeds/{" + DatafeedConfig.ID.getPreferredName() + "}", this, - DELETE, MachineLearning.PRE_V7_BASE_PATH + "datafeeds/{" + DatafeedConfig.ID.getPreferredName() + "}", deprecationLogger); + return Collections.singletonList( + new ReplacedRoute(DELETE, MachineLearning.BASE_PATH + "datafeeds/{" + DatafeedConfig.ID.getPreferredName() + "}", + DELETE, MachineLearning.PRE_V7_BASE_PATH + "datafeeds/{" + DatafeedConfig.ID.getPreferredName() + "}", deprecationLogger) + ); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/datafeeds/RestGetDatafeedStatsAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/datafeeds/RestGetDatafeedStatsAction.java index 65866074dfadf..3a617808d4fdd 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/datafeeds/RestGetDatafeedStatsAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/datafeeds/RestGetDatafeedStatsAction.java @@ -10,7 +10,6 @@ import org.elasticsearch.common.Strings; import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.ml.action.GetDatafeedsStatsAction; @@ -18,6 +17,9 @@ import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.GET; @@ -26,14 +28,21 @@ public class RestGetDatafeedStatsAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestGetDatafeedStatsAction.class)); - public RestGetDatafeedStatsAction(RestController controller) { + @Override + public List routes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - GET, MachineLearning.BASE_PATH + "datafeeds/{" + DatafeedConfig.ID.getPreferredName() + "}/_stats", this, - GET, MachineLearning.PRE_V7_BASE_PATH + "datafeeds/{" + DatafeedConfig.ID.getPreferredName() + "}/_stats", deprecationLogger); - controller.registerWithDeprecatedHandler( - GET, MachineLearning.BASE_PATH + "datafeeds/_stats", this, - GET, MachineLearning.PRE_V7_BASE_PATH + "datafeeds/_stats", deprecationLogger); + return Collections.unmodifiableList(Arrays.asList( + new ReplacedRoute(GET, MachineLearning.BASE_PATH + "datafeeds/{" + DatafeedConfig.ID.getPreferredName() + "}/_stats", + GET, MachineLearning.PRE_V7_BASE_PATH + "datafeeds/{" + DatafeedConfig.ID.getPreferredName() + "}/_stats", + deprecationLogger), + new ReplacedRoute(GET, MachineLearning.BASE_PATH + "datafeeds/_stats", + GET, MachineLearning.PRE_V7_BASE_PATH + "datafeeds/_stats", deprecationLogger) + )); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/datafeeds/RestGetDatafeedsAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/datafeeds/RestGetDatafeedsAction.java index 1ed7ce33ef887..19a4de3dd1401 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/datafeeds/RestGetDatafeedsAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/datafeeds/RestGetDatafeedsAction.java @@ -9,7 +9,6 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.ml.action.GetDatafeedsAction; @@ -17,6 +16,9 @@ import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.GET; @@ -25,14 +27,20 @@ public class RestGetDatafeedsAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestGetDatafeedsAction.class)); - public RestGetDatafeedsAction(RestController controller) { + @Override + public List routes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - GET, MachineLearning.BASE_PATH + "datafeeds/{" + DatafeedConfig.ID.getPreferredName() + "}", this, - GET, MachineLearning.PRE_V7_BASE_PATH + "datafeeds/{" + DatafeedConfig.ID.getPreferredName() + "}", deprecationLogger); - controller.registerWithDeprecatedHandler( - GET, MachineLearning.BASE_PATH + "datafeeds", this, - GET, MachineLearning.PRE_V7_BASE_PATH + "datafeeds", deprecationLogger); + return Collections.unmodifiableList(Arrays.asList( + new ReplacedRoute(GET, MachineLearning.BASE_PATH + "datafeeds/{" + DatafeedConfig.ID.getPreferredName() + "}", + GET, MachineLearning.PRE_V7_BASE_PATH + "datafeeds/{" + DatafeedConfig.ID.getPreferredName() + "}", deprecationLogger), + new ReplacedRoute(GET, MachineLearning.BASE_PATH + "datafeeds", + GET, MachineLearning.PRE_V7_BASE_PATH + "datafeeds", deprecationLogger) + )); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/datafeeds/RestPreviewDatafeedAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/datafeeds/RestPreviewDatafeedAction.java index 6088f42f2d304..85b28bbc14382 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/datafeeds/RestPreviewDatafeedAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/datafeeds/RestPreviewDatafeedAction.java @@ -9,7 +9,6 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.ml.action.PreviewDatafeedAction; @@ -17,6 +16,8 @@ import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.GET; @@ -25,11 +26,19 @@ public class RestPreviewDatafeedAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestPreviewDatafeedAction.class)); - public RestPreviewDatafeedAction(RestController controller) { + @Override + public List routes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - GET, MachineLearning.BASE_PATH + "datafeeds/{" + DatafeedConfig.ID.getPreferredName() + "}/_preview", this, - GET, MachineLearning.PRE_V7_BASE_PATH + "datafeeds/{" + DatafeedConfig.ID.getPreferredName() + "}/_preview", deprecationLogger); + return Collections.singletonList( + new ReplacedRoute(GET, MachineLearning.BASE_PATH + "datafeeds/{" + DatafeedConfig.ID.getPreferredName() + "}/_preview", + GET, MachineLearning.PRE_V7_BASE_PATH + "datafeeds/{" + DatafeedConfig.ID.getPreferredName() + "}/_preview", + deprecationLogger) + ); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/datafeeds/RestPutDatafeedAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/datafeeds/RestPutDatafeedAction.java index 12e8863f68124..bff6f803ffbde 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/datafeeds/RestPutDatafeedAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/datafeeds/RestPutDatafeedAction.java @@ -10,7 +10,6 @@ import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.ml.action.PutDatafeedAction; @@ -18,6 +17,8 @@ import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.PUT; @@ -26,11 +27,19 @@ public class RestPutDatafeedAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestPutDatafeedAction.class)); - public RestPutDatafeedAction(RestController controller) { + @Override + public List routes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - PUT, MachineLearning.BASE_PATH + "datafeeds/{" + DatafeedConfig.ID.getPreferredName() + "}", this, - PUT, MachineLearning.PRE_V7_BASE_PATH + "datafeeds/{" + DatafeedConfig.ID.getPreferredName() + "}", deprecationLogger); + return Collections.singletonList( + new ReplacedRoute(PUT, MachineLearning.BASE_PATH + "datafeeds/{" + DatafeedConfig.ID.getPreferredName() + "}", + PUT, MachineLearning.PRE_V7_BASE_PATH + "datafeeds/{" + DatafeedConfig.ID.getPreferredName() + "}", + deprecationLogger) + ); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/datafeeds/RestStartDatafeedAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/datafeeds/RestStartDatafeedAction.java index 3dbe4ceb10055..2e61d71b29cab 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/datafeeds/RestStartDatafeedAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/datafeeds/RestStartDatafeedAction.java @@ -14,7 +14,6 @@ import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; @@ -24,6 +23,8 @@ import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.POST; @@ -34,11 +35,19 @@ public class RestStartDatafeedAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestStartDatafeedAction.class)); - public RestStartDatafeedAction(RestController controller) { + @Override + public List routes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - POST, MachineLearning.BASE_PATH + "datafeeds/{" + DatafeedConfig.ID.getPreferredName() + "}/_start", this, - POST, MachineLearning.PRE_V7_BASE_PATH + "datafeeds/{" + DatafeedConfig.ID.getPreferredName() + "}/_start", deprecationLogger); + return Collections.singletonList( + new ReplacedRoute(POST, MachineLearning.BASE_PATH + "datafeeds/{" + DatafeedConfig.ID.getPreferredName() + "}/_start", + POST, MachineLearning.PRE_V7_BASE_PATH + "datafeeds/{" + DatafeedConfig.ID.getPreferredName() + "}/_start", + deprecationLogger) + ); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/datafeeds/RestStopDatafeedAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/datafeeds/RestStopDatafeedAction.java index f1cc37e61a88d..efbc6d01a895c 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/datafeeds/RestStopDatafeedAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/datafeeds/RestStopDatafeedAction.java @@ -13,7 +13,6 @@ import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; @@ -24,6 +23,8 @@ import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.POST; @@ -32,11 +33,19 @@ public class RestStopDatafeedAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestStopDatafeedAction.class)); - public RestStopDatafeedAction(RestController controller) { + @Override + public List routes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - POST, MachineLearning.BASE_PATH + "datafeeds/{" + DatafeedConfig.ID.getPreferredName() + "}/_stop", this, - POST, MachineLearning.PRE_V7_BASE_PATH + "datafeeds/{" + DatafeedConfig.ID.getPreferredName() + "}/_stop", deprecationLogger); + return Collections.singletonList( + new ReplacedRoute(POST, MachineLearning.BASE_PATH + "datafeeds/{" + DatafeedConfig.ID.getPreferredName() + "}/_stop", + POST, MachineLearning.PRE_V7_BASE_PATH + "datafeeds/{" + DatafeedConfig.ID.getPreferredName() + "}/_stop", + deprecationLogger) + ); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/datafeeds/RestUpdateDatafeedAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/datafeeds/RestUpdateDatafeedAction.java index b36eb5e0078f8..6c4e03f39f969 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/datafeeds/RestUpdateDatafeedAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/datafeeds/RestUpdateDatafeedAction.java @@ -10,7 +10,6 @@ import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.ml.action.UpdateDatafeedAction; @@ -18,6 +17,8 @@ import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.POST; @@ -26,11 +27,19 @@ public class RestUpdateDatafeedAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestUpdateDatafeedAction.class)); - public RestUpdateDatafeedAction(RestController controller) { + @Override + public List routes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - POST, MachineLearning.BASE_PATH + "datafeeds/{" + DatafeedConfig.ID.getPreferredName() + "}/_update", this, - POST, MachineLearning.PRE_V7_BASE_PATH + "datafeeds/{" + DatafeedConfig.ID.getPreferredName() + "}/_update", deprecationLogger); + return Collections.singletonList( + new ReplacedRoute(POST, MachineLearning.BASE_PATH + "datafeeds/{" + DatafeedConfig.ID.getPreferredName() + "}/_update", + POST, MachineLearning.PRE_V7_BASE_PATH + "datafeeds/{" + DatafeedConfig.ID.getPreferredName() + "}/_update", + deprecationLogger) + ); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/dataframe/RestDeleteDataFrameAnalyticsAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/dataframe/RestDeleteDataFrameAnalyticsAction.java index 9e78a7cd9f214..3b898e870ad44 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/dataframe/RestDeleteDataFrameAnalyticsAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/dataframe/RestDeleteDataFrameAnalyticsAction.java @@ -7,7 +7,6 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.ml.action.DeleteDataFrameAnalyticsAction; @@ -15,12 +14,17 @@ import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.DELETE; public class RestDeleteDataFrameAnalyticsAction extends BaseRestHandler { - public RestDeleteDataFrameAnalyticsAction(RestController controller) { - controller.registerHandler(RestRequest.Method.DELETE, MachineLearning.BASE_PATH + "data_frame/analytics/{" - + DataFrameAnalyticsConfig.ID.getPreferredName() + "}", this); + @Override + public List routes() { + return singletonList( + new Route(DELETE, MachineLearning.BASE_PATH + "data_frame/analytics/{" + DataFrameAnalyticsConfig.ID.getPreferredName() + "}")); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/dataframe/RestEvaluateDataFrameAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/dataframe/RestEvaluateDataFrameAction.java index b991fec70e581..73d2506f3713f 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/dataframe/RestEvaluateDataFrameAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/dataframe/RestEvaluateDataFrameAction.java @@ -7,18 +7,22 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.ml.action.EvaluateDataFrameAction; import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.POST; public class RestEvaluateDataFrameAction extends BaseRestHandler { - public RestEvaluateDataFrameAction(RestController controller) { - controller.registerHandler(RestRequest.Method.POST, MachineLearning.BASE_PATH + "data_frame/_evaluate", this); + @Override + public List routes() { + return singletonList(new Route(POST, MachineLearning.BASE_PATH + "data_frame/_evaluate")); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/dataframe/RestExplainDataFrameAnalyticsAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/dataframe/RestExplainDataFrameAnalyticsAction.java index b16bf7b3efbf1..1d5f99aaf10c7 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/dataframe/RestExplainDataFrameAnalyticsAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/dataframe/RestExplainDataFrameAnalyticsAction.java @@ -9,7 +9,6 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.Strings; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.ml.action.ExplainDataFrameAnalyticsAction; @@ -23,15 +22,22 @@ import java.util.List; import java.util.stream.Collectors; +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; +import static org.elasticsearch.rest.RestRequest.Method.GET; +import static org.elasticsearch.rest.RestRequest.Method.POST; + public class RestExplainDataFrameAnalyticsAction extends BaseRestHandler { - public RestExplainDataFrameAnalyticsAction(RestController controller) { - controller.registerHandler(RestRequest.Method.GET, MachineLearning.BASE_PATH + "data_frame/analytics/_explain", this); - controller.registerHandler(RestRequest.Method.POST, MachineLearning.BASE_PATH + "data_frame/analytics/_explain", this); - controller.registerHandler(RestRequest.Method.GET, MachineLearning.BASE_PATH + "data_frame/analytics/{" - + DataFrameAnalyticsConfig.ID.getPreferredName() + "}/_explain", this); - controller.registerHandler(RestRequest.Method.POST, MachineLearning.BASE_PATH + "data_frame/analytics/{" - + DataFrameAnalyticsConfig.ID.getPreferredName() + "}/_explain", this); + @Override + public List routes() { + return unmodifiableList(asList( + new Route(GET, MachineLearning.BASE_PATH + "data_frame/analytics/_explain"), + new Route(POST, MachineLearning.BASE_PATH + "data_frame/analytics/_explain"), + new Route( + GET, MachineLearning.BASE_PATH + "data_frame/analytics/{" + DataFrameAnalyticsConfig.ID.getPreferredName() + "}/_explain"), + new Route(POST, + MachineLearning.BASE_PATH + "data_frame/analytics/{" + DataFrameAnalyticsConfig.ID.getPreferredName() + "}/_explain"))); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/dataframe/RestGetDataFrameAnalyticsAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/dataframe/RestGetDataFrameAnalyticsAction.java index 3c959056b2a5a..639adbc375a3a 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/dataframe/RestGetDataFrameAnalyticsAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/dataframe/RestGetDataFrameAnalyticsAction.java @@ -8,7 +8,6 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.Strings; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.action.util.PageParams; @@ -17,13 +16,19 @@ import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; +import java.util.List; + +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; +import static org.elasticsearch.rest.RestRequest.Method.GET; public class RestGetDataFrameAnalyticsAction extends BaseRestHandler { - public RestGetDataFrameAnalyticsAction(RestController controller) { - controller.registerHandler(RestRequest.Method.GET, MachineLearning.BASE_PATH + "data_frame/analytics", this); - controller.registerHandler(RestRequest.Method.GET, MachineLearning.BASE_PATH + "data_frame/analytics/{" - + DataFrameAnalyticsConfig.ID.getPreferredName() + "}", this); + @Override + public List routes() { + return unmodifiableList(asList( + new Route(GET, MachineLearning.BASE_PATH + "data_frame/analytics"), + new Route(GET, MachineLearning.BASE_PATH + "data_frame/analytics/{" + DataFrameAnalyticsConfig.ID.getPreferredName() + "}"))); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/dataframe/RestGetDataFrameAnalyticsStatsAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/dataframe/RestGetDataFrameAnalyticsStatsAction.java index 44d43153e75b6..793f41796cc5f 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/dataframe/RestGetDataFrameAnalyticsStatsAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/dataframe/RestGetDataFrameAnalyticsStatsAction.java @@ -8,7 +8,6 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.Strings; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.action.util.PageParams; @@ -17,13 +16,20 @@ import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; +import java.util.List; + +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; +import static org.elasticsearch.rest.RestRequest.Method.GET; public class RestGetDataFrameAnalyticsStatsAction extends BaseRestHandler { - public RestGetDataFrameAnalyticsStatsAction(RestController controller) { - controller.registerHandler(RestRequest.Method.GET, MachineLearning.BASE_PATH + "data_frame/analytics/_stats", this); - controller.registerHandler(RestRequest.Method.GET, MachineLearning.BASE_PATH + "data_frame/analytics/{" - + DataFrameAnalyticsConfig.ID.getPreferredName() + "}/_stats", this); + @Override + public List routes() { + return unmodifiableList(asList( + new Route(GET, MachineLearning.BASE_PATH + "data_frame/analytics/_stats"), + new Route( + GET, MachineLearning.BASE_PATH + "data_frame/analytics/{" + DataFrameAnalyticsConfig.ID.getPreferredName() + "}/_stats"))); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/dataframe/RestPutDataFrameAnalyticsAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/dataframe/RestPutDataFrameAnalyticsAction.java index 11a25e76a6c11..c8983271153e6 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/dataframe/RestPutDataFrameAnalyticsAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/dataframe/RestPutDataFrameAnalyticsAction.java @@ -8,7 +8,6 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.ml.action.PutDataFrameAnalyticsAction; @@ -16,12 +15,17 @@ import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.PUT; public class RestPutDataFrameAnalyticsAction extends BaseRestHandler { - public RestPutDataFrameAnalyticsAction(RestController controller) { - controller.registerHandler(RestRequest.Method.PUT, MachineLearning.BASE_PATH + "data_frame/analytics/{" - + DataFrameAnalyticsConfig.ID.getPreferredName() + "}", this); + @Override + public List routes() { + return singletonList( + new Route(PUT, MachineLearning.BASE_PATH + "data_frame/analytics/{" + DataFrameAnalyticsConfig.ID.getPreferredName() + "}")); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/dataframe/RestStartDataFrameAnalyticsAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/dataframe/RestStartDataFrameAnalyticsAction.java index df98e7bc402f1..9bc6ad6b4ea07 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/dataframe/RestStartDataFrameAnalyticsAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/dataframe/RestStartDataFrameAnalyticsAction.java @@ -8,7 +8,6 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.ml.action.StartDataFrameAnalyticsAction; @@ -16,12 +15,18 @@ import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.POST; public class RestStartDataFrameAnalyticsAction extends BaseRestHandler { - public RestStartDataFrameAnalyticsAction(RestController controller) { - controller.registerHandler(RestRequest.Method.POST, MachineLearning.BASE_PATH + "data_frame/analytics/{" - + DataFrameAnalyticsConfig.ID.getPreferredName() + "}/_start", this); + @Override + public List routes() { + return singletonList( + new Route( + POST, MachineLearning.BASE_PATH + "data_frame/analytics/{" + DataFrameAnalyticsConfig.ID.getPreferredName() + "}/_start")); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/dataframe/RestStopDataFrameAnalyticsAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/dataframe/RestStopDataFrameAnalyticsAction.java index aadc11a659d56..2787aad91579a 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/dataframe/RestStopDataFrameAnalyticsAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/dataframe/RestStopDataFrameAnalyticsAction.java @@ -7,7 +7,6 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.ml.action.StopDataFrameAnalyticsAction; @@ -15,12 +14,18 @@ import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.POST; public class RestStopDataFrameAnalyticsAction extends BaseRestHandler { - public RestStopDataFrameAnalyticsAction(RestController controller) { - controller.registerHandler(RestRequest.Method.POST, MachineLearning.BASE_PATH + "data_frame/analytics/{" - + DataFrameAnalyticsConfig.ID.getPreferredName() + "}/_stop", this); + @Override + public List routes() { + return singletonList( + new Route( + POST, MachineLearning.BASE_PATH + "data_frame/analytics/{" + DataFrameAnalyticsConfig.ID.getPreferredName() + "}/_stop")); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/filter/RestDeleteFilterAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/filter/RestDeleteFilterAction.java index cee5745866148..bb94ffcda4fae 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/filter/RestDeleteFilterAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/filter/RestDeleteFilterAction.java @@ -9,7 +9,6 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.ml.action.DeleteFilterAction; @@ -17,6 +16,8 @@ import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.DELETE; @@ -25,11 +26,19 @@ public class RestDeleteFilterAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestDeleteFilterAction.class)); - public RestDeleteFilterAction(RestController controller) { + @Override + public List routes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - DELETE, MachineLearning.BASE_PATH + "filters/{" + Request.FILTER_ID.getPreferredName() + "}", this, - DELETE, MachineLearning.PRE_V7_BASE_PATH + "filters/{" + Request.FILTER_ID.getPreferredName() + "}", deprecationLogger); + return Collections.singletonList( + new ReplacedRoute(DELETE, MachineLearning.BASE_PATH + "filters/{" + Request.FILTER_ID.getPreferredName() + "}", + DELETE, MachineLearning.PRE_V7_BASE_PATH + "filters/{" + Request.FILTER_ID.getPreferredName() + "}", + deprecationLogger) + ); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/filter/RestGetFiltersAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/filter/RestGetFiltersAction.java index 558da54b7f374..421af0bdee60f 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/filter/RestGetFiltersAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/filter/RestGetFiltersAction.java @@ -10,7 +10,6 @@ import org.elasticsearch.common.Strings; import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestStatusToXContentListener; import org.elasticsearch.xpack.core.action.util.PageParams; @@ -19,6 +18,9 @@ import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.GET; @@ -27,14 +29,22 @@ public class RestGetFiltersAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestGetFiltersAction.class)); - public RestGetFiltersAction(RestController controller) { + @Override + public List routes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - GET, MachineLearning.BASE_PATH + "filters/{" + MlFilter.ID.getPreferredName() + "}", this, - GET, MachineLearning.PRE_V7_BASE_PATH + "filters/{" + MlFilter.ID.getPreferredName() + "}", deprecationLogger); - controller.registerWithDeprecatedHandler( - GET, MachineLearning.BASE_PATH + "filters/", this, - GET, MachineLearning.PRE_V7_BASE_PATH + "filters/", deprecationLogger); + return Collections.unmodifiableList(Arrays.asList( + new ReplacedRoute(GET, MachineLearning.BASE_PATH + "filters/{" + MlFilter.ID.getPreferredName() + "}", + GET, MachineLearning.PRE_V7_BASE_PATH + "filters/{" + MlFilter.ID.getPreferredName() + "}", + deprecationLogger), + new ReplacedRoute(GET, MachineLearning.BASE_PATH + "filters/", + GET, MachineLearning.PRE_V7_BASE_PATH + "filters/", + deprecationLogger) + )); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/filter/RestPutFilterAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/filter/RestPutFilterAction.java index b902c09985382..85a01ac0edf0e 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/filter/RestPutFilterAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/filter/RestPutFilterAction.java @@ -10,7 +10,6 @@ import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.ml.action.PutFilterAction; @@ -18,6 +17,8 @@ import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.PUT; @@ -26,11 +27,19 @@ public class RestPutFilterAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestPutFilterAction.class)); - public RestPutFilterAction(RestController controller) { + @Override + public List routes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - PUT, MachineLearning.BASE_PATH + "filters/{" + MlFilter.ID.getPreferredName() + "}", this, - PUT, MachineLearning.PRE_V7_BASE_PATH + "filters/{" + MlFilter.ID.getPreferredName() + "}", deprecationLogger); + return Collections.singletonList( + new ReplacedRoute(PUT, MachineLearning.BASE_PATH + "filters/{" + MlFilter.ID.getPreferredName() + "}", + PUT, MachineLearning.PRE_V7_BASE_PATH + "filters/{" + MlFilter.ID.getPreferredName() + "}", + deprecationLogger) + ); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/filter/RestUpdateFilterAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/filter/RestUpdateFilterAction.java index b9c544f30c217..6bf83acdc5e82 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/filter/RestUpdateFilterAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/filter/RestUpdateFilterAction.java @@ -10,7 +10,6 @@ import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.ml.action.UpdateFilterAction; @@ -18,6 +17,8 @@ import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.POST; @@ -26,11 +27,19 @@ public class RestUpdateFilterAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestUpdateFilterAction.class)); - public RestUpdateFilterAction(RestController controller) { + @Override + public List routes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - POST, MachineLearning.BASE_PATH + "filters/{" + MlFilter.ID.getPreferredName() + "}/_update", this, - POST, MachineLearning.PRE_V7_BASE_PATH + "filters/{" + MlFilter.ID.getPreferredName() + "}/_update", deprecationLogger); + return Collections.singletonList( + new ReplacedRoute(POST, MachineLearning.BASE_PATH + "filters/{" + MlFilter.ID.getPreferredName() + "}/_update", + POST, MachineLearning.PRE_V7_BASE_PATH + "filters/{" + MlFilter.ID.getPreferredName() + "}/_update", + deprecationLogger) + ); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/inference/RestDeleteTrainedModelAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/inference/RestDeleteTrainedModelAction.java index e9675be4d29fd..e0e2b3f3d20ad 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/inference/RestDeleteTrainedModelAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/inference/RestDeleteTrainedModelAction.java @@ -7,7 +7,6 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.ml.action.DeleteTrainedModelAction; @@ -15,14 +14,17 @@ import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; +import java.util.List; +import static java.util.Collections.singletonList; import static org.elasticsearch.rest.RestRequest.Method.DELETE; public class RestDeleteTrainedModelAction extends BaseRestHandler { - public RestDeleteTrainedModelAction(RestController controller) { - controller.registerHandler( - DELETE, MachineLearning.BASE_PATH + "inference/{" + TrainedModelConfig.MODEL_ID.getPreferredName() + "}", this); + @Override + public List routes() { + return singletonList( + new Route(DELETE, MachineLearning.BASE_PATH + "inference/{" + TrainedModelConfig.MODEL_ID.getPreferredName() + "}")); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/inference/RestGetTrainedModelsAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/inference/RestGetTrainedModelsAction.java index 4d818f974f74e..8c783dbb609f9 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/inference/RestGetTrainedModelsAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/inference/RestGetTrainedModelsAction.java @@ -9,7 +9,6 @@ import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.common.Strings; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.action.util.PageParams; @@ -18,20 +17,22 @@ import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; -import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Set; +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.rest.RestRequest.Method.GET; import static org.elasticsearch.xpack.core.ml.action.GetTrainedModelsAction.Request.ALLOW_NO_MATCH; public class RestGetTrainedModelsAction extends BaseRestHandler { - public RestGetTrainedModelsAction(RestController controller) { - controller.registerHandler( - GET, MachineLearning.BASE_PATH + "inference/{" + TrainedModelConfig.MODEL_ID.getPreferredName() + "}", this); - controller.registerHandler(GET, MachineLearning.BASE_PATH + "inference", this); + @Override + public List routes() { + return unmodifiableList(asList( + new Route(GET, MachineLearning.BASE_PATH + "inference/{" + TrainedModelConfig.MODEL_ID.getPreferredName() + "}"), + new Route(GET, MachineLearning.BASE_PATH + "inference"))); } @Override @@ -49,7 +50,7 @@ protected RestChannelConsumer prepareRequest(RestRequest restRequest, NodeClient GetTrainedModelsAction.Request.INCLUDE_MODEL_DEFINITION.getPreferredName(), false ); - List tags = Arrays.asList(restRequest.paramAsStringArray(TrainedModelConfig.TAGS.getPreferredName(), Strings.EMPTY_ARRAY)); + List tags = asList(restRequest.paramAsStringArray(TrainedModelConfig.TAGS.getPreferredName(), Strings.EMPTY_ARRAY)); GetTrainedModelsAction.Request request = new GetTrainedModelsAction.Request(modelId, includeModelDefinition, tags); if (restRequest.hasParam(PageParams.FROM.getPreferredName()) || restRequest.hasParam(PageParams.SIZE.getPreferredName())) { request.setPageParams(new PageParams(restRequest.paramAsInt(PageParams.FROM.getPreferredName(), PageParams.DEFAULT_FROM), diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/inference/RestGetTrainedModelsStatsAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/inference/RestGetTrainedModelsStatsAction.java index 100c8cfa2f922..a035a67022bc3 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/inference/RestGetTrainedModelsStatsAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/inference/RestGetTrainedModelsStatsAction.java @@ -9,7 +9,6 @@ import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.common.Strings; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.action.util.PageParams; @@ -18,16 +17,20 @@ import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; +import java.util.List; +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.rest.RestRequest.Method.GET; import static org.elasticsearch.xpack.core.ml.action.GetTrainedModelsAction.Request.ALLOW_NO_MATCH; public class RestGetTrainedModelsStatsAction extends BaseRestHandler { - public RestGetTrainedModelsStatsAction(RestController controller) { - controller.registerHandler( - GET, MachineLearning.BASE_PATH + "inference/{" + TrainedModelConfig.MODEL_ID.getPreferredName() + "}/_stats", this); - controller.registerHandler(GET, MachineLearning.BASE_PATH + "inference/_stats", this); + @Override + public List routes() { + return unmodifiableList(asList( + new Route(GET, MachineLearning.BASE_PATH + "inference/{" + TrainedModelConfig.MODEL_ID.getPreferredName() + "}/_stats"), + new Route(GET, MachineLearning.BASE_PATH + MachineLearning.BASE_PATH + "inference/_stats"))); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/inference/RestPutTrainedModelAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/inference/RestPutTrainedModelAction.java index cb3f4e0eddee2..54f0f8476bdf4 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/inference/RestPutTrainedModelAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/inference/RestPutTrainedModelAction.java @@ -8,7 +8,6 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.ml.action.PutTrainedModelAction; @@ -16,13 +15,17 @@ import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.PUT; public class RestPutTrainedModelAction extends BaseRestHandler { - public RestPutTrainedModelAction(RestController controller) { - controller.registerHandler(RestRequest.Method.PUT, - MachineLearning.BASE_PATH + "inference/{" + TrainedModelConfig.MODEL_ID.getPreferredName() + "}", - this); + @Override + public List routes() { + return singletonList( + new Route(PUT, MachineLearning.BASE_PATH + "inference/{" + TrainedModelConfig.MODEL_ID.getPreferredName() + "}")); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/job/RestCloseJobAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/job/RestCloseJobAction.java index 9e8a2eaf7a35a..0b8ed5a9e3796 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/job/RestCloseJobAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/job/RestCloseJobAction.java @@ -10,7 +10,6 @@ import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.ml.action.CloseJobAction; @@ -19,6 +18,8 @@ import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.POST; @@ -27,11 +28,18 @@ public class RestCloseJobAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestCloseJobAction.class)); - public RestCloseJobAction(RestController controller) { + @Override + public List routes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - POST, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/_close", this, - POST, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/_close", deprecationLogger); + return Collections.singletonList( + new ReplacedRoute(POST, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/_close", + POST, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/_close", deprecationLogger) + ); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/job/RestDeleteForecastAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/job/RestDeleteForecastAction.java index 61b15f7794cd5..093b062dda12b 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/job/RestDeleteForecastAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/job/RestDeleteForecastAction.java @@ -10,7 +10,6 @@ import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.ml.action.DeleteForecastAction; @@ -19,7 +18,9 @@ import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; +import java.util.List; +import static java.util.Collections.singletonList; import static org.elasticsearch.rest.RestRequest.Method.DELETE; public class RestDeleteForecastAction extends BaseRestHandler { @@ -27,16 +28,21 @@ public class RestDeleteForecastAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestDeleteForecastAction.class)); - public RestDeleteForecastAction(RestController controller) { + @Override + public List routes() { + return singletonList( + new Route(DELETE, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/_forecast/")); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - DELETE, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + - "}/_forecast/{" + Forecast.FORECAST_ID.getPreferredName() + "}", this, - DELETE, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + - "}/_forecast/{" + Forecast.FORECAST_ID.getPreferredName() + "}", deprecationLogger); - controller.registerHandler( - DELETE, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + - "}/_forecast/", this); + return singletonList( + new ReplacedRoute(DELETE, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + + "}/_forecast/{" + Forecast.FORECAST_ID.getPreferredName() + "}", + DELETE, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + + "}/_forecast/{" + Forecast.FORECAST_ID.getPreferredName() + "}", deprecationLogger) + ); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/job/RestDeleteJobAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/job/RestDeleteJobAction.java index 9f8aed81b6b1b..03515a40a7cc8 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/job/RestDeleteJobAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/job/RestDeleteJobAction.java @@ -11,7 +11,6 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestStatus; import org.elasticsearch.rest.action.RestToXContentListener; @@ -23,6 +22,8 @@ import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.DELETE; @@ -31,11 +32,18 @@ public class RestDeleteJobAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestDeleteJobAction.class)); - public RestDeleteJobAction(RestController controller) { + @Override + public List routes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - DELETE, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}", this, - DELETE, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}", deprecationLogger); + return Collections.singletonList( + new ReplacedRoute(DELETE, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}", + DELETE, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}", deprecationLogger) + ); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/job/RestFlushJobAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/job/RestFlushJobAction.java index a1e6d09285a1c..17c3ef60144e8 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/job/RestFlushJobAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/job/RestFlushJobAction.java @@ -10,7 +10,6 @@ import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.ml.action.FlushJobAction; @@ -18,6 +17,8 @@ import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.POST; @@ -32,11 +33,19 @@ public class RestFlushJobAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestFlushJobAction.class)); - public RestFlushJobAction(RestController controller) { + @Override + public List routes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - POST, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/_flush", this, - POST, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/_flush", deprecationLogger); + return Collections.singletonList( + new ReplacedRoute(POST, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/_flush", + POST, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/_flush", + deprecationLogger) + ); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/job/RestForecastJobAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/job/RestForecastJobAction.java index 12c508daceecd..5d0aee2f4db3b 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/job/RestForecastJobAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/job/RestForecastJobAction.java @@ -10,7 +10,6 @@ import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.ml.action.ForecastJobAction; @@ -18,6 +17,8 @@ import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.POST; @@ -26,11 +27,19 @@ public class RestForecastJobAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestForecastJobAction.class)); - public RestForecastJobAction(RestController controller) { + @Override + public List routes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - POST, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/_forecast", this, - POST, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/_forecast", deprecationLogger); + return Collections.singletonList( + new ReplacedRoute(POST, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/_forecast", + POST, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/_forecast", + deprecationLogger) + ); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/job/RestGetJobStatsAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/job/RestGetJobStatsAction.java index 16b540d04fdd8..caf3402db0615 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/job/RestGetJobStatsAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/job/RestGetJobStatsAction.java @@ -11,7 +11,6 @@ import org.elasticsearch.common.Strings; import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.ml.action.GetJobsStatsAction; @@ -19,6 +18,9 @@ import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.GET; @@ -27,14 +29,21 @@ public class RestGetJobStatsAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestGetJobStatsAction.class)); - public RestGetJobStatsAction(RestController controller) { + @Override + public List routes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - GET, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/_stats", this, - GET, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/_stats", deprecationLogger); - controller.registerWithDeprecatedHandler( - GET, MachineLearning.BASE_PATH + "anomaly_detectors/_stats", this, - GET, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/_stats", deprecationLogger); + return Collections.unmodifiableList(Arrays.asList( + new ReplacedRoute(GET, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/_stats", + GET, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/_stats", + deprecationLogger), + new ReplacedRoute(GET, MachineLearning.BASE_PATH + "anomaly_detectors/_stats", + GET, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/_stats", deprecationLogger) + )); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/job/RestGetJobsAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/job/RestGetJobsAction.java index 5c9bc48400226..b980646a04547 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/job/RestGetJobsAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/job/RestGetJobsAction.java @@ -11,7 +11,6 @@ import org.elasticsearch.common.Strings; import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.ml.action.GetJobsAction; @@ -19,6 +18,9 @@ import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.GET; @@ -27,14 +29,21 @@ public class RestGetJobsAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestGetJobsAction.class)); - public RestGetJobsAction(RestController controller) { + @Override + public List routes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - GET, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}", this, - GET, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}", deprecationLogger); - controller.registerWithDeprecatedHandler( - GET, MachineLearning.BASE_PATH + "anomaly_detectors", this, - GET, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors", deprecationLogger); + return Collections.unmodifiableList(Arrays.asList( + new ReplacedRoute(GET, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}", + GET, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}", + deprecationLogger), + new ReplacedRoute(GET, MachineLearning.BASE_PATH + "anomaly_detectors", + GET, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors", deprecationLogger) + )); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/job/RestOpenJobAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/job/RestOpenJobAction.java index 4e6b02049be59..21b30539ade37 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/job/RestOpenJobAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/job/RestOpenJobAction.java @@ -13,7 +13,6 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; @@ -23,6 +22,8 @@ import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.POST; @@ -31,11 +32,19 @@ public class RestOpenJobAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestOpenJobAction.class)); - public RestOpenJobAction(RestController controller) { + @Override + public List routes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - POST, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/_open", this, - POST, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/_open", deprecationLogger); + return Collections.singletonList( + new ReplacedRoute(POST, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/_open", + POST, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/_open", + deprecationLogger) + ); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/job/RestPostDataAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/job/RestPostDataAction.java index b3e57ca5855a5..26d79114fa4bd 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/job/RestPostDataAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/job/RestPostDataAction.java @@ -9,7 +9,6 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestStatusToXContentListener; import org.elasticsearch.xpack.core.ml.action.PostDataAction; @@ -17,6 +16,8 @@ import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.POST; @@ -28,11 +29,19 @@ public class RestPostDataAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestPostDataAction.class)); - public RestPostDataAction(RestController controller) { + @Override + public List routes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - POST, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/_data", this, - POST, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/_data", deprecationLogger); + return Collections.singletonList( + new ReplacedRoute(POST, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/_data", + POST, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/_data", + deprecationLogger) + ); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/job/RestPostJobUpdateAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/job/RestPostJobUpdateAction.java index a237a8b187459..a3e69048f72cc 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/job/RestPostJobUpdateAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/job/RestPostJobUpdateAction.java @@ -10,7 +10,6 @@ import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.ml.action.UpdateJobAction; @@ -18,6 +17,8 @@ import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.POST; @@ -26,11 +27,19 @@ public class RestPostJobUpdateAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestPostJobUpdateAction.class)); - public RestPostJobUpdateAction(RestController controller) { + @Override + public List routes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - POST, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/_update", this, - POST, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/_update", deprecationLogger); + return Collections.singletonList( + new ReplacedRoute(POST, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/_update", + POST, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/_update", + deprecationLogger) + ); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/job/RestPutJobAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/job/RestPutJobAction.java index fe0e29cde490c..20667e299e495 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/job/RestPutJobAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/job/RestPutJobAction.java @@ -10,7 +10,6 @@ import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.ml.action.PutJobAction; @@ -18,6 +17,8 @@ import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.PUT; @@ -26,11 +27,19 @@ public class RestPutJobAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestPutJobAction.class)); - public RestPutJobAction(RestController controller) { + @Override + public List routes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - PUT, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}", this, - PUT, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}", deprecationLogger); + return Collections.singletonList( + new ReplacedRoute(PUT, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}", + PUT, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}", + deprecationLogger) + ); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/modelsnapshots/RestDeleteModelSnapshotAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/modelsnapshots/RestDeleteModelSnapshotAction.java index 7ea082f9fd12f..75fb5b474b513 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/modelsnapshots/RestDeleteModelSnapshotAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/modelsnapshots/RestDeleteModelSnapshotAction.java @@ -9,15 +9,16 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; -import org.elasticsearch.xpack.ml.MachineLearning; import org.elasticsearch.xpack.core.ml.action.DeleteModelSnapshotAction; import org.elasticsearch.xpack.core.ml.job.config.Job; import org.elasticsearch.xpack.core.ml.job.process.autodetect.state.ModelSnapshotField; +import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.DELETE; @@ -26,13 +27,21 @@ public class RestDeleteModelSnapshotAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestDeleteModelSnapshotAction.class)); - public RestDeleteModelSnapshotAction(RestController controller) { + @Override + public List routes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - DELETE, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + - "}/model_snapshots/{" + ModelSnapshotField.SNAPSHOT_ID.getPreferredName() + "}", this, - DELETE, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + - "}/model_snapshots/{" + ModelSnapshotField.SNAPSHOT_ID.getPreferredName() + "}", deprecationLogger); + return Collections.singletonList( + new ReplacedRoute(DELETE, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + + "}/model_snapshots/{" + ModelSnapshotField.SNAPSHOT_ID.getPreferredName() + "}", + DELETE, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + + "}/model_snapshots/{" + ModelSnapshotField.SNAPSHOT_ID.getPreferredName() + "}", + deprecationLogger) + ); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/modelsnapshots/RestGetModelSnapshotsAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/modelsnapshots/RestGetModelSnapshotsAction.java index 2b2ef21442fa6..24b9e32492a4e 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/modelsnapshots/RestGetModelSnapshotsAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/modelsnapshots/RestGetModelSnapshotsAction.java @@ -10,7 +10,6 @@ import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.action.util.PageParams; @@ -20,6 +19,9 @@ import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.GET; import static org.elasticsearch.rest.RestRequest.Method.POST; @@ -39,31 +41,36 @@ public class RestGetModelSnapshotsAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestGetModelSnapshotsAction.class)); - public RestGetModelSnapshotsAction(RestController controller) { - // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - GET, MachineLearning.BASE_PATH + "anomaly_detectors/{" - + Job.ID.getPreferredName() + "}/model_snapshots/{" + Request.SNAPSHOT_ID.getPreferredName() + "}", this, - GET, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" - + Job.ID.getPreferredName() + "}/model_snapshots/{" + Request.SNAPSHOT_ID.getPreferredName() + "}", deprecationLogger); - // endpoints that support body parameters must also accept POST - controller.registerWithDeprecatedHandler( - POST, MachineLearning.BASE_PATH + "anomaly_detectors/{" - + Job.ID.getPreferredName() + "}/model_snapshots/{" + Request.SNAPSHOT_ID.getPreferredName() + "}", this, - POST, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" - + Job.ID.getPreferredName() + "}/model_snapshots/{" + Request.SNAPSHOT_ID.getPreferredName() + "}", deprecationLogger); + @Override + public List routes() { + return Collections.emptyList(); + } - controller.registerWithDeprecatedHandler( - GET, MachineLearning.BASE_PATH + "anomaly_detectors/{" - + Job.ID.getPreferredName() + "}/model_snapshots", this, - GET, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" - + Job.ID.getPreferredName() + "}/model_snapshots", deprecationLogger); - // endpoints that support body parameters must also accept POST - controller.registerWithDeprecatedHandler( - POST, MachineLearning.BASE_PATH + "anomaly_detectors/{" - + Job.ID.getPreferredName() + "}/model_snapshots", this, - POST, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" - + Job.ID.getPreferredName() + "}/model_snapshots", deprecationLogger); + @Override + public List replacedRoutes() { + // TODO: remove deprecated endpoint in 8.0.0 + return Collections.unmodifiableList(Arrays.asList( + new ReplacedRoute(GET, MachineLearning.BASE_PATH + "anomaly_detectors/{" + + Job.ID.getPreferredName() + "}/model_snapshots/{" + Request.SNAPSHOT_ID.getPreferredName() + "}", + GET, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + + Job.ID.getPreferredName() + "}/model_snapshots/{" + Request.SNAPSHOT_ID.getPreferredName() + "}", + deprecationLogger), + new ReplacedRoute(POST, MachineLearning.BASE_PATH + "anomaly_detectors/{" + + Job.ID.getPreferredName() + "}/model_snapshots/{" + Request.SNAPSHOT_ID.getPreferredName() + "}", + POST, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + + Job.ID.getPreferredName() + "}/model_snapshots/{" + Request.SNAPSHOT_ID.getPreferredName() + "}", + deprecationLogger), + new ReplacedRoute(GET, MachineLearning.BASE_PATH + "anomaly_detectors/{" + + Job.ID.getPreferredName() + "}/model_snapshots", + GET, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + + Job.ID.getPreferredName() + "}/model_snapshots", + deprecationLogger), + new ReplacedRoute(POST, MachineLearning.BASE_PATH + "anomaly_detectors/{" + + Job.ID.getPreferredName() + "}/model_snapshots", + POST, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + + Job.ID.getPreferredName() + "}/model_snapshots", + deprecationLogger) + )); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/modelsnapshots/RestRevertModelSnapshotAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/modelsnapshots/RestRevertModelSnapshotAction.java index 33b31af99526b..2fe0c0eecd01d 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/modelsnapshots/RestRevertModelSnapshotAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/modelsnapshots/RestRevertModelSnapshotAction.java @@ -10,7 +10,6 @@ import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestStatusToXContentListener; import org.elasticsearch.xpack.core.ml.action.RevertModelSnapshotAction; @@ -18,6 +17,8 @@ import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.POST; @@ -28,13 +29,22 @@ public class RestRevertModelSnapshotAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestRevertModelSnapshotAction.class)); - public RestRevertModelSnapshotAction(RestController controller) { + @Override + public List routes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - POST, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/model_snapshots/{" + - RevertModelSnapshotAction.Request.SNAPSHOT_ID.getPreferredName() + "}/_revert", this, - POST, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/model_snapshots/{" + - RevertModelSnapshotAction.Request.SNAPSHOT_ID.getPreferredName() + "}/_revert", deprecationLogger); + return Collections.singletonList( + new ReplacedRoute( + POST, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/model_snapshots/{" + + RevertModelSnapshotAction.Request.SNAPSHOT_ID.getPreferredName() + "}/_revert", + POST, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/model_snapshots/{" + + RevertModelSnapshotAction.Request.SNAPSHOT_ID.getPreferredName() + "}/_revert", + deprecationLogger) + ); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/modelsnapshots/RestUpdateModelSnapshotAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/modelsnapshots/RestUpdateModelSnapshotAction.java index e1cd0b2d2f5f7..1a3b43a03b34b 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/modelsnapshots/RestUpdateModelSnapshotAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/modelsnapshots/RestUpdateModelSnapshotAction.java @@ -10,7 +10,6 @@ import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestStatusToXContentListener; import org.elasticsearch.xpack.core.ml.action.UpdateModelSnapshotAction; @@ -19,6 +18,8 @@ import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.POST; @@ -27,13 +28,21 @@ public class RestUpdateModelSnapshotAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestUpdateModelSnapshotAction.class)); - public RestUpdateModelSnapshotAction(RestController controller) { + @Override + public List routes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - POST, MachineLearning.BASE_PATH + "anomaly_detectors/{" - + Job.ID.getPreferredName() + "}/model_snapshots/{" + ModelSnapshotField.SNAPSHOT_ID +"}/_update", this, - POST, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" - + Job.ID.getPreferredName() + "}/model_snapshots/{" + ModelSnapshotField.SNAPSHOT_ID +"}/_update", deprecationLogger); + return Collections.singletonList( + new ReplacedRoute(POST, MachineLearning.BASE_PATH + "anomaly_detectors/{" + + Job.ID.getPreferredName() + "}/model_snapshots/{" + ModelSnapshotField.SNAPSHOT_ID +"}/_update", + POST, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + + Job.ID.getPreferredName() + "}/model_snapshots/{" + ModelSnapshotField.SNAPSHOT_ID +"}/_update", + deprecationLogger) + ); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/results/RestGetBucketsAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/results/RestGetBucketsAction.java index 8bb423199fe57..ecf94c1fe2220 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/results/RestGetBucketsAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/results/RestGetBucketsAction.java @@ -11,7 +11,6 @@ import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.action.util.PageParams; @@ -21,6 +20,9 @@ import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.GET; import static org.elasticsearch.rest.RestRequest.Method.POST; @@ -30,29 +32,36 @@ public class RestGetBucketsAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestGetBucketsAction.class)); - public RestGetBucketsAction(RestController controller) { - // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - GET, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() - + "}/results/buckets/{" + Result.TIMESTAMP.getPreferredName() + "}", this, - GET, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() - + "}/results/buckets/{" + Result.TIMESTAMP.getPreferredName() + "}", deprecationLogger); - controller.registerWithDeprecatedHandler( - POST, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() - + "}/results/buckets/{" + Result.TIMESTAMP.getPreferredName() + "}", this, - POST, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() - + "}/results/buckets/{" + Result.TIMESTAMP.getPreferredName() + "}", deprecationLogger); + @Override + public List routes() { + return Collections.emptyList(); + } - controller.registerWithDeprecatedHandler( - GET, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() - + "}/results/buckets", this, - GET, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() - + "}/results/buckets", deprecationLogger); - controller.registerWithDeprecatedHandler( - POST, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() - + "}/results/buckets", this, - POST, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() - + "}/results/buckets", deprecationLogger); + @Override + public List replacedRoutes() { + // TODO: remove deprecated endpoint in 8.0.0 + return Collections.unmodifiableList(Arrays.asList( + new ReplacedRoute(GET, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + + "}/results/buckets/{" + Result.TIMESTAMP.getPreferredName() + "}", + GET, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + + "}/results/buckets/{" + Result.TIMESTAMP.getPreferredName() + "}", + deprecationLogger), + new ReplacedRoute(POST, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + + "}/results/buckets/{" + Result.TIMESTAMP.getPreferredName() + "}", + POST, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + + "}/results/buckets/{" + Result.TIMESTAMP.getPreferredName() + "}", + deprecationLogger), + new ReplacedRoute(GET, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + + "}/results/buckets", + GET, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + + "}/results/buckets", + deprecationLogger), + new ReplacedRoute(POST, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + + "}/results/buckets", + POST, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + + "}/results/buckets", + deprecationLogger) + )); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/results/RestGetCategoriesAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/results/RestGetCategoriesAction.java index e2e069efd76fd..55a4fbffd73b7 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/results/RestGetCategoriesAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/results/RestGetCategoriesAction.java @@ -10,7 +10,6 @@ import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.action.util.PageParams; @@ -20,6 +19,9 @@ import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.GET; import static org.elasticsearch.rest.RestRequest.Method.POST; @@ -29,29 +31,35 @@ public class RestGetCategoriesAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestGetCategoriesAction.class)); - public RestGetCategoriesAction(RestController controller) { - // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - GET, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/results/categories/{" - + Request.CATEGORY_ID.getPreferredName() + "}", this, - GET, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/results/categories/{" - + Request.CATEGORY_ID.getPreferredName() + "}", deprecationLogger); - controller.registerWithDeprecatedHandler( - GET, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/results/categories", - this, - GET, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/results/categories", - deprecationLogger); + @Override + public List routes() { + return Collections.emptyList(); + } - controller.registerWithDeprecatedHandler( - POST, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/results/categories/{" - + Request.CATEGORY_ID.getPreferredName() + "}", this, - POST, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/results/categories/{" - + Request.CATEGORY_ID.getPreferredName() + "}", deprecationLogger); - controller.registerWithDeprecatedHandler( - POST, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/results/categories", - this, - POST, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/results/categories", - deprecationLogger); + @Override + public List replacedRoutes() { + // TODO: remove deprecated endpoint in 8.0.0 + return Collections.unmodifiableList(Arrays.asList( + new ReplacedRoute( + GET, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/results/categories/{" + + Request.CATEGORY_ID.getPreferredName() + "}", + GET, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/results/categories/{" + + Request.CATEGORY_ID.getPreferredName() + "}", + deprecationLogger), + new ReplacedRoute(POST, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + + "}/results/categories/{" + Request.CATEGORY_ID.getPreferredName() + "}", + POST, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + + "}/results/categories/{" + Request.CATEGORY_ID.getPreferredName() + "}", + deprecationLogger), + new ReplacedRoute( + GET, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/results/categories", + GET, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/results/categories", + deprecationLogger), + new ReplacedRoute( + POST, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/results/categories", + POST, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/results/categories", + deprecationLogger) + )); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/results/RestGetInfluencersAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/results/RestGetInfluencersAction.java index a1ac9671b3bed..639ba3f17f3ec 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/results/RestGetInfluencersAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/results/RestGetInfluencersAction.java @@ -10,7 +10,6 @@ import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.action.util.PageParams; @@ -19,6 +18,9 @@ import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.GET; import static org.elasticsearch.rest.RestRequest.Method.POST; @@ -28,19 +30,24 @@ public class RestGetInfluencersAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestGetInfluencersAction.class)); - public RestGetInfluencersAction(RestController controller) { + @Override + public List routes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - GET, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/results/influencers", - this, - GET, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/results/influencers", - deprecationLogger); - // endpoints that support body parameters must also accept POST - controller.registerWithDeprecatedHandler( - POST, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/results/influencers", - this, - POST, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/results/influencers", - deprecationLogger); + return Collections.unmodifiableList(Arrays.asList( + new ReplacedRoute( + GET, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/results/influencers", + GET, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/results/influencers", + deprecationLogger), + new ReplacedRoute( + POST, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/results/influencers", + POST, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/results/influencers", + deprecationLogger) + )); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/results/RestGetOverallBucketsAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/results/RestGetOverallBucketsAction.java index 0b7763a8bf61d..541fac368e17c 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/results/RestGetOverallBucketsAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/results/RestGetOverallBucketsAction.java @@ -10,7 +10,6 @@ import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.ml.action.GetOverallBucketsAction; @@ -19,6 +18,9 @@ import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.GET; import static org.elasticsearch.rest.RestRequest.Method.POST; @@ -28,18 +30,24 @@ public class RestGetOverallBucketsAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestGetOverallBucketsAction.class)); - public RestGetOverallBucketsAction(RestController controller) { + @Override + public List routes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - GET, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/results/overall_buckets", - this, - GET, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/results/overall_buckets", - deprecationLogger); - controller.registerWithDeprecatedHandler( - POST, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/results/overall_buckets", - this, - POST, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/results/overall_buckets", - deprecationLogger); + return Collections.unmodifiableList(Arrays.asList( + new ReplacedRoute( + GET, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/results/overall_buckets", + GET, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/results/overall_buckets", + deprecationLogger), + new ReplacedRoute( + POST, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/results/overall_buckets", + POST, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/results/overall_buckets", + deprecationLogger) + )); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/results/RestGetRecordsAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/results/RestGetRecordsAction.java index 0ce2b5e709917..738da300e7d14 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/results/RestGetRecordsAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/results/RestGetRecordsAction.java @@ -10,15 +10,17 @@ import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; -import org.elasticsearch.xpack.core.ml.action.GetRecordsAction; import org.elasticsearch.xpack.core.action.util.PageParams; +import org.elasticsearch.xpack.core.ml.action.GetRecordsAction; import org.elasticsearch.xpack.core.ml.job.config.Job; import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.GET; import static org.elasticsearch.rest.RestRequest.Method.POST; @@ -28,18 +30,24 @@ public class RestGetRecordsAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestGetRecordsAction.class)); - public RestGetRecordsAction(RestController controller) { + @Override + public List routes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - GET, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/results/records", - this, - GET, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/results/records", - deprecationLogger); - controller.registerWithDeprecatedHandler( - POST, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/results/records", - this, - POST, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/results/records", - deprecationLogger); + return Collections.unmodifiableList(Arrays.asList( + new ReplacedRoute( + GET, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/results/records", + GET, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/results/records", + deprecationLogger), + new ReplacedRoute( + POST, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/results/records", + POST, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/results/records", + deprecationLogger) + )); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/validate/RestValidateDetectorAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/validate/RestValidateDetectorAction.java index 3cf5f89f91991..07dda46e4ca4b 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/validate/RestValidateDetectorAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/validate/RestValidateDetectorAction.java @@ -10,13 +10,14 @@ import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.ml.action.ValidateDetectorAction; import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.POST; @@ -25,11 +26,18 @@ public class RestValidateDetectorAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestValidateDetectorAction.class)); - public RestValidateDetectorAction(RestController controller) { + @Override + public List routes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - POST, MachineLearning.BASE_PATH + "anomaly_detectors/_validate/detector", this, - POST, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/_validate/detector", deprecationLogger); + return Collections.singletonList( + new ReplacedRoute(POST, MachineLearning.BASE_PATH + "anomaly_detectors/_validate/detector", + POST, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/_validate/detector", deprecationLogger) + ); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/validate/RestValidateJobConfigAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/validate/RestValidateJobConfigAction.java index 9f16162d17264..aa96b3c591f66 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/validate/RestValidateJobConfigAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/validate/RestValidateJobConfigAction.java @@ -10,13 +10,14 @@ import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.ml.action.ValidateJobConfigAction; import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.POST; @@ -25,11 +26,18 @@ public class RestValidateJobConfigAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestValidateJobConfigAction.class)); - public RestValidateJobConfigAction(RestController controller) { + @Override + public List routes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - POST, MachineLearning.BASE_PATH + "anomaly_detectors/_validate", this, - POST, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/_validate", deprecationLogger); + return Collections.singletonList( + new ReplacedRoute(POST, MachineLearning.BASE_PATH + "anomaly_detectors/_validate", + POST, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/_validate", deprecationLogger) + ); } @Override diff --git a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/rest/datafeeds/RestStartDatafeedActionTests.java b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/rest/datafeeds/RestStartDatafeedActionTests.java index e36b8a6aaa33c..533da79aeb6fc 100644 --- a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/rest/datafeeds/RestStartDatafeedActionTests.java +++ b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/rest/datafeeds/RestStartDatafeedActionTests.java @@ -8,7 +8,6 @@ import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.xcontent.NamedXContentRegistry; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.rest.FakeRestRequest; @@ -21,8 +20,7 @@ public class RestStartDatafeedActionTests extends ESTestCase { public void testPrepareRequest() throws Exception { - RestStartDatafeedAction action = new RestStartDatafeedAction( - mock(RestController.class)); + RestStartDatafeedAction action = new RestStartDatafeedAction(); Map params = new HashMap<>(); params.put("start", "not-a-date"); diff --git a/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/Monitoring.java b/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/Monitoring.java index 50a7d9afa2efa..f5f777bc668a4 100644 --- a/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/Monitoring.java +++ b/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/Monitoring.java @@ -169,7 +169,7 @@ public List getRestHandlers(Settings settings, RestController restC if (false == enabled) { return emptyList(); } - return singletonList(new RestMonitoringBulkAction(restController)); + return singletonList(new RestMonitoringBulkAction()); } @Override diff --git a/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/rest/action/RestMonitoringBulkAction.java b/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/rest/action/RestMonitoringBulkAction.java index 5cb732d22f0a3..639f0e2156e97 100644 --- a/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/rest/action/RestMonitoringBulkAction.java +++ b/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/rest/action/RestMonitoringBulkAction.java @@ -9,10 +9,10 @@ import org.apache.logging.log4j.Logger; import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.common.Strings; +import org.elasticsearch.common.collect.MapBuilder; import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.action.RestBuilderListener; @@ -24,13 +24,13 @@ import org.elasticsearch.xpack.core.rest.XPackRestHandler; import java.io.IOException; -import java.util.Arrays; import java.util.Collections; -import java.util.HashMap; import java.util.List; import java.util.Map; +import static java.util.Arrays.asList; import static java.util.Collections.emptyList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.common.unit.TimeValue.parseTimeValue; import static org.elasticsearch.rest.RestRequest.Method.POST; import static org.elasticsearch.rest.RestRequest.Method.PUT; @@ -42,25 +42,33 @@ public class RestMonitoringBulkAction extends XPackRestHandler { public static final String INTERVAL = "interval"; private static final Logger logger = LogManager.getLogger(RestMonitoringBulkAction.class); private static final DeprecationLogger deprecationLogger = new DeprecationLogger(logger); - private final Map> supportedApiVersions; - - public RestMonitoringBulkAction(RestController controller) { - // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler(POST, "/_monitoring/bulk", this, - POST, "/_xpack/monitoring/_bulk", deprecationLogger); - controller.registerWithDeprecatedHandler(PUT, "/_monitoring/bulk", this, - PUT, "/_xpack/monitoring/_bulk", deprecationLogger); - - final List allVersions = Arrays.asList( - MonitoringTemplateUtils.TEMPLATE_VERSION, - MonitoringTemplateUtils.OLD_TEMPLATE_VERSION - ); - - final Map> versionsMap = new HashMap<>(); - versionsMap.put(MonitoredSystem.KIBANA, allVersions); - versionsMap.put(MonitoredSystem.LOGSTASH, allVersions); - versionsMap.put(MonitoredSystem.BEATS, allVersions); - supportedApiVersions = Collections.unmodifiableMap(versionsMap); + + private static final List ALL_VERSIONS = asList( + MonitoringTemplateUtils.TEMPLATE_VERSION, + MonitoringTemplateUtils.OLD_TEMPLATE_VERSION + ); + + private static final Map> SUPPORTED_API_VERSIONS = + Collections.unmodifiableMap(MapBuilder.>newMapBuilder() + .put(MonitoredSystem.KIBANA, ALL_VERSIONS) + .put(MonitoredSystem.LOGSTASH, ALL_VERSIONS) + .put(MonitoredSystem.BEATS, ALL_VERSIONS) + .map()); + + @Override + public List routes() { + return emptyList(); + } + + @Override + public List replacedRoutes() { + return unmodifiableList(asList( + new ReplacedRoute( + POST, "/_monitoring/bulk", + POST, "/_xpack/monitoring/_bulk", deprecationLogger), + new ReplacedRoute( + PUT, "/_monitoring/bulk", + PUT, "/_xpack/monitoring/_bulk", deprecationLogger))); } @Override @@ -136,7 +144,7 @@ public boolean supportsContentStream() { * @return true if supported, false otherwise */ private boolean isSupportedSystemVersion(final MonitoredSystem system, final String version) { - final List monitoredSystem = supportedApiVersions.getOrDefault(system, emptyList()); + final List monitoredSystem = SUPPORTED_API_VERSIONS.getOrDefault(system, emptyList()); return monitoredSystem.contains(version); } } diff --git a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/rest/action/RestMonitoringBulkActionTests.java b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/rest/action/RestMonitoringBulkActionTests.java index 604f9dd453b16..57ffd97fc81f3 100644 --- a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/rest/action/RestMonitoringBulkActionTests.java +++ b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/rest/action/RestMonitoringBulkActionTests.java @@ -17,7 +17,6 @@ import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.common.xcontent.json.JsonXContent; import org.elasticsearch.rest.RestChannel; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; @@ -45,9 +44,7 @@ public class RestMonitoringBulkActionTests extends ESTestCase { - private final RestController controller = mock(RestController.class); - - private final RestMonitoringBulkAction action = new RestMonitoringBulkAction(controller); + private final RestMonitoringBulkAction action = new RestMonitoringBulkAction(); public void testGetName() { // Are you sure that you want to change the name? diff --git a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/Rollup.java b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/Rollup.java index 956d67c1be78d..101b82f592d72 100644 --- a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/Rollup.java +++ b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/Rollup.java @@ -136,14 +136,14 @@ public List getRestHandlers(Settings settings, RestController restC } return Arrays.asList( - new RestRollupSearchAction(restController), - new RestPutRollupJobAction(restController), - new RestStartRollupJobAction(restController), - new RestStopRollupJobAction(restController), - new RestDeleteRollupJobAction(restController), - new RestGetRollupJobsAction(restController), - new RestGetRollupCapsAction(restController), - new RestGetRollupIndexCapsAction(restController) + new RestRollupSearchAction(), + new RestPutRollupJobAction(), + new RestStartRollupJobAction(), + new RestStopRollupJobAction(), + new RestDeleteRollupJobAction(), + new RestGetRollupJobsAction(), + new RestGetRollupCapsAction(), + new RestGetRollupIndexCapsAction() ); } diff --git a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/rest/RestDeleteRollupJobAction.java b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/rest/RestDeleteRollupJobAction.java index 2ab2af450680a..9bad837f5c187 100644 --- a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/rest/RestDeleteRollupJobAction.java +++ b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/rest/RestDeleteRollupJobAction.java @@ -11,12 +11,15 @@ import org.elasticsearch.common.ParseField; import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestStatus; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.rollup.action.DeleteRollupJobAction; +import java.util.List; + +import static java.util.Collections.emptyList; +import static java.util.Collections.singletonList; import static org.elasticsearch.rest.RestRequest.Method.DELETE; public class RestDeleteRollupJobAction extends BaseRestHandler { @@ -25,11 +28,14 @@ public class RestDeleteRollupJobAction extends BaseRestHandler { public static final ParseField ID = new ParseField("id"); - public RestDeleteRollupJobAction(RestController controller) { - // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - DELETE, "/_rollup/job/{id}", this, - DELETE, "/_xpack/rollup/job/{id}/", deprecationLogger); + @Override + public List routes() { + return emptyList(); + } + + @Override + public List replacedRoutes() { + return singletonList(new ReplacedRoute(DELETE, "/_rollup/job/{id}", DELETE, "/_xpack/rollup/job/{id}/", deprecationLogger)); } @Override diff --git a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/rest/RestGetRollupCapsAction.java b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/rest/RestGetRollupCapsAction.java index 9ddd9459425e8..a0c6bda82ba8f 100644 --- a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/rest/RestGetRollupCapsAction.java +++ b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/rest/RestGetRollupCapsAction.java @@ -11,11 +11,14 @@ import org.elasticsearch.common.ParseField; import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.rollup.action.GetRollupCapsAction; +import java.util.List; + +import static java.util.Collections.emptyList; +import static java.util.Collections.singletonList; import static org.elasticsearch.rest.RestRequest.Method.GET; public class RestGetRollupCapsAction extends BaseRestHandler { @@ -24,11 +27,14 @@ public class RestGetRollupCapsAction extends BaseRestHandler { public static final ParseField ID = new ParseField("id"); - public RestGetRollupCapsAction(RestController controller) { - // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - GET, "/_rollup/data/{id}", this, - GET, "/_xpack/rollup/data/{id}/", deprecationLogger); + @Override + public List routes() { + return emptyList(); + } + + @Override + public List replacedRoutes() { + return singletonList(new ReplacedRoute(GET, "/_rollup/data/{id}", GET, "/_xpack/rollup/data/{id}/", deprecationLogger)); } @Override diff --git a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/rest/RestGetRollupIndexCapsAction.java b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/rest/RestGetRollupIndexCapsAction.java index a5e2e6ea8068e..fea3d12358581 100644 --- a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/rest/RestGetRollupIndexCapsAction.java +++ b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/rest/RestGetRollupIndexCapsAction.java @@ -13,11 +13,14 @@ import org.elasticsearch.common.Strings; import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.rollup.action.GetRollupIndexCapsAction; +import java.util.List; + +import static java.util.Collections.emptyList; +import static java.util.Collections.singletonList; import static org.elasticsearch.rest.RestRequest.Method.GET; public class RestGetRollupIndexCapsAction extends BaseRestHandler { @@ -27,11 +30,14 @@ public class RestGetRollupIndexCapsAction extends BaseRestHandler { static final ParseField INDEX = new ParseField("index"); - public RestGetRollupIndexCapsAction(RestController controller) { - // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - GET, "/{index}/_rollup/data", this, - GET, "/{index}/_xpack/rollup/data", deprecationLogger); + @Override + public List routes() { + return emptyList(); + } + + @Override + public List replacedRoutes() { + return singletonList(new ReplacedRoute(GET, "/{index}/_rollup/data", GET, "/{index}/_xpack/rollup/data", deprecationLogger)); } @Override diff --git a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/rest/RestGetRollupJobsAction.java b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/rest/RestGetRollupJobsAction.java index 8b1327be55b82..1d060d29e03d2 100644 --- a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/rest/RestGetRollupJobsAction.java +++ b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/rest/RestGetRollupJobsAction.java @@ -11,11 +11,14 @@ import org.elasticsearch.common.ParseField; import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.rollup.action.GetRollupJobsAction; +import java.util.List; + +import static java.util.Collections.emptyList; +import static java.util.Collections.singletonList; import static org.elasticsearch.rest.RestRequest.Method.GET; public class RestGetRollupJobsAction extends BaseRestHandler { @@ -24,11 +27,14 @@ public class RestGetRollupJobsAction extends BaseRestHandler { public static final ParseField ID = new ParseField("id"); - public RestGetRollupJobsAction(RestController controller) { - // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - GET, "/_rollup/job/{id}", this, - GET, "/_xpack/rollup/job/{id}/", deprecationLogger); + @Override + public List routes() { + return emptyList(); + } + + @Override + public List replacedRoutes() { + return singletonList(new ReplacedRoute(GET, "/_rollup/job/{id}", GET, "/_xpack/rollup/job/{id}/", deprecationLogger)); } @Override diff --git a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/rest/RestPutRollupJobAction.java b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/rest/RestPutRollupJobAction.java index 25612350ddea5..3e8edd6d013e5 100644 --- a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/rest/RestPutRollupJobAction.java +++ b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/rest/RestPutRollupJobAction.java @@ -10,24 +10,29 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.rollup.action.PutRollupJobAction; import java.io.IOException; +import java.util.List; +import static java.util.Collections.emptyList; +import static java.util.Collections.singletonList; import static org.elasticsearch.rest.RestRequest.Method.PUT; public class RestPutRollupJobAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestPutRollupJobAction.class)); - public RestPutRollupJobAction(RestController controller) { - // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - PUT, "/_rollup/job/{id}", this, - PUT, "/_xpack/rollup/job/{id}", deprecationLogger); + @Override + public List routes() { + return emptyList(); + } + + @Override + public List replacedRoutes() { + return singletonList(new ReplacedRoute(PUT, "/_rollup/job/{id}", PUT, "/_xpack/rollup/job/{id}", deprecationLogger)); } @Override diff --git a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/rest/RestRollupSearchAction.java b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/rest/RestRollupSearchAction.java index c354e1ed1ed5f..2e9bee9f47bbc 100644 --- a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/rest/RestRollupSearchAction.java +++ b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/rest/RestRollupSearchAction.java @@ -8,7 +8,6 @@ import org.elasticsearch.action.search.SearchRequest; import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.rest.action.search.RestSearchAction; @@ -18,19 +17,27 @@ import java.util.Arrays; import java.util.Collections; import java.util.HashSet; +import java.util.List; import java.util.Set; +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; +import static org.elasticsearch.rest.RestRequest.Method.GET; +import static org.elasticsearch.rest.RestRequest.Method.POST; + public class RestRollupSearchAction extends BaseRestHandler { private static final Set RESPONSE_PARAMS = Collections.unmodifiableSet(new HashSet<>(Arrays.asList( RestSearchAction.TYPED_KEYS_PARAM, RestSearchAction.TOTAL_HITS_AS_INT_PARAM))); - public RestRollupSearchAction(RestController controller) { - controller.registerHandler(RestRequest.Method.GET, "_rollup_search", this); - controller.registerHandler(RestRequest.Method.POST, "_rollup_search", this); - controller.registerHandler(RestRequest.Method.GET, "{index}/_rollup_search", this); - controller.registerHandler(RestRequest.Method.POST, "{index}/_rollup_search", this); + @Override + public List routes() { + return unmodifiableList(asList( + new Route(GET, "_rollup_search"), + new Route(POST, "_rollup_search"), + new Route(GET, "{index}/_rollup_search"), + new Route(POST, "{index}/_rollup_search"))); } @Override diff --git a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/rest/RestStartRollupJobAction.java b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/rest/RestStartRollupJobAction.java index 3e9e3ad0fc652..25728e64f6d48 100644 --- a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/rest/RestStartRollupJobAction.java +++ b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/rest/RestStartRollupJobAction.java @@ -10,23 +10,30 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.rollup.RollupField; import org.elasticsearch.xpack.core.rollup.action.StartRollupJobAction; +import java.util.List; + +import static java.util.Collections.emptyList; +import static java.util.Collections.singletonList; import static org.elasticsearch.rest.RestRequest.Method.POST; public class RestStartRollupJobAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestStartRollupJobAction.class)); - public RestStartRollupJobAction(RestController controller) { - // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - POST, "/_rollup/job/{id}/_start", this, - POST, "/_xpack/rollup/job/{id}/_start", deprecationLogger); + @Override + public List routes() { + return emptyList(); + } + + @Override + public List replacedRoutes() { + return singletonList( + new ReplacedRoute(POST, "/_rollup/job/{id}/_start", POST, "/_xpack/rollup/job/{id}/_start", deprecationLogger)); } @Override diff --git a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/rest/RestStopRollupJobAction.java b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/rest/RestStopRollupJobAction.java index 107adf941b2ce..b818c590ac3b5 100644 --- a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/rest/RestStopRollupJobAction.java +++ b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/rest/RestStopRollupJobAction.java @@ -11,23 +11,30 @@ import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.rollup.RollupField; import org.elasticsearch.xpack.core.rollup.action.StopRollupJobAction; +import java.util.List; + +import static java.util.Collections.emptyList; +import static java.util.Collections.singletonList; import static org.elasticsearch.rest.RestRequest.Method.POST; public class RestStopRollupJobAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestStopRollupJobAction.class)); - public RestStopRollupJobAction(RestController controller) { - // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - POST, "/_rollup/job/{id}/_stop", this, - POST, "/_xpack/rollup/job/{id}/_stop", deprecationLogger); + @Override + public List routes() { + return emptyList(); + } + + @Override + public List replacedRoutes() { + return singletonList( + new ReplacedRoute(POST, "/_rollup/job/{id}/_stop", POST, "/_xpack/rollup/job/{id}/_stop", deprecationLogger)); } @Override diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/Security.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/Security.java index f43fb5d805ca6..0393ca4931f7e 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/Security.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/Security.java @@ -815,40 +815,40 @@ public List getRestHandlers(Settings settings, RestController restC return emptyList(); } return Arrays.asList( - new RestAuthenticateAction(settings, restController, securityContext.get(), getLicenseState()), - new RestClearRealmCacheAction(settings, restController, getLicenseState()), - new RestClearRolesCacheAction(settings, restController, getLicenseState()), - new RestGetUsersAction(settings, restController, getLicenseState()), - new RestPutUserAction(settings, restController, getLicenseState()), - new RestDeleteUserAction(settings, restController, getLicenseState()), - new RestGetRolesAction(settings, restController, getLicenseState()), - new RestPutRoleAction(settings, restController, getLicenseState()), - new RestDeleteRoleAction(settings, restController, getLicenseState()), - new RestChangePasswordAction(settings, restController, securityContext.get(), getLicenseState()), - new RestSetEnabledAction(settings, restController, getLicenseState()), - new RestHasPrivilegesAction(settings, restController, securityContext.get(), getLicenseState()), - new RestGetUserPrivilegesAction(settings, restController, securityContext.get(), getLicenseState()), - new RestGetRoleMappingsAction(settings, restController, getLicenseState()), - new RestPutRoleMappingAction(settings, restController, getLicenseState()), - new RestDeleteRoleMappingAction(settings, restController, getLicenseState()), - new RestGetTokenAction(settings, restController, getLicenseState()), - new RestInvalidateTokenAction(settings, restController, getLicenseState()), - new RestGetCertificateInfoAction(restController), - new RestSamlPrepareAuthenticationAction(settings, restController, getLicenseState()), - new RestSamlAuthenticateAction(settings, restController, getLicenseState()), - new RestSamlLogoutAction(settings, restController, getLicenseState()), - new RestSamlInvalidateSessionAction(settings, restController, getLicenseState()), - new RestOpenIdConnectPrepareAuthenticationAction(settings, restController, getLicenseState()), - new RestOpenIdConnectAuthenticateAction(settings, restController, getLicenseState()), - new RestOpenIdConnectLogoutAction(settings, restController, getLicenseState()), - new RestGetBuiltinPrivilegesAction(settings, restController, getLicenseState()), - new RestGetPrivilegesAction(settings, restController, getLicenseState()), - new RestPutPrivilegesAction(settings, restController, getLicenseState()), - new RestDeletePrivilegesAction(settings, restController, getLicenseState()), - new RestCreateApiKeyAction(settings, restController, getLicenseState()), - new RestInvalidateApiKeyAction(settings, restController, getLicenseState()), - new RestGetApiKeyAction(settings, restController, getLicenseState()), - new RestDelegatePkiAuthenticationAction(settings, restController, getLicenseState()) + new RestAuthenticateAction(settings, securityContext.get(), getLicenseState()), + new RestClearRealmCacheAction(settings, getLicenseState()), + new RestClearRolesCacheAction(settings, getLicenseState()), + new RestGetUsersAction(settings, getLicenseState()), + new RestPutUserAction(settings, getLicenseState()), + new RestDeleteUserAction(settings, getLicenseState()), + new RestGetRolesAction(settings, getLicenseState()), + new RestPutRoleAction(settings, getLicenseState()), + new RestDeleteRoleAction(settings, getLicenseState()), + new RestChangePasswordAction(settings, securityContext.get(), getLicenseState()), + new RestSetEnabledAction(settings, getLicenseState()), + new RestHasPrivilegesAction(settings, securityContext.get(), getLicenseState()), + new RestGetUserPrivilegesAction(settings, securityContext.get(), getLicenseState()), + new RestGetRoleMappingsAction(settings, getLicenseState()), + new RestPutRoleMappingAction(settings, getLicenseState()), + new RestDeleteRoleMappingAction(settings, getLicenseState()), + new RestGetTokenAction(settings, getLicenseState()), + new RestInvalidateTokenAction(settings, getLicenseState()), + new RestGetCertificateInfoAction(), + new RestSamlPrepareAuthenticationAction(settings, getLicenseState()), + new RestSamlAuthenticateAction(settings, getLicenseState()), + new RestSamlLogoutAction(settings, getLicenseState()), + new RestSamlInvalidateSessionAction(settings, getLicenseState()), + new RestOpenIdConnectPrepareAuthenticationAction(settings, getLicenseState()), + new RestOpenIdConnectAuthenticateAction(settings, getLicenseState()), + new RestOpenIdConnectLogoutAction(settings, getLicenseState()), + new RestGetBuiltinPrivilegesAction(settings, getLicenseState()), + new RestGetPrivilegesAction(settings, getLicenseState()), + new RestPutPrivilegesAction(settings, getLicenseState()), + new RestDeletePrivilegesAction(settings, getLicenseState()), + new RestCreateApiKeyAction(settings, getLicenseState()), + new RestInvalidateApiKeyAction(settings, getLicenseState()), + new RestGetApiKeyAction(settings, getLicenseState()), + new RestDelegatePkiAuthenticationAction(settings, getLicenseState()) ); } diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/SecurityRestFilter.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/SecurityRestFilter.java index 4131d1e735883..62cf944819a27 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/SecurityRestFilter.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/SecurityRestFilter.java @@ -24,6 +24,7 @@ import org.elasticsearch.xpack.security.transport.SSLEngineUtils; import java.io.IOException; +import java.util.List; public class SecurityRestFilter implements RestHandler { @@ -91,6 +92,21 @@ public boolean allowsUnsafeBuffers() { return restHandler.allowsUnsafeBuffers(); } + @Override + public List routes() { + return restHandler.routes(); + } + + @Override + public List deprecatedRoutes() { + return restHandler.deprecatedRoutes(); + } + + @Override + public List replacedRoutes() { + return restHandler.replacedRoutes(); + } + private RestRequest maybeWrapRestRequest(RestRequest restRequest) throws IOException { if (restHandler instanceof RestRequestFilter) { return ((RestRequestFilter)restHandler).getFilteredRequest(restRequest); diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/RestAuthenticateAction.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/RestAuthenticateAction.java index 09f0679378c54..33dcc311c4882 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/RestAuthenticateAction.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/RestAuthenticateAction.java @@ -13,7 +13,6 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.license.XPackLicenseState; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; @@ -25,6 +24,8 @@ import org.elasticsearch.xpack.core.security.user.User; import java.io.IOException; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.GET; @@ -33,14 +34,21 @@ public class RestAuthenticateAction extends SecurityBaseRestHandler { private final SecurityContext securityContext; private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestAuthenticateAction.class)); - public RestAuthenticateAction(Settings settings, RestController controller, SecurityContext securityContext, - XPackLicenseState licenseState) { + public RestAuthenticateAction(Settings settings, SecurityContext securityContext, XPackLicenseState licenseState) { super(settings, licenseState); this.securityContext = securityContext; + } + + @Override + public List routes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - GET, "/_security/_authenticate", this, - GET, "/_xpack/security/_authenticate", deprecationLogger); + return Collections.singletonList(new ReplacedRoute(GET, "/_security/_authenticate", GET, + "/_xpack/security/_authenticate", deprecationLogger)); } @Override diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/RestDelegatePkiAuthenticationAction.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/RestDelegatePkiAuthenticationAction.java index c63d965a3b7c6..4dea0899f83f2 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/RestDelegatePkiAuthenticationAction.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/RestDelegatePkiAuthenticationAction.java @@ -10,25 +10,26 @@ import org.apache.logging.log4j.Logger; import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.license.LicenseUtils; import org.elasticsearch.license.XPackLicenseState; -import org.elasticsearch.rest.RestController; -import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.BytesRestResponse; +import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; import org.elasticsearch.rest.action.RestBuilderListener; import org.elasticsearch.xpack.core.security.action.DelegatePkiAuthenticationAction; import org.elasticsearch.xpack.core.security.action.DelegatePkiAuthenticationRequest; -import org.elasticsearch.xpack.security.action.TransportDelegatePkiAuthenticationAction; -import org.elasticsearch.xpack.security.authc.Realms; import org.elasticsearch.xpack.core.security.action.DelegatePkiAuthenticationResponse; import org.elasticsearch.xpack.core.security.authc.pki.PkiRealmSettings; -import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.xpack.security.action.TransportDelegatePkiAuthenticationAction; +import org.elasticsearch.xpack.security.authc.Realms; import java.io.IOException; +import java.util.List; +import static java.util.Collections.singletonList; import static org.elasticsearch.rest.RestRequest.Method.POST; /** @@ -40,9 +41,13 @@ public final class RestDelegatePkiAuthenticationAction extends SecurityBaseRestH protected Logger logger = LogManager.getLogger(RestDelegatePkiAuthenticationAction.class); - public RestDelegatePkiAuthenticationAction(Settings settings, RestController controller, XPackLicenseState xPackLicenseState) { + public RestDelegatePkiAuthenticationAction(Settings settings, XPackLicenseState xPackLicenseState) { super(settings, xPackLicenseState); - controller.registerHandler(POST, "/_security/delegate_pki", this); + } + + @Override + public List routes() { + return singletonList(new Route(POST, "/_security/delegate_pki")); } @Override diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/apikey/RestCreateApiKeyAction.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/apikey/RestCreateApiKeyAction.java index 14d4726553dff..75b91246caa22 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/apikey/RestCreateApiKeyAction.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/apikey/RestCreateApiKeyAction.java @@ -11,7 +11,6 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.license.XPackLicenseState; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.security.action.CreateApiKeyRequest; @@ -20,6 +19,12 @@ import org.elasticsearch.xpack.core.security.client.SecurityClient; import java.io.IOException; +import java.util.List; + +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; +import static org.elasticsearch.rest.RestRequest.Method.POST; +import static org.elasticsearch.rest.RestRequest.Method.PUT; /** * Rest action to create an API key @@ -31,10 +36,15 @@ public final class RestCreateApiKeyAction extends ApiKeyBaseRestHandler { * @param licenseState the license state that will be used to determine if * security is licensed */ - public RestCreateApiKeyAction(Settings settings, RestController controller, XPackLicenseState licenseState) { + public RestCreateApiKeyAction(Settings settings, XPackLicenseState licenseState) { super(settings, licenseState); - controller.registerHandler(RestRequest.Method.POST, "/_security/api_key", this); - controller.registerHandler(RestRequest.Method.PUT, "/_security/api_key", this); + } + + @Override + public List routes() { + return unmodifiableList(asList( + new Route(POST, "/_security/api_key"), + new Route(PUT, "/_security/api_key"))); } @Override diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/apikey/RestGetApiKeyAction.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/apikey/RestGetApiKeyAction.java index ca07952478444..74bf64ba4daf3 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/apikey/RestGetApiKeyAction.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/apikey/RestGetApiKeyAction.java @@ -12,7 +12,6 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.license.XPackLicenseState; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; @@ -22,15 +21,23 @@ import org.elasticsearch.xpack.core.security.action.GetApiKeyResponse; import java.io.IOException; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.GET; /** * Rest action to get one or more API keys information. */ public final class RestGetApiKeyAction extends ApiKeyBaseRestHandler { - public RestGetApiKeyAction(Settings settings, RestController controller, XPackLicenseState licenseState) { + public RestGetApiKeyAction(Settings settings, XPackLicenseState licenseState) { super(settings, licenseState); - controller.registerHandler(RestRequest.Method.GET, "/_security/api_key", this); + } + + @Override + public List routes() { + return singletonList(new Route(GET, "/_security/api_key")); } @Override diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/apikey/RestInvalidateApiKeyAction.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/apikey/RestInvalidateApiKeyAction.java index 0579932887677..86064b953d008 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/apikey/RestInvalidateApiKeyAction.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/apikey/RestInvalidateApiKeyAction.java @@ -14,7 +14,6 @@ import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.license.XPackLicenseState; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; @@ -24,6 +23,10 @@ import org.elasticsearch.xpack.core.security.action.InvalidateApiKeyResponse; import java.io.IOException; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.DELETE; /** * Rest action to invalidate one or more API keys @@ -43,9 +46,13 @@ public final class RestInvalidateApiKeyAction extends ApiKeyBaseRestHandler { PARSER.declareBoolean(ConstructingObjectParser.optionalConstructorArg(), new ParseField("owner")); } - public RestInvalidateApiKeyAction(Settings settings, RestController controller, XPackLicenseState licenseState) { + public RestInvalidateApiKeyAction(Settings settings, XPackLicenseState licenseState) { super(settings, licenseState); - controller.registerHandler(RestRequest.Method.DELETE, "/_security/api_key", this); + } + + @Override + public List routes() { + return singletonList(new Route(DELETE, "/_security/api_key")); } @Override diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/oauth2/RestGetTokenAction.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/oauth2/RestGetTokenAction.java index c3734f37d1a54..d2efb784a76ec 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/oauth2/RestGetTokenAction.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/oauth2/RestGetTokenAction.java @@ -8,9 +8,9 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.elasticsearch.ElasticsearchSecurityException; -import org.elasticsearch.action.ActionType; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.ActionRequestValidationException; +import org.elasticsearch.action.ActionType; import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.ParseField; import org.elasticsearch.common.logging.DeprecationLogger; @@ -23,7 +23,6 @@ import org.elasticsearch.license.XPackLicenseState; import org.elasticsearch.rest.BytesRestResponse; import org.elasticsearch.rest.RestChannel; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestStatus; import org.elasticsearch.xpack.core.security.action.token.CreateTokenAction; @@ -34,6 +33,7 @@ import java.io.IOException; import java.util.Arrays; +import java.util.Collections; import java.util.List; import java.util.Locale; @@ -65,12 +65,21 @@ public final class RestGetTokenAction extends TokenBaseRestHandler { PARSER.declareString(ConstructingObjectParser.optionalConstructorArg(), new ParseField("refresh_token")); } - public RestGetTokenAction(Settings settings, RestController controller, XPackLicenseState xPackLicenseState) { + public RestGetTokenAction(Settings settings, XPackLicenseState xPackLicenseState) { super(settings, xPackLicenseState); + } + + @Override + public List routes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - POST, "/_security/oauth2/token", this, - POST, "/_xpack/security/oauth2/token", deprecationLogger); + return Collections.singletonList( + new ReplacedRoute(POST, "/_security/oauth2/token", POST, "/_xpack/security/oauth2/token", deprecationLogger) + ); } @Override diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/oauth2/RestInvalidateTokenAction.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/oauth2/RestInvalidateTokenAction.java index cb72e53bcc8d3..26caf487950d1 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/oauth2/RestInvalidateTokenAction.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/oauth2/RestInvalidateTokenAction.java @@ -16,7 +16,6 @@ import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.license.XPackLicenseState; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; @@ -26,6 +25,8 @@ import org.elasticsearch.xpack.core.security.action.token.InvalidateTokenResponse; import java.io.IOException; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.DELETE; @@ -63,12 +64,21 @@ public final class RestInvalidateTokenAction extends TokenBaseRestHandler { PARSER.declareString(ConstructingObjectParser.optionalConstructorArg(), new ParseField("username")); } - public RestInvalidateTokenAction(Settings settings, RestController controller, XPackLicenseState xPackLicenseState) { + public RestInvalidateTokenAction(Settings settings, XPackLicenseState xPackLicenseState) { super(settings, xPackLicenseState); + } + + @Override + public List routes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - DELETE, "/_security/oauth2/token", this, - DELETE, "/_xpack/security/oauth2/token", deprecationLogger); + return Collections.singletonList( + new ReplacedRoute(DELETE, "/_security/oauth2/token", DELETE, "/_xpack/security/oauth2/token", deprecationLogger) + ); } @Override diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/oidc/RestOpenIdConnectAuthenticateAction.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/oidc/RestOpenIdConnectAuthenticateAction.java index d820fb7a88b47..a297b2f7cd6b5 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/oidc/RestOpenIdConnectAuthenticateAction.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/oidc/RestOpenIdConnectAuthenticateAction.java @@ -15,7 +15,6 @@ import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.license.XPackLicenseState; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; @@ -25,7 +24,9 @@ import org.elasticsearch.xpack.core.security.action.oidc.OpenIdConnectAuthenticateResponse; import java.io.IOException; +import java.util.List; +import static java.util.Collections.singletonList; import static org.elasticsearch.rest.RestRequest.Method.POST; /** @@ -44,9 +45,13 @@ public class RestOpenIdConnectAuthenticateAction extends OpenIdConnectBaseRestHa PARSER.declareStringOrNull(OpenIdConnectAuthenticateRequest::setRealm, new ParseField("realm")); } - public RestOpenIdConnectAuthenticateAction(Settings settings, RestController controller, XPackLicenseState licenseState) { + public RestOpenIdConnectAuthenticateAction(Settings settings, XPackLicenseState licenseState) { super(settings, licenseState); - controller.registerHandler(POST, "/_security/oidc/authenticate", this); + } + + @Override + public List routes() { + return singletonList(new Route(POST, "/_security/oidc/authenticate")); } @Override diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/oidc/RestOpenIdConnectLogoutAction.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/oidc/RestOpenIdConnectLogoutAction.java index e098e14c423b8..f9485f91beba2 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/oidc/RestOpenIdConnectLogoutAction.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/oidc/RestOpenIdConnectLogoutAction.java @@ -13,7 +13,6 @@ import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.license.XPackLicenseState; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; @@ -23,7 +22,9 @@ import org.elasticsearch.xpack.core.security.action.oidc.OpenIdConnectLogoutResponse; import java.io.IOException; +import java.util.List; +import static java.util.Collections.singletonList; import static org.elasticsearch.rest.RestRequest.Method.POST; /** @@ -40,9 +41,13 @@ public class RestOpenIdConnectLogoutAction extends OpenIdConnectBaseRestHandler PARSER.declareString(OpenIdConnectLogoutRequest::setRefreshToken, new ParseField("refresh_token")); } - public RestOpenIdConnectLogoutAction(Settings settings, RestController controller, XPackLicenseState licenseState) { + public RestOpenIdConnectLogoutAction(Settings settings, XPackLicenseState licenseState) { super(settings, licenseState); - controller.registerHandler(POST, "/_security/oidc/logout", this); + } + + @Override + public List routes() { + return singletonList(new Route(POST, "/_security/oidc/logout")); } @Override diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/oidc/RestOpenIdConnectPrepareAuthenticationAction.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/oidc/RestOpenIdConnectPrepareAuthenticationAction.java index c86da0ed4edc9..d38febbbc33e8 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/oidc/RestOpenIdConnectPrepareAuthenticationAction.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/oidc/RestOpenIdConnectPrepareAuthenticationAction.java @@ -15,7 +15,6 @@ import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.license.XPackLicenseState; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; @@ -25,7 +24,9 @@ import org.elasticsearch.xpack.core.security.action.oidc.OpenIdConnectPrepareAuthenticationResponse; import java.io.IOException; +import java.util.List; +import static java.util.Collections.singletonList; import static org.elasticsearch.rest.RestRequest.Method.POST; /** @@ -45,9 +46,13 @@ public class RestOpenIdConnectPrepareAuthenticationAction extends OpenIdConnectB PARSER.declareString(OpenIdConnectPrepareAuthenticationRequest::setNonce, new ParseField("nonce")); } - public RestOpenIdConnectPrepareAuthenticationAction(Settings settings, RestController controller, XPackLicenseState licenseState) { + public RestOpenIdConnectPrepareAuthenticationAction(Settings settings, XPackLicenseState licenseState) { super(settings, licenseState); - controller.registerHandler(POST, "/_security/oidc/prepare", this); + } + + @Override + public List routes() { + return singletonList(new Route(POST, "/_security/oidc/prepare")); } @Override diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/privilege/RestDeletePrivilegesAction.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/privilege/RestDeletePrivilegesAction.java index 1f96df23e0e77..1ac737c9f7259 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/privilege/RestDeletePrivilegesAction.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/privilege/RestDeletePrivilegesAction.java @@ -12,7 +12,6 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.license.XPackLicenseState; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; @@ -25,6 +24,7 @@ import java.util.Arrays; import java.util.Collections; import java.util.HashSet; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.DELETE; @@ -36,12 +36,20 @@ public class RestDeletePrivilegesAction extends SecurityBaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestDeletePrivilegesAction.class)); - public RestDeletePrivilegesAction(Settings settings, RestController controller, XPackLicenseState licenseState) { + public RestDeletePrivilegesAction(Settings settings, XPackLicenseState licenseState) { super(settings, licenseState); + } + + @Override + public List routes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - DELETE, "/_security/privilege/{application}/{privilege}", this, - DELETE, "/_xpack/security/privilege/{application}/{privilege}", deprecationLogger); + return Collections.singletonList(new ReplacedRoute(DELETE, "/_security/privilege/{application}/{privilege}", DELETE, + "/_xpack/security/privilege/{application}/{privilege}", deprecationLogger)); } @Override diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/privilege/RestGetBuiltinPrivilegesAction.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/privilege/RestGetBuiltinPrivilegesAction.java index 6079647f0935a..a40ff65f581f1 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/privilege/RestGetBuiltinPrivilegesAction.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/privilege/RestGetBuiltinPrivilegesAction.java @@ -10,7 +10,6 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.license.XPackLicenseState; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; @@ -21,7 +20,9 @@ import org.elasticsearch.xpack.security.rest.action.SecurityBaseRestHandler; import java.io.IOException; +import java.util.List; +import static java.util.Collections.singletonList; import static org.elasticsearch.rest.RestRequest.Method.GET; /** @@ -29,10 +30,13 @@ */ public class RestGetBuiltinPrivilegesAction extends SecurityBaseRestHandler { - public RestGetBuiltinPrivilegesAction(Settings settings, RestController controller, XPackLicenseState licenseState) { + public RestGetBuiltinPrivilegesAction(Settings settings, XPackLicenseState licenseState) { super(settings, licenseState); - controller.registerHandler( - GET, "/_security/privilege/_builtin", this); + } + + @Override + public List routes() { + return singletonList(new Route(GET, "/_security/privilege/_builtin")); } @Override diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/privilege/RestGetPrivilegesAction.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/privilege/RestGetPrivilegesAction.java index e0d0898704e3b..0cf4bc6d4b879 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/privilege/RestGetPrivilegesAction.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/privilege/RestGetPrivilegesAction.java @@ -14,7 +14,6 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.license.XPackLicenseState; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; @@ -27,6 +26,7 @@ import java.io.IOException; import java.util.Arrays; import java.util.Collections; +import java.util.List; import java.util.Map; import java.util.Set; import java.util.stream.Collectors; @@ -40,18 +40,25 @@ public class RestGetPrivilegesAction extends SecurityBaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestGetPrivilegesAction.class)); - public RestGetPrivilegesAction(Settings settings, RestController controller, XPackLicenseState licenseState) { + public RestGetPrivilegesAction(Settings settings, XPackLicenseState licenseState) { super(settings, licenseState); + } + + @Override + public List routes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - GET, "/_security/privilege/", this, - GET, "/_xpack/security/privilege/", deprecationLogger); - controller.registerWithDeprecatedHandler( - GET, "/_security/privilege/{application}", this, - GET, "/_xpack/security/privilege/{application}", deprecationLogger); - controller.registerWithDeprecatedHandler( - GET, "/_security/privilege/{application}/{privilege}", this, - GET, "/_xpack/security/privilege/{application}/{privilege}", deprecationLogger); + return Collections.unmodifiableList(Arrays.asList( + new ReplacedRoute(GET, "/_security/privilege/", GET, "/_xpack/security/privilege/", deprecationLogger), + new ReplacedRoute(GET, "/_security/privilege/{application}", + GET, "/_xpack/security/privilege/{application}", deprecationLogger), + new ReplacedRoute(GET, "/_security/privilege/{application}/{privilege}", + GET, "/_xpack/security/privilege/{application}/{privilege}", deprecationLogger) + )); } @Override diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/privilege/RestPutPrivilegesAction.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/privilege/RestPutPrivilegesAction.java index abc2f00afcd81..38bde90e1f221 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/privilege/RestPutPrivilegesAction.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/privilege/RestPutPrivilegesAction.java @@ -12,7 +12,6 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.license.XPackLicenseState; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; @@ -25,6 +24,7 @@ import org.elasticsearch.xpack.security.rest.action.SecurityBaseRestHandler; import java.io.IOException; +import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.List; @@ -39,15 +39,22 @@ public class RestPutPrivilegesAction extends SecurityBaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestPutPrivilegesAction.class)); - public RestPutPrivilegesAction(Settings settings, RestController controller, XPackLicenseState licenseState) { + public RestPutPrivilegesAction(Settings settings, XPackLicenseState licenseState) { super(settings, licenseState); + } + + @Override + public List routes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - PUT, "/_security/privilege/", this, - PUT, "/_xpack/security/privilege/", deprecationLogger); - controller.registerWithDeprecatedHandler( - POST, "/_security/privilege/", this, - POST, "/_xpack/security/privilege/", deprecationLogger); + return Collections.unmodifiableList(Arrays.asList( + new ReplacedRoute(PUT, "/_security/privilege/", PUT, "/_xpack/security/privilege/", deprecationLogger), + new ReplacedRoute(POST, "/_security/privilege/", POST, "/_xpack/security/privilege/", deprecationLogger) + )); } @Override diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/realm/RestClearRealmCacheAction.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/realm/RestClearRealmCacheAction.java index da9b1a1828b66..df2f8c89d2b72 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/realm/RestClearRealmCacheAction.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/realm/RestClearRealmCacheAction.java @@ -10,7 +10,6 @@ import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.license.XPackLicenseState; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestActions.NodesResponseRestListener; import org.elasticsearch.xpack.core.security.action.realm.ClearRealmCacheRequest; @@ -18,6 +17,8 @@ import org.elasticsearch.xpack.security.rest.action.SecurityBaseRestHandler; import java.io.IOException; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.POST; @@ -25,12 +26,22 @@ public final class RestClearRealmCacheAction extends SecurityBaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestClearRealmCacheAction.class)); - public RestClearRealmCacheAction(Settings settings, RestController controller, XPackLicenseState licenseState) { + public RestClearRealmCacheAction(Settings settings, XPackLicenseState licenseState) { super(settings, licenseState); + } + + @Override + public List routes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - POST, "/_security/realm/{realms}/_clear_cache", this, - POST, "/_xpack/security/realm/{realms}/_clear_cache", deprecationLogger); + return Collections.singletonList( + new ReplacedRoute(POST, "/_security/realm/{realms}/_clear_cache", + POST, "/_xpack/security/realm/{realms}/_clear_cache", deprecationLogger) + ); } @Override diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/role/RestClearRolesCacheAction.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/role/RestClearRolesCacheAction.java index a51db748ccc29..af62e8d5ccc74 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/role/RestClearRolesCacheAction.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/role/RestClearRolesCacheAction.java @@ -10,7 +10,6 @@ import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.license.XPackLicenseState; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestActions.NodesResponseRestListener; import org.elasticsearch.xpack.core.security.action.role.ClearRolesCacheRequest; @@ -18,6 +17,8 @@ import org.elasticsearch.xpack.security.rest.action.SecurityBaseRestHandler; import java.io.IOException; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.POST; @@ -25,12 +26,20 @@ public final class RestClearRolesCacheAction extends SecurityBaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestClearRolesCacheAction.class)); - public RestClearRolesCacheAction(Settings settings, RestController controller, XPackLicenseState licenseState) { + public RestClearRolesCacheAction(Settings settings, XPackLicenseState licenseState) { super(settings, licenseState); + } + + @Override + public List routes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - POST, "/_security/role/{name}/_clear_cache", this, - POST, "/_xpack/security/role/{name}/_clear_cache", deprecationLogger); + return Collections.singletonList(new ReplacedRoute(POST, "/_security/role/{name}/_clear_cache", POST, + "/_xpack/security/role/{name}/_clear_cache", deprecationLogger)); } @Override diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/role/RestDeleteRoleAction.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/role/RestDeleteRoleAction.java index 26399f4da9118..fa92846d25678 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/role/RestDeleteRoleAction.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/role/RestDeleteRoleAction.java @@ -12,7 +12,6 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.license.XPackLicenseState; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; @@ -22,6 +21,8 @@ import org.elasticsearch.xpack.security.rest.action.SecurityBaseRestHandler; import java.io.IOException; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.DELETE; @@ -32,12 +33,20 @@ public class RestDeleteRoleAction extends SecurityBaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestDeleteRoleAction.class)); - public RestDeleteRoleAction(Settings settings, RestController controller, XPackLicenseState licenseState) { + public RestDeleteRoleAction(Settings settings, XPackLicenseState licenseState) { super(settings, licenseState); + } + + @Override + public List routes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - DELETE, "/_security/role/{name}", this, - DELETE, "/_xpack/security/role/{name}", deprecationLogger); + return Collections.singletonList(new ReplacedRoute(DELETE, "/_security/role/{name}", DELETE, + "/_xpack/security/role/{name}", deprecationLogger)); } @Override diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/role/RestGetRolesAction.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/role/RestGetRolesAction.java index 850709eea8634..e935c6c837e60 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/role/RestGetRolesAction.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/role/RestGetRolesAction.java @@ -13,7 +13,6 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.license.XPackLicenseState; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; @@ -24,6 +23,9 @@ import org.elasticsearch.xpack.security.rest.action.SecurityBaseRestHandler; import java.io.IOException; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.GET; @@ -34,15 +36,22 @@ public class RestGetRolesAction extends SecurityBaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestGetRolesAction.class)); - public RestGetRolesAction(Settings settings, RestController controller, XPackLicenseState licenseState) { + public RestGetRolesAction(Settings settings, XPackLicenseState licenseState) { super(settings, licenseState); + } + + @Override + public List routes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - GET, "/_security/role/", this, - GET, "/_xpack/security/role/", deprecationLogger); - controller.registerWithDeprecatedHandler( - GET, "/_security/role/{name}", this, - GET, "/_xpack/security/role/{name}", deprecationLogger); + return Collections.unmodifiableList(Arrays.asList( + new ReplacedRoute(GET, "/_security/role/", GET, "/_xpack/security/role/", deprecationLogger), + new ReplacedRoute(GET, "/_security/role/{name}", GET, "/_xpack/security/role/{name}", deprecationLogger) + )); } @Override diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/role/RestPutRoleAction.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/role/RestPutRoleAction.java index 10673cd79fac7..83cd63714cea9 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/role/RestPutRoleAction.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/role/RestPutRoleAction.java @@ -12,7 +12,6 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.license.XPackLicenseState; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; @@ -23,6 +22,9 @@ import org.elasticsearch.xpack.security.rest.action.SecurityBaseRestHandler; import java.io.IOException; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.POST; import static org.elasticsearch.rest.RestRequest.Method.PUT; @@ -34,15 +36,22 @@ public class RestPutRoleAction extends SecurityBaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestPutRoleAction.class)); - public RestPutRoleAction(Settings settings, RestController controller, XPackLicenseState licenseState) { + public RestPutRoleAction(Settings settings, XPackLicenseState licenseState) { super(settings, licenseState); + } + + @Override + public List routes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - POST, "/_security/role/{name}", this, - POST, "/_xpack/security/role/{name}", deprecationLogger); - controller.registerWithDeprecatedHandler( - PUT, "/_security/role/{name}", this, - PUT, "/_xpack/security/role/{name}", deprecationLogger); + return Collections.unmodifiableList(Arrays.asList( + new ReplacedRoute(POST, "/_security/role/{name}", POST, "/_xpack/security/role/{name}", deprecationLogger), + new ReplacedRoute(PUT, "/_security/role/{name}", PUT, "/_xpack/security/role/{name}", deprecationLogger) + )); } @Override diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/rolemapping/RestDeleteRoleMappingAction.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/rolemapping/RestDeleteRoleMappingAction.java index a2be9ba9e041e..f2415f8a2cca3 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/rolemapping/RestDeleteRoleMappingAction.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/rolemapping/RestDeleteRoleMappingAction.java @@ -12,7 +12,6 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.license.XPackLicenseState; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; @@ -22,6 +21,8 @@ import org.elasticsearch.xpack.security.rest.action.SecurityBaseRestHandler; import java.io.IOException; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.DELETE; @@ -33,12 +34,21 @@ public class RestDeleteRoleMappingAction extends SecurityBaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestDeleteRoleMappingAction.class)); - public RestDeleteRoleMappingAction(Settings settings, RestController controller, XPackLicenseState licenseState) { + public RestDeleteRoleMappingAction(Settings settings, XPackLicenseState licenseState) { super(settings, licenseState); + } + + @Override + public List routes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - DELETE, "/_security/role_mapping/{name}", this, - DELETE, "/_xpack/security/role_mapping/{name}", deprecationLogger); + return Collections.singletonList( + new ReplacedRoute(DELETE, "/_security/role_mapping/{name}", DELETE, "/_xpack/security/role_mapping/{name}", deprecationLogger) + ); } @Override diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/rolemapping/RestGetRoleMappingsAction.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/rolemapping/RestGetRoleMappingsAction.java index ceabeb3a62eb2..76da6cc46c780 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/rolemapping/RestGetRoleMappingsAction.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/rolemapping/RestGetRoleMappingsAction.java @@ -12,7 +12,6 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.license.XPackLicenseState; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; @@ -23,6 +22,9 @@ import org.elasticsearch.xpack.security.rest.action.SecurityBaseRestHandler; import java.io.IOException; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.GET; @@ -33,15 +35,22 @@ public class RestGetRoleMappingsAction extends SecurityBaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestGetRoleMappingsAction.class)); - public RestGetRoleMappingsAction(Settings settings, RestController controller, XPackLicenseState licenseState) { + public RestGetRoleMappingsAction(Settings settings, XPackLicenseState licenseState) { super(settings, licenseState); + } + + @Override + public List routes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - GET, "/_security/role_mapping/", this, - GET, "/_xpack/security/role_mapping/", deprecationLogger); - controller.registerWithDeprecatedHandler( - GET, "/_security/role_mapping/{name}", this, - GET, "/_xpack/security/role_mapping/{name}", deprecationLogger); + return Collections.unmodifiableList(Arrays.asList( + new ReplacedRoute(GET, "/_security/role_mapping/", GET, "/_xpack/security/role_mapping/", deprecationLogger), + new ReplacedRoute(GET, "/_security/role_mapping/{name}", GET, "/_xpack/security/role_mapping/{name}", deprecationLogger) + )); } @Override diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/rolemapping/RestPutRoleMappingAction.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/rolemapping/RestPutRoleMappingAction.java index 64c4bc9c52bc1..bb4b21144a9be 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/rolemapping/RestPutRoleMappingAction.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/rolemapping/RestPutRoleMappingAction.java @@ -12,7 +12,6 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.license.XPackLicenseState; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; @@ -23,6 +22,9 @@ import org.elasticsearch.xpack.security.rest.action.SecurityBaseRestHandler; import java.io.IOException; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.POST; import static org.elasticsearch.rest.RestRequest.Method.PUT; @@ -36,15 +38,22 @@ public class RestPutRoleMappingAction extends SecurityBaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestPutRoleMappingAction.class)); - public RestPutRoleMappingAction(Settings settings, RestController controller, XPackLicenseState licenseState) { + public RestPutRoleMappingAction(Settings settings, XPackLicenseState licenseState) { super(settings, licenseState); + } + + @Override + public List routes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - POST, "/_security/role_mapping/{name}", this, - POST, "/_xpack/security/role_mapping/{name}", deprecationLogger); - controller.registerWithDeprecatedHandler( - PUT, "/_security/role_mapping/{name}", this, - PUT, "/_xpack/security/role_mapping/{name}", deprecationLogger); + return Collections.unmodifiableList(Arrays.asList( + new ReplacedRoute(POST, "/_security/role_mapping/{name}", POST, "/_xpack/security/role_mapping/{name}", deprecationLogger), + new ReplacedRoute(PUT, "/_security/role_mapping/{name}", PUT, "/_xpack/security/role_mapping/{name}", deprecationLogger) + )); } @Override diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/saml/RestSamlAuthenticateAction.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/saml/RestSamlAuthenticateAction.java index 8416e9e035af4..e210e9ac8a3c8 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/saml/RestSamlAuthenticateAction.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/saml/RestSamlAuthenticateAction.java @@ -17,8 +17,6 @@ import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.license.XPackLicenseState; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; -import org.elasticsearch.rest.RestHandler; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; @@ -29,6 +27,7 @@ import java.io.IOException; import java.util.Base64; +import java.util.Collections; import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.POST; @@ -36,7 +35,7 @@ /** * A REST handler that attempts to authenticate a user based on the provided SAML response/assertion. */ -public class RestSamlAuthenticateAction extends SamlBaseRestHandler implements RestHandler { +public class RestSamlAuthenticateAction extends SamlBaseRestHandler { private static final Logger logger = LogManager.getLogger(); private static final DeprecationLogger deprecationLogger = new DeprecationLogger(logger); @@ -64,13 +63,22 @@ void setIds(List ids) { PARSER.declareStringOrNull(Input::setRealm, new ParseField("realm")); } - public RestSamlAuthenticateAction(Settings settings, RestController controller, - XPackLicenseState licenseState) { + public RestSamlAuthenticateAction(Settings settings, XPackLicenseState licenseState) { super(settings, licenseState); + } + + @Override + public List routes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - POST, "/_security/saml/authenticate", this, - POST, "/_xpack/security/saml/authenticate", deprecationLogger); + return Collections.singletonList( + new ReplacedRoute(POST, "/_security/saml/authenticate", + POST, "/_xpack/security/saml/authenticate", deprecationLogger) + ); } @Override diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/saml/RestSamlInvalidateSessionAction.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/saml/RestSamlInvalidateSessionAction.java index 4fe8e7ac5b256..0d5c0e3a027db 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/saml/RestSamlInvalidateSessionAction.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/saml/RestSamlInvalidateSessionAction.java @@ -5,8 +5,6 @@ */ package org.elasticsearch.xpack.security.rest.action.saml; -import java.io.IOException; - import org.apache.logging.log4j.LogManager; import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.ParseField; @@ -17,7 +15,6 @@ import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.license.XPackLicenseState; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; @@ -26,6 +23,10 @@ import org.elasticsearch.xpack.core.security.action.saml.SamlInvalidateSessionRequest; import org.elasticsearch.xpack.core.security.action.saml.SamlInvalidateSessionResponse; +import java.io.IOException; +import java.util.Collections; +import java.util.List; + import static org.elasticsearch.rest.RestRequest.Method.POST; /** @@ -45,12 +46,22 @@ public class RestSamlInvalidateSessionAction extends SamlBaseRestHandler { PARSER.declareString(SamlInvalidateSessionRequest::setRealmName, new ParseField("realm")); } - public RestSamlInvalidateSessionAction(Settings settings, RestController controller, XPackLicenseState licenseState) { + public RestSamlInvalidateSessionAction(Settings settings, XPackLicenseState licenseState) { super(settings, licenseState); + } + + @Override + public List routes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - POST, "/_security/saml/invalidate", this, - POST, "/_xpack/security/saml/invalidate", deprecationLogger); + return Collections.singletonList( + new ReplacedRoute(POST, "/_security/saml/invalidate", + POST, "/_xpack/security/saml/invalidate", deprecationLogger) + ); } @Override diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/saml/RestSamlLogoutAction.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/saml/RestSamlLogoutAction.java index 3a584664073b9..0e947c9eb038b 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/saml/RestSamlLogoutAction.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/saml/RestSamlLogoutAction.java @@ -5,8 +5,6 @@ */ package org.elasticsearch.xpack.security.rest.action.saml; -import java.io.IOException; - import org.apache.logging.log4j.LogManager; import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.ParseField; @@ -17,7 +15,6 @@ import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.license.XPackLicenseState; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; @@ -26,6 +23,10 @@ import org.elasticsearch.xpack.core.security.action.saml.SamlLogoutRequest; import org.elasticsearch.xpack.core.security.action.saml.SamlLogoutResponse; +import java.io.IOException; +import java.util.Collections; +import java.util.List; + import static org.elasticsearch.rest.RestRequest.Method.POST; /** @@ -44,12 +45,22 @@ public class RestSamlLogoutAction extends SamlBaseRestHandler { PARSER.declareString(SamlLogoutRequest::setRefreshToken, new ParseField("refresh_token")); } - public RestSamlLogoutAction(Settings settings, RestController controller, XPackLicenseState licenseState) { + public RestSamlLogoutAction(Settings settings, XPackLicenseState licenseState) { super(settings, licenseState); + } + + @Override + public List routes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - POST, "/_security/saml/logout", this, - POST, "/_xpack/security/saml/logout", deprecationLogger); + return Collections.singletonList( + new ReplacedRoute(POST, "/_security/saml/logout", + POST, "/_xpack/security/saml/logout", deprecationLogger) + ); } @Override diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/saml/RestSamlPrepareAuthenticationAction.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/saml/RestSamlPrepareAuthenticationAction.java index b227f2c767f67..13d2f771ce617 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/saml/RestSamlPrepareAuthenticationAction.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/saml/RestSamlPrepareAuthenticationAction.java @@ -5,8 +5,6 @@ */ package org.elasticsearch.xpack.security.rest.action.saml; -import java.io.IOException; - import org.apache.logging.log4j.LogManager; import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.ParseField; @@ -17,7 +15,6 @@ import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.license.XPackLicenseState; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; @@ -26,6 +23,10 @@ import org.elasticsearch.xpack.core.security.action.saml.SamlPrepareAuthenticationRequest; import org.elasticsearch.xpack.core.security.action.saml.SamlPrepareAuthenticationResponse; +import java.io.IOException; +import java.util.Collections; +import java.util.List; + import static org.elasticsearch.rest.RestRequest.Method.POST; /** @@ -47,12 +48,22 @@ public class RestSamlPrepareAuthenticationAction extends SamlBaseRestHandler { PARSER.declareString(SamlPrepareAuthenticationRequest::setRelayState, new ParseField("relay_state")); } - public RestSamlPrepareAuthenticationAction(Settings settings, RestController controller, XPackLicenseState licenseState) { + public RestSamlPrepareAuthenticationAction(Settings settings, XPackLicenseState licenseState) { super(settings, licenseState); + } + + @Override + public List routes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - POST, "/_security/saml/prepare", this, - POST, "/_xpack/security/saml/prepare", deprecationLogger); + return Collections.singletonList( + new ReplacedRoute(POST, "/_security/saml/prepare", + POST, "/_xpack/security/saml/prepare", deprecationLogger) + ); } @Override diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/user/RestChangePasswordAction.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/user/RestChangePasswordAction.java index 53341ce0b7283..de9f588fb4f2f 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/user/RestChangePasswordAction.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/user/RestChangePasswordAction.java @@ -12,7 +12,6 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.license.XPackLicenseState; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; @@ -27,7 +26,9 @@ import org.elasticsearch.xpack.security.rest.action.SecurityBaseRestHandler; import java.io.IOException; +import java.util.Arrays; import java.util.Collections; +import java.util.List; import java.util.Set; import static org.elasticsearch.rest.RestRequest.Method.POST; @@ -39,24 +40,30 @@ public class RestChangePasswordAction extends SecurityBaseRestHandler implements private final SecurityContext securityContext; private final Hasher passwordHasher; - public RestChangePasswordAction(Settings settings, RestController controller, SecurityContext securityContext, - XPackLicenseState licenseState) { + public RestChangePasswordAction(Settings settings, SecurityContext securityContext, XPackLicenseState licenseState) { super(settings, licenseState); this.securityContext = securityContext; passwordHasher = Hasher.resolve(XPackSettings.PASSWORD_HASHING_ALGORITHM.get(settings)); + } + + @Override + public List routes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - POST, "/_security/user/{username}/_password", this, - POST, "/_xpack/security/user/{username}/_password", deprecationLogger); - controller.registerWithDeprecatedHandler( - PUT, "/_security/user/{username}/_password", this, - PUT, "/_xpack/security/user/{username}/_password", deprecationLogger); - controller.registerWithDeprecatedHandler( - POST, "/_security/user/_password", this, - POST, "/_xpack/security/user/_password", deprecationLogger); - controller.registerWithDeprecatedHandler( - PUT, "/_security/user/_password", this, - PUT, "/_xpack/security/user/_password", deprecationLogger); + return Collections.unmodifiableList(Arrays.asList( + new ReplacedRoute(PUT, "/_security/user/{username}/_password", + PUT, "/_xpack/security/user/{username}/_password", deprecationLogger), + new ReplacedRoute(POST, "/_security/user/{username}/_password", + POST, "/_xpack/security/user/{username}/_password", deprecationLogger), + new ReplacedRoute(PUT, "/_security/user/_password", + PUT, "/_xpack/security/user/_password", deprecationLogger), + new ReplacedRoute(POST, "/_security/user/_password", + POST, "/_xpack/security/user/_password", deprecationLogger) + )); } @Override diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/user/RestDeleteUserAction.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/user/RestDeleteUserAction.java index 3c810ca230830..ec32528a95406 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/user/RestDeleteUserAction.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/user/RestDeleteUserAction.java @@ -12,7 +12,6 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.license.XPackLicenseState; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; @@ -22,6 +21,8 @@ import org.elasticsearch.xpack.security.rest.action.SecurityBaseRestHandler; import java.io.IOException; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.DELETE; @@ -32,12 +33,21 @@ public class RestDeleteUserAction extends SecurityBaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestDeleteUserAction.class)); - public RestDeleteUserAction(Settings settings, RestController controller, XPackLicenseState licenseState) { + public RestDeleteUserAction(Settings settings, XPackLicenseState licenseState) { super(settings, licenseState); + } + + @Override + public List routes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - DELETE, "/_security/user/{username}", this, - DELETE, "/_xpack/security/user/{username}", deprecationLogger); + return Collections.singletonList( + new ReplacedRoute(DELETE, "/_security/user/{username}", DELETE, "/_xpack/security/user/{username}", deprecationLogger) + ); } @Override diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/user/RestGetUserPrivilegesAction.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/user/RestGetUserPrivilegesAction.java index c3cd01d7e228f..6a0cf3e297216 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/user/RestGetUserPrivilegesAction.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/user/RestGetUserPrivilegesAction.java @@ -15,7 +15,6 @@ import org.elasticsearch.license.XPackLicenseState; import org.elasticsearch.rest.BytesRestResponse; import org.elasticsearch.rest.RestChannel; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; @@ -32,6 +31,7 @@ import java.io.IOException; import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.GET; @@ -44,14 +44,22 @@ public class RestGetUserPrivilegesAction extends SecurityBaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestGetUserPrivilegesAction.class)); - public RestGetUserPrivilegesAction(Settings settings, RestController controller, SecurityContext securityContext, - XPackLicenseState licenseState) { + public RestGetUserPrivilegesAction(Settings settings, SecurityContext securityContext, XPackLicenseState licenseState) { super(settings, licenseState); this.securityContext = securityContext; + } + + @Override + public List routes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - GET, "/_security/user/_privileges", this, - GET, "/_xpack/security/user/_privileges", deprecationLogger); + return Collections.singletonList( + new ReplacedRoute(GET, "/_security/user/_privileges", GET, "/_xpack/security/user/_privileges", deprecationLogger) + ); } @Override diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/user/RestGetUsersAction.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/user/RestGetUsersAction.java index 2751022d9f007..675036e67212c 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/user/RestGetUsersAction.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/user/RestGetUsersAction.java @@ -13,7 +13,6 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.license.XPackLicenseState; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; @@ -24,6 +23,9 @@ import org.elasticsearch.xpack.security.rest.action.SecurityBaseRestHandler; import java.io.IOException; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.GET; @@ -34,15 +36,22 @@ public class RestGetUsersAction extends SecurityBaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestGetUsersAction.class)); - public RestGetUsersAction(Settings settings, RestController controller, XPackLicenseState licenseState) { + public RestGetUsersAction(Settings settings, XPackLicenseState licenseState) { super(settings, licenseState); + } + + @Override + public List routes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - GET, "/_security/user/", this, - GET, "/_xpack/security/user/", deprecationLogger); - controller.registerWithDeprecatedHandler( - GET, "/_security/user/{username}", this, - GET, "/_xpack/security/user/{username}", deprecationLogger); + return Collections.unmodifiableList(Arrays.asList( + new ReplacedRoute(GET, "/_security/user/", GET, "/_xpack/security/user/", deprecationLogger), + new ReplacedRoute(GET, "/_security/user/{username}", GET, "/_xpack/security/user/{username}", deprecationLogger) + )); } @Override diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/user/RestHasPrivilegesAction.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/user/RestHasPrivilegesAction.java index f114888e16c61..ea7a680a261d1 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/user/RestHasPrivilegesAction.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/user/RestHasPrivilegesAction.java @@ -17,7 +17,6 @@ import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.license.XPackLicenseState; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; @@ -31,6 +30,9 @@ import org.elasticsearch.xpack.security.rest.action.SecurityBaseRestHandler; import java.io.IOException; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.GET; import static org.elasticsearch.rest.RestRequest.Method.POST; @@ -44,23 +46,29 @@ public class RestHasPrivilegesAction extends SecurityBaseRestHandler { private final SecurityContext securityContext; private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestHasPrivilegesAction.class)); - public RestHasPrivilegesAction(Settings settings, RestController controller, SecurityContext securityContext, - XPackLicenseState licenseState) { + public RestHasPrivilegesAction(Settings settings, SecurityContext securityContext, XPackLicenseState licenseState) { super(settings, licenseState); this.securityContext = securityContext; + } + + @Override + public List routes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - GET, "/_security/user/{username}/_has_privileges", this, - GET, "/_xpack/security/user/{username}/_has_privileges", deprecationLogger); - controller.registerWithDeprecatedHandler( - POST, "/_security/user/{username}/_has_privileges", this, - POST, "/_xpack/security/user/{username}/_has_privileges", deprecationLogger); - controller.registerWithDeprecatedHandler( - GET, "/_security/user/_has_privileges", this, - GET, "/_xpack/security/user/_has_privileges", deprecationLogger); - controller.registerWithDeprecatedHandler( - POST, "/_security/user/_has_privileges", this, - POST, "/_xpack/security/user/_has_privileges", deprecationLogger); + return Collections.unmodifiableList(Arrays.asList( + new ReplacedRoute(GET, "/_security/user/{username}/_has_privileges", + GET, "/_xpack/security/user/{username}/_has_privileges", deprecationLogger), + new ReplacedRoute(POST, "/_security/user/{username}/_has_privileges", + POST, "/_xpack/security/user/{username}/_has_privileges", deprecationLogger), + new ReplacedRoute(GET, "/_security/user/_has_privileges", + GET, "/_xpack/security/user/_has_privileges", deprecationLogger), + new ReplacedRoute(POST, "/_security/user/_has_privileges", + POST, "/_xpack/security/user/_has_privileges", deprecationLogger) + )); } @Override diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/user/RestPutUserAction.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/user/RestPutUserAction.java index b56daba0bfa4a..e8ebea5342aea 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/user/RestPutUserAction.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/user/RestPutUserAction.java @@ -13,7 +13,6 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.license.XPackLicenseState; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; @@ -27,7 +26,9 @@ import org.elasticsearch.xpack.security.rest.action.SecurityBaseRestHandler; import java.io.IOException; +import java.util.Arrays; import java.util.Collections; +import java.util.List; import java.util.Set; import static org.elasticsearch.rest.RestRequest.Method.POST; @@ -41,16 +42,25 @@ public class RestPutUserAction extends SecurityBaseRestHandler implements RestRe private final Hasher passwordHasher; private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestPutUserAction.class)); - public RestPutUserAction(Settings settings, RestController controller, XPackLicenseState licenseState) { + public RestPutUserAction(Settings settings, XPackLicenseState licenseState) { super(settings, licenseState); passwordHasher = Hasher.resolve(XPackSettings.PASSWORD_HASHING_ALGORITHM.get(settings)); + } + + @Override + public List routes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - POST, "/_security/user/{username}", this, - POST, "/_xpack/security/user/{username}", deprecationLogger); - controller.registerWithDeprecatedHandler( - PUT, "/_security/user/{username}", this, - PUT, "/_xpack/security/user/{username}", deprecationLogger); + return Collections.unmodifiableList(Arrays.asList( + new ReplacedRoute(POST, "/_security/user/{username}", + POST, "/_xpack/security/user/{username}", deprecationLogger), + new ReplacedRoute(PUT, "/_security/user/{username}", + PUT, "/_xpack/security/user/{username}", deprecationLogger) + )); } @Override diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/user/RestSetEnabledAction.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/user/RestSetEnabledAction.java index a78b2c85aa62c..38c88625f651f 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/user/RestSetEnabledAction.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/user/RestSetEnabledAction.java @@ -12,7 +12,6 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.license.XPackLicenseState; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; @@ -22,6 +21,9 @@ import org.elasticsearch.xpack.security.rest.action.SecurityBaseRestHandler; import java.io.IOException; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.POST; import static org.elasticsearch.rest.RestRequest.Method.PUT; @@ -34,21 +36,28 @@ public class RestSetEnabledAction extends SecurityBaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestSetEnabledAction.class)); - public RestSetEnabledAction(Settings settings, RestController controller, XPackLicenseState licenseState) { + public RestSetEnabledAction(Settings settings, XPackLicenseState licenseState) { super(settings, licenseState); + } + + @Override + public List routes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - POST, "/_security/user/{username}/_enable", this, - POST, "/_xpack/security/user/{username}/_enable", deprecationLogger); - controller.registerWithDeprecatedHandler( - PUT, "/_security/user/{username}/_enable", this, - PUT, "/_xpack/security/user/{username}/_enable", deprecationLogger); - controller.registerWithDeprecatedHandler( - POST, "/_security/user/{username}/_disable", this, - POST, "/_xpack/security/user/{username}/_disable", deprecationLogger); - controller.registerWithDeprecatedHandler( - PUT, "/_security/user/{username}/_disable", this, - PUT, "/_xpack/security/user/{username}/_disable", deprecationLogger); + return Collections.unmodifiableList(Arrays.asList( + new ReplacedRoute(POST, "/_security/user/{username}/_enable", + POST, "/_xpack/security/user/{username}/_enable", deprecationLogger), + new ReplacedRoute(PUT, "/_security/user/{username}/_enable", + PUT, "/_xpack/security/user/{username}/_enable", deprecationLogger), + new ReplacedRoute(POST, "/_security/user/{username}/_disable", + POST, "/_xpack/security/user/{username}/_disable", deprecationLogger), + new ReplacedRoute(PUT, "/_security/user/{username}/_disable", + PUT, "/_xpack/security/user/{username}/_disable", deprecationLogger) + )); } @Override @@ -58,6 +67,7 @@ public String getName() { @Override public RestChannelConsumer innerPrepareRequest(RestRequest request, NodeClient client) throws IOException { + // TODO consider splitting up enable and disable to have their own rest handler final boolean enabled = request.path().endsWith("_enable"); assert enabled || request.path().endsWith("_disable"); final String username = request.param("username"); diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/rest/action/SecurityBaseRestHandlerTests.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/rest/action/SecurityBaseRestHandlerTests.java index 4b40d165b5e49..0000616002411 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/rest/action/SecurityBaseRestHandlerTests.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/rest/action/SecurityBaseRestHandlerTests.java @@ -15,6 +15,8 @@ import org.elasticsearch.test.rest.FakeRestRequest; import java.io.IOException; +import java.util.Collections; +import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; import static org.mockito.Mockito.mock; @@ -39,6 +41,11 @@ public String getName() { return "test_xpack_security_base_action"; } + @Override + public List routes() { + return Collections.emptyList(); + } + @Override protected RestChannelConsumer innerPrepareRequest(RestRequest request, NodeClient client) throws IOException { return channel -> { diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/rest/action/apikey/RestCreateApiKeyActionTests.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/rest/action/apikey/RestCreateApiKeyActionTests.java index 3f9b743c8e788..e51a4bfe09ebe 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/rest/action/apikey/RestCreateApiKeyActionTests.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/rest/action/apikey/RestCreateApiKeyActionTests.java @@ -8,10 +8,10 @@ import org.apache.lucene.util.SetOnce; import org.elasticsearch.ElasticsearchSecurityException; -import org.elasticsearch.action.ActionType; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.ActionRequest; import org.elasticsearch.action.ActionResponse; +import org.elasticsearch.action.ActionType; import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.settings.SecureString; @@ -22,7 +22,6 @@ import org.elasticsearch.license.XPackLicenseState; import org.elasticsearch.rest.AbstractRestChannel; import org.elasticsearch.rest.RestChannel; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.test.ESTestCase; @@ -42,7 +41,6 @@ public class RestCreateApiKeyActionTests extends ESTestCase { private final XPackLicenseState mockLicenseState = mock(XPackLicenseState.class); - private final RestController mockRestController = mock(RestController.class); private Settings settings = null; private ThreadPool threadPool = null; @@ -98,8 +96,7 @@ void doExecute(ActionType action, Request request, ActionListener action, Request request, ActionListener action, Request request, ActionListener action, Request request, ActionListener action, Request request, ActionListener routes() { + return Collections.emptyList(); + } + @Override protected RestChannelConsumer innerPrepareRequest(RestRequest request, NodeClient client) { return null; diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/rest/action/user/RestGetUserPrivilegesActionTests.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/rest/action/user/RestGetUserPrivilegesActionTests.java index 16c9218058f1c..fd2418c09f7dc 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/rest/action/user/RestGetUserPrivilegesActionTests.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/rest/action/user/RestGetUserPrivilegesActionTests.java @@ -13,7 +13,6 @@ import org.elasticsearch.common.util.set.Sets; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.license.XPackLicenseState; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestStatus; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.rest.FakeRestChannel; @@ -41,8 +40,8 @@ public class RestGetUserPrivilegesActionTests extends ESTestCase { public void testBasicLicense() throws Exception { final XPackLicenseState licenseState = mock(XPackLicenseState.class); - final RestGetUserPrivilegesAction action = new RestGetUserPrivilegesAction(Settings.EMPTY, mock(RestController.class), - mock(SecurityContext.class), licenseState); + final RestGetUserPrivilegesAction action = + new RestGetUserPrivilegesAction(Settings.EMPTY, mock(SecurityContext.class), licenseState); when(licenseState.isSecurityAvailable()).thenReturn(false); final FakeRestRequest request = new FakeRestRequest(); final FakeRestChannel channel = new FakeRestChannel(request, true, 1); diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/rest/action/user/RestHasPrivilegesActionTests.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/rest/action/user/RestHasPrivilegesActionTests.java index d0173479f37d6..50561f427b9b8 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/rest/action/user/RestHasPrivilegesActionTests.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/rest/action/user/RestHasPrivilegesActionTests.java @@ -13,7 +13,6 @@ import org.elasticsearch.common.xcontent.json.JsonXContent; import org.elasticsearch.license.XPackLicenseState; import org.elasticsearch.rest.RestChannel; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestStatus; import org.elasticsearch.test.ESTestCase; @@ -39,7 +38,7 @@ public class RestHasPrivilegesActionTests extends ESTestCase { public void testBodyConsumed() throws Exception { final XPackLicenseState licenseState = mock(XPackLicenseState.class); final RestHasPrivilegesAction action = - new RestHasPrivilegesAction(Settings.EMPTY, mock(RestController.class), mock(SecurityContext.class), licenseState); + new RestHasPrivilegesAction(Settings.EMPTY, mock(SecurityContext.class), licenseState); try (XContentBuilder bodyBuilder = JsonXContent.contentBuilder().startObject().endObject()) { final RestRequest request = new FakeRestRequest.Builder(xContentRegistry()) .withPath("/_security/user/_has_privileges/") @@ -52,8 +51,8 @@ public void testBodyConsumed() throws Exception { public void testBasicLicense() throws Exception { final XPackLicenseState licenseState = mock(XPackLicenseState.class); - final RestHasPrivilegesAction action = new RestHasPrivilegesAction(Settings.EMPTY, mock(RestController.class), - mock(SecurityContext.class), licenseState); + final RestHasPrivilegesAction action = + new RestHasPrivilegesAction(Settings.EMPTY, mock(SecurityContext.class), licenseState); when(licenseState.isSecurityAvailable()).thenReturn(false); try (XContentBuilder bodyBuilder = JsonXContent.contentBuilder().startObject().endObject()) { final RestRequest request = new FakeRestRequest.Builder(xContentRegistry()) diff --git a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/plugin/RestSqlClearCursorAction.java b/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/plugin/RestSqlClearCursorAction.java index 5d02e81dda792..fbb4eedc57cc9 100644 --- a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/plugin/RestSqlClearCursorAction.java +++ b/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/plugin/RestSqlClearCursorAction.java @@ -11,7 +11,6 @@ import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.sql.action.SqlClearCursorAction; @@ -19,18 +18,26 @@ import org.elasticsearch.xpack.sql.proto.Protocol; import java.io.IOException; +import java.util.List; +import static java.util.Collections.emptyList; +import static java.util.Collections.singletonList; import static org.elasticsearch.rest.RestRequest.Method.POST; public class RestSqlClearCursorAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestSqlClearCursorAction.class)); - public RestSqlClearCursorAction(RestController controller) { - // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - POST, Protocol.CLEAR_CURSOR_REST_ENDPOINT, this, - POST, Protocol.CLEAR_CURSOR_DEPRECATED_REST_ENDPOINT, deprecationLogger); + @Override + public List routes() { + return emptyList(); + } + + @Override + public List replacedRoutes() { + return singletonList(new ReplacedRoute( + POST, Protocol.CLEAR_CURSOR_REST_ENDPOINT, + POST, Protocol.CLEAR_CURSOR_DEPRECATED_REST_ENDPOINT, deprecationLogger)); } @Override diff --git a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/plugin/RestSqlQueryAction.java b/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/plugin/RestSqlQueryAction.java index 5a3b5731d4ad7..9c4f413c1701f 100644 --- a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/plugin/RestSqlQueryAction.java +++ b/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/plugin/RestSqlQueryAction.java @@ -14,7 +14,6 @@ import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; @@ -27,7 +26,11 @@ import java.io.IOException; import java.nio.charset.StandardCharsets; +import java.util.List; +import static java.util.Arrays.asList; +import static java.util.Collections.emptyList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.rest.RestRequest.Method.GET; import static org.elasticsearch.rest.RestRequest.Method.POST; @@ -35,15 +38,20 @@ public class RestSqlQueryAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestSqlQueryAction.class)); - public RestSqlQueryAction(RestController controller) { - // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - GET, Protocol.SQL_QUERY_REST_ENDPOINT, this, - GET, Protocol.SQL_QUERY_DEPRECATED_REST_ENDPOINT, deprecationLogger); - // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - POST, Protocol.SQL_QUERY_REST_ENDPOINT, this, - POST, Protocol.SQL_QUERY_DEPRECATED_REST_ENDPOINT, deprecationLogger); + @Override + public List routes() { + return emptyList(); + } + + @Override + public List replacedRoutes() { + return unmodifiableList(asList( + new ReplacedRoute( + GET, Protocol.SQL_QUERY_REST_ENDPOINT, + GET, Protocol.SQL_QUERY_DEPRECATED_REST_ENDPOINT, deprecationLogger), + new ReplacedRoute( + POST, Protocol.SQL_QUERY_REST_ENDPOINT, + POST, Protocol.SQL_QUERY_DEPRECATED_REST_ENDPOINT, deprecationLogger))); } @Override @@ -67,7 +75,7 @@ protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient cli * isn't then we use the {@code Content-Type} header which is required. */ String accept = null; - + if ((Mode.isDriver(sqlRequest.requestInfo().mode()) || sqlRequest.requestInfo().mode() == Mode.CLI) && (sqlRequest.binaryCommunication() == null || sqlRequest.binaryCommunication())) { // enforce CBOR response for drivers and CLI (unless instructed differently through the config param) diff --git a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/plugin/RestSqlStatsAction.java b/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/plugin/RestSqlStatsAction.java index bc6af60d79683..c4a0f5f570b82 100644 --- a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/plugin/RestSqlStatsAction.java +++ b/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/plugin/RestSqlStatsAction.java @@ -10,22 +10,30 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestActions; import org.elasticsearch.xpack.sql.proto.Protocol; +import java.util.List; + +import static java.util.Collections.emptyList; +import static java.util.Collections.singletonList; import static org.elasticsearch.rest.RestRequest.Method.GET; public class RestSqlStatsAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestSqlStatsAction.class)); - protected RestSqlStatsAction(RestController controller) { - // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - GET, Protocol.SQL_STATS_REST_ENDPOINT, this, - GET, Protocol.SQL_STATS_DEPRECATED_REST_ENDPOINT, deprecationLogger); + @Override + public List routes() { + return emptyList(); + } + + @Override + public List replacedRoutes() { + return singletonList(new ReplacedRoute( + GET, Protocol.SQL_STATS_REST_ENDPOINT, + GET, Protocol.SQL_STATS_DEPRECATED_REST_ENDPOINT, deprecationLogger)); } @Override diff --git a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/plugin/RestSqlTranslateAction.java b/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/plugin/RestSqlTranslateAction.java index 8ac6ef9fc81f8..0d4aeeedec826 100644 --- a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/plugin/RestSqlTranslateAction.java +++ b/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/plugin/RestSqlTranslateAction.java @@ -10,7 +10,6 @@ import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.sql.action.SqlTranslateAction; @@ -18,7 +17,11 @@ import org.elasticsearch.xpack.sql.proto.Protocol; import java.io.IOException; +import java.util.List; +import static java.util.Arrays.asList; +import static java.util.Collections.emptyList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.rest.RestRequest.Method.GET; import static org.elasticsearch.rest.RestRequest.Method.POST; @@ -29,15 +32,20 @@ public class RestSqlTranslateAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestSqlTranslateAction.class)); - public RestSqlTranslateAction(RestController controller) { - // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - GET, Protocol.SQL_TRANSLATE_REST_ENDPOINT, this, - GET, Protocol.SQL_TRANSLATE_DEPRECATED_REST_ENDPOINT, deprecationLogger); - // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - POST, Protocol.SQL_TRANSLATE_REST_ENDPOINT, this, - POST, Protocol.SQL_TRANSLATE_DEPRECATED_REST_ENDPOINT, deprecationLogger); + @Override + public List routes() { + return emptyList(); + } + + @Override + public List replacedRoutes() { + return unmodifiableList(asList( + new ReplacedRoute( + GET, Protocol.SQL_TRANSLATE_REST_ENDPOINT, + GET, Protocol.SQL_TRANSLATE_DEPRECATED_REST_ENDPOINT, deprecationLogger), + new ReplacedRoute( + POST, Protocol.SQL_TRANSLATE_REST_ENDPOINT, + POST, Protocol.SQL_TRANSLATE_DEPRECATED_REST_ENDPOINT, deprecationLogger))); } @Override diff --git a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/plugin/SqlPlugin.java b/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/plugin/SqlPlugin.java index fc184eff29a41..f9e043af9ee7d 100644 --- a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/plugin/SqlPlugin.java +++ b/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/plugin/SqlPlugin.java @@ -121,10 +121,10 @@ public List getRestHandlers(Settings settings, RestController restC return emptyList(); } - return Arrays.asList(new RestSqlQueryAction(restController), - new RestSqlTranslateAction(restController), - new RestSqlClearCursorAction(restController), - new RestSqlStatsAction(restController)); + return Arrays.asList(new RestSqlQueryAction(), + new RestSqlTranslateAction(), + new RestSqlClearCursorAction(), + new RestSqlStatsAction()); } @Override diff --git a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/Transform.java b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/Transform.java index 453a998b13a2d..4889aec19a9cf 100644 --- a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/Transform.java +++ b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/Transform.java @@ -176,24 +176,24 @@ public List getRestHandlers( } return Arrays.asList( - new RestPutTransformAction(restController), - new RestStartTransformAction(restController), - new RestStopTransformAction(restController), - new RestDeleteTransformAction(restController), - new RestGetTransformAction(restController), - new RestGetTransformStatsAction(restController), - new RestPreviewTransformAction(restController), - new RestUpdateTransformAction(restController), + new RestPutTransformAction(), + new RestStartTransformAction(), + new RestStopTransformAction(), + new RestDeleteTransformAction(), + new RestGetTransformAction(), + new RestGetTransformStatsAction(), + new RestPreviewTransformAction(), + new RestUpdateTransformAction(), // deprecated endpoints, to be removed for 8.0.0 - new RestPutTransformActionDeprecated(restController), - new RestStartTransformActionDeprecated(restController), - new RestStopTransformActionDeprecated(restController), - new RestDeleteTransformActionDeprecated(restController), - new RestGetTransformActionDeprecated(restController), - new RestGetTransformStatsActionDeprecated(restController), - new RestPreviewTransformActionDeprecated(restController), - new RestUpdateTransformActionDeprecated(restController) + new RestPutTransformActionDeprecated(), + new RestStartTransformActionDeprecated(), + new RestStopTransformActionDeprecated(), + new RestDeleteTransformActionDeprecated(), + new RestGetTransformActionDeprecated(), + new RestGetTransformStatsActionDeprecated(), + new RestPreviewTransformActionDeprecated(), + new RestUpdateTransformActionDeprecated() ); } diff --git a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/RestDeleteTransformAction.java b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/RestDeleteTransformAction.java index d6dbe7e468a3e..da60f8e040ee1 100644 --- a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/RestDeleteTransformAction.java +++ b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/RestDeleteTransformAction.java @@ -8,16 +8,21 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.transform.TransformField; import org.elasticsearch.xpack.core.transform.action.DeleteTransformAction; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.DELETE; + public class RestDeleteTransformAction extends BaseRestHandler { - public RestDeleteTransformAction(RestController controller) { - controller.registerHandler(RestRequest.Method.DELETE, TransformField.REST_BASE_PATH_TRANSFORMS_BY_ID, this); + @Override + public List routes() { + return singletonList(new Route(DELETE, TransformField.REST_BASE_PATH_TRANSFORMS_BY_ID)); } @Override diff --git a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/RestGetTransformAction.java b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/RestGetTransformAction.java index 23484f0e9408f..58670d10dce2a 100644 --- a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/RestGetTransformAction.java +++ b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/RestGetTransformAction.java @@ -8,20 +8,26 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.action.util.PageParams; import org.elasticsearch.xpack.core.transform.TransformField; import org.elasticsearch.xpack.core.transform.action.GetTransformAction; +import java.util.List; + +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; +import static org.elasticsearch.rest.RestRequest.Method.GET; import static org.elasticsearch.xpack.core.transform.TransformField.ALLOW_NO_MATCH; public class RestGetTransformAction extends BaseRestHandler { - public RestGetTransformAction(RestController controller) { - controller.registerHandler(RestRequest.Method.GET, TransformField.REST_BASE_PATH_TRANSFORMS, this); - controller.registerHandler(RestRequest.Method.GET, TransformField.REST_BASE_PATH_TRANSFORMS_BY_ID, this); + @Override + public List routes() { + return unmodifiableList(asList( + new Route(GET, TransformField.REST_BASE_PATH_TRANSFORMS), + new Route(GET, TransformField.REST_BASE_PATH_TRANSFORMS_BY_ID))); } @Override diff --git a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/RestGetTransformStatsAction.java b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/RestGetTransformStatsAction.java index 662f9840d0267..fa4d2364437f8 100644 --- a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/RestGetTransformStatsAction.java +++ b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/RestGetTransformStatsAction.java @@ -8,20 +8,26 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.action.util.PageParams; import org.elasticsearch.xpack.core.transform.TransformField; import org.elasticsearch.xpack.core.transform.action.GetTransformStatsAction; +import java.util.List; + +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; +import static org.elasticsearch.rest.RestRequest.Method.GET; import static org.elasticsearch.xpack.core.transform.TransformField.ALLOW_NO_MATCH; public class RestGetTransformStatsAction extends BaseRestHandler { - public RestGetTransformStatsAction(RestController controller) { - controller.registerHandler(RestRequest.Method.GET, TransformField.REST_BASE_PATH_TRANSFORMS + "_stats", this); - controller.registerHandler(RestRequest.Method.GET, TransformField.REST_BASE_PATH_TRANSFORMS_BY_ID + "_stats", this); + @Override + public List routes() { + return unmodifiableList(asList( + new Route(GET, TransformField.REST_BASE_PATH_TRANSFORMS + "_stats"), + new Route(GET, TransformField.REST_BASE_PATH_TRANSFORMS_BY_ID + "_stats"))); } @Override diff --git a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/RestPreviewTransformAction.java b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/RestPreviewTransformAction.java index 114c88b761c65..f5c0fe1808c24 100644 --- a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/RestPreviewTransformAction.java +++ b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/RestPreviewTransformAction.java @@ -9,18 +9,22 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.transform.TransformField; import org.elasticsearch.xpack.core.transform.action.PreviewTransformAction; import java.io.IOException; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.POST; public class RestPreviewTransformAction extends BaseRestHandler { - public RestPreviewTransformAction(RestController controller) { - controller.registerHandler(RestRequest.Method.POST, TransformField.REST_BASE_PATH_TRANSFORMS + "_preview", this); + @Override + public List routes() { + return singletonList(new Route(POST, TransformField.REST_BASE_PATH_TRANSFORMS + "_preview")); } @Override diff --git a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/RestPutTransformAction.java b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/RestPutTransformAction.java index b61d81fb6e132..06bb43ee3cd80 100644 --- a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/RestPutTransformAction.java +++ b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/RestPutTransformAction.java @@ -9,18 +9,22 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.transform.TransformField; import org.elasticsearch.xpack.core.transform.action.PutTransformAction; import java.io.IOException; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.PUT; public class RestPutTransformAction extends BaseRestHandler { - public RestPutTransformAction(RestController controller) { - controller.registerHandler(RestRequest.Method.PUT, TransformField.REST_BASE_PATH_TRANSFORMS_BY_ID, this); + @Override + public List routes() { + return singletonList(new Route(PUT, TransformField.REST_BASE_PATH_TRANSFORMS_BY_ID)); } @Override diff --git a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/RestStartTransformAction.java b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/RestStartTransformAction.java index ac6bb368cffab..bf791c2179103 100644 --- a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/RestStartTransformAction.java +++ b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/RestStartTransformAction.java @@ -9,16 +9,21 @@ import org.elasticsearch.action.support.master.AcknowledgedRequest; import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.transform.TransformField; import org.elasticsearch.xpack.core.transform.action.StartTransformAction; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.POST; + public class RestStartTransformAction extends BaseRestHandler { - public RestStartTransformAction(RestController controller) { - controller.registerHandler(RestRequest.Method.POST, TransformField.REST_BASE_PATH_TRANSFORMS_BY_ID + "_start", this); + @Override + public List routes() { + return singletonList(new Route(POST, TransformField.REST_BASE_PATH_TRANSFORMS_BY_ID + "_start")); } @Override diff --git a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/RestStopTransformAction.java b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/RestStopTransformAction.java index 85d138bfc37fd..4ed3f03648ccb 100644 --- a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/RestStopTransformAction.java +++ b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/RestStopTransformAction.java @@ -8,16 +8,21 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.transform.TransformField; import org.elasticsearch.xpack.core.transform.action.StopTransformAction; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.POST; + public class RestStopTransformAction extends BaseRestHandler { - public RestStopTransformAction(RestController controller) { - controller.registerHandler(RestRequest.Method.POST, TransformField.REST_BASE_PATH_TRANSFORMS_BY_ID + "_stop", this); + @Override + public List routes() { + return singletonList(new Route(POST, TransformField.REST_BASE_PATH_TRANSFORMS_BY_ID + "_stop")); } @Override diff --git a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/RestUpdateTransformAction.java b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/RestUpdateTransformAction.java index 563c978641303..08ac7566ff469 100644 --- a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/RestUpdateTransformAction.java +++ b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/RestUpdateTransformAction.java @@ -9,18 +9,22 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.transform.TransformField; import org.elasticsearch.xpack.core.transform.action.UpdateTransformAction; import java.io.IOException; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.POST; public class RestUpdateTransformAction extends BaseRestHandler { - public RestUpdateTransformAction(RestController controller) { - controller.registerHandler(RestRequest.Method.POST, TransformField.REST_BASE_PATH_TRANSFORMS_BY_ID + "_update", this); + @Override + public List routes() { + return singletonList(new Route(POST, TransformField.REST_BASE_PATH_TRANSFORMS_BY_ID + "_update")); } @Override diff --git a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/compat/RestDeleteTransformActionDeprecated.java b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/compat/RestDeleteTransformActionDeprecated.java index 94d4b5c65433b..7340c65811655 100644 --- a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/compat/RestDeleteTransformActionDeprecated.java +++ b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/compat/RestDeleteTransformActionDeprecated.java @@ -10,7 +10,6 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.transform.TransformField; @@ -18,14 +17,26 @@ import org.elasticsearch.xpack.core.transform.action.DeleteTransformAction; import org.elasticsearch.xpack.core.transform.action.compat.DeleteTransformActionDeprecated; +import java.util.Collections; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.DELETE; + public class RestDeleteTransformActionDeprecated extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger( LogManager.getLogger(RestDeleteTransformActionDeprecated.class)); - public RestDeleteTransformActionDeprecated(RestController controller) { - controller.registerAsDeprecatedHandler(RestRequest.Method.DELETE, TransformField.REST_BASE_PATH_TRANSFORMS_BY_ID_DEPRECATED, this, - TransformMessages.REST_DEPRECATED_ENDPOINT, deprecationLogger); + @Override + public List routes() { + return Collections.emptyList(); + } + + @Override + public List deprecatedRoutes() { + return singletonList(new DeprecatedRoute(DELETE, TransformField.REST_BASE_PATH_TRANSFORMS_BY_ID_DEPRECATED, + TransformMessages.REST_DEPRECATED_ENDPOINT, deprecationLogger)); } @Override diff --git a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/compat/RestGetTransformActionDeprecated.java b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/compat/RestGetTransformActionDeprecated.java index ca92942a52dd1..0f47320688dfa 100644 --- a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/compat/RestGetTransformActionDeprecated.java +++ b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/compat/RestGetTransformActionDeprecated.java @@ -10,7 +10,6 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.action.util.PageParams; @@ -19,6 +18,12 @@ import org.elasticsearch.xpack.core.transform.action.GetTransformAction; import org.elasticsearch.xpack.core.transform.action.compat.GetTransformActionDeprecated; +import java.util.Collections; +import java.util.List; + +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; +import static org.elasticsearch.rest.RestRequest.Method.GET; import static org.elasticsearch.xpack.core.transform.TransformField.ALLOW_NO_MATCH; public class RestGetTransformActionDeprecated extends BaseRestHandler { @@ -26,11 +31,18 @@ public class RestGetTransformActionDeprecated extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger( LogManager.getLogger(RestGetTransformActionDeprecated.class)); - public RestGetTransformActionDeprecated(RestController controller) { - controller.registerAsDeprecatedHandler(RestRequest.Method.GET, TransformField.REST_BASE_PATH_TRANSFORMS_DEPRECATED, this, - TransformMessages.REST_DEPRECATED_ENDPOINT, deprecationLogger); - controller.registerAsDeprecatedHandler(RestRequest.Method.GET, TransformField.REST_BASE_PATH_TRANSFORMS_BY_ID_DEPRECATED, this, - TransformMessages.REST_DEPRECATED_ENDPOINT, deprecationLogger); + @Override + public List routes() { + return Collections.emptyList(); + } + + @Override + public List deprecatedRoutes() { + return unmodifiableList(asList( + new DeprecatedRoute(GET, TransformField.REST_BASE_PATH_TRANSFORMS_DEPRECATED, + TransformMessages.REST_DEPRECATED_ENDPOINT, deprecationLogger), + new DeprecatedRoute(GET, TransformField.REST_BASE_PATH_TRANSFORMS_BY_ID_DEPRECATED, + TransformMessages.REST_DEPRECATED_ENDPOINT, deprecationLogger))); } @Override diff --git a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/compat/RestGetTransformStatsActionDeprecated.java b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/compat/RestGetTransformStatsActionDeprecated.java index b444ea3beef14..9b34769ca0e6b 100644 --- a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/compat/RestGetTransformStatsActionDeprecated.java +++ b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/compat/RestGetTransformStatsActionDeprecated.java @@ -10,7 +10,6 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.action.util.PageParams; @@ -19,6 +18,12 @@ import org.elasticsearch.xpack.core.transform.action.GetTransformStatsAction; import org.elasticsearch.xpack.core.transform.action.compat.GetTransformStatsActionDeprecated; +import java.util.Collections; +import java.util.List; + +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; +import static org.elasticsearch.rest.RestRequest.Method.GET; import static org.elasticsearch.xpack.core.transform.TransformField.ALLOW_NO_MATCH; public class RestGetTransformStatsActionDeprecated extends BaseRestHandler { @@ -26,12 +31,18 @@ public class RestGetTransformStatsActionDeprecated extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger( LogManager.getLogger(RestGetTransformStatsActionDeprecated.class)); - public RestGetTransformStatsActionDeprecated(RestController controller) { - controller.registerAsDeprecatedHandler(RestRequest.Method.GET, TransformField.REST_BASE_PATH_TRANSFORMS_DEPRECATED + "_stats", - this, TransformMessages.REST_DEPRECATED_ENDPOINT, deprecationLogger); - controller.registerAsDeprecatedHandler(RestRequest.Method.GET, - TransformField.REST_BASE_PATH_TRANSFORMS_BY_ID_DEPRECATED + "_stats", this, - TransformMessages.REST_DEPRECATED_ENDPOINT, deprecationLogger); + @Override + public List routes() { + return Collections.emptyList(); + } + + @Override + public List deprecatedRoutes() { + return unmodifiableList(asList( + new DeprecatedRoute(GET, TransformField.REST_BASE_PATH_TRANSFORMS_DEPRECATED + "_stats", + TransformMessages.REST_DEPRECATED_ENDPOINT, deprecationLogger), + new DeprecatedRoute(GET, TransformField.REST_BASE_PATH_TRANSFORMS_BY_ID_DEPRECATED + "_stats", + TransformMessages.REST_DEPRECATED_ENDPOINT, deprecationLogger))); } @Override diff --git a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/compat/RestPreviewTransformActionDeprecated.java b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/compat/RestPreviewTransformActionDeprecated.java index 8c0a994ebbeff..97f66c29c2726 100644 --- a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/compat/RestPreviewTransformActionDeprecated.java +++ b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/compat/RestPreviewTransformActionDeprecated.java @@ -11,7 +11,6 @@ import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.transform.TransformField; @@ -20,15 +19,26 @@ import org.elasticsearch.xpack.core.transform.action.compat.PreviewTransformActionDeprecated; import java.io.IOException; +import java.util.Collections; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.POST; public class RestPreviewTransformActionDeprecated extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger( LogManager.getLogger(RestPreviewTransformActionDeprecated.class)); - public RestPreviewTransformActionDeprecated(RestController controller) { - controller.registerAsDeprecatedHandler(RestRequest.Method.POST, TransformField.REST_BASE_PATH_TRANSFORMS_DEPRECATED + "_preview", - this, TransformMessages.REST_DEPRECATED_ENDPOINT, deprecationLogger); + @Override + public List routes() { + return Collections.emptyList(); + } + + @Override + public List deprecatedRoutes() { + return singletonList(new DeprecatedRoute(POST, TransformField.REST_BASE_PATH_TRANSFORMS_DEPRECATED + "_preview", + TransformMessages.REST_DEPRECATED_ENDPOINT, deprecationLogger)); } @Override diff --git a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/compat/RestPutTransformActionDeprecated.java b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/compat/RestPutTransformActionDeprecated.java index aeac2c91be2f9..9ceb7da78a704 100644 --- a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/compat/RestPutTransformActionDeprecated.java +++ b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/compat/RestPutTransformActionDeprecated.java @@ -11,7 +11,6 @@ import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.transform.TransformField; @@ -20,15 +19,26 @@ import org.elasticsearch.xpack.core.transform.action.compat.PutTransformActionDeprecated; import java.io.IOException; +import java.util.Collections; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.PUT; public class RestPutTransformActionDeprecated extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger( LogManager.getLogger(RestPutTransformActionDeprecated.class)); - public RestPutTransformActionDeprecated(RestController controller) { - controller.registerAsDeprecatedHandler(RestRequest.Method.PUT, TransformField.REST_BASE_PATH_TRANSFORMS_BY_ID_DEPRECATED, this, - TransformMessages.REST_DEPRECATED_ENDPOINT, deprecationLogger); + @Override + public List routes() { + return Collections.emptyList(); + } + + @Override + public List deprecatedRoutes() { + return singletonList(new DeprecatedRoute(PUT, TransformField.REST_BASE_PATH_TRANSFORMS_BY_ID_DEPRECATED, + TransformMessages.REST_DEPRECATED_ENDPOINT, deprecationLogger)); } @Override diff --git a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/compat/RestStartTransformActionDeprecated.java b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/compat/RestStartTransformActionDeprecated.java index 796c9833222aa..322b5f3eb4501 100644 --- a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/compat/RestStartTransformActionDeprecated.java +++ b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/compat/RestStartTransformActionDeprecated.java @@ -11,7 +11,6 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.transform.TransformField; @@ -19,15 +18,26 @@ import org.elasticsearch.xpack.core.transform.action.StartTransformAction; import org.elasticsearch.xpack.core.transform.action.compat.StartTransformActionDeprecated; +import java.util.Collections; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.POST; + public class RestStartTransformActionDeprecated extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger( LogManager.getLogger(RestStartTransformActionDeprecated.class)); - public RestStartTransformActionDeprecated(RestController controller) { - controller.registerAsDeprecatedHandler(RestRequest.Method.POST, - TransformField.REST_BASE_PATH_TRANSFORMS_BY_ID_DEPRECATED + "_start", this, TransformMessages.REST_DEPRECATED_ENDPOINT, - deprecationLogger); + @Override + public List routes() { + return Collections.emptyList(); + } + + @Override + public List deprecatedRoutes() { + return singletonList(new DeprecatedRoute(POST, TransformField.REST_BASE_PATH_TRANSFORMS_BY_ID_DEPRECATED + "_start", + TransformMessages.REST_DEPRECATED_ENDPOINT, deprecationLogger)); } @Override diff --git a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/compat/RestStopTransformActionDeprecated.java b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/compat/RestStopTransformActionDeprecated.java index 2a43df2a7f94d..b308fc98015fb 100644 --- a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/compat/RestStopTransformActionDeprecated.java +++ b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/compat/RestStopTransformActionDeprecated.java @@ -10,7 +10,6 @@ import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.transform.TransformField; @@ -18,14 +17,26 @@ import org.elasticsearch.xpack.core.transform.action.StopTransformAction; import org.elasticsearch.xpack.core.transform.action.compat.StopTransformActionDeprecated; +import java.util.Collections; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.POST; + public class RestStopTransformActionDeprecated extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger( LogManager.getLogger(RestStopTransformActionDeprecated.class)); - public RestStopTransformActionDeprecated(RestController controller) { - controller.registerAsDeprecatedHandler(RestRequest.Method.POST, TransformField.REST_BASE_PATH_TRANSFORMS_BY_ID_DEPRECATED + "_stop", - this, TransformMessages.REST_DEPRECATED_ENDPOINT, deprecationLogger); + @Override + public List routes() { + return Collections.emptyList(); + } + + @Override + public List deprecatedRoutes() { + return singletonList(new DeprecatedRoute(POST, TransformField.REST_BASE_PATH_TRANSFORMS_BY_ID_DEPRECATED + "_stop", + TransformMessages.REST_DEPRECATED_ENDPOINT, deprecationLogger)); } @Override diff --git a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/compat/RestUpdateTransformActionDeprecated.java b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/compat/RestUpdateTransformActionDeprecated.java index 5be2586f955e8..ff9752f7767d4 100644 --- a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/compat/RestUpdateTransformActionDeprecated.java +++ b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/compat/RestUpdateTransformActionDeprecated.java @@ -11,7 +11,6 @@ import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.transform.TransformField; @@ -20,16 +19,26 @@ import org.elasticsearch.xpack.core.transform.action.compat.UpdateTransformActionDeprecated; import java.io.IOException; +import java.util.Collections; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.POST; public class RestUpdateTransformActionDeprecated extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger( LogManager.getLogger(RestUpdateTransformActionDeprecated.class)); - public RestUpdateTransformActionDeprecated(RestController controller) { - controller.registerAsDeprecatedHandler(RestRequest.Method.POST, - TransformField.REST_BASE_PATH_TRANSFORMS_BY_ID_DEPRECATED + "_update", this, TransformMessages.REST_DEPRECATED_ENDPOINT, - deprecationLogger); + @Override + public List routes() { + return Collections.emptyList(); + } + + @Override + public List deprecatedRoutes() { + return singletonList(new DeprecatedRoute(POST, TransformField.REST_BASE_PATH_TRANSFORMS_BY_ID_DEPRECATED + "_update", + TransformMessages.REST_DEPRECATED_ENDPOINT, deprecationLogger)); } @Override diff --git a/x-pack/plugin/transform/src/test/java/org/elasticsearch/xpack/transform/rest/action/RestDeleteTransformActionTests.java b/x-pack/plugin/transform/src/test/java/org/elasticsearch/xpack/transform/rest/action/RestDeleteTransformActionTests.java index 36891461c2702..7672cf71f65d3 100644 --- a/x-pack/plugin/transform/src/test/java/org/elasticsearch/xpack/transform/rest/action/RestDeleteTransformActionTests.java +++ b/x-pack/plugin/transform/src/test/java/org/elasticsearch/xpack/transform/rest/action/RestDeleteTransformActionTests.java @@ -12,7 +12,6 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.common.xcontent.json.JsonXContent; -import org.elasticsearch.rest.RestController; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.rest.FakeRestRequest; @@ -22,8 +21,7 @@ public class RestDeleteTransformActionTests extends ESTestCase { public void testBodyRejection() throws Exception { - final RestDeleteTransformAction handler = new RestDeleteTransformAction( - mock(RestController.class)); + final RestDeleteTransformAction handler = new RestDeleteTransformAction(); try (XContentBuilder builder = JsonXContent.contentBuilder()) { builder.startObject(); { diff --git a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/Watcher.java b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/Watcher.java index a71695f38e4d5..2d11fa0e6474c 100644 --- a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/Watcher.java +++ b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/Watcher.java @@ -139,6 +139,7 @@ import org.elasticsearch.xpack.watcher.notification.slack.SlackService; import org.elasticsearch.xpack.watcher.rest.action.RestAckWatchAction; import org.elasticsearch.xpack.watcher.rest.action.RestActivateWatchAction; +import org.elasticsearch.xpack.watcher.rest.action.RestActivateWatchAction.DeactivateRestHandler; import org.elasticsearch.xpack.watcher.rest.action.RestDeleteWatchAction; import org.elasticsearch.xpack.watcher.rest.action.RestExecuteWatchAction; import org.elasticsearch.xpack.watcher.rest.action.RestGetWatchAction; @@ -570,14 +571,16 @@ public List getRestHandlers(Settings settings, RestController restC return emptyList(); } return Arrays.asList( - new RestPutWatchAction(restController), - new RestDeleteWatchAction(restController), - new RestWatcherStatsAction(restController), - new RestGetWatchAction(restController), - new RestWatchServiceAction(restController), - new RestAckWatchAction(restController), - new RestActivateWatchAction(restController), - new RestExecuteWatchAction(restController)); + new RestPutWatchAction(), + new RestDeleteWatchAction(), + new RestWatcherStatsAction(), + new RestGetWatchAction(), + new RestWatchServiceAction(), + new RestWatchServiceAction.StopRestHandler(), + new RestAckWatchAction(), + new RestActivateWatchAction(), + new DeactivateRestHandler(), + new RestExecuteWatchAction()); } @Override diff --git a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestAckWatchAction.java b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestAckWatchAction.java index 5fa7c42cb0772..1582fd01962c7 100644 --- a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestAckWatchAction.java +++ b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestAckWatchAction.java @@ -10,7 +10,6 @@ import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; @@ -22,6 +21,11 @@ import org.elasticsearch.xpack.core.watcher.watch.WatchField; import org.elasticsearch.xpack.watcher.rest.WatcherRestHandler; +import java.util.List; + +import static java.util.Arrays.asList; +import static java.util.Collections.emptyList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.rest.RestRequest.Method.POST; import static org.elasticsearch.rest.RestRequest.Method.PUT; @@ -32,20 +36,22 @@ public class RestAckWatchAction extends WatcherRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestAckWatchAction.class)); - public RestAckWatchAction(RestController controller) { - // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - POST, "/_watcher/watch/{id}/_ack", this, - POST, URI_BASE + "/watcher/watch/{id}/_ack", deprecationLogger); - controller.registerWithDeprecatedHandler( - PUT, "/_watcher/watch/{id}/_ack", this, - PUT, URI_BASE + "/watcher/watch/{id}/_ack", deprecationLogger); - controller.registerWithDeprecatedHandler( - POST, "/_watcher/watch/{id}/_ack/{actions}", this, - POST, URI_BASE + "/watcher/watch/{id}/_ack/{actions}", deprecationLogger); - controller.registerWithDeprecatedHandler( - PUT, "/_watcher/watch/{id}/_ack/{actions}", this, - PUT, URI_BASE + "/watcher/watch/{id}/_ack/{actions}", deprecationLogger); + @Override + public List routes() { + return emptyList(); + } + + @Override + public List replacedRoutes() { + return unmodifiableList(asList( + new ReplacedRoute(POST, "/_watcher/watch/{id}/_ack", POST, URI_BASE + "/watcher/watch/{id}/_ack", deprecationLogger), + new ReplacedRoute(PUT, "/_watcher/watch/{id}/_ack", PUT, URI_BASE + "/watcher/watch/{id}/_ack", deprecationLogger), + new ReplacedRoute( + POST, "/_watcher/watch/{id}/_ack/{actions}", + POST, URI_BASE + "/watcher/watch/{id}/_ack/{actions}", deprecationLogger), + new ReplacedRoute( + PUT, "/_watcher/watch/{id}/_ack/{actions}", + PUT, URI_BASE + "/watcher/watch/{id}/_ack/{actions}", deprecationLogger))); } @Override diff --git a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestActivateWatchAction.java b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestActivateWatchAction.java index d31b704df10ed..ba9ac0b64a597 100644 --- a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestActivateWatchAction.java +++ b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestActivateWatchAction.java @@ -10,7 +10,6 @@ import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; @@ -22,6 +21,11 @@ import org.elasticsearch.xpack.core.watcher.watch.WatchField; import org.elasticsearch.xpack.watcher.rest.WatcherRestHandler; +import java.util.List; + +import static java.util.Arrays.asList; +import static java.util.Collections.emptyList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.rest.RestRequest.Method.POST; import static org.elasticsearch.rest.RestRequest.Method.PUT; @@ -32,22 +36,16 @@ public class RestActivateWatchAction extends WatcherRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestActivateWatchAction.class)); - public RestActivateWatchAction(RestController controller) { - // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - POST, "/_watcher/watch/{id}/_activate", this, - POST, URI_BASE + "/watcher/watch/{id}/_activate", deprecationLogger); - controller.registerWithDeprecatedHandler( - PUT, "/_watcher/watch/{id}/_activate", this, - PUT, URI_BASE + "/watcher/watch/{id}/_activate", deprecationLogger); - - final DeactivateRestHandler deactivateRestHandler = new DeactivateRestHandler(); - controller.registerWithDeprecatedHandler( - POST, "/_watcher/watch/{id}/_deactivate", deactivateRestHandler, - POST, URI_BASE + "/watcher/watch/{id}/_deactivate", deprecationLogger); - controller.registerWithDeprecatedHandler( - PUT, "/_watcher/watch/{id}/_deactivate", deactivateRestHandler, - PUT, URI_BASE + "/watcher/watch/{id}/_deactivate", deprecationLogger); + @Override + public List routes() { + return emptyList(); + } + + @Override + public List replacedRoutes() { + return unmodifiableList(asList( + new ReplacedRoute(POST, "/_watcher/watch/{id}/_activate", POST, URI_BASE + "/watcher/watch/{id}/_activate", deprecationLogger), + new ReplacedRoute(PUT, "/_watcher/watch/{id}/_activate", PUT, URI_BASE + "/watcher/watch/{id}/_activate", deprecationLogger))); } @Override @@ -69,9 +67,22 @@ public RestResponse buildResponse(ActivateWatchResponse response, XContentBuilde }); } - private static class DeactivateRestHandler extends WatcherRestHandler { + public static class DeactivateRestHandler extends WatcherRestHandler { - DeactivateRestHandler() { + @Override + public List routes() { + return emptyList(); + } + + @Override + public List replacedRoutes() { + return unmodifiableList(asList( + new ReplacedRoute( + POST, "/_watcher/watch/{id}/_deactivate", + POST, URI_BASE + "/watcher/watch/{id}/_deactivate", deprecationLogger), + new ReplacedRoute( + PUT, "/_watcher/watch/{id}/_deactivate", + PUT, URI_BASE + "/watcher/watch/{id}/_deactivate", deprecationLogger))); } @Override diff --git a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestDeleteWatchAction.java b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestDeleteWatchAction.java index 4314462c78df2..18dac6ac8b968 100644 --- a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestDeleteWatchAction.java +++ b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestDeleteWatchAction.java @@ -10,7 +10,6 @@ import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; @@ -20,6 +19,10 @@ import org.elasticsearch.protocol.xpack.watcher.DeleteWatchResponse; import org.elasticsearch.xpack.watcher.rest.WatcherRestHandler; +import java.util.List; + +import static java.util.Collections.emptyList; +import static java.util.Collections.singletonList; import static org.elasticsearch.rest.RestRequest.Method.DELETE; import static org.elasticsearch.rest.RestStatus.NOT_FOUND; import static org.elasticsearch.rest.RestStatus.OK; @@ -28,11 +31,15 @@ public class RestDeleteWatchAction extends WatcherRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestDeleteWatchAction.class)); - public RestDeleteWatchAction(RestController controller) { - // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - DELETE, "/_watcher/watch/{id}", this, - DELETE, URI_BASE + "/watcher/watch/{id}", deprecationLogger); + @Override + public List routes() { + return emptyList(); + } + + @Override + public List replacedRoutes() { + return singletonList( + new ReplacedRoute(DELETE, "/_watcher/watch/{id}", DELETE, URI_BASE + "/watcher/watch/{id}", deprecationLogger)); } @Override diff --git a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestExecuteWatchAction.java b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestExecuteWatchAction.java index cd213a65dfb8d..d33c7c6cb0c4f 100644 --- a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestExecuteWatchAction.java +++ b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestExecuteWatchAction.java @@ -15,7 +15,6 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; @@ -31,11 +30,13 @@ import org.elasticsearch.xpack.watcher.rest.WatcherRestHandler; import java.io.IOException; -import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Set; +import static java.util.Arrays.asList; +import static java.util.Collections.emptyList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.rest.RestRequest.Method.POST; import static org.elasticsearch.rest.RestRequest.Method.PUT; import static org.elasticsearch.xpack.watcher.rest.action.RestExecuteWatchAction.Field.IGNORE_CONDITION; @@ -45,26 +46,24 @@ public class RestExecuteWatchAction extends WatcherRestHandler implements RestRe private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestExecuteWatchAction.class)); - private static final List RESERVED_FIELD_NAMES = Arrays.asList(WatchField.TRIGGER.getPreferredName(), + private static final List RESERVED_FIELD_NAMES = asList(WatchField.TRIGGER.getPreferredName(), WatchField.INPUT.getPreferredName(), WatchField.CONDITION.getPreferredName(), WatchField.ACTIONS.getPreferredName(), WatchField.TRANSFORM.getPreferredName(), WatchField.THROTTLE_PERIOD.getPreferredName(), WatchField.THROTTLE_PERIOD_HUMAN.getPreferredName(), WatchField.METADATA.getPreferredName(), WatchField.STATUS.getPreferredName()); - public RestExecuteWatchAction(RestController controller) { - // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - POST, "/_watcher/watch/{id}/_execute", this, - POST, URI_BASE + "/watcher/watch/{id}/_execute", deprecationLogger); - controller.registerWithDeprecatedHandler( - PUT, "/_watcher/watch/{id}/_execute", this, - PUT, URI_BASE + "/watcher/watch/{id}/_execute", deprecationLogger); - controller.registerWithDeprecatedHandler( - POST, "/_watcher/watch/_execute", this, - POST, URI_BASE + "/watcher/watch/_execute", deprecationLogger); - controller.registerWithDeprecatedHandler( - PUT, "/_watcher/watch/_execute", this, - PUT, URI_BASE + "/watcher/watch/_execute", deprecationLogger); + @Override + public List routes() { + return emptyList(); + } + + @Override + public List replacedRoutes() { + return unmodifiableList(asList( + new ReplacedRoute(POST, "/_watcher/watch/{id}/_execute", POST, URI_BASE + "/watcher/watch/{id}/_execute", deprecationLogger), + new ReplacedRoute(PUT, "/_watcher/watch/{id}/_execute", PUT, URI_BASE + "/watcher/watch/{id}/_execute", deprecationLogger), + new ReplacedRoute(POST, "/_watcher/watch/_execute", POST, URI_BASE + "/watcher/watch/_execute", deprecationLogger), + new ReplacedRoute(PUT, "/_watcher/watch/_execute", PUT, URI_BASE + "/watcher/watch/_execute", deprecationLogger))); } @Override diff --git a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestGetWatchAction.java b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestGetWatchAction.java index 38128259e3aa1..56abbbe2d593e 100644 --- a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestGetWatchAction.java +++ b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestGetWatchAction.java @@ -10,7 +10,6 @@ import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; @@ -20,6 +19,10 @@ import org.elasticsearch.xpack.core.watcher.transport.actions.get.GetWatchResponse; import org.elasticsearch.xpack.watcher.rest.WatcherRestHandler; +import java.util.List; + +import static java.util.Collections.emptyList; +import static java.util.Collections.singletonList; import static org.elasticsearch.rest.RestRequest.Method.GET; import static org.elasticsearch.rest.RestStatus.NOT_FOUND; import static org.elasticsearch.rest.RestStatus.OK; @@ -28,11 +31,14 @@ public class RestGetWatchAction extends WatcherRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestGetWatchAction.class)); - public RestGetWatchAction(RestController controller) { - // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - GET, "/_watcher/watch/{id}", this, - GET, URI_BASE + "/watcher/watch/{id}", deprecationLogger); + @Override + public List routes() { + return emptyList(); + } + + @Override + public List replacedRoutes() { + return singletonList(new ReplacedRoute(GET, "/_watcher/watch/{id}", GET, URI_BASE + "/watcher/watch/{id}", deprecationLogger)); } @Override diff --git a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestPutWatchAction.java b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestPutWatchAction.java index c422907ce1745..1214b43f0f36e 100644 --- a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestPutWatchAction.java +++ b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestPutWatchAction.java @@ -14,7 +14,6 @@ import org.elasticsearch.protocol.xpack.watcher.PutWatchRequest; import org.elasticsearch.protocol.xpack.watcher.PutWatchResponse; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; @@ -24,8 +23,12 @@ import org.elasticsearch.xpack.watcher.rest.WatcherRestHandler; import java.util.Collections; +import java.util.List; import java.util.Set; +import static java.util.Arrays.asList; +import static java.util.Collections.emptyList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.rest.RestRequest.Method.POST; import static org.elasticsearch.rest.RestRequest.Method.PUT; import static org.elasticsearch.rest.RestStatus.CREATED; @@ -35,14 +38,16 @@ public class RestPutWatchAction extends WatcherRestHandler implements RestReques private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestPutWatchAction.class)); - public RestPutWatchAction(RestController controller) { - // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - POST, "/_watcher/watch/{id}", this, - POST, URI_BASE + "/watcher/watch/{id}", deprecationLogger); - controller.registerWithDeprecatedHandler( - PUT, "/_watcher/watch/{id}", this, - PUT, URI_BASE + "/watcher/watch/{id}", deprecationLogger); + @Override + public List routes() { + return emptyList(); + } + + @Override + public List replacedRoutes() { + return unmodifiableList(asList( + new ReplacedRoute(POST, "/_watcher/watch/{id}", POST, URI_BASE + "/watcher/watch/{id}", deprecationLogger), + new ReplacedRoute(PUT, "/_watcher/watch/{id}", PUT, URI_BASE + "/watcher/watch/{id}", deprecationLogger))); } @Override diff --git a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestWatchServiceAction.java b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestWatchServiceAction.java index c9f6db4b6e065..0ef08c545a6eb 100644 --- a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestWatchServiceAction.java +++ b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestWatchServiceAction.java @@ -8,27 +8,30 @@ import org.apache.logging.log4j.LogManager; import org.elasticsearch.common.logging.DeprecationLogger; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.watcher.client.WatcherClient; import org.elasticsearch.xpack.core.watcher.transport.actions.service.WatcherServiceRequest; import org.elasticsearch.xpack.watcher.rest.WatcherRestHandler; +import java.util.List; + +import static java.util.Collections.emptyList; +import static java.util.Collections.singletonList; import static org.elasticsearch.rest.RestRequest.Method.POST; public class RestWatchServiceAction extends WatcherRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestWatchServiceAction.class)); - public RestWatchServiceAction(RestController controller) { - // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - POST, "/_watcher/_start", this, - POST, URI_BASE + "/watcher/_start", deprecationLogger); - controller.registerWithDeprecatedHandler( - POST, "/_watcher/_stop", new StopRestHandler(), - POST, URI_BASE + "/watcher/_stop", deprecationLogger); + @Override + public List routes() { + return emptyList(); + } + + @Override + public List replacedRoutes() { + return singletonList(new ReplacedRoute(POST, "/_watcher/_start", POST, URI_BASE + "/watcher/_start", deprecationLogger)); } @Override @@ -41,9 +44,16 @@ public RestChannelConsumer doPrepareRequest(RestRequest request, WatcherClient c return channel -> client.watcherService(new WatcherServiceRequest().start(), new RestToXContentListener<>(channel)); } - private static class StopRestHandler extends WatcherRestHandler { + public static class StopRestHandler extends WatcherRestHandler { - StopRestHandler() { + @Override + public List routes() { + return emptyList(); + } + + @Override + public List replacedRoutes() { + return singletonList(new ReplacedRoute(POST, "/_watcher/_stop", POST, URI_BASE + "/watcher/_stop", deprecationLogger)); } @Override diff --git a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestWatcherStatsAction.java b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestWatcherStatsAction.java index 1a41f8d951e71..e712e1cf545b9 100644 --- a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestWatcherStatsAction.java +++ b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestWatcherStatsAction.java @@ -10,7 +10,6 @@ import org.apache.logging.log4j.LogManager; import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.common.Strings; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestActions; import org.elasticsearch.xpack.core.watcher.client.WatcherClient; @@ -18,22 +17,28 @@ import org.elasticsearch.xpack.watcher.rest.WatcherRestHandler; import java.util.Collections; +import java.util.List; import java.util.Set; +import static java.util.Arrays.asList; +import static java.util.Collections.emptyList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.rest.RestRequest.Method.GET; public class RestWatcherStatsAction extends WatcherRestHandler { private static final Logger logger = LogManager.getLogger(RestWatcherStatsAction.class); private static final DeprecationLogger deprecationLogger = new DeprecationLogger(logger); - public RestWatcherStatsAction(RestController controller) { - // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - GET, "/_watcher/stats", this, - GET, URI_BASE + "/watcher/stats", deprecationLogger); - controller.registerWithDeprecatedHandler( - GET, "/_watcher/stats/{metric}", this, - GET, URI_BASE + "/watcher/stats/{metric}", deprecationLogger); + @Override + public List routes() { + return emptyList(); + } + + @Override + public List replacedRoutes() { + return unmodifiableList(asList( + new ReplacedRoute(GET, "/_watcher/stats", GET, URI_BASE + "/watcher/stats", deprecationLogger), + new ReplacedRoute(GET, "/_watcher/stats/{metric}", GET, URI_BASE + "/watcher/stats/{metric}", deprecationLogger))); } @Override diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/rest/action/RestExecuteWatchActionTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/rest/action/RestExecuteWatchActionTests.java index 89be42ae5b951..ac488ce9d8e13 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/rest/action/RestExecuteWatchActionTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/rest/action/RestExecuteWatchActionTests.java @@ -9,7 +9,6 @@ import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.XContentType; -import org.elasticsearch.rest.RestController; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.rest.FakeRestRequest; import org.elasticsearch.test.rest.FakeRestRequest.Builder; @@ -26,7 +25,6 @@ public class RestExecuteWatchActionTests extends ESTestCase { - private RestController restController = mock(RestController.class); private Client client = mock(Client.class); private WatcherClient watcherClient = mock(WatcherClient.class); @@ -38,7 +36,7 @@ public void testThatFlagsCanBeSpecifiedViaParameters() throws Exception { ExecuteWatchRequestBuilder builder = new ExecuteWatchRequestBuilder(client); when(watcherClient.prepareExecuteWatch()).thenReturn(builder); - RestExecuteWatchAction restExecuteWatchAction = new RestExecuteWatchAction(restController); + RestExecuteWatchAction restExecuteWatchAction = new RestExecuteWatchAction(); restExecuteWatchAction.doPrepareRequest(createFakeRestRequest(randomId, recordExecution, ignoreCondition, debugCondition), watcherClient);