use of com.github.ambry.account.Container in project ambry by linkedin.
the class BlobStoreStatsTest method getContainerStorageStats.
/**
* Go over the referenceIndex to collect valid data size information per container. The result is used for
* verification purposes.
* @param deleteReferenceTimeInMs the reference time in ms until which deletes are relevant
* @param expiryReferenceTimeInMs the reference time in ms until which expirations are relevant
* @param deleteTombstoneStats a hashmap that tracks stats related delete tombstones in log segments.
* @return a nested {@link Map} of serviceId to containerId to valid data size
*/
private Map<Short, Map<Short, ContainerStorageStats>> getContainerStorageStats(long deleteReferenceTimeInMs, long expiryReferenceTimeInMs, Map<String, Pair<AtomicLong, AtomicLong>> deleteTombstoneStats) {
Map<Short, Map<Short, ContainerStorageStats>> containerStorageStats = new HashMap<>();
Map<Short, Map<Short, Long>> validSizeMap = new HashMap<>();
Map<Short, Map<Short, Long>> physicalSizeMap = new HashMap<>();
Map<Short, Map<Short, Set<StoreKey>>> storeKeyMap = new HashMap<>();
Pair<Set<MockId>, Set<MockId>> expiredDeletes = new Pair<>(new HashSet<>(), new HashSet<>());
for (Offset indSegStartOffset : state.referenceIndex.keySet()) {
state.getValidIndexEntriesForIndexSegment(indSegStartOffset, deleteReferenceTimeInMs, expiryReferenceTimeInMs, null, deleteTombstoneStats, expiredDeletes, true, (entry, isValid) -> {
IndexValue indexValue = entry.getValue();
if (indexValue.isPut() && isValid) {
StatsUtils.updateNestedMapHelper(validSizeMap, indexValue.getAccountId(), indexValue.getContainerId(), indexValue.getSize());
}
StatsUtils.updateNestedMapHelper(physicalSizeMap, indexValue.getAccountId(), indexValue.getContainerId(), indexValue.getSize());
storeKeyMap.computeIfAbsent(indexValue.getAccountId(), k -> new HashMap<>()).computeIfAbsent(indexValue.getContainerId(), k -> new HashSet<>()).add(entry.getKey());
});
}
for (short accountId : validSizeMap.keySet()) {
for (short containerId : validSizeMap.get(accountId).keySet()) {
containerStorageStats.computeIfAbsent(accountId, k -> new HashMap<>()).put(containerId, new ContainerStorageStats(containerId, validSizeMap.get(accountId).get(containerId), physicalSizeMap.get(accountId).get(containerId), storeKeyMap.get(accountId).get(containerId).size()));
}
}
return containerStorageStats;
}
use of com.github.ambry.account.Container in project ambry by linkedin.
the class AmbrySecurityServiceTest method testGetBlob.
/**
* Tests {@link SecurityService#processResponse(RestRequest, RestResponseChannel, BlobInfo, Callback)} for a Get blob
* with the passed in {@link BlobInfo} and {@link ByteRange}
* @param blobInfo the {@link BlobInfo} to be used for the {@link RestRequest}
* @param range the {@link ByteRange} for the {@link RestRequest}
* @throws Exception
*/
private void testGetBlob(BlobInfo blobInfo, ByteRange range) throws Exception {
MockRestResponseChannel restResponseChannel = new MockRestResponseChannel();
JSONObject headers = range != null ? new JSONObject().put(RestUtils.Headers.RANGE, RestTestUtils.getRangeHeaderString(range)) : null;
RestRequest restRequest = createRestRequest(RestMethod.GET, "/", headers);
Pair<Account, Container> accountAndContainer = getAccountAndContainer(blobInfo.getBlobProperties());
insertAccountAndContainer(restRequest, accountAndContainer.getFirst(), accountAndContainer.getSecond());
securityService.processResponse(restRequest, restResponseChannel, blobInfo).get();
Assert.assertEquals("ProcessResponse status should have been set", range == null ? ResponseStatus.Ok : ResponseStatus.PartialContent, restResponseChannel.getStatus());
verifyHeadersForGetBlob(restRequest, blobInfo, accountAndContainer, range, restResponseChannel);
}
use of com.github.ambry.account.Container in project ambry by linkedin.
the class FrontendIntegrationTest method updateContainersAndVerify.
// accountApiTest() helpers
/**
* Call the {@code POST /accounts/updateContainers} API to update account metadata and verify that the update succeeded.
* @param account the account in which to update containers.
* @param containers the containers to update.
*/
private void updateContainersAndVerify(Account account, Container... containers) throws Exception {
byte[] containersUpdateJson = AccountCollectionSerde.serializeContainersInJson(Arrays.asList(containers));
String accountName = account.getName();
HttpHeaders headers = new DefaultHttpHeaders();
headers.add(RestUtils.Headers.TARGET_ACCOUNT_NAME, accountName);
FullHttpRequest request = buildRequest(HttpMethod.POST, Operations.ACCOUNTS_CONTAINERS, headers, ByteBuffer.wrap(containersUpdateJson));
ResponseParts responseParts = nettyClient.sendRequest(request, null, null).get();
HttpResponse response = getHttpResponse(responseParts);
assertEquals("Unexpected response status", HttpResponseStatus.OK, response.status());
// verify regular response header
assertEquals("Unexpected account id in response header", account.getId(), Short.parseShort(response.headers().get(RestUtils.Headers.TARGET_ACCOUNT_ID)));
assertEquals("Unexpected content type in response header", RestUtils.JSON_CONTENT_TYPE, response.headers().get(RestUtils.Headers.CONTENT_TYPE));
verifyTrackingHeaders(response);
ByteBuffer content = getContent(responseParts.queue, HttpUtil.getContentLength(response));
Collection<Container> outputContainers = AccountCollectionSerde.containersFromInputStreamInJson(new ByteArrayInputStream(content.array()), account.getId());
for (Container container : outputContainers) {
assertEquals("Update not reflected in AccountService", container, ACCOUNT_SERVICE.getContainerByName(accountName, container.getName()));
}
}
use of com.github.ambry.account.Container in project ambry by linkedin.
the class FrontendIntegrationTest method accountApiTest.
/**
* Tests for the account/container get/update API.
*/
@Test
public void accountApiTest() throws Exception {
verifyGetAccountsAndContainer();
// update and add accounts
Map<Short, Account> accountsById = ACCOUNT_SERVICE.getAllAccounts().stream().collect(Collectors.toMap(Account::getId, Function.identity()));
Account editedAccount = accountsById.values().stream().findAny().get();
Container editedContainer = editedAccount.getAllContainers().stream().findAny().get();
editedContainer = new ContainerBuilder(editedContainer).setDescription("new description abcdefgh").build();
editedAccount = new AccountBuilder(editedAccount).addOrUpdateContainer(editedContainer).build();
updateAccountsAndVerify(ACCOUNT_SERVICE, editedAccount, ACCOUNT_SERVICE.generateRandomAccount());
verifyGetAccountsAndContainer();
// Test adding a container to the account
Container newContainer = ACCOUNT_SERVICE.getRandomContainer(editedAccount.getId());
updateContainersAndVerify(editedAccount, newContainer);
}
use of com.github.ambry.account.Container in project ambry by linkedin.
the class FrontendIntegrationTest method multipartPostGetHeadUpdateDeleteUndeleteTest.
/**
* Tests multipart POST and verifies it via GET operations.
* @throws Exception
*/
@Test
public void multipartPostGetHeadUpdateDeleteUndeleteTest() throws Exception {
Account refAccount = ACCOUNT_SERVICE.createAndAddRandomAccount();
Container refContainer = refAccount.getContainerById(Container.DEFAULT_PUBLIC_CONTAINER_ID);
doPostGetHeadUpdateDeleteUndeleteTest(0, refAccount, refContainer, refAccount.getName(), !refContainer.isCacheable(), refAccount.getName(), refContainer.getName(), true);
doPostGetHeadUpdateDeleteUndeleteTest((int) FRONTEND_CONFIG.chunkedGetResponseThresholdInBytes * 3, refAccount, refContainer, refAccount.getName(), !refContainer.isCacheable(), refAccount.getName(), refContainer.getName(), true);
// failure case
// size of content being POSTed is higher than what is allowed via multipart/form-data
long maxAllowedSizeBytes = new NettyConfig(FRONTEND_VERIFIABLE_PROPS).nettyMultipartPostMaxSizeBytes;
ByteBuffer content = ByteBuffer.wrap(TestUtils.getRandomBytes((int) maxAllowedSizeBytes + 1));
HttpHeaders headers = new DefaultHttpHeaders();
setAmbryHeadersForPut(headers, TTL_SECS, !refContainer.isCacheable(), refAccount.getName(), "application/octet-stream", null, refAccount.getName(), refContainer.getName());
HttpRequest httpRequest = RestTestUtils.createRequest(HttpMethod.POST, "/", headers);
HttpPostRequestEncoder encoder = createEncoder(httpRequest, content, ByteBuffer.allocate(0));
ResponseParts responseParts = nettyClient.sendRequest(encoder.finalizeRequest(), encoder, null).get();
HttpResponse response = getHttpResponse(responseParts);
assertEquals("Unexpected response status", HttpResponseStatus.REQUEST_ENTITY_TOO_LARGE, response.status());
assertTrue("No Date header", response.headers().getTimeMillis(HttpHeaderNames.DATE, -1) != -1);
assertFalse("Channel should not be active", HttpUtil.isKeepAlive(response));
}
Aggregations