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