Class Container
- java.lang.Object
-
- com.github.ambry.account.Container
-
public class Container extends java.lang.Object
A representation of a container. A container virtually groups a number of blobs under the same
Account
, so that an operation on a container can be applied to all the blobs of the container. When posting a blob, a container needs to be specified. There can be multiple containers under the the sameAccount
, but containers cannot be nested.Container name is provided by a user as an external reference to that container. Container id is an internal identifier of the container, and is one-to-one mapped to a container name. Container name/id has to be distinct within the same
Account
, but can be the same across differentAccount
s.Container is serialized into
JSONObject
in thecurrentJsonVersion
, which is version 1 for now. Below lists all the metadata versions and their formats:{ "containerName": "MyPrivateContainer", "description": "This is my private container", "isPrivate": "true", "containerId": 0, "version": 1, "status": "active" "parentAccountId": "101" }
A container object is immutable. To update a container, refer to
ContainerBuilder
andAccountBuilder
.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Container.ContainerStatus
Status of the container.
-
Field Summary
Fields Modifier and Type Field Description static Container
DEFAULT_PRIVATE_CONTAINER
Deprecated.static boolean
DEFAULT_PRIVATE_CONTAINER_CACHEABLE_SETTING
The cache setting ofDEFAULT_PRIVATE_CONTAINER
.static long
DEFAULT_PRIVATE_CONTAINER_DELETE_TRIGGER_TIME
The delete trigger time ofDEFAULT_PRIVATE_CONTAINER
static java.lang.String
DEFAULT_PRIVATE_CONTAINER_DESCRIPTION
The description for the containers to be associated with the blobs that are put without specifying a target container, but are specified private.static boolean
DEFAULT_PRIVATE_CONTAINER_ENCRYPTED_SETTING
The encryption setting ofDEFAULT_PRIVATE_CONTAINER
.static short
DEFAULT_PRIVATE_CONTAINER_ID
The id for the containers to be associated with the blobs that are put without specifying a target container, but are specified private.static boolean
DEFAULT_PRIVATE_CONTAINER_MEDIA_SCAN_DISABLED_SETTING
The media scan disabled setting forDEFAULT_PRIVATE_CONTAINER
.static java.lang.String
DEFAULT_PRIVATE_CONTAINER_NAME
The name for the containers to be associated with the blobs that are put without specifying a target container, but are specified private.static short
DEFAULT_PRIVATE_CONTAINER_PARENT_ACCOUNT_ID
The parent account id ofDEFAULT_PRIVATE_CONTAINER
.static boolean
DEFAULT_PRIVATE_CONTAINER_PREVIOUSLY_ENCRYPTED_SETTING
The previously encrypted flag forDEFAULT_PRIVATE_CONTAINER
.static Container.ContainerStatus
DEFAULT_PRIVATE_CONTAINER_STATUS
The status for the containers to be associated with the blobs that are put without specifying a target container, but are specified private.static boolean
DEFAULT_PRIVATE_CONTAINER_TTL_REQUIRED_SETTING
The ttl required setting forDEFAULT_PRIVATE_CONTAINER
.static Container
DEFAULT_PUBLIC_CONTAINER
Deprecated.static boolean
DEFAULT_PUBLIC_CONTAINER_CACHEABLE_SETTING
The cache setting ofDEFAULT_PUBLIC_CONTAINER
.static long
DEFAULT_PUBLIC_CONTAINER_DELETE_TRIGGER_TIME
The delete trigger time ofDEFAULT_PUBLIC_CONTAINER
static java.lang.String
DEFAULT_PUBLIC_CONTAINER_DESCRIPTION
The description for the containers to be associated with the blobs that are put without specifying a target container, but are specified public.static boolean
DEFAULT_PUBLIC_CONTAINER_ENCRYPTED_SETTING
The encryption setting ofDEFAULT_PUBLIC_CONTAINER
.static short
DEFAULT_PUBLIC_CONTAINER_ID
The id for the containers to be associated with the blobs that are put without specifying a target container, but are specified public.static boolean
DEFAULT_PUBLIC_CONTAINER_MEDIA_SCAN_DISABLED_SETTING
The media scan disabled setting forDEFAULT_PUBLIC_CONTAINER
.static java.lang.String
DEFAULT_PUBLIC_CONTAINER_NAME
The name for the containers to be associated with the blobs that are put without specifying a target container, but are specified public.static short
DEFAULT_PUBLIC_CONTAINER_PARENT_ACCOUNT_ID
The parent account id ofDEFAULT_PUBLIC_CONTAINER
.static boolean
DEFAULT_PUBLIC_CONTAINER_PREVIOUSLY_ENCRYPTED_SETTING
The previously encrypted flag forDEFAULT_PUBLIC_CONTAINER
.static Container.ContainerStatus
DEFAULT_PUBLIC_CONTAINER_STATUS
The status for the containers to be associated with the blobs that are put without specifying a target container, but are specified public.static boolean
DEFAULT_PUBLIC_CONTAINER_TTL_REQUIRED_SETTING
The ttl required setting forDEFAULT_PUBLIC_CONTAINER
.static short
HELIX_ACCOUNT_SERVICE_CONTAINER_ID
The id for HelixAccountService to storeAccount
metadata.static short
JSON_VERSION_1
static short
JSON_VERSION_2
static Container
UNKNOWN_CONTAINER
Deprecated.static boolean
UNKNOWN_CONTAINER_CACHEABLE_SETTING
The cache setting ofUNKNOWN_CONTAINER
.static long
UNKNOWN_CONTAINER_DELETE_TRIGGER_TIME
The delete trigger time ofUNKNOWN_CONTAINER
static java.lang.String
UNKNOWN_CONTAINER_DESCRIPTION
The description ofUNKNOWN_CONTAINER
.static boolean
UNKNOWN_CONTAINER_ENCRYPTED_SETTING
The encryption setting ofUNKNOWN_CONTAINER
.static short
UNKNOWN_CONTAINER_ID
The id ofUNKNOWN_CONTAINER
.static boolean
UNKNOWN_CONTAINER_MEDIA_SCAN_DISABLED_SETTING
The media scan disabled setting forUNKNOWN_CONTAINER
.static java.lang.String
UNKNOWN_CONTAINER_NAME
The name ofUNKNOWN_CONTAINER
.static short
UNKNOWN_CONTAINER_PARENT_ACCOUNT_ID
The parent account id ofUNKNOWN_CONTAINER
.static boolean
UNKNOWN_CONTAINER_PREVIOUSLY_ENCRYPTED_SETTING
The previously encrypted flag forUNKNOWN_CONTAINER
.static Container.ContainerStatus
UNKNOWN_CONTAINER_STATUS
The status ofUNKNOWN_CONTAINER
.static boolean
UNKNOWN_CONTAINER_TTL_REQUIRED_SETTING
The ttl required setting forUNKNOWN_CONTAINER
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(java.lang.Object o)
static Container
fromJson(org.json.JSONObject json, short parentAccountId)
Deserializes aJSONObject
to a container object.java.util.Set<java.lang.String>
getContentTypeWhitelistForFilenamesOnDownload()
static short
getCurrentJsonVersion()
java.lang.Long
getDeleteTriggerTime()
Gets the delete trigger time of the container.java.lang.String
getDescription()
Gets the description of the container.short
getId()
Gets the id of the container.long
getLastModifiedTime()
Get the created/modified time of this Containerjava.lang.String
getName()
Gets the name of the container.short
getParentAccountId()
Gets the if of theAccount
that owns this container.java.lang.String
getReplicationPolicy()
int
getSnapshotVersion()
The snapshot version is generally the number of modifications to the container that were expected to have occurred before the current time.Container.ContainerStatus
getStatus()
Gets the status of the container.int
hashCode()
boolean
isBackupEnabled()
boolean
isCacheable()
boolean
isEncrypted()
boolean
isMediaScanDisabled()
boolean
isSecurePathRequired()
boolean
isTtlRequired()
static void
setCurrentJsonVersion(short currentJsonVersion)
Set the JSON version to serialize in.org.json.JSONObject
toJson()
Gets the metadata of the container.java.lang.String
toString()
Generates a String representation that uniquely identifies this container.boolean
wasPreviouslyEncrypted()
-
-
-
Field Detail
-
JSON_VERSION_1
public static final short JSON_VERSION_1
- See Also:
- Constant Field Values
-
JSON_VERSION_2
public static final short JSON_VERSION_2
- See Also:
- Constant Field Values
-
UNKNOWN_CONTAINER_ID
public static final short UNKNOWN_CONTAINER_ID
The id ofUNKNOWN_CONTAINER
.- See Also:
- Constant Field Values
-
HELIX_ACCOUNT_SERVICE_CONTAINER_ID
public static final short HELIX_ACCOUNT_SERVICE_CONTAINER_ID
The id for HelixAccountService to storeAccount
metadata.- See Also:
- Constant Field Values
-
DEFAULT_PUBLIC_CONTAINER_ID
public static final short DEFAULT_PUBLIC_CONTAINER_ID
The id for the containers to be associated with the blobs that are put without specifying a target container, but are specified public.DEFAULT_PUBLIC_CONTAINER
is one of the containers that use it.- See Also:
- Constant Field Values
-
DEFAULT_PRIVATE_CONTAINER_ID
public static final short DEFAULT_PRIVATE_CONTAINER_ID
The id for the containers to be associated with the blobs that are put without specifying a target container, but are specified private.DEFAULT_PRIVATE_CONTAINER
is one of the containers that use it.- See Also:
- Constant Field Values
-
UNKNOWN_CONTAINER_NAME
public static final java.lang.String UNKNOWN_CONTAINER_NAME
The name ofUNKNOWN_CONTAINER
.- See Also:
- Constant Field Values
-
DEFAULT_PUBLIC_CONTAINER_NAME
public static final java.lang.String DEFAULT_PUBLIC_CONTAINER_NAME
The name for the containers to be associated with the blobs that are put without specifying a target container, but are specified public.DEFAULT_PUBLIC_CONTAINER
is one of the containers that use it.- See Also:
- Constant Field Values
-
DEFAULT_PRIVATE_CONTAINER_NAME
public static final java.lang.String DEFAULT_PRIVATE_CONTAINER_NAME
The name for the containers to be associated with the blobs that are put without specifying a target container, but are specified private.DEFAULT_PRIVATE_CONTAINER
is one of the containers that use it.- See Also:
- Constant Field Values
-
UNKNOWN_CONTAINER_STATUS
public static final Container.ContainerStatus UNKNOWN_CONTAINER_STATUS
The status ofUNKNOWN_CONTAINER
.
-
UNKNOWN_CONTAINER_DELETE_TRIGGER_TIME
public static final long UNKNOWN_CONTAINER_DELETE_TRIGGER_TIME
The delete trigger time ofUNKNOWN_CONTAINER
- See Also:
- Constant Field Values
-
DEFAULT_PUBLIC_CONTAINER_DELETE_TRIGGER_TIME
public static final long DEFAULT_PUBLIC_CONTAINER_DELETE_TRIGGER_TIME
The delete trigger time ofDEFAULT_PUBLIC_CONTAINER
- See Also:
- Constant Field Values
-
DEFAULT_PRIVATE_CONTAINER_DELETE_TRIGGER_TIME
public static final long DEFAULT_PRIVATE_CONTAINER_DELETE_TRIGGER_TIME
The delete trigger time ofDEFAULT_PRIVATE_CONTAINER
- See Also:
- Constant Field Values
-
DEFAULT_PUBLIC_CONTAINER_STATUS
public static final Container.ContainerStatus DEFAULT_PUBLIC_CONTAINER_STATUS
The status for the containers to be associated with the blobs that are put without specifying a target container, but are specified public.DEFAULT_PUBLIC_CONTAINER
is one of the containers that use it.
-
DEFAULT_PRIVATE_CONTAINER_STATUS
public static final Container.ContainerStatus DEFAULT_PRIVATE_CONTAINER_STATUS
The status for the containers to be associated with the blobs that are put without specifying a target container, but are specified private.DEFAULT_PRIVATE_CONTAINER
is one of the containers that use it.
-
UNKNOWN_CONTAINER_DESCRIPTION
public static final java.lang.String UNKNOWN_CONTAINER_DESCRIPTION
The description ofUNKNOWN_CONTAINER
.- See Also:
- Constant Field Values
-
DEFAULT_PUBLIC_CONTAINER_DESCRIPTION
public static final java.lang.String DEFAULT_PUBLIC_CONTAINER_DESCRIPTION
The description for the containers to be associated with the blobs that are put without specifying a target container, but are specified public.DEFAULT_PUBLIC_CONTAINER
is one of the containers that use it.- See Also:
- Constant Field Values
-
DEFAULT_PRIVATE_CONTAINER_DESCRIPTION
public static final java.lang.String DEFAULT_PRIVATE_CONTAINER_DESCRIPTION
The description for the containers to be associated with the blobs that are put without specifying a target container, but are specified private.DEFAULT_PRIVATE_CONTAINER
is one of the containers that use it.- See Also:
- Constant Field Values
-
UNKNOWN_CONTAINER_ENCRYPTED_SETTING
public static final boolean UNKNOWN_CONTAINER_ENCRYPTED_SETTING
The encryption setting ofUNKNOWN_CONTAINER
.- See Also:
- Constant Field Values
-
DEFAULT_PUBLIC_CONTAINER_ENCRYPTED_SETTING
public static final boolean DEFAULT_PUBLIC_CONTAINER_ENCRYPTED_SETTING
The encryption setting ofDEFAULT_PUBLIC_CONTAINER
.- See Also:
- Constant Field Values
-
DEFAULT_PRIVATE_CONTAINER_ENCRYPTED_SETTING
public static final boolean DEFAULT_PRIVATE_CONTAINER_ENCRYPTED_SETTING
The encryption setting ofDEFAULT_PRIVATE_CONTAINER
.- See Also:
- Constant Field Values
-
UNKNOWN_CONTAINER_PREVIOUSLY_ENCRYPTED_SETTING
public static final boolean UNKNOWN_CONTAINER_PREVIOUSLY_ENCRYPTED_SETTING
The previously encrypted flag forUNKNOWN_CONTAINER
.- See Also:
- Constant Field Values
-
DEFAULT_PUBLIC_CONTAINER_PREVIOUSLY_ENCRYPTED_SETTING
public static final boolean DEFAULT_PUBLIC_CONTAINER_PREVIOUSLY_ENCRYPTED_SETTING
The previously encrypted flag forDEFAULT_PUBLIC_CONTAINER
.- See Also:
- Constant Field Values
-
DEFAULT_PRIVATE_CONTAINER_PREVIOUSLY_ENCRYPTED_SETTING
public static final boolean DEFAULT_PRIVATE_CONTAINER_PREVIOUSLY_ENCRYPTED_SETTING
The previously encrypted flag forDEFAULT_PRIVATE_CONTAINER
.- See Also:
- Constant Field Values
-
UNKNOWN_CONTAINER_CACHEABLE_SETTING
public static final boolean UNKNOWN_CONTAINER_CACHEABLE_SETTING
The cache setting ofUNKNOWN_CONTAINER
.- See Also:
- Constant Field Values
-
DEFAULT_PUBLIC_CONTAINER_CACHEABLE_SETTING
public static final boolean DEFAULT_PUBLIC_CONTAINER_CACHEABLE_SETTING
The cache setting ofDEFAULT_PUBLIC_CONTAINER
.- See Also:
- Constant Field Values
-
DEFAULT_PRIVATE_CONTAINER_CACHEABLE_SETTING
public static final boolean DEFAULT_PRIVATE_CONTAINER_CACHEABLE_SETTING
The cache setting ofDEFAULT_PRIVATE_CONTAINER
.- See Also:
- Constant Field Values
-
UNKNOWN_CONTAINER_MEDIA_SCAN_DISABLED_SETTING
public static final boolean UNKNOWN_CONTAINER_MEDIA_SCAN_DISABLED_SETTING
The media scan disabled setting forUNKNOWN_CONTAINER
.- See Also:
- Constant Field Values
-
DEFAULT_PUBLIC_CONTAINER_MEDIA_SCAN_DISABLED_SETTING
public static final boolean DEFAULT_PUBLIC_CONTAINER_MEDIA_SCAN_DISABLED_SETTING
The media scan disabled setting forDEFAULT_PUBLIC_CONTAINER
.- See Also:
- Constant Field Values
-
DEFAULT_PRIVATE_CONTAINER_MEDIA_SCAN_DISABLED_SETTING
public static final boolean DEFAULT_PRIVATE_CONTAINER_MEDIA_SCAN_DISABLED_SETTING
The media scan disabled setting forDEFAULT_PRIVATE_CONTAINER
.- See Also:
- Constant Field Values
-
UNKNOWN_CONTAINER_TTL_REQUIRED_SETTING
public static final boolean UNKNOWN_CONTAINER_TTL_REQUIRED_SETTING
The ttl required setting forUNKNOWN_CONTAINER
.- See Also:
- Constant Field Values
-
DEFAULT_PUBLIC_CONTAINER_TTL_REQUIRED_SETTING
public static final boolean DEFAULT_PUBLIC_CONTAINER_TTL_REQUIRED_SETTING
The ttl required setting forDEFAULT_PUBLIC_CONTAINER
.- See Also:
- Constant Field Values
-
DEFAULT_PRIVATE_CONTAINER_TTL_REQUIRED_SETTING
public static final boolean DEFAULT_PRIVATE_CONTAINER_TTL_REQUIRED_SETTING
The ttl required setting forDEFAULT_PRIVATE_CONTAINER
.- See Also:
- Constant Field Values
-
UNKNOWN_CONTAINER_PARENT_ACCOUNT_ID
public static final short UNKNOWN_CONTAINER_PARENT_ACCOUNT_ID
The parent account id ofUNKNOWN_CONTAINER
.- See Also:
- Constant Field Values
-
DEFAULT_PUBLIC_CONTAINER_PARENT_ACCOUNT_ID
public static final short DEFAULT_PUBLIC_CONTAINER_PARENT_ACCOUNT_ID
The parent account id ofDEFAULT_PUBLIC_CONTAINER
.- See Also:
- Constant Field Values
-
DEFAULT_PRIVATE_CONTAINER_PARENT_ACCOUNT_ID
public static final short DEFAULT_PRIVATE_CONTAINER_PARENT_ACCOUNT_ID
The parent account id ofDEFAULT_PRIVATE_CONTAINER
.- See Also:
- Constant Field Values
-
UNKNOWN_CONTAINER
@Deprecated public static final Container UNKNOWN_CONTAINER
Deprecated.A container defined specifically for the blobs put without specifying target account and container. In the pre-containerization world, a put-blob request does not carry any information which account/container to store the blob. These blobs are literally put into this container, because the target container information is unknown. DO NOT USE IN PRODUCTION CODE.
-
DEFAULT_PUBLIC_CONTAINER
@Deprecated public static final Container DEFAULT_PUBLIC_CONTAINER
Deprecated.A container defined specifically for the blobs put without specifying target container but isPrivate flag is set tofalse
. DO NOT USE IN PRODUCTION CODE.
-
DEFAULT_PRIVATE_CONTAINER
@Deprecated public static final Container DEFAULT_PRIVATE_CONTAINER
Deprecated.A container defined specifically for the blobs put without specifying target container but isPrivate flag is set totrue
. DO NOT USE IN PRODUCTION CODE.
-
-
Method Detail
-
getCurrentJsonVersion
public static short getCurrentJsonVersion()
- Returns:
- the JSON version to serialize in.
-
setCurrentJsonVersion
public static void setCurrentJsonVersion(short currentJsonVersion)
Set the JSON version to serialize in. Note that this is a static setting that will affect allContainer
serialization.- Parameters:
currentJsonVersion
- the JSON version to serialize in.
-
fromJson
public static Container fromJson(org.json.JSONObject json, short parentAccountId) throws org.json.JSONException
Deserializes aJSONObject
to a container object.- Parameters:
json
- TheJSONObject
to deserialize.parentAccountId
- The ID of the parentAccount
of this container. This is passed in because it is not always included in the JSON record.- Returns:
- A container object deserialized from the
JSONObject
. - Throws:
org.json.JSONException
- If parsing theJSONObject
fails.
-
toJson
public org.json.JSONObject toJson() throws org.json.JSONException
Gets the metadata of the container.- Returns:
- The metadata of the container.
- Throws:
org.json.JSONException
- If fails to compose metadata.
-
getId
public short getId()
Gets the id of the container.- Returns:
- The id of the container.
-
getName
public java.lang.String getName()
Gets the name of the container.- Returns:
- The name of the container.
-
getStatus
public Container.ContainerStatus getStatus()
Gets the status of the container.- Returns:
- The status of the container.
-
getDeleteTriggerTime
public java.lang.Long getDeleteTriggerTime()
Gets the delete trigger time of the container.- Returns:
- The delete trigger time of the container.
-
getDescription
public java.lang.String getDescription()
Gets the description of the container.- Returns:
- The description of the container.
-
isEncrypted
public boolean isEncrypted()
- Returns:
true
if blobs in theContainer
should be encrypted,false
otherwise.
-
isBackupEnabled
public boolean isBackupEnabled()
- Returns:
true
if blobs in theContainer
should be backed up,false
otherwise.
-
wasPreviouslyEncrypted
public boolean wasPreviouslyEncrypted()
- Returns:
true
if thisContainer
was encrypted in the past, and a subset of blobs in it could still be encrypted.
-
isCacheable
public boolean isCacheable()
- Returns:
true
if cache control headers should be set to allow CDNs and browsers to cache blobs in this container.
-
isMediaScanDisabled
public boolean isMediaScanDisabled()
- Returns:
true
if media scans should be disabled on content created in this container.
-
getReplicationPolicy
public java.lang.String getReplicationPolicy()
- Returns:
- the replication policy desired by the container. Can be
null
if the container has no preference.
-
isTtlRequired
public boolean isTtlRequired()
- Returns:
true
if ttl is required on content created in this container.
-
getContentTypeWhitelistForFilenamesOnDownload
public java.util.Set<java.lang.String> getContentTypeWhitelistForFilenamesOnDownload()
- Returns:
- the set of content types for which the filename can be sent on download
-
isSecurePathRequired
public boolean isSecurePathRequired()
- Returns:
true
if secure path validation is required for url to access blobs in this container.
-
getParentAccountId
public short getParentAccountId()
Gets the if of theAccount
that owns this container.- Returns:
- The id of the parent
Account
of this container.
-
getLastModifiedTime
public long getLastModifiedTime()
Get the created/modified time of this Container- Returns:
- epoch time in milliseconds
-
getSnapshotVersion
public int getSnapshotVersion()
The snapshot version is generally the number of modifications to the container that were expected to have occurred before the current time. This is used to validate that there were no unexpected container modifications that could be inadvertently overwritten by an container update.- Returns:
- the expected version for the container record.
-
toString
public java.lang.String toString()
Generates a String representation that uniquely identifies this container. The string is in the format ofContainer[accountId:containerId]
.- Overrides:
toString
in classjava.lang.Object
- Returns:
- The String representation of this container.
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
-