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