Search in sources :

Example 1 with GetSnapshotsRequest

use of org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsRequest in project elasticsearch by elastic.

the class RestGetSnapshotsAction method prepareRequest.

@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
    String repository = request.param("repository");
    String[] snapshots = request.paramAsStringArray("snapshot", Strings.EMPTY_ARRAY);
    GetSnapshotsRequest getSnapshotsRequest = getSnapshotsRequest(repository).snapshots(snapshots);
    getSnapshotsRequest.ignoreUnavailable(request.paramAsBoolean("ignore_unavailable", getSnapshotsRequest.ignoreUnavailable()));
    getSnapshotsRequest.masterNodeTimeout(request.paramAsTime("master_timeout", getSnapshotsRequest.masterNodeTimeout()));
    return channel -> client.admin().cluster().getSnapshots(getSnapshotsRequest, new RestToXContentListener<>(channel));
}
Also used : BaseRestHandler(org.elasticsearch.rest.BaseRestHandler) Settings(org.elasticsearch.common.settings.Settings) GET(org.elasticsearch.rest.RestRequest.Method.GET) Requests.getSnapshotsRequest(org.elasticsearch.client.Requests.getSnapshotsRequest) RestToXContentListener(org.elasticsearch.rest.action.RestToXContentListener) RestRequest(org.elasticsearch.rest.RestRequest) NodeClient(org.elasticsearch.client.node.NodeClient) IOException(java.io.IOException) RestController(org.elasticsearch.rest.RestController) GetSnapshotsRequest(org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsRequest) Strings(org.elasticsearch.common.Strings) GetSnapshotsRequest(org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsRequest)

Example 2 with GetSnapshotsRequest

use of org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsRequest in project elasticsearch by elastic.

the class RestSnapshotAction method doCatRequest.

@Override
protected RestChannelConsumer doCatRequest(final RestRequest request, NodeClient client) {
    GetSnapshotsRequest getSnapshotsRequest = new GetSnapshotsRequest().repository(request.param("repository")).snapshots(new String[] { GetSnapshotsRequest.ALL_SNAPSHOTS });
    getSnapshotsRequest.ignoreUnavailable(request.paramAsBoolean("ignore_unavailable", getSnapshotsRequest.ignoreUnavailable()));
    getSnapshotsRequest.masterNodeTimeout(request.paramAsTime("master_timeout", getSnapshotsRequest.masterNodeTimeout()));
    return channel -> client.admin().cluster().getSnapshots(getSnapshotsRequest, new RestResponseListener<GetSnapshotsResponse>(channel) {

        @Override
        public RestResponse buildResponse(GetSnapshotsResponse getSnapshotsResponse) throws Exception {
            return RestTable.buildResponse(buildTable(request, getSnapshotsResponse), channel);
        }
    });
}
Also used : DateTimeFormat(org.joda.time.format.DateTimeFormat) GET(org.elasticsearch.rest.RestRequest.Method.GET) DateTimeFormatter(org.joda.time.format.DateTimeFormatter) RestResponse(org.elasticsearch.rest.RestResponse) Table(org.elasticsearch.common.Table) RestController(org.elasticsearch.rest.RestController) GetSnapshotsRequest(org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsRequest) SnapshotInfo(org.elasticsearch.snapshots.SnapshotInfo) TimeUnit(java.util.concurrent.TimeUnit) Settings(org.elasticsearch.common.settings.Settings) TimeValue(org.elasticsearch.common.unit.TimeValue) RestRequest(org.elasticsearch.rest.RestRequest) NodeClient(org.elasticsearch.client.node.NodeClient) SnapshotState(org.elasticsearch.snapshots.SnapshotState) GetSnapshotsResponse(org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsResponse) RestResponseListener(org.elasticsearch.rest.action.RestResponseListener) GetSnapshotsResponse(org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsResponse) GetSnapshotsRequest(org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsRequest) RestResponse(org.elasticsearch.rest.RestResponse)

Example 3 with GetSnapshotsRequest

use of org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsRequest in project crate by crate.

the class SnapshotRestoreDDLDispatcher method resolveIndexNames.

@VisibleForTesting
static CompletableFuture<List<String>> resolveIndexNames(List<RestoreSnapshotAnalyzedStatement.RestoreTableInfo> restoreTables, boolean ignoreUnavailable, TransportGetSnapshotsAction getSnapshotsAction, String repositoryName) {
    Collection<String> resolvedIndices = new HashSet<>();
    List<RestoreSnapshotAnalyzedStatement.RestoreTableInfo> toResolveFromSnapshot = new ArrayList<>();
    for (RestoreSnapshotAnalyzedStatement.RestoreTableInfo table : restoreTables) {
        if (table.hasPartitionInfo()) {
            resolvedIndices.add(table.partitionName().asIndexName());
        } else if (ignoreUnavailable) {
            // If ignoreUnavailable is true, it's cheaper to simply return indexName and the partitioned wildcard instead
            // checking if it's a partitioned table or not
            resolvedIndices.add(table.tableIdent().indexName());
            resolvedIndices.add(PartitionName.templateName(table.tableIdent().schema(), table.tableIdent().name()) + "*");
        } else {
            // index name needs to be resolved from snapshot
            toResolveFromSnapshot.add(table);
        }
    }
    if (toResolveFromSnapshot.isEmpty()) {
        return CompletableFuture.completedFuture(ImmutableList.copyOf(resolvedIndices));
    }
    final CompletableFuture<List<String>> f = new CompletableFuture<>();
    getSnapshotsAction.execute(new GetSnapshotsRequest(repositoryName), new ResolveFromSnapshotActionListener(f, toResolveFromSnapshot, resolvedIndices));
    return f;
}
Also used : GetSnapshotsRequest(org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsRequest) ArrayList(java.util.ArrayList) RestoreSnapshotAnalyzedStatement(io.crate.analyze.RestoreSnapshotAnalyzedStatement) CompletableFuture(java.util.concurrent.CompletableFuture) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) HashSet(java.util.HashSet) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

GetSnapshotsRequest (org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsRequest)3 NodeClient (org.elasticsearch.client.node.NodeClient)2 Settings (org.elasticsearch.common.settings.Settings)2 RestController (org.elasticsearch.rest.RestController)2 RestRequest (org.elasticsearch.rest.RestRequest)2 GET (org.elasticsearch.rest.RestRequest.Method.GET)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ImmutableList (com.google.common.collect.ImmutableList)1 RestoreSnapshotAnalyzedStatement (io.crate.analyze.RestoreSnapshotAnalyzedStatement)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 List (java.util.List)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 TimeUnit (java.util.concurrent.TimeUnit)1 GetSnapshotsResponse (org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsResponse)1 Requests.getSnapshotsRequest (org.elasticsearch.client.Requests.getSnapshotsRequest)1 Strings (org.elasticsearch.common.Strings)1 Table (org.elasticsearch.common.Table)1 TimeValue (org.elasticsearch.common.unit.TimeValue)1