Skip to content

Commit

Permalink
Added support for acknowledgement in update index settings api
Browse files Browse the repository at this point in the history
Added support for serialization based on version to AcknowledgedResponse. Useful in api that don't support yet the acknowledged flag in the response.
Moved also ack warmer tests to more specific AckTests class

Close #3983
  • Loading branch information
javanna committed Oct 29, 2013
1 parent 7309832 commit ef18e72
Show file tree
Hide file tree
Showing 22 changed files with 507 additions and 164 deletions.
Expand Up @@ -24,6 +24,8 @@
import org.elasticsearch.action.support.master.TransportMasterNodeOperationAction;
import org.elasticsearch.cluster.ClusterService;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.ack.ClusterStateUpdateListener;
import org.elasticsearch.cluster.ack.ClusterStateUpdateResponse;
import org.elasticsearch.cluster.metadata.MetaDataUpdateSettingsService;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
Expand Down Expand Up @@ -67,10 +69,17 @@ protected UpdateSettingsResponse newResponse() {

@Override
protected void masterOperation(final UpdateSettingsRequest request, final ClusterState state, final ActionListener<UpdateSettingsResponse> listener) throws ElasticSearchException {
updateSettingsService.updateSettings(request.settings(), request.indices(), request.masterNodeTimeout(), new MetaDataUpdateSettingsService.Listener() {

UpdateSettingsClusterStateUpdateRequest clusterStateUpdateRequest = new UpdateSettingsClusterStateUpdateRequest()
.indices(request.indices())
.settings(request.settings())
.ackTimeout(request.timeout())
.masterNodeTimeout(request.masterNodeTimeout());

updateSettingsService.updateSettings(clusterStateUpdateRequest, new ClusterStateUpdateListener() {
@Override
public void onSuccess() {
listener.onResponse(new UpdateSettingsResponse());
public void onResponse(ClusterStateUpdateResponse response) {
listener.onResponse(new UpdateSettingsResponse(response.isAcknowledged()));
}

@Override
Expand Down
@@ -0,0 +1,65 @@
/*
* Licensed to ElasticSearch and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. ElasticSearch licenses this
* file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.elasticsearch.action.admin.indices.settings;

import org.elasticsearch.cluster.ack.ClusterStateUpdateRequest;
import org.elasticsearch.common.settings.Settings;

/**
* Cluster state update request that allows to update settings for some indices
*/
public class UpdateSettingsClusterStateUpdateRequest extends ClusterStateUpdateRequest<UpdateSettingsClusterStateUpdateRequest> {
private Settings settings;
private String[] indices;

public UpdateSettingsClusterStateUpdateRequest() {

}

/**
* Returns the indices that needs to be updated
*/
public String[] indices() {
return indices;
}

/**
* Sets the indices to update
*/
public UpdateSettingsClusterStateUpdateRequest indices(String[] indices) {
this.indices = indices;
return this;
}

/**
* Returns the {@link Settings} to update
*/
public Settings settings() {
return settings;
}

/**
* Sets the {@link Settings} to update
*/
public UpdateSettingsClusterStateUpdateRequest settings(Settings settings) {
this.settings = settings;
return this;
}
}
Expand Up @@ -20,8 +20,9 @@
package org.elasticsearch.action.admin.indices.settings;

import org.elasticsearch.ElasticSearchGenerationException;
import org.elasticsearch.Version;
import org.elasticsearch.action.ActionRequestValidationException;
import org.elasticsearch.action.support.master.MasterNodeOperationRequest;
import org.elasticsearch.action.support.master.AcknowledgedRequest;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.settings.ImmutableSettings;
Expand All @@ -39,9 +40,9 @@
import static org.elasticsearch.common.settings.ImmutableSettings.writeSettingsToStream;

/**
*
* Request for an update index settings action
*/
public class UpdateSettingsRequest extends MasterNodeOperationRequest<UpdateSettingsRequest> {
public class UpdateSettingsRequest extends AcknowledgedRequest<UpdateSettingsRequest> {

private String[] indices;

Expand All @@ -51,14 +52,14 @@ public class UpdateSettingsRequest extends MasterNodeOperationRequest<UpdateSett
}

/**
* Constructs a new request to create an index with the specified name and settings.
* Constructs a new request to update settings for one or more indices
*/
public UpdateSettingsRequest(String... indices) {
this.indices = indices;
}

/**
* Constructs a new request to create an index with the specified name and settings.
* Constructs a new request to update settings for one or more indices
*/
public UpdateSettingsRequest(Settings settings, String... indices) {
this.indices = indices;
Expand All @@ -82,38 +83,42 @@ Settings settings() {
return settings;
}

/**
* Sets the indices to apply to settings update to
*/
public UpdateSettingsRequest indices(String... indices) {
this.indices = indices;
return this;
}

/**
* The settings to created the index with.
* Sets the settings to be updated
*/
public UpdateSettingsRequest settings(Settings settings) {
this.settings = settings;
return this;
}

/**
* The settings to created the index with.
* Sets the settings to be updated
*/
public UpdateSettingsRequest settings(Settings.Builder settings) {
this.settings = settings.build();
return this;
}

/**
* The settings to crete the index with (either json/yaml/properties format)
* Sets the settings to be updated (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)
* Sets the settings to be updated (either json/yaml/properties format)
*/
@SuppressWarnings("unchecked")
public UpdateSettingsRequest settings(Map source) {
try {
XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
Expand All @@ -130,12 +135,14 @@ public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
indices = in.readStringArray();
settings = readSettingsFromStream(in);
readTimeout(in, Version.V_0_90_6);
}

@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeStringArrayNullable(indices);
writeSettingsToStream(settings, out);
writeTimeout(out, Version.V_0_90_6);
}
}
Expand Up @@ -20,53 +20,56 @@
package org.elasticsearch.action.admin.indices.settings;

import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.support.master.MasterNodeOperationRequestBuilder;
import org.elasticsearch.action.support.master.AcknowledgedRequestBuilder;
import org.elasticsearch.client.IndicesAdminClient;
import org.elasticsearch.client.internal.InternalIndicesAdminClient;
import org.elasticsearch.common.settings.Settings;

import java.util.Map;

/**
*
* Builder for an update index settings request
*/
public class UpdateSettingsRequestBuilder extends MasterNodeOperationRequestBuilder<UpdateSettingsRequest, UpdateSettingsResponse, UpdateSettingsRequestBuilder> {
public class UpdateSettingsRequestBuilder extends AcknowledgedRequestBuilder<UpdateSettingsRequest, UpdateSettingsResponse, UpdateSettingsRequestBuilder> {

public UpdateSettingsRequestBuilder(IndicesAdminClient indicesClient, String... indices) {
super((InternalIndicesAdminClient) indicesClient, new UpdateSettingsRequest(indices));
}

/**
* Sets the indices the update settings will execute on
*/
public UpdateSettingsRequestBuilder setIndices(String... indices) {
request.indices(indices);
return this;
}

/**
* The settings update.
* Sets the settings to be updated
*/
public UpdateSettingsRequestBuilder setSettings(Settings settings) {
request.settings(settings);
return this;
}

/**
* The settings to update.
* Sets the settings to be updated
*/
public UpdateSettingsRequestBuilder setSettings(Settings.Builder settings) {
request.settings(settings);
return this;
}

/**
* The settings to update (either json/yaml/properties format)
* Sets the settings to be updated (either json/yaml/properties format)
*/
public UpdateSettingsRequestBuilder setSettings(String source) {
request.settings(source);
return this;
}

/**
* The settings to update (either json/yaml/properties format)
* Sets the settings to be updated (either json/yaml/properties format)
*/
public UpdateSettingsRequestBuilder setSettings(Map<String, Object> source) {
request.settings(source);
Expand Down
Expand Up @@ -19,27 +19,34 @@

package org.elasticsearch.action.admin.indices.settings;

import org.elasticsearch.action.ActionResponse;
import org.elasticsearch.Version;
import org.elasticsearch.action.support.master.AcknowledgedResponse;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;

import java.io.IOException;

/**
* A response for a update settings action.
* A response for an update index settings action
*/
public class UpdateSettingsResponse extends ActionResponse {
public class UpdateSettingsResponse extends AcknowledgedResponse {

UpdateSettingsResponse() {
}

UpdateSettingsResponse(boolean acknowledged) {
super(acknowledged);
}

@Override
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
readAcknowledged(in, Version.V_0_90_6);
}

@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
writeAcknowledged(out, Version.V_0_90_6);
}
}
Expand Up @@ -26,12 +26,9 @@
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.unit.TimeValue;

import java.io.IOException;

import static org.elasticsearch.common.unit.TimeValue.timeValueSeconds;

/**
* A request to delete an index warmer.
*/
Expand All @@ -41,8 +38,6 @@ public class DeleteWarmerRequest extends AcknowledgedRequest<DeleteWarmerRequest

private String[] indices = Strings.EMPTY_ARRAY;

private TimeValue timeout = timeValueSeconds(10);

DeleteWarmerRequest() {
}

Expand All @@ -57,8 +52,7 @@ public DeleteWarmerRequest(String name) {

@Override
public ActionRequestValidationException validate() {
ActionRequestValidationException validationException = null;
return validationException;
return null;
}

/**
Expand Down
Expand Up @@ -20,15 +20,14 @@
package org.elasticsearch.action.admin.indices.warmer.delete;

import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.support.master.MasterNodeOperationRequestBuilder;
import org.elasticsearch.action.support.master.AcknowledgedRequestBuilder;
import org.elasticsearch.client.IndicesAdminClient;
import org.elasticsearch.client.internal.InternalIndicesAdminClient;
import org.elasticsearch.common.unit.TimeValue;

/**
*
*/
public class DeleteWarmerRequestBuilder extends MasterNodeOperationRequestBuilder<DeleteWarmerRequest, DeleteWarmerResponse, DeleteWarmerRequestBuilder> {
public class DeleteWarmerRequestBuilder extends AcknowledgedRequestBuilder<DeleteWarmerRequest, DeleteWarmerResponse, DeleteWarmerRequestBuilder> {

public DeleteWarmerRequestBuilder(IndicesAdminClient indicesClient) {
super((InternalIndicesAdminClient) indicesClient, new DeleteWarmerRequest());
Expand All @@ -48,23 +47,6 @@ public DeleteWarmerRequestBuilder setName(String name) {
return this;
}

/**
* Sets the maximum wait for acknowledgement from other nodes
*/
public DeleteWarmerRequestBuilder setTimeout(TimeValue timeout) {
request.timeout(timeout);
return this;
}

/**
* Timeout to wait for the operation to be acknowledged by current cluster nodes. Defaults
* to <tt>10s</tt>.
*/
public DeleteWarmerRequestBuilder setTimeout(String timeout) {
request.timeout(timeout);
return this;
}

@Override
protected void doExecute(ActionListener<DeleteWarmerResponse> listener) {
((IndicesAdminClient) client).deleteWarmer(request, listener);
Expand Down

0 comments on commit ef18e72

Please sign in to comment.