Skip to content

Commit

Permalink
Duplicate Protocol classes into Core
Browse files Browse the repository at this point in the history
This is needed as with recent changes to master (see #32952), protocol
is no longer accessible from core, so these classes need to be
duplicated in both places.
  • Loading branch information
gwbrown committed Aug 23, 2018
1 parent 191bd7c commit 650f12a
Show file tree
Hide file tree
Showing 39 changed files with 1,390 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -439,26 +439,29 @@ public List<NamedXContentRegistry.Entry> getNamedXContent() {
new NamedXContentRegistry.Entry(Task.Status.class, new ParseField(RollupJobStatus.NAME),
RollupJobStatus::fromXContent),
new NamedXContentRegistry.Entry(PersistentTaskState.class, new ParseField(RollupJobStatus.NAME),
RollupJobStatus::fromXContent),
RollupJobStatus::fromXContent)
// ILM
new NamedXContentRegistry.Entry(org.elasticsearch.protocol.xpack.indexlifecycle.LifecycleAction.class,
new ParseField(org.elasticsearch.protocol.xpack.indexlifecycle.AllocateAction.NAME),
org.elasticsearch.protocol.xpack.indexlifecycle.AllocateAction::parse),
new NamedXContentRegistry.Entry(org.elasticsearch.protocol.xpack.indexlifecycle.LifecycleAction.class,
new ParseField(org.elasticsearch.protocol.xpack.indexlifecycle.DeleteAction.NAME),
org.elasticsearch.protocol.xpack.indexlifecycle.DeleteAction::parse),
new NamedXContentRegistry.Entry(org.elasticsearch.protocol.xpack.indexlifecycle.LifecycleAction.class,
new ParseField(org.elasticsearch.protocol.xpack.indexlifecycle.ForceMergeAction.NAME),
org.elasticsearch.protocol.xpack.indexlifecycle.ForceMergeAction::parse),
new NamedXContentRegistry.Entry(org.elasticsearch.protocol.xpack.indexlifecycle.LifecycleAction.class,
new ParseField(org.elasticsearch.protocol.xpack.indexlifecycle.ReadOnlyAction.NAME),
org.elasticsearch.protocol.xpack.indexlifecycle.ReadOnlyAction::parse),
new NamedXContentRegistry.Entry(org.elasticsearch.protocol.xpack.indexlifecycle.LifecycleAction.class,
new ParseField(org.elasticsearch.protocol.xpack.indexlifecycle.RolloverAction.NAME),
org.elasticsearch.protocol.xpack.indexlifecycle.RolloverAction::parse),
new NamedXContentRegistry.Entry(org.elasticsearch.protocol.xpack.indexlifecycle.LifecycleAction.class,
new ParseField(org.elasticsearch.protocol.xpack.indexlifecycle.ShrinkAction.NAME),
org.elasticsearch.protocol.xpack.indexlifecycle.ShrinkAction::parse)
// TODO NORELEASE: These lines may not be necessary, and they cause errors if present
// as they are duplicated in IndexLifecycle.
// Leaving this for now in case they are necessary as we move forward with the HLRC.
// new NamedXContentRegistry.Entry(LifecycleAction.class,
// new ParseField(org.elasticsearch.xpack.core.indexlifecycle.AllocateAction.NAME),
// org.elasticsearch.xpack.core.indexlifecycle.AllocateAction::parse),
// new NamedXContentRegistry.Entry(org.elasticsearch.xpack.core.indexlifecycle.LifecycleAction.class,
// new ParseField(org.elasticsearch.xpack.core.indexlifecycle.DeleteAction.NAME),
// org.elasticsearch.xpack.core.indexlifecycle.DeleteAction::parse),
// new NamedXContentRegistry.Entry(org.elasticsearch.xpack.core.indexlifecycle.LifecycleAction.class,
// new ParseField(org.elasticsearch.xpack.core.indexlifecycle.ForceMergeAction.NAME),
// org.elasticsearch.xpack.core.indexlifecycle.ForceMergeAction::parse),
// new NamedXContentRegistry.Entry(org.elasticsearch.xpack.core.indexlifecycle.LifecycleAction.class,
// new ParseField(org.elasticsearch.xpack.core.indexlifecycle.ReadOnlyAction.NAME),
// org.elasticsearch.xpack.core.indexlifecycle.ReadOnlyAction::parse),
// new NamedXContentRegistry.Entry(org.elasticsearch.xpack.core.indexlifecycle.LifecycleAction.class,
// new ParseField(org.elasticsearch.xpack.core.indexlifecycle.RolloverAction.NAME),
// org.elasticsearch.xpack.core.indexlifecycle.RolloverAction::parse),
// new NamedXContentRegistry.Entry(org.elasticsearch.xpack.core.indexlifecycle.LifecycleAction.class,
// new ParseField(org.elasticsearch.xpack.core.indexlifecycle.ShrinkAction.NAME),
// org.elasticsearch.xpack.core.indexlifecycle.ShrinkAction::parse)
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* 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.indexlifecycle;

import org.elasticsearch.action.ActionRequestValidationException;
import org.elasticsearch.action.support.master.info.ClusterInfoRequest;
import org.elasticsearch.common.io.stream.StreamInput;

import java.io.IOException;
import java.util.Arrays;
import java.util.Objects;

/**
* The request object used by the Explain Lifecycle API.
*
* Multiple indices may be queried in the same request using the
* {@link #indices(String...)} method
*/
public class ExplainLifecycleRequest extends ClusterInfoRequest<ExplainLifecycleRequest> {

public ExplainLifecycleRequest() {
super();
}

public ExplainLifecycleRequest(StreamInput in) throws IOException {
super(in);
}

@Override
public ActionRequestValidationException validate() {
return null;
}

@Override
public int hashCode() {
return Objects.hash(Arrays.hashCode(indices()), indicesOptions());
}

@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (obj.getClass() != getClass()) {
return false;
}
ExplainLifecycleRequest other = (ExplainLifecycleRequest) obj;
return Objects.deepEquals(indices(), other.indices()) &&
Objects.equals(indicesOptions(), other.indicesOptions());
}

@Override
public String toString() {
return "ExplainLifecycleRequest [indices()=" + Arrays.toString(indices()) + ", indicesOptions()=" + indicesOptions() + "]";
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
/*
* 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.indexlifecycle;

import org.elasticsearch.action.ActionResponse;
import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
import org.elasticsearch.common.xcontent.ToXContentObject;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
* The response object returned by the Explain Lifecycle API.
*
* Since the API can be run over multiple indices the response provides a map of
* index to the explanation of the lifecycle status for that index.
*/
public class ExplainLifecycleResponse extends ActionResponse implements ToXContentObject {

public static final ParseField INDICES_FIELD = new ParseField("indices");

private Map<String, IndexLifecycleExplainResponse> indexResponses;

@SuppressWarnings("unchecked")
private static final ConstructingObjectParser<ExplainLifecycleResponse, Void> PARSER = new ConstructingObjectParser<>(
"explain_lifecycle_response", a -> new ExplainLifecycleResponse(((List<IndexLifecycleExplainResponse>) a[0]).stream()
.collect(Collectors.toMap(IndexLifecycleExplainResponse::getIndex, Function.identity()))));
static {
PARSER.declareNamedObjects(ConstructingObjectParser.constructorArg(), (p, c, n) -> IndexLifecycleExplainResponse.PARSER.apply(p, c),
INDICES_FIELD);
}

public static ExplainLifecycleResponse fromXContent(XContentParser parser) {
return PARSER.apply(parser, null);
}

public ExplainLifecycleResponse() {
}

public ExplainLifecycleResponse(Map<String, IndexLifecycleExplainResponse> indexResponses) {
this.indexResponses = indexResponses;
}

/**
* @return a map of the responses from each requested index. The maps key is
* the index name and the value is the
* {@link IndexLifecycleExplainResponse} describing the current
* lifecycle status of that index
*/
public Map<String, IndexLifecycleExplainResponse> getIndexResponses() {
return indexResponses;
}

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject();
builder.startObject(INDICES_FIELD.getPreferredName());
for (IndexLifecycleExplainResponse indexResponse : indexResponses.values()) {
builder.field(indexResponse.getIndex(), indexResponse);
}
builder.endObject();
builder.endObject();
return builder;
}

@Override
public void readFrom(StreamInput in) throws IOException {
int size = in.readVInt();
Map<String, IndexLifecycleExplainResponse> indexResponses = new HashMap<>(size);
for (int i = 0; i < size; i++) {
IndexLifecycleExplainResponse indexResponse = new IndexLifecycleExplainResponse(in);
indexResponses.put(indexResponse.getIndex(), indexResponse);
}
this.indexResponses = indexResponses;
}

@Override
public void writeTo(StreamOutput out) throws IOException {
out.writeVInt(indexResponses.size());
for (IndexLifecycleExplainResponse e : indexResponses.values()) {
e.writeTo(out);
}
}

@Override
public int hashCode() {
return Objects.hash(indexResponses);
}

@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (obj.getClass() != getClass()) {
return false;
}
ExplainLifecycleResponse other = (ExplainLifecycleResponse) obj;
return Objects.equals(indexResponses, other.indexResponses);
}

@Override
public String toString() {
return Strings.toString(this, true, true);
}

}
Loading

0 comments on commit 650f12a

Please sign in to comment.