Class: SdbS3Env::GlueEnv
- Inherits:
-
Object
- Object
- SdbS3Env::GlueEnv
- Defined in:
- lib/glue_envs/sdb_s3_glue_env.rb
Constant Summary collapse
- VersionKey =
PersistLayerKey not needed, node key can be used as persistent layer key see mysql_glue_env to decouple persistent layer key from node key
:_rev
- NamespaceKey =
to have timestamp
:sdbs3_namespace
- @@log =
TinkitLog.set(self.name, :warn)
Instance Attribute Summary collapse
-
#_files_mgr_class ⇒ Object
TODO: Rather than using File class directly, should a special class be used? <- still applicable?.
-
#metadata_keys ⇒ Object
TODO: Rather than using File class directly, should a special class be used? <- still applicable?.
-
#moab_data ⇒ Object
TODO: Rather than using File class directly, should a special class be used? <- still applicable?.
-
#model_key ⇒ Object
TODO: Rather than using File class directly, should a special class be used? <- still applicable?.
-
#model_save_params ⇒ Object
TODO: Rather than using File class directly, should a special class be used? <- still applicable?.
-
#namespace_key ⇒ Object
TODO: Rather than using File class directly, should a special class be used? <- still applicable?.
-
#node_key ⇒ Object
TODO: Rather than using File class directly, should a special class be used? <- still applicable?.
-
#persist_layer_key ⇒ Object
TODO: Rather than using File class directly, should a special class be used? <- still applicable?.
-
#required_instance_keys ⇒ Object
TODO: Rather than using File class directly, should a special class be used? <- still applicable?.
-
#required_save_keys ⇒ Object
TODO: Rather than using File class directly, should a special class be used? <- still applicable?.
-
#user_datastore_location ⇒ Object
TODO: Rather than using File class directly, should a special class be used? <- still applicable?.
-
#user_id ⇒ Object
TODO: Rather than using File class directly, should a special class be used? <- still applicable?.
-
#version_key ⇒ Object
TODO: Rather than using File class directly, should a special class be used? <- still applicable?.
-
#views ⇒ Object
TODO: Rather than using File class directly, should a special class be used? <- still applicable?.
Instance Method Summary collapse
- #destroy_bulk(list_of_native_records) ⇒ Object
- #destroy_node(model_metadata) ⇒ Object
- #find_contains(key, this_value) ⇒ Object
- #find_contains_type_helper(stored_data, this_value) ⇒ Object
- #find_equals(key, this_value) ⇒ Object
-
#find_nodes_where(key, relation, this_value) ⇒ Object
current relations supported: - :equals (data in the key field matches this_value) - :contains (this_value is contained in the key field data (same as equals for non-enumerable types ).
-
#generate_model_key(namespace, node_key) ⇒ Object
namespace is used to distinguish between unique data sets (i.e., users) within the model, for sdb, each user has their own domain, so the key only has to be unique within the domain.
- #get(id) ⇒ Object
-
#initialize(persist_env, data_model_bindings) ⇒ GlueEnv
constructor
A new instance of GlueEnv.
-
#query_all ⇒ Object
TODO move to ViewsMgr.
- #raw_all ⇒ Object
- #save(new_data) ⇒ Object
Constructor Details
#initialize(persist_env, data_model_bindings) ⇒ GlueEnv
Returns a new instance of GlueEnv.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/glue_envs/sdb_s3_glue_env.rb', line 45 def initialize(persist_env, data_model_bindings) #TODO: determine if class_name is needed to segment cluster data within user data #host = "https://sdb.amazonaws.com/" (not provided by user) #user_id = env[:user_id] sdb_s3_env = persist_env[:env] #TODO: validations on format domain_base_name = sdb_s3_env[:path] @user_id = sdb_s3_env[:user_id] @cluster_name = persist_env[:name] #data_model_bindings from NodeElementOperations key_fields = data_model_bindings[:key_fields] initial_views_data = data_model_bindings[:views] @required_instance_keys = key_fields[:required_keys] #DataStructureModels::Tinkit::RequiredInstanceKeys @required_save_keys = key_fields[:required_keys] #DataStructureModels::Tinkit::RequiredSaveKeys @node_key = key_fields[:primary_key] #DataStructureModels::Tinkit::NodeKey @persist_layer_key = @node_key #@moab_datastore_name = MoabDatastoreName @version_key = VersionKey @model_key = @node_key #ModelKey @namespace_key = NamespaceKey @metadata_keys = [@version_key, @namespace_key] aak = ENV["AMAZON_ACCESS_KEY_ID"] asak = ENV["AMAZON_SECRET_ACCESS_KEY"] #rightaws_log = TinkitLog.set("RightAWS::SDBInterface", :warn) #sdb = RightAws::SdbInterface.new(aak, asak, :logger => rightaws_log, :multi_thread => true) sdb = AwsSdb::Service.new #aws-sdb @user_datastore_location = use_domain!(sdb, "#{domain_base_name}__#{@user_id}") @model_save_params = {:sdb => sdb, :domain => user_datastore_location, :node_key => @node_key} @_files_mgr_class = SdbS3Interface::FilesMgr @views = "temp" @moab_data = {} #@views_mgr = ViewsMgr.new({:data_file => @data_file_name}) #@record_locker = {} #tracks records that are in the process of being saved end |
Instance Attribute Details
#_files_mgr_class ⇒ Object
TODO: Rather than using File class directly, should a special class be used? <- still applicable?
27 28 29 |
# File 'lib/glue_envs/sdb_s3_glue_env.rb', line 27 def _files_mgr_class @_files_mgr_class end |
#metadata_keys ⇒ Object
TODO: Rather than using File class directly, should a special class be used? <- still applicable?
27 28 29 |
# File 'lib/glue_envs/sdb_s3_glue_env.rb', line 27 def @metadata_keys end |
#moab_data ⇒ Object
TODO: Rather than using File class directly, should a special class be used? <- still applicable?
27 28 29 |
# File 'lib/glue_envs/sdb_s3_glue_env.rb', line 27 def moab_data @moab_data end |
#model_key ⇒ Object
TODO: Rather than using File class directly, should a special class be used? <- still applicable?
27 28 29 |
# File 'lib/glue_envs/sdb_s3_glue_env.rb', line 27 def model_key @model_key end |
#model_save_params ⇒ Object
TODO: Rather than using File class directly, should a special class be used? <- still applicable?
27 28 29 |
# File 'lib/glue_envs/sdb_s3_glue_env.rb', line 27 def model_save_params @model_save_params end |
#namespace_key ⇒ Object
TODO: Rather than using File class directly, should a special class be used? <- still applicable?
27 28 29 |
# File 'lib/glue_envs/sdb_s3_glue_env.rb', line 27 def namespace_key @namespace_key end |
#node_key ⇒ Object
TODO: Rather than using File class directly, should a special class be used? <- still applicable?
27 28 29 |
# File 'lib/glue_envs/sdb_s3_glue_env.rb', line 27 def node_key @node_key end |
#persist_layer_key ⇒ Object
TODO: Rather than using File class directly, should a special class be used? <- still applicable?
27 28 29 |
# File 'lib/glue_envs/sdb_s3_glue_env.rb', line 27 def persist_layer_key @persist_layer_key end |
#required_instance_keys ⇒ Object
TODO: Rather than using File class directly, should a special class be used? <- still applicable?
27 28 29 |
# File 'lib/glue_envs/sdb_s3_glue_env.rb', line 27 def required_instance_keys @required_instance_keys end |
#required_save_keys ⇒ Object
TODO: Rather than using File class directly, should a special class be used? <- still applicable?
27 28 29 |
# File 'lib/glue_envs/sdb_s3_glue_env.rb', line 27 def required_save_keys @required_save_keys end |
#user_datastore_location ⇒ Object
TODO: Rather than using File class directly, should a special class be used? <- still applicable?
27 28 29 |
# File 'lib/glue_envs/sdb_s3_glue_env.rb', line 27 def user_datastore_location @user_datastore_location end |
#user_id ⇒ Object
TODO: Rather than using File class directly, should a special class be used? <- still applicable?
27 28 29 |
# File 'lib/glue_envs/sdb_s3_glue_env.rb', line 27 def user_id @user_id end |
#version_key ⇒ Object
TODO: Rather than using File class directly, should a special class be used? <- still applicable?
27 28 29 |
# File 'lib/glue_envs/sdb_s3_glue_env.rb', line 27 def version_key @version_key end |
#views ⇒ Object
TODO: Rather than using File class directly, should a special class be used? <- still applicable?
27 28 29 |
# File 'lib/glue_envs/sdb_s3_glue_env.rb', line 27 def views @views end |
Instance Method Details
#destroy_bulk(list_of_native_records) ⇒ Object
189 190 191 192 193 194 195 196 197 198 |
# File 'lib/glue_envs/sdb_s3_glue_env.rb', line 189 def destroy_bulk(list_of_native_records) sdb = @model_save_params[:sdb] domain = @model_save_params[:domain] node_key = @model_save_params[:node_key] list_of_native_records.each do |rcd| item_name = rcd[node_key] #TODO: use the batch delete request sdb.delete_attributes(domain, item_name) end end |
#destroy_node(model_metadata) ⇒ Object
168 169 170 171 172 173 174 175 |
# File 'lib/glue_envs/sdb_s3_glue_env.rb', line 168 def destroy_node() sdb = @model_save_params[:sdb] domain = @model_save_params[:domain] #node_key = @model_save_params[:node_key] item_name = [@model_key] @@log.info {"Deleting node: #{.inspect} with key #{item_name} from domain: #{domain}"} if @@log.info? sdb.delete_attributes(domain, item_name) end |
#find_contains(key, this_value) ⇒ Object
119 120 121 122 123 124 125 126 127 128 |
# File 'lib/glue_envs/sdb_s3_glue_env.rb', line 119 def find_contains(key, this_value) #there is probably an optimized way to do this natively #in sdb's pseodo sql, but I can't figure it out results =[] query_all.each do |record| test_val = record[key] results << record if find_contains_type_helper(test_val, this_value) end results end |
#find_contains_type_helper(stored_data, this_value) ⇒ Object
130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/glue_envs/sdb_s3_glue_env.rb', line 130 def find_contains_type_helper(stored_data, this_value) #p stored_dataj resp = nil #stored_data = jparse(stored_dataj) if stored_data.respond_to?(:"include?") resp = (stored_data.include?(this_value)) else resp = (stored_data == this_value) end return resp end |
#find_equals(key, this_value) ⇒ Object
110 111 112 113 114 115 116 117 |
# File 'lib/glue_envs/sdb_s3_glue_env.rb', line 110 def find_equals(key, this_value) results =[] query_all.each do |record| test_val = record[key] results << record if test_val == this_value end results end |
#find_nodes_where(key, relation, this_value) ⇒ Object
current relations supported:
-
:equals (data in the key field matches this_value)
-
:contains (this_value is contained in the key field data (same as equals for non-enumerable types )
100 101 102 103 104 105 106 107 108 |
# File 'lib/glue_envs/sdb_s3_glue_env.rb', line 100 def find_nodes_where(key, relation, this_value) res = case relation when :equals find_equals(key, this_value) when :contains find_contains(key, this_value) end #case return res end |
#generate_model_key(namespace, node_key) ⇒ Object
namespace is used to distinguish between unique data sets (i.e., users) within the model, for sdb, each user has their own domain, so the key only has to be unique within the domain
180 181 182 183 |
# File 'lib/glue_envs/sdb_s3_glue_env.rb', line 180 def generate_model_key(namespace, node_key) "#{node_key}" #"#{namespace}::#{node_key}" end |
#get(id) ⇒ Object
142 143 144 145 146 147 148 149 150 |
# File 'lib/glue_envs/sdb_s3_glue_env.rb', line 142 def get(id) sdb = @model_save_params[:sdb] domain = @model_save_params[:domain] raw_data = sdb.get_attributes(domain, id) #puts "Raw Data: #{raw_data.inspect}" data = from_sdb(raw_data) data = nil if data.empty? return data end |
#query_all ⇒ Object
TODO move to ViewsMgr
83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/glue_envs/sdb_s3_glue_env.rb', line 83 def query_all #TODO move to ViewsMgr sdb = @model_save_params[:sdb] domain = @model_save_params[:domain] query = "select * from `#{domain}`" raw_data = sdb.select(query).first data = {} #puts "QA Raw: #{raw_data.inspect}" raw_data.each do |k,v| data[k] = from_sdb(v) end @@log.info{"Query All data: #{data.values}"} if @@log.info? data.values end |
#raw_all ⇒ Object
185 186 187 |
# File 'lib/glue_envs/sdb_s3_glue_env.rb', line 185 def raw_all query_all end |
#save(new_data) ⇒ Object
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/glue_envs/sdb_s3_glue_env.rb', line 152 def save(new_data) sdb = @model_save_params[:sdb] domain = @model_save_params[:domain] #although we could pull @node_key directly, I do it this way to make it clear #that it's a parameter used in saving to the persistence model #I should try to be consistent on this node_key = @model_save_params[:node_key] rev_data = new_data.dup rev_data[@version_key] = Time.now.hash raw_model_data = HashKeys.sym_to_str(rev_data) model_data = to_sdb(raw_model_data) sdb.put_attributes(domain, new_data[node_key], model_data) raw_model_data['rev'] = raw_model_data[@version_key] return raw_model_data end |