pipe_fitter 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/pipe_fitter/data_pipeline_client.rb +2 -2
- data/lib/pipe_fitter/pipeline.rb +160 -70
- data/lib/pipe_fitter/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d7fb6064d720bceb50a5f67593a34d8ab88e0265
|
4
|
+
data.tar.gz: 42ad10d0a56aa467273b792ba3e96d0940a2e6a6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 80191b605a9a17ae25820fbf1a0ab4baa5908e009d8fb96e11b9ad8a1e5bb85d9873e221cd01ebde4ec4b5d912b918df106b1eb9db6fbe5f0b37e7a13c329633
|
7
|
+
data.tar.gz: a4a95adea95583151321ef7eef80f773f0052573f25a7c66abb06e6b1574c07ada735d9b50243876cd9f8a1374b0ee08e5dfd6d97d028f9e7a99a60279b71e3d
|
@@ -26,7 +26,7 @@ module PipeFitter
|
|
26
26
|
def definition(pipeline_id)
|
27
27
|
res = exec(:get_pipeline_definition, pipeline_id: pipeline_id)
|
28
28
|
desc = description(pipeline_id)
|
29
|
-
Pipeline.
|
29
|
+
Pipeline.create(res.to_h, desc.to_h)
|
30
30
|
end
|
31
31
|
|
32
32
|
def put_definition(pipeline_id, pipeline)
|
@@ -55,7 +55,7 @@ module PipeFitter
|
|
55
55
|
def sync_tags(pipeline_id, pipeline)
|
56
56
|
p = definition(pipeline_id)
|
57
57
|
return if p.tags == pipeline.tags
|
58
|
-
exec(:remove_tags, p.remove_tags_opts) unless p.tags.empty?
|
58
|
+
exec(:remove_tags, p.remove_tags_opts(pipeline_id)) unless p.tags.empty?
|
59
59
|
exec(:add_tags, pipeline.add_tags_opts(pipeline_id)) unless pipeline.tags.empty?
|
60
60
|
end
|
61
61
|
|
data/lib/pipe_fitter/pipeline.rb
CHANGED
@@ -5,108 +5,198 @@ require "pathname"
|
|
5
5
|
|
6
6
|
module PipeFitter
|
7
7
|
class Pipeline
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
Pipeline.new(definition, desc)
|
14
|
-
end
|
8
|
+
def self.create(definition_from_api, description_from_api)
|
9
|
+
new(PipelineObjects.create(definition_from_api[:pipeline_objects]),
|
10
|
+
ParameterObjects.create(definition_from_api[:parameter_objects]),
|
11
|
+
ParameterValues.create(definition_from_api[:parameter_values]),
|
12
|
+
PipelineDescription.create(description_from_api))
|
15
13
|
end
|
16
14
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
h.unique_id ||= f[:string_value]
|
25
|
-
end
|
26
|
-
end
|
27
|
-
@description = Hashie::Mash.new(@full_description.select { |k, v| DESCRIPTION_KEYS.include?(k) && !v.nil? })
|
15
|
+
def self.load_yaml(filename)
|
16
|
+
filepath = Pathname.new(filename)
|
17
|
+
yml = YamlLoader.load(filepath)
|
18
|
+
new(PipelineObjects.new(yml["pipeline_objects"]),
|
19
|
+
ParameterObjects.new(yml["parameter_objects"]),
|
20
|
+
ParameterValues.new(yml["parameter_values"]),
|
21
|
+
PipelineDescription.new(yml["pipeline_description"]))
|
28
22
|
end
|
29
23
|
|
30
|
-
def
|
31
|
-
|
24
|
+
def initialize(pipeline_objects, parameter_objects, parameter_values, pipeline_description)
|
25
|
+
@pipeline_objects = pipeline_objects
|
26
|
+
@parameter_objects = parameter_objects
|
27
|
+
@parameter_values = parameter_values
|
28
|
+
@pipeline_description = pipeline_description
|
32
29
|
end
|
33
30
|
|
34
|
-
def
|
35
|
-
|
31
|
+
def tags
|
32
|
+
@pipeline_description.tags
|
36
33
|
end
|
37
34
|
|
38
|
-
def
|
39
|
-
|
40
|
-
|
35
|
+
def to_yaml
|
36
|
+
{
|
37
|
+
"pipeline_description" => @pipeline_description.to_objs,
|
38
|
+
"pipeline_objects" => @pipeline_objects.to_objs,
|
39
|
+
"parameter_objects" => @parameter_objects.to_objs,
|
40
|
+
"parameter_values" => @parameter_values.to_objs,
|
41
|
+
}.to_yaml
|
41
42
|
end
|
42
43
|
|
43
|
-
def
|
44
|
-
{
|
44
|
+
def put_definition_opts(pipeline_id)
|
45
|
+
{
|
46
|
+
pipeline_id: pipeline_id,
|
47
|
+
pipeline_objects: @pipeline_objects.to_api_opts,
|
48
|
+
parameter_objects: @parameter_objects.to_api_opts,
|
49
|
+
parameter_values: @parameter_values.to_api_opts,
|
50
|
+
}
|
45
51
|
end
|
46
52
|
|
47
|
-
def
|
48
|
-
{ pipeline_id:
|
53
|
+
def add_tags_opts(pipeline_id)
|
54
|
+
{ pipeline_id: pipeline_id, tags: @pipeline_description.tags_opts }
|
49
55
|
end
|
50
56
|
|
51
|
-
def
|
52
|
-
|
53
|
-
{ pipeline_id: id || pipeline_id, parameter_values: pv, start_timestamp: start_timestamp }.select { |_, v| !v.nil? }
|
57
|
+
def remove_tags_opts(pipeline_id)
|
58
|
+
{ pipeline_id: pipeline_id, tag_keys: @pipeline_description.tag_keys }
|
54
59
|
end
|
55
60
|
|
56
|
-
def
|
57
|
-
|
61
|
+
def diff(other, format = nil)
|
62
|
+
Diffy::Diff.new(self.to_yaml, other.to_yaml).to_s(format)
|
58
63
|
end
|
59
64
|
|
60
|
-
|
61
|
-
|
62
|
-
|
65
|
+
class PipelineBaseObjects
|
66
|
+
def initialize(objs)
|
67
|
+
@objs = case objs
|
68
|
+
when Array then objs.map { |obj| symbolize_keys(obj) }
|
69
|
+
else symbolize_keys(objs) || {}
|
70
|
+
end
|
71
|
+
end
|
63
72
|
|
64
|
-
|
65
|
-
|
66
|
-
|
73
|
+
def to_objs
|
74
|
+
case @objs
|
75
|
+
when Array then @objs.map { |obj| stringify_keys(obj) }
|
76
|
+
else stringify_keys(@objs)
|
77
|
+
end
|
78
|
+
end
|
67
79
|
|
68
|
-
|
69
|
-
|
80
|
+
private
|
81
|
+
|
82
|
+
def stringify_keys(val)
|
83
|
+
modify_keys_recursively(val, __method__)
|
84
|
+
end
|
85
|
+
|
86
|
+
def symbolize_keys(val)
|
87
|
+
modify_keys_recursively(val, __method__)
|
88
|
+
end
|
89
|
+
|
90
|
+
def modify_keys_recursively(val, method)
|
91
|
+
return val unless val.is_a?(Hash)
|
92
|
+
h = Hashie.send(method, val.to_h)
|
93
|
+
h.each do |k, v|
|
94
|
+
case v
|
95
|
+
when Array then h[k].map! { |e| self.send(method, e) }
|
96
|
+
when Hash then h[k] = self.send(method, v)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
h
|
100
|
+
end
|
70
101
|
end
|
71
102
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
103
|
+
class PipelineObjects < PipelineBaseObjects
|
104
|
+
def self.create(api_res)
|
105
|
+
objs = api_res.map(&:to_h).sort_by { |obj| obj[:id] }.map do |obj|
|
106
|
+
base = { id: obj[:id], name: obj[:name] }
|
107
|
+
obj[:fields].sort_by { |f| f[:key] }.inject(base) do |a, e|
|
108
|
+
a.update(e[:key].to_sym => (e[:string_value] || { ref: e[:ref_value] } ))
|
109
|
+
end
|
110
|
+
end
|
111
|
+
new(objs)
|
112
|
+
end
|
113
|
+
|
114
|
+
def to_api_opts
|
115
|
+
@objs.map do |obj|
|
116
|
+
base = { id: obj[:id], name: obj[:name], fields: [] }
|
117
|
+
obj.each do |k, v|
|
118
|
+
next if k == :id || k == :name
|
119
|
+
if v.is_a?(Hash) && v.key?(:ref)
|
120
|
+
base[:fields] << { key: k, ref_value: v[:ref] }
|
121
|
+
else
|
122
|
+
base[:fields] << { key: k, string_value: v }
|
123
|
+
end
|
124
|
+
end
|
125
|
+
base
|
87
126
|
end
|
88
127
|
end
|
89
|
-
d
|
90
128
|
end
|
91
129
|
|
92
|
-
|
93
|
-
|
130
|
+
class ParameterObjects < PipelineBaseObjects
|
131
|
+
def self.create(api_res)
|
132
|
+
objs = api_res.map(&:to_h).sort_by { |obj| obj[:id] }.map do |obj|
|
133
|
+
base = { id: obj[:id] }
|
134
|
+
obj[:attributes].sort_by { |a| a[:key] }.inject(base) do |a, e|
|
135
|
+
a.update(e[:key].to_sym => e[:string_value])
|
136
|
+
end
|
137
|
+
end
|
138
|
+
new(objs)
|
139
|
+
end
|
140
|
+
|
141
|
+
def to_api_opts
|
142
|
+
@objs.map do |obj|
|
143
|
+
base = { id: obj[:id], attributes: [] }
|
144
|
+
obj.each do |k, v|
|
145
|
+
next if k == :id
|
146
|
+
base[:attributes] << { key: k, string_value: v }
|
147
|
+
end
|
148
|
+
base
|
149
|
+
end
|
150
|
+
end
|
94
151
|
end
|
95
152
|
|
96
|
-
|
97
|
-
|
153
|
+
class ParameterValues < PipelineBaseObjects
|
154
|
+
def self.create(api_res)
|
155
|
+
objs = (api_res || []).sort_by { |obj| [obj[:id], obj[:string_value]] }.map do |obj|
|
156
|
+
{ obj[:id].to_sym => obj[:string_value] }
|
157
|
+
end
|
158
|
+
new(objs)
|
159
|
+
end
|
160
|
+
|
161
|
+
def to_api_opts
|
162
|
+
@objs.map do |e|
|
163
|
+
e.map do |k, v|
|
164
|
+
{ id: k, string_value: v }
|
165
|
+
end
|
166
|
+
end.flatten
|
167
|
+
end
|
98
168
|
end
|
99
169
|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
170
|
+
class PipelineDescription < PipelineBaseObjects
|
171
|
+
def self.create(api_res)
|
172
|
+
objs = {
|
173
|
+
pipeline_id: api_res[:pipeline_id],
|
174
|
+
name: api_res[:name],
|
175
|
+
description: api_res[:description],
|
176
|
+
}
|
177
|
+
objs[:tags] = api_res[:tags].map { |e| { e[:key].to_sym => e[:value] } }
|
178
|
+
api_res[:fields].inject(objs) do |a, e|
|
179
|
+
a.update(e[:key].to_sym => (e[:string_value] || { ref: e[:ref_value] } ))
|
107
180
|
end
|
181
|
+
new(objs)
|
182
|
+
end
|
183
|
+
|
184
|
+
def to_objs
|
185
|
+
keys = %i(name description tags uniqueId)
|
186
|
+
stringify_keys(@objs.select { |k, _| keys.include?(k) })
|
187
|
+
end
|
188
|
+
|
189
|
+
def tags
|
190
|
+
@objs[:tags]
|
191
|
+
end
|
192
|
+
|
193
|
+
def tags_opts
|
194
|
+
@objs[:tags].map { |e| e.map { |k, v| { key: k, value: v } } }.flatten
|
195
|
+
end
|
196
|
+
|
197
|
+
def tag_keys
|
198
|
+
@objs[:tags].map(&keys).flatten
|
108
199
|
end
|
109
|
-
h
|
110
200
|
end
|
111
201
|
end
|
112
202
|
end
|
data/lib/pipe_fitter/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pipe_fitter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- masa21kik
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-06-
|
11
|
+
date: 2016-06-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk
|