Search in sources :

Example 21 with StorageException

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);
    }
}
Also used : File(java.io.File) StorageException(com.microsoft.azure.storage.StorageException) Test(org.junit.Test)

Example 22 with StorageException

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);
    }
}
Also used : URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) StorageException(com.microsoft.azure.storage.StorageException)

Example 23 with StorageException

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
    }
}
Also used : AzureStorageServiceImpl(org.elasticsearch.cloud.azure.storage.AzureStorageServiceImpl) ClusterAdminClient(org.elasticsearch.client.ClusterAdminClient) RepositoryVerificationException(org.elasticsearch.repositories.RepositoryVerificationException) URISyntaxException(java.net.URISyntaxException) AzureStorageService(org.elasticsearch.cloud.azure.storage.AzureStorageService) StorageException(com.microsoft.azure.storage.StorageException)

Example 24 with StorageException

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);
}
Also used : RepositoryVerificationException(org.elasticsearch.repositories.RepositoryVerificationException) PutRepositoryResponse(org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryResponse) URISyntaxException(java.net.URISyntaxException) StorageException(com.microsoft.azure.storage.StorageException)

Example 25 with StorageException

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;
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) FileSystem(org.talend.webhcat.launcher.fs.FileSystem) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) StorageException(com.microsoft.azure.storage.StorageException) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) InvalidKeyException(java.security.InvalidKeyException)

Aggregations

StorageException (com.microsoft.azure.storage.StorageException)55 URISyntaxException (java.net.URISyntaxException)34 IOException (java.io.IOException)31 Path (org.apache.hadoop.fs.Path)13 FileNotFoundException (java.io.FileNotFoundException)10 DataStoreException (org.apache.jackrabbit.core.data.DataStoreException)10 CloudBlockBlob (com.microsoft.azure.storage.blob.CloudBlockBlob)8 InputStream (java.io.InputStream)7 JsonParseException (com.fasterxml.jackson.core.JsonParseException)5 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)5 CloudStorageAccount (com.microsoft.azure.storage.CloudStorageAccount)5 CloudBlob (com.microsoft.azure.storage.blob.CloudBlob)5 EOFException (java.io.EOFException)5 InvalidKeyException (java.security.InvalidKeyException)5 FileAlreadyExistsException (org.apache.hadoop.fs.FileAlreadyExistsException)5 AccessCondition (com.microsoft.azure.storage.AccessCondition)4 BlobRequestOptions (com.microsoft.azure.storage.blob.BlobRequestOptions)4 CloudBlobClient (com.microsoft.azure.storage.blob.CloudBlobClient)4 CloudBlobContainer (com.microsoft.azure.storage.blob.CloudBlobContainer)4 CloudBlobDirectory (com.microsoft.azure.storage.blob.CloudBlobDirectory)4