Permalink
Browse files

Cluster Update Settings API, closes #1266.

  • Loading branch information...
kimchy committed Aug 20, 2011
1 parent a83c45b commit 03217c460abcca893c00a6a09fc6bc2dcc19e410
Showing with 1,029 additions and 32 deletions.
  1. +2 −0 modules/elasticsearch/src/main/java/org/elasticsearch/action/TransportActionModule.java
  2. +1 −0 modules/elasticsearch/src/main/java/org/elasticsearch/action/TransportActions.java
  3. +130 −0 ...h/src/main/java/org/elasticsearch/action/admin/cluster/settings/ClusterUpdateSettingsRequest.java
  4. +42 −0 .../src/main/java/org/elasticsearch/action/admin/cluster/settings/ClusterUpdateSettingsResponse.java
  5. +126 −0 ...in/java/org/elasticsearch/action/admin/cluster/settings/TransportClusterUpdateSettingsAction.java
  6. +18 −0 modules/elasticsearch/src/main/java/org/elasticsearch/client/ClusterAdminClient.java
  7. +5 −0 modules/elasticsearch/src/main/java/org/elasticsearch/client/Requests.java
  8. +99 −0 ...a/org/elasticsearch/client/action/admin/cluster/settings/ClusterUpdateSettingsRequestBuilder.java
  9. +15 −1 modules/elasticsearch/src/main/java/org/elasticsearch/client/node/NodeClusterAdminClient.java
  10. +5 −0 modules/elasticsearch/src/main/java/org/elasticsearch/client/support/AbstractClusterAdminClient.java
  11. +2 −0 ...icsearch/src/main/java/org/elasticsearch/client/transport/action/ClientTransportActionModule.java
  12. +41 −0 ...ch/client/transport/action/admin/cluster/settings/ClientTransportClusterUpdateSettingsAction.java
  13. +23 −1 ...src/main/java/org/elasticsearch/client/transport/support/InternalTransportClusterAdminClient.java
  14. +17 −2 modules/elasticsearch/src/main/java/org/elasticsearch/cluster/ClusterModule.java
  15. +75 −3 modules/elasticsearch/src/main/java/org/elasticsearch/cluster/metadata/MetaData.java
  16. +3 −2 ...les/elasticsearch/src/main/java/org/elasticsearch/cluster/routing/allocation/NodeAllocations.java
  17. +2 −1 ...es/elasticsearch/src/main/java/org/elasticsearch/cluster/routing/allocation/ShardsAllocation.java
  18. +30 −3 ...icsearch/src/main/java/org/elasticsearch/cluster/routing/allocation/ThrottlingNodeAllocation.java
  19. +12 −1 modules/elasticsearch/src/main/java/org/elasticsearch/cluster/service/InternalClusterService.java
  20. +99 −0 modules/elasticsearch/src/main/java/org/elasticsearch/cluster/settings/ClusterSettingsService.java
  21. +2 −0 modules/elasticsearch/src/main/java/org/elasticsearch/common/logging/ESLogger.java
  22. +14 −0 modules/elasticsearch/src/main/java/org/elasticsearch/common/logging/jdk/JdkESLogger.java
  23. +14 −0 modules/elasticsearch/src/main/java/org/elasticsearch/common/logging/log4j/Log4jESLogger.java
  24. +4 −0 modules/elasticsearch/src/main/java/org/elasticsearch/common/logging/slf4j/Slf4jESLogger.java
  25. +3 −2 modules/elasticsearch/src/main/java/org/elasticsearch/discovery/zen/ZenDiscovery.java
  26. +20 −2 modules/elasticsearch/src/main/java/org/elasticsearch/discovery/zen/elect/ElectMasterService.java
  27. +2 −0 modules/elasticsearch/src/main/java/org/elasticsearch/gateway/GatewayService.java
  28. +31 −6 modules/elasticsearch/src/main/java/org/elasticsearch/index/shard/recovery/RecoverySource.java
  29. +0 −6 modules/elasticsearch/src/main/java/org/elasticsearch/rest/XContentRestResponse.java
  30. +4 −0 modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/RestActionModule.java
  31. +90 −0 .../main/java/org/elasticsearch/rest/action/admin/cluster/settings/RestClusterGetSettingsAction.java
  32. +95 −0 ...in/java/org/elasticsearch/rest/action/admin/cluster/settings/RestClusterUpdateSettingsAction.java
  33. +3 −2 plugins/cloud/aws/src/main/java/org/elasticsearch/discovery/ec2/Ec2Discovery.java
