use of org.elasticsearch.common.blobstore.BlobContainer in project elasticsearch by elastic.
the class URLBlobStoreTests method testURLBlobStoreCanReadBlob.
public void testURLBlobStoreCanReadBlob() throws IOException {
BlobContainer container = urlBlobStore.blobContainer(BlobPath.cleanPath().add("indices"));
try (InputStream stream = container.readBlob(blobName)) {
byte[] bytes = new byte[message.length];
int read = stream.read(bytes);
assertEquals(message.length, read);
assertArrayEquals(message, bytes);
}
}
use of org.elasticsearch.common.blobstore.BlobContainer in project elasticsearch by elastic.
the class URLBlobStoreTests method testNoBlobFound.
public void testNoBlobFound() throws IOException {
BlobContainer container = urlBlobStore.blobContainer(BlobPath.cleanPath().add("indices"));
String incorrectBlobName = "incorrect_" + blobName;
try (InputStream ignored = container.readBlob(incorrectBlobName)) {
fail("Should have thrown NoSuchFileException exception");
ignored.read();
} catch (NoSuchFileException e) {
assertEquals(String.format("[%s] blob not found", incorrectBlobName), e.getMessage());
}
}
use of org.elasticsearch.common.blobstore.BlobContainer in project elasticsearch by elastic.
the class ESBlobStoreContainerTestCase method testDeleteBlob.
public void testDeleteBlob() throws IOException {
try (BlobStore store = newBlobStore()) {
final String blobName = "foobar";
final BlobContainer container = store.blobContainer(new BlobPath());
expectThrows(IOException.class, () -> container.deleteBlob(blobName));
byte[] data = randomBytes(randomIntBetween(10, scaledRandomIntBetween(1024, 1 << 16)));
final BytesArray bytesArray = new BytesArray(data);
writeBlob(container, blobName, bytesArray);
// should not raise
container.deleteBlob(blobName);
// blob deleted, so should raise again
expectThrows(IOException.class, () -> container.deleteBlob(blobName));
}
}
use of org.elasticsearch.common.blobstore.BlobContainer in project elasticsearch by elastic.
the class ESBlobStoreContainerTestCase method testVerifyOverwriteFails.
public void testVerifyOverwriteFails() throws IOException {
try (BlobStore store = newBlobStore()) {
final String blobName = "foobar";
final BlobContainer container = store.blobContainer(new BlobPath());
byte[] data = randomBytes(randomIntBetween(10, scaledRandomIntBetween(1024, 1 << 16)));
final BytesArray bytesArray = new BytesArray(data);
writeBlob(container, blobName, bytesArray);
// should not be able to overwrite existing blob
expectThrows(IOException.class, () -> writeBlob(container, blobName, bytesArray));
container.deleteBlob(blobName);
// after deleting the previous blob, we should be able to write to it again
writeBlob(container, blobName, bytesArray);
}
}
use of org.elasticsearch.common.blobstore.BlobContainer in project elasticsearch by elastic.
the class BlobStoreRepository method initializeSnapshot.
@Override
public void initializeSnapshot(SnapshotId snapshotId, List<IndexId> indices, MetaData clusterMetaData) {
if (isReadOnly()) {
throw new RepositoryException(metadata.name(), "cannot create snapshot in a readonly repository");
}
try {
final String snapshotName = snapshotId.getName();
// check if the snapshot name already exists in the repository
final RepositoryData repositoryData = getRepositoryData();
if (repositoryData.getAllSnapshotIds().stream().anyMatch(s -> s.getName().equals(snapshotName))) {
throw new InvalidSnapshotNameException(metadata.name(), snapshotId.getName(), "snapshot with the same name already exists");
}
if (snapshotFormat.exists(snapshotsBlobContainer, snapshotId.getUUID())) {
throw new InvalidSnapshotNameException(metadata.name(), snapshotId.getName(), "snapshot with the same name already exists");
}
// Write Global MetaData
globalMetaDataFormat.write(clusterMetaData, snapshotsBlobContainer, snapshotId.getUUID());
// write the index metadata for each index in the snapshot
for (IndexId index : indices) {
final IndexMetaData indexMetaData = clusterMetaData.index(index.getName());
final BlobPath indexPath = basePath().add("indices").add(index.getId());
final BlobContainer indexMetaDataBlobContainer = blobStore().blobContainer(indexPath);
indexMetaDataFormat.write(indexMetaData, indexMetaDataBlobContainer, snapshotId.getUUID());
}
} catch (IOException ex) {
throw new SnapshotCreationException(metadata.name(), snapshotId, ex);
}
}
Aggregations