Search in sources :

Example 21 with RepositoryMetadata

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

the class RepositoriesService method registerRepository.

/**
 * Creates a new repository and adds it to the list of registered repositories.
 * <p>
 * If a repository with the same name but different types or settings already exists, it will be closed and
 * replaced with the new repository. If a repository with the same name exists but it has the same type and settings
 * the new repository is ignored.
 *
 * @param repositoryMetadata new repository metadata
 * @return {@code true} if new repository was added or {@code false} if it was ignored
 */
private boolean registerRepository(RepositoryMetadata repositoryMetadata) throws IOException {
    Repository previous = repositories.get(repositoryMetadata.name());
    if (previous != null) {
        RepositoryMetadata previousMetadata = previous.getMetadata();
        if (previousMetadata.equals(repositoryMetadata)) {
            // Previous version is the same as this one - ignore it
            return false;
        }
    }
    Repository newRepo = createRepository(repositoryMetadata);
    if (previous != null) {
        closeRepository(previous);
    }
    Map<String, Repository> newRepositories = new HashMap<>(repositories);
    newRepositories.put(repositoryMetadata.name(), newRepo);
    repositories = newRepositories;
    return true;
}
Also used : HashMap(java.util.HashMap) RepositoryMetadata(org.elasticsearch.cluster.metadata.RepositoryMetadata)

Example 22 with RepositoryMetadata

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

the class RepositoriesMetadataSerializationTests method makeTestChanges.

@Override
protected Custom makeTestChanges(Custom testInstance) {
    RepositoriesMetadata repositoriesMetadata = (RepositoriesMetadata) testInstance;
    List<RepositoryMetadata> repos = new ArrayList<>(repositoriesMetadata.repositories());
    if (randomBoolean() && repos.size() > 1) {
        // remove some elements
        int leaveElements = randomIntBetween(0, repositoriesMetadata.repositories().size() - 1);
        repos = randomSubsetOf(leaveElements, repos.toArray(new RepositoryMetadata[leaveElements]));
    }
    if (randomBoolean()) {
        // add some elements
        int addElements = randomInt(10);
        for (int i = 0; i < addElements; i++) {
            repos.add(new RepositoryMetadata(randomAlphaOfLength(10), randomAlphaOfLength(10), randomSettings()));
        }
    }
    return new RepositoriesMetadata(repos);
}
Also used : RepositoriesMetadata(org.elasticsearch.cluster.metadata.RepositoriesMetadata) RepositoryMetadata(org.elasticsearch.cluster.metadata.RepositoryMetadata) ArrayList(java.util.ArrayList)

Example 23 with RepositoryMetadata

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

the class RepositoriesMetadataSerializationTests method mutateInstance.

@Override
protected Custom mutateInstance(Custom instance) {
    List<RepositoryMetadata> entries = new ArrayList<>(((RepositoriesMetadata) instance).repositories());
    boolean addEntry = entries.isEmpty() ? true : randomBoolean();
    if (addEntry) {
        entries.add(new RepositoryMetadata(randomAlphaOfLength(10), randomAlphaOfLength(10), randomSettings()));
    } else {
        entries.remove(randomIntBetween(0, entries.size() - 1));
    }
    return new RepositoriesMetadata(entries);
}
Also used : RepositoriesMetadata(org.elasticsearch.cluster.metadata.RepositoriesMetadata) RepositoryMetadata(org.elasticsearch.cluster.metadata.RepositoryMetadata) ArrayList(java.util.ArrayList)

Example 24 with RepositoryMetadata

