Skip to content

Commit

Permalink
[Transform] Replace transforms with transform, index constants (#47023)
Browse files Browse the repository at this point in the history
* rename transforms to transform in action names

* move index versioning to core and use constants

* fix indentation

* checkstyle

* checkstyle

* review comments
  • Loading branch information
Hendrik Muhs authored Sep 25, 2019
1 parent fd3dc4d commit 169ac92
Show file tree
Hide file tree
Showing 30 changed files with 190 additions and 150 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,8 @@
import org.elasticsearch.xpack.core.transform.TransformFeatureSetUsage;
import org.elasticsearch.xpack.core.transform.TransformField;
import org.elasticsearch.xpack.core.transform.action.DeleteTransformAction;
import org.elasticsearch.xpack.core.transform.action.GetTransformsAction;
import org.elasticsearch.xpack.core.transform.action.GetTransformsStatsAction;
import org.elasticsearch.xpack.core.transform.action.GetTransformAction;
import org.elasticsearch.xpack.core.transform.action.GetTransformStatsAction;
import org.elasticsearch.xpack.core.transform.action.PreviewTransformAction;
import org.elasticsearch.xpack.core.transform.action.PutTransformAction;
import org.elasticsearch.xpack.core.transform.action.StartTransformAction;
Expand Down Expand Up @@ -394,8 +394,8 @@ public List<ActionType<? extends ActionResponse>> getClientActions() {
StartTransformAction.INSTANCE,
StopTransformAction.INSTANCE,
DeleteTransformAction.INSTANCE,
GetTransformsAction.INSTANCE,
GetTransformsStatsAction.INSTANCE,
GetTransformAction.INSTANCE,
GetTransformStatsAction.INSTANCE,
PreviewTransformAction.INSTANCE
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@

import static org.elasticsearch.action.ValidateActions.addValidationError;

public class GetTransformsAction extends ActionType<GetTransformsAction.Response> {
public class GetTransformAction extends ActionType<GetTransformAction.Response> {

public static final GetTransformsAction INSTANCE = new GetTransformsAction();
public static final GetTransformAction INSTANCE = new GetTransformAction();
public static final String NAME = "cluster:monitor/data_frame/get";

private static final DeprecationLogger deprecationLogger = new DeprecationLogger(
LogManager.getLogger(GetTransformsAction.class));
LogManager.getLogger(GetTransformAction.class));

private GetTransformsAction() {
super(NAME, GetTransformsAction.Response::new);
private GetTransformAction() {
super(NAME, GetTransformAction.Response::new);
}

public static class Request extends AbstractGetResourcesRequest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@

import static org.elasticsearch.action.ValidateActions.addValidationError;

public class GetTransformsStatsAction extends ActionType<GetTransformsStatsAction.Response> {
public class GetTransformStatsAction extends ActionType<GetTransformStatsAction.Response> {

public static final GetTransformsStatsAction INSTANCE = new GetTransformsStatsAction();
public static final GetTransformStatsAction INSTANCE = new GetTransformStatsAction();
public static final String NAME = "cluster:monitor/data_frame/stats/get";
public GetTransformsStatsAction() {
super(NAME, GetTransformsStatsAction.Response::new);
public GetTransformStatsAction() {
super(NAME, GetTransformStatsAction.Response::new);
}

public static class Request extends BaseTasksRequest<Request> {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

package org.elasticsearch.xpack.core.transform.transforms.persistence;

public final class TransformInternalIndexConstants {

/* Constants for internal indexes of the transform plugin
* (defined in core to provide wider access)
*
* Increase the version number for every mapping change, see TransformInternalIndex for details
*
* Together with increasing the version number please keep the following in sync:
*
* - XPackRestTestConstants
* - yaml tests under x-pack/qa/
*
* (pro-tip: grep for the constant)
*/

// internal index
public static final String INDEX_VERSION = "2";
public static final String INDEX_PATTERN = ".data-frame-internal-";
public static final String LATEST_INDEX_VERSIONED_NAME = INDEX_PATTERN + INDEX_VERSION;
public static final String LATEST_INDEX_NAME = LATEST_INDEX_VERSIONED_NAME;
public static final String INDEX_NAME_PATTERN = INDEX_PATTERN + "*";

// audit index
public static final String AUDIT_TEMPLATE_VERSION = "1";
public static final String AUDIT_INDEX_PREFIX = ".data-frame-notifications-";
public static final String AUDIT_INDEX = AUDIT_INDEX_PREFIX + AUDIT_TEMPLATE_VERSION;

private TransformInternalIndexConstants() {
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,13 @@
import org.elasticsearch.xpack.core.security.user.SystemUser;
import org.elasticsearch.xpack.core.security.user.XPackUser;
import org.elasticsearch.xpack.core.transform.action.DeleteTransformAction;
import org.elasticsearch.xpack.core.transform.action.GetTransformsAction;
import org.elasticsearch.xpack.core.transform.action.GetTransformsStatsAction;
import org.elasticsearch.xpack.core.transform.action.GetTransformAction;
import org.elasticsearch.xpack.core.transform.action.GetTransformStatsAction;
import org.elasticsearch.xpack.core.transform.action.PreviewTransformAction;
import org.elasticsearch.xpack.core.transform.action.PutTransformAction;
import org.elasticsearch.xpack.core.transform.action.StartTransformAction;
import org.elasticsearch.xpack.core.transform.action.StopTransformAction;
import org.elasticsearch.xpack.core.transform.transforms.persistence.TransformInternalIndexConstants;
import org.elasticsearch.xpack.core.watcher.execution.TriggeredWatchStoreField;
import org.elasticsearch.xpack.core.watcher.history.HistoryStoreField;
import org.elasticsearch.xpack.core.watcher.transport.actions.ack.AckWatchAction;
Expand Down Expand Up @@ -1130,8 +1131,8 @@ public void testDataFrameTransformsAdminRole() {

Role role = Role.builder(roleDescriptor, null).build();
assertThat(role.cluster().check(DeleteTransformAction.NAME, request, authentication), is(true));
assertThat(role.cluster().check(GetTransformsAction.NAME, request, authentication), is(true));
assertThat(role.cluster().check(GetTransformsStatsAction.NAME, request, authentication), is(true));
assertThat(role.cluster().check(GetTransformAction.NAME, request, authentication), is(true));
assertThat(role.cluster().check(GetTransformStatsAction.NAME, request, authentication), is(true));
assertThat(role.cluster().check(PreviewTransformAction.NAME, request, authentication), is(true));
assertThat(role.cluster().check(PutTransformAction.NAME, request, authentication), is(true));
assertThat(role.cluster().check(StartTransformAction.NAME, request, authentication), is(true));
Expand All @@ -1140,9 +1141,9 @@ public void testDataFrameTransformsAdminRole() {

assertThat(role.runAs().check(randomAlphaOfLengthBetween(1, 30)), is(false));

assertOnlyReadAllowed(role, ".data-frame-notifications-1");
assertOnlyReadAllowed(role, TransformInternalIndexConstants.AUDIT_INDEX);
assertNoAccessAllowed(role, "foo");
assertNoAccessAllowed(role, ".data-frame-internal-1"); // internal use only
assertNoAccessAllowed(role, TransformInternalIndexConstants.LATEST_INDEX_NAME); // internal use only

assertNoAccessAllowed(role, RestrictedIndicesNames.RESTRICTED_NAMES);

Expand All @@ -1169,8 +1170,8 @@ public void testDataFrameTransformsUserRole() {

Role role = Role.builder(roleDescriptor, null).build();
assertThat(role.cluster().check(DeleteTransformAction.NAME, request, authentication), is(false));
assertThat(role.cluster().check(GetTransformsAction.NAME, request, authentication), is(true));
assertThat(role.cluster().check(GetTransformsStatsAction.NAME, request, authentication), is(true));
assertThat(role.cluster().check(GetTransformAction.NAME, request, authentication), is(true));
assertThat(role.cluster().check(GetTransformStatsAction.NAME, request, authentication), is(true));
assertThat(role.cluster().check(PreviewTransformAction.NAME, request, authentication), is(false));
assertThat(role.cluster().check(PutTransformAction.NAME, request, authentication), is(false));
assertThat(role.cluster().check(StartTransformAction.NAME, request, authentication), is(false));
Expand All @@ -1179,9 +1180,9 @@ public void testDataFrameTransformsUserRole() {

assertThat(role.runAs().check(randomAlphaOfLengthBetween(1, 30)), is(false));

assertOnlyReadAllowed(role, ".data-frame-notifications-1");
assertOnlyReadAllowed(role, TransformInternalIndexConstants.AUDIT_INDEX);
assertNoAccessAllowed(role, "foo");
assertNoAccessAllowed(role, ".data-frame-internal-1");
assertNoAccessAllowed(role, TransformInternalIndexConstants.LATEST_INDEX_NAME);

assertNoAccessAllowed(role, RestrictedIndicesNames.RESTRICTED_NAMES);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
import org.elasticsearch.cluster.metadata.MetaData;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.test.AbstractWireSerializingTestCase;
import org.elasticsearch.xpack.core.transform.action.GetTransformsAction.Request;
import org.elasticsearch.xpack.core.transform.action.GetTransformAction.Request;

public class GetTransformsActionRequestTests extends AbstractWireSerializingTestCase<Request> {
public class GetTransformActionRequestTests extends AbstractWireSerializingTestCase<Request> {

@Override
protected Request createTestInstance() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.common.xcontent.support.XContentMapValues;
import org.elasticsearch.xpack.core.transform.action.GetTransformsAction.Response;
import org.elasticsearch.xpack.core.transform.action.GetTransformAction.Response;
import org.elasticsearch.xpack.core.transform.transforms.TransformConfig;
import org.elasticsearch.xpack.core.transform.transforms.TransformConfigTests;
import org.elasticsearch.xpack.core.watcher.watch.Payload.XContent;
Expand All @@ -22,7 +22,7 @@
import java.util.List;
import java.util.Map;

public class GetTransformsActionResponseTests extends AbstractWireSerializingTransformTestCase<Response> {
public class GetTransformActionResponseTests extends AbstractWireSerializingTransformTestCase<Response> {

public void testInvalidTransforms() throws IOException {
List<TransformConfig> transforms = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
import org.elasticsearch.cluster.metadata.MetaData;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.test.AbstractWireSerializingTestCase;
import org.elasticsearch.xpack.core.transform.action.GetTransformsStatsAction.Request;
import org.elasticsearch.xpack.core.transform.action.GetTransformStatsAction.Request;

public class GetTransformsStatsActionRequestTests extends AbstractWireSerializingTestCase<Request> {
public class GetTransformStatsActionRequestTests extends AbstractWireSerializingTestCase<Request> {
@Override
protected Request createTestInstance() {
if (randomBoolean()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
import org.elasticsearch.action.FailedNodeException;
import org.elasticsearch.action.TaskOperationFailure;
import org.elasticsearch.common.io.stream.Writeable.Reader;
import org.elasticsearch.xpack.core.transform.action.GetTransformsStatsAction.Response;
import org.elasticsearch.xpack.core.transform.action.GetTransformStatsAction.Response;
import org.elasticsearch.xpack.core.transform.transforms.TransformStats;
import org.elasticsearch.xpack.core.transform.transforms.TransformStatsTests;

import java.util.ArrayList;
import java.util.List;

public class GetTransformsStatsActionResponseTests extends AbstractWireSerializingTransformTestCase<Response> {
public class GetTransformStatsActionResponseTests extends AbstractWireSerializingTransformTestCase<Response> {
@Override
protected Response createTestInstance() {
List<TransformStats> stats = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
package org.elasticsearch.xpack.transform.integration;

import org.elasticsearch.client.Request;
import org.elasticsearch.xpack.transform.persistence.TransformInternalIndex;
import org.elasticsearch.xpack.core.transform.transforms.persistence.TransformInternalIndexConstants;
import org.junit.Before;

import java.io.IOException;
Expand Down Expand Up @@ -63,15 +63,15 @@ public void testAuditorWritesAudits() throws Exception {
startAndWaitForTransform(transformId, transformIndex, BASIC_AUTH_VALUE_TRANSFORM_ADMIN_WITH_SOME_DATA_ACCESS);

// Make sure we wrote to the audit
final Request request = new Request("GET", TransformInternalIndex.AUDIT_INDEX + "/_search");
final Request request = new Request("GET", TransformInternalIndexConstants.AUDIT_INDEX + "/_search");
request.setJsonEntity("{\"query\":{\"term\":{\"transform_id\":\"simple_pivot_for_audit\"}}}");
assertBusy(() -> {
assertTrue(indexExists(TransformInternalIndex.AUDIT_INDEX));
assertTrue(indexExists(TransformInternalIndexConstants.AUDIT_INDEX));
});
// Since calls to write the AbstractAuditor are sent and forgot (async) we could have returned from the start,
// finished the job (as this is a very short DF job), all without the audit being fully written.
assertBusy(() -> {
refreshIndex(TransformInternalIndex.AUDIT_INDEX);
refreshIndex(TransformInternalIndexConstants.AUDIT_INDEX);
Map<String, Object> response = entityAsMap(client().performRequest(request));
List<?> hitList = ((List<?>) ((Map<?, ?>)response.get("hits")).get("hits"));
assertThat(hitList, is(not(empty())));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import org.elasticsearch.common.xcontent.support.XContentMapValues;
import org.elasticsearch.xpack.core.transform.TransformField;
import org.elasticsearch.xpack.core.transform.transforms.TransformConfig;
import org.elasticsearch.xpack.transform.persistence.TransformInternalIndex;
import org.elasticsearch.xpack.core.transform.transforms.persistence.TransformInternalIndexConstants;

import java.io.IOException;

Expand All @@ -42,13 +42,13 @@ public void testDeleteConfigurationLeftOver() throws IOException {
builder.endObject();
final StringEntity entity = new StringEntity(Strings.toString(builder), ContentType.APPLICATION_JSON);
Request req = new Request("PUT",
TransformInternalIndex.LATEST_INDEX_NAME + "/_doc/" + TransformConfig.documentId(fakeTransformName));
TransformInternalIndexConstants.LATEST_INDEX_NAME + "/_doc/" + TransformConfig.documentId(fakeTransformName));
req.setEntity(entity);
client().performRequest(req);
}

// refresh the index
assertOK(client().performRequest(new Request("POST", TransformInternalIndex.LATEST_INDEX_NAME + "/_refresh")));
assertOK(client().performRequest(new Request("POST", TransformInternalIndexConstants.LATEST_INDEX_NAME + "/_refresh")));

Request deleteRequest = new Request("DELETE", TRANSFORM_ENDPOINT + fakeTransformName);
Response deleteResponse = client().performRequest(deleteRequest);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import org.elasticsearch.search.SearchModule;
import org.elasticsearch.xpack.core.transform.TransformField;
import org.elasticsearch.xpack.core.transform.transforms.TransformConfig;
import org.elasticsearch.xpack.transform.persistence.TransformInternalIndex;
import org.elasticsearch.xpack.core.transform.transforms.persistence.TransformInternalIndexConstants;
import org.elasticsearch.client.indices.CreateIndexRequest;
import org.elasticsearch.client.transform.GetTransformRequest;
import org.elasticsearch.client.transform.GetTransformResponse;
Expand All @@ -42,8 +42,8 @@
public class TransformInternalIndexIT extends ESRestTestCase {


private static final String CURRENT_INDEX = TransformInternalIndex.LATEST_INDEX_NAME;
private static final String OLD_INDEX = TransformInternalIndex.INDEX_PATTERN + "1";
private static final String CURRENT_INDEX = TransformInternalIndexConstants.LATEST_INDEX_NAME;
private static final String OLD_INDEX = TransformInternalIndexConstants.INDEX_PATTERN + "1";


public void testUpdateDeletesOldTransformConfig() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import org.elasticsearch.common.xcontent.support.XContentMapValues;
import org.elasticsearch.test.rest.ESRestTestCase;
import org.elasticsearch.xpack.core.transform.TransformField;
import org.elasticsearch.xpack.transform.persistence.TransformInternalIndex;
import org.elasticsearch.xpack.core.transform.transforms.persistence.TransformInternalIndexConstants;
import org.junit.After;
import org.junit.AfterClass;

Expand Down Expand Up @@ -384,7 +384,7 @@ public void wipeTransforms() throws IOException {
assertTrue(transformConfigs.isEmpty());

// the configuration index should be empty
Request request = new Request("GET", TransformInternalIndex.LATEST_INDEX_NAME + "/_search");
Request request = new Request("GET", TransformInternalIndexConstants.LATEST_INDEX_NAME + "/_search");
try {
Response searchResponse = adminClient().performRequest(request);
Map<String, Object> searchResult = entityAsMap(searchResponse);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import org.elasticsearch.common.xcontent.support.XContentMapValues;
import org.elasticsearch.xpack.core.transform.transforms.TransformIndexerStats;
import org.elasticsearch.xpack.core.transform.transforms.TransformStoredDoc;
import org.elasticsearch.xpack.transform.persistence.TransformInternalIndex;
import org.elasticsearch.xpack.core.transform.transforms.persistence.TransformInternalIndexConstants;
import org.junit.Before;

import java.io.IOException;
Expand Down Expand Up @@ -53,7 +53,7 @@ public void testUsage() throws Exception {
stopTransform("test_usage", false);

Request statsExistsRequest = new Request("GET",
TransformInternalIndex.LATEST_INDEX_NAME+"/_search?q=" +
TransformInternalIndexConstants.LATEST_INDEX_NAME+"/_search?q=" +
INDEX_DOC_TYPE.getPreferredName() + ":" +
TransformStoredDoc.NAME);
// Verify that we have one stat document
Expand Down Expand Up @@ -95,7 +95,7 @@ public void testUsage() throws Exception {
XContentMapValues.extractValue("transform.stats." + statName, statsMap));
}
// Refresh the index so that statistics are searchable
refreshIndex(TransformInternalIndex.LATEST_INDEX_VERSIONED_NAME);
refreshIndex(TransformInternalIndexConstants.LATEST_INDEX_VERSIONED_NAME);
}, 60, TimeUnit.SECONDS);


Expand Down
Loading

0 comments on commit 169ac92

Please sign in to comment.