use of org.opensearch.cluster.metadata.RepositoriesMetadata in project OpenSearch by opensearch-project.
the class RepositoriesServiceTests method createClusterStateWithRepo.
private ClusterState createClusterStateWithRepo(String repoName, String repoType) {
ClusterState.Builder state = ClusterState.builder(new ClusterName("test"));
Metadata.Builder mdBuilder = Metadata.builder();
mdBuilder.putCustom(RepositoriesMetadata.TYPE, new RepositoriesMetadata(Collections.singletonList(new RepositoryMetadata(repoName, repoType, Settings.EMPTY))));
state.metadata(mdBuilder);
return state.build();
}
use of org.opensearch.cluster.metadata.RepositoriesMetadata in project OpenSearch by opensearch-project.
the class RepositoriesMetadataSerializationTests method makeTestChanges.
@Override
protected Custom makeTestChanges(Custom testInstance) {
RepositoriesMetadata repositoriesMetadata = (RepositoriesMetadata) testInstance;
List<RepositoryMetadata> repos = new ArrayList<>(repositoriesMetadata.repositories());
if (randomBoolean() && repos.size() > 1) {
// remove some elements
int leaveElements = randomIntBetween(0, repositoriesMetadata.repositories().size() - 1);
repos = randomSubsetOf(leaveElements, repos.toArray(new RepositoryMetadata[leaveElements]));
}
if (randomBoolean()) {
// add some elements
int addElements = randomInt(10);
for (int i = 0; i < addElements; i++) {
repos.add(new RepositoryMetadata(randomAlphaOfLength(10), randomAlphaOfLength(10), randomSettings()));
}
}
return new RepositoriesMetadata(repos);
}
use of org.opensearch.cluster.metadata.RepositoriesMetadata in project OpenSearch by opensearch-project.
the class ClusterModuleTests method testPre63CustomsFiltering.
public void testPre63CustomsFiltering() {
final String allowListedClusterCustom = randomFrom(ClusterModule.PRE_6_3_CLUSTER_CUSTOMS_WHITE_LIST);
final String allowListedMetadataCustom = randomFrom(ClusterModule.PRE_6_3_METADATA_CUSTOMS_WHITE_LIST);
final ClusterState clusterState = ClusterState.builder(ClusterName.DEFAULT).putCustom(allowListedClusterCustom, new RestoreInProgress.Builder().build()).putCustom("other", new RestoreInProgress.Builder().build()).metadata(Metadata.builder().putCustom(allowListedMetadataCustom, new RepositoriesMetadata(Collections.emptyList())).putCustom("other", new RepositoriesMetadata(Collections.emptyList())).build()).build();
assertNotNull(clusterState.custom(allowListedClusterCustom));
assertNotNull(clusterState.custom("other"));
assertNotNull(clusterState.metadata().custom(allowListedMetadataCustom));
assertNotNull(clusterState.metadata().custom("other"));
final ClusterState fixedClusterState = ClusterModule.filterCustomsForPre63Clients(clusterState);
assertNotNull(fixedClusterState.custom(allowListedClusterCustom));
assertNull(fixedClusterState.custom("other"));
assertNotNull(fixedClusterState.metadata().custom(allowListedMetadataCustom));
assertNull(fixedClusterState.metadata().custom("other"));
}
use of org.opensearch.cluster.metadata.RepositoriesMetadata in project OpenSearch by opensearch-project.
the class AbstractSnapshotIntegTestCase method addBwCFailedSnapshot.
/**
* Adds a snapshot in state {@link SnapshotState#FAILED} to the given repository.
*
* @param repoName repository to add snapshot to
* @param snapshotName name for the new failed snapshot
* @param metadata snapshot metadata to write (as returned by {@link SnapshotInfo#userMetadata()})
*/
protected void addBwCFailedSnapshot(String repoName, String snapshotName, Map<String, Object> metadata) throws Exception {
final ClusterState state = clusterAdmin().prepareState().get().getState();
final RepositoriesMetadata repositoriesMetadata = state.metadata().custom(RepositoriesMetadata.TYPE);
assertNotNull(repositoriesMetadata);
final RepositoryMetadata initialRepoMetadata = repositoriesMetadata.repository(repoName);
assertNotNull(initialRepoMetadata);
assertThat("We can only manually insert a snapshot into a repository that does not have a generation tracked in the CS", initialRepoMetadata.generation(), is(RepositoryData.UNKNOWN_REPO_GEN));
final Repository repo = internalCluster().getCurrentMasterNodeInstance(RepositoriesService.class).repository(repoName);
final SnapshotId snapshotId = new SnapshotId(snapshotName, UUIDs.randomBase64UUID(random()));
logger.info("--> adding old version FAILED snapshot [{}] to repository [{}]", snapshotId, repoName);
final SnapshotInfo snapshotInfo = new SnapshotInfo(snapshotId, Collections.emptyList(), Collections.emptyList(), SnapshotState.FAILED, "failed on purpose", SnapshotsService.OLD_SNAPSHOT_FORMAT, 0L, 0L, 0, 0, Collections.emptyList(), randomBoolean(), metadata);
PlainActionFuture.<RepositoryData, Exception>get(f -> repo.finalizeSnapshot(ShardGenerations.EMPTY, getRepositoryData(repoName).getGenId(), state.metadata(), snapshotInfo, SnapshotsService.OLD_SNAPSHOT_FORMAT, Function.identity(), f));
}
use of org.opensearch.cluster.metadata.RepositoriesMetadata in project OpenSearch by opensearch-project.
the class RepositoriesMetadataSerializationTests method mutateInstance.
@Override
protected Custom mutateInstance(Custom instance) {
List<RepositoryMetadata> entries = new ArrayList<>(((RepositoriesMetadata) instance).repositories());
boolean addEntry = entries.isEmpty() ? true : randomBoolean();
if (addEntry) {
entries.add(new RepositoryMetadata(randomAlphaOfLength(10), randomAlphaOfLength(10), randomSettings()));
} else {
entries.remove(randomIntBetween(0, entries.size() - 1));
}
return new RepositoriesMetadata(entries);
}
Aggregations