Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@
import org.opensearch.action.admin.cluster.snapshots.restore.TransportRestoreSnapshotAction;
import org.opensearch.action.admin.cluster.snapshots.status.SnapshotsStatusAction;
import org.opensearch.action.admin.cluster.snapshots.status.TransportSnapshotsStatusAction;
import org.opensearch.action.admin.cluster.snapshots.list.SnapshotIndicesListAction;
import org.opensearch.action.admin.cluster.snapshots.list.TransportSnapshotIndicesListAction;
import org.opensearch.action.admin.cluster.state.ClusterStateAction;
import org.opensearch.action.admin.cluster.state.TransportClusterStateAction;
import org.opensearch.action.admin.cluster.stats.ClusterStatsAction;
Expand Down Expand Up @@ -484,6 +486,7 @@
import org.opensearch.rest.action.list.RestIndicesListAction;
import org.opensearch.rest.action.list.RestListAction;
import org.opensearch.rest.action.list.RestShardsListAction;
import org.opensearch.rest.action.list.RestSnapshotIndicesListAction;
import org.opensearch.rest.action.search.RestClearScrollAction;
import org.opensearch.rest.action.search.RestCountAction;
import org.opensearch.rest.action.search.RestCreatePitAction;
Expand Down Expand Up @@ -672,6 +675,7 @@ public <Request extends ActionRequest, Response extends ActionResponse> void reg
actions.register(CloneSnapshotAction.INSTANCE, TransportCloneSnapshotAction.class);
actions.register(RestoreSnapshotAction.INSTANCE, TransportRestoreSnapshotAction.class);
actions.register(SnapshotsStatusAction.INSTANCE, TransportSnapshotsStatusAction.class);
actions.register(SnapshotIndicesListAction.INSTANCE, TransportSnapshotIndicesListAction.class);

actions.register(ClusterAddWeightedRoutingAction.INSTANCE, TransportAddWeightedRoutingAction.class);
actions.register(ClusterGetWeightedRoutingAction.INSTANCE, TransportGetWeightedRoutingAction.class);
Expand Down Expand Up @@ -1025,6 +1029,7 @@ public void initRestHandlers(Supplier<DiscoveryNodes> nodesInCluster) {
// LIST API
registerHandler.accept(new RestIndicesListAction(responseLimitSettings));
registerHandler.accept(new RestShardsListAction());
registerHandler.accept(new RestSnapshotIndicesListAction());

// Point in time API
registerHandler.accept(new RestCreatePitAction());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/

package org.opensearch.action.admin.cluster.snapshots.list;

import org.opensearch.action.ActionType;

/**
* ActionType for listing snapshot indices with pagination.
*
* @opensearch.internal
*/
public class SnapshotIndicesListAction extends ActionType<SnapshotIndicesListResponse> {

public static final SnapshotIndicesListAction INSTANCE = new SnapshotIndicesListAction();
public static final String NAME = "cluster:admin/snapshot/list/indices";

private SnapshotIndicesListAction() {
super(NAME, SnapshotIndicesListResponse::new);
}
}


Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/

package org.opensearch.action.admin.cluster.snapshots.list;

import org.opensearch.action.ActionRequestValidationException;
import org.opensearch.action.support.clustermanager.ClusterManagerNodeRequest;
import org.opensearch.core.common.io.stream.StreamInput;
import org.opensearch.core.common.io.stream.StreamOutput;

import java.io.IOException;

/**
* Request for listing snapshot indices with pagination.
*
* @opensearch.internal
*/
public class SnapshotIndicesListRequest extends ClusterManagerNodeRequest<SnapshotIndicesListRequest> {

private String repository;
private String snapshot;
private int from;
private int size;

public SnapshotIndicesListRequest() {}

public SnapshotIndicesListRequest(StreamInput in) throws IOException {
super(in);
this.repository = in.readString();
this.snapshot = in.readString();
this.from = in.readVInt();
this.size = in.readVInt();
}

@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeString(repository);
out.writeString(snapshot);
out.writeVInt(from);
out.writeVInt(size);
}

@Override
public ActionRequestValidationException validate() {
return null;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would you add any validation here?

}

public String repository() { return repository; }
public String snapshot() { return snapshot; }
public int from() { return from; }
public int size() { return size; }

public SnapshotIndicesListRequest repository(String repository) {
this.repository = repository;
return this;
}

public SnapshotIndicesListRequest snapshot(String snapshot) {
this.snapshot = snapshot;
return this;
}

public SnapshotIndicesListRequest from(int from) {
this.from = from;
return this;
}

public SnapshotIndicesListRequest size(int size) {
this.size = size;
return this;
}
}


Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/

