Class: Megam::Appdefns

Inherits:
Object
  • Object
show all
Defined in:
lib/megam/core/appdefns.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeAppdefns

def self.hash_tree Hash.new do |hash, key| hash = hash_tree end end



28
29
30
31
32
33
34
# File 'lib/megam/core/appdefns.rb', line 28

def initialize
  @id = nil
  @node_id = nil
  @node_name = nil
  @appdefns ={}
  @created_at = nil
end

Class Method Details

.create(o) ⇒ Object



170
171
172
173
# File 'lib/megam/core/appdefns.rb', line 170

def self.create(o)
  acct = from_hash(o)
  acct.create
end

.from_hash(o) ⇒ Object



155
156
157
158
159
# File 'lib/megam/core/appdefns.rb', line 155

def self.from_hash(o)
  node = self.new()
  node.from_hash(o)
  node
end

.json_create(o) ⇒ Object

Create a Megam::Node from NodeResult-JSON

[{ "id":"NOD362212018897289216", "accounts_id":"ACT362211962353876992", "json_claz":"Megam::Node", "request":{ "req_id":"NOD362212018897289216", "command":"commands" }, "predefs":{ "name":"", "scm":"", "war":"", "db":"", "queue":"" } }]



139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/megam/core/appdefns.rb', line 139

def self.json_create(o)
  node = new
  node.id(o["id"]) if o.has_key?("id")
  node.node_id(o["node_id"]) if o.has_key?("node_id")
  node.node_name(o["node_name"]) if o.has_key?("node_name")
  node.created_at(o["created_at"]) if o.has_key?("created_at")

  #APP DEFINITIONS
  op = o["appdefns"]
  node.appdefns[:timetokill] = op["timetokill"] if op && op.has_key?("timetokill")
  node.appdefns[:metered] = op["metered"] if op && op.has_key?("metered")
  node.appdefns[:logging]= op["logging"] if op && op.has_key?("logging")
  node.appdefns[:runtime_exec] = op["runtime_exec"] if op && op.has_key?("runtime_exec")
  node
end

.show(node_name) ⇒ Object

Load a account by email_p



181
182
183
184
# File 'lib/megam/core/appdefns.rb', line 181

def self.show(node_name)
  megam_rest.get_appdefn(node_name)
  self
end

Instance Method Details

#appdefns(arg = nil) ⇒ Object



68
69
70
71
72
73
74
# File 'lib/megam/core/appdefns.rb', line 68

def appdefns(arg=nil)
  if arg != nil
    @appdefns = arg
  else
  @appdefns
  end
end

#createObject

Create the node via the REST API



176
177
178
# File 'lib/megam/core/appdefns.rb', line 176

def create
  megam_rest.post_appdefn(to_hash)
end

#created_at(arg = nil) ⇒ Object



77
78
79
80
81
82
83
# File 'lib/megam/core/appdefns.rb', line 77

def created_at(arg=nil)
  if arg != nil
    @created_at = arg
  else
  @created_at
  end
end

#error?Boolean

Returns:

  • (Boolean)


85
86
87
# File 'lib/megam/core/appdefns.rb', line 85

def error?
  crocked  = true if (some_msg.has_key?(:msg_type) && some_msg[:msg_type] == "error")
end

#for_jsonObject



109
110
111
112
113
114
115
116
117
118
# File 'lib/megam/core/appdefns.rb', line 109

def for_json
  result = {
    "id" => id,
    "node_id" => node_id,
    "node_name" => node_name,
    "appdefns" => appdefns,
    "created_at" => created_at
  }
  result
end

#from_hash(o) ⇒ Object



161
162
163
164
165
166
167
168
# File 'lib/megam/core/appdefns.rb', line 161

def from_hash(o)
  @id        = o["id"] if o.has_key?("id")
  @node_id    = o["node_id"] if o.has_key?("node_id")
  @node_name = o["node_name"] if o.has_key?("node_name")
  @appdefns   = o["appdefns"] if o.has_key?("appdefns")
  @created_at        = o["created_at"] if o.has_key?("created_at")
  self
end

#id(arg = nil) ⇒ Object



44
45
46
47
48
49
50
# File 'lib/megam/core/appdefns.rb', line 44

def id(arg=nil)
  if arg != nil
    @id = arg
  else
  @id
  end
end

#megam_restObject



39
40
41
42
# File 'lib/megam/core/appdefns.rb', line 39

def megam_rest
  options = { :email => Megam::Config[:email], :api_key => Megam::Config[:api_key]}
  Megam::API.new(options)
end

#nodeObject



35
36
37
# File 'lib/megam/core/appdefns.rb', line 35

def node
  self
end

#node_id(arg = nil) ⇒ Object



52
53
54
55
56
57
58
# File 'lib/megam/core/appdefns.rb', line 52

def node_id(arg=nil)
  if arg != nil
    @node_id = arg
  else
  @node_id
  end
end

#node_name(arg = nil) ⇒ Object



60
61
62
63
64
65
66
# File 'lib/megam/core/appdefns.rb', line 60

def node_name(arg=nil)
  if arg != nil
    @node_name = arg
  else
  @node_name
  end
end

#to_hashObject

Transform the ruby obj -> to a Hash



90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/megam/core/appdefns.rb', line 90

def to_hash
puts "===================> CLASS NAME ====================================="
puts self.class.name
  index_hash = Hash.new
  index_hash["json_claz"] = self.class.name
  index_hash["id"] = id
  index_hash["node_id"] = node_id
  index_hash["node_name"] = node_name
  index_hash["appdefns"] = appdefns
  index_hash["created_at"] = created_at
  index_hash
end

#to_json(*a) ⇒ Object

Serialize this object as a hash: called from JsonCompat. Verify if this called from JsonCompat during testing.



105
106
107
# File 'lib/megam/core/appdefns.rb', line 105

def to_json(*a)
  for_json.to_json(*a)
end

#to_sObject



186
187
188
189
# File 'lib/megam/core/appdefns.rb', line 186

def to_s
  Megam::Stuff.styled_hash(to_hash)
#"---> Megam::Account:[error=#{error?}]\n"+
end