mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-17 10:25:15 +00:00
Merge pull request #15151 from ywelsch/feature/get-snapshot-wildcards
Support wildcards for getting repositories and snapshots
This commit is contained in:
commit
ce50fb49b3
@ -31,6 +31,7 @@ import org.elasticsearch.cluster.metadata.MetaData;
|
|||||||
import org.elasticsearch.cluster.metadata.RepositoriesMetaData;
|
import org.elasticsearch.cluster.metadata.RepositoriesMetaData;
|
||||||
import org.elasticsearch.cluster.metadata.RepositoryMetaData;
|
import org.elasticsearch.cluster.metadata.RepositoryMetaData;
|
||||||
import org.elasticsearch.common.inject.Inject;
|
import org.elasticsearch.common.inject.Inject;
|
||||||
|
import org.elasticsearch.common.regex.Regex;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.repositories.RepositoryMissingException;
|
import org.elasticsearch.repositories.RepositoryMissingException;
|
||||||
import org.elasticsearch.threadpool.ThreadPool;
|
import org.elasticsearch.threadpool.ThreadPool;
|
||||||
@ -38,7 +39,9 @@ import org.elasticsearch.transport.TransportService;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.LinkedHashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Transport action for get repositories operation
|
* Transport action for get repositories operation
|
||||||
@ -78,8 +81,20 @@ public class TransportGetRepositoriesAction extends TransportMasterNodeReadActio
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (repositories != null) {
|
if (repositories != null) {
|
||||||
|
Set<String> repositoriesToGet = new LinkedHashSet<>(); // to keep insertion order
|
||||||
|
for (String repositoryOrPattern : request.repositories()) {
|
||||||
|
if (Regex.isSimpleMatchPattern(repositoryOrPattern) == false) {
|
||||||
|
repositoriesToGet.add(repositoryOrPattern);
|
||||||
|
} else {
|
||||||
|
for (RepositoryMetaData repository : repositories.repositories()) {
|
||||||
|
if (Regex.simpleMatch(repositoryOrPattern, repository.name())) {
|
||||||
|
repositoriesToGet.add(repository.name());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
List<RepositoryMetaData> repositoryListBuilder = new ArrayList<>();
|
List<RepositoryMetaData> repositoryListBuilder = new ArrayList<>();
|
||||||
for (String repository : request.repositories()) {
|
for (String repository : repositoriesToGet) {
|
||||||
RepositoryMetaData repositoryMetaData = repositories.repository(repository);
|
RepositoryMetaData repositoryMetaData = repositories.repository(repository);
|
||||||
if (repositoryMetaData == null) {
|
if (repositoryMetaData == null) {
|
||||||
listener.onFailure(new RepositoryMissingException(repository));
|
listener.onFailure(new RepositoryMissingException(repository));
|
||||||
|
@ -29,6 +29,7 @@ import org.elasticsearch.cluster.block.ClusterBlockLevel;
|
|||||||
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
|
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
|
||||||
import org.elasticsearch.cluster.metadata.SnapshotId;
|
import org.elasticsearch.cluster.metadata.SnapshotId;
|
||||||
import org.elasticsearch.common.inject.Inject;
|
import org.elasticsearch.common.inject.Inject;
|
||||||
|
import org.elasticsearch.common.regex.Regex;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.snapshots.Snapshot;
|
import org.elasticsearch.snapshots.Snapshot;
|
||||||
import org.elasticsearch.snapshots.SnapshotInfo;
|
import org.elasticsearch.snapshots.SnapshotInfo;
|
||||||
@ -38,7 +39,9 @@ import org.elasticsearch.transport.TransportService;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.LinkedHashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Transport Action for get snapshots operation
|
* Transport Action for get snapshots operation
|
||||||
@ -84,8 +87,24 @@ public class TransportGetSnapshotsAction extends TransportMasterNodeAction<GetSn
|
|||||||
snapshotInfoBuilder.add(new SnapshotInfo(snapshot));
|
snapshotInfoBuilder.add(new SnapshotInfo(snapshot));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (int i = 0; i < request.snapshots().length; i++) {
|
Set<String> snapshotsToGet = new LinkedHashSet<>(); // to keep insertion order
|
||||||
SnapshotId snapshotId = new SnapshotId(request.repository(), request.snapshots()[i]);
|
List<Snapshot> snapshots = null;
|
||||||
|
for (String snapshotOrPattern : request.snapshots()) {
|
||||||
|
if (Regex.isSimpleMatchPattern(snapshotOrPattern) == false) {
|
||||||
|
snapshotsToGet.add(snapshotOrPattern);
|
||||||
|
} else {
|
||||||
|
if (snapshots == null) { // lazily load snapshots
|
||||||
|
snapshots = snapshotsService.snapshots(request.repository(), request.ignoreUnavailable());
|
||||||
|
}
|
||||||
|
for (Snapshot snapshot : snapshots) {
|
||||||
|
if (Regex.simpleMatch(snapshotOrPattern, snapshot.name())) {
|
||||||
|
snapshotsToGet.add(snapshot.name());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (String snapshot : snapshotsToGet) {
|
||||||
|
SnapshotId snapshotId = new SnapshotId(request.repository(), snapshot);
|
||||||
snapshotInfoBuilder.add(new SnapshotInfo(snapshotsService.snapshot(snapshotId)));
|
snapshotInfoBuilder.add(new SnapshotInfo(snapshotsService.snapshot(snapshotId)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -94,7 +94,8 @@ public class RepositoriesIT extends AbstractSnapshotIntegTestCase {
|
|||||||
assertThat(repositoriesMetaData.repository("test-repo-2").type(), equalTo("fs"));
|
assertThat(repositoriesMetaData.repository("test-repo-2").type(), equalTo("fs"));
|
||||||
|
|
||||||
logger.info("--> check that both repositories can be retrieved by getRepositories query");
|
logger.info("--> check that both repositories can be retrieved by getRepositories query");
|
||||||
GetRepositoriesResponse repositoriesResponse = client.admin().cluster().prepareGetRepositories().get();
|
GetRepositoriesResponse repositoriesResponse = client.admin().cluster()
|
||||||
|
.prepareGetRepositories(randomFrom("_all", "*", "test-repo-*")).get();
|
||||||
assertThat(repositoriesResponse.repositories().size(), equalTo(2));
|
assertThat(repositoriesResponse.repositories().size(), equalTo(2));
|
||||||
assertThat(findRepository(repositoriesResponse.repositories(), "test-repo-1"), notNullValue());
|
assertThat(findRepository(repositoriesResponse.repositories(), "test-repo-1"), notNullValue());
|
||||||
assertThat(findRepository(repositoriesResponse.repositories(), "test-repo-2"), notNullValue());
|
assertThat(findRepository(repositoriesResponse.repositories(), "test-repo-2"), notNullValue());
|
||||||
|
@ -149,7 +149,10 @@ public class SharedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTestCas
|
|||||||
assertThat(createSnapshotResponse.getSnapshotInfo().successfulShards(), greaterThan(0));
|
assertThat(createSnapshotResponse.getSnapshotInfo().successfulShards(), greaterThan(0));
|
||||||
assertThat(createSnapshotResponse.getSnapshotInfo().successfulShards(), equalTo(createSnapshotResponse.getSnapshotInfo().totalShards()));
|
assertThat(createSnapshotResponse.getSnapshotInfo().successfulShards(), equalTo(createSnapshotResponse.getSnapshotInfo().totalShards()));
|
||||||
|
|
||||||
SnapshotInfo snapshotInfo = client.admin().cluster().prepareGetSnapshots("test-repo").setSnapshots("test-snap").get().getSnapshots().get(0);
|
List<SnapshotInfo> snapshotInfos = client.admin().cluster().prepareGetSnapshots("test-repo")
|
||||||
|
.setSnapshots(randomFrom("test-snap", "_all", "*", "*-snap", "test*")).get().getSnapshots();
|
||||||
|
assertThat(snapshotInfos.size(), equalTo(1));
|
||||||
|
SnapshotInfo snapshotInfo = snapshotInfos.get(0);
|
||||||
assertThat(snapshotInfo.state(), equalTo(SnapshotState.SUCCESS));
|
assertThat(snapshotInfo.state(), equalTo(SnapshotState.SUCCESS));
|
||||||
assertThat(snapshotInfo.version(), equalTo(Version.CURRENT));
|
assertThat(snapshotInfo.version(), equalTo(Version.CURRENT));
|
||||||
|
|
||||||
|
@ -45,6 +45,15 @@ which returns:
|
|||||||
}
|
}
|
||||||
-----------------------------------
|
-----------------------------------
|
||||||
|
|
||||||
|
Information about multiple repositories can be fetched in one go by using a comma-delimited list of repository names.
|
||||||
|
Star wildcards are supported as well. For example, information about repositories that start with `repo` or that contain `backup`
|
||||||
|
can be obtained using the following command:
|
||||||
|
|
||||||
|
[source,js]
|
||||||
|
-----------------------------------
|
||||||
|
GET /_snapshot/repo*,*backup*
|
||||||
|
-----------------------------------
|
||||||
|
|
||||||
If a repository name is not specified, or `_all` is used as repository name Elasticsearch will return information about
|
If a repository name is not specified, or `_all` is used as repository name Elasticsearch will return information about
|
||||||
all repositories currently registered in the cluster:
|
all repositories currently registered in the cluster:
|
||||||
|
|
||||||
@ -251,6 +260,14 @@ GET /_snapshot/my_backup/snapshot_1
|
|||||||
-----------------------------------
|
-----------------------------------
|
||||||
// AUTOSENSE
|
// AUTOSENSE
|
||||||
|
|
||||||
|
Similar as for repositories, information about multiple snapshots can be queried in one go, supporting wildcards as well:
|
||||||
|
|
||||||
|
[source,sh]
|
||||||
|
-----------------------------------
|
||||||
|
GET /_snapshot/my_backup/snapshot_*,some_other_snapshot
|
||||||
|
-----------------------------------
|
||||||
|
// AUTOSENSE
|
||||||
|
|
||||||
All snapshots currently stored in the repository can be listed using the following command:
|
All snapshots currently stored in the repository can be listed using the following command:
|
||||||
|
|
||||||
[source,sh]
|
[source,sh]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user