Search in sources :

Example 26 with RepositoriesMetaData

use of org.elasticsearch.cluster.metadata.RepositoriesMetaData 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)

Example 27 with RepositoriesMetaData

use of org.elasticsearch.cluster.metadata.RepositoriesMetaData in project crate by crate.

the class AccessControlMayExecuteTest method setUpSQLExecutor.

@Before
public void setUpSQLExecutor() throws Exception {
    validationCallArguments = new ArrayList<>();
    RepositoriesMetadata repositoriesMetadata = new RepositoriesMetadata(singletonList(new RepositoryMetadata("my_repo", "fs", Settings.builder().put("location", "/tmp/my_repo").build())));
    ClusterState clusterState = ClusterState.builder(clusterService.state()).metadata(Metadata.builder(clusterService.state().metadata()).putCustom(RepositoriesMetadata.TYPE, repositoriesMetadata)).build();
    ClusterServiceUtils.setState(clusterService, clusterState);
    user = new User("normal", Set.of(), Set.of(), null) {

        @Override
        public boolean hasPrivilege(Privilege.Type type, Privilege.Clazz clazz, String ident, String defaultSchema) {
            validationCallArguments.add(CollectionUtils.arrayAsArrayList(type, clazz, ident, user.name()));
            return true;
        }
    };
    superUser = new User("crate", EnumSet.of(User.Role.SUPERUSER), Set.of(), null) {

        @Override
        public boolean hasPrivilege(Privilege.Type type, Privilege.Clazz clazz, @Nullable String ident, String defaultSchema) {
            validationCallArguments.add(CollectionUtils.arrayAsArrayList(type, clazz, ident, superUser.name()));
            return true;
        }
    };
    UserLookupService userLookupService = new UserLookupService(clusterService) {

        @Nullable
        @Override
        public User findUser(String userName) {
            if ("crate".equals(userName)) {
                return superUser;
            }
            return super.findUser(userName);
        }
    };
    userManager = new UserManagerService(null, null, null, null, mock(SysTableRegistry.class), clusterService, userLookupService, new DDLClusterStateService());
    e = SQLExecutor.builder(clusterService).addBlobTable("create blob table blobs").enableDefaultTables().setUser(superUser).addView(new RelationName("doc", "v1"), "select * from users").setUserManager(userManager).build();
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) UserLookupService(io.crate.user.UserLookupService) User(io.crate.user.User) RepositoriesMetadata(org.elasticsearch.cluster.metadata.RepositoriesMetadata) UserManagerService(io.crate.user.UserManagerService) DDLClusterStateService(io.crate.metadata.cluster.DDLClusterStateService) RepositoryMetadata(org.elasticsearch.cluster.metadata.RepositoryMetadata) RelationName(io.crate.metadata.RelationName) Privilege(io.crate.user.Privilege) Before(org.junit.Before)

Example 28 with RepositoriesMetaData

use of org.elasticsearch.cluster.metadata.RepositoriesMetaData in project crate by crate.

the class RepositoriesMetadataSerializationTests method createTestInstance.

@Override
protected Custom createTestInstance() {
    int numberOfRepositories = randomInt(10);
    List<RepositoryMetadata> entries = new ArrayList<>();
    for (int i = 0; i < numberOfRepositories; i++) {
        // divide by 2 to not overflow when adding to this number for the pending generation below
        final long generation = randomNonNegativeLong() / 2L;
        entries.add(new RepositoryMetadata(randomAlphaOfLength(10), randomAlphaOfLength(10), randomSettings(), generation, generation + randomLongBetween(0, generation)));
    }
    entries.sort(Comparator.comparing(RepositoryMetadata::name));
    return new RepositoriesMetadata(entries);
}
Also used : RepositoriesMetadata(org.elasticsearch.cluster.metadata.RepositoriesMetadata) RepositoryMetadata(org.elasticsearch.cluster.metadata.RepositoryMetadata) ArrayList(java.util.ArrayList)

Example 29 with RepositoriesMetaData

use of org.elasticsearch.cluster.metadata.RepositoriesMetaData in project crate by crate.

the class RepositoriesMetadataSerializationTests method doParseInstance.

@Override
protected Custom doParseInstance(XContentParser parser) throws IOException {
    assertEquals(XContentParser.Token.START_OBJECT, parser.nextToken());
    RepositoriesMetadata repositoriesMetadata = RepositoriesMetadata.fromXContent(parser);
    assertEquals(XContentParser.Token.END_OBJECT, parser.currentToken());
    List<RepositoryMetadata> repos = new ArrayList<>(repositoriesMetadata.repositories());
    repos.sort(Comparator.comparing(RepositoryMetadata::name));
    return new RepositoriesMetadata(repos);
}
Also used : RepositoriesMetadata(org.elasticsearch.cluster.metadata.RepositoriesMetadata) RepositoryMetadata(org.elasticsearch.cluster.metadata.RepositoryMetadata) ArrayList(java.util.ArrayList)

Aggregations

RepositoriesMetadata (org.elasticsearch.cluster.metadata.RepositoriesMetadata)15 ClusterState (org.elasticsearch.cluster.ClusterState)14 RepositoriesMetaData (org.elasticsearch.cluster.metadata.RepositoriesMetaData)14 RepositoryMetadata (org.elasticsearch.cluster.metadata.RepositoryMetadata)13 ArrayList (java.util.ArrayList)10 RepositoryMetaData (org.elasticsearch.cluster.metadata.RepositoryMetaData)10 ClusterName (org.elasticsearch.cluster.ClusterName)8 Before (org.junit.Before)7 IOException (java.io.IOException)5 ParameterizedMessage (org.apache.logging.log4j.message.ParameterizedMessage)5 Map (java.util.Map)4 ActionListener (org.elasticsearch.action.ActionListener)4 RepositoryParamValidator (io.crate.analyze.repositories.RepositoryParamValidator)3 TypeSettings (io.crate.analyze.repositories.TypeSettings)3 HashMap (java.util.HashMap)3 DeleteRepositoryRequest (org.elasticsearch.action.admin.cluster.repositories.delete.DeleteRepositoryRequest)3 PutRepositoryRequest (org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryRequest)3 RepositoryException (org.elasticsearch.repositories.RepositoryException)3 Path (java.nio.file.Path)2 List (java.util.List)2