Search in sources :

Example 1 with RepositoryMetadata

use of org.opensearch.cluster.metadata.RepositoryMetadata in project OpenSearch by opensearch-project.

the class SnapshotClientDocumentationIT method testSnapshotGetRepository.

public void testSnapshotGetRepository() throws IOException {
    RestHighLevelClient client = highLevelClient();
    createTestRepositories();
    // tag::get-repository-request
    GetRepositoriesRequest request = new GetRepositoriesRequest();
    // end::get-repository-request
    // tag::get-repository-request-repositories
    String[] repositories = new String[] { repositoryName };
    // <1>
    request.repositories(repositories);
    // end::get-repository-request-repositories
    // tag::get-repository-request-local
    // <1>
    request.local(true);
    // end::get-repository-request-local
    // tag::get-repository-request-masterTimeout
    // <1>
    request.masterNodeTimeout(TimeValue.timeValueMinutes(1));
    // <2>
    request.masterNodeTimeout("1m");
    // end::get-repository-request-masterTimeout
    // tag::get-repository-execute
    GetRepositoriesResponse response = client.snapshot().getRepository(request, RequestOptions.DEFAULT);
    // end::get-repository-execute
    // tag::get-repository-response
    List<RepositoryMetadata> repositoryMetadataResponse = response.repositories();
    // end::get-repository-response
    assertThat(1, equalTo(repositoryMetadataResponse.size()));
    assertThat(repositoryName, equalTo(repositoryMetadataResponse.get(0).name()));
}
Also used : RepositoryMetadata(org.opensearch.cluster.metadata.RepositoryMetadata) RestHighLevelClient(org.opensearch.client.RestHighLevelClient) GetRepositoriesRequest(org.opensearch.action.admin.cluster.repositories.get.GetRepositoriesRequest) GetRepositoriesResponse(org.opensearch.action.admin.cluster.repositories.get.GetRepositoriesResponse)

Example 2 with RepositoryMetadata

use of org.opensearch.cluster.metadata.RepositoryMetadata in project OpenSearch by opensearch-project.

the class URLRepositoryTests method testNonNormalizedUrl.

public void testNonNormalizedUrl() throws IOException {
    Settings baseSettings = Settings.builder().put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString()).put(URLRepository.ALLOWED_URLS_SETTING.getKey(), "file:/tmp/").put(URLRepository.REPOSITORIES_URL_SETTING.getKey(), "file:/var/").build();
    RepositoryMetadata repositoryMetadata = new RepositoryMetadata("url", URLRepository.TYPE, baseSettings);
    final URLRepository repository = createRepository(baseSettings, repositoryMetadata);
    repository.start();
    try {
        repository.blobContainer();
        fail("RepositoryException should have been thrown.");
    } catch (RepositoryException e) {
        assertEquals("[url] file url [file:/var/] doesn't match any of the locations " + "specified by path.repo or repositories.url.allowed_urls", e.getMessage());
    }
}
Also used : RepositoryMetadata(org.opensearch.cluster.metadata.RepositoryMetadata) RepositoryException(org.opensearch.repositories.RepositoryException) Settings(org.opensearch.common.settings.Settings) ClusterSettings(org.opensearch.common.settings.ClusterSettings) RecoverySettings(org.opensearch.indices.recovery.RecoverySettings)

Example 3 with RepositoryMetadata

use of org.opensearch.cluster.metadata.RepositoryMetadata in project OpenSearch by opensearch-project.

the class AzureBlobContainerRetriesTests method createBlobContainer.

