Search in sources :

Example 1 with PutBlobOptionsBuilder

use of com.github.ambry.router.PutBlobOptionsBuilder in project ambry by linkedin.

the class UndeleteHandlerTest method setupBlob.

/**
 * Setup a blob and delete it so later we can undelete it.
 * @throws Exception
 */
public void setupBlob() throws Exception {
    ReadableStreamChannel channel = new ByteBufferReadableStreamChannel(ByteBuffer.wrap(BLOB_DATA));
    blobId = router.putBlob(BLOB_PROPERTIES, new byte[0], channel, new PutBlobOptionsBuilder().build()).get(1, TimeUnit.SECONDS);
    idConverterFactory.translation = blobId;
    router.deleteBlob(blobId, SERVICE_ID).get(1, TimeUnit.SECONDS);
}
Also used : ByteBufferReadableStreamChannel(com.github.ambry.commons.ByteBufferReadableStreamChannel) ByteBufferReadableStreamChannel(com.github.ambry.commons.ByteBufferReadableStreamChannel) ReadableStreamChannel(com.github.ambry.router.ReadableStreamChannel) PutBlobOptionsBuilder(com.github.ambry.router.PutBlobOptionsBuilder)

Example 2 with PutBlobOptionsBuilder

use of com.github.ambry.router.PutBlobOptionsBuilder in project ambry by linkedin.

the class MockHeadCallback method handlePost.

@Override
public void handlePost(RestRequest restRequest, RestResponseChannel restResponseChannel) {
    if (shouldProceed(restRequest, restResponseChannel)) {
        try {
            restRequest.setArg(RestUtils.InternalKeys.TARGET_ACCOUNT_KEY, InMemAccountService.UNKNOWN_ACCOUNT);
            restRequest.setArg(RestUtils.InternalKeys.TARGET_CONTAINER_KEY, Container.UNKNOWN_CONTAINER);
            BlobProperties blobProperties = RestUtils.buildBlobProperties(restRequest.getArgs());
            byte[] usermetadata = RestUtils.buildUserMetadata(restRequest.getArgs());
            router.putBlob(blobProperties, usermetadata, restRequest, new PutBlobOptionsBuilder().build(), new MockPostCallback(this, restRequest, restResponseChannel, blobProperties), null);
        } catch (RestServiceException e) {
            handleResponse(restRequest, restResponseChannel, null, e);
        }
    }
}
Also used : PutBlobOptionsBuilder(com.github.ambry.router.PutBlobOptionsBuilder) BlobProperties(com.github.ambry.messageformat.BlobProperties)

Example 3 with PutBlobOptionsBuilder

use of com.github.ambry.router.PutBlobOptionsBuilder in project ambry by linkedin.

the class FrontendTestUrlSigningServiceFactory method oldStyleUserMetadataTest.

/**
 * Tests how metadata that has not been POSTed in the form of headers is returned.
 * @throws Exception
 */
@Test
public void oldStyleUserMetadataTest() throws Exception {
    ByteBuffer content = ByteBuffer.allocate(0);
    BlobProperties blobProperties = new BlobProperties(0, "userMetadataTestOldStyleServiceID", Account.UNKNOWN_ACCOUNT_ID, Container.UNKNOWN_CONTAINER_ID, false);
    byte[] usermetadata = TestUtils.getRandomBytes(25);
    String blobId = router.putBlob(blobProperties, usermetadata, new ByteBufferReadableStreamChannel(content), new PutBlobOptionsBuilder().build()).get();
    RestUtils.SubResource[] subResources = { RestUtils.SubResource.UserMetadata, RestUtils.SubResource.BlobInfo };
    for (RestUtils.SubResource subResource : subResources) {
        RestRequest restRequest = createRestRequest(RestMethod.GET, blobId + "/" + subResource, null, null);
        MockRestResponseChannel restResponseChannel = new MockRestResponseChannel();
        doOperation(restRequest, restResponseChannel);
        assertEquals("Unexpected response status for " + subResource, ResponseStatus.Ok, restResponseChannel.getStatus());
        assertEquals("Unexpected Content-Type for " + subResource, "application/octet-stream", restResponseChannel.getHeader(RestUtils.Headers.CONTENT_TYPE));
        assertEquals("Unexpected Content-Length for " + subResource, usermetadata.length, Integer.parseInt(restResponseChannel.getHeader(RestUtils.Headers.CONTENT_LENGTH)));
        assertArrayEquals("Unexpected user metadata for " + subResource, usermetadata, restResponseChannel.getResponseBody());
    }
}
Also used : ByteBufferReadableStreamChannel(com.github.ambry.commons.ByteBufferReadableStreamChannel) MockRestRequest(com.github.ambry.rest.MockRestRequest) RestRequest(com.github.ambry.rest.RestRequest) PutBlobOptionsBuilder(com.github.ambry.router.PutBlobOptionsBuilder) BlobProperties(com.github.ambry.messageformat.BlobProperties) RestUtils(com.github.ambry.rest.RestUtils) MockRestResponseChannel(com.github.ambry.rest.MockRestResponseChannel) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test) RestUtilsTest(com.github.ambry.rest.RestUtilsTest) StorageStatsUtilTest(com.github.ambry.server.StorageStatsUtilTest)

Example 4 with PutBlobOptionsBuilder

use of com.github.ambry.router.PutBlobOptionsBuilder in project ambry by linkedin.

the class PostBlobHandlerTest method uploadChunksViaRouter.

