Search in sources :

Example 11 with Container

use of com.github.ambry.account.Container in project ambry by linkedin.

the class AccountContainerTest method testToString.

// Tests for builders
/**
 * Tests {@code toString()} methods.
 * @throws JSONException
 */
@Test
public void testToString() throws JSONException {
    Account account = accountFromJson(refAccountJson);
    assertEquals("Account[" + account.getId() + "," + account.getSnapshotVersion() + "]", account.toString());
    for (int i = 0; i < CONTAINER_COUNT; i++) {
        Container container = containerFromJson(containerJsonList.get(i), refAccountId);
        assertEquals("Container[" + account.getId() + ":" + container.getId() + "]", container.toString());
    }
}
Also used : Account(com.github.ambry.account.Account) Container(com.github.ambry.account.Container) Test(org.junit.Test)

Example 12 with Container

use of com.github.ambry.account.Container in project ambry by linkedin.

the class AccountContainerTest method testRemoveNonExistContainer.

/**
 * Tests removing a non-existent container from accountBuilder.
 * @throws JSONException
 */
@Test
public void testRemoveNonExistContainer() throws JSONException {
    Account origin = accountFromJson(refAccountJson);
    AccountBuilder accountBuilder = new AccountBuilder(origin);
    ContainerBuilder containerBuilder = new ContainerBuilder((short) -999, refContainerNames.get(0), refContainerStatuses.get(0), refContainerDescriptions.get(0), refAccountId).setEncrypted(refContainerEncryptionValues.get(0)).setPreviouslyEncrypted(refContainerPreviousEncryptionValues.get(0)).setCacheable(refContainerCachingValues.get(0)).setBackupEnabled(refContainerBackupEnabledValues.get(0)).setMediaScanDisabled(refContainerMediaScanDisabledValues.get(0)).setReplicationPolicy(refContainerReplicationPolicyValues.get(0)).setTtlRequired(refContainerTtlRequiredValues.get(0)).setContentTypeWhitelistForFilenamesOnDownload(refContainerContentTypeAllowListForFilenamesOnDownloadValues.get(0)).setDeleteTriggerTime(refContainerDeleteTriggerTime.get(0)).setAccessControlAllowOrigin(refAccessControlAllowOriginValues.get(0));
    Container container = containerBuilder.build();
    accountBuilder.removeContainer(container);
    accountBuilder.removeContainer(null);
    Account account = accountBuilder.build();
    assertAccountAgainstReference(account, true, true);
}
Also used : Account(com.github.ambry.account.Account) Container(com.github.ambry.account.Container) Test(org.junit.Test)

Example 13 with Container

use of com.github.ambry.account.Container in project ambry by linkedin.

the class RestUtils method buildBlobProperties.

/**
 * Builds {@link BlobProperties} given the arguments associated with a request.
 * @param args the arguments associated with the request. Cannot be {@code null}.
 * @return the {@link BlobProperties} extracted from the arguments.
 * @throws RestServiceException if required arguments aren't present or if they aren't in the format or number
 *                                    expected.
 */
public static BlobProperties buildBlobProperties(Map<String, Object> args) throws RestServiceException {
    Account account = getAccountFromArgs(args);
    Container container = getContainerFromArgs(args);
    String serviceId = getHeader(args, Headers.SERVICE_ID, true);
    String contentType = getHeader(args, Headers.AMBRY_CONTENT_TYPE, true);
    String ownerId = getHeader(args, Headers.OWNER_ID, false);
    String externalAssetTag = getHeader(args, Headers.EXTERNAL_ASSET_TAG, false);
    String contentEncoding = getHeader(args, Headers.AMBRY_CONTENT_ENCODING, false);
    String filename = getHeader(args, Headers.AMBRY_FILENAME, false);
    long ttl = getTtlFromRequestHeader(args);
    // This field should not matter on newly created blobs, because all privacy/cacheability decisions should be made
    // based on the container properties and ACLs. For now, BlobProperties still includes this field, though.
    boolean isPrivate = !container.isCacheable();
    return new BlobProperties(-1, serviceId, ownerId, contentType, isPrivate, ttl, account.getId(), container.getId(), container.isEncrypted(), externalAssetTag, contentEncoding, filename);
}
Also used : Account(com.github.ambry.account.Account) Container(com.github.ambry.account.Container) BlobProperties(com.github.ambry.messageformat.BlobProperties)

Example 14 with Container

use of com.github.ambry.account.Container in project ambry by linkedin.

the class RestUtils method accountAndContainerNamePreconditionCheck.

/**
 * Check preconditions for request if the {@code restRequest} contains the target account and container.
 * @param restRequest the {@link RestRequest} that contains the {@link Account} and {@link Container} details.
 * @throws RestServiceException if preconditions check failed.
 */
