Search in sources :

Example 11 with ChunkStorageException

use of io.pravega.segmentstore.storage.chunklayer.ChunkStorageException in project pravega by pravega.

the class HDFSChunkStorageMockTest method testGetUsedException.

@Test
public void testGetUsedException() throws Exception {
    val mockFs = spy(FileSystem.get(new Configuration()));
    HDFSChunkStorage storage = new MockHDFSChunkStorage(storageConfig, executorService(), mockFs);
    storage.initialize();
    doThrow(new IOException("Intentional")).when(mockFs).getUsed();
    AssertExtensions.assertFutureThrows("should throw ChunkStorageFull exception", storage.getUsedSpace(), ex -> ex instanceof ChunkStorageException);
}
Also used : lombok.val(lombok.val) Configuration(org.apache.hadoop.conf.Configuration) IOException(java.io.IOException) ChunkStorageException(io.pravega.segmentstore.storage.chunklayer.ChunkStorageException) Test(org.junit.Test)

Example 12 with ChunkStorageException

use of io.pravega.segmentstore.storage.chunklayer.ChunkStorageException in project pravega by pravega.

the class S3ChunkStorage method convertException.

private ChunkStorageException convertException(String chunkName, String message, Exception e) {
    ChunkStorageException retValue = null;
    if (e instanceof ChunkStorageException) {
        return (ChunkStorageException) e;
    }
    if (e instanceof S3Exception) {
        S3Exception s3Exception = (S3Exception) e;
        String errorCode = Strings.nullToEmpty(s3Exception.awsErrorDetails().errorCode());
        if (errorCode.equals(NO_SUCH_KEY)) {
            retValue = new ChunkNotFoundException(chunkName, message, e);
        }
        if (errorCode.equals(PRECONDITION_FAILED)) {
            retValue = new ChunkAlreadyExistsException(chunkName, message, e);
        }
        if (errorCode.equals(INVALID_RANGE) || errorCode.equals(INVALID_ARGUMENT) || errorCode.equals(METHOD_NOT_ALLOWED) || s3Exception.awsErrorDetails().sdkHttpResponse().statusCode() == HttpStatus.SC_REQUESTED_RANGE_NOT_SATISFIABLE) {
            throw new IllegalArgumentException(chunkName, e);
        }
        if (errorCode.equals(ACCESS_DENIED)) {
            retValue = new ChunkStorageException(chunkName, String.format("Access denied for chunk %s - %s.", chunkName, message), e);
        }
    }
    if (retValue == null) {
        retValue = new ChunkStorageException(chunkName, message, e);
    }
    return retValue;
}
Also used : ChunkNotFoundException(io.pravega.segmentstore.storage.chunklayer.ChunkNotFoundException) ChunkAlreadyExistsException(io.pravega.segmentstore.storage.chunklayer.ChunkAlreadyExistsException) S3Exception(software.amazon.awssdk.services.s3.model.S3Exception) ChunkStorageException(io.pravega.segmentstore.storage.chunklayer.ChunkStorageException)

Example 13 with ChunkStorageException

use of io.pravega.segmentstore.storage.chunklayer.ChunkStorageException in project pravega by pravega.

the class S3ChunkStorage method doCreateWithContent.

@Override
protected ChunkHandle doCreateWithContent(String chunkName, int length, InputStream data) throws ChunkStorageException {
    try {
        val objectPath = getObjectPath(chunkName);
        Map<String, String> metadata = new HashMap<>();
        metadata.put("Content-Type", "application/octet-stream");
        metadata.put("Content-Length", Integer.toString(length));
        val request = PutObjectRequest.builder().bucket(this.config.getBucket()).key(objectPath).metadata(metadata).build();
        client.putObject(request, RequestBody.fromInputStream(data, length));
        return ChunkHandle.writeHandle(chunkName);
    } catch (Exception e) {
        throw convertException(chunkName, "doCreateWithContent", e);
    }
}
Also used : lombok.val(lombok.val) HashMap(java.util.HashMap) S3Exception(software.amazon.awssdk.services.s3.model.S3Exception) ChunkStorageException(io.pravega.segmentstore.storage.chunklayer.ChunkStorageException) ChunkNotFoundException(io.pravega.segmentstore.storage.chunklayer.ChunkNotFoundException) ChunkAlreadyExistsException(io.pravega.segmentstore.storage.chunklayer.ChunkAlreadyExistsException)

