Search in sources :

Example 6 with RepositoriesMetadata

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();
}
Also used : ClusterState(org.opensearch.cluster.ClusterState) RepositoriesMetadata(org.opensearch.cluster.metadata.RepositoriesMetadata) RepositoryMetadata(org.opensearch.cluster.metadata.RepositoryMetadata) Metadata(org.opensearch.cluster.metadata.Metadata) IndexMetadata(org.opensearch.cluster.metadata.IndexMetadata) RepositoriesMetadata(org.opensearch.cluster.metadata.RepositoriesMetadata) RepositoryMetadata(org.opensearch.cluster.metadata.RepositoryMetadata) ClusterName(org.opensearch.cluster.ClusterName)

Example 7 with RepositoriesMetadata

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);
}
Also used : RepositoriesMetadata(org.opensearch.cluster.metadata.RepositoriesMetadata) RepositoryMetadata(org.opensearch.cluster.metadata.RepositoryMetadata) ArrayList(java.util.ArrayList)

Example 8 with RepositoriesMetadata

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"));
}
Also used : RepositoriesMetadata(org.opensearch.cluster.metadata.RepositoriesMetadata)

Example 9 with RepositoriesMetadata

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));
}
Also used : ClusterState(org.opensearch.cluster.ClusterState) RepositoriesMetadata(org.opensearch.cluster.metadata.RepositoriesMetadata) BlobStoreRepository(org.opensearch.repositories.blobstore.BlobStoreRepository) Repository(org.opensearch.repositories.Repository) MockRepository(org.opensearch.snapshots.mockstore.MockRepository) RepositoryMetadata(org.opensearch.cluster.metadata.RepositoryMetadata) RepositoriesService(org.opensearch.repositories.RepositoriesService) TimeoutException(java.util.concurrent.TimeoutException) NodeClosedException(org.opensearch.node.NodeClosedException) IOException(java.io.IOException) RepositoryData(org.opensearch.repositories.RepositoryData)

Example 10 with RepositoriesMetadata

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);
}
Also used : RepositoriesMetadata(org.opensearch.cluster.metadata.RepositoriesMetadata) RepositoryMetadata(org.opensearch.cluster.metadata.RepositoryMetadata) ArrayList(java.util.ArrayList)

Aggregations

RepositoriesMetadata (org.opensearch.cluster.metadata.RepositoriesMetadata)16 RepositoryMetadata (org.opensearch.cluster.metadata.RepositoryMetadata)12 ArrayList (java.util.ArrayList)8 ClusterState (org.opensearch.cluster.ClusterState)5 Metadata (org.opensearch.cluster.metadata.Metadata)5 IOException (java.io.IOException)4 Map (java.util.Map)3 ParameterizedMessage (org.apache.logging.log4j.message.ParameterizedMessage)3 SnapshotsInProgress (org.opensearch.cluster.SnapshotsInProgress)3 Path (java.nio.file.Path)2 Collection (java.util.Collection)2 Collections (java.util.Collections)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 Stream (java.util.stream.Stream)2 LogManager (org.apache.logging.log4j.LogManager)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2 ClusterService (org.opensearch.cluster.service.ClusterService)2