All Downloads are FREE. Search and download functionalities are using the official Maven repository.
Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
org.elasticsearch.xpack.core.action.GetDataStreamAction Maven / Gradle / Ivy
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
package org.elasticsearch.xpack.core.action;
import org.elasticsearch.action.ActionRequestValidationException;
import org.elasticsearch.action.ActionResponse;
import org.elasticsearch.action.ActionType;
import org.elasticsearch.action.IndicesRequest;
import org.elasticsearch.action.support.IndicesOptions;
import org.elasticsearch.action.support.master.MasterNodeReadRequest;
import org.elasticsearch.cluster.AbstractDiffable;
import org.elasticsearch.cluster.health.ClusterHealthStatus;
import org.elasticsearch.cluster.metadata.DataStream;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.xcontent.ToXContentObject;
import org.elasticsearch.common.xcontent.XContentBuilder;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
public class GetDataStreamAction extends ActionType {
public static final GetDataStreamAction INSTANCE = new GetDataStreamAction();
public static final String NAME = "indices:admin/data_stream/get";
private GetDataStreamAction() {
super(NAME, Response::new);
}
public static class Request extends MasterNodeReadRequest implements IndicesRequest.Replaceable {
private String[] names;
private IndicesOptions indicesOptions = IndicesOptions.fromOptions(false, true, true, true, false, false, true, false);
public Request(String[] names) {
this.names = names;
}
public String[] getNames() {
return names;
}
@Override
public ActionRequestValidationException validate() {
return null;
}
public Request(StreamInput in) throws IOException {
super(in);
this.names = in.readOptionalStringArray();
if (in.getVersion().onOrAfter(DataStream.NEW_FEATURES_VERSION)) {
this.indicesOptions = IndicesOptions.readIndicesOptions(in);
}
}
@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeOptionalStringArray(names);
if (out.getVersion().onOrAfter(DataStream.NEW_FEATURES_VERSION)) {
indicesOptions.writeIndicesOptions(out);
}
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Request request = (Request) o;
return Arrays.equals(names, request.names) &&
indicesOptions.equals(request.indicesOptions);
}
@Override
public int hashCode() {
int result = Objects.hash(indicesOptions);
result = 31 * result + Arrays.hashCode(names);
return result;
}
@Override
public String[] indices() {
return names;
}
@Override
public IndicesOptions indicesOptions() {
return indicesOptions;
}
public Request indicesOptions(IndicesOptions indicesOptions){
this.indicesOptions = indicesOptions;
return this;
}
@Override
public boolean includeDataStreams() {
return true;
}
@Override
public IndicesRequest indices(String... indices) {
this.names = indices;
return this;
}
}
public static class Response extends ActionResponse implements ToXContentObject {
public static final ParseField DATASTREAMS_FIELD = new ParseField("data_streams");
public static class DataStreamInfo extends AbstractDiffable implements ToXContentObject {
public static final ParseField STATUS_FIELD = new ParseField("status");
public static final ParseField INDEX_TEMPLATE_FIELD = new ParseField("template");
public static final ParseField ILM_POLICY_FIELD = new ParseField("ilm_policy");
public static final ParseField HIDDEN_FIELD = new ParseField("hidden");
DataStream dataStream;
ClusterHealthStatus dataStreamStatus;
@Nullable String indexTemplate;
@Nullable String ilmPolicyName;
public DataStreamInfo(DataStream dataStream, ClusterHealthStatus dataStreamStatus, @Nullable String indexTemplate,
@Nullable String ilmPolicyName) {
this.dataStream = dataStream;
this.dataStreamStatus = dataStreamStatus;
this.indexTemplate = indexTemplate;
this.ilmPolicyName = ilmPolicyName;
}
public DataStreamInfo(StreamInput in) throws IOException {
this(new DataStream(in), ClusterHealthStatus.readFrom(in), in.readOptionalString(), in.readOptionalString());
}
public DataStream getDataStream() {
return dataStream;
}
public ClusterHealthStatus getDataStreamStatus() {
return dataStreamStatus;
}
@Nullable
public String getIndexTemplate() {
return indexTemplate;
}
@Nullable
public String getIlmPolicy() {
return ilmPolicyName;
}
@Override
public void writeTo(StreamOutput out) throws IOException {
dataStream.writeTo(out);
dataStreamStatus.writeTo(out);
out.writeOptionalString(indexTemplate);
out.writeOptionalString(ilmPolicyName);
}
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject();
builder.field(DataStream.NAME_FIELD.getPreferredName(), dataStream.getName());
builder.field(DataStream.TIMESTAMP_FIELD_FIELD.getPreferredName(), dataStream.getTimeStampField());
builder.field(DataStream.INDICES_FIELD.getPreferredName(), dataStream.getIndices());
builder.field(DataStream.GENERATION_FIELD.getPreferredName(), dataStream.getGeneration());
if (dataStream.getMetadata() != null) {
builder.field(DataStream.METADATA_FIELD.getPreferredName(), dataStream.getMetadata());
}
builder.field(STATUS_FIELD.getPreferredName(), dataStreamStatus);
if (indexTemplate != null) {
builder.field(INDEX_TEMPLATE_FIELD.getPreferredName(), indexTemplate);
}
if (ilmPolicyName != null) {
builder.field(ILM_POLICY_FIELD.getPreferredName(), ilmPolicyName);
}
builder.field(HIDDEN_FIELD.getPreferredName(), dataStream.isHidden());
builder.endObject();
return builder;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
DataStreamInfo that = (DataStreamInfo) o;
return dataStream.equals(that.dataStream) &&
dataStreamStatus == that.dataStreamStatus &&
Objects.equals(indexTemplate, that.indexTemplate) &&
Objects.equals(ilmPolicyName, that.ilmPolicyName);
}
@Override
public int hashCode() {
return Objects.hash(dataStream, dataStreamStatus, indexTemplate, ilmPolicyName);
}
}
private final List dataStreams;
public Response(List dataStreams) {
this.dataStreams = dataStreams;
}
public Response(StreamInput in) throws IOException {
this(in.readList(DataStreamInfo::new));
}
public List getDataStreams() {
return dataStreams;
}
@Override
public void writeTo(StreamOutput out) throws IOException {
out.writeList(dataStreams);
}
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject();
builder.startArray(DATASTREAMS_FIELD.getPreferredName());
for (DataStreamInfo dataStream : dataStreams) {
dataStream.toXContent(builder, params);
}
builder.endArray();
builder.endObject();
return builder;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Response response = (Response) o;
return dataStreams.equals(response.dataStreams);
}
@Override
public int hashCode() {
return Objects.hash(dataStreams);
}
}
}