use of org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryRequest in project crate by crate.
the class CreateDropRepositoryAnalyzerTest method testCreateRepository.
@Test
public void testCreateRepository() {
PutRepositoryRequest request = analyze(e, "CREATE REPOSITORY \"new_repository\" TYPE \"fs\" WITH (" + " location='/mount/backups/my_backup'," + " compress=True)");
assertThat(request.name(), is("new_repository"));
assertThat(request.type(), is("fs"));
assertThat(request.settings().getAsStructuredMap(), allOf(hasEntry("compress", "true"), hasEntry("location", "/mount/backups/my_backup")));
}
use of org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryRequest in project crate by crate.
the class S3RepositoryPluginAnalyzerTest method testCreateS3RepositoryWithAllSettings.
@Test
public void testCreateS3RepositoryWithAllSettings() {
PutRepositoryRequest request = analyze(e, "CREATE REPOSITORY foo TYPE s3 WITH (" + " bucket='abc'," + " endpoint='www.example.com'," + " protocol='http'," + " base_path='/holz/'," + " access_key='0xAFFE'," + " secret_key='0xCAFEE'," + " chunk_size='12mb'," + " compress=true," + " server_side_encryption=false," + " buffer_size='5mb'," + " max_retries=2," + " use_throttle_retries=false," + " readonly=false, " + " canned_acl=false)");
assertThat(request.name(), is("foo"));
assertThat(request.type(), is("s3"));
assertThat(request.settings().getAsStructuredMap(), Matchers.allOf(Matchers.hasEntry("access_key", "0xAFFE"), Matchers.hasEntry("base_path", "/holz/"), Matchers.hasEntry("bucket", "abc"), Matchers.hasEntry("buffer_size", "5mb"), Matchers.hasEntry("canned_acl", "false"), Matchers.hasEntry("chunk_size", "12mb"), Matchers.hasEntry("compress", "true"), Matchers.hasEntry("endpoint", "www.example.com"), Matchers.hasEntry("max_retries", "2"), Matchers.hasEntry("use_throttle_retries", "false"), Matchers.hasEntry("protocol", "http"), Matchers.hasEntry("secret_key", "0xCAFEE"), Matchers.hasEntry("server_side_encryption", "false"), Matchers.hasEntry("readonly", "false")));
}
use of org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryRequest in project crate by crate.
the class CreateRepositoryPlan method executeOrFail.
@Override
public void executeOrFail(DependencyCarrier dependencies, PlannerContext plannerContext, RowConsumer consumer, Row parameters, SubQueryResults subQueryResults) {
PutRepositoryRequest request = createRequest(createRepository, plannerContext.transactionContext(), dependencies.nodeContext(), parameters, subQueryResults, dependencies.repositoryParamValidator());
dependencies.repositoryService().execute(request).whenComplete(new OneRowActionListener<>(consumer, rCount -> new Row1(rCount == null ? -1 : rCount)));
}
use of org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryRequest in project crate by crate.
the class CreateRepositoryPlan method createRequest.
@VisibleForTesting
public static PutRepositoryRequest createRequest(AnalyzedCreateRepository createRepository, CoordinatorTxnCtx txnCtx, NodeContext nodeCtx, Row parameters, SubQueryResults subQueryResults, RepositoryParamValidator repositoryParamValidator) {
Function<? super Symbol, Object> eval = x -> SymbolEvaluator.evaluate(txnCtx, nodeCtx, x, parameters, subQueryResults);
var genericProperties = createRepository.properties().map(eval);
var settings = genericPropertiesToSettings(genericProperties, // supported settings for the repository type
repositoryParamValidator.settingsForType(createRepository.type()).all());
repositoryParamValidator.validate(createRepository.type(), createRepository.properties(), settings);
PutRepositoryRequest request = new PutRepositoryRequest(createRepository.name());
request.type(createRepository.type());
request.settings(settings);
return request;
}
use of org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryRequest in project crate by crate.
the class RepositoryServiceTest method testRepositoryIsDroppedOnFailure.
@Test
public void testRepositoryIsDroppedOnFailure() throws Throwable {
expectedException.expect(RepositoryException.class);
// add repo to cluster service so that it exists..
RepositoriesMetadata repos = new RepositoriesMetadata(Collections.singletonList(new RepositoryMetadata("repo1", "fs", Settings.EMPTY)));
ClusterState state = ClusterState.builder(new ClusterName("dummy")).metadata(Metadata.builder().putCustom(RepositoriesMetadata.TYPE, repos)).build();
ClusterServiceUtils.setState(clusterService, state);
IndexNameExpressionResolver indexNameExpressionResolver = new IndexNameExpressionResolver();
final AtomicBoolean deleteRepoCalled = new AtomicBoolean(false);
MockTransportService transportService = MockTransportService.createNewService(Settings.EMPTY, Version.CURRENT, THREAD_POOL, clusterService.getClusterSettings());
TransportDeleteRepositoryAction deleteRepositoryAction = new TransportDeleteRepositoryAction(transportService, clusterService, mock(RepositoriesService.class), THREAD_POOL, indexNameExpressionResolver) {
@Override
protected void doExecute(DeleteRepositoryRequest request, ActionListener<AcknowledgedResponse> listener) {
deleteRepoCalled.set(true);
listener.onResponse(mock(AcknowledgedResponse.class));
}
};
TransportPutRepositoryAction putRepo = new TransportPutRepositoryAction(transportService, clusterService, mock(RepositoriesService.class), THREAD_POOL, indexNameExpressionResolver) {
@Override
protected void doExecute(PutRepositoryRequest request, ActionListener<AcknowledgedResponse> listener) {
listener.onFailure(new RepositoryException(request.name(), "failure"));
}
};
RepositoryService repositoryService = new RepositoryService(clusterService, deleteRepositoryAction, putRepo);
try {
PutRepositoryRequest request = new PutRepositoryRequest("repo1");
request.type("fs");
repositoryService.execute(request).get(10, TimeUnit.SECONDS);
} catch (ExecutionException e) {
assertThat(deleteRepoCalled.get(), is(true));
throw e.getCause();
}
}
Aggregations