class Atmos::Metadata
Metadata¶ ↑
In all cases, metadata
refers to key/value pairs, and is
represented as a ruby Hash attached to an Atmos::Object object.
Standard Metadata¶ ↑
In Atmos, metadata
with no
modifier (e.g. listable
or system
) refers to
metadata on an object that is not indexed. In other words, objects cannot
be referenced by the metadata information. The only way to get this
metadata information is to already have the object the metadata is attached
to.
Defaults¶ ↑
By default, when you create an object, there is no metadata. So:
obj.metadata => {}
Adding ¶ ↑
Add metadata in key/value pairs as you would to a hash. Keys and values must be ruby Strings.
obj.metadata[key] = value obj.metadata.store(key, value) obj.metadata.merge!({key => value})
Modifying¶ ↑
Modify metadata as you would a hash. Keys and values must be ruby Strings.
obj.metadata[pre-existing-key] = new-value obj.metadata.store(pre-existing-key, new-value) obj.metadata.merge!({pre-existing-key => new-value})
Deleting¶ ↑
Delete metadata as you would a hash. Keys must be ruby Strings.
obj.metadata.delete(key) obj.metadata.clear
Listable Metadata¶ ↑
Listable metadata means atmos indexes the object by the key in the key/value metadata pair. The keys of listable metadata are also known as listable tags. Currently, an Atmos server can handle about 10k listable tags easily, so use judiciously with very large datasets.
Defaults¶ ↑
By default, when you create an object, there is no listable metadata. So:
obj.listable_metadata => {}
Adding ¶ ↑
Add metadata in key/value pairs as you would to a hash. Keys and values must be ruby Strings.
obj.listable_metadata[key] = value obj.listable_metadata.store(key, value) obj.listable_metadata.merge!({key => value})
Modifying¶ ↑
Modify metadata as you would a hash. Keys and values must be ruby Strings.
obj.listable_metadata[pre-existing-key] = new-value obj.listable_metadata.store(pre-existing-key, new-value) obj.listable_metadata.merge!({pre-existing-key => new-value})
Deleting¶ ↑
Delete metadata as you would a hash. Keys must be ruby Strings.
obj.listable_metadata.delete(key) obj.listable_metadata.clear
System Metadata¶ ↑
System metadata is a standard group of information maintained by Atmos for each object, such as atime
,
mtime
, type
, policyname
.
System metadata is not modifiable.
Constants
- LISTABLE
- NON_LISTABLE
- SYSTEM
Public Class Methods
This constructor is only meant for internal use. To get the metadata on an object:
obj.metadata => Hash obj.listable_metadata => Hash obj.system_metadata => Hash
# File lib/atmos/attributes.rb, line 422 def initialize(obj, type) raise Atmos::Exceptions::ArgumentException, "The 'obj' parameter cannot be nil." if (obj.nil?) raise Atmos::Exceptions::ArgumentException, "The 'obj' parameter must have an id." if (obj.aoid.nil?) raise Atmos::Exceptions::ArgumentException, "The 'type' parameter must be one of Atmos::Metadata::LISTABLE Atmos::Metadata::NON_LISTABLE Atmos::Metadata::SYSTEM." if (![SYSTEM, LISTABLE, NON_LISTABLE].include?(type)) super() @obj = obj @type = type @header = (@type == LISTABLE) ? 'x-emc-listable-meta' : 'x-emc-meta' @reload_action = (@type == SYSTEM) ? :list_system_metadata : :list_metadata @set_action = (@type == LISTABLE) ? :set_listable_metadata : :set_metadata reload(@reload_action, @obj.aoid) end
Public Instance Methods
Adds the specified metadata to the object unless the object is representing system metadata.
System metadata cannot be modified, so an Atmos::Exceptions::NotImplementedException is thrown.
The change is made on the Atmos server immediately.
# File lib/atmos/attributes.rb, line 448 def []=(key,value) raise Atmos::Exceptions::NotImplementedException, "System metadata cannot be modified." if (@type == SYSTEM) raise Atmos::Exceptions::ArgumentException, "The 'value' parameter must be of type String'." if (!value.nil? && !value.kind_of?(String)) response = @obj.request.do(@set_action, :id => @obj.aoid, @header => "#{key}=#{value}") reload(@reload_action, @obj.aoid) end
Deletes all metadata from the object unless the object is representing system metadata.
System metadata cannot be modified, so an Atmos::Exceptions::NotImplementedException is thrown.
The change is made on the Atmos server immediately.
# File lib/atmos/attributes.rb, line 464 def clear raise Atmos::Exceptions::NotImplementedException, "System metadata cannot be modified." if (@type == SYSTEM) reload(@reload_action, @obj.aoid) response = @obj.request.do(:delete_metadata, :id => @obj.aoid, 'x-emc-tags' => self.keys.join(',')) self.clear_without_atmos reload(@reload_action, @obj.aoid) end
Deletes the specified metadata from the object unless the object is
representing system metadata. System metadata cannot be modified, so an
Atmos::Exceptions::NotImplementedException
is thrown.
The deleted is executed on the Atmos server immediately.
Required:
*<tt>key</tt> -
# File lib/atmos/attributes.rb, line 483 def delete(key) raise Atmos::Exceptions::NotImplementedException, "System metadata cannot be modified." if (@type == SYSTEM) response = @obj.request.do(:delete_metadata, :id => @obj.aoid, 'x-emc-tags' => key) self.delete_without_atmos(key) reload(@reload_action, @obj.aoid) end
Returns true
if this Metadata
object is representing listable metadata.
# File lib/atmos/attributes.rb, line 494 def listable? @type == LISTABLE end
Returns true
if this Metadata
object is representing non-listable metadata.
# File lib/atmos/attributes.rb, line 502 def non_listable? @type == NON_LISTABLE end
Returns true
if this Metadata
object is representing system metadata.
# File lib/atmos/attributes.rb, line 510 def system? @type == SYSTEM end
Private Instance Methods
This method is defined to override AttributeHashBase.validate_input_hash, which simply returns true. This allows the base class to contain the method definitions for several standard Hash functions, yet allows the validation to be specialized for each subclass.
Required: *h
- the hash to validate
# File lib/atmos/attributes.rb, line 525 def validate_input_hash(h) msg = nil bad_keys = [] bad_values = [] good_values = [:none, :read, :write, :full] h.each do |k,v| bad_keys.push(k) if (k.nil? || !k.kind_of?(String)) bad_values.push(v) if (v.nil? || !good_values.include?(v)) end msg = "The input has was bad: " if (!bad_keys.empty? || !bad_values.empty?) msg += "bad keys: #{bad_keys.inspect} " if (!bad_keys.empty?) msg += "bad values: #{bad_values.inspect}" if (!bad_values.empty?) raise Atmos::Exceptions::ArgumentException, msg if (!msg.nil?) end