public static void accountAndContainerNamePreconditionCheck(RestRequest restRequest) throws RestServiceException {
    String accountNameFromHeader = getHeader(restRequest.getArgs(), Headers.TARGET_ACCOUNT_NAME, false);
    String containerNameFromHeader = getHeader(restRequest.getArgs(), Headers.TARGET_CONTAINER_NAME, false);
    if (accountNameFromHeader != null) {
        Account targetAccount = getAccountFromArgs(restRequest.getArgs());
        String accountNameFromBlobId = targetAccount.getName();
        if (!accountNameFromHeader.equals(accountNameFromBlobId)) {
            throw new RestServiceException("Account name: " + accountNameFromHeader + " from request doesn't match the account name from Blob id : " + accountNameFromBlobId, RestServiceErrorCode.PreconditionFailed);
        }
        if (containerNameFromHeader != null) {
            Container targetContainer = getContainerFromArgs(restRequest.getArgs());
            String containerNameFromBlobId = targetContainer.getName();
            if (!containerNameFromHeader.equals(containerNameFromBlobId)) {
                throw new RestServiceException("Container name: " + containerNameFromHeader + "from request doesn't match the container name from Blob id : " + containerNameFromBlobId, RestServiceErrorCode.PreconditionFailed);
            }
        }
    } else if (containerNameFromHeader != null) {
        throw new RestServiceException("Only container name is set in request with no corresponding account name is not allowed.", RestServiceErrorCode.BadRequest);
    }
}
Also used : Account(com.github.ambry.account.Account) Container(com.github.ambry.account.Container)

Example 15 with Container

use of com.github.ambry.account.Container in project ambry by linkedin.

the class AzureContainerCompactorIntegrationTest method testCompactAssignedDeprecatedContainers.

@Test
public void testCompactAssignedDeprecatedContainers() throws CloudStorageException, DocumentClientException {
    // Create a deprecated container.
    Set<Container> containers = generateContainers(1);
    cloudDestination.deprecateContainers(containers);
    verifyCosmosData(containers);
    verifyCheckpoint(containers);
    Container testContainer = containers.iterator().next();
    // Create blobs in the deprecated container and test partition.
    int numBlobs = 100;
    PartitionId partitionId = new MockPartitionId(testPartitionId, MockClusterMap.DEFAULT_PARTITION_CLASS);
    long creationTime = System.currentTimeMillis();
    Map<BlobId, byte[]> blobIdtoDataMap = createUnencryptedPermanentBlobs(numBlobs, dataCenterId, testContainer.getParentAccountId(), testContainer.getId(), partitionId, blobSize, cloudRequestAgent, cloudDestination, creationTime);
    // Assert that blobs exist.
    Map<String, CloudBlobMetadata> metadataMap = getBlobMetadataWithRetry(new ArrayList<>(blobIdtoDataMap.keySet()), partitionId.toPathString(), cloudRequestAgent, cloudDestination);
    assertEquals("Unexpected size of returned metadata map", numBlobs, metadataMap.size());
    // compact the deprecated container.
    cloudDestination.getContainerCompactor().compactAssignedDeprecatedContainers(Collections.singletonList(partitionId));
    // Assert that deprecated container's blobs don't exist anymore.
    assertTrue("Expected empty set after container compaction", getBlobMetadataWithRetry(new ArrayList<>(blobIdtoDataMap.keySet()), partitionId.toPathString(), cloudRequestAgent, cloudDestination).isEmpty());
    cleanup();
}
Also used : Container(com.github.ambry.account.Container) MockPartitionId(com.github.ambry.clustermap.MockPartitionId) CloudBlobMetadata(com.github.ambry.cloud.CloudBlobMetadata) MockPartitionId(com.github.ambry.clustermap.MockPartitionId) PartitionId(com.github.ambry.clustermap.PartitionId) BlobId(com.github.ambry.commons.BlobId) Test(org.junit.Test)

Aggregations

Container (com.github.ambry.account.Container)119 Account (com.github.ambry.account.Account)88 Test (org.junit.Test)61 ArrayList (java.util.ArrayList)30 RestServiceException (com.github.ambry.rest.RestServiceException)20 ContainerBuilder (com.github.ambry.account.ContainerBuilder)17 JSONObject (org.json.JSONObject)17 VerifiableProperties (com.github.ambry.config.VerifiableProperties)16 HashSet (java.util.HashSet)15 HashMap (java.util.HashMap)14 Properties (java.util.Properties)14 AccountBuilder (com.github.ambry.account.AccountBuilder)13 RestRequest (com.github.ambry.rest.RestRequest)13 ByteBuffer (java.nio.ByteBuffer)13 Map (java.util.Map)13 MetricRegistry (com.codahale.metrics.MetricRegistry)12 TestUtils (com.github.ambry.utils.TestUtils)12 Collections (java.util.Collections)12 List (java.util.List)12 Assert (org.junit.Assert)12