// stitchedUploadTest() helpers
/**
 * Upload chunks using the router directly.
 * @param creationTimeMs the creation time to set for the chunks.
 * @param container the {@link Container} to create the chunks in.
 * @param chunkSizes the sizes for each chunk to upload.
 * @return a list of {@link ChunkInfo} objects that contains metadata about each chunk uploaded.
 */
private List<ChunkInfo> uploadChunksViaRouter(long creationTimeMs, Container container, int... chunkSizes) throws Exception {
    long blobTtlSecs = TimeUnit.DAYS.toSeconds(1);
    List<ChunkInfo> chunks = new ArrayList<>();
    for (int chunkSize : chunkSizes) {
        byte[] content = TestUtils.getRandomBytes(chunkSize);
        BlobProperties blobProperties = new BlobProperties(-1, SERVICE_ID, OWNER_ID, CONTENT_TYPE, !container.isCacheable(), blobTtlSecs, creationTimeMs, container.getParentAccountId(), container.getId(), container.isEncrypted(), null, null, null);
        String blobId = router.putBlob(blobProperties, null, new ByteBufferReadableStreamChannel(ByteBuffer.wrap(content)), new PutBlobOptionsBuilder().chunkUpload(true).build()).get(TIMEOUT_SECS, TimeUnit.SECONDS);
        chunks.add(new ChunkInfo(blobId, chunkSize, Utils.addSecondsToEpochTime(creationTimeMs, blobTtlSecs)));
    }
    return chunks;
}
Also used : ChunkInfo(com.github.ambry.router.ChunkInfo) ByteBufferReadableStreamChannel(com.github.ambry.commons.ByteBufferReadableStreamChannel) PutBlobOptionsBuilder(com.github.ambry.router.PutBlobOptionsBuilder) BlobProperties(com.github.ambry.messageformat.BlobProperties) ArrayList(java.util.ArrayList)

Example 5 with PutBlobOptionsBuilder

use of com.github.ambry.router.PutBlobOptionsBuilder in project ambry by linkedin.

the class NamedBlobPutHandlerTest method uploadChunksViaRouter.

/**
 * Upload chunks using the router directly.
 * @param creationTimeMs the creation time to set for the chunks.
 * @param container the {@link Container} to create the chunks in.
 * @param chunkSizes the sizes for each chunk to upload.
 * @return a list of {@link ChunkInfo} objects that contains metadata about each chunk uploaded.
 */
private List<ChunkInfo> uploadChunksViaRouter(long creationTimeMs, Container container, int... chunkSizes) throws Exception {
    long blobTtlSecs = TimeUnit.DAYS.toSeconds(1);
    List<ChunkInfo> chunks = new ArrayList<>();
    for (int chunkSize : chunkSizes) {
        byte[] content = TestUtils.getRandomBytes(chunkSize);
        BlobProperties blobProperties = new BlobProperties(-1, SERVICE_ID, OWNER_ID, CONTENT_TYPE, !container.isCacheable(), blobTtlSecs, creationTimeMs, container.getParentAccountId(), container.getId(), container.isEncrypted(), null, null, null);
        String blobId = router.putBlob(blobProperties, null, new ByteBufferReadableStreamChannel(ByteBuffer.wrap(content)), new PutBlobOptionsBuilder().chunkUpload(true).build()).get(TIMEOUT_SECS, TimeUnit.SECONDS);
        chunks.add(new ChunkInfo(blobId, chunkSize, Utils.addSecondsToEpochTime(creationTimeMs, blobTtlSecs)));
    }
    return chunks;
}
Also used : ChunkInfo(com.github.ambry.router.ChunkInfo) ByteBufferReadableStreamChannel(com.github.ambry.commons.ByteBufferReadableStreamChannel) PutBlobOptionsBuilder(com.github.ambry.router.PutBlobOptionsBuilder) BlobProperties(com.github.ambry.messageformat.BlobProperties) ArrayList(java.util.ArrayList)

Aggregations

PutBlobOptionsBuilder (com.github.ambry.router.PutBlobOptionsBuilder)7 ByteBufferReadableStreamChannel (com.github.ambry.commons.ByteBufferReadableStreamChannel)6 BlobProperties (com.github.ambry.messageformat.BlobProperties)5 ArrayList (java.util.ArrayList)3 ChunkInfo (com.github.ambry.router.ChunkInfo)2 MetricRegistry (com.codahale.metrics.MetricRegistry)1 AccountService (com.github.ambry.account.AccountService)1 InMemAccountService (com.github.ambry.account.InMemAccountService)1 MockClusterMap (com.github.ambry.clustermap.MockClusterMap)1 MockDataNodeId (com.github.ambry.clustermap.MockDataNodeId)1 MockDiskId (com.github.ambry.clustermap.MockDiskId)1 MockPartitionId (com.github.ambry.clustermap.MockPartitionId)1 MockReplicaId (com.github.ambry.clustermap.MockReplicaId)1 PartitionId (com.github.ambry.clustermap.PartitionId)1 ReplicaId (com.github.ambry.clustermap.ReplicaId)1 BlobId (com.github.ambry.commons.BlobId)1 BlobIdFactory (com.github.ambry.commons.BlobIdFactory)1 ClusterMapConfig (com.github.ambry.config.ClusterMapConfig)1 ConnectionPoolConfig (com.github.ambry.config.ConnectionPoolConfig)1 SSLConfig (com.github.ambry.config.SSLConfig)1