Search in sources :

Example 6 with UploaderException

use of org.apache.heron.spi.uploader.UploaderException in project heron by twitter.

the class SubmitterMainTest method testSubmitTopologyUploaderException.

@Test(expected = UploaderException.class)
public void testSubmitTopologyUploaderException() throws Exception {
    SubmitterMain submitterMain = spy(new SubmitterMain(config, topology));
    doNothing().when(submitterMain).validateSubmit(any(SchedulerStateManagerAdaptor.class), anyString());
    doThrow(new UploaderException("")).when(submitterMain).uploadPackage(eq(uploader));
    try {
        submitterMain.submitTopology();
    } finally {
        verify(uploader, never()).undo();
        verify(uploader).close();
        verify(launcher).close();
        verify(statemgr).close();
    }
}
Also used : UploaderException(org.apache.heron.spi.uploader.UploaderException) SchedulerStateManagerAdaptor(org.apache.heron.spi.statemgr.SchedulerStateManagerAdaptor) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 7 with UploaderException

use of org.apache.heron.spi.uploader.UploaderException in project heron by twitter.

the class S3Uploader method uploadPackage.

@Override
public URI uploadPackage() throws UploaderException {
    // Backup any existing files incase we need to undo this action
    if (s3Client.doesObjectExist(bucket, remoteFilePath)) {
        s3Client.copyObject(bucket, remoteFilePath, bucket, previousVersionFilePath);
    }
    // Attempt to write the topology package to s3
    try {
        s3Client.putObject(bucket, remoteFilePath, packageFileHandler);
    } catch (SdkClientException e) {
        throw new UploaderException(String.format("Error writing topology package to %s %s", bucket, remoteFilePath), e);
    }
    // Ask s3 for the url to the topology package we just uploaded
    final URL resourceUrl = s3Client.getUrl(bucket, remoteFilePath);
    LOG.log(Level.INFO, "Package URL: {0}", resourceUrl);
    // This will happen if the package does not actually exist in the place where we uploaded it to.
    if (resourceUrl == null) {
        throw new UploaderException(String.format("Resource not found for bucket %s and path %s", bucket, remoteFilePath));
    }
    try {
        return resourceUrl.toURI();
    } catch (URISyntaxException e) {
        throw new UploaderException(String.format("Could not convert URL %s to URI", resourceUrl), e);
    }
}
Also used : SdkClientException(com.amazonaws.SdkClientException) URISyntaxException(java.net.URISyntaxException) UploaderException(org.apache.heron.spi.uploader.UploaderException) URL(java.net.URL)

Aggregations

UploaderException (org.apache.heron.spi.uploader.UploaderException)7 IOException (java.io.IOException)2 URI (java.net.URI)2 URISyntaxException (java.net.URISyntaxException)2 SchedulerStateManagerAdaptor (org.apache.heron.spi.statemgr.SchedulerStateManagerAdaptor)2 Test (org.junit.Test)2 SdkClientException (com.amazonaws.SdkClientException)1 StorageObject (com.google.api.services.storage.model.StorageObject)1 File (java.io.File)1 OutputStream (java.io.OutputStream)1 URL (java.net.URL)1 CopyOption (java.nio.file.CopyOption)1 Path (java.nio.file.Path)1 StandardCopyOption (java.nio.file.StandardCopyOption)1 Namespace (org.apache.distributedlog.api.namespace.Namespace)1 DLOutputStream (org.apache.heron.dlog.DLOutputStream)1 Config (org.apache.heron.spi.common.Config)1 PackingException (org.apache.heron.spi.packing.PackingException)1 PackingPlan (org.apache.heron.spi.packing.PackingPlan)1 ILauncher (org.apache.heron.spi.scheduler.ILauncher)1