Example 14 with ChunkStorageException

use of io.pravega.segmentstore.storage.chunklayer.ChunkStorageException in project pravega by pravega.

the class FileSystemChunkStorageMockTest method testWithNonRegularFile.

@Test
public void testWithNonRegularFile() throws Exception {
    String chunkName = "test";
    FileChannel channel = mock(FileChannel.class);
    fixChannelMock(channel);
    FileSystemWrapper fileSystemWrapper = mock(FileSystemWrapper.class);
    when(fileSystemWrapper.exists(any())).thenReturn(true);
    when(fileSystemWrapper.isRegularFile(any())).thenReturn(false);
    @Cleanup FileSystemChunkStorage testStorage = new FileSystemChunkStorage(storageConfig, fileSystemWrapper, executorService());
    AssertExtensions.assertFutureThrows(" openRead should throw ChunkStorageException.", testStorage.openRead(chunkName), ex -> ex instanceof ChunkStorageException && ex.getMessage().contains("chunk is not a regular file"));
    AssertExtensions.assertFutureThrows(" openRead should throw ChunkStorageException.", testStorage.openWrite(chunkName), ex -> ex instanceof ChunkStorageException && ex.getMessage().contains("chunk is not a regular file"));
}
Also used : FileChannel(java.nio.channels.FileChannel) Cleanup(lombok.Cleanup) ChunkStorageException(io.pravega.segmentstore.storage.chunklayer.ChunkStorageException) Test(org.junit.Test)

Example 15 with ChunkStorageException

use of io.pravega.segmentstore.storage.chunklayer.ChunkStorageException in project pravega by pravega.

the class FileSystemChunkStorageMockTest method testGetUsageException.

@Test
public void testGetUsageException() {
    val fs = spy(new FileSystemWrapper(CACHE_SIZE, CACHE_SIZE, CACHE_EXP, CACHE_EXP));
    doThrow(new RuntimeException("Intentional")).when(fs).getUsedSpace(any());
    FileSystemChunkStorage storage = new FileSystemChunkStorage(storageConfig, fs, executorService());
    AssertExtensions.assertFutureThrows("should throw ChunkStorageException exception", storage.getUsedSpace(), ex -> ex instanceof ChunkStorageException);
}
Also used : lombok.val(lombok.val) ChunkStorageException(io.pravega.segmentstore.storage.chunklayer.ChunkStorageException) Test(org.junit.Test)

Aggregations

ChunkStorageException (io.pravega.segmentstore.storage.chunklayer.ChunkStorageException)18 ChunkAlreadyExistsException (io.pravega.segmentstore.storage.chunklayer.ChunkAlreadyExistsException)13 ChunkNotFoundException (io.pravega.segmentstore.storage.chunklayer.ChunkNotFoundException)12 lombok.val (lombok.val)9 S3Exception (com.emc.object.s3.S3Exception)6 InvalidOffsetException (io.pravega.segmentstore.storage.chunklayer.InvalidOffsetException)6 S3Exception (software.amazon.awssdk.services.s3.model.S3Exception)6 S3ObjectMetadata (com.emc.object.s3.S3ObjectMetadata)4 Test (org.junit.Test)4 IOException (java.io.IOException)3 PutObjectRequest (com.emc.object.s3.request.PutObjectRequest)2 Cleanup (lombok.Cleanup)2 CopyPartResult (com.emc.object.s3.bean.CopyPartResult)1 MultipartPartETag (com.emc.object.s3.bean.MultipartPartETag)1 AbortMultipartUploadRequest (com.emc.object.s3.request.AbortMultipartUploadRequest)1 CompleteMultipartUploadRequest (com.emc.object.s3.request.CompleteMultipartUploadRequest)1 CopyPartRequest (com.emc.object.s3.request.CopyPartRequest)1 ChunkHandle (io.pravega.segmentstore.storage.chunklayer.ChunkHandle)1 ChunkInfo (io.pravega.segmentstore.storage.chunklayer.ChunkInfo)1 ConcatArgument (io.pravega.segmentstore.storage.chunklayer.ConcatArgument)1