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

Add start rollup job support to HL REST Client #34623

Merged
merged 11 commits into from
Oct 29, 2018
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,21 @@

package org.elasticsearch.client.rollup;

import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.ToXContentObject;
import org.elasticsearch.common.xcontent.XContentBuilder;

import java.io.IOException;
import java.util.Objects;
import java.util.function.Function;

import static org.elasticsearch.common.xcontent.ConstructingObjectParser.constructorArg;

public abstract class AcknowledgedResponse implements ToXContentObject {

protected static final String PARSE_FIELD_NAME = "acknowledged";
private final boolean acknowledged;

public AcknowledgedResponse(final boolean acknowledged) {
Expand All @@ -37,6 +44,12 @@ public boolean isAcknowledged() {
return acknowledged;
}

protected static <T> ConstructingObjectParser<T, Void> generateParser(String name, Function<Boolean, T> ctor, String parseField) {
ConstructingObjectParser<T, Void> p = new ConstructingObjectParser<>(name, true, args -> ctor.apply((boolean) args[0]));
p.declareBoolean(constructorArg(), new ParseField(parseField));
return p;
}

@Override
public boolean equals(Object o) {
if (this == o) {
Expand Down Expand Up @@ -67,5 +80,7 @@ public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params par
/**
* @return the field name this response uses to output the acknowledged flag
*/
protected abstract String getFieldName();
protected String getFieldName() {
return PARSE_FIELD_NAME;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,35 +19,21 @@

package org.elasticsearch.client.rollup;

import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
import org.elasticsearch.common.xcontent.XContentParser;

import java.io.IOException;

import static org.elasticsearch.common.xcontent.ConstructingObjectParser.constructorArg;

public class DeleteRollupJobResponse extends AcknowledgedResponse {

private static final String PARSE_FIELD_NAME = "acknowledged";

public DeleteRollupJobResponse(boolean acknowledged) {
super(acknowledged);
}

private static final ConstructingObjectParser<DeleteRollupJobResponse, Void> PARSER = AcknowledgedResponse
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

super bueno!

.generateParser("delete_rollup_job_response", DeleteRollupJobResponse::new, AcknowledgedResponse.PARSE_FIELD_NAME);

public static DeleteRollupJobResponse fromXContent(final XContentParser parser) throws IOException {
return PARSER.parse(parser, null);
}

private static final ConstructingObjectParser<DeleteRollupJobResponse, Void> PARSER
= new ConstructingObjectParser<>("delete_rollup_job_response", true,
args -> new DeleteRollupJobResponse((boolean) args[0]));
static {
PARSER.declareBoolean(constructorArg(), new ParseField(PARSE_FIELD_NAME));
}

@Override
protected String getFieldName() {
return PARSE_FIELD_NAME;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,34 +18,21 @@
*/
package org.elasticsearch.client.rollup;

import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
import org.elasticsearch.common.xcontent.XContentParser;

import java.io.IOException;

import static org.elasticsearch.common.xcontent.ConstructingObjectParser.constructorArg;

public class PutRollupJobResponse extends AcknowledgedResponse {

private static final String PARSE_FIELD_NAME = "acknowledged";

public PutRollupJobResponse(boolean acknowledged) {
super(acknowledged);
}

private static final ConstructingObjectParser<PutRollupJobResponse, Void> PARSER = AcknowledgedResponse
.generateParser("delete_rollup_job_response", PutRollupJobResponse::new, AcknowledgedResponse.PARSE_FIELD_NAME);

public static PutRollupJobResponse fromXContent(final XContentParser parser) throws IOException {
return PARSER.parse(parser, null);
}

private static final ConstructingObjectParser<PutRollupJobResponse, Void> PARSER
= new ConstructingObjectParser<>("put_rollup_job_response", true, args -> new PutRollupJobResponse((boolean) args[0]));
static {
PARSER.declareBoolean(constructorArg(), new ParseField(PARSE_FIELD_NAME));
}

@Override
protected String getFieldName() {
return PARSE_FIELD_NAME;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@

package org.elasticsearch.client.rollup;

import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
import org.elasticsearch.common.xcontent.XContentParser;

import java.io.IOException;

import static org.elasticsearch.common.xcontent.ConstructingObjectParser.constructorArg;

public class StartRollupJobResponse extends AcknowledgedResponse {

private static final String PARSE_FIELD_NAME = "started";

private static final ConstructingObjectParser<StartRollupJobResponse, Void> PARSER = AcknowledgedResponse
.generateParser("delete_rollup_job_response", StartRollupJobResponse::new, PARSE_FIELD_NAME);

public StartRollupJobResponse(boolean acknowledged) {
super(acknowledged);
}
Expand All @@ -39,13 +39,6 @@ public static StartRollupJobResponse fromXContent(final XContentParser parser) t
return PARSER.parse(parser, null);
}

private static final ConstructingObjectParser<StartRollupJobResponse, Void> PARSER
= new ConstructingObjectParser<>("start_rollup_job_response", true,
args -> new StartRollupJobResponse((boolean) args[0]));
static {
PARSER.declareBoolean(constructorArg(), new ParseField(PARSE_FIELD_NAME));
}

@Override
protected String getFieldName() {
return PARSE_FIELD_NAME;
Expand Down