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.");
}
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")))));
}
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()));
}
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;
}
Aggregations