Search in sources :

Example 21 with RepositoriesService

use of org.opensearch.repositories.RepositoriesService in project OpenSearch by opensearch-project.

the class RepositoryCredentialsTests method testRepositoryCredentialsOverrideSecureCredentials.

public void testRepositoryCredentialsOverrideSecureCredentials() {
    final String repositoryName = "repo-creds-override";
    final Settings.Builder repositorySettings = Settings.builder().put(S3Repository.ACCESS_KEY_SETTING.getKey(), "insecure_aws_key").put(S3Repository.SECRET_KEY_SETTING.getKey(), "insecure_aws_secret");
    final String clientName = randomFrom("default", "other", null);
    if (clientName != null) {
        repositorySettings.put(S3Repository.CLIENT_NAME.getKey(), clientName);
    }
    createRepository(repositoryName, repositorySettings.build());
    final RepositoriesService repositories = getInstanceFromNode(RepositoriesService.class);
    assertThat(repositories.repository(repositoryName), notNullValue());
    assertThat(repositories.repository(repositoryName), instanceOf(S3Repository.class));
    final S3Repository repository = (S3Repository) repositories.repository(repositoryName);
    final AmazonS3 client = repository.createBlobStore().clientReference().get();
    assertThat(client, instanceOf(ProxyS3RepositoryPlugin.ClientAndCredentials.class));
    final AWSCredentials credentials = ((ProxyS3RepositoryPlugin.ClientAndCredentials) client).credentials.getCredentials();
    assertThat(credentials.getAWSAccessKeyId(), is("insecure_aws_key"));
    assertThat(credentials.getAWSSecretKey(), is("insecure_aws_secret"));
    assertWarnings("[secret_key] setting was deprecated in OpenSearch and will be removed in a future release!" + " See the breaking changes documentation for the next major version.", "Using s3 access/secret key from repository settings. Instead store these in named clients and" + " the opensearch keystore for secure settings.", "[access_key] setting was deprecated in OpenSearch and will be removed in a future release!" + " See the breaking changes documentation for the next major version.");
}
Also used : AmazonS3(com.amazonaws.services.s3.AmazonS3) RepositoriesService(org.opensearch.repositories.RepositoriesService) Matchers.containsString(org.hamcrest.Matchers.containsString) AWSCredentials(com.amazonaws.auth.AWSCredentials) MockSecureSettings(org.opensearch.common.settings.MockSecureSettings) RecoverySettings(org.opensearch.indices.recovery.RecoverySettings) Settings(org.opensearch.common.settings.Settings)

Example 22 with RepositoriesService

use of org.opensearch.repositories.RepositoriesService in project OpenSearch by opensearch-project.

the class GoogleCloudStorageBlobStoreRepositoryTests method testDeleteSingleItem.

public void testDeleteSingleItem() {
    final String repoName = createRepository(randomName());
    final RepositoriesService repositoriesService = internalCluster().getMasterNodeInstance(RepositoriesService.class);
    final BlobStoreRepository repository = (BlobStoreRepository) repositoriesService.repository(repoName);
    PlainActionFuture.get(f -> repository.threadPool().generic().execute(ActionRunnable.run(f, () -> repository.blobStore().blobContainer(repository.basePath()).deleteBlobsIgnoringIfNotExists(Collections.singletonList("foo")))));
}
Also used : BlobStoreRepository(org.opensearch.repositories.blobstore.BlobStoreRepository) RepositoriesService(org.opensearch.repositories.RepositoriesService)

Example 23 with RepositoriesService

use of org.opensearch.repositories.RepositoriesService in project OpenSearch by opensearch-project.

the class S3BlobStoreRepositoryTests method testEnforcedCooldownPeriod.