private BlobContainer createBlobContainer(final int maxRetries) {
    final Settings.Builder clientSettings = Settings.builder();
    final String clientName = randomAlphaOfLength(5).toLowerCase(Locale.ROOT);
    final InetSocketAddress address = httpServer.getAddress();
    final String endpoint = "ignored;DefaultEndpointsProtocol=http;BlobEndpoint=http://" + InetAddresses.toUriString(address.getAddress()) + ":" + address.getPort() + "/";
    clientSettings.put(ENDPOINT_SUFFIX_SETTING.getConcreteSettingForNamespace(clientName).getKey(), endpoint);
    clientSettings.put(MAX_RETRIES_SETTING.getConcreteSettingForNamespace(clientName).getKey(), maxRetries);
    clientSettings.put(TIMEOUT_SETTING.getConcreteSettingForNamespace(clientName).getKey(), TimeValue.timeValueMillis(2000));
    final MockSecureSettings secureSettings = new MockSecureSettings();
    secureSettings.setString(ACCOUNT_SETTING.getConcreteSettingForNamespace(clientName).getKey(), "account");
    final String key = Base64.getEncoder().encodeToString(randomAlphaOfLength(10).getBytes(UTF_8));
    secureSettings.setString(KEY_SETTING.getConcreteSettingForNamespace(clientName).getKey(), key);
    clientSettings.setSecureSettings(secureSettings);
    service = new AzureStorageService(clientSettings.build()) {

        @Override
        RequestRetryOptions createRetryPolicy(final AzureStorageSettings azureStorageSettings, String secondaryHost) {
            return new RequestRetryOptions(RetryPolicyType.EXPONENTIAL, azureStorageSettings.getMaxRetries(), 1, 10L, 100L, secondaryHost);
        }

        @Override
        ParallelTransferOptions getBlobRequestOptionsForWriteBlob() {
            return new ParallelTransferOptions().setMaxSingleUploadSizeLong(ByteSizeUnit.MB.toBytes(1));
        }
    };
    final RepositoryMetadata repositoryMetadata = new RepositoryMetadata("repository", AzureRepository.TYPE, Settings.builder().put(CONTAINER_SETTING.getKey(), "container").put(ACCOUNT_SETTING.getKey(), clientName).build());
    return new AzureBlobContainer(BlobPath.cleanPath(), new AzureBlobStore(repositoryMetadata, service, threadPool), threadPool);
}
Also used : RequestRetryOptions(com.azure.storage.common.policy.RequestRetryOptions) InetSocketAddress(java.net.InetSocketAddress) Matchers.containsString(org.hamcrest.Matchers.containsString) MockSecureSettings(org.opensearch.common.settings.MockSecureSettings) RepositoryMetadata(org.opensearch.cluster.metadata.RepositoryMetadata) ParallelTransferOptions(com.azure.storage.blob.models.ParallelTransferOptions) MockSecureSettings(org.opensearch.common.settings.MockSecureSettings) Settings(org.opensearch.common.settings.Settings)

Example 4 with RepositoryMetadata

use of org.opensearch.cluster.metadata.RepositoryMetadata in project OpenSearch by opensearch-project.

the class RepositoriesServiceIT method testUpdateRepository.

public void testUpdateRepository() {
    final InternalTestCluster cluster = internalCluster();
    final String repositoryName = "test-repo";
    final Client client = client();
    final RepositoriesService repositoriesService = cluster.getDataOrMasterNodeInstances(RepositoriesService.class).iterator().next();
    final Settings.Builder repoSettings = Settings.builder().put("location", randomRepoPath());
    assertAcked(client.admin().cluster().preparePutRepository(repositoryName).setType(FsRepository.TYPE).setSettings(repoSettings).get());
    final GetRepositoriesResponse originalGetRepositoriesResponse = client.admin().cluster().prepareGetRepositories(repositoryName).get();
    assertThat(originalGetRepositoriesResponse.repositories(), hasSize(1));
    RepositoryMetadata originalRepositoryMetadata = originalGetRepositoriesResponse.repositories().get(0);
    assertThat(originalRepositoryMetadata.type(), equalTo(FsRepository.TYPE));
    final Repository originalRepository = repositoriesService.repository(repositoryName);
    assertThat(originalRepository, instanceOf(FsRepository.class));
    final boolean updated = randomBoolean();
    final String updatedRepositoryType = updated ? "mock" : FsRepository.TYPE;
    assertAcked(client.admin().cluster().preparePutRepository(repositoryName).setType(updatedRepositoryType).setSettings(repoSettings).get());
    final GetRepositoriesResponse updatedGetRepositoriesResponse = client.admin().cluster().prepareGetRepositories(repositoryName).get();
    assertThat(updatedGetRepositoriesResponse.repositories(), hasSize(1));
    final RepositoryMetadata updatedRepositoryMetadata = updatedGetRepositoriesResponse.repositories().get(0);
    assertThat(updatedRepositoryMetadata.type(), equalTo(updatedRepositoryType));
    final Repository updatedRepository = repositoriesService.repository(repositoryName);
    assertThat(updatedRepository, updated ? not(sameInstance(originalRepository)) : sameInstance(originalRepository));
}
Also used : FsRepository(org.opensearch.repositories.fs.FsRepository) MockRepository(org.opensearch.snapshots.mockstore.MockRepository) RepositoryMetadata(org.opensearch.cluster.metadata.RepositoryMetadata) InternalTestCluster(org.opensearch.test.InternalTestCluster) Client(org.opensearch.client.Client) GetRepositoriesResponse(org.opensearch.action.admin.cluster.repositories.get.GetRepositoriesResponse) Settings(org.opensearch.common.settings.Settings) FsRepository(org.opensearch.repositories.fs.FsRepository)

