From 3a2c698ce0c7f86a61503caa468fa670facfe540 Mon Sep 17 00:00:00 2001 From: Ryan Ernst Date: Sun, 30 Jun 2019 22:00:17 -0700 Subject: [PATCH 01/77] Rename Action to ActionType (#43778) Action is a class that encapsulates meta information about an action that allows it to be called remotely, specifically the action name and response type. With recent refactoring, the action class can now be constructed as a static constant, instead of needing to create a subclass. This makes the old pattern of creating a singleton INSTANCE both misnamed and lacking a common placement. This commit renames Action to ActionType, thus allowing the old INSTANCE naming pattern to be TYPE on the transport action itself. ActionType also conveys that this class is also not the action itself, although this change does not rename any concrete classes as those will be removed organically as they are converted to TYPE constants. relates #34389 --- .../noop/action/bulk/NoopBulkAction.java | 4 +-- .../noop/action/search/NoopSearchAction.java | 4 +-- .../ingest/common/GrokProcessorGetAction.java | 4 +-- .../mustache/MultiSearchTemplateAction.java | 4 +-- .../script/mustache/SearchTemplateAction.java | 4 +-- .../action/PainlessContextAction.java | 4 +-- .../action/PainlessExecuteAction.java | 4 +-- .../index/rankeval/RankEvalAction.java | 6 ++-- .../rankeval/RankEvalRequestBuilder.java | 4 +-- .../AbstractBaseReindexRestHandler.java | 4 +-- .../AbstractBulkByQueryRestHandler.java | 4 +-- .../BulkByScrollParallelizationHelper.java | 8 +++--- .../index/reindex/RethrottleAction.java | 4 +-- .../reindex/RethrottleRequestBuilder.java | 4 +-- .../reindex/AsyncBulkByScrollActionTests.java | 4 +-- .../ReindexFromRemoteWithAuthTests.java | 2 +- .../elasticsearch/action/ActionModule.java | 8 +++--- .../action/ActionRequestBuilder.java | 4 +-- .../action/{Action.java => ActionType.java} | 8 +++--- ...java => StreamableResponseActionType.java} | 6 ++-- .../action/TransportActionNodeProxy.java | 4 +-- .../ClusterAllocationExplainAction.java | 6 ++-- .../AddVotingConfigExclusionsAction.java | 4 +-- .../ClearVotingConfigExclusionsAction.java | 4 +-- .../cluster/health/ClusterHealthAction.java | 4 +-- .../hotthreads/NodesHotThreadsAction.java | 4 +-- .../cluster/node/info/NodesInfoAction.java | 4 +-- .../NodesReloadSecureSettingsAction.java | 4 +-- .../cluster/node/stats/NodesStatsAction.java | 4 +-- .../node/tasks/cancel/CancelTasksAction.java | 6 ++-- .../cluster/node/tasks/get/GetTaskAction.java | 6 ++-- .../tasks/get/TransportGetTaskAction.java | 2 +- .../node/tasks/list/ListTasksAction.java | 6 ++-- .../cluster/node/usage/NodesUsageAction.java | 4 +-- .../node/usage/NodesUsageRequestBuilder.java | 4 +-- .../cluster/remote/RemoteInfoAction.java | 4 +-- .../delete/DeleteRepositoryAction.java | 4 +-- .../get/GetRepositoriesAction.java | 4 +-- .../repositories/put/PutRepositoryAction.java | 4 +-- .../verify/VerifyRepositoryAction.java | 4 +-- .../cluster/reroute/ClusterRerouteAction.java | 4 +-- .../settings/ClusterUpdateSettingsAction.java | 4 +-- .../shards/ClusterSearchShardsAction.java | 4 +-- .../create/CreateSnapshotAction.java | 4 +-- .../delete/DeleteSnapshotAction.java | 4 +-- .../snapshots/get/GetSnapshotsAction.java | 4 +-- .../restore/RestoreSnapshotAction.java | 4 +-- .../status/SnapshotsStatusAction.java | 4 +-- .../cluster/state/ClusterStateAction.java | 4 +-- .../cluster/stats/ClusterStatsAction.java | 4 +-- .../DeleteStoredScriptAction.java | 4 +-- .../storedscripts/GetStoredScriptAction.java | 4 +-- .../storedscripts/PutStoredScriptAction.java | 4 +-- .../tasks/PendingClusterTasksAction.java | 4 +-- .../indices/alias/IndicesAliasesAction.java | 4 +-- .../alias/exists/AliasesExistAction.java | 4 +-- .../alias/get/BaseAliasesRequestBuilder.java | 4 +-- .../indices/alias/get/GetAliasesAction.java | 4 +-- .../admin/indices/analyze/AnalyzeAction.java | 4 +-- .../cache/clear/ClearIndicesCacheAction.java | 4 +-- .../admin/indices/close/CloseIndexAction.java | 4 +-- .../indices/create/CreateIndexAction.java | 4 +-- .../indices/delete/DeleteIndexAction.java | 4 +-- .../exists/indices/IndicesExistsAction.java | 4 +-- .../exists/types/TypesExistsAction.java | 4 +-- .../admin/indices/flush/FlushAction.java | 4 +-- .../indices/flush/SyncedFlushAction.java | 4 +-- .../indices/flush/TransportFlushAction.java | 2 +- .../flush/TransportSyncedFlushAction.java | 2 +- .../indices/forcemerge/ForceMergeAction.java | 4 +-- .../admin/indices/get/GetIndexAction.java | 4 +-- .../mapping/get/GetFieldMappingsAction.java | 4 +-- .../mapping/get/GetMappingsAction.java | 4 +-- .../indices/mapping/put/PutMappingAction.java | 4 +-- .../admin/indices/open/OpenIndexAction.java | 4 +-- .../indices/recovery/RecoveryAction.java | 4 +-- .../admin/indices/refresh/RefreshAction.java | 4 +-- .../indices/rollover/RolloverAction.java | 4 +-- .../segments/IndicesSegmentsAction.java | 4 +-- .../settings/get/GetSettingsAction.java | 4 +-- .../settings/put/UpdateSettingsAction.java | 4 +-- .../IndicesShardStoreRequestBuilder.java | 4 +-- .../shards/IndicesShardStoresAction.java | 6 ++-- .../admin/indices/shrink/ResizeAction.java | 4 +-- .../indices/shrink/ResizeRequestBuilder.java | 4 +-- .../admin/indices/shrink/ShrinkAction.java | 4 +-- .../indices/stats/IndicesStatsAction.java | 4 +-- .../delete/DeleteIndexTemplateAction.java | 4 +-- .../template/get/GetIndexTemplatesAction.java | 4 +-- .../template/put/PutIndexTemplateAction.java | 4 +-- .../upgrade/get/UpgradeStatusAction.java | 4 +-- .../indices/upgrade/post/UpgradeAction.java | 4 +-- .../upgrade/post/UpgradeSettingsAction.java | 4 +-- .../validate/query/ValidateQueryAction.java | 4 +-- .../elasticsearch/action/bulk/BulkAction.java | 4 +-- .../action/delete/DeleteAction.java | 4 +-- .../action/explain/ExplainAction.java | 4 +-- .../fieldcaps/FieldCapabilitiesAction.java | 4 +-- .../elasticsearch/action/get/GetAction.java | 4 +-- .../action/get/MultiGetAction.java | 4 +-- .../action/index/IndexAction.java | 4 +-- .../action/ingest/DeletePipelineAction.java | 4 +-- .../action/ingest/GetPipelineAction.java | 4 +-- .../action/ingest/IngestActionForwarder.java | 4 +-- .../action/ingest/PutPipelineAction.java | 4 +-- .../action/ingest/SimulatePipelineAction.java | 4 +-- .../elasticsearch/action/main/MainAction.java | 4 +-- .../action/search/ClearScrollAction.java | 4 +-- .../action/search/MultiSearchAction.java | 4 +-- .../action/search/SearchAction.java | 4 +-- .../action/search/SearchScrollAction.java | 4 +-- .../BroadcastOperationRequestBuilder.java | 4 +-- .../master/AcknowledgedRequestBuilder.java | 4 +-- .../MasterNodeOperationRequestBuilder.java | 4 +-- ...MasterNodeReadOperationRequestBuilder.java | 4 +-- .../info/ClusterInfoRequestBuilder.java | 4 +-- .../nodes/NodesOperationRequestBuilder.java | 4 +-- .../ReplicationRequestBuilder.java | 4 +-- .../InstanceShardOperationRequestBuilder.java | 4 +-- .../SingleShardOperationRequestBuilder.java | 4 +-- .../support/tasks/TasksRequestBuilder.java | 4 +-- .../termvectors/MultiTermVectorsAction.java | 4 +-- .../action/termvectors/TermVectorsAction.java | 4 +-- .../action/update/UpdateAction.java | 4 +-- .../client/ElasticsearchClient.java | 10 +++---- .../elasticsearch/client/FilterClient.java | 4 +-- .../client/OriginSettingClient.java | 4 +-- .../client/ParentTaskAssigningClient.java | 4 +-- .../elasticsearch/client/node/NodeClient.java | 28 +++++++++---------- .../client/support/AbstractClient.java | 18 ++++++------ .../client/transport/TransportClient.java | 8 +++--- .../transport/TransportProxyClient.java | 12 ++++---- .../AbstractBulkByScrollRequestBuilder.java | 4 +-- ...stractBulkIndexByScrollRequestBuilder.java | 6 ++-- .../index/reindex/DeleteByQueryAction.java | 4 +-- .../reindex/DeleteByQueryRequestBuilder.java | 6 ++-- .../index/reindex/ReindexAction.java | 4 +-- .../index/reindex/ReindexRequestBuilder.java | 6 ++-- .../index/reindex/UpdateByQueryAction.java | 4 +-- .../reindex/UpdateByQueryRequestBuilder.java | 6 ++-- .../index/seqno/RetentionLeaseActions.java | 8 +++--- .../java/org/elasticsearch/node/Node.java | 4 +-- .../CompletionPersistentTaskAction.java | 6 ++-- .../persistent/PersistentTasksService.java | 4 +-- .../RemovePersistentTaskAction.java | 4 +-- .../persistent/StartPersistentTaskAction.java | 4 +-- .../UpdatePersistentTaskStatusAction.java | 4 +-- .../elasticsearch/plugins/ActionPlugin.java | 14 +++++----- .../transport/RemoteClusterAwareClient.java | 4 +-- .../action/ActionModuleTests.java | 2 +- .../org/elasticsearch/action/ActionTests.java | 2 +- .../cluster/node/tasks/TestTaskPlugin.java | 12 ++++---- .../bulk/TransportBulkActionTookTests.java | 4 +-- .../client/AbstractClientHeadersTestCase.java | 6 ++-- .../client/OriginSettingClientTests.java | 4 +-- .../ParentTaskAssigningClientTests.java | 4 +-- .../client/node/NodeClientHeadersTests.java | 10 +++---- .../TransportClientHeadersTests.java | 4 +-- .../InternalOrPrivateSettingsPlugin.java | 4 +-- .../PersistentTasksNodeServiceTests.java | 2 +- .../persistent/TestPersistentTasksPlugin.java | 4 +-- .../indices/RestValidateQueryActionTests.java | 4 +-- .../snapshots/SnapshotResiliencyTests.java | 4 +-- .../elasticsearch/test/client/NoOpClient.java | 4 +-- .../xpack/ccr/CcrLicenseChecker.java | 6 ++-- .../xpack/ccr/action/ShardChangesAction.java | 4 +-- .../bulk/BulkShardOperationsAction.java | 4 +-- .../ClearCcrRestoreSessionAction.java | 4 +-- .../DeleteInternalCcrRepositoryAction.java | 4 +-- .../GetCcrRestoreFileChunkAction.java | 4 +-- .../PutCcrRestoreSessionAction.java | 4 +-- .../PutInternalCcrRepositoryAction.java | 4 +-- .../license/DeleteLicenseAction.java | 4 +-- .../license/GetBasicStatusAction.java | 4 +-- .../license/GetLicenseAction.java | 4 +-- .../license/GetTrialStatusAction.java | 4 +-- .../license/PostStartBasicAction.java | 4 +-- .../license/PostStartTrialAction.java | 4 +-- .../license/PutLicenseAction.java | 4 +-- .../xpack/core/ClientHelper.java | 6 ++-- .../xpack/core/XPackClientPlugin.java | 4 +-- .../elasticsearch/xpack/core/XPackPlugin.java | 6 ++-- .../core/action/ReloadAnalyzerAction.java | 4 +-- .../action/TransportFreezeIndexAction.java | 4 +-- .../xpack/core/action/XPackInfoAction.java | 4 +-- .../xpack/core/action/XPackUsageAction.java | 4 +-- .../xpack/core/ccr/action/CcrStatsAction.java | 4 +-- .../action/DeleteAutoFollowPatternAction.java | 4 +-- .../core/ccr/action/FollowInfoAction.java | 4 +-- .../core/ccr/action/FollowStatsAction.java | 4 +-- .../core/ccr/action/ForgetFollowerAction.java | 4 +-- .../action/GetAutoFollowPatternAction.java | 4 +-- .../core/ccr/action/PauseFollowAction.java | 4 +-- .../action/PutAutoFollowPatternAction.java | 4 +-- .../core/ccr/action/PutFollowAction.java | 4 +-- .../core/ccr/action/ResumeFollowAction.java | 4 +-- .../xpack/core/ccr/action/UnfollowAction.java | 4 +-- .../DeleteDataFrameTransformAction.java | 4 +-- .../action/GetDataFrameTransformsAction.java | 4 +-- .../GetDataFrameTransformsStatsAction.java | 4 +-- .../PreviewDataFrameTransformAction.java | 4 +-- .../action/PutDataFrameTransformAction.java | 4 +-- .../action/StartDataFrameTransformAction.java | 4 +-- .../StartDataFrameTransformTaskAction.java | 4 +-- .../action/StopDataFrameTransformAction.java | 4 +-- .../deprecation/DeprecationInfoAction.java | 4 +-- .../NodesDeprecationCheckAction.java | 8 +++--- .../core/graph/action/GraphExploreAction.java | 4 +-- .../action/DeleteLifecycleAction.java | 4 +-- .../action/ExplainLifecycleAction.java | 4 +-- .../action/GetLifecycleAction.java | 4 +-- .../action/GetStatusAction.java | 4 +-- .../action/MoveToStepAction.java | 4 +-- .../action/PutLifecycleAction.java | 4 +-- .../RemoveIndexLifecyclePolicyAction.java | 4 +-- .../indexlifecycle/action/RetryAction.java | 4 +-- .../indexlifecycle/action/StartILMAction.java | 4 +-- .../indexlifecycle/action/StopILMAction.java | 4 +-- .../xpack/core/ml/action/CloseJobAction.java | 4 +-- .../core/ml/action/DeleteCalendarAction.java | 4 +-- .../ml/action/DeleteCalendarEventAction.java | 4 +-- .../DeleteDataFrameAnalyticsAction.java | 4 +-- .../core/ml/action/DeleteDatafeedAction.java | 4 +-- .../ml/action/DeleteExpiredDataAction.java | 4 +-- .../core/ml/action/DeleteFilterAction.java | 4 +-- .../core/ml/action/DeleteForecastAction.java | 4 +-- .../xpack/core/ml/action/DeleteJobAction.java | 4 +-- .../ml/action/DeleteModelSnapshotAction.java | 4 +-- .../ml/action/EvaluateDataFrameAction.java | 4 +-- .../ml/action/FinalizeJobExecutionAction.java | 4 +-- .../ml/action/FindFileStructureAction.java | 4 +-- .../xpack/core/ml/action/FlushJobAction.java | 4 +-- .../core/ml/action/ForecastJobAction.java | 4 +-- .../core/ml/action/GetBucketsAction.java | 4 +-- .../ml/action/GetCalendarEventsAction.java | 4 +-- .../core/ml/action/GetCalendarsAction.java | 4 +-- .../core/ml/action/GetCategoriesAction.java | 4 +-- .../action/GetDataFrameAnalyticsAction.java | 4 +-- .../GetDataFrameAnalyticsStatsAction.java | 4 +-- .../core/ml/action/GetDatafeedsAction.java | 4 +-- .../ml/action/GetDatafeedsStatsAction.java | 4 +-- .../core/ml/action/GetFiltersAction.java | 4 +-- .../core/ml/action/GetInfluencersAction.java | 4 +-- .../xpack/core/ml/action/GetJobsAction.java | 4 +-- .../core/ml/action/GetJobsStatsAction.java | 4 +-- .../ml/action/GetModelSnapshotsAction.java | 4 +-- .../ml/action/GetOverallBucketsAction.java | 4 +-- .../core/ml/action/GetRecordsAction.java | 4 +-- .../core/ml/action/IsolateDatafeedAction.java | 4 +-- .../core/ml/action/KillProcessAction.java | 4 +-- .../xpack/core/ml/action/MlInfoAction.java | 4 +-- .../xpack/core/ml/action/OpenJobAction.java | 4 +-- .../core/ml/action/PersistJobAction.java | 4 +-- .../ml/action/PostCalendarEventsAction.java | 4 +-- .../xpack/core/ml/action/PostDataAction.java | 4 +-- .../core/ml/action/PreviewDatafeedAction.java | 4 +-- .../core/ml/action/PutCalendarAction.java | 4 +-- .../action/PutDataFrameAnalyticsAction.java | 4 +-- .../core/ml/action/PutDatafeedAction.java | 4 +-- .../xpack/core/ml/action/PutFilterAction.java | 4 +-- .../xpack/core/ml/action/PutJobAction.java | 4 +-- .../ml/action/RevertModelSnapshotAction.java | 4 +-- .../core/ml/action/SetUpgradeModeAction.java | 4 +-- .../action/StartDataFrameAnalyticsAction.java | 4 +-- .../core/ml/action/StartDatafeedAction.java | 4 +-- .../action/StopDataFrameAnalyticsAction.java | 4 +-- .../core/ml/action/StopDatafeedAction.java | 4 +-- .../ml/action/UpdateCalendarJobAction.java | 4 +-- .../core/ml/action/UpdateDatafeedAction.java | 4 +-- .../core/ml/action/UpdateFilterAction.java | 4 +-- .../xpack/core/ml/action/UpdateJobAction.java | 4 +-- .../ml/action/UpdateModelSnapshotAction.java | 4 +-- .../core/ml/action/UpdateProcessAction.java | 4 +-- .../ml/action/ValidateDetectorAction.java | 4 +-- .../ml/action/ValidateJobConfigAction.java | 4 +-- .../action/MonitoringBulkAction.java | 4 +-- .../rollup/action/DeleteRollupJobAction.java | 4 +-- .../rollup/action/GetRollupCapsAction.java | 4 +-- .../action/GetRollupIndexCapsAction.java | 4 +-- .../rollup/action/GetRollupJobsAction.java | 4 +-- .../rollup/action/PutRollupJobAction.java | 4 +-- .../rollup/action/RollupSearchAction.java | 4 +-- .../rollup/action/StartRollupJobAction.java | 4 +-- .../rollup/action/StopRollupJobAction.java | 4 +-- .../security/action/CreateApiKeyAction.java | 6 ++-- .../core/security/action/GetApiKeyAction.java | 6 ++-- .../action/InvalidateApiKeyAction.java | 6 ++-- .../oidc/OpenIdConnectAuthenticateAction.java | 6 ++-- .../oidc/OpenIdConnectLogoutAction.java | 4 +-- ...nIdConnectPrepareAuthenticationAction.java | 4 +-- .../privilege/DeletePrivilegesAction.java | 6 ++-- .../action/privilege/GetPrivilegesAction.java | 6 ++-- .../action/privilege/PutPrivilegesAction.java | 6 ++-- .../action/realm/ClearRealmCacheAction.java | 4 +-- .../action/role/ClearRolesCacheAction.java | 4 +-- .../action/role/DeleteRoleAction.java | 6 ++-- .../security/action/role/GetRolesAction.java | 6 ++-- .../security/action/role/PutRoleAction.java | 6 ++-- .../rolemapping/DeleteRoleMappingAction.java | 6 ++-- .../rolemapping/GetRoleMappingsAction.java | 6 ++-- .../rolemapping/PutRoleMappingAction.java | 6 ++-- .../action/saml/SamlAuthenticateAction.java | 6 ++-- .../saml/SamlInvalidateSessionAction.java | 6 ++-- .../action/saml/SamlLogoutAction.java | 6 ++-- .../saml/SamlPrepareAuthenticationAction.java | 6 ++-- .../action/token/CreateTokenAction.java | 6 ++-- .../token/CreateTokenRequestBuilder.java | 4 +-- .../action/token/InvalidateTokenAction.java | 6 ++-- .../action/token/RefreshTokenAction.java | 4 +-- .../action/user/AuthenticateAction.java | 4 +-- .../action/user/ChangePasswordAction.java | 4 +-- .../action/user/DeleteUserAction.java | 6 ++-- .../action/user/GetUserPrivilegesAction.java | 6 ++-- .../security/action/user/GetUsersAction.java | 6 ++-- .../action/user/HasPrivilegesAction.java | 4 +-- .../security/action/user/PutUserAction.java | 6 ++-- .../action/user/SetEnabledAction.java | 4 +-- .../ssl/action/GetCertificateInfoAction.java | 6 ++-- .../upgrade/actions/IndexUpgradeAction.java | 4 +-- .../actions/IndexUpgradeInfoAction.java | 4 +-- .../transport/actions/ack/AckWatchAction.java | 4 +-- .../actions/activate/ActivateWatchAction.java | 4 +-- .../actions/delete/DeleteWatchAction.java | 4 +-- .../actions/execute/ExecuteWatchAction.java | 4 +-- .../transport/actions/get/GetWatchAction.java | 4 +-- .../transport/actions/put/PutWatchAction.java | 4 +-- .../actions/service/WatcherServiceAction.java | 4 +-- .../actions/stats/WatcherStatsAction.java | 6 ++-- ...meTransformCheckpointServiceNodeTests.java | 6 ++-- .../transforms/pivot/PivotTests.java | 6 ++-- .../LifecyclePolicySecurityClient.java | 6 ++-- .../action/oauth2/RestGetTokenAction.java | 4 +-- ...sportSamlInvalidateSessionActionTests.java | 4 +-- .../authc/esnative/NativeUsersStoreTests.java | 4 +-- .../store/NativePrivilegeStoreTests.java | 4 +-- .../apikey/RestCreateApiKeyActionTests.java | 7 ++--- .../apikey/RestGetApiKeyActionTests.java | 7 ++--- .../RestInvalidateApiKeyActionTests.java | 7 ++--- .../support/SecurityIndexManagerTests.java | 6 ++-- .../sql/action/SqlClearCursorAction.java | 4 +-- .../xpack/sql/action/SqlQueryAction.java | 4 +-- .../xpack/sql/action/SqlTranslateAction.java | 4 +-- .../xpack/sql/plugin/SqlStatsAction.java | 4 +-- 343 files changed, 777 insertions(+), 780 deletions(-) rename server/src/main/java/org/elasticsearch/action/{Action.java => ActionType.java} (89%) rename server/src/main/java/org/elasticsearch/action/{StreamableResponseAction.java => StreamableResponseActionType.java} (85%) diff --git a/client/client-benchmark-noop-api-plugin/src/main/java/org/elasticsearch/plugin/noop/action/bulk/NoopBulkAction.java b/client/client-benchmark-noop-api-plugin/src/main/java/org/elasticsearch/plugin/noop/action/bulk/NoopBulkAction.java index 40c65aee700..e6412099fee 100644 --- a/client/client-benchmark-noop-api-plugin/src/main/java/org/elasticsearch/plugin/noop/action/bulk/NoopBulkAction.java +++ b/client/client-benchmark-noop-api-plugin/src/main/java/org/elasticsearch/plugin/noop/action/bulk/NoopBulkAction.java @@ -18,10 +18,10 @@ */ package org.elasticsearch.plugin.noop.action.bulk; -import org.elasticsearch.action.StreamableResponseAction; +import org.elasticsearch.action.StreamableResponseActionType; import org.elasticsearch.action.bulk.BulkResponse; -public class NoopBulkAction extends StreamableResponseAction { +public class NoopBulkAction extends StreamableResponseActionType { public static final String NAME = "mock:data/write/bulk"; public static final NoopBulkAction INSTANCE = new NoopBulkAction(); diff --git a/client/client-benchmark-noop-api-plugin/src/main/java/org/elasticsearch/plugin/noop/action/search/NoopSearchAction.java b/client/client-benchmark-noop-api-plugin/src/main/java/org/elasticsearch/plugin/noop/action/search/NoopSearchAction.java index aa316ae435a..fb83bda148b 100644 --- a/client/client-benchmark-noop-api-plugin/src/main/java/org/elasticsearch/plugin/noop/action/search/NoopSearchAction.java +++ b/client/client-benchmark-noop-api-plugin/src/main/java/org/elasticsearch/plugin/noop/action/search/NoopSearchAction.java @@ -18,11 +18,11 @@ */ package org.elasticsearch.plugin.noop.action.search; -import org.elasticsearch.action.Action; +import org.elasticsearch.action.ActionType; import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.common.io.stream.Writeable; -public class NoopSearchAction extends Action { +public class NoopSearchAction extends ActionType { public static final NoopSearchAction INSTANCE = new NoopSearchAction(); public static final String NAME = "mock:data/read/search"; 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 ee2f49390b8..f6eadab8014 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 @@ -22,7 +22,7 @@ import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.ActionRequest; import org.elasticsearch.action.ActionRequestValidationException; import org.elasticsearch.action.ActionResponse; -import org.elasticsearch.action.StreamableResponseAction; +import org.elasticsearch.action.StreamableResponseActionType; import org.elasticsearch.action.support.ActionFilters; import org.elasticsearch.action.support.HandledTransportAction; import org.elasticsearch.client.node.NodeClient; @@ -45,7 +45,7 @@ import java.util.Map; import static org.elasticsearch.ingest.common.IngestCommonPlugin.GROK_PATTERNS; import static org.elasticsearch.rest.RestRequest.Method.GET; -public class GrokProcessorGetAction extends StreamableResponseAction { +public class GrokProcessorGetAction extends StreamableResponseActionType { static final GrokProcessorGetAction INSTANCE = new GrokProcessorGetAction(); static final String NAME = "cluster:admin/ingest/processor/grok/get"; diff --git a/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/MultiSearchTemplateAction.java b/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/MultiSearchTemplateAction.java index 573c5888991..a096a89951e 100644 --- a/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/MultiSearchTemplateAction.java +++ b/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/MultiSearchTemplateAction.java @@ -19,10 +19,10 @@ package org.elasticsearch.script.mustache; -import org.elasticsearch.action.Action; +import org.elasticsearch.action.ActionType; import org.elasticsearch.common.io.stream.Writeable; -public class MultiSearchTemplateAction extends Action { +public class MultiSearchTemplateAction extends ActionType { public static final MultiSearchTemplateAction INSTANCE = new MultiSearchTemplateAction(); public static final String NAME = "indices:data/read/msearch/template"; diff --git a/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/SearchTemplateAction.java b/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/SearchTemplateAction.java index 7bd57154e26..2e8417c9939 100644 --- a/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/SearchTemplateAction.java +++ b/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/SearchTemplateAction.java @@ -19,10 +19,10 @@ package org.elasticsearch.script.mustache; -import org.elasticsearch.action.Action; +import org.elasticsearch.action.ActionType; import org.elasticsearch.common.io.stream.Writeable; -public class SearchTemplateAction extends Action { +public class SearchTemplateAction extends ActionType { public static final SearchTemplateAction INSTANCE = new SearchTemplateAction(); public static final String NAME = "indices:data/read/search/template"; 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 4abad4d78af..5e941a2d0e2 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 @@ -19,7 +19,7 @@ package org.elasticsearch.painless.action; -import org.elasticsearch.action.Action; +import org.elasticsearch.action.ActionType; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.ActionRequest; import org.elasticsearch.action.ActionRequestValidationException; @@ -64,7 +64,7 @@ import static org.elasticsearch.rest.RestRequest.Method.GET; * retrieves all available information about the API for this specific context * */ -public class PainlessContextAction extends Action { +public class PainlessContextAction extends ActionType { public static final PainlessContextAction INSTANCE = new PainlessContextAction(); private static final String NAME = "cluster:admin/scripts/painless/context"; 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 bc34c90ad52..93e24816ed7 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 @@ -31,7 +31,7 @@ import org.apache.lucene.search.Scorer; import org.apache.lucene.search.Weight; import org.apache.lucene.store.RAMDirectory; import org.elasticsearch.Version; -import org.elasticsearch.action.Action; +import org.elasticsearch.action.ActionType; import org.elasticsearch.action.ActionRequestValidationException; import org.elasticsearch.action.ActionResponse; import org.elasticsearch.action.support.ActionFilters; @@ -92,7 +92,7 @@ import static org.elasticsearch.action.ValidateActions.addValidationError; import static org.elasticsearch.rest.RestRequest.Method.GET; import static org.elasticsearch.rest.RestRequest.Method.POST; -public class PainlessExecuteAction extends Action { +public class PainlessExecuteAction extends ActionType { public static final PainlessExecuteAction INSTANCE = new PainlessExecuteAction(); private static final String NAME = "cluster:admin/scripts/painless/execute"; diff --git a/modules/rank-eval/src/main/java/org/elasticsearch/index/rankeval/RankEvalAction.java b/modules/rank-eval/src/main/java/org/elasticsearch/index/rankeval/RankEvalAction.java index 664377786f8..07de8c8a22c 100644 --- a/modules/rank-eval/src/main/java/org/elasticsearch/index/rankeval/RankEvalAction.java +++ b/modules/rank-eval/src/main/java/org/elasticsearch/index/rankeval/RankEvalAction.java @@ -19,12 +19,12 @@ package org.elasticsearch.index.rankeval; -import org.elasticsearch.action.StreamableResponseAction; +import org.elasticsearch.action.StreamableResponseActionType; /** - * Action for explaining evaluating search ranking results. + * ActionType for explaining evaluating search ranking results. */ -public class RankEvalAction extends StreamableResponseAction { +public class RankEvalAction extends StreamableResponseActionType { public static final RankEvalAction INSTANCE = new RankEvalAction(); public static final String NAME = "indices:data/read/rank_eval"; diff --git a/modules/rank-eval/src/main/java/org/elasticsearch/index/rankeval/RankEvalRequestBuilder.java b/modules/rank-eval/src/main/java/org/elasticsearch/index/rankeval/RankEvalRequestBuilder.java index 4108a817f04..1bfb576c379 100644 --- a/modules/rank-eval/src/main/java/org/elasticsearch/index/rankeval/RankEvalRequestBuilder.java +++ b/modules/rank-eval/src/main/java/org/elasticsearch/index/rankeval/RankEvalRequestBuilder.java @@ -19,13 +19,13 @@ package org.elasticsearch.index.rankeval; -import org.elasticsearch.action.Action; +import org.elasticsearch.action.ActionType; import org.elasticsearch.action.ActionRequestBuilder; import org.elasticsearch.client.ElasticsearchClient; public class RankEvalRequestBuilder extends ActionRequestBuilder { - public RankEvalRequestBuilder(ElasticsearchClient client, Action action, + public RankEvalRequestBuilder(ElasticsearchClient client, ActionType action, RankEvalRequest request) { super(client, action, request); } diff --git a/modules/reindex/src/main/java/org/elasticsearch/index/reindex/AbstractBaseReindexRestHandler.java b/modules/reindex/src/main/java/org/elasticsearch/index/reindex/AbstractBaseReindexRestHandler.java index 8111aac3945..63451abb7cc 100644 --- a/modules/reindex/src/main/java/org/elasticsearch/index/reindex/AbstractBaseReindexRestHandler.java +++ b/modules/reindex/src/main/java/org/elasticsearch/index/reindex/AbstractBaseReindexRestHandler.java @@ -19,7 +19,7 @@ package org.elasticsearch.index.reindex; -import org.elasticsearch.action.Action; +import org.elasticsearch.action.ActionType; import org.elasticsearch.action.ActionRequestValidationException; import org.elasticsearch.action.support.ActiveShardCount; import org.elasticsearch.client.node.NodeClient; @@ -38,7 +38,7 @@ import java.util.Map; public abstract class AbstractBaseReindexRestHandler< Request extends AbstractBulkByScrollRequest, - A extends Action + A extends ActionType > extends BaseRestHandler { private final A action; diff --git a/modules/reindex/src/main/java/org/elasticsearch/index/reindex/AbstractBulkByQueryRestHandler.java b/modules/reindex/src/main/java/org/elasticsearch/index/reindex/AbstractBulkByQueryRestHandler.java index 240ccde3505..834703cddc7 100644 --- a/modules/reindex/src/main/java/org/elasticsearch/index/reindex/AbstractBulkByQueryRestHandler.java +++ b/modules/reindex/src/main/java/org/elasticsearch/index/reindex/AbstractBulkByQueryRestHandler.java @@ -19,7 +19,7 @@ package org.elasticsearch.index.reindex; -import org.elasticsearch.action.Action; +import org.elasticsearch.action.ActionType; import org.elasticsearch.action.search.SearchRequest; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.settings.Settings; @@ -39,7 +39,7 @@ import java.util.function.Consumer; */ public abstract class AbstractBulkByQueryRestHandler< Request extends AbstractBulkByScrollRequest, - A extends Action> extends AbstractBaseReindexRestHandler { + A extends ActionType> extends AbstractBaseReindexRestHandler { protected AbstractBulkByQueryRestHandler(Settings settings, A action) { super(settings, action); diff --git a/modules/reindex/src/main/java/org/elasticsearch/index/reindex/BulkByScrollParallelizationHelper.java b/modules/reindex/src/main/java/org/elasticsearch/index/reindex/BulkByScrollParallelizationHelper.java index dfb8deac58c..6df73414e81 100644 --- a/modules/reindex/src/main/java/org/elasticsearch/index/reindex/BulkByScrollParallelizationHelper.java +++ b/modules/reindex/src/main/java/org/elasticsearch/index/reindex/BulkByScrollParallelizationHelper.java @@ -19,7 +19,7 @@ package org.elasticsearch.index.reindex; -import org.elasticsearch.action.Action; +import org.elasticsearch.action.ActionType; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.admin.cluster.shards.ClusterSearchShardsRequest; import org.elasticsearch.action.admin.cluster.shards.ClusterSearchShardsResponse; @@ -61,7 +61,7 @@ class BulkByScrollParallelizationHelper { static > void startSlicedAction( Request request, BulkByScrollTask task, - Action action, + ActionType action, ActionListener listener, Client client, DiscoveryNode node, @@ -85,7 +85,7 @@ class BulkByScrollParallelizationHelper { private static > void sliceConditionally( Request request, BulkByScrollTask task, - Action action, + ActionType action, ActionListener listener, Client client, DiscoveryNode node, @@ -118,7 +118,7 @@ class BulkByScrollParallelizationHelper { private static > void sendSubRequests( Client client, - Action action, + ActionType action, String localNodeId, BulkByScrollTask task, Request request, diff --git a/modules/reindex/src/main/java/org/elasticsearch/index/reindex/RethrottleAction.java b/modules/reindex/src/main/java/org/elasticsearch/index/reindex/RethrottleAction.java index 513b4261bdf..cf04d6d856d 100644 --- a/modules/reindex/src/main/java/org/elasticsearch/index/reindex/RethrottleAction.java +++ b/modules/reindex/src/main/java/org/elasticsearch/index/reindex/RethrottleAction.java @@ -19,11 +19,11 @@ package org.elasticsearch.index.reindex; -import org.elasticsearch.action.Action; +import org.elasticsearch.action.ActionType; import org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksResponse; import org.elasticsearch.common.io.stream.Writeable; -public class RethrottleAction extends Action { +public class RethrottleAction extends ActionType { public static final RethrottleAction INSTANCE = new RethrottleAction(); public static final String NAME = "cluster:admin/reindex/rethrottle"; diff --git a/modules/reindex/src/main/java/org/elasticsearch/index/reindex/RethrottleRequestBuilder.java b/modules/reindex/src/main/java/org/elasticsearch/index/reindex/RethrottleRequestBuilder.java index 25407e6dc93..648eb6e441b 100644 --- a/modules/reindex/src/main/java/org/elasticsearch/index/reindex/RethrottleRequestBuilder.java +++ b/modules/reindex/src/main/java/org/elasticsearch/index/reindex/RethrottleRequestBuilder.java @@ -19,7 +19,7 @@ package org.elasticsearch.index.reindex; -import org.elasticsearch.action.Action; +import org.elasticsearch.action.ActionType; import org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksResponse; import org.elasticsearch.action.support.tasks.TasksRequestBuilder; import org.elasticsearch.client.ElasticsearchClient; @@ -29,7 +29,7 @@ import org.elasticsearch.client.ElasticsearchClient; */ public class RethrottleRequestBuilder extends TasksRequestBuilder { public RethrottleRequestBuilder(ElasticsearchClient client, - Action action) { + ActionType action) { super(client, action, new RethrottleRequest()); } diff --git a/modules/reindex/src/test/java/org/elasticsearch/index/reindex/AsyncBulkByScrollActionTests.java b/modules/reindex/src/test/java/org/elasticsearch/index/reindex/AsyncBulkByScrollActionTests.java index bdedc65b7a6..3d28ce3bcbc 100644 --- a/modules/reindex/src/test/java/org/elasticsearch/index/reindex/AsyncBulkByScrollActionTests.java +++ b/modules/reindex/src/test/java/org/elasticsearch/index/reindex/AsyncBulkByScrollActionTests.java @@ -23,7 +23,7 @@ import org.apache.lucene.search.TotalHits; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.ExceptionsHelper; import org.elasticsearch.Version; -import org.elasticsearch.action.Action; +import org.elasticsearch.action.ActionType; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.ActionRequest; import org.elasticsearch.action.ActionResponse; @@ -761,7 +761,7 @@ public class AsyncBulkByScrollActionTests extends ESTestCase { @Override @SuppressWarnings("unchecked") protected - void doExecute(Action action, Request request, ActionListener listener) { + void doExecute(ActionType action, Request request, ActionListener listener) { if (false == expectedHeaders.equals(threadPool().getThreadContext().getHeaders())) { listener.onFailure( new RuntimeException("Expected " + expectedHeaders + " but got " + threadPool().getThreadContext().getHeaders())); diff --git a/modules/reindex/src/test/java/org/elasticsearch/index/reindex/ReindexFromRemoteWithAuthTests.java b/modules/reindex/src/test/java/org/elasticsearch/index/reindex/ReindexFromRemoteWithAuthTests.java index dc6d5eac588..9c017cb2ded 100644 --- a/modules/reindex/src/test/java/org/elasticsearch/index/reindex/ReindexFromRemoteWithAuthTests.java +++ b/modules/reindex/src/test/java/org/elasticsearch/index/reindex/ReindexFromRemoteWithAuthTests.java @@ -167,7 +167,7 @@ public class ReindexFromRemoteWithAuthTests extends ESSingleNodeTestCase { } /** - * Action filter that will reject the request if it isn't authenticated. + * ActionType filter that will reject the request if it isn't authenticated. */ public static class TestFilter implements ActionFilter { /** diff --git a/server/src/main/java/org/elasticsearch/action/ActionModule.java b/server/src/main/java/org/elasticsearch/action/ActionModule.java index 27d441830c5..c787ea6e7e2 100644 --- a/server/src/main/java/org/elasticsearch/action/ActionModule.java +++ b/server/src/main/java/org/elasticsearch/action/ActionModule.java @@ -424,7 +424,7 @@ public class ActionModule extends AbstractModule { } public void register( - Action action, Class> transportAction, + ActionType action, Class> transportAction, Class... supportTransportActions) { register(new ActionHandler<>(action, transportAction, supportTransportActions)); } @@ -703,10 +703,10 @@ public class ActionModule extends AbstractModule { bind(AutoCreateIndex.class).toInstance(autoCreateIndex); bind(TransportLivenessAction.class).asEagerSingleton(); - // register Action -> transportAction Map used by NodeClient + // register ActionType -> transportAction Map used by NodeClient @SuppressWarnings("rawtypes") - MapBinder transportActionsBinder - = MapBinder.newMapBinder(binder(), Action.class, TransportAction.class); + MapBinder transportActionsBinder + = MapBinder.newMapBinder(binder(), ActionType.class, TransportAction.class); for (ActionHandler action : actions.values()) { // bind the action as eager singleton, so the map binder one will reuse it bind(action.getTransportAction()).asEagerSingleton(); diff --git a/server/src/main/java/org/elasticsearch/action/ActionRequestBuilder.java b/server/src/main/java/org/elasticsearch/action/ActionRequestBuilder.java index a3aa8ac2a52..166bec9e065 100644 --- a/server/src/main/java/org/elasticsearch/action/ActionRequestBuilder.java +++ b/server/src/main/java/org/elasticsearch/action/ActionRequestBuilder.java @@ -26,11 +26,11 @@ import java.util.Objects; public abstract class ActionRequestBuilder { - protected final Action action; + protected final ActionType action; protected final Request request; protected final ElasticsearchClient client; - protected ActionRequestBuilder(ElasticsearchClient client, Action action, Request request) { + protected ActionRequestBuilder(ElasticsearchClient client, ActionType action, Request request) { Objects.requireNonNull(action, "action must not be null"); this.action = action; this.request = request; diff --git a/server/src/main/java/org/elasticsearch/action/Action.java b/server/src/main/java/org/elasticsearch/action/ActionType.java similarity index 89% rename from server/src/main/java/org/elasticsearch/action/Action.java rename to server/src/main/java/org/elasticsearch/action/ActionType.java index 0037533797d..02f8f3c6fc2 100644 --- a/server/src/main/java/org/elasticsearch/action/Action.java +++ b/server/src/main/java/org/elasticsearch/action/ActionType.java @@ -26,7 +26,7 @@ import org.elasticsearch.transport.TransportRequestOptions; /** * A generic action. Should strive to make it a singleton. */ -public class Action { +public class ActionType { private final String name; private final Writeable.Reader responseReader; @@ -36,7 +36,7 @@ public class Action { * @deprecated Pass a {@link Writeable.Reader} with {@link } */ @Deprecated - protected Action(String name) { + protected ActionType(String name) { this(name, null); } @@ -44,7 +44,7 @@ public class Action { * @param name The name of the action, must be unique across actions. * @param responseReader A reader for the response type */ - public Action(String name, Writeable.Reader responseReader) { + public ActionType(String name, Writeable.Reader responseReader) { this.name = name; this.responseReader = responseReader; } @@ -72,7 +72,7 @@ public class Action { @Override public boolean equals(Object o) { - return o instanceof Action && name.equals(((Action) o).name()); + return o instanceof ActionType && name.equals(((ActionType) o).name()); } @Override diff --git a/server/src/main/java/org/elasticsearch/action/StreamableResponseAction.java b/server/src/main/java/org/elasticsearch/action/StreamableResponseActionType.java similarity index 85% rename from server/src/main/java/org/elasticsearch/action/StreamableResponseAction.java rename to server/src/main/java/org/elasticsearch/action/StreamableResponseActionType.java index c7eecfc35d7..b8206bb03f8 100644 --- a/server/src/main/java/org/elasticsearch/action/StreamableResponseAction.java +++ b/server/src/main/java/org/elasticsearch/action/StreamableResponseActionType.java @@ -23,12 +23,12 @@ import org.elasticsearch.common.io.stream.Writeable; /** * An action for with the response type implements {@link org.elasticsearch.common.io.stream.Streamable}. - * @deprecated Use {@link Action} directly and provide a {@link Writeable.Reader} + * @deprecated Use {@link ActionType} directly and provide a {@link Writeable.Reader} */ @Deprecated -public abstract class StreamableResponseAction extends Action { +public abstract class StreamableResponseActionType extends ActionType { - protected StreamableResponseAction(String name) { + protected StreamableResponseActionType(String name) { super(name); } diff --git a/server/src/main/java/org/elasticsearch/action/TransportActionNodeProxy.java b/server/src/main/java/org/elasticsearch/action/TransportActionNodeProxy.java index a4c3e17e802..4319a745ba8 100644 --- a/server/src/main/java/org/elasticsearch/action/TransportActionNodeProxy.java +++ b/server/src/main/java/org/elasticsearch/action/TransportActionNodeProxy.java @@ -30,10 +30,10 @@ import org.elasticsearch.transport.TransportService; public class TransportActionNodeProxy { private final TransportService transportService; - private final Action action; + private final ActionType action; private final TransportRequestOptions transportOptions; - public TransportActionNodeProxy(Settings settings, Action action, TransportService transportService) { + public TransportActionNodeProxy(Settings settings, ActionType action, TransportService transportService) { this.action = action; this.transportService = transportService; this.transportOptions = action.transportOptions(settings); diff --git a/server/src/main/java/org/elasticsearch/action/admin/cluster/allocation/ClusterAllocationExplainAction.java b/server/src/main/java/org/elasticsearch/action/admin/cluster/allocation/ClusterAllocationExplainAction.java index b4b348ae97e..acaaed9eaa9 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/cluster/allocation/ClusterAllocationExplainAction.java +++ b/server/src/main/java/org/elasticsearch/action/admin/cluster/allocation/ClusterAllocationExplainAction.java @@ -19,12 +19,12 @@ package org.elasticsearch.action.admin.cluster.allocation; -import org.elasticsearch.action.StreamableResponseAction; +import org.elasticsearch.action.StreamableResponseActionType; /** - * Action for explaining shard allocation for a shard in the cluster + * ActionType for explaining shard allocation for a shard in the cluster */ -public class ClusterAllocationExplainAction extends StreamableResponseAction { +public class ClusterAllocationExplainAction extends StreamableResponseActionType { public static final ClusterAllocationExplainAction INSTANCE = new ClusterAllocationExplainAction(); public static final String NAME = "cluster:monitor/allocation/explain"; diff --git a/server/src/main/java/org/elasticsearch/action/admin/cluster/configuration/AddVotingConfigExclusionsAction.java b/server/src/main/java/org/elasticsearch/action/admin/cluster/configuration/AddVotingConfigExclusionsAction.java index 20f1e3c5044..a2f0c721b5d 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/cluster/configuration/AddVotingConfigExclusionsAction.java +++ b/server/src/main/java/org/elasticsearch/action/admin/cluster/configuration/AddVotingConfigExclusionsAction.java @@ -18,10 +18,10 @@ */ package org.elasticsearch.action.admin.cluster.configuration; -import org.elasticsearch.action.Action; +import org.elasticsearch.action.ActionType; import org.elasticsearch.common.io.stream.Writeable.Reader; -public class AddVotingConfigExclusionsAction extends Action { +public class AddVotingConfigExclusionsAction extends ActionType { public static final AddVotingConfigExclusionsAction INSTANCE = new AddVotingConfigExclusionsAction(); public static final String NAME = "cluster:admin/voting_config/add_exclusions"; diff --git a/server/src/main/java/org/elasticsearch/action/admin/cluster/configuration/ClearVotingConfigExclusionsAction.java b/server/src/main/java/org/elasticsearch/action/admin/cluster/configuration/ClearVotingConfigExclusionsAction.java index 6cafcb7653f..6091800693f 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/cluster/configuration/ClearVotingConfigExclusionsAction.java +++ b/server/src/main/java/org/elasticsearch/action/admin/cluster/configuration/ClearVotingConfigExclusionsAction.java @@ -18,10 +18,10 @@ */ package org.elasticsearch.action.admin.cluster.configuration; -import org.elasticsearch.action.Action; +import org.elasticsearch.action.ActionType; import org.elasticsearch.common.io.stream.Writeable.Reader; -public class ClearVotingConfigExclusionsAction extends Action { +public class ClearVotingConfigExclusionsAction extends ActionType { public static final ClearVotingConfigExclusionsAction INSTANCE = new ClearVotingConfigExclusionsAction(); public static final String NAME = "cluster:admin/voting_config/clear_exclusions"; diff --git a/server/src/main/java/org/elasticsearch/action/admin/cluster/health/ClusterHealthAction.java b/server/src/main/java/org/elasticsearch/action/admin/cluster/health/ClusterHealthAction.java index ceb2a145fb6..e8f5ecfaf5b 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/cluster/health/ClusterHealthAction.java +++ b/server/src/main/java/org/elasticsearch/action/admin/cluster/health/ClusterHealthAction.java @@ -19,9 +19,9 @@ package org.elasticsearch.action.admin.cluster.health; -import org.elasticsearch.action.StreamableResponseAction; +import org.elasticsearch.action.StreamableResponseActionType; -public class ClusterHealthAction extends StreamableResponseAction { +public class ClusterHealthAction extends StreamableResponseActionType { public static final ClusterHealthAction INSTANCE = new ClusterHealthAction(); public static final String NAME = "cluster:monitor/health"; diff --git a/server/src/main/java/org/elasticsearch/action/admin/cluster/node/hotthreads/NodesHotThreadsAction.java b/server/src/main/java/org/elasticsearch/action/admin/cluster/node/hotthreads/NodesHotThreadsAction.java index 317fa984163..4833625d295 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/cluster/node/hotthreads/NodesHotThreadsAction.java +++ b/server/src/main/java/org/elasticsearch/action/admin/cluster/node/hotthreads/NodesHotThreadsAction.java @@ -19,9 +19,9 @@ package org.elasticsearch.action.admin.cluster.node.hotthreads; -import org.elasticsearch.action.StreamableResponseAction; +import org.elasticsearch.action.StreamableResponseActionType; -public class NodesHotThreadsAction extends StreamableResponseAction { +public class NodesHotThreadsAction extends StreamableResponseActionType { public static final NodesHotThreadsAction INSTANCE = new NodesHotThreadsAction(); public static final String NAME = "cluster:monitor/nodes/hot_threads"; diff --git a/server/src/main/java/org/elasticsearch/action/admin/cluster/node/info/NodesInfoAction.java b/server/src/main/java/org/elasticsearch/action/admin/cluster/node/info/NodesInfoAction.java index b860f07c8ff..e94390d8f92 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/cluster/node/info/NodesInfoAction.java +++ b/server/src/main/java/org/elasticsearch/action/admin/cluster/node/info/NodesInfoAction.java @@ -19,9 +19,9 @@ package org.elasticsearch.action.admin.cluster.node.info; -import org.elasticsearch.action.StreamableResponseAction; +import org.elasticsearch.action.StreamableResponseActionType; -public class NodesInfoAction extends StreamableResponseAction { +public class NodesInfoAction extends StreamableResponseActionType { public static final NodesInfoAction INSTANCE = new NodesInfoAction(); public static final String NAME = "cluster:monitor/nodes/info"; diff --git a/server/src/main/java/org/elasticsearch/action/admin/cluster/node/reload/NodesReloadSecureSettingsAction.java b/server/src/main/java/org/elasticsearch/action/admin/cluster/node/reload/NodesReloadSecureSettingsAction.java index 0a0c8a74fe9..e22595c1870 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/cluster/node/reload/NodesReloadSecureSettingsAction.java +++ b/server/src/main/java/org/elasticsearch/action/admin/cluster/node/reload/NodesReloadSecureSettingsAction.java @@ -19,10 +19,10 @@ package org.elasticsearch.action.admin.cluster.node.reload; -import org.elasticsearch.action.StreamableResponseAction; +import org.elasticsearch.action.StreamableResponseActionType; public class NodesReloadSecureSettingsAction - extends StreamableResponseAction { + extends StreamableResponseActionType { public static final NodesReloadSecureSettingsAction INSTANCE = new NodesReloadSecureSettingsAction(); public static final String NAME = "cluster:admin/nodes/reload_secure_settings"; diff --git a/server/src/main/java/org/elasticsearch/action/admin/cluster/node/stats/NodesStatsAction.java b/server/src/main/java/org/elasticsearch/action/admin/cluster/node/stats/NodesStatsAction.java index 1febe1b4872..dbe7deed74a 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/cluster/node/stats/NodesStatsAction.java +++ b/server/src/main/java/org/elasticsearch/action/admin/cluster/node/stats/NodesStatsAction.java @@ -19,9 +19,9 @@ package org.elasticsearch.action.admin.cluster.node.stats; -import org.elasticsearch.action.StreamableResponseAction; +import org.elasticsearch.action.StreamableResponseActionType; -public class NodesStatsAction extends StreamableResponseAction { +public class NodesStatsAction extends StreamableResponseActionType { public static final NodesStatsAction INSTANCE = new NodesStatsAction(); public static final String NAME = "cluster:monitor/nodes/stats"; diff --git a/server/src/main/java/org/elasticsearch/action/admin/cluster/node/tasks/cancel/CancelTasksAction.java b/server/src/main/java/org/elasticsearch/action/admin/cluster/node/tasks/cancel/CancelTasksAction.java index 39532d18519..a0fa139dc73 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/cluster/node/tasks/cancel/CancelTasksAction.java +++ b/server/src/main/java/org/elasticsearch/action/admin/cluster/node/tasks/cancel/CancelTasksAction.java @@ -19,13 +19,13 @@ package org.elasticsearch.action.admin.cluster.node.tasks.cancel; -import org.elasticsearch.action.Action; +import org.elasticsearch.action.ActionType; import org.elasticsearch.common.io.stream.Writeable; /** - * Action for cancelling running tasks + * ActionType for cancelling running tasks */ -public class CancelTasksAction extends Action { +public class CancelTasksAction extends ActionType { public static final CancelTasksAction INSTANCE = new CancelTasksAction(); public static final String NAME = "cluster:admin/tasks/cancel"; diff --git a/server/src/main/java/org/elasticsearch/action/admin/cluster/node/tasks/get/GetTaskAction.java b/server/src/main/java/org/elasticsearch/action/admin/cluster/node/tasks/get/GetTaskAction.java index cdb5bbc3906..978e07555b5 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/cluster/node/tasks/get/GetTaskAction.java +++ b/server/src/main/java/org/elasticsearch/action/admin/cluster/node/tasks/get/GetTaskAction.java @@ -19,12 +19,12 @@ package org.elasticsearch.action.admin.cluster.node.tasks.get; -import org.elasticsearch.action.StreamableResponseAction; +import org.elasticsearch.action.StreamableResponseActionType; /** - * Action for retrieving a list of currently running tasks + * ActionType for retrieving a list of currently running tasks */ -public class GetTaskAction extends StreamableResponseAction { +public class GetTaskAction extends StreamableResponseActionType { public static final String TASKS_ORIGIN = "tasks"; public static final GetTaskAction INSTANCE = new GetTaskAction(); diff --git a/server/src/main/java/org/elasticsearch/action/admin/cluster/node/tasks/get/TransportGetTaskAction.java b/server/src/main/java/org/elasticsearch/action/admin/cluster/node/tasks/get/TransportGetTaskAction.java index d1d72da5445..2b0ac0233be 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/cluster/node/tasks/get/TransportGetTaskAction.java +++ b/server/src/main/java/org/elasticsearch/action/admin/cluster/node/tasks/get/TransportGetTaskAction.java @@ -56,7 +56,7 @@ import static org.elasticsearch.action.admin.cluster.node.tasks.get.GetTaskActio import static org.elasticsearch.action.admin.cluster.node.tasks.list.TransportListTasksAction.waitForCompletionTimeout; /** - * Action to get a single task. If the task isn't running then it'll try to request the status from request index. + * ActionType to get a single task. If the task isn't running then it'll try to request the status from request index. * * The general flow is: * */ public CreateTokenRequest(String grantType, @Nullable String scope, @Nullable String username, @Nullable char[] password, - @Nullable String refreshToken) { + @Nullable String refreshToken, @Nullable char[] kerberosTicket) { if (Strings.isNullOrEmpty(grantType)) { throw new IllegalArgumentException("grant_type is required"); } @@ -60,6 +62,7 @@ public final class CreateTokenRequest implements Validatable, ToXContentObject { this.password = password; this.scope = scope; this.refreshToken = refreshToken; + this.kerberosTicket = kerberosTicket; } public static CreateTokenRequest passwordGrant(String username, char[] password) { @@ -69,18 +72,25 @@ public final class CreateTokenRequest implements Validatable, ToXContentObject { if (password == null || password.length == 0) { throw new IllegalArgumentException("password is required"); } - return new CreateTokenRequest("password", null, username, password, null); + return new CreateTokenRequest("password", null, username, password, null, null); } public static CreateTokenRequest refreshTokenGrant(String refreshToken) { if (Strings.isNullOrEmpty(refreshToken)) { throw new IllegalArgumentException("refresh_token is required"); } - return new CreateTokenRequest("refresh_token", null, null, null, refreshToken); + return new CreateTokenRequest("refresh_token", null, null, null, refreshToken, null); } public static CreateTokenRequest clientCredentialsGrant() { - return new CreateTokenRequest("client_credentials", null, null, null, null); + return new CreateTokenRequest("client_credentials", null, null, null, null, null); + } + + public static CreateTokenRequest kerberosGrant(char[] kerberosTicket) { + if (kerberosTicket == null || kerberosTicket.length == 0) { + throw new IllegalArgumentException("kerberos ticket is required"); + } + return new CreateTokenRequest("_kerberos", null, null, null, null, kerberosTicket); } public String getGrantType() { @@ -103,6 +113,10 @@ public final class CreateTokenRequest implements Validatable, ToXContentObject { return refreshToken; } + public char[] getKerberosTicket() { + return kerberosTicket; + } + @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject() @@ -124,6 +138,14 @@ public final class CreateTokenRequest implements Validatable, ToXContentObject { if (refreshToken != null) { builder.field("refresh_token", refreshToken); } + if (kerberosTicket != null) { + byte[] kerberosTicketBytes = CharArrays.toUtf8Bytes(kerberosTicket); + try { + builder.field("kerberos_ticket").utf8Value(kerberosTicketBytes, 0, kerberosTicketBytes.length); + } finally { + Arrays.fill(kerberosTicketBytes, (byte) 0); + } + } return builder.endObject(); } @@ -140,13 +162,15 @@ public final class CreateTokenRequest implements Validatable, ToXContentObject { Objects.equals(scope, that.scope) && Objects.equals(username, that.username) && Arrays.equals(password, that.password) && - Objects.equals(refreshToken, that.refreshToken); + Objects.equals(refreshToken, that.refreshToken) && + Arrays.equals(kerberosTicket, that.kerberosTicket); } @Override public int hashCode() { int result = Objects.hash(grantType, scope, username, refreshToken); result = 31 * result + Arrays.hashCode(password); + result = 31 * result + Arrays.hashCode(kerberosTicket); return result; } } diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/security/CreateTokenRequestTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/security/CreateTokenRequestTests.java index 53f3e1d0f36..760d5e52cb3 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/security/CreateTokenRequestTests.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/security/CreateTokenRequestTests.java @@ -66,31 +66,54 @@ public class CreateTokenRequestTests extends ESTestCase { assertThat(Strings.toString(request), equalTo("{\"grant_type\":\"client_credentials\"}")); } + public void testCreateTokenFromKerberosTicket() { + final CreateTokenRequest request = CreateTokenRequest.kerberosGrant("top secret kerberos ticket".toCharArray()); + assertThat(request.getGrantType(), equalTo("_kerberos")); + assertThat(request.getScope(), nullValue()); + assertThat(request.getUsername(), nullValue()); + assertThat(request.getPassword(), nullValue()); + assertThat(request.getRefreshToken(), nullValue()); + assertThat(new String(request.getKerberosTicket()), equalTo("top secret kerberos ticket")); + assertThat(Strings.toString(request), equalTo("{\"grant_type\":\"_kerberos\"," + + "\"kerberos_ticket\":\"top secret kerberos ticket\"}")); + } + public void testEqualsAndHashCode() { final String grantType = randomAlphaOfLength(8); final String scope = randomBoolean() ? null : randomAlphaOfLength(6); final String username = randomBoolean() ? null : randomAlphaOfLengthBetween(4, 10); final char[] password = randomBoolean() ? null : randomAlphaOfLengthBetween(8, 12).toCharArray(); final String refreshToken = randomBoolean() ? null : randomAlphaOfLengthBetween(12, 24); - final CreateTokenRequest request = new CreateTokenRequest(grantType, scope, username, password, refreshToken); + final char[] kerberosTicket = randomBoolean() ? null : randomAlphaOfLengthBetween(8, 12).toCharArray(); + final CreateTokenRequest request = new CreateTokenRequest(grantType, scope, username, password, refreshToken, kerberosTicket); EqualsHashCodeTestUtils.checkEqualsAndHashCode(request, - r -> new CreateTokenRequest(r.getGrantType(), r.getScope(), r.getUsername(), r.getPassword(), r.getRefreshToken()), + r -> new CreateTokenRequest(r.getGrantType(), r.getScope(), r.getUsername(), r.getPassword(), + r.getRefreshToken(), r.getKerberosTicket()), this::mutate); } private CreateTokenRequest mutate(CreateTokenRequest req) { - switch (randomIntBetween(1, 5)) { - case 1: - return new CreateTokenRequest("g", req.getScope(), req.getUsername(), req.getPassword(), req.getRefreshToken()); - case 2: - return new CreateTokenRequest(req.getGrantType(), "s", req.getUsername(), req.getPassword(), req.getRefreshToken()); - case 3: - return new CreateTokenRequest(req.getGrantType(), req.getScope(), "u", req.getPassword(), req.getRefreshToken()); - case 4: - final char[] password = {'p'}; - return new CreateTokenRequest(req.getGrantType(), req.getScope(), req.getUsername(), password, req.getRefreshToken()); - case 5: - return new CreateTokenRequest(req.getGrantType(), req.getScope(), req.getUsername(), req.getPassword(), "r"); + switch (randomIntBetween(1, 6)) { + case 1: + return new CreateTokenRequest("g", req.getScope(), req.getUsername(), req.getPassword(), req.getRefreshToken(), + req.getKerberosTicket()); + case 2: + return new CreateTokenRequest(req.getGrantType(), "s", req.getUsername(), req.getPassword(), req.getRefreshToken(), + req.getKerberosTicket()); + case 3: + return new CreateTokenRequest(req.getGrantType(), req.getScope(), "u", req.getPassword(), req.getRefreshToken(), + req.getKerberosTicket()); + case 4: + final char[] password = { 'p' }; + return new CreateTokenRequest(req.getGrantType(), req.getScope(), req.getUsername(), password, req.getRefreshToken(), + req.getKerberosTicket()); + case 5: + final char[] kerberosTicket = { 'k' }; + return new CreateTokenRequest(req.getGrantType(), req.getScope(), req.getUsername(), req.getPassword(), req.getRefreshToken(), + kerberosTicket); + case 6: + return new CreateTokenRequest(req.getGrantType(), req.getScope(), req.getUsername(), req.getPassword(), "r", + req.getKerberosTicket()); } throw new IllegalStateException("Bad random number"); } diff --git a/server/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java b/server/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java index 7a763c5a049..2e213cccf13 100644 --- a/server/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java +++ b/server/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java @@ -30,11 +30,13 @@ import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.CharsRef; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.Version; +import org.elasticsearch.common.CharArrays; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.Strings; import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.geo.GeoPoint; +import org.elasticsearch.common.settings.SecureString; import org.elasticsearch.common.text.Text; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.util.concurrent.EsRejectedExecutionException; @@ -59,6 +61,7 @@ import java.time.Instant; import java.time.ZoneId; import java.time.ZonedDateTime; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.Date; @@ -358,6 +361,21 @@ public abstract class StreamInput extends InputStream { return null; } + @Nullable + public SecureString readOptionalSecureString() throws IOException { + SecureString value = null; + BytesReference bytesRef = readOptionalBytesReference(); + if (bytesRef != null) { + byte[] bytes = BytesReference.toBytes(bytesRef); + try { + value = new SecureString(CharArrays.utf8BytesToChars(bytes)); + } finally { + Arrays.fill(bytes, (byte) 0); + } + } + return value; + } + @Nullable public Float readOptionalFloat() throws IOException { if (readBoolean()) { @@ -415,6 +433,16 @@ public abstract class StreamInput extends InputStream { return spare.toString(); } + public SecureString readSecureString() throws IOException { + BytesReference bytesRef = readBytesReference(); + byte[] bytes = BytesReference.toBytes(bytesRef); + try { + return new SecureString(CharArrays.utf8BytesToChars(bytes)); + } finally { + Arrays.fill(bytes, (byte) 0); + } + } + public final float readFloat() throws IOException { return Float.intBitsToFloat(readInt()); } diff --git a/server/src/main/java/org/elasticsearch/common/io/stream/StreamOutput.java b/server/src/main/java/org/elasticsearch/common/io/stream/StreamOutput.java index 1c9dfd7ea44..702cf3313d7 100644 --- a/server/src/main/java/org/elasticsearch/common/io/stream/StreamOutput.java +++ b/server/src/main/java/org/elasticsearch/common/io/stream/StreamOutput.java @@ -32,10 +32,13 @@ import org.elasticsearch.ElasticsearchException; import org.elasticsearch.Version; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.metadata.MetaData; +import org.elasticsearch.common.CharArrays; import org.elasticsearch.common.Nullable; +import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.geo.GeoPoint; import org.elasticsearch.common.io.stream.Writeable.Writer; +import org.elasticsearch.common.settings.SecureString; import org.elasticsearch.common.text.Text; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.util.concurrent.EsRejectedExecutionException; @@ -58,6 +61,7 @@ import java.nio.file.NotDirectoryException; import java.time.ZoneId; import java.time.Instant; import java.time.ZonedDateTime; +import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.Date; @@ -324,6 +328,19 @@ public abstract class StreamOutput extends OutputStream { } } + public void writeOptionalSecureString(@Nullable SecureString secureStr) throws IOException { + if (secureStr == null) { + writeOptionalBytesReference(null); + } else { + final byte[] secureStrBytes = CharArrays.toUtf8Bytes(secureStr.getChars()); + try { + writeOptionalBytesReference(new BytesArray(secureStrBytes)); + } finally { + Arrays.fill(secureStrBytes, (byte) 0); + } + } + } + /** * Writes an optional {@link Integer}. */ @@ -414,6 +431,15 @@ public abstract class StreamOutput extends OutputStream { writeBytes(buffer, offset); } + public void writeSecureString(SecureString secureStr) throws IOException { + final byte[] secureStrBytes = CharArrays.toUtf8Bytes(secureStr.getChars()); + try { + writeBytesReference(new BytesArray(secureStrBytes)); + } finally { + Arrays.fill(secureStrBytes, (byte) 0); + } + } + public void writeFloat(float v) throws IOException { writeInt(Float.floatToIntBits(v)); } diff --git a/server/src/test/java/org/elasticsearch/common/io/stream/StreamTests.java b/server/src/test/java/org/elasticsearch/common/io/stream/StreamTests.java index 837c0202faf..ce0bce03b03 100644 --- a/server/src/test/java/org/elasticsearch/common/io/stream/StreamTests.java +++ b/server/src/test/java/org/elasticsearch/common/io/stream/StreamTests.java @@ -25,6 +25,7 @@ import org.elasticsearch.common.CheckedFunction; import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.collect.Tuple; +import org.elasticsearch.common.settings.SecureString; import org.elasticsearch.test.ESTestCase; import java.io.ByteArrayInputStream; @@ -49,7 +50,9 @@ import java.util.stream.IntStream; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.hasToString; +import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.iterableWithSize; +import static org.hamcrest.Matchers.nullValue; public class StreamTests extends ESTestCase { @@ -405,4 +408,30 @@ public class StreamTests extends ESTestCase { } } + public void testSecureStringSerialization() throws IOException { + try (BytesStreamOutput output = new BytesStreamOutput()) { + final SecureString secureString = new SecureString("super secret".toCharArray()); + output.writeSecureString(secureString); + + final BytesReference bytesReference = output.bytes(); + final StreamInput input = bytesReference.streamInput(); + + assertThat(secureString, is(equalTo(input.readSecureString()))); + } + + try (BytesStreamOutput output = new BytesStreamOutput()) { + final SecureString secureString = randomBoolean() ? null : new SecureString("super secret".toCharArray()); + output.writeOptionalSecureString(secureString); + + final BytesReference bytesReference = output.bytes(); + final StreamInput input = bytesReference.streamInput(); + + if (secureString != null) { + assertThat(input.readOptionalSecureString(), is(equalTo(secureString))); + } else { + assertThat(input.readOptionalSecureString(), is(nullValue())); + } + } + } + } diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/token/CreateTokenRequest.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/token/CreateTokenRequest.java index fc671a833fa..85a518133ff 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/token/CreateTokenRequest.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/token/CreateTokenRequest.java @@ -8,17 +8,13 @@ package org.elasticsearch.xpack.core.security.action.token; import org.elasticsearch.Version; import org.elasticsearch.action.ActionRequest; import org.elasticsearch.action.ActionRequestValidationException; -import org.elasticsearch.common.CharArrays; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.Strings; -import org.elasticsearch.common.bytes.BytesArray; -import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.settings.SecureString; import java.io.IOException; -import java.util.Arrays; import java.util.Collections; import java.util.EnumSet; import java.util.Locale; @@ -214,32 +210,23 @@ public final class CreateTokenRequest extends ActionRequest { throw new IllegalArgumentException("a request with the client_credentials grant_type cannot be sent to version [" + out.getVersion() + "]"); } + if (out.getVersion().before(Version.V_7_3_0) && GrantType.KERBEROS.getValue().equals(grantType)) { + throw new IllegalArgumentException("a request with the _kerberos grant_type cannot be sent to version [" + + out.getVersion() + "]"); + } out.writeString(grantType); if (out.getVersion().onOrAfter(Version.V_6_2_0)) { out.writeOptionalString(username); - if (password == null) { - out.writeOptionalBytesReference(null); - } else { - final byte[] passwordBytes = CharArrays.toUtf8Bytes(password.getChars()); - try { - out.writeOptionalBytesReference(new BytesArray(passwordBytes)); - } finally { - Arrays.fill(passwordBytes, (byte) 0); - } - } + out.writeOptionalSecureString(password); out.writeOptionalString(refreshToken); + out.writeOptionalSecureString(kerberosTicket); } else { if ("refresh_token".equals(grantType)) { throw new IllegalArgumentException("a refresh request cannot be sent to an older version"); } else { out.writeString(username); - final byte[] passwordBytes = CharArrays.toUtf8Bytes(password.getChars()); - try { - out.writeByteArray(passwordBytes); - } finally { - Arrays.fill(passwordBytes, (byte) 0); - } + out.writeSecureString(password); } } out.writeOptionalString(scope); @@ -251,26 +238,12 @@ public final class CreateTokenRequest extends ActionRequest { grantType = in.readString(); if (in.getVersion().onOrAfter(Version.V_6_2_0)) { username = in.readOptionalString(); - BytesReference bytesRef = in.readOptionalBytesReference(); - if (bytesRef != null) { - byte[] bytes = BytesReference.toBytes(bytesRef); - try { - password = new SecureString(CharArrays.utf8BytesToChars(bytes)); - } finally { - Arrays.fill(bytes, (byte) 0); - } - } else { - password = null; - } + password = in.readOptionalSecureString(); refreshToken = in.readOptionalString(); + kerberosTicket = in.readOptionalSecureString(); } else { username = in.readString(); - final byte[] passwordBytes = in.readByteArray(); - try { - password = new SecureString(CharArrays.utf8BytesToChars(passwordBytes)); - } finally { - Arrays.fill(passwordBytes, (byte) 0); - } + password = in.readSecureString(); } scope = in.readOptionalString(); } diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/security/action/token/CreateTokenRequestTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/security/action/token/CreateTokenRequestTests.java index d5edbc8f1c3..54681e97fc5 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/security/action/token/CreateTokenRequestTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/security/action/token/CreateTokenRequestTests.java @@ -6,8 +6,15 @@ package org.elasticsearch.xpack.core.security.action.token; import org.elasticsearch.action.ActionRequestValidationException; +import org.elasticsearch.common.io.stream.BytesStreamOutput; +import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.settings.SecureString; import org.elasticsearch.test.ESTestCase; +import org.elasticsearch.xpack.core.security.action.token.CreateTokenRequest.GrantType; + +import java.io.IOException; +import java.util.Arrays; +import java.util.stream.Collectors; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.hasItem; @@ -106,4 +113,35 @@ public class CreateTokenRequestTests extends ESTestCase { ve = request.validate(); assertNull(ve); } + + public void testSerialization() throws IOException { + final String grantType = randomFrom(Arrays.stream(GrantType.values()).map(gt -> gt.getValue()).collect(Collectors.toList())); + final String username = randomBoolean() ? randomAlphaOfLength(5) : null; + final String scope = randomBoolean() ? randomAlphaOfLength(5) : null; + final SecureString password = randomBoolean() ? new SecureString(new char[] { 'p', 'a', 's', 's' }) : null; + final SecureString kerberosTicket = randomBoolean() ? new SecureString(new char[] { 'k', 'e', 'r', 'b' }) : null; + final String refreshToken = randomBoolean() ? randomAlphaOfLength(5) : null; + final CreateTokenRequest request = new CreateTokenRequest(grantType, username, password, kerberosTicket, scope, refreshToken); + + try (BytesStreamOutput out = new BytesStreamOutput()) { + request.writeTo(out); + try (StreamInput in = out.bytes().streamInput()) { + final CreateTokenRequest serialized = new CreateTokenRequest(); + serialized.readFrom(in); + assertEquals(grantType, serialized.getGrantType()); + if (scope != null) { + assertEquals(scope, serialized.getScope()); + } + if (password != null) { + assertEquals(password, serialized.getPassword()); + } + if (kerberosTicket != null) { + assertEquals(kerberosTicket, serialized.getKerberosTicket()); + } + if (refreshToken != null) { + assertEquals(refreshToken, serialized.getRefreshToken()); + } + } + } + } } From eb0c7196cb2b5c096c2bbaed0f602e1b2bf2f16f Mon Sep 17 00:00:00 2001 From: Alpar Torok Date: Mon, 1 Jul 2019 18:13:26 +0300 Subject: [PATCH 18/77] Disable Gradle running in parallel --- .ci/java-versions.properties | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.ci/java-versions.properties b/.ci/java-versions.properties index 9df8850c301..ac8682d9769 100644 --- a/.ci/java-versions.properties +++ b/.ci/java-versions.properties @@ -7,5 +7,4 @@ ES_BUILD_JAVA=openjdk12 ES_RUNTIME_JAVA=java8 GRADLE_TASK=build - - +GRADLE_EXTRA_ARGS=--no-parallel From fe3f9f0c6bca4be3e88370e652bff83e5daee687 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20B=C3=BCscher?= Date: Mon, 1 Jul 2019 16:25:40 +0200 Subject: [PATCH 19/77] Yet another `the the` cleanup (#43815) --- docs/reference/sql/functions/geo.asciidoc | 4 ++-- .../org/elasticsearch/action/bulk/TransportBulkAction.java | 2 +- .../cluster/snapshots/create/CreateSnapshotResponseTests.java | 2 +- .../cluster/snapshots/get/GetSnapshotsResponseTests.java | 2 +- .../org/elasticsearch/index/seqno/GlobalCheckpointSyncIT.java | 2 +- .../org/elasticsearch/xpack/ml/job/JobNodeSelectorTests.java | 2 +- .../xpack/security/authc/oidc/OpenIdConnectAuthenticator.java | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/reference/sql/functions/geo.asciidoc b/docs/reference/sql/functions/geo.asciidoc index 72f69af8552..fc9a85ce97e 100644 --- a/docs/reference/sql/functions/geo.asciidoc +++ b/docs/reference/sql/functions/geo.asciidoc @@ -147,7 +147,7 @@ ST_Y( .Description: -Returns the the latitude of the first point in the geometry. +Returns the latitude of the first point in the geometry. ["source","sql",subs="attributes,macros"] -------------------------------------------------- @@ -206,4 +206,4 @@ Returns the distance between geometries in meters. Both geometries have to be po ["source","sql",subs="attributes,macros"] -------------------------------------------------- include-tagged::{sql-specs}/docs/geo.csv-spec[distance] --------------------------------------------------- \ No newline at end of file +-------------------------------------------------- diff --git a/server/src/main/java/org/elasticsearch/action/bulk/TransportBulkAction.java b/server/src/main/java/org/elasticsearch/action/bulk/TransportBulkAction.java index eae84940766..e2ca6cb21bb 100644 --- a/server/src/main/java/org/elasticsearch/action/bulk/TransportBulkAction.java +++ b/server/src/main/java/org/elasticsearch/action/bulk/TransportBulkAction.java @@ -174,7 +174,7 @@ public class TransportBulkAction extends HandledTransportAction field.startsWith("snapshot.metadata"); } diff --git a/server/src/test/java/org/elasticsearch/action/admin/cluster/snapshots/get/GetSnapshotsResponseTests.java b/server/src/test/java/org/elasticsearch/action/admin/cluster/snapshots/get/GetSnapshotsResponseTests.java index 695bc4734dd..05d27757e10 100644 --- a/server/src/test/java/org/elasticsearch/action/admin/cluster/snapshots/get/GetSnapshotsResponseTests.java +++ b/server/src/test/java/org/elasticsearch/action/admin/cluster/snapshots/get/GetSnapshotsResponseTests.java @@ -68,7 +68,7 @@ public class GetSnapshotsResponseTests extends AbstractStreamableXContentTestCas // Don't inject random fields into the custom snapshot metadata, because the metadata map is equality-checked after doing a // round-trip through xContent serialization/deserialization. Even though the rest of the object ignores unknown fields, // `metadata` doesn't ignore unknown fields (it just includes them in the parsed object, because the keys are arbitrary), so any - // new fields added to the the metadata before it gets deserialized that weren't in the serialized version will cause the equality + // new fields added to the metadata before it gets deserialized that weren't in the serialized version will cause the equality // check to fail. // The actual fields are nested in an array, so this regex matches fields with names of the form `snapshots.3.metadata` diff --git a/server/src/test/java/org/elasticsearch/index/seqno/GlobalCheckpointSyncIT.java b/server/src/test/java/org/elasticsearch/index/seqno/GlobalCheckpointSyncIT.java index 31104166346..65dce061a3d 100644 --- a/server/src/test/java/org/elasticsearch/index/seqno/GlobalCheckpointSyncIT.java +++ b/server/src/test/java/org/elasticsearch/index/seqno/GlobalCheckpointSyncIT.java @@ -84,7 +84,7 @@ public class GlobalCheckpointSyncIT extends ESIntegTestCase { } public void testPostOperationGlobalCheckpointSync() throws Exception { - // set the sync interval high so it does not execute during this test. This only allows the the global checkpoint to catch up + // set the sync interval high so it does not execute during this test. This only allows the global checkpoint to catch up // on a post-operation background sync if translog durability is set to sync. Async durability relies on a scheduled global // checkpoint sync to allow the information about persisted local checkpoints to be transferred to the primary. runGlobalCheckpointSyncTest(TimeValue.timeValueHours(24), diff --git a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/JobNodeSelectorTests.java b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/JobNodeSelectorTests.java index f26dd3f81f6..ad69cbc9729 100644 --- a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/JobNodeSelectorTests.java +++ b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/JobNodeSelectorTests.java @@ -47,7 +47,7 @@ import static org.mockito.Mockito.when; // TODO: in 8.0.0 remove all instances of MAX_OPEN_JOBS_NODE_ATTR from this file public class JobNodeSelectorTests extends ESTestCase { - // To simplify the the logic in this class all jobs have the same memory requirement + // To simplify the logic in this class all jobs have the same memory requirement private static final ByteSizeValue JOB_MEMORY_REQUIREMENT = new ByteSizeValue(10, ByteSizeUnit.MB); private MlMemoryTracker memoryTracker; diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/oidc/OpenIdConnectAuthenticator.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/oidc/OpenIdConnectAuthenticator.java index 35a01d15dda..9994e30140e 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/oidc/OpenIdConnectAuthenticator.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/oidc/OpenIdConnectAuthenticator.java @@ -626,7 +626,7 @@ public class OpenIdConnectAuthenticator { * necessary as some OPs return slightly different values for some claims (i.e. Google for the profile picture) and * {@link JSONObject#merge(Object)} would throw a runtime exception. The merging is performed based on the following rules: *