public void testEnforcedCooldownPeriod() throws IOException {
    final String repoName = createRepository(randomName(), Settings.builder().put(repositorySettings()).put(S3Repository.COOLDOWN_PERIOD.getKey(), TEST_COOLDOWN_PERIOD).build());
    final SnapshotId fakeOldSnapshot = client().admin().cluster().prepareCreateSnapshot(repoName, "snapshot-old").setWaitForCompletion(true).setIndices().get().getSnapshotInfo().snapshotId();
    final RepositoriesService repositoriesService = internalCluster().getCurrentMasterNodeInstance(RepositoriesService.class);
    final BlobStoreRepository repository = (BlobStoreRepository) repositoriesService.repository(repoName);
    final RepositoryData repositoryData = getRepositoryData(repository);
    final RepositoryData modifiedRepositoryData = repositoryData.withVersions(Collections.singletonMap(fakeOldSnapshot, SnapshotsService.SHARD_GEN_IN_REPO_DATA_VERSION.minimumCompatibilityVersion()));
    final BytesReference serialized = BytesReference.bytes(modifiedRepositoryData.snapshotsToXContent(XContentFactory.jsonBuilder(), SnapshotsService.OLD_SNAPSHOT_FORMAT));
    PlainActionFuture.get(f -> repository.threadPool().generic().execute(ActionRunnable.run(f, () -> {
        try (InputStream stream = serialized.streamInput()) {
            repository.blobStore().blobContainer(repository.basePath()).writeBlobAtomic(BlobStoreRepository.INDEX_FILE_PREFIX + modifiedRepositoryData.getGenId(), stream, serialized.length(), true);
        }
    })));
    final String newSnapshotName = "snapshot-new";
    final long beforeThrottledSnapshot = repository.threadPool().relativeTimeInNanos();
    client().admin().cluster().prepareCreateSnapshot(repoName, newSnapshotName).setWaitForCompletion(true).setIndices().get();
    assertThat(repository.threadPool().relativeTimeInNanos() - beforeThrottledSnapshot, greaterThan(TEST_COOLDOWN_PERIOD.getNanos()));
    final long beforeThrottledDelete = repository.threadPool().relativeTimeInNanos();
    client().admin().cluster().prepareDeleteSnapshot(repoName, newSnapshotName).get();
    assertThat(repository.threadPool().relativeTimeInNanos() - beforeThrottledDelete, greaterThan(TEST_COOLDOWN_PERIOD.getNanos()));
    final long beforeFastDelete = repository.threadPool().relativeTimeInNanos();
    client().admin().cluster().prepareDeleteSnapshot(repoName, fakeOldSnapshot.getName()).get();
    assertThat(repository.threadPool().relativeTimeInNanos() - beforeFastDelete, lessThan(TEST_COOLDOWN_PERIOD.getNanos()));
}
Also used : BytesReference(org.opensearch.common.bytes.BytesReference) SnapshotId(org.opensearch.snapshots.SnapshotId) BlobStoreRepository(org.opensearch.repositories.blobstore.BlobStoreRepository) InputStream(java.io.InputStream) RepositoriesService(org.opensearch.repositories.RepositoriesService) Matchers.containsString(org.hamcrest.Matchers.containsString) RepositoryData(org.opensearch.repositories.RepositoryData)

Example 24 with RepositoriesService

use of org.opensearch.repositories.RepositoriesService in project security by opensearch-project.

the class SnapshotRestoreHelper method getSnapshotInfo.

public static SnapshotInfo getSnapshotInfo(RestoreSnapshotRequest restoreRequest) {
    final RepositoriesService repositoriesService = Objects.requireNonNull(OpenSearchSecurityPlugin.GuiceHolder.getRepositoriesService(), "RepositoriesService not initialized");
    final Repository repository = repositoriesService.repository(restoreRequest.repository());
    final String threadName = Thread.currentThread().getName();
    SnapshotInfo snapshotInfo = null;
    try {
        setCurrentThreadName("[" + ThreadPool.Names.GENERIC + "]");
        for (SnapshotId snapshotId : PlainActionFuture.get(repository::getRepositoryData).getSnapshotIds()) {
            if (snapshotId.getName().equals(restoreRequest.snapshot())) {
                if (log.isDebugEnabled()) {
                    log.debug("snapshot found: {} (UUID: {})", snapshotId.getName(), snapshotId.getUUID());
                }
                snapshotInfo = repository.getSnapshotInfo(snapshotId);
                break;
            }
        }
    } finally {
        setCurrentThreadName(threadName);
    }
    return snapshotInfo;
}
Also used : SnapshotId(org.opensearch.snapshots.SnapshotId) Repository(org.opensearch.repositories.Repository) SnapshotInfo(org.opensearch.snapshots.SnapshotInfo) RepositoriesService(org.opensearch.repositories.RepositoriesService)

Aggregations

RepositoriesService (org.opensearch.repositories.RepositoriesService)24 Settings (org.opensearch.common.settings.Settings)8 Repository (org.opensearch.repositories.Repository)8 ThreadPool (org.opensearch.threadpool.ThreadPool)6 Collections (java.util.Collections)5 Map (java.util.Map)5 Function (java.util.function.Function)5 Client (org.opensearch.client.Client)5 Locale (java.util.Locale)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 TimeUnit (java.util.concurrent.TimeUnit)4 Arrays (java.util.Arrays)3 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 SetOnce (org.apache.lucene.util.SetOnce)3 Matchers.containsString (org.hamcrest.Matchers.containsString)3 CreateSnapshotResponse (org.opensearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse)3 IndexMetadata (org.opensearch.cluster.metadata.IndexMetadata)3 RecoverySource (org.opensearch.cluster.routing.RecoverySource)3 ShardRouting (org.opensearch.cluster.routing.ShardRouting)3