Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ML] fixes xcontent serialization for ML scaling reason #66548

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
builder.startObject();
builder.field(WAITING_ANALYTICS_JOBS, waitingAnalyticsJobs);
builder.field(WAITING_ANOMALY_JOBS, waitingAnalyticsJobs);
builder.field(CONFIGURATION, passedConfiguration);
builder.startObject(CONFIGURATION).value(passedConfiguration).endObject();
if (largestWaitingAnalyticsJob != null) {
builder.field(LARGEST_WAITING_ANALYTICS_JOB, largestWaitingAnalyticsJob);
}
Expand All @@ -132,6 +132,11 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
return builder;
}

@Override
public boolean isFragment() {
return false;
}

static class Builder {
private List<String> waitingAnalyticsJobs = Collections.emptyList();
private List<String> waitingAnomalyJobs = Collections.emptyList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

package org.elasticsearch.xpack.ml.autoscaling;

import org.elasticsearch.common.Strings;
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.settings.Settings;
Expand All @@ -16,6 +17,13 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static org.elasticsearch.xpack.ml.autoscaling.MlScalingReason.CONFIGURATION;
import static org.elasticsearch.xpack.ml.autoscaling.MlScalingReason.CURRENT_CAPACITY;
import static org.elasticsearch.xpack.ml.autoscaling.MlScalingReason.REASON;
import static org.elasticsearch.xpack.ml.autoscaling.MlScalingReason.WAITING_ANALYTICS_JOBS;
import static org.elasticsearch.xpack.ml.autoscaling.MlScalingReason.WAITING_ANOMALY_JOBS;
import static org.hamcrest.Matchers.containsString;

public class MlScalingReasonTests extends AbstractWireSerializingTestCase<MlScalingReason> {

@Override
Expand Down Expand Up @@ -55,4 +63,13 @@ private static Settings randomConfiguration() {
return builder.build();
}

public void testToXContent() throws Exception {
MlScalingReason reason = createTestInstance();
String xcontentString = Strings.toString(reason);
assertThat(xcontentString, containsString(WAITING_ANALYTICS_JOBS));
assertThat(xcontentString, containsString(WAITING_ANOMALY_JOBS));
assertThat(xcontentString, containsString(CONFIGURATION));
assertThat(xcontentString, containsString(CURRENT_CAPACITY));
assertThat(xcontentString, containsString(REASON));
}
}