use of com.github.ambry.router.GetBlobResult in project ambry by linkedin.
the class PerfRouter method getBlob.
@Override
public Future<GetBlobResult> getBlob(String blobId, GetBlobOptions options, Callback<GetBlobResult> callback) {
logger.trace("Received getBlob call");
FutureResult<GetBlobResult> futureResult = new FutureResult<>();
if (!routerOpen) {
completeOperation(futureResult, callback, null, ROUTER_CLOSED_EXCEPTION);
} else {
GetBlobResult result = null;
switch(options.getOperationType()) {
case All:
result = new GetBlobResult(new BlobInfo(blobProperties, usermetadata), new PerfRSC(chunk, blobProperties.getBlobSize()));
break;
case Data:
result = new GetBlobResult(null, new PerfRSC(chunk, blobProperties.getBlobSize()));
break;
case BlobInfo:
result = new GetBlobResult(new BlobInfo(blobProperties, usermetadata), null);
break;
}
completeOperation(futureResult, callback, result, null);
}
return futureResult;
}
use of com.github.ambry.router.GetBlobResult in project ambry by linkedin.
the class TtlUpdateHandlerTest method assertTtl.
/**
* Verifies that the TTL is {@code expectedTtlSecs}
* @param expectedTtlSecs the expected TTL (in secs) of the blob
* @throws Exception
*/
private void assertTtl(long expectedTtlSecs) throws Exception {
GetBlobResult result = router.getBlob(blobId, new GetBlobOptionsBuilder().build()).get(1, TimeUnit.SECONDS);
assertEquals("TTL not as expected", expectedTtlSecs, result.getBlobInfo().getBlobProperties().getTimeToLiveInSeconds());
}
use of com.github.ambry.router.GetBlobResult in project ambry by linkedin.
the class RouterStore method readAccountMetadataFromBlobID.
/**
* Fetch the {@link Account} metadata from the given blob id.
* @param blobID The blobID to fetch {@link Account} metadata from.
* @return {@link Account} metadata in a map, and null when there is any error.
*/
Map<String, String> readAccountMetadataFromBlobID(String blobID) {
long startTimeMs = System.currentTimeMillis();
Future<GetBlobResult> resultF = router.get().getBlob(blobID, new GetBlobOptionsBuilder().build());
try {
GetBlobResult result = resultF.get();
accountServiceMetrics.accountFetchFromAmbryTimeInMs.update(System.currentTimeMillis() - startTimeMs);
int blobSize = (int) result.getBlobInfo().getBlobProperties().getBlobSize();
InputStream input = new ReadableStreamChannelInputStream(result.getBlobDataChannel());
byte[] bytes = Utils.readBytesFromStream(input, blobSize);
JSONObject object = new JSONObject(new String(bytes, Charsets.UTF_8));
Map<String, String> map = new HashMap<>();
object.keySet().forEach(key -> map.put(key, object.getString(key)));
return map;
} catch (Exception e) {
logger.error("Failed to read account metadata from blob id={}", blobID, e);
accountServiceMetrics.accountFetchFromAmbryServerErrorCount.inc();
}
return null;
}
use of com.github.ambry.router.GetBlobResult in project ambry by linkedin.
the class PerfRouter method getBlob.
@Override
public Future<GetBlobResult> getBlob(String blobId, GetBlobOptions options, Callback<GetBlobResult> callback, QuotaChargeCallback quotaChargeCallback) {
logger.trace("Received getBlob call");
FutureResult<GetBlobResult> futureResult = new FutureResult<>();
if (!routerOpen) {
completeOperation(futureResult, callback, null, ROUTER_CLOSED_EXCEPTION);
} else {
GetBlobResult result = null;
switch(options.getOperationType()) {
case All:
result = new GetBlobResult(new BlobInfo(blobProperties, usermetadata), new PerfRSC(chunk, blobProperties.getBlobSize()));
break;
case Data:
result = new GetBlobResult(null, new PerfRSC(chunk, blobProperties.getBlobSize()));
break;
case BlobInfo:
result = new GetBlobResult(new BlobInfo(blobProperties, usermetadata), null);
break;
}
completeOperation(futureResult, callback, result, null);
}
return futureResult;
}
use of com.github.ambry.router.GetBlobResult in project ambry by linkedin.
the class MockRouter method getBlob.
@Override
public Future<GetBlobResult> getBlob(String blobId, GetBlobOptions options, Callback<GetBlobResult> callback, QuotaChargeCallback quotaChargeCallback) {
lock.lock();
try {
BlobInfoAndData blob = allBlobs.get(blobId);
FutureResult<GetBlobResult> future = new FutureResult<>();
if (blob == null) {
Exception e = new RouterException("NotFound", RouterErrorCode.BlobDoesNotExist);
future.done(null, e);
if (callback != null) {
callback.onCompletion(null, e);
}
return future;
}
// Discard the options and only return the BlobAll.
ReadableStreamChannel channel = new ByteBufferReadableStreamChannel(ByteBuffer.wrap(blob.getData()));
GetBlobResult result = new GetBlobResult(blob.getBlobInfo(), channel);
future.done(result, null);
if (callback != null) {
callback.onCompletion(result, null);
}
return future;
} finally {
lock.unlock();
}
}
Aggregations