use of org.elasticsearch.cluster.metadata.RepositoryMetadata 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(new RepositoryMetaData("repo1", "fs", Settings.EMPTY));
    ClusterState state = ClusterState.builder(new ClusterName("dummy")).metaData(MetaData.builder().putCustom(RepositoriesMetaData.TYPE, repos)).build();
    ClusterService clusterService = new NoopClusterService(state);
    final ActionFilters actionFilters = mock(ActionFilters.class, Answers.RETURNS_MOCKS.get());
    IndexNameExpressionResolver indexNameExpressionResolver = new IndexNameExpressionResolver(Settings.EMPTY);
    final AtomicBoolean deleteRepoCalled = new AtomicBoolean(false);
    TransportDeleteRepositoryAction deleteRepositoryAction = new TransportDeleteRepositoryAction(Settings.EMPTY, mock(TransportService.class, Answers.RETURNS_MOCKS.get()), clusterService, mock(RepositoriesService.class), threadPool, actionFilters, indexNameExpressionResolver) {

        @Override
        protected void doExecute(Task task, DeleteRepositoryRequest request, ActionListener<DeleteRepositoryResponse> listener) {
            deleteRepoCalled.set(true);
            listener.onResponse(mock(DeleteRepositoryResponse.class));
        }
    };
    TransportPutRepositoryAction putRepo = new TransportPutRepositoryAction(Settings.EMPTY, mock(TransportService.class, Answers.RETURNS_MOCKS.get()), clusterService, mock(RepositoriesService.class), threadPool, actionFilters, indexNameExpressionResolver) {

        @Override
        protected void doExecute(Task task, PutRepositoryRequest request, ActionListener<PutRepositoryResponse> listener) {
            listener.onFailure(new RepositoryException(request.name(), "failure"));
        }
    };
    RepositoryService repositoryService = new RepositoryService(clusterService, deleteRepositoryAction, putRepo);
    try {
        repositoryService.execute(new CreateRepositoryAnalyzedStatement("repo1", "fs", Settings.EMPTY)).get(10, TimeUnit.SECONDS);
    } catch (ExecutionException e) {
        assertThat(deleteRepoCalled.get(), is(true));
        throw e.getCause();
    }
}
Also used : RepositoriesMetaData(org.elasticsearch.cluster.metadata.RepositoriesMetaData) ClusterState(org.elasticsearch.cluster.ClusterState) Task(org.elasticsearch.tasks.Task) TransportDeleteRepositoryAction(org.elasticsearch.action.admin.cluster.repositories.delete.TransportDeleteRepositoryAction) DeleteRepositoryRequest(org.elasticsearch.action.admin.cluster.repositories.delete.DeleteRepositoryRequest) RepositoryException(org.elasticsearch.repositories.RepositoryException) ActionFilters(org.elasticsearch.action.support.ActionFilters) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CreateRepositoryAnalyzedStatement(io.crate.analyze.CreateRepositoryAnalyzedStatement) NoopClusterService(org.elasticsearch.test.cluster.NoopClusterService) ClusterService(org.elasticsearch.cluster.ClusterService) DeleteRepositoryResponse(org.elasticsearch.action.admin.cluster.repositories.delete.DeleteRepositoryResponse) ActionListener(org.elasticsearch.action.ActionListener) TransportService(org.elasticsearch.transport.TransportService) RepositoriesService(org.elasticsearch.repositories.RepositoriesService) RepositoryMetaData(org.elasticsearch.cluster.metadata.RepositoryMetaData) 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) NoopClusterService(org.elasticsearch.test.cluster.NoopClusterService) PutRepositoryRequest(org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryRequest) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 25 with RepositoryMetadata

use of org.elasticsearch.cluster.metadata.RepositoryMetadata in project elasticsearch by elastic.

the class GetRepositoriesResponse method readFrom.

@Override
public void readFrom(StreamInput in) throws IOException {
    super.readFrom(in);
    int size = in.readVInt();
    List<RepositoryMetaData> repositoryListBuilder = new ArrayList<>();
    for (int j = 0; j < size; j++) {
        repositoryListBuilder.add(new RepositoryMetaData(in.readString(), in.readString(), Settings.readSettingsFromStream(in)));
    }
    repositories = Collections.unmodifiableList(repositoryListBuilder);
}
Also used : ArrayList(java.util.ArrayList) RepositoryMetaData(org.elasticsearch.cluster.metadata.RepositoryMetaData)

Aggregations

RepositoryMetadata (org.elasticsearch.cluster.metadata.RepositoryMetadata)29 RepositoryMetaData (org.elasticsearch.cluster.metadata.RepositoryMetaData)24 ClusterState (org.elasticsearch.cluster.ClusterState)13 RepositoriesMetadata (org.elasticsearch.cluster.metadata.RepositoriesMetadata)13 ArrayList (java.util.ArrayList)11 Settings (org.elasticsearch.common.settings.Settings)11 RepositoriesMetaData (org.elasticsearch.cluster.metadata.RepositoriesMetaData)10 IOException (java.io.IOException)8 ClusterName (org.elasticsearch.cluster.ClusterName)8 Before (org.junit.Before)7 HashMap (java.util.HashMap)6 BlobStoreRepository (org.elasticsearch.repositories.blobstore.BlobStoreRepository)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 ParameterizedMessage (org.apache.logging.log4j.message.ParameterizedMessage)5 ActionListener (org.elasticsearch.action.ActionListener)5 BlobContainer (org.elasticsearch.common.blobstore.BlobContainer)5 RepositoryException (org.elasticsearch.repositories.RepositoryException)5 Test (org.junit.Test)5 List (java.util.List)4 Map (java.util.Map)4