package org.opensearch.action.admin.cluster.snapshots.list;

import org.opensearch.core.action.ActionResponse;
import org.opensearch.core.common.io.stream.StreamInput;
import org.opensearch.core.common.io.stream.StreamOutput;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
* Response payload for snapshot indices list.
*
* @opensearch.internal
*/
public class SnapshotIndicesListResponse extends ActionResponse {

public static class IndexRow {
public String index;
public int shardsTotal;
public int shardsDone;
public int shardsFailed;
public long fileCount;
public long sizeInBytes;
public long startTimeInMillis;
public long timeInMillis;

public IndexRow() {}

public IndexRow(StreamInput in) throws IOException {
this.index = in.readString();
this.shardsTotal = in.readVInt();
this.shardsDone = in.readVInt();
this.shardsFailed = in.readVInt();
this.fileCount = in.readVLong();
this.sizeInBytes = in.readVLong();
this.startTimeInMillis = in.readVLong();
this.timeInMillis = in.readVLong();
}

public void writeTo(StreamOutput out) throws IOException {
out.writeString(index);
out.writeVInt(shardsTotal);
out.writeVInt(shardsDone);
out.writeVInt(shardsFailed);
out.writeVLong(fileCount);
out.writeVLong(sizeInBytes);
out.writeVLong(startTimeInMillis);
out.writeVLong(timeInMillis);
}
}

private List<IndexRow> rows = new ArrayList<>();

public SnapshotIndicesListResponse() {}

public SnapshotIndicesListResponse(StreamInput in) throws IOException {
super(in);
int n = in.readVInt();
for (int i = 0; i < n; i++) {
rows.add(new IndexRow(in));
}
}

@Override
public void writeTo(StreamOutput out) throws IOException {
out.writeVInt(rows.size());
for (IndexRow r : rows) {
r.writeTo(out);
}
}

public List<IndexRow> rows() { return rows; }
}


Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/

package org.opensearch.action.admin.cluster.snapshots.list;

import org.opensearch.cluster.metadata.IndexMetadata;
import org.opensearch.core.index.shard.ShardId;
import org.opensearch.index.snapshots.IndexShardSnapshotStatus;
import org.opensearch.repositories.IndexId;
import org.opensearch.repositories.Repository;
import org.opensearch.repositories.RepositoryData;
import org.opensearch.snapshots.SnapshotId;
import org.opensearch.snapshots.SnapshotInfo;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* Utilities for snapshot listing that read only page-relevant data from repository.
*
* @opensearch.internal
*/
final class SnapshotListUtils {

static class IndexFileStats {
static final IndexFileStats EMPTY = new IndexFileStats(0L, 0L);
final long fileCount;
final long sizeInBytes;

IndexFileStats(long fileCount, long sizeInBytes) {
this.fileCount = fileCount;
this.sizeInBytes = sizeInBytes;
}
}

private SnapshotListUtils() {}

static Map<String, IndexMetadata> loadIndexMetadata(
Repository repo,
RepositoryData repositoryData,
SnapshotInfo snapshotInfo,
List<String> indices
) throws IOException {
Map<String, IndexMetadata> result = new HashMap<>();
SnapshotId snapshotId = snapshotInfo.snapshotId();
for (String index : indices) {
IndexId indexId = repositoryData.resolveIndexId(index);
IndexMetadata meta = repo.getSnapshotIndexMetaData(repositoryData, snapshotId, indexId);
if (meta != null) {
result.put(index, meta);
}
}
return result;
}

static Map<String, IndexFileStats> loadIndexFileStats(
Repository repo,
RepositoryData repositoryData,
SnapshotInfo snapshotInfo,
List<String> indices,
Map<String, IndexMetadata> indexMetadataMap
) throws IOException {
Map<String, IndexFileStats> result = new HashMap<>();
SnapshotId snapshotId = snapshotInfo.snapshotId();
for (String index : indices) {
IndexMetadata meta = indexMetadataMap.get(index);
int numShards = meta == null ? 0 : meta.getNumberOfShards();
long files = 0L;
long bytes = 0L;
if (numShards > 0) {
IndexId indexId = repositoryData.resolveIndexId(index);
for (int shard = 0; shard < numShards; shard++) {
IndexShardSnapshotStatus.Copy s = repo.getShardSnapshotStatus(snapshotId, indexId, new ShardId(meta.getIndex(), shard))
.asCopy();
files += s.getTotalFileCount();
bytes += s.getTotalSize();
}
}
result.put(index, new IndexFileStats(files, bytes));
}
return result;
}
}


Loading
Loading