Skip to content

Commit

Permalink
[ML] Removing usages of ToXContentParams.INCLUDE_TYPE (#48165)
Browse files Browse the repository at this point in the history
Removing the option of ToXContentParams.INCLUDE_TYPE and replacing them with ToXContentParams.FOR_INTERNAL_STORAGE
Closes #48057
  • Loading branch information
rsarawgi authored and droberts195 committed Oct 18, 2019
1 parent 6a97aef commit 5e4dd0f
Show file tree
Hide file tree
Showing 13 changed files with 18 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
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();
Expand Down Expand Up @@ -201,4 +201,4 @@ public MlFilter build() {
return new MlFilter(id, description, items);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ protected void doExecute(Task task, PostCalendarEventsAction.Request request,
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ protected void doExecute(Task task, PutCalendarAction.Request request, ActionLis
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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ protected void doExecute(Task task, PutFilterAction.Request request, ActionListe
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ private void indexUpdatedFilter(MlFilter filter, final long seqNo, final long pr
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
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;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,8 @@ private void indexScheduledEvents(List<ScheduledEvent> events) throws IOExceptio
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);
}
Expand Down Expand Up @@ -606,7 +607,8 @@ private void indexFilters(List<MlFilter> filters) throws IOException {
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);
}
Expand Down Expand Up @@ -636,7 +638,8 @@ private void indexCalendars(List<Calendar> calendars) throws IOException {
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);
}
Expand Down

0 comments on commit 5e4dd0f

Please sign in to comment.