Skip to content

Commit

Permalink
use RestRequest params
Browse files Browse the repository at this point in the history
  • Loading branch information
Ali Beyad committed Jun 28, 2017
1 parent c148601 commit 3d34d08
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,15 @@ public class GetSnapshotsRequest extends MasterNodeRequest<GetSnapshotsRequest>

public static final String ALL_SNAPSHOTS = "_all";
public static final String CURRENT_SNAPSHOT = "_current";
public static final boolean DEFAULT_VERBOSE_MODE = true;

private String repository;

private String[] snapshots = Strings.EMPTY_ARRAY;

private boolean ignoreUnavailable;

private boolean verbose = true;
private boolean verbose = DEFAULT_VERBOSE_MODE;

public GetSnapshotsRequest() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,18 @@
package org.elasticsearch.rest.action.admin.cluster;

import org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsRequest;
import org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsResponse;
import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.rest.BaseRestHandler;
import org.elasticsearch.rest.BytesRestResponse;
import org.elasticsearch.rest.RestController;
import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.RestResponse;
import org.elasticsearch.rest.action.RestBuilderListener;
import org.elasticsearch.rest.action.RestToXContentListener;

import java.io.IOException;
import java.util.Collections;
import java.util.Map;

import static org.elasticsearch.client.Requests.getSnapshotsRequest;
import static org.elasticsearch.rest.RestRequest.Method.GET;
import static org.elasticsearch.rest.RestStatus.OK;

/**
* Returns information about snapshot
Expand All @@ -60,19 +52,10 @@ public RestChannelConsumer prepareRequest(final RestRequest request, final NodeC
String repository = request.param("repository");
String[] snapshots = request.paramAsStringArray("snapshot", Strings.EMPTY_ARRAY);

final GetSnapshotsRequest getSnapshotsRequest = getSnapshotsRequest(repository).snapshots(snapshots);
GetSnapshotsRequest getSnapshotsRequest = getSnapshotsRequest(repository).snapshots(snapshots);
getSnapshotsRequest.ignoreUnavailable(request.paramAsBoolean("ignore_unavailable", getSnapshotsRequest.ignoreUnavailable()));
getSnapshotsRequest.verbose(request.paramAsBoolean("verbose", getSnapshotsRequest.verbose()));
getSnapshotsRequest.masterNodeTimeout(request.paramAsTime("master_timeout", getSnapshotsRequest.masterNodeTimeout()));
return channel -> client.admin().cluster().getSnapshots(getSnapshotsRequest,
new RestBuilderListener<GetSnapshotsResponse>(channel) {
@Override
public RestResponse buildResponse(GetSnapshotsResponse response, XContentBuilder builder) throws Exception {
Map<String, String> params = Collections.singletonMap("verbose", Boolean.toString(getSnapshotsRequest.verbose()));
ToXContent.MapParams xContentParams = new ToXContent.MapParams(params);
response.toXContent(builder, xContentParams);
return new BytesRestResponse(OK, builder);
}
});
return channel -> client.admin().cluster().getSnapshots(getSnapshotsRequest, new RestToXContentListener<>(channel));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.Version;
import org.elasticsearch.action.ShardOperationFailedException;
import org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsRequest;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
Expand Down Expand Up @@ -346,7 +347,7 @@ public XContentBuilder toXContent(final XContentBuilder builder, final Params pa
return toXContentSnapshot(builder, params);
}

final boolean verbose = params.paramAsBoolean("verbose", false);
final boolean verbose = params.paramAsBoolean("verbose", GetSnapshotsRequest.DEFAULT_VERBOSE_MODE);
// write snapshot info for the API and any other situations
builder.startObject();
builder.field(SNAPSHOT, snapshotId.getName());
Expand Down

0 comments on commit 3d34d08

Please sign in to comment.