forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
184 changed files
with
4,736 additions
and
1,511 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
...ava/org/elasticsearch/action/admin/cluster/allocation/ClusterAllocationExplainAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.elasticsearch.action.admin.cluster.allocation; | ||
|
||
import org.elasticsearch.action.Action; | ||
import org.elasticsearch.client.ElasticsearchClient; | ||
|
||
/** | ||
* Action for explaining shard allocation for a shard in the cluster | ||
*/ | ||
public class ClusterAllocationExplainAction extends Action<ClusterAllocationExplainRequest, | ||
ClusterAllocationExplainResponse, | ||
ClusterAllocationExplainRequestBuilder> { | ||
|
||
public static final ClusterAllocationExplainAction INSTANCE = new ClusterAllocationExplainAction(); | ||
public static final String NAME = "cluster:monitor/allocation/explain"; | ||
|
||
private ClusterAllocationExplainAction() { | ||
super(NAME); | ||
} | ||
|
||
@Override | ||
public ClusterAllocationExplainResponse newResponse() { | ||
return new ClusterAllocationExplainResponse(); | ||
} | ||
|
||
@Override | ||
public ClusterAllocationExplainRequestBuilder newRequestBuilder(ElasticsearchClient client) { | ||
return new ClusterAllocationExplainRequestBuilder(client, this); | ||
} | ||
} |
195 changes: 195 additions & 0 deletions
195
...va/org/elasticsearch/action/admin/cluster/allocation/ClusterAllocationExplainRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,195 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.elasticsearch.action.admin.cluster.allocation; | ||
|
||
import org.elasticsearch.ElasticsearchParseException; | ||
import org.elasticsearch.action.ActionRequestValidationException; | ||
import org.elasticsearch.action.support.master.MasterNodeRequest; | ||
import org.elasticsearch.common.Nullable; | ||
import org.elasticsearch.common.Strings; | ||
import org.elasticsearch.common.io.stream.StreamInput; | ||
import org.elasticsearch.common.io.stream.StreamOutput; | ||
import org.elasticsearch.common.xcontent.XContentParser; | ||
|
||
import java.io.IOException; | ||
import java.util.Objects; | ||
|
||
import static org.elasticsearch.action.ValidateActions.addValidationError; | ||
|
||
/** | ||
* A request to explain the allocation of a shard in the cluster | ||
*/ | ||
public class ClusterAllocationExplainRequest extends MasterNodeRequest<ClusterAllocationExplainRequest> { | ||
|
||
private String index; | ||
private Integer shard; | ||
private Boolean primary; | ||
private boolean includeYesDecisions = false; | ||
|
||
/** Explain the first unassigned shard */ | ||
public ClusterAllocationExplainRequest() { | ||
this.index = null; | ||
this.shard = null; | ||
this.primary = null; | ||
} | ||
|
||
/** | ||
* Create a new allocation explain request. If {@code primary} is false, the first unassigned replica | ||
* will be picked for explanation. If no replicas are unassigned, the first assigned replica will | ||
* be explained. | ||
*/ | ||
public ClusterAllocationExplainRequest(String index, int shard, boolean primary) { | ||
this.index = index; | ||
this.shard = shard; | ||
this.primary = primary; | ||
} | ||
|
||
@Override | ||
public ActionRequestValidationException validate() { | ||
ActionRequestValidationException validationException = null; | ||
if (this.useAnyUnassignedShard() == false) { | ||
if (this.index == null) { | ||
validationException = addValidationError("index must be specified", validationException); | ||
} | ||
if (this.shard == null) { | ||
validationException = addValidationError("shard must be specified", validationException); | ||
} | ||
if (this.primary == null) { | ||
validationException = addValidationError("primary must be specified", validationException); | ||
} | ||
} | ||
return validationException; | ||
} | ||
|
||
/** | ||
* Returns {@code true} iff the first unassigned shard is to be used | ||
*/ | ||
public boolean useAnyUnassignedShard() { | ||
return this.index == null && this.shard == null && this.primary == null; | ||
} | ||
|
||
public ClusterAllocationExplainRequest setIndex(String index) { | ||
this.index = index; | ||
return this; | ||
} | ||
|
||
@Nullable | ||
public String getIndex() { | ||
return this.index; | ||
} | ||
|
||
public ClusterAllocationExplainRequest setShard(Integer shard) { | ||
this.shard = shard; | ||
return this; | ||
} | ||
|
||
@Nullable | ||
public int getShard() { | ||
return this.shard; | ||
} | ||
|
||
public ClusterAllocationExplainRequest setPrimary(Boolean primary) { | ||
this.primary = primary; | ||
return this; | ||
} | ||
|
||
@Nullable | ||
public boolean isPrimary() { | ||
return this.primary; | ||
} | ||
|
||
public void includeYesDecisions(boolean includeYesDecisions) { | ||
this.includeYesDecisions = includeYesDecisions; | ||
} | ||
|
||
/** Returns true if all decisions should be included. Otherwise only "NO" and "THROTTLE" decisions are returned */ | ||
public boolean includeYesDecisions() { | ||
return this.includeYesDecisions; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
StringBuilder sb = new StringBuilder("ClusterAllocationExplainRequest["); | ||
if (this.useAnyUnassignedShard()) { | ||
sb.append("useAnyUnassignedShard=true"); | ||
} else { | ||
sb.append("index=").append(index); | ||
sb.append(",shard=").append(shard); | ||
sb.append(",primary?=").append(primary); | ||
} | ||
sb.append(",includeYesDecisions?=").append(includeYesDecisions); | ||
return sb.toString(); | ||
} | ||
|
||
public static ClusterAllocationExplainRequest parse(XContentParser parser) throws IOException { | ||
String currentFieldName = null; | ||
String index = null; | ||
Integer shard = null; | ||
Boolean primary = null; | ||
XContentParser.Token token; | ||
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { | ||
if (token == XContentParser.Token.FIELD_NAME) { | ||
currentFieldName = parser.currentName(); | ||
} else if (token.isValue()) { | ||
if ("index".equals(currentFieldName)) { | ||
index = parser.text(); | ||
} else if ("shard".equals(currentFieldName)) { | ||
shard = parser.intValue(); | ||
} else if ("primary".equals(currentFieldName)) { | ||
primary = parser.booleanValue(); | ||
} else { | ||
throw new ElasticsearchParseException("unexpected field [" + currentFieldName + "] in allocation explain request"); | ||
} | ||
|
||
} else if (token == XContentParser.Token.START_OBJECT) { | ||
// the object was started | ||
continue; | ||
} else { | ||
throw new ElasticsearchParseException("unexpected token [" + token + "] in allocation explain request"); | ||
} | ||
} | ||
|
||
if (index == null && shard == null && primary == null) { | ||
// If it was an empty body, use the "any unassigned shard" request | ||
return new ClusterAllocationExplainRequest(); | ||
} else if (index == null || shard == null || primary == null) { | ||
throw new ElasticsearchParseException("'index', 'shard', and 'primary' must be specified in allocation explain request"); | ||
} | ||
return new ClusterAllocationExplainRequest(index, shard, primary); | ||
} | ||
|
||
@Override | ||
public void readFrom(StreamInput in) throws IOException { | ||
super.readFrom(in); | ||
this.index = in.readOptionalString(); | ||
this.shard = in.readOptionalVInt(); | ||
this.primary = in.readOptionalBoolean(); | ||
this.includeYesDecisions = in.readBoolean(); | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
super.writeTo(out); | ||
out.writeOptionalString(index); | ||
out.writeOptionalVInt(shard); | ||
out.writeOptionalBoolean(primary); | ||
out.writeBoolean(includeYesDecisions); | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
...elasticsearch/action/admin/cluster/allocation/ClusterAllocationExplainRequestBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.elasticsearch.action.admin.cluster.allocation; | ||
|
||
import org.elasticsearch.action.support.IndicesOptions; | ||
import org.elasticsearch.action.support.master.MasterNodeOperationRequestBuilder; | ||
import org.elasticsearch.client.ElasticsearchClient; | ||
|
||
/** | ||
* Builder for requests to explain the allocation of a shard in the cluster | ||
*/ | ||
public class ClusterAllocationExplainRequestBuilder | ||
extends MasterNodeOperationRequestBuilder<ClusterAllocationExplainRequest, | ||
ClusterAllocationExplainResponse, | ||
ClusterAllocationExplainRequestBuilder> { | ||
|
||
public ClusterAllocationExplainRequestBuilder(ElasticsearchClient client, ClusterAllocationExplainAction action) { | ||
super(client, action, new ClusterAllocationExplainRequest()); | ||
} | ||
|
||
/** The index name to use when finding the shard to explain */ | ||
public ClusterAllocationExplainRequestBuilder setIndex(String index) { | ||
request.setIndex(index); | ||
return this; | ||
} | ||
|
||
/** The shard number to use when finding the shard to explain */ | ||
public ClusterAllocationExplainRequestBuilder setShard(int shard) { | ||
request.setShard(shard); | ||
return this; | ||
} | ||
|
||
/** Whether the primary or replica should be explained */ | ||
public ClusterAllocationExplainRequestBuilder setPrimary(boolean primary) { | ||
request.setPrimary(primary); | ||
return this; | ||
} | ||
|
||
/** | ||
* Signal that the first unassigned shard should be used | ||
*/ | ||
public ClusterAllocationExplainRequestBuilder useAnyUnassignedShard() { | ||
request.setIndex(null); | ||
request.setShard(null); | ||
request.setPrimary(null); | ||
return this; | ||
} | ||
|
||
} |
Oops, something went wrong.