New API, update settings, allowing to change specific runtime settings of the cluster (indices). number_of_replicas is the only settings supported, allowing to change the number of repliacs of one or more indices.

This commit is contained in:
kimchy 2010-08-08 09:17:09 +03:00
parent 6d3d9fd807
commit d4547c629f
36 changed files with 930 additions and 75 deletions

View File

@ -41,6 +41,7 @@ import org.elasticsearch.action.admin.indices.gateway.snapshot.TransportShardGat
import org.elasticsearch.action.admin.indices.mapping.put.TransportPutMappingAction;
import org.elasticsearch.action.admin.indices.optimize.TransportOptimizeAction;
import org.elasticsearch.action.admin.indices.refresh.TransportRefreshAction;
import org.elasticsearch.action.admin.indices.settings.TransportUpdateSettingsAction;
import org.elasticsearch.action.admin.indices.status.TransportIndicesStatusAction;
import org.elasticsearch.action.count.TransportCountAction;
import org.elasticsearch.action.delete.TransportDeleteAction;
@ -80,6 +81,7 @@ public class TransportActionModule extends AbstractModule {
bind(TransportPutMappingAction.class).asEagerSingleton();
bind(TransportDeleteIndexAction.class).asEagerSingleton();
bind(TransportIndicesAliasesAction.class).asEagerSingleton();
bind(TransportUpdateSettingsAction.class).asEagerSingleton();
bind(TransportShardGatewaySnapshotAction.class).asEagerSingleton();
bind(TransportIndexGatewaySnapshotAction.class).asEagerSingleton();

View File

@ -52,6 +52,7 @@ public class TransportActions {
public static final String OPTIMIZE = "indices/optimize";
public static final String STATUS = "indices/status";
public static final String ALIASES = "indices/aliases";
public static final String UPDATE_SETTINGS = "indices/updateSettings";
public static class Gateway {
public static final String SNAPSHOT = "indices/gateway/snapshot";

View File

@ -0,0 +1,92 @@
/*
* Licensed to Elastic Search and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. Elastic Search 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.indices.settings;
import org.elasticsearch.ElasticSearchException;
import org.elasticsearch.action.TransportActions;
import org.elasticsearch.action.support.master.TransportMasterNodeOperationAction;
import org.elasticsearch.cluster.ClusterService;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.metadata.MetaDataUpdateSettingsService;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.transport.TransportService;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicReference;
/**
* @author kimchy (shay.banon)
*/
public class TransportUpdateSettingsAction extends TransportMasterNodeOperationAction<UpdateSettingsRequest, UpdateSettingsResponse> {
private final MetaDataUpdateSettingsService updateSettingsService;
@Inject public TransportUpdateSettingsAction(Settings settings, TransportService transportService, ClusterService clusterService, ThreadPool threadPool,
MetaDataUpdateSettingsService updateSettingsService) {
super(settings, transportService, clusterService, threadPool);
this.updateSettingsService = updateSettingsService;
}
@Override protected String transportAction() {
return TransportActions.Admin.Indices.UPDATE_SETTINGS;
}
@Override protected UpdateSettingsRequest newRequest() {
return new UpdateSettingsRequest();
}
@Override protected UpdateSettingsResponse newResponse() {
return new UpdateSettingsResponse();
}
@Override protected UpdateSettingsResponse masterOperation(UpdateSettingsRequest request, ClusterState state) throws ElasticSearchException {
final AtomicReference<Throwable> failureRef = new AtomicReference<Throwable>();
final CountDownLatch latch = new CountDownLatch(1);
updateSettingsService.updateSettings(request.settings(), request.indices(), new MetaDataUpdateSettingsService.Listener() {
@Override public void onSuccess() {
latch.countDown();
}
@Override public void onFailure(Throwable t) {
failureRef.set(t);
latch.countDown();
}
});
try {
latch.await();
} catch (InterruptedException e) {
failureRef.set(e);
}
if (failureRef.get() != null) {
if (failureRef.get() instanceof ElasticSearchException) {
throw (ElasticSearchException) failureRef.get();
} else {
throw new ElasticSearchException(failureRef.get().getMessage(), failureRef.get());
}
}
return new UpdateSettingsResponse();
}
}

View File

@ -0,0 +1,147 @@
/*
* Licensed to Elastic Search and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. Elastic Search 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.indices.settings;
import org.elasticsearch.ElasticSearchGenerationException;
import org.elasticsearch.action.ActionRequestValidationException;
import org.elasticsearch.action.support.master.MasterNodeOperationRequest;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.common.xcontent.builder.TextXContentBuilder;
import java.io.IOException;
import java.util.Map;
import static org.elasticsearch.action.Actions.*;
import static org.elasticsearch.common.settings.ImmutableSettings.Builder.*;
import static org.elasticsearch.common.settings.ImmutableSettings.*;
/**
* @author kimchy
*/
public class UpdateSettingsRequest extends MasterNodeOperationRequest {
private String[] indices;
private Settings settings = EMPTY_SETTINGS;
UpdateSettingsRequest() {
}
/**
* Constructs a new request to create an index with the specified name and settings.
*/
public UpdateSettingsRequest(String... indices) {
this.indices = indices;
}
/**
* Constructs a new request to create an index with the specified name and settings.
*/
public UpdateSettingsRequest(Settings settings, String... indices) {
this.indices = indices;
this.settings = settings;
}
@Override public ActionRequestValidationException validate() {
ActionRequestValidationException validationException = null;
if (settings.getAsMap().isEmpty()) {
validationException = addValidationError("no settings to update", validationException);
}
return validationException;
}
String[] indices() {
return indices;
}
Settings settings() {
return settings;
}
public UpdateSettingsRequest indices(String... indices) {
this.indices = indices;
return this;
}
/**
* The settings to created the index with.
*/
public UpdateSettingsRequest settings(Settings settings) {
this.settings = settings;
return this;
}
/**
* The settings to created the index with.
*/
public UpdateSettingsRequest settings(Settings.Builder settings) {
this.settings = settings.build();
return this;
}
/**
* The settings to crete the index with (either json/yaml/properties format)
*/
public UpdateSettingsRequest settings(String source) {
this.settings = ImmutableSettings.settingsBuilder().loadFromSource(source).build();
return this;
}
/**
* The settings to crete the index with (either json/yaml/properties format)
*/
public UpdateSettingsRequest settings(Map source) {
try {
TextXContentBuilder builder = XContentFactory.contentTextBuilder(XContentType.JSON);
builder.map(source);
settings(builder.string());
} catch (IOException e) {
throw new ElasticSearchGenerationException("Failed to generate [" + source + "]", e);
}
return this;
}
@Override public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
indices = new String[in.readVInt()];
for (int i = 0; i < indices.length; i++) {
indices[i] = in.readUTF();
}
settings = readSettingsFromStream(in);
}
@Override public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
if (indices == null) {
out.writeVInt(0);
} else {
out.writeVInt(indices.length);
for (String index : indices) {
out.writeUTF(index);
}
}
writeSettingsToStream(settings, out);
}
}

View File

@ -0,0 +1,44 @@
/*
* Licensed to Elastic Search and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. Elastic Search 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.indices.settings;
import org.elasticsearch.action.ActionResponse;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Streamable;
import java.io.IOException;
/**
* A response for a update settings action.
*
* @author kimchy (shay.banon)
*/
public class UpdateSettingsResponse implements ActionResponse, Streamable {
UpdateSettingsResponse() {
}
@Override public void readFrom(StreamInput in) throws IOException {
}
@Override public void writeTo(StreamOutput out) throws IOException {
}
}

View File

@ -62,7 +62,7 @@ public interface ClusterAdminClient {
*
* @param request The cluster state request
* @return The result future
* @see Requests#clusterHealth(String...)
* @see Requests#clusterHealthRequest(String...)
*/
ActionFuture<ClusterHealthResponse> health(ClusterHealthRequest request);
@ -71,7 +71,7 @@ public interface ClusterAdminClient {
*
* @param request The cluster state request
* @param listener A listener to be notified with a result
* @see Requests#clusterHealth(String...)
* @see Requests#clusterHealthRequest(String...)
*/
void health(ClusterHealthRequest request, ActionListener<ClusterHealthResponse> listener);
@ -85,7 +85,7 @@ public interface ClusterAdminClient {
*
* @param request The cluster state request.
* @return The result future
* @see Requests#clusterState()
* @see Requests#clusterStateRequest()
*/
ActionFuture<ClusterStateResponse> state(ClusterStateRequest request);
@ -94,7 +94,7 @@ public interface ClusterAdminClient {
*
* @param request The cluster state request.
* @param listener A listener to be notified with a result
* @see Requests#clusterState()
* @see Requests#clusterStateRequest()
*/
void state(ClusterStateRequest request, ActionListener<ClusterStateResponse> listener);
@ -108,7 +108,7 @@ public interface ClusterAdminClient {
*
* @param request The nodes info request
* @return The result future
* @see org.elasticsearch.client.Requests#nodesInfo(String...)
* @see org.elasticsearch.client.Requests#nodesInfoRequest(String...)
*/
ActionFuture<NodesInfoResponse> nodesInfo(NodesInfoRequest request);
@ -117,7 +117,7 @@ public interface ClusterAdminClient {
*
* @param request The nodes info request
* @param listener A listener to be notified with a result
* @see org.elasticsearch.client.Requests#nodesInfo(String...)
* @see org.elasticsearch.client.Requests#nodesInfoRequest(String...)
*/
void nodesInfo(NodesInfoRequest request, ActionListener<NodesInfoResponse> listener);
@ -131,7 +131,7 @@ public interface ClusterAdminClient {
*
* @param request The nodes info request
* @return The result future
* @see org.elasticsearch.client.Requests#nodesStats(String...)
* @see org.elasticsearch.client.Requests#nodesStatsRequest(String...)
*/
ActionFuture<NodesStatsResponse> nodesStats(NodesStatsRequest request);
@ -140,7 +140,7 @@ public interface ClusterAdminClient {
*
* @param request The nodes info request
* @param listener A listener to be notified with a result
* @see org.elasticsearch.client.Requests#nodesStats(String...)
* @see org.elasticsearch.client.Requests#nodesStatsRequest(String...)
*/
void nodesStats(NodesStatsRequest request, ActionListener<NodesStatsResponse> listener);
@ -154,7 +154,7 @@ public interface ClusterAdminClient {
*
* @param request The nodes shutdown request
* @return The result future
* @see org.elasticsearch.client.Requests#nodesShutdown(String...)
* @see org.elasticsearch.client.Requests#nodesShutdownRequest(String...)
*/
ActionFuture<NodesShutdownResponse> nodesShutdown(NodesShutdownRequest request);
@ -163,7 +163,7 @@ public interface ClusterAdminClient {
*
* @param request The nodes shutdown request
* @param listener A listener to be notified with a result
* @see org.elasticsearch.client.Requests#nodesShutdown(String...)
* @see org.elasticsearch.client.Requests#nodesShutdownRequest(String...)
*/
void nodesShutdown(NodesShutdownRequest request, ActionListener<NodesShutdownResponse> listener);
@ -177,7 +177,7 @@ public interface ClusterAdminClient {
*
* @param request The nodes restart request
* @return The result future
* @see org.elasticsearch.client.Requests#nodesRestart(String...)
* @see org.elasticsearch.client.Requests#nodesRestartRequest(String...)
*/
ActionFuture<NodesRestartResponse> nodesRestart(NodesRestartRequest request);
@ -186,7 +186,7 @@ public interface ClusterAdminClient {
*
* @param request The nodes restart request
* @param listener A listener to be notified with a result
* @see org.elasticsearch.client.Requests#nodesRestart(String...)
* @see org.elasticsearch.client.Requests#nodesRestartRequest(String...)
*/
void nodesRestart(NodesRestartRequest request, ActionListener<NodesRestartResponse> listener);

View File

@ -39,6 +39,8 @@ import org.elasticsearch.action.admin.indices.optimize.OptimizeRequest;
import org.elasticsearch.action.admin.indices.optimize.OptimizeResponse;
import org.elasticsearch.action.admin.indices.refresh.RefreshRequest;
import org.elasticsearch.action.admin.indices.refresh.RefreshResponse;
import org.elasticsearch.action.admin.indices.settings.UpdateSettingsRequest;
import org.elasticsearch.action.admin.indices.settings.UpdateSettingsResponse;
import org.elasticsearch.action.admin.indices.status.IndicesStatusRequest;
import org.elasticsearch.action.admin.indices.status.IndicesStatusResponse;
import org.elasticsearch.client.action.admin.indices.alias.IndicesAliasesRequestBuilder;
@ -50,6 +52,7 @@ import org.elasticsearch.client.action.admin.indices.gateway.snapshot.GatewaySna
import org.elasticsearch.client.action.admin.indices.mapping.put.PutMappingRequestBuilder;
import org.elasticsearch.client.action.admin.indices.optimize.OptimizeRequestBuilder;
import org.elasticsearch.client.action.admin.indices.refresh.RefreshRequestBuilder;
import org.elasticsearch.client.action.admin.indices.settings.UpdateSettingsRequestBuilder;
import org.elasticsearch.client.action.admin.indices.status.IndicesStatusRequestBuilder;
/**
@ -65,7 +68,7 @@ public interface IndicesAdminClient {
*
* @param request The indices status request
* @return The result future
* @see Requests#indicesStatus(String...)
* @see Requests#indicesStatusRequest(String...)
*/
ActionFuture<IndicesStatusResponse> status(IndicesStatusRequest request);
@ -74,7 +77,7 @@ public interface IndicesAdminClient {
*
* @param request The indices status request
* @param listener A listener to be notified with a result
* @see Requests#indicesStatus(String...)
* @see Requests#indicesStatusRequest(String...)
*/
void status(IndicesStatusRequest request, ActionListener<IndicesStatusResponse> listener);
@ -276,7 +279,7 @@ public interface IndicesAdminClient {
*
* @param request The clear indices cache request
* @return The result future
* @see Requests#clearIndicesCache(String...)
* @see Requests#clearIndicesCacheRequest(String...)
*/
ActionFuture<ClearIndicesCacheResponse> clearCache(ClearIndicesCacheRequest request);
@ -285,7 +288,7 @@ public interface IndicesAdminClient {
*
* @param request The clear indices cache request
* @param listener A listener to be notified with a result
* @see Requests#clearIndicesCache(String...)
* @see Requests#clearIndicesCacheRequest(String...)
*/
void clearCache(ClearIndicesCacheRequest request, ActionListener<ClearIndicesCacheResponse> listener);
@ -293,4 +296,25 @@ public interface IndicesAdminClient {
* Clear indices cache.
*/
ClearIndicesCacheRequestBuilder prepareClearCache(String... indices);
/**
* Updates settings of one or more indices.
*
* @param request the update settings request
* @return The result future
*/
ActionFuture<UpdateSettingsResponse> updateSettings(UpdateSettingsRequest request);
/**
* Updates settings of one or more indices.
*
* @param request the update settings request
* @param listener A listener to be notified with the response
*/
void updateSettings(UpdateSettingsRequest request, ActionListener<UpdateSettingsResponse> listener);
/**
* Update indices settings.
*/
UpdateSettingsRequestBuilder prepareUpdateSettings(String... indices);
}

View File

@ -37,6 +37,7 @@ import org.elasticsearch.action.admin.indices.gateway.snapshot.GatewaySnapshotRe
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest;
import org.elasticsearch.action.admin.indices.optimize.OptimizeRequest;
import org.elasticsearch.action.admin.indices.refresh.RefreshRequest;
import org.elasticsearch.action.admin.indices.settings.UpdateSettingsRequest;
import org.elasticsearch.action.admin.indices.status.IndicesStatusRequest;
import org.elasticsearch.action.count.CountRequest;
import org.elasticsearch.action.delete.DeleteRequest;
@ -166,7 +167,7 @@ public class Requests {
* @return The indices status request
* @see org.elasticsearch.client.IndicesAdminClient#status(org.elasticsearch.action.admin.indices.status.IndicesStatusRequest)
*/
public static IndicesStatusRequest indicesStatus(String... indices) {
public static IndicesStatusRequest indicesStatusRequest(String... indices) {
return new IndicesStatusRequest(indices);
}
@ -262,17 +263,27 @@ public class Requests {
* @param indices The indices the gateway snapshot will be performed on. Use <tt>null</tt> or <tt>_all</tt> to execute against all indices
* @return The request
*/
public static ClearIndicesCacheRequest clearIndicesCache(String... indices) {
public static ClearIndicesCacheRequest clearIndicesCacheRequest(String... indices) {
return new ClearIndicesCacheRequest(indices);
}
/**
* A request to update indices settings.
*
* @param indices The indices to update the settings for. Use <tt>null</tt> or <tt>_all</tt> to executed against all indices.
* @return The request
*/
public static UpdateSettingsRequest updateSettingsRequest(String... indices) {
return new UpdateSettingsRequest(indices);
}
/**
* Creates a cluster state request.
*
* @return The cluster state request.
* @see org.elasticsearch.client.ClusterAdminClient#state(org.elasticsearch.action.admin.cluster.state.ClusterStateRequest)
*/
public static ClusterStateRequest clusterState() {
public static ClusterStateRequest clusterStateRequest() {
return new ClusterStateRequest();
}
@ -283,7 +294,7 @@ public class Requests {
* @return The cluster health request
* @see org.elasticsearch.client.ClusterAdminClient#health(org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest)
*/
public static ClusterHealthRequest clusterHealth(String... indices) {
public static ClusterHealthRequest clusterHealthRequest(String... indices) {
return new ClusterHealthRequest(indices);
}
@ -293,7 +304,7 @@ public class Requests {
* @return The nodes info request
* @see org.elasticsearch.client.ClusterAdminClient#nodesInfo(org.elasticsearch.action.admin.cluster.node.info.NodesInfoRequest)
*/
public static NodesInfoRequest nodesInfo() {
public static NodesInfoRequest nodesInfoRequest() {
return new NodesInfoRequest();
}
@ -304,7 +315,7 @@ public class Requests {
* @return The nodes info request
* @see org.elasticsearch.client.ClusterAdminClient#nodesStats(org.elasticsearch.action.admin.cluster.node.stats.NodesStatsRequest)
*/
public static NodesInfoRequest nodesInfo(String... nodesIds) {
public static NodesInfoRequest nodesInfoRequest(String... nodesIds) {
return new NodesInfoRequest(nodesIds);
}
@ -315,14 +326,14 @@ public class Requests {
* @return The nodes info request
* @see org.elasticsearch.client.ClusterAdminClient#nodesStats(org.elasticsearch.action.admin.cluster.node.stats.NodesStatsRequest)
*/
public static NodesStatsRequest nodesStats(String... nodesIds) {
public static NodesStatsRequest nodesStatsRequest(String... nodesIds) {
return new NodesStatsRequest(nodesIds);
}
/**
* Shuts down all nodes in the cluster.
*/
public static NodesShutdownRequest nodesShutdown() {
public static NodesShutdownRequest nodesShutdownRequest() {
return new NodesShutdownRequest();
}
@ -333,14 +344,14 @@ public class Requests {
* @return The nodes info request
* @see org.elasticsearch.client.ClusterAdminClient#nodesShutdown(org.elasticsearch.action.admin.cluster.node.shutdown.NodesShutdownRequest)
*/
public static NodesShutdownRequest nodesShutdown(String... nodesIds) {
public static NodesShutdownRequest nodesShutdownRequest(String... nodesIds) {
return new NodesShutdownRequest(nodesIds);
}
/**
* Restarts all nodes in the cluster.
*/
public static NodesRestartRequest nodesRestart() {
public static NodesRestartRequest nodesRestartRequest() {
return new NodesRestartRequest();
}
@ -351,7 +362,7 @@ public class Requests {
* @return The nodes info request
* @see org.elasticsearch.client.ClusterAdminClient#nodesRestart(org.elasticsearch.action.admin.cluster.node.restart.NodesRestartRequest)
*/
public static NodesRestartRequest nodesRestart(String... nodesIds) {
public static NodesRestartRequest nodesRestartRequest(String... nodesIds) {
return new NodesRestartRequest(nodesIds);
}

View File

@ -0,0 +1,80 @@
/*
* Licensed to Elastic Search and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. Elastic Search 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.client.action.admin.indices.settings;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.admin.indices.settings.UpdateSettingsRequest;
import org.elasticsearch.action.admin.indices.settings.UpdateSettingsResponse;
import org.elasticsearch.client.IndicesAdminClient;
import org.elasticsearch.client.action.admin.indices.support.BaseIndicesRequestBuilder;
import org.elasticsearch.common.settings.Settings;
import java.util.Map;
/**
* @author kimchy (shay.banon)
*/
public class UpdateSettingsRequestBuilder extends BaseIndicesRequestBuilder<UpdateSettingsRequest, UpdateSettingsResponse> {
public UpdateSettingsRequestBuilder(IndicesAdminClient indicesClient, String... indices) {
super(indicesClient, new UpdateSettingsRequest(indices));
}
public UpdateSettingsRequestBuilder setIndices(String... indices) {
request.indices(indices);
return this;
}
/**
* The settings update.
*/
public UpdateSettingsRequestBuilder setSettings(Settings settings) {
request.settings(settings);
return this;
}
/**
* The settings to update.
*/
public UpdateSettingsRequestBuilder setSettings(Settings.Builder settings) {
request.settings(settings);
return this;
}
/**
* The settings to update (either json/yaml/properties format)
*/
public UpdateSettingsRequestBuilder setSettings(String source) {
request.settings(source);
return this;
}
/**
* The settings to update (either json/yaml/properties format)
*/
public UpdateSettingsRequestBuilder setSettings(Map<String, Object> source) {
request.settings(source);
return this;
}
@Override protected void doExecute(ActionListener<UpdateSettingsResponse> listener) {
client.updateSettings(request, listener);
}
}

View File

@ -48,6 +48,9 @@ import org.elasticsearch.action.admin.indices.optimize.TransportOptimizeAction;
import org.elasticsearch.action.admin.indices.refresh.RefreshRequest;
import org.elasticsearch.action.admin.indices.refresh.RefreshResponse;
import org.elasticsearch.action.admin.indices.refresh.TransportRefreshAction;
import org.elasticsearch.action.admin.indices.settings.TransportUpdateSettingsAction;
import org.elasticsearch.action.admin.indices.settings.UpdateSettingsRequest;
import org.elasticsearch.action.admin.indices.settings.UpdateSettingsResponse;
import org.elasticsearch.action.admin.indices.status.IndicesStatusRequest;
import org.elasticsearch.action.admin.indices.status.IndicesStatusResponse;
import org.elasticsearch.action.admin.indices.status.TransportIndicesStatusAction;
@ -84,11 +87,14 @@ public class NodeIndicesAdminClient extends AbstractIndicesAdminClient implement
private final TransportClearIndicesCacheAction clearIndicesCacheAction;
private final TransportUpdateSettingsAction updateSettingsAction;
@Inject public NodeIndicesAdminClient(Settings settings, ThreadPool threadPool, TransportIndicesStatusAction indicesStatusAction,
TransportCreateIndexAction createIndexAction, TransportDeleteIndexAction deleteIndexAction,
TransportRefreshAction refreshAction, TransportFlushAction flushAction, TransportOptimizeAction optimizeAction,
TransportPutMappingAction putMappingAction, TransportGatewaySnapshotAction gatewaySnapshotAction,
TransportIndicesAliasesAction indicesAliasesAction, TransportClearIndicesCacheAction clearIndicesCacheAction) {
TransportIndicesAliasesAction indicesAliasesAction, TransportClearIndicesCacheAction clearIndicesCacheAction,
TransportUpdateSettingsAction updateSettingsAction) {
this.threadPool = threadPool;
this.indicesStatusAction = indicesStatusAction;
this.createIndexAction = createIndexAction;
@ -100,6 +106,7 @@ public class NodeIndicesAdminClient extends AbstractIndicesAdminClient implement
this.gatewaySnapshotAction = gatewaySnapshotAction;
this.indicesAliasesAction = indicesAliasesAction;
this.clearIndicesCacheAction = clearIndicesCacheAction;
this.updateSettingsAction = updateSettingsAction;
}
@Override public ThreadPool threadPool() {
@ -185,4 +192,12 @@ public class NodeIndicesAdminClient extends AbstractIndicesAdminClient implement
@Override public void clearCache(ClearIndicesCacheRequest request, ActionListener<ClearIndicesCacheResponse> listener) {
clearIndicesCacheAction.execute(request, listener);
}
@Override public ActionFuture<UpdateSettingsResponse> updateSettings(UpdateSettingsRequest request) {
return updateSettingsAction.execute(request);
}
@Override public void updateSettings(UpdateSettingsRequest request, ActionListener<UpdateSettingsResponse> listener) {
updateSettingsAction.execute(request, listener);
}
}

View File

@ -28,6 +28,7 @@ import org.elasticsearch.client.action.admin.indices.gateway.snapshot.GatewaySna
import org.elasticsearch.client.action.admin.indices.mapping.put.PutMappingRequestBuilder;
import org.elasticsearch.client.action.admin.indices.optimize.OptimizeRequestBuilder;
import org.elasticsearch.client.action.admin.indices.refresh.RefreshRequestBuilder;
import org.elasticsearch.client.action.admin.indices.settings.UpdateSettingsRequestBuilder;
import org.elasticsearch.client.action.admin.indices.status.IndicesStatusRequestBuilder;
import org.elasticsearch.client.internal.InternalIndicesAdminClient;
@ -75,4 +76,8 @@ public abstract class AbstractIndicesAdminClient implements InternalIndicesAdmin
@Override public IndicesStatusRequestBuilder prepareStatus(String... indices) {
return new IndicesStatusRequestBuilder(this).setIndices(indices);
}
@Override public UpdateSettingsRequestBuilder prepareUpdateSettings(String... indices) {
return new UpdateSettingsRequestBuilder(this).setIndices(indices);
}
}

View File

@ -183,7 +183,7 @@ public class TransportClientNodesService extends AbstractComponent implements Cl
@Override public void run() {
try {
transportService.connectToNode(listedNode); // make sure we are connected to it
transportService.sendRequest(listedNode, TransportActions.Admin.Cluster.Node.INFO, Requests.nodesInfo("_local"), new BaseTransportResponseHandler<NodesInfoResponse>() {
transportService.sendRequest(listedNode, TransportActions.Admin.Cluster.Node.INFO, Requests.nodesInfoRequest("_local"), new BaseTransportResponseHandler<NodesInfoResponse>() {
@Override public NodesInfoResponse newInstance() {
return new NodesInfoResponse();

View File

@ -37,6 +37,7 @@ import org.elasticsearch.client.transport.action.admin.indices.gateway.snapshot.
import org.elasticsearch.client.transport.action.admin.indices.mapping.create.ClientTransportPutMappingAction;
import org.elasticsearch.client.transport.action.admin.indices.optimize.ClientTransportOptimizeAction;
import org.elasticsearch.client.transport.action.admin.indices.refresh.ClientTransportRefreshAction;
import org.elasticsearch.client.transport.action.admin.indices.settings.ClientTransportUpdateSettingsAction;
import org.elasticsearch.client.transport.action.admin.indices.status.ClientTransportIndicesStatusAction;
import org.elasticsearch.client.transport.action.count.ClientTransportCountAction;
import org.elasticsearch.client.transport.action.delete.ClientTransportDeleteAction;
@ -71,6 +72,7 @@ public class ClientTransportActionModule extends AbstractModule {
bind(ClientTransportGatewaySnapshotAction.class).asEagerSingleton();
bind(ClientTransportIndicesAliasesAction.class).asEagerSingleton();
bind(ClientTransportClearIndicesCacheAction.class).asEagerSingleton();
bind(ClientTransportUpdateSettingsAction.class).asEagerSingleton();
bind(ClientTransportNodesInfoAction.class).asEagerSingleton();
bind(ClientTransportNodesStatsAction.class).asEagerSingleton();

View File

@ -0,0 +1,42 @@
/*
* Licensed to Elastic Search and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. Elastic Search 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.client.transport.action.admin.indices.settings;
import org.elasticsearch.action.TransportActions;
import org.elasticsearch.action.admin.indices.settings.UpdateSettingsRequest;
import org.elasticsearch.action.admin.indices.settings.UpdateSettingsResponse;
import org.elasticsearch.client.transport.action.support.BaseClientTransportAction;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.transport.TransportService;
/**
* @author kimchy (shay.banon)
*/
public class ClientTransportUpdateSettingsAction extends BaseClientTransportAction<UpdateSettingsRequest, UpdateSettingsResponse> {
@Inject public ClientTransportUpdateSettingsAction(Settings settings, TransportService transportService) {
super(settings, transportService, UpdateSettingsResponse.class);
}
@Override protected String action() {
return TransportActions.Admin.Indices.UPDATE_SETTINGS;
}
}

View File

@ -40,6 +40,8 @@ import org.elasticsearch.action.admin.indices.optimize.OptimizeRequest;
import org.elasticsearch.action.admin.indices.optimize.OptimizeResponse;
import org.elasticsearch.action.admin.indices.refresh.RefreshRequest;
import org.elasticsearch.action.admin.indices.refresh.RefreshResponse;
import org.elasticsearch.action.admin.indices.settings.UpdateSettingsRequest;
import org.elasticsearch.action.admin.indices.settings.UpdateSettingsResponse;
import org.elasticsearch.action.admin.indices.status.IndicesStatusRequest;
import org.elasticsearch.action.admin.indices.status.IndicesStatusResponse;
import org.elasticsearch.client.IndicesAdminClient;
@ -54,6 +56,7 @@ import org.elasticsearch.client.transport.action.admin.indices.gateway.snapshot.
import org.elasticsearch.client.transport.action.admin.indices.mapping.create.ClientTransportPutMappingAction;
import org.elasticsearch.client.transport.action.admin.indices.optimize.ClientTransportOptimizeAction;
import org.elasticsearch.client.transport.action.admin.indices.refresh.ClientTransportRefreshAction;
import org.elasticsearch.client.transport.action.admin.indices.settings.ClientTransportUpdateSettingsAction;
import org.elasticsearch.client.transport.action.admin.indices.status.ClientTransportIndicesStatusAction;
import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.common.inject.Inject;
@ -89,12 +92,15 @@ public class InternalTransportIndicesAdminClient extends AbstractIndicesAdminCli
private final ClientTransportClearIndicesCacheAction clearIndicesCacheAction;
private final ClientTransportUpdateSettingsAction updateSettingsAction;
@Inject public InternalTransportIndicesAdminClient(Settings settings, TransportClientNodesService nodesService, ThreadPool threadPool,
ClientTransportIndicesStatusAction indicesStatusAction,
ClientTransportCreateIndexAction createIndexAction, ClientTransportDeleteIndexAction deleteIndexAction,
ClientTransportRefreshAction refreshAction, ClientTransportFlushAction flushAction, ClientTransportOptimizeAction optimizeAction,
ClientTransportPutMappingAction putMappingAction, ClientTransportGatewaySnapshotAction gatewaySnapshotAction,
ClientTransportIndicesAliasesAction indicesAliasesAction, ClientTransportClearIndicesCacheAction clearIndicesCacheAction) {
ClientTransportIndicesAliasesAction indicesAliasesAction, ClientTransportClearIndicesCacheAction clearIndicesCacheAction,
ClientTransportUpdateSettingsAction updateSettingsAction) {
this.nodesService = nodesService;
this.threadPool = threadPool;
this.indicesStatusAction = indicesStatusAction;
@ -107,6 +113,7 @@ public class InternalTransportIndicesAdminClient extends AbstractIndicesAdminCli
this.gatewaySnapshotAction = gatewaySnapshotAction;
this.indicesAliasesAction = indicesAliasesAction;
this.clearIndicesCacheAction = clearIndicesCacheAction;
this.updateSettingsAction = updateSettingsAction;
}
@Override public ThreadPool threadPool() {
@ -282,4 +289,21 @@ public class InternalTransportIndicesAdminClient extends AbstractIndicesAdminCli
}
});
}
@Override public ActionFuture<UpdateSettingsResponse> updateSettings(final UpdateSettingsRequest request) {
return nodesService.execute(new TransportClientNodesService.NodeCallback<org.elasticsearch.action.ActionFuture<UpdateSettingsResponse>>() {
@Override public ActionFuture<UpdateSettingsResponse> doWithNode(DiscoveryNode node) throws ElasticSearchException {
return updateSettingsAction.execute(node, request);
}
});
}
@Override public void updateSettings(final UpdateSettingsRequest request, final ActionListener<UpdateSettingsResponse> listener) {
nodesService.execute(new TransportClientNodesService.NodeCallback<Void>() {
@Override public Void doWithNode(DiscoveryNode node) throws ElasticSearchException {
updateSettingsAction.execute(node, request, listener);
return null;
}
});
}
}

View File

@ -24,10 +24,7 @@ import org.elasticsearch.cluster.action.index.NodeIndexCreatedAction;
import org.elasticsearch.cluster.action.index.NodeIndexDeletedAction;
import org.elasticsearch.cluster.action.index.NodeMappingCreatedAction;
import org.elasticsearch.cluster.action.shard.ShardStateAction;
import org.elasticsearch.cluster.metadata.MetaDataCreateIndexService;
import org.elasticsearch.cluster.metadata.MetaDataDeleteIndexService;
import org.elasticsearch.cluster.metadata.MetaDataIndexAliasesService;
import org.elasticsearch.cluster.metadata.MetaDataMappingService;
import org.elasticsearch.cluster.metadata.*;
import org.elasticsearch.cluster.routing.RoutingService;
import org.elasticsearch.cluster.routing.strategy.PreferUnallocatedShardUnassignedStrategy;
import org.elasticsearch.cluster.routing.strategy.ShardsRoutingStrategy;
@ -56,6 +53,7 @@ public class ClusterModule extends AbstractModule {
bind(MetaDataDeleteIndexService.class).asEagerSingleton();
bind(MetaDataMappingService.class).asEagerSingleton();
bind(MetaDataIndexAliasesService.class).asEagerSingleton();
bind(MetaDataUpdateSettingsService.class).asEagerSingleton();
bind(RoutingService.class).asEagerSingleton();

View File

@ -0,0 +1,84 @@
/*
* Licensed to Elastic Search and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. Elastic Search 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.cluster.metadata;
import org.elasticsearch.ElasticSearchIllegalArgumentException;
import org.elasticsearch.cluster.ClusterService;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.ClusterStateUpdateTask;
import org.elasticsearch.cluster.routing.RoutingTable;
import org.elasticsearch.common.component.AbstractComponent;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import static org.elasticsearch.cluster.routing.RoutingTable.*;
/**
* @author kimchy (shay.banon)
*/
public class MetaDataUpdateSettingsService extends AbstractComponent {
private final ClusterService clusterService;
@Inject public MetaDataUpdateSettingsService(Settings settings, ClusterService clusterService) {
super(settings);
this.clusterService = clusterService;
}
public void updateSettings(final Settings settings, final String[] indices, final Listener listener) {
clusterService.submitStateUpdateTask("update-settings", new ClusterStateUpdateTask() {
@Override public ClusterState execute(ClusterState currentState) {
try {
boolean changed = false;
String[] actualIndices = currentState.metaData().concreteIndices(indices);
RoutingTable.Builder routingTableBuilder = newRoutingTableBuilder().routingTable(currentState.routingTable());
MetaData.Builder metaDataBuilder = MetaData.newMetaDataBuilder().metaData(currentState.metaData());
int updatedNumberOfReplicas = settings.getAsInt(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, -1);
if (updatedNumberOfReplicas != -1) {
routingTableBuilder.updateNumberOfReplicas(updatedNumberOfReplicas, actualIndices);
metaDataBuilder.updateNumberOfReplicas(updatedNumberOfReplicas, actualIndices);
changed = true;
}
if (!changed) {
listener.onFailure(new ElasticSearchIllegalArgumentException("No settings applied"));
return currentState;
}
logger.info("Updating number_of_replicas to [{}] for indices {}", updatedNumberOfReplicas, actualIndices);
listener.onSuccess();
return ClusterState.builder().state(currentState).metaData(metaDataBuilder).routingTable(routingTableBuilder).build();
} catch (Exception e) {
listener.onFailure(e);
return currentState;
}
}
});
}
public static interface Listener {
void onSuccess();
void onFailure(Throwable t);
}
}

View File

@ -39,6 +39,7 @@ import org.elasticsearch.rest.action.admin.indices.mapping.get.RestGetMappingAct
import org.elasticsearch.rest.action.admin.indices.mapping.put.RestPutMappingAction;
import org.elasticsearch.rest.action.admin.indices.optimize.RestOptimizeAction;
import org.elasticsearch.rest.action.admin.indices.refresh.RestRefreshAction;
import org.elasticsearch.rest.action.admin.indices.settings.RestUpdateSettingsAction;
import org.elasticsearch.rest.action.admin.indices.status.RestIndicesStatusAction;
import org.elasticsearch.rest.action.count.RestCountAction;
import org.elasticsearch.rest.action.delete.RestDeleteAction;
@ -73,6 +74,7 @@ public class RestActionModule extends AbstractModule {
bind(RestIndicesAliasesAction.class).asEagerSingleton();
bind(RestCreateIndexAction.class).asEagerSingleton();
bind(RestDeleteIndexAction.class).asEagerSingleton();
bind(RestUpdateSettingsAction.class).asEagerSingleton();
bind(RestPutMappingAction.class).asEagerSingleton();
bind(RestGetMappingAction.class).asEagerSingleton();

View File

@ -47,7 +47,7 @@ public class RestClusterHealthAction extends BaseRestHandler {
}
@Override public void handleRequest(final RestRequest request, final RestChannel channel) {
ClusterHealthRequest clusterHealthRequest = clusterHealth(RestActions.splitIndices(request.param("index")));
ClusterHealthRequest clusterHealthRequest = clusterHealthRequest(RestActions.splitIndices(request.param("index")));
int level = 0;
try {
clusterHealthRequest.timeout(request.paramAsTime("timeout", clusterHealthRequest.timeout()));

View File

@ -62,7 +62,7 @@ public class RestClusterStateAction extends BaseRestHandler {
}
@Override public void handleRequest(final RestRequest request, final RestChannel channel) {
final ClusterStateRequest clusterStateRequest = Requests.clusterState();
final ClusterStateRequest clusterStateRequest = Requests.clusterStateRequest();
clusterStateRequest.filterNodes(request.paramAsBoolean("filter_nodes", clusterStateRequest.filterNodes()));
clusterStateRequest.filterRoutingTable(request.paramAsBoolean("filter_routing_table", clusterStateRequest.filterRoutingTable()));
clusterStateRequest.filterMetaData(request.paramAsBoolean("filter_metadata", clusterStateRequest.filterMetaData()));

View File

@ -59,7 +59,7 @@ public class RestGetMappingAction extends BaseRestHandler {
final String[] indices = splitIndices(request.param("index"));
final Set<String> types = ImmutableSet.copyOf(splitTypes(request.param("type")));
ClusterStateRequest clusterStateRequest = Requests.clusterState()
ClusterStateRequest clusterStateRequest = Requests.clusterStateRequest()
.filterRoutingTable(true)
.filterNodes(true)
.filteredIndices(indices);

View File

@ -0,0 +1,96 @@
/*
* Licensed to Elastic Search and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. Elastic Search 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.rest.action.admin.indices.settings;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.admin.indices.settings.UpdateSettingsRequest;
import org.elasticsearch.action.admin.indices.settings.UpdateSettingsResponse;
import org.elasticsearch.client.Client;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.settings.SettingsException;
import org.elasticsearch.common.xcontent.builder.XContentBuilder;
import org.elasticsearch.rest.*;
import org.elasticsearch.rest.action.support.RestXContentBuilder;
import java.io.IOException;
import java.util.Map;
import static org.elasticsearch.client.Requests.*;
import static org.elasticsearch.rest.RestResponse.Status.*;
import static org.elasticsearch.rest.action.support.RestActions.*;
/**
* @author kimchy (shay.banon)
*/
public class RestUpdateSettingsAction extends BaseRestHandler {
@Inject public RestUpdateSettingsAction(Settings settings, Client client, RestController controller) {
super(settings, client);
controller.registerHandler(RestRequest.Method.PUT, "/{index}/_settings", this);
controller.registerHandler(RestRequest.Method.PUT, "/_settings", this);
}
@Override public void handleRequest(final RestRequest request, final RestChannel channel) {
UpdateSettingsRequest updateSettingsRequest = updateSettingsRequest(splitIndices(request.param("index")));
ImmutableSettings.Builder updateSettings = ImmutableSettings.settingsBuilder();
String bodySettings = request.contentAsString();
if (Strings.hasText(bodySettings)) {
try {
updateSettings.put(ImmutableSettings.settingsBuilder().loadFromSource(bodySettings).build());
} catch (Exception e) {
try {
channel.sendResponse(new XContentThrowableRestResponse(request, BAD_REQUEST, new SettingsException("Failed to parse index settings", e)));
} catch (IOException e1) {
logger.warn("Failed to send response", e1);
return;
}
}
}
for (Map.Entry<String, String> entry : request.params().entrySet()) {
updateSettings.put(entry.getKey(), entry.getValue());
}
updateSettingsRequest.settings(updateSettings);
client.admin().indices().updateSettings(updateSettingsRequest, new ActionListener<UpdateSettingsResponse>() {
@Override public void onResponse(UpdateSettingsResponse updateSettingsResponse) {
try {
XContentBuilder builder = RestXContentBuilder.restContentBuilder(request);
builder.startObject()
.field("ok", true)
.endObject();
channel.sendResponse(new XContentRestResponse(request, OK, builder));
} catch (Exception e) {
onFailure(e);
}
}
@Override public void onFailure(Throwable e) {
try {
channel.sendResponse(new XContentThrowableRestResponse(request, e));
} catch (IOException e1) {
logger.error("Failed to send failure response", e1);
}
}
});
}
}

View File

@ -69,7 +69,7 @@ public class IndexAliasesTests extends AbstractNodesTests {
client1.admin().indices().create(createIndexRequest("test")).actionGet();
logger.info("Running Cluster Health");
ClusterHealthResponse clusterHealth = client1.admin().cluster().health(clusterHealth().waitForGreenStatus()).actionGet();
ClusterHealthResponse clusterHealth = client1.admin().cluster().health(clusterHealthRequest().waitForGreenStatus()).actionGet();
logger.info("Done Cluster Health, status " + clusterHealth.status());
assertThat(clusterHealth.timedOut(), equalTo(false));
assertThat(clusterHealth.status(), equalTo(ClusterHealthStatus.GREEN));
@ -94,7 +94,7 @@ public class IndexAliasesTests extends AbstractNodesTests {
client1.admin().indices().create(createIndexRequest("test_x")).actionGet();
logger.info("Running Cluster Health");
clusterHealth = client1.admin().cluster().health(clusterHealth().waitForGreenStatus()).actionGet();
clusterHealth = client1.admin().cluster().health(clusterHealthRequest().waitForGreenStatus()).actionGet();
logger.info("Done Cluster Health, status " + clusterHealth.status());
assertThat(clusterHealth.timedOut(), equalTo(false));
assertThat(clusterHealth.status(), equalTo(ClusterHealthStatus.GREEN));

View File

@ -56,7 +56,7 @@ public class BroadcastActionsTests extends AbstractNodesTests {
client("server1").admin().indices().prepareCreate("test").execute().actionGet(5000);
logger.info("Running Cluster Health");
ClusterHealthResponse clusterHealth = client("server1").admin().cluster().health(clusterHealth().waitForYellowStatus()).actionGet();
ClusterHealthResponse clusterHealth = client("server1").admin().cluster().health(clusterHealthRequest().waitForYellowStatus()).actionGet();
logger.info("Done Cluster Health, status " + clusterHealth.status());
assertThat(clusterHealth.timedOut(), equalTo(false));
assertThat(clusterHealth.status(), equalTo(ClusterHealthStatus.YELLOW));

View File

@ -97,7 +97,7 @@ public class DocumentActionsTests extends AbstractNodesTests {
@Test public void testIndexActions() throws Exception {
logger.info("Running Cluster Health");
ClusterHealthResponse clusterHealth = client1.admin().cluster().health(clusterHealth().waitForGreenStatus()).actionGet();
ClusterHealthResponse clusterHealth = client1.admin().cluster().health(clusterHealthRequest().waitForGreenStatus()).actionGet();
logger.info("Done Cluster Health, status " + clusterHealth.status());
assertThat(clusterHealth.timedOut(), equalTo(false));
assertThat(clusterHealth.status(), equalTo(ClusterHealthStatus.GREEN));
@ -113,7 +113,7 @@ public class DocumentActionsTests extends AbstractNodesTests {
assertThat(refreshResponse.failedShards(), equalTo(0));
logger.info("Clearing cache");
ClearIndicesCacheResponse clearIndicesCacheResponse = client1.admin().indices().clearCache(clearIndicesCache("test")).actionGet();
ClearIndicesCacheResponse clearIndicesCacheResponse = client1.admin().indices().clearCache(clearIndicesCacheRequest("test")).actionGet();
assertThat(clearIndicesCacheResponse.successfulShards(), equalTo(10));
assertThat(clearIndicesCacheResponse.failedShards(), equalTo(0));

View File

@ -67,7 +67,7 @@ public class MoreLikeThisActionTests extends AbstractNodesTests {
client1.admin().indices().create(createIndexRequest("test")).actionGet();
logger.info("Running Cluster Health");
ClusterHealthResponse clusterHealth = client1.admin().cluster().health(clusterHealth().waitForGreenStatus()).actionGet();
ClusterHealthResponse clusterHealth = client1.admin().cluster().health(clusterHealthRequest().waitForGreenStatus()).actionGet();
logger.info("Done Cluster Health, status " + clusterHealth.status());
assertThat(clusterHealth.timedOut(), equalTo(false));
assertThat(clusterHealth.status(), equalTo(ClusterHealthStatus.GREEN));

View File

@ -69,7 +69,7 @@ public abstract class AbstractSimpleIndexGatewayTests extends AbstractNodesTests
assertThat(putMappingResponse.acknowledged(), equalTo(true));
// verify that mapping is there
ClusterStateResponse clusterState = client("server1").admin().cluster().state(clusterState()).actionGet();
ClusterStateResponse clusterState = client("server1").admin().cluster().state(clusterStateRequest()).actionGet();
assertThat(clusterState.state().metaData().index("test").mapping("type1"), notNullValue());
// create two and delete the first
@ -93,13 +93,13 @@ public abstract class AbstractSimpleIndexGatewayTests extends AbstractNodesTests
startNode("server1");
logger.info("Running Cluster Health (wait for the shards to startup)");
ClusterHealthResponse clusterHealth = client("server1").admin().cluster().health(clusterHealth().waitForYellowStatus().waitForActiveShards(1)).actionGet();
ClusterHealthResponse clusterHealth = client("server1").admin().cluster().health(clusterHealthRequest().waitForYellowStatus().waitForActiveShards(1)).actionGet();
logger.info("Done Cluster Health, status " + clusterHealth.status());
assertThat(clusterHealth.timedOut(), equalTo(false));
assertThat(clusterHealth.status(), equalTo(ClusterHealthStatus.YELLOW));
// verify that mapping is there
clusterState = client("server1").admin().cluster().state(clusterState()).actionGet();
clusterState = client("server1").admin().cluster().state(clusterStateRequest()).actionGet();
assertThat(clusterState.state().metaData().index("test").mapping("type1"), notNullValue());
logger.info("Getting #1, should not exists");
@ -126,7 +126,7 @@ public abstract class AbstractSimpleIndexGatewayTests extends AbstractNodesTests
startNode("server1");
logger.info("Running Cluster Health (wait for the shards to startup)");
clusterHealth = client("server1").admin().cluster().health(clusterHealth().waitForYellowStatus().waitForActiveShards(1)).actionGet();
clusterHealth = client("server1").admin().cluster().health(clusterHealthRequest().waitForYellowStatus().waitForActiveShards(1)).actionGet();
logger.info("Done Cluster Health, status " + clusterHealth.status());
assertThat(clusterHealth.timedOut(), equalTo(false));
assertThat(clusterHealth.status(), equalTo(ClusterHealthStatus.YELLOW));
@ -155,7 +155,7 @@ public abstract class AbstractSimpleIndexGatewayTests extends AbstractNodesTests
startNode("server1");
logger.info("Running Cluster Health (wait for the shards to startup)");
clusterHealth = client("server1").admin().cluster().health(clusterHealth().waitForYellowStatus().waitForActiveShards(1)).actionGet();
clusterHealth = client("server1").admin().cluster().health(clusterHealthRequest().waitForYellowStatus().waitForActiveShards(1)).actionGet();
logger.info("Done Cluster Health, status " + clusterHealth.status());
assertThat(clusterHealth.timedOut(), equalTo(false));
assertThat(clusterHealth.status(), equalTo(ClusterHealthStatus.YELLOW));

View File

@ -82,7 +82,7 @@ public class IndexLifecycleActionTests extends AbstractNodesTests {
RoutingNode routingNodeEntry1 = clusterState1.readOnlyRoutingNodes().nodesToShards().get(clusterState1.nodes().localNodeId());
assertThat(routingNodeEntry1.numberOfShardsWithState(STARTED), equalTo(11));
clusterState1 = client("server1").admin().cluster().state(clusterState()).actionGet().state();
clusterState1 = client("server1").admin().cluster().state(clusterStateRequest()).actionGet().state();
routingNodeEntry1 = clusterState1.readOnlyRoutingNodes().nodesToShards().get(clusterState1.nodes().localNodeId());
assertThat(routingNodeEntry1.numberOfShardsWithState(STARTED), equalTo(11));
@ -92,7 +92,7 @@ public class IndexLifecycleActionTests extends AbstractNodesTests {
ClusterService clusterService2 = ((InternalNode) node("server2")).injector().getInstance(ClusterService.class);
logger.info("Running Cluster Health");
clusterHealth = client("server1").admin().cluster().health(clusterHealth().waitForGreenStatus().waitForNodes("2")).actionGet();
clusterHealth = client("server1").admin().cluster().health(clusterHealthRequest().waitForGreenStatus().waitForNodes("2")).actionGet();
logger.info("Done Cluster Health, status " + clusterHealth.status());
assertThat(clusterHealth.timedOut(), equalTo(false));
assertThat(clusterHealth.status(), equalTo(ClusterHealthStatus.GREEN));
@ -116,7 +116,7 @@ public class IndexLifecycleActionTests extends AbstractNodesTests {
ClusterService clusterService3 = ((InternalNode) node("server3")).injector().getInstance(ClusterService.class);
logger.info("Running Cluster Health");
clusterHealth = client("server1").admin().cluster().health(clusterHealth().waitForGreenStatus().waitForNodes("3").waitForRelocatingShards(0)).actionGet();
clusterHealth = client("server1").admin().cluster().health(clusterHealthRequest().waitForGreenStatus().waitForNodes("3").waitForRelocatingShards(0)).actionGet();
logger.info("Done Cluster Health, status " + clusterHealth.status());
assertThat(clusterHealth.timedOut(), equalTo(false));
assertThat(clusterHealth.status(), equalTo(ClusterHealthStatus.GREEN));
@ -146,7 +146,7 @@ public class IndexLifecycleActionTests extends AbstractNodesTests {
closeNode("server1");
// verify health
logger.info("Running Cluster Health");
clusterHealth = client("server2").admin().cluster().health(clusterHealth().waitForGreenStatus().waitForRelocatingShards(0).waitForNodes("2")).actionGet();
clusterHealth = client("server2").admin().cluster().health(clusterHealthRequest().waitForGreenStatus().waitForRelocatingShards(0).waitForNodes("2")).actionGet();
logger.info("Done Cluster Health, status " + clusterHealth.status());
assertThat(clusterHealth.timedOut(), equalTo(false));
assertThat(clusterHealth.status(), equalTo(ClusterHealthStatus.GREEN));
@ -200,7 +200,7 @@ public class IndexLifecycleActionTests extends AbstractNodesTests {
assertThat(createIndexResponse.acknowledged(), equalTo(true));
logger.info("Running Cluster Health");
ClusterHealthResponse clusterHealth = client("server1").admin().cluster().health(clusterHealth().waitForGreenStatus()).actionGet();
ClusterHealthResponse clusterHealth = client("server1").admin().cluster().health(clusterHealthRequest().waitForGreenStatus()).actionGet();
logger.info("Done Cluster Health, status " + clusterHealth.status());
assertThat(clusterHealth.timedOut(), equalTo(false));
assertThat(clusterHealth.status(), equalTo(ClusterHealthStatus.GREEN));
@ -218,7 +218,7 @@ public class IndexLifecycleActionTests extends AbstractNodesTests {
Thread.sleep(200);
logger.info("Running Cluster Health");
clusterHealth = client("server1").admin().cluster().health(clusterHealth().waitForGreenStatus().waitForRelocatingShards(0).waitForNodes("2")).actionGet();
clusterHealth = client("server1").admin().cluster().health(clusterHealthRequest().waitForGreenStatus().waitForRelocatingShards(0).waitForNodes("2")).actionGet();
logger.info("Done Cluster Health, status " + clusterHealth.status());
assertThat(clusterHealth.timedOut(), equalTo(false));
assertThat(clusterHealth.status(), equalTo(ClusterHealthStatus.GREEN));
@ -247,7 +247,7 @@ public class IndexLifecycleActionTests extends AbstractNodesTests {
ClusterService clusterService3 = ((InternalNode) node("server3")).injector().getInstance(ClusterService.class);
logger.info("Running Cluster Health");
clusterHealth = client("server1").admin().cluster().health(clusterHealth().waitForGreenStatus().waitForRelocatingShards(0).waitForNodes("3")).actionGet();
clusterHealth = client("server1").admin().cluster().health(clusterHealthRequest().waitForGreenStatus().waitForRelocatingShards(0).waitForNodes("3")).actionGet();
logger.info("Done Cluster Health, status " + clusterHealth.status());
assertThat(clusterHealth.timedOut(), equalTo(false));
assertThat(clusterHealth.status(), equalTo(ClusterHealthStatus.GREEN));
@ -277,7 +277,7 @@ public class IndexLifecycleActionTests extends AbstractNodesTests {
closeNode("server1");
logger.info("Running Cluster Health");
clusterHealth = client("server3").admin().cluster().health(clusterHealth().waitForGreenStatus().waitForNodes("2").waitForRelocatingShards(0)).actionGet();
clusterHealth = client("server3").admin().cluster().health(clusterHealthRequest().waitForGreenStatus().waitForNodes("2").waitForRelocatingShards(0)).actionGet();
logger.info("Done Cluster Health, status " + clusterHealth.status());
assertThat(clusterHealth.timedOut(), equalTo(false));
assertThat(clusterHealth.status(), equalTo(ClusterHealthStatus.GREEN));

View File

@ -0,0 +1,150 @@
/*
* Licensed to Elastic Search and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. Elastic Search 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.test.integration.indices.settings;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus;
import org.elasticsearch.action.count.CountResponse;
import org.elasticsearch.client.Client;
import org.elasticsearch.test.integration.AbstractNodesTests;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import static org.elasticsearch.client.Requests.*;
import static org.elasticsearch.common.settings.ImmutableSettings.*;
import static org.elasticsearch.common.xcontent.XContentFactory.*;
import static org.elasticsearch.index.query.xcontent.QueryBuilders.*;
import static org.hamcrest.MatcherAssert.*;
import static org.hamcrest.Matchers.*;
/**
* @author kimchy (shay.banon)
*/
public class UpdateNumberOfReplicasTests extends AbstractNodesTests {
protected Client client1;
protected Client client2;
@BeforeMethod public void startNodes() {
startNode("node1");
startNode("node2");
client1 = getClient1();
client2 = getClient2();
createIndex();
}
protected void createIndex() {
logger.info("Creating index test");
client1.admin().indices().create(createIndexRequest("test")).actionGet();
}
protected String getConcreteIndexName() {
return "test";
}
@AfterMethod public void closeNodes() {
client1.close();
client2.close();
closeAllNodes();
}
protected Client getClient1() {
return client("node1");
}
protected Client getClient2() {
return client("node2");
}
@Test public void simpleUpdateNumberOfReplicasTests() throws Exception {
logger.info("Running Cluster Health");
ClusterHealthResponse clusterHealth = client1.admin().cluster().prepareHealth().setWaitForGreenStatus().execute().actionGet();
logger.info("Done Cluster Health, status " + clusterHealth.status());
assertThat(clusterHealth.timedOut(), equalTo(false));
assertThat(clusterHealth.status(), equalTo(ClusterHealthStatus.GREEN));
assertThat(clusterHealth.indices().get("test").activePrimaryShards(), equalTo(5));
assertThat(clusterHealth.indices().get("test").numberOfReplicas(), equalTo(1));
assertThat(clusterHealth.indices().get("test").activeShards(), equalTo(10));
for (int i = 0; i < 10; i++) {
client1.prepareIndex("test", "type1", Integer.toString(i)).setSource(jsonBuilder().startObject()
.field("value", "test" + i)
.endObject()).execute().actionGet();
}
client1.admin().indices().prepareRefresh().execute().actionGet();
for (int i = 0; i < 10; i++) {
CountResponse countResponse = client1.prepareCount().setQuery(matchAllQuery()).execute().actionGet();
assertThat(countResponse.count(), equalTo(10l));
}
logger.info("Increasing the number of replicas from 1 to 2");
client1.admin().indices().prepareUpdateSettings("test").setSettings(settingsBuilder().put("index.number_of_replicas", 2)).execute().actionGet();
Thread.sleep(200);
logger.info("Running Cluster Health");
clusterHealth = client1.admin().cluster().prepareHealth().setWaitForYellowStatus().execute().actionGet();
logger.info("Done Cluster Health, status " + clusterHealth.status());
assertThat(clusterHealth.timedOut(), equalTo(false));
assertThat(clusterHealth.status(), equalTo(ClusterHealthStatus.YELLOW));
assertThat(clusterHealth.indices().get("test").activePrimaryShards(), equalTo(5));
assertThat(clusterHealth.indices().get("test").numberOfReplicas(), equalTo(2));
assertThat(clusterHealth.indices().get("test").activeShards(), equalTo(10));
logger.info("starting another node to new replicas will be allocated to it");
startNode("node3");
Thread.sleep(100);
logger.info("Running Cluster Health");
clusterHealth = client1.admin().cluster().prepareHealth().setWaitForGreenStatus().setWaitForNodes("3").execute().actionGet();
logger.info("Done Cluster Health, status " + clusterHealth.status());
assertThat(clusterHealth.timedOut(), equalTo(false));
assertThat(clusterHealth.status(), equalTo(ClusterHealthStatus.GREEN));
assertThat(clusterHealth.indices().get("test").activePrimaryShards(), equalTo(5));
assertThat(clusterHealth.indices().get("test").numberOfReplicas(), equalTo(2));
assertThat(clusterHealth.indices().get("test").activeShards(), equalTo(15));
for (int i = 0; i < 10; i++) {
CountResponse countResponse = client1.prepareCount().setQuery(matchAllQuery()).execute().actionGet();
assertThat(countResponse.count(), equalTo(10l));
}
logger.info("Decreasing number of replicas from 2 to 0");
client1.admin().indices().prepareUpdateSettings("test").setSettings(settingsBuilder().put("index.number_of_replicas", 0)).execute().actionGet();
Thread.sleep(200);
logger.info("Running Cluster Health");
clusterHealth = client1.admin().cluster().prepareHealth().setWaitForGreenStatus().setWaitForNodes("3").execute().actionGet();
logger.info("Done Cluster Health, status " + clusterHealth.status());
assertThat(clusterHealth.timedOut(), equalTo(false));
assertThat(clusterHealth.status(), equalTo(ClusterHealthStatus.GREEN));
assertThat(clusterHealth.indices().get("test").activePrimaryShards(), equalTo(5));
assertThat(clusterHealth.indices().get("test").numberOfReplicas(), equalTo(0));
assertThat(clusterHealth.indices().get("test").activeShards(), equalTo(5));
for (int i = 0; i < 10; i++) {
CountResponse countResponse = client1.prepareCount().setQuery(matchAllQuery()).execute().actionGet();
assertThat(countResponse.count(), equalTo(10l));
}
}
}

View File

@ -50,24 +50,24 @@ public class SimpleNodesInfoTests extends AbstractNodesTests {
assertThat(response.nodesMap().get(server1NodeId), notNullValue());
assertThat(response.nodesMap().get(server2NodeId), notNullValue());
response = client("server2").admin().cluster().nodesInfo(nodesInfo()).actionGet();
response = client("server2").admin().cluster().nodesInfo(nodesInfoRequest()).actionGet();
assertThat(response.nodes().length, equalTo(2));
assertThat(response.nodesMap().get(server1NodeId), notNullValue());
assertThat(response.nodesMap().get(server2NodeId), notNullValue());
response = client("server1").admin().cluster().nodesInfo(nodesInfo(server1NodeId)).actionGet();
response = client("server1").admin().cluster().nodesInfo(nodesInfoRequest(server1NodeId)).actionGet();
assertThat(response.nodes().length, equalTo(1));
assertThat(response.nodesMap().get(server1NodeId), notNullValue());
response = client("server2").admin().cluster().nodesInfo(nodesInfo(server1NodeId)).actionGet();
response = client("server2").admin().cluster().nodesInfo(nodesInfoRequest(server1NodeId)).actionGet();
assertThat(response.nodes().length, equalTo(1));
assertThat(response.nodesMap().get(server1NodeId), notNullValue());
response = client("server1").admin().cluster().nodesInfo(nodesInfo(server2NodeId)).actionGet();
response = client("server1").admin().cluster().nodesInfo(nodesInfoRequest(server2NodeId)).actionGet();
assertThat(response.nodes().length, equalTo(1));
assertThat(response.nodesMap().get(server2NodeId), notNullValue());
response = client("server2").admin().cluster().nodesInfo(nodesInfo(server2NodeId)).actionGet();
response = client("server2").admin().cluster().nodesInfo(nodesInfoRequest(server2NodeId)).actionGet();
assertThat(response.nodes().length, equalTo(1));
assertThat(response.nodesMap().get(server2NodeId), notNullValue());
}

View File

@ -47,7 +47,7 @@ public class SimpleRecoveryTests extends AbstractNodesTests {
client("server1").admin().indices().create(createIndexRequest("test")).actionGet(5000);
logger.info("Running Cluster Health");
ClusterHealthResponse clusterHealth = client("server1").admin().cluster().health(clusterHealth().waitForYellowStatus()).actionGet();
ClusterHealthResponse clusterHealth = client("server1").admin().cluster().health(clusterHealthRequest().waitForYellowStatus()).actionGet();
logger.info("Done Cluster Health, status " + clusterHealth.status());
assertThat(clusterHealth.timedOut(), equalTo(false));
assertThat(clusterHealth.status(), equalTo(ClusterHealthStatus.YELLOW));
@ -66,7 +66,7 @@ public class SimpleRecoveryTests extends AbstractNodesTests {
startNode("server2");
logger.info("Running Cluster Health");
clusterHealth = client("server1").admin().cluster().health(clusterHealth().waitForGreenStatus()).actionGet();
clusterHealth = client("server1").admin().cluster().health(clusterHealthRequest().waitForGreenStatus()).actionGet();
logger.info("Done Cluster Health, status " + clusterHealth.status());
assertThat(clusterHealth.timedOut(), equalTo(false));
assertThat(clusterHealth.status(), equalTo(ClusterHealthStatus.GREEN));
@ -88,7 +88,7 @@ public class SimpleRecoveryTests extends AbstractNodesTests {
startNode("server3");
Thread.sleep(200);
logger.info("Running Cluster Health");
clusterHealth = client("server1").admin().cluster().health(clusterHealth().waitForGreenStatus().waitForRelocatingShards(0).waitForNodes("3")).actionGet();
clusterHealth = client("server1").admin().cluster().health(clusterHealthRequest().waitForGreenStatus().waitForRelocatingShards(0).waitForNodes("3")).actionGet();
logger.info("Done Cluster Health, status " + clusterHealth.status());
assertThat(clusterHealth.timedOut(), equalTo(false));
assertThat(clusterHealth.status(), equalTo(ClusterHealthStatus.GREEN));

View File

@ -80,7 +80,7 @@ public class RestHttpDocumentActions extends AbstractNodesTests {
@Test public void testSimpleActions() throws IOException, ExecutionException, InterruptedException {
logger.info("Running Cluster Health");
ClusterHealthResponse clusterHealth = client1.admin().cluster().health(clusterHealth().waitForGreenStatus()).actionGet();
ClusterHealthResponse clusterHealth = client1.admin().cluster().health(clusterHealthRequest().waitForGreenStatus()).actionGet();
logger.info("Done Cluster Health, status " + clusterHealth.status());
assertThat(clusterHealth.timedOut(), equalTo(false));
assertThat(clusterHealth.status(), equalTo(ClusterHealthStatus.GREEN));

View File

@ -78,7 +78,7 @@ public class TransportSearchFailuresTests extends AbstractNodesTests {
assertThat(client("server1").admin().cluster().prepareHealth().setWaitForNodes("2").execute().actionGet().timedOut(), equalTo(false));
logger.info("Running Cluster Health");
ClusterHealthResponse clusterHealth = client("server1").admin().cluster().health(clusterHealth("test")
ClusterHealthResponse clusterHealth = client("server1").admin().cluster().health(clusterHealthRequest("test")
.waitForYellowStatus().waitForRelocatingShards(0).waitForActiveShards(6)).actionGet();
logger.info("Done Cluster Health, status " + clusterHealth.status());
assertThat(clusterHealth.timedOut(), equalTo(false));

View File

@ -38,6 +38,8 @@ import org.elasticsearch.action.admin.indices.optimize.OptimizeRequest
import org.elasticsearch.action.admin.indices.optimize.OptimizeResponse
import org.elasticsearch.action.admin.indices.refresh.RefreshRequest
import org.elasticsearch.action.admin.indices.refresh.RefreshResponse
import org.elasticsearch.action.admin.indices.settings.UpdateSettingsRequest
import org.elasticsearch.action.admin.indices.settings.UpdateSettingsResponse
import org.elasticsearch.action.admin.indices.status.IndicesStatusRequest
import org.elasticsearch.action.admin.indices.status.IndicesStatusResponse
import org.elasticsearch.client.IndicesAdminClient
@ -50,6 +52,7 @@ import org.elasticsearch.client.action.admin.indices.gateway.snapshot.GatewaySna
import org.elasticsearch.client.action.admin.indices.mapping.put.PutMappingRequestBuilder
import org.elasticsearch.client.action.admin.indices.optimize.OptimizeRequestBuilder
import org.elasticsearch.client.action.admin.indices.refresh.RefreshRequestBuilder
import org.elasticsearch.client.action.admin.indices.settings.UpdateSettingsRequestBuilder
import org.elasticsearch.client.action.admin.indices.status.IndicesStatusRequestBuilder
import org.elasticsearch.client.internal.InternalClient
import org.elasticsearch.groovy.client.action.GActionFuture
@ -95,6 +98,19 @@ class GIndicesAdminClient {
PutMappingRequestBuilder.metaClass.source = {Closure c ->
delegate.setSource(new GXContentBuilder().buildAsString(c))
}
UpdateSettingsRequest.metaClass.setSettings = {Closure c ->
delegate.settings(new GXContentBuilder().buildAsString(c))
}
UpdateSettingsRequest.metaClass.settings = {Closure c ->
delegate.settings(new GXContentBuilder().buildAsString(c))
}
UpdateSettingsRequestBuilder.metaClass.setSettings = {Closure c ->
delegate.setSettings(new GXContentBuilder().buildAsString(c))
}
UpdateSettingsRequestBuilder.metaClass.settings = {Closure c ->
delegate.setSettings(new GXContentBuilder().buildAsString(c))
}
}
private final GClient gClient
@ -325,6 +341,10 @@ class GIndicesAdminClient {
indicesAdminClient.aliases(request, listener)
}
void aliases(ClearIndicesCacheRequest request, ActionListener<ClearIndicesCacheResponse> listener) {
indicesAdminClient.clearCache(request, listener)
}
// CLEAR CACHE
ClearIndicesCacheRequestBuilder prepareClearCache(String... indices) {
@ -345,7 +365,23 @@ class GIndicesAdminClient {
return future
}
void aliases(ClearIndicesCacheRequest request, ActionListener<ClearIndicesCacheResponse> listener) {
indicesAdminClient.clearCache(request, listener)
// UPDATE SETTINGS
UpdateSettingsRequestBuilder prepareUpdateSettings(String... indices) {
indicesAdminClient.prepareUpdateSettings(indices)
}
GActionFuture<UpdateSettingsResponse> updateSettings(Closure c) {
UpdateSettingsRequest request = new UpdateSettingsRequest()
c.setDelegate request
c.resolveStrategy = gClient.resolveStrategy
c.call()
updateSettings(request)
}
GActionFuture<UpdateSettingsResponse> updateSettings(UpdateSettingsRequest request) {
GActionFuture<UpdateSettingsResponse> future = new GActionFuture<UpdateSettingsResponse>(internalClient.threadPool(), request);
indicesAdminClient.updateSettings(request, future)
return future
}
}

View File

@ -89,7 +89,7 @@ public class HdfsGatewayTests {
}
logger.info("Running Cluster Health (wait for the shards to startup)");
ClusterHealthResponse clusterHealth = node.client().admin().cluster().health(clusterHealth().waitForYellowStatus().waitForActiveShards(1)).actionGet();
ClusterHealthResponse clusterHealth = node.client().admin().cluster().health(clusterHealthRequest().waitForYellowStatus().waitForActiveShards(1)).actionGet();
logger.info("Done Cluster Health, status " + clusterHealth.status());
assertThat(clusterHealth.timedOut(), equalTo(false));
assertThat(clusterHealth.status(), equalTo(ClusterHealthStatus.YELLOW));
@ -101,7 +101,7 @@ public class HdfsGatewayTests {
assertThat(putMappingResponse.acknowledged(), equalTo(true));
// verify that mapping is there
ClusterStateResponse clusterState = node.client().admin().cluster().state(clusterState()).actionGet();
ClusterStateResponse clusterState = node.client().admin().cluster().state(clusterStateRequest()).actionGet();
assertThat(clusterState.state().metaData().index("test").mapping("type1"), notNullValue());
// create two and delete the first
@ -125,13 +125,13 @@ public class HdfsGatewayTests {
node = buildNode().start();
logger.info("Running Cluster Health (wait for the shards to startup)");
clusterHealth = node.client().admin().cluster().health(clusterHealth().waitForYellowStatus().waitForActiveShards(1)).actionGet();
clusterHealth = node.client().admin().cluster().health(clusterHealthRequest().waitForYellowStatus().waitForActiveShards(1)).actionGet();
logger.info("Done Cluster Health, status " + clusterHealth.status());
assertThat(clusterHealth.timedOut(), equalTo(false));
assertThat(clusterHealth.status(), equalTo(ClusterHealthStatus.YELLOW));
// verify that mapping is there
clusterState = node.client().admin().cluster().state(clusterState()).actionGet();
clusterState = node.client().admin().cluster().state(clusterStateRequest()).actionGet();
assertThat(clusterState.state().metaData().index("test").mapping("type1"), notNullValue());
logger.info("Getting #1, should not exists");
@ -158,7 +158,7 @@ public class HdfsGatewayTests {
node = buildNode().start();
logger.info("Running Cluster Health (wait for the shards to startup)");
clusterHealth = node.client().admin().cluster().health(clusterHealth().waitForYellowStatus().waitForActiveShards(1)).actionGet();
clusterHealth = node.client().admin().cluster().health(clusterHealthRequest().waitForYellowStatus().waitForActiveShards(1)).actionGet();
logger.info("Done Cluster Health, status " + clusterHealth.status());
assertThat(clusterHealth.timedOut(), equalTo(false));
assertThat(clusterHealth.status(), equalTo(ClusterHealthStatus.YELLOW));
@ -187,7 +187,7 @@ public class HdfsGatewayTests {
node = buildNode().start();
logger.info("Running Cluster Health (wait for the shards to startup)");
clusterHealth = node.client().admin().cluster().health(clusterHealth().waitForYellowStatus().waitForActiveShards(1)).actionGet();
clusterHealth = node.client().admin().cluster().health(clusterHealthRequest().waitForYellowStatus().waitForActiveShards(1)).actionGet();
logger.info("Done Cluster Health, status " + clusterHealth.status());
assertThat(clusterHealth.timedOut(), equalTo(false));
assertThat(clusterHealth.status(), equalTo(ClusterHealthStatus.YELLOW));

View File

@ -58,7 +58,7 @@ public class SimpleAttachmentIntegrationTests {
logger.info("creating index [test]");
node.client().admin().indices().create(createIndexRequest("test").settings(settingsBuilder().put("index.numberOfReplicas", 0))).actionGet();
logger.info("Running Cluster Health");
ClusterHealthResponse clusterHealth = node.client().admin().cluster().health(clusterHealth().waitForGreenStatus()).actionGet();
ClusterHealthResponse clusterHealth = node.client().admin().cluster().health(clusterHealthRequest().waitForGreenStatus()).actionGet();
logger.info("Done Cluster Health, status " + clusterHealth.status());
assertThat(clusterHealth.timedOut(), equalTo(false));
assertThat(clusterHealth.status(), equalTo(ClusterHealthStatus.GREEN));