use of com.microsoft.azure.storage.StorageException in project druid by druid-io.
the class AzureDataSegmentPullerTest method testDeleteOutputDirectoryWhenErrorIsRaisedPullingSegmentFiles.
@Test(expected = RuntimeException.class)
public void testDeleteOutputDirectoryWhenErrorIsRaisedPullingSegmentFiles() throws IOException, URISyntaxException, StorageException, SegmentLoadingException {
final File outDir = Files.createTempDirectory("druid").toFile();
try {
expect(azureStorage.getBlobInputStream(containerName, blobPath)).andThrow(new StorageException("error", "error", 404, null, null));
replayAll();
AzureDataSegmentPuller puller = new AzureDataSegmentPuller(azureStorage);
puller.getSegmentFiles(containerName, blobPath, outDir);
assertFalse(outDir.exists());
verifyAll();
} finally {
org.apache.commons.io.FileUtils.deleteDirectory(outDir);
}
}
use of com.microsoft.azure.storage.StorageException in project elasticsearch by elastic.
the class AzureBlobContainer method move.
@Override
public void move(String sourceBlobName, String targetBlobName) throws IOException {
logger.trace("move({}, {})", sourceBlobName, targetBlobName);
try {
String source = keyPath + sourceBlobName;
String target = keyPath + targetBlobName;
logger.debug("moving blob [{}] to [{}] in container {{}}", source, target, blobStore.container());
blobStore.moveBlob(blobStore.container(), source, target);
} catch (URISyntaxException | StorageException e) {
logger.warn("can not move blob [{}] to [{}] in container {{}}: {}", sourceBlobName, targetBlobName, blobStore.container(), e.getMessage());
throw new IOException(e);
}
}
use of com.microsoft.azure.storage.StorageException in project elasticsearch by elastic.
the class AzureSnapshotRestoreTests method testRemoveAndCreateContainer.
/**
* When a user remove a container you can not immediately create it again.
*/
public void testRemoveAndCreateContainer() throws Exception {
final String container = getContainerName().concat("-testremove");
final AzureStorageService storageService = new AzureStorageServiceImpl(internalCluster().getDefaultSettings());
// It could happen that we run this test really close to a previous one
// so we might need some time to be able to create the container
assertBusy(() -> {
try {
storageService.createContainer(null, LocationMode.PRIMARY_ONLY, container);
logger.debug(" -> container created...");
} catch (URISyntaxException e) {
// Incorrect URL. This should never happen.
fail();
} catch (StorageException e) {
// It could happen. Let's wait for a while.
logger.debug(" -> container is being removed. Let's wait a bit...");
fail();
}
}, 30, TimeUnit.SECONDS);
storageService.removeContainer(null, LocationMode.PRIMARY_ONLY, container);
ClusterAdminClient client = client().admin().cluster();
logger.info("--> creating azure repository while container is being removed");
try {
client.preparePutRepository("test-repo").setType("azure").setSettings(Settings.builder().put(Repository.CONTAINER_SETTING.getKey(), container)).get();
fail("we should get a RepositoryVerificationException");
} catch (RepositoryVerificationException e) {
// Fine we expect that
}
}
use of com.microsoft.azure.storage.StorageException in project elasticsearch by elastic.
the class AzureSnapshotRestoreTests method checkContainerName.
/**
* Create repository with wrong or correct container name
* @param container Container name we want to create
* @param correct Is this container name correct
*/
private void checkContainerName(final String container, final boolean correct) throws Exception {
logger.info("--> creating azure repository with container name [{}]", container);
// It could happen that we just removed from a previous test the same container so
// we can not create it yet.
assertBusy(() -> {
try {
PutRepositoryResponse putRepositoryResponse = client().admin().cluster().preparePutRepository("test-repo").setType("azure").setSettings(Settings.builder().put(Repository.CONTAINER_SETTING.getKey(), container).put(Repository.BASE_PATH_SETTING.getKey(), getRepositoryPath()).put(Repository.CHUNK_SIZE_SETTING.getKey(), randomIntBetween(1000, 10000), ByteSizeUnit.BYTES)).get();
client().admin().cluster().prepareDeleteRepository("test-repo").get();
try {
logger.info("--> remove container [{}]", container);
cleanRepositoryFiles(container);
} catch (StorageException | URISyntaxException e) {
// We can ignore that as we just try to clean after the test
}
assertTrue(putRepositoryResponse.isAcknowledged() == correct);
} catch (RepositoryVerificationException e) {
if (correct) {
logger.debug(" -> container is being removed. Let's wait a bit...");
fail();
}
}
}, 5, TimeUnit.MINUTES);
}
use of com.microsoft.azure.storage.StorageException in project tdi-studio-se by Talend.
the class Job method execute.
public Integer execute() throws IOException, InterruptedException, InvalidKeyException, URISyntaxException, StorageException {
String status = this.statusFolder;
String exitCode = status + "/exit";
final String stderr = status + "/stderr";
final FileSystem fs = this.fileSystem;
class StreamStrErr implements Runnable {
public void run() {
InputStream is = null;
BufferedReader d = null;
try {
while (!fs.exists(stderr)) {
Thread.sleep(2000);
}
is = fs.open(stderr);
d = new BufferedReader(new InputStreamReader(is));
String s;
while ((s = d.readLine()) == null) {
if (is != null) {
is.close();
}
if (d != null) {
d.close();
}
is = fs.open(stderr);
d = new BufferedReader(new InputStreamReader(is));
}
do {
System.err.println(s);
} while ((s = d.readLine()) != null);
} catch (Exception e) {
e.printStackTrace();
} finally {
if (is != null) {
try {
is.close();
} catch (IOException e) {
}
}
if (d != null) {
try {
d.close();
} catch (IOException e) {
}
}
}
}
}
StreamStrErr stream = new StreamStrErr();
stream.run();
while (!fs.exists(exitCode)) {
Thread.sleep(2000);
}
InputStream is = fs.open(exitCode);
BufferedReader br = new BufferedReader(new InputStreamReader(is));
String r = br.readLine();
try {
return Integer.parseInt(r);
} catch (Exception e) {
return 1;
}
}
Aggregations