Search in sources :

Example 6 with PutRepositoryRequest

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")));
}
Also used : PutRepositoryRequest(org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryRequest) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Example 7 with PutRepositoryRequest

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")));
}
Also used : PutRepositoryRequest(org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryRequest) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Example 8 with PutRepositoryRequest

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)));
}
Also used : NodeContext(io.crate.metadata.NodeContext) GenericPropertiesConverter.genericPropertiesToSettings(io.crate.analyze.GenericPropertiesConverter.genericPropertiesToSettings) RepositoryParamValidator(io.crate.analyze.repositories.RepositoryParamValidator) Function(java.util.function.Function) RowConsumer(io.crate.data.RowConsumer) DependencyCarrier(io.crate.planner.DependencyCarrier) PutRepositoryRequest(org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryRequest) SymbolEvaluator(io.crate.analyze.SymbolEvaluator) Row(io.crate.data.Row) AnalyzedCreateRepository(io.crate.analyze.AnalyzedCreateRepository) Symbol(io.crate.expression.symbol.Symbol) PlannerContext(io.crate.planner.PlannerContext) Plan(io.crate.planner.Plan) SubQueryResults(io.crate.planner.operators.SubQueryResults) VisibleForTesting(io.crate.common.annotations.VisibleForTesting) OneRowActionListener(io.crate.execution.support.OneRowActionListener) Row1(io.crate.data.Row1) CoordinatorTxnCtx(io.crate.metadata.CoordinatorTxnCtx) Row1(io.crate.data.Row1) PutRepositoryRequest(org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryRequest)

Example 9 with PutRepositoryRequest

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;
}
Also used : NodeContext(io.crate.metadata.NodeContext) GenericPropertiesConverter.genericPropertiesToSettings(io.crate.analyze.GenericPropertiesConverter.genericPropertiesToSettings) RepositoryParamValidator(io.crate.analyze.repositories.RepositoryParamValidator) Function(java.util.function.Function) RowConsumer(io.crate.data.RowConsumer) DependencyCarrier(io.crate.planner.DependencyCarrier) PutRepositoryRequest(org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryRequest) SymbolEvaluator(io.crate.analyze.SymbolEvaluator) Row(io.crate.data.Row) AnalyzedCreateRepository(io.crate.analyze.AnalyzedCreateRepository) Symbol(io.crate.expression.symbol.Symbol) PlannerContext(io.crate.planner.PlannerContext) Plan(io.crate.planner.Plan) SubQueryResults(io.crate.planner.operators.SubQueryResults) VisibleForTesting(io.crate.common.annotations.VisibleForTesting) OneRowActionListener(io.crate.execution.support.OneRowActionListener) Row1(io.crate.data.Row1) CoordinatorTxnCtx(io.crate.metadata.CoordinatorTxnCtx) PutRepositoryRequest(org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryRequest) VisibleForTesting(io.crate.common.annotations.VisibleForTesting)

Example 10 with PutRepositoryRequest

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();
    }
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) MockTransportService(org.elasticsearch.test.transport.MockTransportService) TransportDeleteRepositoryAction(org.elasticsearch.action.admin.cluster.repositories.delete.TransportDeleteRepositoryAction) DeleteRepositoryRequest(org.elasticsearch.action.admin.cluster.repositories.delete.DeleteRepositoryRequest) AcknowledgedResponse(org.elasticsearch.action.support.master.AcknowledgedResponse) RepositoryException(org.elasticsearch.repositories.RepositoryException) RepositoriesMetadata(org.elasticsearch.cluster.metadata.RepositoriesMetadata) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ActionListener(org.elasticsearch.action.ActionListener) RepositoryMetadata(org.elasticsearch.cluster.metadata.RepositoryMetadata) RepositoriesService(org.elasticsearch.repositories.RepositoriesService) ClusterName(org.elasticsearch.cluster.ClusterName) IndexNameExpressionResolver(org.elasticsearch.cluster.metadata.IndexNameExpressionResolver) TransportPutRepositoryAction(org.elasticsearch.action.admin.cluster.repositories.put.TransportPutRepositoryAction) ExecutionException(java.util.concurrent.ExecutionException) PutRepositoryRequest(org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryRequest) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Aggregations

PutRepositoryRequest (org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryRequest)10 Test (org.junit.Test)5 CrateDummyClusterServiceUnitTest (io.crate.test.integration.CrateDummyClusterServiceUnitTest)4 ActionListener (org.elasticsearch.action.ActionListener)3 DeleteRepositoryRequest (org.elasticsearch.action.admin.cluster.repositories.delete.DeleteRepositoryRequest)3 ClusterState (org.elasticsearch.cluster.ClusterState)3 AnalyzedCreateRepository (io.crate.analyze.AnalyzedCreateRepository)2 GenericPropertiesConverter.genericPropertiesToSettings (io.crate.analyze.GenericPropertiesConverter.genericPropertiesToSettings)2 SymbolEvaluator (io.crate.analyze.SymbolEvaluator)2 RepositoryParamValidator (io.crate.analyze.repositories.RepositoryParamValidator)2 VisibleForTesting (io.crate.common.annotations.VisibleForTesting)2 Row (io.crate.data.Row)2 Row1 (io.crate.data.Row1)2 RowConsumer (io.crate.data.RowConsumer)2 OneRowActionListener (io.crate.execution.support.OneRowActionListener)2 Symbol (io.crate.expression.symbol.Symbol)2 CoordinatorTxnCtx (io.crate.metadata.CoordinatorTxnCtx)2 NodeContext (io.crate.metadata.NodeContext)2 DependencyCarrier (io.crate.planner.DependencyCarrier)2 Plan (io.crate.planner.Plan)2