[ML] Removing usages of ToXContentParams.INCLUDE_TYPE (#48165)

Removing the option of ToXContentParams.INCLUDE_TYPE and replacing them with ToXContentParams.FOR_INTERNAL_STORAGE
Closes #48057
This commit is contained in:
rsarawgi 2019-10-18 06:38:34 -07:00 committed by David Roberts
parent 6a97aef8ac
commit 5e4dd0fd2e
13 changed files with 18 additions and 36 deletions

View File

@ -111,7 +111,7 @@ public class Calendar implements ToXContentObject, Writeable {
if (description != null) {
builder.field(DESCRIPTION.getPreferredName(), description);
}
if (params.paramAsBoolean(ToXContentParams.INCLUDE_TYPE, false)) {
if (params.paramAsBoolean(ToXContentParams.FOR_INTERNAL_STORAGE, false)) {
builder.field(TYPE.getPreferredName(), CALENDAR_TYPE);
}
builder.endObject();

View File

@ -167,7 +167,7 @@ public class ScheduledEvent implements ToXContentObject, Writeable {
if (eventId != null) {
builder.field(EVENT_ID.getPreferredName(), eventId);
}
if (params.paramAsBoolean(ToXContentParams.INCLUDE_TYPE, false)) {
if (params.paramAsBoolean(ToXContentParams.FOR_INTERNAL_STORAGE, false)) {
builder.field(TYPE.getPreferredName(), SCHEDULED_EVENT_TYPE);
}
builder.endObject();

View File

@ -462,7 +462,7 @@ public class DatafeedConfig extends AbstractDiffable<DatafeedConfig> implements
builder.startObject();
builder.field(ID.getPreferredName(), id);
builder.field(Job.ID.getPreferredName(), jobId);
if (params.paramAsBoolean(ToXContentParams.INCLUDE_TYPE, false) == true) {
if (params.paramAsBoolean(ToXContentParams.FOR_INTERNAL_STORAGE, false) == true) {
builder.field(CONFIG_TYPE.getPreferredName(), TYPE);
}
builder.field(QUERY_DELAY.getPreferredName(), queryDelay.getStringRep());

View File

@ -228,7 +228,7 @@ public class DataFrameAnalyticsConfig implements ToXContentObject, Writeable {
builder.field(analysis.getWriteableName(), analysis);
builder.endObject();
if (params.paramAsBoolean(ToXContentParams.INCLUDE_TYPE, false)) {
if (params.paramAsBoolean(ToXContentParams.FOR_INTERNAL_STORAGE, false)) {
builder.field(CONFIG_TYPE.getPreferredName(), TYPE);
}
if (analyzedFields != null) {

View File

@ -101,7 +101,7 @@ public class MlFilter implements ToXContentObject, Writeable {
builder.field(DESCRIPTION.getPreferredName(), description);
}
builder.field(ITEMS.getPreferredName(), items);
if (params.paramAsBoolean(ToXContentParams.INCLUDE_TYPE, false)) {
if (params.paramAsBoolean(ToXContentParams.FOR_INTERNAL_STORAGE, false)) {
builder.field(TYPE.getPreferredName(), FILTER_TYPE);
}
builder.endObject();
@ -201,4 +201,4 @@ public class MlFilter implements ToXContentObject, Writeable {
return new MlFilter(id, description, items);
}
}
}
}

View File

@ -18,12 +18,6 @@ public final class ToXContentParams {
*/
public static final String FOR_INTERNAL_STORAGE = "for_internal_storage";
/**
* When serialising POJOs to X Content this indicates whether the type field
* should be included or not
*/
public static final String INCLUDE_TYPE = "include_type";
/**
* When serialising POJOs to X Content this indicates whether the calculated (i.e. not stored) fields
* should be included or not

View File

@ -65,7 +65,7 @@ public class TransportPostCalendarEventsAction extends HandledTransportAction<Po
IndexRequest indexRequest = new IndexRequest(MlMetaIndex.INDEX_NAME);
try (XContentBuilder builder = XContentFactory.jsonBuilder()) {
indexRequest.source(event.toXContent(builder,
new ToXContent.MapParams(Collections.singletonMap(ToXContentParams.INCLUDE_TYPE,
new ToXContent.MapParams(Collections.singletonMap(ToXContentParams.FOR_INTERNAL_STORAGE,
"true"))));
} catch (IOException e) {
throw new IllegalStateException("Failed to serialise event", e);

View File

@ -50,7 +50,7 @@ public class TransportPutCalendarAction extends HandledTransportAction<PutCalend
IndexRequest indexRequest = new IndexRequest(MlMetaIndex.INDEX_NAME).id(calendar.documentId());
try (XContentBuilder builder = XContentFactory.jsonBuilder()) {
indexRequest.source(calendar.toXContent(builder,
new ToXContent.MapParams(Collections.singletonMap(ToXContentParams.INCLUDE_TYPE, "true"))));
new ToXContent.MapParams(Collections.singletonMap(ToXContentParams.FOR_INTERNAL_STORAGE, "true"))));
} catch (IOException e) {
throw new IllegalStateException("Failed to serialise calendar with id [" + calendar.getId() + "]", e);
}

View File

@ -51,7 +51,7 @@ public class TransportPutFilterAction extends HandledTransportAction<PutFilterAc
indexRequest.opType(DocWriteRequest.OpType.CREATE);
indexRequest.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE);
try (XContentBuilder builder = XContentFactory.jsonBuilder()) {
ToXContent.MapParams params = new ToXContent.MapParams(Collections.singletonMap(ToXContentParams.INCLUDE_TYPE, "true"));
ToXContent.MapParams params = new ToXContent.MapParams(Collections.singletonMap(ToXContentParams.FOR_INTERNAL_STORAGE, "true"));
indexRequest.source(filter.toXContent(builder, params));
} catch (IOException e) {
throw new IllegalStateException("Failed to serialise filter with id [" + filter.getId() + "]", e);

View File

@ -107,7 +107,7 @@ public class TransportUpdateFilterAction extends HandledTransportAction<UpdateFi
indexRequest.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE);
try (XContentBuilder builder = XContentFactory.jsonBuilder()) {
ToXContent.MapParams params = new ToXContent.MapParams(Collections.singletonMap(ToXContentParams.INCLUDE_TYPE, "true"));
ToXContent.MapParams params = new ToXContent.MapParams(Collections.singletonMap(ToXContentParams.FOR_INTERNAL_STORAGE, "true"));
indexRequest.source(filter.toXContent(builder, params));
} catch (IOException e) {
throw new IllegalStateException("Failed to serialise filter with id [" + filter.getId() + "]", e);

View File

@ -58,7 +58,6 @@ import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
@ -86,13 +85,7 @@ public class DatafeedConfigProvider {
private final Client client;
private final NamedXContentRegistry xContentRegistry;
public static final Map<String, String> TO_XCONTENT_PARAMS;
static {
Map<String, String> modifiable = new HashMap<>();
modifiable.put(ToXContentParams.FOR_INTERNAL_STORAGE, "true");
modifiable.put(ToXContentParams.INCLUDE_TYPE, "true");
TO_XCONTENT_PARAMS = Collections.unmodifiableMap(modifiable);
}
public static final Map<String, String> TO_XCONTENT_PARAMS = Collections.singletonMap(ToXContentParams.FOR_INTERNAL_STORAGE, "true");
public DatafeedConfigProvider(Client client, NamedXContentRegistry xContentRegistry) {
this.client = client;

View File

@ -42,7 +42,6 @@ import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
@ -59,14 +58,7 @@ public class DataFrameAnalyticsConfigProvider {
private static final int MAX_CONFIGS_SIZE = 10000;
private static final Map<String, String> TO_XCONTENT_PARAMS;
static {
Map<String, String> modifiable = new HashMap<>();
modifiable.put(ToXContentParams.INCLUDE_TYPE, "true");
modifiable.put(ToXContentParams.FOR_INTERNAL_STORAGE, "true");
TO_XCONTENT_PARAMS = Collections.unmodifiableMap(modifiable);
}
private static final Map<String, String> TO_XCONTENT_PARAMS = Collections.singletonMap(ToXContentParams.FOR_INTERNAL_STORAGE, "true");
private final Client client;
private final NamedXContentRegistry xContentRegistry;

View File

@ -563,7 +563,8 @@ public class JobResultsProviderIT extends MlSingleNodeTestCase {
for (ScheduledEvent event : events) {
IndexRequest indexRequest = new IndexRequest(MlMetaIndex.INDEX_NAME);
try (XContentBuilder builder = XContentFactory.jsonBuilder()) {
ToXContent.MapParams params = new ToXContent.MapParams(Collections.singletonMap(ToXContentParams.INCLUDE_TYPE, "true"));
ToXContent.MapParams params = new ToXContent.MapParams(Collections.singletonMap(
ToXContentParams.FOR_INTERNAL_STORAGE, "true"));
indexRequest.source(event.toXContent(builder, params));
bulkRequest.add(indexRequest);
}
@ -606,7 +607,8 @@ public class JobResultsProviderIT extends MlSingleNodeTestCase {
for (MlFilter filter : filters) {
IndexRequest indexRequest = new IndexRequest(MlMetaIndex.INDEX_NAME).id(filter.documentId());
try (XContentBuilder builder = XContentFactory.jsonBuilder()) {
ToXContent.MapParams params = new ToXContent.MapParams(Collections.singletonMap(ToXContentParams.INCLUDE_TYPE, "true"));
ToXContent.MapParams params = new ToXContent.MapParams(Collections.singletonMap(
ToXContentParams.FOR_INTERNAL_STORAGE, "true"));
indexRequest.source(filter.toXContent(builder, params));
bulkRequest.add(indexRequest);
}
@ -636,7 +638,8 @@ public class JobResultsProviderIT extends MlSingleNodeTestCase {
for (Calendar calendar: calendars) {
IndexRequest indexRequest = new IndexRequest(MlMetaIndex.INDEX_NAME).id(calendar.documentId());
try (XContentBuilder builder = XContentFactory.jsonBuilder()) {
ToXContent.MapParams params = new ToXContent.MapParams(Collections.singletonMap(ToXContentParams.INCLUDE_TYPE, "true"));
ToXContent.MapParams params = new ToXContent.MapParams(
Collections.singletonMap(ToXContentParams.FOR_INTERNAL_STORAGE, "true"));
indexRequest.source(calendar.toXContent(builder, params));
bulkRequest.add(indexRequest);
}