Example 5 with RepositoryMetadata

use of org.opensearch.cluster.metadata.RepositoryMetadata in project OpenSearch by opensearch-project.

the class BlobStoreRepository method executeConsistentStateUpdate.

@Override
public void executeConsistentStateUpdate(Function<RepositoryData, ClusterStateUpdateTask> createUpdateTask, String source, Consumer<Exception> onFailure) {
    final RepositoryMetadata repositoryMetadataStart = metadata;
    getRepositoryData(ActionListener.wrap(repositoryData -> {
        final ClusterStateUpdateTask updateTask = createUpdateTask.apply(repositoryData);
        clusterService.submitStateUpdateTask(source, new ClusterStateUpdateTask(updateTask.priority()) {

            private boolean executedTask = false;

            @Override
            public ClusterState execute(ClusterState currentState) throws Exception {
                // to change in any form.
                if (repositoryMetadataStart.equals(getRepoMetadata(currentState))) {
                    executedTask = true;
                    return updateTask.execute(currentState);
                }
                return currentState;
            }

            @Override
            public void onFailure(String source, Exception e) {
                if (executedTask) {
                    updateTask.onFailure(source, e);
                } else {
                    onFailure.accept(e);
                }
            }

            @Override
            public void clusterStateProcessed(String source, ClusterState oldState, ClusterState newState) {
                if (executedTask) {
                    updateTask.clusterStateProcessed(source, oldState, newState);
                } else {
                    executeConsistentStateUpdate(createUpdateTask, source, onFailure);
                }
            }

            @Override
            public TimeValue timeout() {
                return updateTask.timeout();
            }
        });
    }, onFailure));
}
Also used : Metadata(org.opensearch.cluster.metadata.Metadata) IndexFormatTooNewException(org.apache.lucene.index.IndexFormatTooNewException) AllocationService(org.opensearch.cluster.routing.allocation.AllocationService) AlreadyClosedException(org.apache.lucene.store.AlreadyClosedException) Version(org.opensearch.Version) Strings(org.opensearch.common.Strings) AbortedSnapshotException(org.opensearch.snapshots.AbortedSnapshotException) GroupedActionListener(org.opensearch.action.support.GroupedActionListener) RecoveryState(org.opensearch.indices.recovery.RecoveryState) Map(java.util.Map) Lucene(org.opensearch.common.lucene.Lucene) ActionListener(org.opensearch.action.ActionListener) IOContext(org.apache.lucene.store.IOContext) Repository(org.opensearch.repositories.Repository) TimeValue(org.opensearch.common.unit.TimeValue) ExceptionsHelper(org.opensearch.ExceptionsHelper) Set(java.util.Set) Settings(org.opensearch.common.settings.Settings) BlobStoreIndexShardSnapshot(org.opensearch.index.snapshots.blobstore.BlobStoreIndexShardSnapshot) BlockingQueue(java.util.concurrent.BlockingQueue) AbstractLifecycleComponent(org.opensearch.common.component.AbstractLifecycleComponent) Logger(org.apache.logging.log4j.Logger) RepositoryOperation(org.opensearch.repositories.RepositoryOperation) Stream(java.util.stream.Stream) ClusterStateUpdateTask(org.opensearch.cluster.ClusterStateUpdateTask) BytesArray(org.opensearch.common.bytes.BytesArray) BlobStoreIndexShardSnapshots(org.opensearch.index.snapshots.blobstore.BlobStoreIndexShardSnapshots) FsBlobContainer(org.opensearch.common.blobstore.fs.FsBlobContainer) StepListener(org.opensearch.action.StepListener) XContentType(org.opensearch.common.xcontent.XContentType) IndexCommit(org.apache.lucene.index.IndexCommit) ThreadPool(org.opensearch.threadpool.ThreadPool) BlobContainer(org.opensearch.common.blobstore.BlobContainer) Releasable(org.opensearch.common.lease.Releasable) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) ClusterState(org.opensearch.cluster.ClusterState) SnapshotMissingException(org.opensearch.snapshots.SnapshotMissingException) Numbers(org.opensearch.common.Numbers) SlicedInputStream(org.opensearch.index.snapshots.blobstore.SlicedInputStream) SnapshotException(org.opensearch.snapshots.SnapshotException) Streams(org.opensearch.common.io.Streams) CompressorFactory(org.opensearch.common.compress.CompressorFactory) RepositoryVerificationException(org.opensearch.repositories.RepositoryVerificationException) RepositoryCleanupInProgress(org.opensearch.cluster.RepositoryCleanupInProgress) InputStreamIndexInput(org.opensearch.common.lucene.store.InputStreamIndexInput) LongStream(java.util.stream.LongStream) IndexInput(org.apache.lucene.store.IndexInput) SetOnce(org.apache.lucene.util.SetOnce) RepositoriesMetadata(org.opensearch.cluster.metadata.RepositoriesMetadata) Executor(java.util.concurrent.Executor) SnapshotInfo(org.opensearch.snapshots.SnapshotInfo) RepositoryMetadata(org.opensearch.cluster.metadata.RepositoryMetadata) IOException(java.io.IOException) IndexShardSnapshotFailedException(org.opensearch.index.snapshots.IndexShardSnapshotFailedException) NotXContentException(org.opensearch.common.compress.NotXContentException) AtomicLong(java.util.concurrent.atomic.AtomicLong) RepositoryCleanupResult(org.opensearch.repositories.RepositoryCleanupResult) BlobPath(org.opensearch.common.blobstore.BlobPath) NamedXContentRegistry(org.opensearch.common.xcontent.NamedXContentRegistry) ClusterService(org.opensearch.cluster.service.ClusterService) CounterMetric(org.opensearch.common.metrics.CounterMetric) ShardGenerations(org.opensearch.repositories.ShardGenerations) NoSuchFileException(java.nio.file.NoSuchFileException) AbstractRunnable(org.opensearch.common.util.concurrent.AbstractRunnable) SnapshotCreationException(org.opensearch.snapshots.SnapshotCreationException) ByteSizeUnit(org.opensearch.common.unit.ByteSizeUnit) SnapshotFiles(org.opensearch.index.snapshots.blobstore.SnapshotFiles) SnapshotsService(org.opensearch.snapshots.SnapshotsService) CorruptIndexException(org.apache.lucene.index.CorruptIndexException) ConcurrentCollections(org.opensearch.common.util.concurrent.ConcurrentCollections) XContentParser(org.opensearch.common.xcontent.XContentParser) DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) MapperService(org.opensearch.index.mapper.MapperService) IndexId(org.opensearch.repositories.IndexId) XContentFactory(org.opensearch.common.xcontent.XContentFactory) RepositoryStats(org.opensearch.repositories.RepositoryStats) BlobMetadata(org.opensearch.common.blobstore.BlobMetadata) RecoverySettings(org.opensearch.indices.recovery.RecoverySettings) RepositoryException(org.opensearch.repositories.RepositoryException) FileInfo.canonicalName(org.opensearch.index.snapshots.blobstore.BlobStoreIndexShardSnapshot.FileInfo.canonicalName) BytesRef(org.apache.lucene.util.BytesRef) SnapshotId(org.opensearch.snapshots.SnapshotId) Collection(java.util.Collection) LoggingDeprecationHandler(org.opensearch.common.xcontent.LoggingDeprecationHandler) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Store(org.opensearch.index.store.Store) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) Collectors(java.util.stream.Collectors) Nullable(org.opensearch.common.Nullable) Tuple(org.opensearch.common.collect.Tuple) BlobStore(org.opensearch.common.blobstore.BlobStore) List(java.util.List) Optional(java.util.Optional) BytesReference(org.opensearch.common.bytes.BytesReference) RateLimitingInputStream(org.opensearch.index.snapshots.blobstore.RateLimitingInputStream) IndexMetadata(org.opensearch.cluster.metadata.IndexMetadata) ActionRunnable(org.opensearch.action.ActionRunnable) SnapshotsInProgress(org.opensearch.cluster.SnapshotsInProgress) ByteSizeValue(org.opensearch.common.unit.ByteSizeValue) SnapshotDeletionsInProgress(org.opensearch.cluster.SnapshotDeletionsInProgress) ParameterizedMessage(org.apache.logging.log4j.message.ParameterizedMessage) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) FilterInputStream(java.io.FilterInputStream) IndexShardSnapshotStatus(org.opensearch.index.snapshots.IndexShardSnapshotStatus) IndexMetaDataGenerations(org.opensearch.repositories.IndexMetaDataGenerations) UUIDs(org.opensearch.common.UUIDs) StoreFileMetadata(org.opensearch.index.store.StoreFileMetadata) IndexOutput(org.apache.lucene.store.IndexOutput) IndexShardRestoreFailedException(org.opensearch.index.snapshots.IndexShardRestoreFailedException) RepositoryData(org.opensearch.repositories.RepositoryData) Setting(org.opensearch.common.settings.Setting) RepositoryShardId(org.opensearch.repositories.RepositoryShardId) IndexFormatTooOldException(org.apache.lucene.index.IndexFormatTooOldException) ShardId(org.opensearch.index.shard.ShardId) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) DeleteResult(org.opensearch.common.blobstore.DeleteResult) LogManager(org.apache.logging.log4j.LogManager) Collections(java.util.Collections) RateLimiter(org.apache.lucene.store.RateLimiter) InputStream(java.io.InputStream) ClusterState(org.opensearch.cluster.ClusterState) RepositoryMetadata(org.opensearch.cluster.metadata.RepositoryMetadata) ClusterStateUpdateTask(org.opensearch.cluster.ClusterStateUpdateTask) IndexFormatTooNewException(org.apache.lucene.index.IndexFormatTooNewException) AlreadyClosedException(org.apache.lucene.store.AlreadyClosedException) AbortedSnapshotException(org.opensearch.snapshots.AbortedSnapshotException) SnapshotMissingException(org.opensearch.snapshots.SnapshotMissingException) SnapshotException(org.opensearch.snapshots.SnapshotException) RepositoryVerificationException(org.opensearch.repositories.RepositoryVerificationException) IOException(java.io.IOException) IndexShardSnapshotFailedException(org.opensearch.index.snapshots.IndexShardSnapshotFailedException) NotXContentException(org.opensearch.common.compress.NotXContentException) NoSuchFileException(java.nio.file.NoSuchFileException) SnapshotCreationException(org.opensearch.snapshots.SnapshotCreationException) CorruptIndexException(org.apache.lucene.index.CorruptIndexException) RepositoryException(org.opensearch.repositories.RepositoryException) IndexShardRestoreFailedException(org.opensearch.index.snapshots.IndexShardRestoreFailedException) IndexFormatTooOldException(org.apache.lucene.index.IndexFormatTooOldException)

Aggregations

RepositoryMetadata (org.opensearch.cluster.metadata.RepositoryMetadata)37 Settings (org.opensearch.common.settings.Settings)16 RepositoriesMetadata (org.opensearch.cluster.metadata.RepositoriesMetadata)12 RecoverySettings (org.opensearch.indices.recovery.RecoverySettings)11 ArrayList (java.util.ArrayList)8 BlobContainer (org.opensearch.common.blobstore.BlobContainer)8 ClusterSettings (org.opensearch.common.settings.ClusterSettings)8 IOException (java.io.IOException)7 BlobStoreRepository (org.opensearch.repositories.blobstore.BlobStoreRepository)7 ByteArrayInputStream (java.io.ByteArrayInputStream)6 ParameterizedMessage (org.apache.logging.log4j.message.ParameterizedMessage)6 ClusterState (org.opensearch.cluster.ClusterState)6 Metadata (org.opensearch.cluster.metadata.Metadata)6 ClusterService (org.opensearch.cluster.service.ClusterService)6 Collections (java.util.Collections)5 Path (java.nio.file.Path)4 Collection (java.util.Collection)4 List (java.util.List)4 Map (java.util.Map)4 Collectors (java.util.stream.Collectors)4