@@ -29,6 +29,7 @@
import org.elasticsearch.action.admin.cluster.ping.replication.TransportReplicationPingAction;
import org.elasticsearch.action.admin.cluster.ping.replication.TransportShardReplicationPingAction;
import org.elasticsearch.action.admin.cluster.ping.single.TransportSinglePingAction;
import org.elasticsearch.action.admin.cluster.settings.TransportClusterUpdateSettingsAction;
import org.elasticsearch.action.admin.cluster.state.TransportClusterStateAction;
import org.elasticsearch.action.admin.indices.alias.TransportIndicesAliasesAction;
import org.elasticsearch.action.admin.indices.analyze.TransportAnalyzeAction;
@@ -90,6 +91,7 @@
bind(TransportNodesRestartAction.class).asEagerSingleton();
bind(TransportClusterStateAction.class).asEagerSingleton();
bind(TransportClusterHealthAction.class).asEagerSingleton();
bind(TransportClusterUpdateSettingsAction.class).asEagerSingleton();
bind(TransportSinglePingAction.class).asEagerSingleton();
bind(TransportBroadcastPingAction.class).asEagerSingleton();
@@ -85,6 +85,7 @@
public static final String STATE = "/cluster/state";
public static final String HEALTH = "/cluster/health";
public static final String UPDATE_SETTINGS = "/cluster/updateSettings";
public static class Node {
public static final String INFO = "/cluster/nodes/info";
@@ -0,0 +1,130 @@
/*
* 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.cluster.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.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.XContentType;
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.*;
/**
*/
public class ClusterUpdateSettingsRequest extends MasterNodeOperationRequest {
private Settings transientSettings = EMPTY_SETTINGS;
private Settings persistentSettings = EMPTY_SETTINGS;
public ClusterUpdateSettingsRequest() {
}
@Override public ActionRequestValidationException validate() {
ActionRequestValidationException validationException = null;
if (transientSettings.getAsMap().isEmpty() && persistentSettings.getAsMap().isEmpty()) {
validationException = addValidationError("no settings to update", validationException);
}
return validationException;
}
Settings transientSettings() {
return transientSettings;
}
Settings persistentSettings() {
return persistentSettings;
}
public ClusterUpdateSettingsRequest transientSettings(Settings settings) {
this.transientSettings = settings;
return this;
}
public ClusterUpdateSettingsRequest transientSettings(Settings.Builder settings) {
this.transientSettings = settings.build();
return this;
}
public ClusterUpdateSettingsRequest transientSettings(String source) {
this.transientSettings = ImmutableSettings.settingsBuilder().loadFromSource(source).build();
return this;
}
public ClusterUpdateSettingsRequest transientSettings(Map source) {
try {
XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
builder.map(source);
transientSettings(builder.string());
} catch (IOException e) {
throw new ElasticSearchGenerationException("Failed to generate [" + source + "]", e);
}
return this;
}
public ClusterUpdateSettingsRequest persistentSettings(Settings settings) {
this.persistentSettings = settings;
return this;
}
public ClusterUpdateSettingsRequest persistentSettings(Settings.Builder settings) {
this.persistentSettings = settings.build();
return this;
}
public ClusterUpdateSettingsRequest persistentSettings(String source) {
this.persistentSettings = ImmutableSettings.settingsBuilder().loadFromSource(source).build();
return this;
}
public ClusterUpdateSettingsRequest persistentSettings(Map source) {
try {
XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
builder.map(source);
persistentSettings(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);
transientSettings = readSettingsFromStream(in);
persistentSettings = readSettingsFromStream(in);
}
@Override public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
writeSettingsToStream(transientSettings, out);
writeSettingsToStream(persistentSettings, out);
}
}
@@ -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.action.admin.cluster.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 cluster update settings action.
*/
public class ClusterUpdateSettingsResponse implements ActionResponse, Streamable {
ClusterUpdateSettingsResponse() {
}
@Override public void readFrom(StreamInput in) throws IOException {
}
@Override public void writeTo(StreamOutput out) throws IOException {
}
}
@@ -0,0 +1,126 @@
/*
* 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.cluster.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.ClusterStateUpdateTask;
import org.elasticsearch.cluster.metadata.MetaData;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.transport.TransportService;
import java.util.Map;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicReference;
/**
* @author kimchy (shay.banon)
*/
public class TransportClusterUpdateSettingsAction extends TransportMasterNodeOperationAction<ClusterUpdateSettingsRequest, ClusterUpdateSettingsResponse> {
@Inject public TransportClusterUpdateSettingsAction(Settings settings, TransportService transportService, ClusterService clusterService, ThreadPool threadPool) {
super(settings, transportService, clusterService, threadPool);
}
@Override protected String executor() {
return ThreadPool.Names.MANAGEMENT;
}
@Override protected String transportAction() {
return TransportActions.Admin.Cluster.UPDATE_SETTINGS;
}
@Override protected ClusterUpdateSettingsRequest newRequest() {
return new ClusterUpdateSettingsRequest();
}
@Override protected ClusterUpdateSettingsResponse newResponse() {
return new ClusterUpdateSettingsResponse();
}
@Override protected ClusterUpdateSettingsResponse masterOperation(final ClusterUpdateSettingsRequest request, ClusterState state) throws ElasticSearchException {
final AtomicReference<Throwable> failureRef = new AtomicReference<Throwable>();
final CountDownLatch latch = new CountDownLatch(1);
clusterService.submitStateUpdateTask("cluster_update_settings", new ClusterStateUpdateTask() {
@Override public ClusterState execute(ClusterState currentState) {
try {
boolean changed = false;
ImmutableSettings.Builder transientSettings = ImmutableSettings.settingsBuilder();
transientSettings.put(currentState.metaData().transientSettings());
for (Map.Entry<String, String> entry : request.transientSettings().getAsMap().entrySet()) {
if (MetaData.dynamicSettings().contains(entry.getKey()) || entry.getKey().startsWith("logger.")) {
transientSettings.put(entry.getKey(), entry.getValue());
changed = true;
} else {
logger.warn("ignoring transient setting [{}], not dynamically updateable", entry.getKey());
}
}
ImmutableSettings.Builder persistentSettings = ImmutableSettings.settingsBuilder();
persistentSettings.put(currentState.metaData().persistentSettings());
for (Map.Entry<String, String> entry : request.persistentSettings().getAsMap().entrySet()) {
if (MetaData.dynamicSettings().contains(entry.getKey()) || entry.getKey().startsWith("logger.")) {
changed = true;
persistentSettings.put(entry.getKey(), entry.getValue());
} else {
logger.warn("ignoring persistent setting [{}], not dynamically updateable", entry.getKey());
}
}
if (!changed) {
return currentState;
}
MetaData.Builder metaData = MetaData.builder().metaData(currentState.metaData())
.persistentSettings(persistentSettings.build())
.transientSettings(transientSettings.build());
return ClusterState.builder().state(currentState).metaData(metaData).build();
} finally {
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 ClusterUpdateSettingsResponse();
}
}
@@ -37,6 +37,8 @@
import org.elasticsearch.action.admin.cluster.ping.replication.ReplicationPingResponse;
import org.elasticsearch.action.admin.cluster.ping.single.SinglePingRequest;
import org.elasticsearch.action.admin.cluster.ping.single.SinglePingResponse;
import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest;
import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsResponse;
import org.elasticsearch.action.admin.cluster.state.ClusterStateRequest;
import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse;
import org.elasticsearch.client.action.admin.cluster.health.ClusterHealthRequestBuilder;
@@ -47,6 +49,7 @@
import org.elasticsearch.client.action.admin.cluster.ping.broadcast.BroadcastPingRequestBuilder;
import org.elasticsearch.client.action.admin.cluster.ping.replication.ReplicationPingRequestBuilder;
import org.elasticsearch.client.action.admin.cluster.ping.single.SinglePingRequestBuilder;
import org.elasticsearch.client.action.admin.cluster.settings.ClusterUpdateSettingsRequestBuilder;
import org.elasticsearch.client.action.admin.cluster.state.ClusterStateRequestBuilder;
/**
@@ -103,6 +106,21 @@
*/
ClusterStateRequestBuilder prepareState();
/**
* Updates settings in the cluster.
*/
ActionFuture<ClusterUpdateSettingsResponse> updateSettings(ClusterUpdateSettingsRequest request);
/**
* Update settings in the cluster.
*/
void updateSettings(ClusterUpdateSettingsRequest request, ActionListener<ClusterUpdateSettingsResponse> listener);
/**
* Update settings in the cluster.
*/
ClusterUpdateSettingsRequestBuilder prepareUpdateSettings();
/**
* Nodes info of the cluster.
*
@@ -27,6 +27,7 @@
import org.elasticsearch.action.admin.cluster.ping.broadcast.BroadcastPingRequest;
import org.elasticsearch.action.admin.cluster.ping.replication.ReplicationPingRequest;
import org.elasticsearch.action.admin.cluster.ping.single.SinglePingRequest;
import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest;
import org.elasticsearch.action.admin.cluster.state.ClusterStateRequest;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest;
import org.elasticsearch.action.admin.indices.cache.clear.ClearIndicesCacheRequest;
@@ -353,6 +354,10 @@ public static ClusterStateRequest clusterStateRequest() {
return new ClusterStateRequest();
}
public static ClusterUpdateSettingsRequest clusterUpdateSettingsRequest() {
return new ClusterUpdateSettingsRequest();
}
/**
* Creates a cluster health request.
*
Oops, something went wrong.

0 comments on commit 03217c4

Please sign in to comment.