|
| 1 | +/* |
| 2 | + * Licensed to Elasticsearch under one or more contributor |
| 3 | + * license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright |
| 5 | + * ownership. Elasticsearch licenses this file to you under |
| 6 | + * the Apache License, Version 2.0 (the "License"); you may |
| 7 | + * not use this file except in compliance with the License. |
| 8 | + * You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | +package org.elasticsearch.action.admin.indices.datastream; |
| 20 | + |
| 21 | +import org.elasticsearch.action.ActionListener; |
| 22 | +import org.elasticsearch.action.ActionRequestValidationException; |
| 23 | +import org.elasticsearch.action.ActionType; |
| 24 | +import org.elasticsearch.action.support.ActionFilters; |
| 25 | +import org.elasticsearch.action.support.master.AcknowledgedResponse; |
| 26 | +import org.elasticsearch.action.support.master.MasterNodeRequest; |
| 27 | +import org.elasticsearch.action.support.master.TransportMasterNodeAction; |
| 28 | +import org.elasticsearch.cluster.ClusterState; |
| 29 | +import org.elasticsearch.cluster.block.ClusterBlockException; |
| 30 | +import org.elasticsearch.cluster.block.ClusterBlockLevel; |
| 31 | +import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; |
| 32 | +import org.elasticsearch.cluster.service.ClusterService; |
| 33 | +import org.elasticsearch.common.inject.Inject; |
| 34 | +import org.elasticsearch.common.io.stream.StreamInput; |
| 35 | +import org.elasticsearch.common.io.stream.StreamOutput; |
| 36 | +import org.elasticsearch.tasks.Task; |
| 37 | +import org.elasticsearch.threadpool.ThreadPool; |
| 38 | +import org.elasticsearch.transport.TransportService; |
| 39 | + |
| 40 | +import java.io.IOException; |
| 41 | +import java.util.Objects; |
| 42 | + |
| 43 | +public class CreateDataStreamAction extends ActionType<AcknowledgedResponse> { |
| 44 | + |
| 45 | + public static final CreateDataStreamAction INSTANCE = new CreateDataStreamAction(); |
| 46 | + public static final String NAME = "indices:admin/data_stream/create"; |
| 47 | + |
| 48 | + private CreateDataStreamAction() { |
| 49 | + super(NAME, AcknowledgedResponse::new); |
| 50 | + } |
| 51 | + |
| 52 | + public static class Request extends MasterNodeRequest<Request> { |
| 53 | + |
| 54 | + private final String name; |
| 55 | + private String timestampFieldName; |
| 56 | + |
| 57 | + public Request(String name) { |
| 58 | + this.name = name; |
| 59 | + } |
| 60 | + |
| 61 | + public void setTimestampFieldName(String timestampFieldName) { |
| 62 | + this.timestampFieldName = timestampFieldName; |
| 63 | + } |
| 64 | + |
| 65 | + @Override |
| 66 | + public ActionRequestValidationException validate() { |
| 67 | + return null; |
| 68 | + } |
| 69 | + |
| 70 | + public Request(StreamInput in) throws IOException { |
| 71 | + super(in); |
| 72 | + this.name = in.readString(); |
| 73 | + this.timestampFieldName = in.readString(); |
| 74 | + } |
| 75 | + |
| 76 | + @Override |
| 77 | + public void writeTo(StreamOutput out) throws IOException { |
| 78 | + super.writeTo(out); |
| 79 | + out.writeString(name); |
| 80 | + out.writeString(timestampFieldName); |
| 81 | + } |
| 82 | + |
| 83 | + @Override |
| 84 | + public boolean equals(Object o) { |
| 85 | + if (this == o) return true; |
| 86 | + if (o == null || getClass() != o.getClass()) return false; |
| 87 | + Request request = (Request) o; |
| 88 | + return name.equals(request.name) && |
| 89 | + timestampFieldName.equals(request.timestampFieldName); |
| 90 | + } |
| 91 | + |
| 92 | + @Override |
| 93 | + public int hashCode() { |
| 94 | + return Objects.hash(name, timestampFieldName); |
| 95 | + } |
| 96 | + } |
| 97 | + |
| 98 | + public static class TransportAction extends TransportMasterNodeAction<Request, AcknowledgedResponse> { |
| 99 | + |
| 100 | + @Inject |
| 101 | + public TransportAction(TransportService transportService, ClusterService clusterService, ThreadPool threadPool, |
| 102 | + ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver) { |
| 103 | + super(NAME, transportService, clusterService, threadPool, actionFilters, Request::new, indexNameExpressionResolver); |
| 104 | + } |
| 105 | + |
| 106 | + @Override |
| 107 | + protected String executor() { |
| 108 | + return ThreadPool.Names.SAME; |
| 109 | + } |
| 110 | + |
| 111 | + @Override |
| 112 | + protected AcknowledgedResponse read(StreamInput in) throws IOException { |
| 113 | + return new AcknowledgedResponse(in); |
| 114 | + } |
| 115 | + |
| 116 | + @Override |
| 117 | + protected void masterOperation(Task task, Request request, ClusterState state, |
| 118 | + ActionListener<AcknowledgedResponse> listener) throws Exception { |
| 119 | + listener.onResponse(new AcknowledgedResponse(true)); |
| 120 | + } |
| 121 | + |
| 122 | + @Override |
| 123 | + protected ClusterBlockException checkBlock(Request request, ClusterState state) { |
| 124 | + return state.blocks().globalBlockedException(ClusterBlockLevel.METADATA_WRITE); |
| 125 | + } |
| 126 | + } |
| 127 | + |
| 128 | +} |
0 commit comments