org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsResponse Java Examples

The following examples show how to use org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsResponse. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RestSnapshotAction.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Override
protected void doRequest(final RestRequest request, RestChannel channel, Client 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()));

    client.admin().cluster().getSnapshots(getSnapshotsRequest, new RestResponseListener<GetSnapshotsResponse>(channel) {
        @Override
        public RestResponse buildResponse(GetSnapshotsResponse getSnapshotsResponse) throws Exception {
            return RestTable.buildResponse(buildTable(request, getSnapshotsResponse), channel);
        }
    });
}
 
Example #2
Source File: RestGetSnapshotsAction.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
    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()));
    client.admin().cluster().getSnapshots(getSnapshotsRequest, new RestToXContentListener<GetSnapshotsResponse>(channel));
}
 
Example #3
Source File: RestSnapshotAction.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
private Table buildTable(RestRequest req, GetSnapshotsResponse getSnapshotsResponse) {
    Table table = getTableWithHeader(req);
    for (SnapshotInfo snapshotStatus : getSnapshotsResponse.getSnapshots()) {
        table.startRow();

        table.addCell(snapshotStatus.name());
        table.addCell(snapshotStatus.state());
        table.addCell(TimeUnit.SECONDS.convert(snapshotStatus.startTime(), TimeUnit.MILLISECONDS));
        table.addCell(dateFormat.print(snapshotStatus.startTime()));
        table.addCell(TimeUnit.SECONDS.convert(snapshotStatus.endTime(), TimeUnit.MILLISECONDS));
        table.addCell(dateFormat.print(snapshotStatus.endTime()));
        final long durationMillis;
        if (snapshotStatus.state() == SnapshotState.IN_PROGRESS) {
            durationMillis = System.currentTimeMillis() - snapshotStatus.startTime();
        } else {
            durationMillis = snapshotStatus.endTime() - snapshotStatus.startTime();
        }
        table.addCell(TimeValue.timeValueMillis(durationMillis));
        table.addCell(snapshotStatus.indices().size());
        table.addCell(snapshotStatus.successfulShards());
        table.addCell(snapshotStatus.failedShards());
        table.addCell(snapshotStatus.totalShards());
        table.addCell(snapshotStatus.reason());

        table.endRow();
    }

    return table;
}
 
Example #4
Source File: ElasticsearchUtils.java    From Raigad with Apache License 2.0 5 votes vote down vote up
public static List<String> getAvailableSnapshots(Client transportClient, String repositoryName) {
    logger.info("Searching for available snapshots");

    List<String> snapshots = new ArrayList<>();
    GetSnapshotsResponse getSnapshotsResponse = transportClient.admin().cluster()
            .prepareGetSnapshots(repositoryName)
            .get();

    for (SnapshotInfo snapshotInfo : getSnapshotsResponse.getSnapshots()) {
        snapshots.add(snapshotInfo.snapshotId().getName());
    }

    return snapshots;
}
 
Example #5
Source File: RestoreSnapshotPlan.java    From crate with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
static CompletableFuture<ResolveIndicesAndTemplatesContext> resolveIndexNames(String repositoryName,
                                                                              Set<BoundRestoreSnapshot.RestoreTableInfo> restoreTables,
                                                                              boolean ignoreUnavailable,
                                                                              TransportGetSnapshotsAction transportGetSnapshotsAction) {
    ResolveIndicesAndTemplatesContext context = new ResolveIndicesAndTemplatesContext();
    ArrayList<BoundRestoreSnapshot.RestoreTableInfo> toResolveFromSnapshot = new ArrayList<>();
    for (var table : restoreTables) {
        if (table.hasPartitionInfo()) {
            context.addIndex(table.partitionName().asIndexName());
            context.addTemplate(table.partitionTemplate());
        } 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
            context.addIndex(table.tableIdent().indexNameOrAlias());
            // For the case its a partitioned table we restore all partitions and the templates
            String templateName = table.partitionTemplate();
            context.addIndex(templateName + "*");
            context.addTemplate(templateName);
        } else {
            // index name needs to be resolved from snapshot
            toResolveFromSnapshot.add(table);
        }
    }

    if (toResolveFromSnapshot.isEmpty()) {
        return CompletableFuture.completedFuture(context);
    } else {
        FutureActionListener<GetSnapshotsResponse, ResolveIndicesAndTemplatesContext> listener =
            new FutureActionListener<>(
                response -> {
                    resolveTablesFromSnapshots(toResolveFromSnapshot, response.getSnapshots(), context);
                    return context;
                }
            );
        transportGetSnapshotsAction.execute(new GetSnapshotsRequest(repositoryName), listener);
        return listener;
    }
}
 
Example #6
Source File: AbstractClient.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public ActionFuture<GetSnapshotsResponse> getSnapshots(GetSnapshotsRequest request) {
    return execute(GetSnapshotsAction.INSTANCE, request);
}
 
Example #7
Source File: AbstractClient.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public void getSnapshots(GetSnapshotsRequest request, ActionListener<GetSnapshotsResponse> listener) {
    execute(GetSnapshotsAction.INSTANCE, request, listener);
}
 
Example #8
Source File: ClusterAdminClient.java    From Elasticsearch with Apache License 2.0 2 votes vote down vote up
/**
 * Get snapshot.
 */
ActionFuture<GetSnapshotsResponse> getSnapshots(GetSnapshotsRequest request);
 
Example #9
Source File: ClusterAdminClient.java    From Elasticsearch with Apache License 2.0 2 votes vote down vote up
/**
 * Get snapshot.
 */
void getSnapshots(GetSnapshotsRequest request, ActionListener<GetSnapshotsResponse> listener);