megam_api 0.17 → 0.18
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +1 -1
- data/lib/megam/api.rb +20 -35
- data/lib/megam/api/{nodes.rb → assemblies.rb} +9 -9
- data/lib/megam/api/domains.rb +30 -0
- data/lib/megam/api/organizations.rb +30 -0
- data/lib/megam/api/version.rb +1 -1
- data/lib/megam/core/assemblies.rb +180 -0
- data/lib/megam/core/{node_collection.rb → assemblies_collection.rb} +44 -65
- data/lib/megam/core/csar.rb +0 -1
- data/lib/megam/core/domains.rb +129 -0
- data/lib/megam/core/json_compat.rb +17 -4
- data/lib/megam/core/organizations.rb +129 -0
- data/test/test_accounts.rb +1 -1
- data/test/test_assemblies.rb +10 -0
- data/test/test_domains.rb +27 -0
- data/test/test_helper.rb +25 -16
- data/test/test_organizations.rb +26 -0
- metadata +12 -38
- data/lib/megam/api/app_request.rb +0 -27
- data/lib/megam/api/appdefns.rb +0 -47
- data/lib/megam/api/bolt_request.rb +0 -27
- data/lib/megam/api/boltdefns.rb +0 -39
- data/lib/megam/api/cloud_tools.rb +0 -35
- data/lib/megam/api/logs.rb +0 -18
- data/lib/megam/api/predefs.rb +0 -35
- data/lib/megam/builder/delete_node.rb +0 -107
- data/lib/megam/builder/make_node.rb +0 -133
- data/lib/megam/core/app_request.rb +0 -227
- data/lib/megam/core/app_request_collection.rb +0 -148
- data/lib/megam/core/appdefns.rb +0 -182
- data/lib/megam/core/appdefns_collection.rb +0 -148
- data/lib/megam/core/bolt_request.rb +0 -225
- data/lib/megam/core/bolt_request_collection.rb +0 -148
- data/lib/megam/core/boltdefns.rb +0 -207
- data/lib/megam/core/boltdefns_collection.rb +0 -148
- data/lib/megam/core/cloudinstruction.rb +0 -110
- data/lib/megam/core/cloudinstruction_collection.rb +0 -145
- data/lib/megam/core/cloudinstruction_group.rb +0 -99
- data/lib/megam/core/cloudtemplate.rb +0 -127
- data/lib/megam/core/cloudtemplate_collection.rb +0 -145
- data/lib/megam/core/cloudtool.rb +0 -152
- data/lib/megam/core/cloudtool_collection.rb +0 -145
- data/lib/megam/core/node.rb +0 -366
- data/lib/megam/core/predef.rb +0 -201
- data/lib/megam/core/predef_collection.rb +0 -164
- data/test/test_appdefns.rb +0 -35
- data/test/test_appreqs.rb +0 -25
- data/test/test_boltdefns.rb +0 -32
- data/test/test_boltreqs.rb +0 -26
- data/test/test_cloudtools.rb +0 -22
- data/test/test_nodes.rb +0 -140
- data/test/test_predefs.rb +0 -72
@@ -14,36 +14,35 @@
|
|
14
14
|
# limitations under the License.
|
15
15
|
#
|
16
16
|
module Megam
|
17
|
-
class
|
17
|
+
class AssembliesCollection
|
18
18
|
include Enumerable
|
19
19
|
|
20
|
-
|
21
20
|
attr_reader :iterator
|
22
21
|
def initialize
|
23
|
-
@
|
24
|
-
@
|
22
|
+
@assemblies = Array.new
|
23
|
+
@assemblies_by_name = Hash.new
|
25
24
|
@insert_after_idx = nil
|
26
25
|
end
|
27
26
|
|
28
|
-
def
|
29
|
-
@
|
27
|
+
def all_assemblies
|
28
|
+
@assemblies
|
30
29
|
end
|
31
30
|
|
32
31
|
def [](index)
|
33
|
-
@
|
32
|
+
@assemblies[index]
|
34
33
|
end
|
35
34
|
|
36
35
|
def []=(index, arg)
|
37
|
-
|
38
|
-
@
|
39
|
-
@
|
36
|
+
is_megam_assemblies(arg)
|
37
|
+
@assemblies[index] = arg
|
38
|
+
@assemblies_by_name[arg.assembies_name] = index
|
40
39
|
end
|
41
40
|
|
42
41
|
def <<(*args)
|
43
42
|
args.flatten.each do |a|
|
44
|
-
|
45
|
-
@
|
46
|
-
@
|
43
|
+
is_megam_assemblies(a)
|
44
|
+
@assemblies << a
|
45
|
+
@assemblies_by_name[a.name] = @assemblies.length - 1
|
47
46
|
end
|
48
47
|
self
|
49
48
|
end
|
@@ -51,62 +50,62 @@ module Megam
|
|
51
50
|
# 'push' is an alias method to <<
|
52
51
|
alias_method :push, :<<
|
53
52
|
|
54
|
-
def insert(
|
55
|
-
|
53
|
+
def insert(assemblies)
|
54
|
+
is_megam_assemblies(assemblies)
|
56
55
|
if @insert_after_idx
|
57
56
|
# in the middle of executing a run, so any nodes inserted now should
|
58
57
|
# be placed after the most recent addition done by the currently executing
|
59
58
|
# node
|
60
|
-
@
|
59
|
+
@assemblies.insert(@insert_after_idx + 1, assemblies)
|
61
60
|
# update name -> location mappings and register new node
|
62
|
-
@
|
63
|
-
@
|
61
|
+
@assemblies_by_name.each_key do |key|
|
62
|
+
@assemblies_by_name[key] += 1 if @assemblies_by_name[key] > @insert_after_idx
|
64
63
|
end
|
65
|
-
@
|
64
|
+
@assemblies_by_name[assemblies.name] = @insert_after_idx + 1
|
66
65
|
@insert_after_idx += 1
|
67
66
|
else
|
68
|
-
@
|
69
|
-
@
|
67
|
+
@assemblies << assemblies
|
68
|
+
@assemblies_by_name[assemblies.name] = @assemblies.length - 1
|
70
69
|
end
|
71
70
|
end
|
72
71
|
|
73
72
|
def each
|
74
|
-
@
|
75
|
-
yield
|
73
|
+
@assemblies.each do |assemblies|
|
74
|
+
yield assemblies
|
76
75
|
end
|
77
76
|
end
|
78
77
|
|
79
78
|
def each_index
|
80
|
-
@
|
79
|
+
@assemblies.each_index do |i|
|
81
80
|
yield i
|
82
81
|
end
|
83
82
|
end
|
84
83
|
|
85
84
|
def empty?
|
86
|
-
@
|
85
|
+
@assemblies.empty?
|
87
86
|
end
|
88
87
|
|
89
|
-
def lookup(
|
88
|
+
def lookup(assemblies)
|
90
89
|
lookup_by = nil
|
91
|
-
if
|
92
|
-
lookup_by =
|
93
|
-
elsif
|
94
|
-
lookup_by =
|
90
|
+
if assemblies.kind_of?(Megam::Assemblies)
|
91
|
+
lookup_by = assemblies.name
|
92
|
+
elsif assemblies.kind_of?(String)
|
93
|
+
lookup_by = assemblies
|
95
94
|
else
|
96
|
-
raise ArgumentError, "Must pass a Megam::
|
95
|
+
raise ArgumentError, "Must pass a Megam::Assemblies or String to lookup"
|
97
96
|
end
|
98
|
-
res = @
|
97
|
+
res = @assemblies_by_name[lookup_by]
|
99
98
|
unless res
|
100
99
|
raise ArgumentError, "Cannot find a node matching #{lookup_by} (did you define it first?)"
|
101
100
|
end
|
102
|
-
@
|
101
|
+
@assemblies[res]
|
103
102
|
end
|
104
|
-
|
105
|
-
|
103
|
+
|
104
|
+
# Transform the ruby obj -> to a Hash
|
106
105
|
def to_hash
|
107
106
|
index_hash = Hash.new
|
108
|
-
self.each do |
|
109
|
-
index_hash[
|
107
|
+
self.each do |assemblies|
|
108
|
+
index_hash[assemblies.name] = assemblies.to_s
|
110
109
|
end
|
111
110
|
index_hash
|
112
111
|
end
|
@@ -117,31 +116,13 @@ module Megam
|
|
117
116
|
for_json.to_json(*a)
|
118
117
|
end
|
119
118
|
|
120
|
-
|
121
|
-
=begin
|
122
|
-
["json_claz":"Megam::NodeCollection",{
|
123
|
-
"id":"NOD362428315933343744",
|
124
|
-
"accounts_id":"ACT362211963352121344",
|
125
|
-
"json_claz":"Megam::Node",
|
126
|
-
"request":{
|
127
|
-
"req_id":"NOD362428315933343744",
|
128
|
-
"command":"commands"
|
129
|
-
},
|
130
|
-
"predefs":{
|
131
|
-
"name":"",
|
132
|
-
"scm":"",
|
133
|
-
"war":"",
|
134
|
-
"db":"",
|
135
|
-
"queue":""
|
136
|
-
}
|
137
|
-
}]
|
138
|
-
=end
|
139
119
|
def self.json_create(o)
|
140
120
|
collection = self.new()
|
141
|
-
o["results"].each do |
|
142
|
-
|
143
|
-
|
144
|
-
collection.insert(
|
121
|
+
o["results"].each do |assemblies_list|
|
122
|
+
assemblies_array = assemblies_list.kind_of?(Array) ? assemblies_list : [ assemblies_list ]
|
123
|
+
assemblies_array.each do |assemblies|
|
124
|
+
collection.insert(assemblies)
|
125
|
+
|
145
126
|
end
|
146
127
|
end
|
147
128
|
collection
|
@@ -149,11 +130,9 @@ module Megam
|
|
149
130
|
|
150
131
|
private
|
151
132
|
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
unless arg.kind_of?(Megam::Node)
|
156
|
-
raise ArgumentError, "Members must be Megam::Node's"
|
133
|
+
def is_megam_assemblies(arg)
|
134
|
+
unless arg.kind_of?(Megam::Assemblies)
|
135
|
+
raise ArgumentError, "Members must be Megam::Assemblies's"
|
157
136
|
end
|
158
137
|
true
|
159
138
|
end
|
data/lib/megam/core/csar.rb
CHANGED
@@ -0,0 +1,129 @@
|
|
1
|
+
# Copyright:: Copyright (c) 2012-2013 Megam Systems, Inc.
|
2
|
+
# License:: Apache License, Version 2.0
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#
|
16
|
+
|
17
|
+
module Megam
|
18
|
+
class Domains < Megam::ServerAPI
|
19
|
+
def initialize(email=nil, api_key=nil)
|
20
|
+
@id = nil
|
21
|
+
@name = nil
|
22
|
+
@created_at = nil
|
23
|
+
super(email, api_key)
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
def domain
|
28
|
+
self
|
29
|
+
end
|
30
|
+
|
31
|
+
def id(arg=nil)
|
32
|
+
if arg != nil
|
33
|
+
@id = arg
|
34
|
+
else
|
35
|
+
@id
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
def name(arg=nil)
|
42
|
+
if arg != nil
|
43
|
+
@name = arg
|
44
|
+
else
|
45
|
+
@name
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
def created_at(arg=nil)
|
52
|
+
if arg != nil
|
53
|
+
@created_at = arg
|
54
|
+
else
|
55
|
+
@created_at
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
# Transform the ruby obj -> to a Hash
|
62
|
+
def to_hash
|
63
|
+
index_hash = Hash.new
|
64
|
+
index_hash["json_claz"] = self.class.name
|
65
|
+
index_hash["id"] = id
|
66
|
+
index_hash["name"] = name
|
67
|
+
index_hash["created_at"] = created_at
|
68
|
+
index_hash
|
69
|
+
end
|
70
|
+
|
71
|
+
def to_json(*a)
|
72
|
+
for_json.to_json(*a)
|
73
|
+
end
|
74
|
+
|
75
|
+
def for_json
|
76
|
+
result = {
|
77
|
+
"id" => id,
|
78
|
+
"name" => name,
|
79
|
+
"created_at" => created_at
|
80
|
+
}
|
81
|
+
result
|
82
|
+
end
|
83
|
+
|
84
|
+
# Create a Megam::Domains from JSON (used by the backgroud job workers)
|
85
|
+
def self.json_create(o)
|
86
|
+
dmn = new
|
87
|
+
dmn.id(o["id"]) if o.has_key?("id")
|
88
|
+
dmn.name(o["name"]) if o.has_key?("name")
|
89
|
+
dmn.created_at(o["created_at"]) if o.has_key?("created_at")
|
90
|
+
dmn
|
91
|
+
end
|
92
|
+
|
93
|
+
def self.from_hash(o)
|
94
|
+
dmn = self.new(o[:email], o[:api_key])
|
95
|
+
dmn.from_hash(o)
|
96
|
+
dmn
|
97
|
+
end
|
98
|
+
|
99
|
+
def from_hash(o)
|
100
|
+
@id = o[:id] if o.has_key?(:id)
|
101
|
+
@name = o[:name] if o.has_key?(:name)
|
102
|
+
@created_at = o[:created_at] if o.has_key?(:created_at)
|
103
|
+
self
|
104
|
+
end
|
105
|
+
|
106
|
+
def self.create(o)
|
107
|
+
dmn = from_hash(o)
|
108
|
+
dmn.create
|
109
|
+
end
|
110
|
+
|
111
|
+
# Load a Domain by email_p
|
112
|
+
def self.show(email,api_key=nil)
|
113
|
+
dmn = self.new(email, api_key)
|
114
|
+
dmn.megam_rest.get_domains(email)
|
115
|
+
end
|
116
|
+
|
117
|
+
|
118
|
+
def create
|
119
|
+
megam_rest.post_domains(to_hash)
|
120
|
+
end
|
121
|
+
|
122
|
+
def to_s
|
123
|
+
Megam::Stuff.styled_hash(to_hash)
|
124
|
+
end
|
125
|
+
|
126
|
+
|
127
|
+
end
|
128
|
+
|
129
|
+
end
|
@@ -37,6 +37,10 @@ module Megam
|
|
37
37
|
MEGAM_BOLTDEFNSCOLLECTION = "Megam::BoltDefnCollection".freeze
|
38
38
|
MEGAM_REQUEST = "Megam::Request".freeze
|
39
39
|
MEGAM_REQUESTCOLLECTION = "Megam::RequestCollection".freeze
|
40
|
+
MEGAM_ORGANIZATION = "Megam::Organizations".freeze
|
41
|
+
MEGAM_DOMAIN = "Megam::Domains".freeze
|
42
|
+
MEGAM_ASSEMBLIES = "Megam::Assemblies".freeze
|
43
|
+
MEGAM_ASSEMBLIESCOLLECTION = "Megam::AssembliesCollection".freeze
|
40
44
|
|
41
45
|
MEGAM_PREDEF = "Megam::Predef".freeze
|
42
46
|
MEGAM_PREDEFCOLLECTION = "Megam::PredefCollection".freeze
|
@@ -59,9 +63,6 @@ module Megam
|
|
59
63
|
MEGAM_MARKETPLACEADDONCOLLECTION = "Megam::MarketPlaceAddonsCollection".freeze
|
60
64
|
MEGAM_CSAR = "Megam::CSAR".freeze
|
61
65
|
MEGAM_CSARCOLLECTION = "Megam::CSARCollection".freeze
|
62
|
-
|
63
|
-
|
64
|
-
|
65
66
|
class <<self
|
66
67
|
# Increase the max nesting for JSON, which defaults
|
67
68
|
# to 19, and isn't enough for some (for example, a Node within a Node)
|
@@ -77,6 +78,7 @@ module Megam
|
|
77
78
|
# Just call the JSON gem's parse method with a modified :max_nesting field
|
78
79
|
def from_json(source, opts = {})
|
79
80
|
obj = ::Yajl::Parser.parse(source)
|
81
|
+
|
80
82
|
# JSON gem requires top level object to be a Hash or Array (otherwise
|
81
83
|
# you get the "must contain two octets" error). Yajl doesn't impose the
|
82
84
|
# same limitation. For compatibility, we re-impose this condition.
|
@@ -98,16 +100,19 @@ module Megam
|
|
98
100
|
# Look at an object that's a basic type (from json parse) and convert it
|
99
101
|
# to an instance of Megam classes if desired.
|
100
102
|
def map_to_rb_obj(json_obj)
|
103
|
+
|
101
104
|
case json_obj
|
102
105
|
when Hash
|
103
106
|
mapped_hash = map_hash_to_rb_obj(json_obj)
|
107
|
+
|
104
108
|
if json_obj.has_key?(JSON_CLAZ) && (class_to_inflate = class_for_json_class(json_obj[JSON_CLAZ]))
|
105
109
|
class_to_inflate.json_create(mapped_hash)
|
110
|
+
|
106
111
|
else
|
107
112
|
mapped_hash
|
108
113
|
end
|
109
114
|
when Array
|
110
|
-
json_obj.map {|e| map_to_rb_obj(e)
|
115
|
+
json_obj.map {|e| map_to_rb_obj(e)}
|
111
116
|
else
|
112
117
|
json_obj
|
113
118
|
end
|
@@ -202,10 +207,18 @@ module Megam
|
|
202
207
|
Megam::MarketPlaceAddons
|
203
208
|
when MEGAM_MARKETPLACEADDONCOLLECTION
|
204
209
|
Megam::MarketPlaceAddonsCollection
|
210
|
+
when MEGAM_ORGANIZATION
|
211
|
+
Megam::Organizations
|
205
212
|
when MEGAM_CSAR
|
206
213
|
Megam::CSAR
|
207
214
|
when MEGAM_CSARCOLLECTION
|
208
215
|
Megam::CSARCollection
|
216
|
+
when MEGAM_DOMAIN
|
217
|
+
Megam::Organizations
|
218
|
+
when MEGAM_ASSEMBLIES
|
219
|
+
Megam::Assemblies
|
220
|
+
when MEGAM_ASSEMBLIESCOLLECTION
|
221
|
+
Megam::AssembliesCollection
|
209
222
|
else
|
210
223
|
raise JSON::ParserError, "Unsupported `json_class` type '#{json_class}'"
|
211
224
|
end
|
@@ -0,0 +1,129 @@
|
|
1
|
+
# Copyright:: Copyright (c) 2012-2013 Megam Systems, Inc.
|
2
|
+
# License:: Apache License, Version 2.0
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#
|
16
|
+
|
17
|
+
module Megam
|
18
|
+
class Organizations < Megam::ServerAPI
|
19
|
+
def initialize(email=nil, api_key=nil)
|
20
|
+
@id = nil
|
21
|
+
@name = nil
|
22
|
+
@created_at = nil
|
23
|
+
super(email, api_key)
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
def organization
|
28
|
+
self
|
29
|
+
end
|
30
|
+
|
31
|
+
def id(arg=nil)
|
32
|
+
if arg != nil
|
33
|
+
@id = arg
|
34
|
+
else
|
35
|
+
@id
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
def name(arg=nil)
|
42
|
+
if arg != nil
|
43
|
+
@name = arg
|
44
|
+
else
|
45
|
+
@name
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
def created_at(arg=nil)
|
52
|
+
if arg != nil
|
53
|
+
@created_at = arg
|
54
|
+
else
|
55
|
+
@created_at
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
# Transform the ruby obj -> to a Hash
|
62
|
+
def to_hash
|
63
|
+
index_hash = Hash.new
|
64
|
+
index_hash["json_claz"] = self.class.name
|
65
|
+
index_hash["id"] = id
|
66
|
+
index_hash["name"] = name
|
67
|
+
index_hash["created_at"] = created_at
|
68
|
+
index_hash
|
69
|
+
end
|
70
|
+
|
71
|
+
def to_json(*a)
|
72
|
+
for_json.to_json(*a)
|
73
|
+
end
|
74
|
+
|
75
|
+
def for_json
|
76
|
+
result = {
|
77
|
+
"id" => id,
|
78
|
+
"name" => name,
|
79
|
+
"created_at" => created_at
|
80
|
+
}
|
81
|
+
result
|
82
|
+
end
|
83
|
+
|
84
|
+
# Create a Megam::Organization from JSON (used by the backgroud job workers)
|
85
|
+
def self.json_create(o)
|
86
|
+
org = new
|
87
|
+
org.id(o["id"]) if o.has_key?("id")
|
88
|
+
org.name(o["name"]) if o.has_key?("name")
|
89
|
+
org.created_at(o["created_at"]) if o.has_key?("created_at")
|
90
|
+
org
|
91
|
+
end
|
92
|
+
|
93
|
+
def self.from_hash(o)
|
94
|
+
org = self.new(o[:email], o[:api_key])
|
95
|
+
org.from_hash(o)
|
96
|
+
org
|
97
|
+
end
|
98
|
+
|
99
|
+
def from_hash(o)
|
100
|
+
@id = o[:id] if o.has_key?(:id)
|
101
|
+
@name = o[:name] if o.has_key?(:name)
|
102
|
+
@created_at = o[:created_at] if o.has_key?(:created_at)
|
103
|
+
self
|
104
|
+
end
|
105
|
+
|
106
|
+
def self.create(o)
|
107
|
+
org = from_hash(o)
|
108
|
+
org.create
|
109
|
+
end
|
110
|
+
|
111
|
+
# Load a organization by email_p
|
112
|
+
def self.show(email,api_key=nil)
|
113
|
+
org = self.new(email, api_key)
|
114
|
+
org.megam_rest.get_organizations(email)
|
115
|
+
end
|
116
|
+
|
117
|
+
|
118
|
+
def create
|
119
|
+
megam_rest.post_organizations(to_hash)
|
120
|
+
end
|
121
|
+
|
122
|
+
def to_s
|
123
|
+
Megam::Stuff.styled_hash(to_hash)
|
124
|
+
end
|
125
|
+
|
126
|
+
|
127
|
+
end
|
128
|
+
|
129
|
+
end
|