dtk-client 0.9.0 → 0.9.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/README.md +17 -8
- data/lib/command_helpers/service_importer.rb +1 -1
- data/lib/commands/common/thor/assembly_workspace.rb +63 -8
- data/lib/commands/common/thor/set_required_attributes.rb +2 -2
- data/lib/commands/thor/assembly.rb +34 -23
- data/lib/commands/thor/dtk.rb +25 -16
- data/lib/commands/thor/service.rb +92 -6
- data/lib/commands/thor/service_module.rb +178 -50
- data/lib/commands/thor/workspace.rb +2 -1
- data/lib/dtk-client/version.rb +1 -1
- data/lib/dtk_error.rb +7 -1
- data/lib/shell/context.rb +1 -1
- data/lib/shell/interactive_wizard.rb +3 -3
- data/lib/shell.rb +44 -24
- metadata +17 -17
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
ZThiYjk4YThmM2I4OTg2YTRlNzZhNTVlNjkxNWJlY2Q2YjI3Y2YwMQ==
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 65f98d3a29d9f7cbd1368bdb0ef41a7d5f294fa6
|
4
|
+
data.tar.gz: 1edf46630c80023aac016dfa21414fb9a27098ba
|
7
5
|
SHA512:
|
8
|
-
metadata.gz:
|
9
|
-
|
10
|
-
ZjQyMDQzNjZjN2QzMzYwMGFiNGY3MjQ3NjBkMzQxNTQ2NTA0ZDFmNWZlNGZh
|
11
|
-
MmU1YmUwNzI1MzNmN2RhNDdmYjM1ZWY3MTdjNWY1ZDI1MmE3NjM=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
ZGQyZDhjOWQ3Njc3ZmM5YmQ3OWJjYTcyNzA5YTRlZTM2ZTU5NTA1ZDU3MmZm
|
14
|
-
NjNmYWVmODFkMTY5NGMwMjM4ODI3ZGQ2YWE5MGI1YzUxNTE1ZGQxMWRlNWNl
|
15
|
-
YzRjZTRjNzFlYmQ1ZTE0NzYyOTBiY2Q4ODU3ZmNhOWM2YjdkODU=
|
6
|
+
metadata.gz: 12ed89cec1938c97083425aa8528d9ab14d2ed478abcd4c9bd1bda3432e44ac9a1c26cbf16ec843f36cdb1a1ae62983c51c4e7d8f7aab42b42f7a86cf3d57301
|
7
|
+
data.tar.gz: 4b2664285e145724fb4eeebcb14390eb990ea0183b2dad8076801ea1baaab1623176a106351090cb1ea5f76d2b79b1939b3f7f2b5b318b4c868d81a79387ba04
|
data/README.md
CHANGED
@@ -11,11 +11,11 @@ It's main purpose is to provide an easy to use interface for importing modules,
|
|
11
11
|
---
|
12
12
|
#### Sytstem requirements
|
13
13
|
|
14
|
-
- Ruby 1.9.3
|
14
|
+
- Ruby 1.9.3
|
15
15
|
- Unix OS
|
16
16
|
|
17
17
|
---
|
18
|
-
#### Installation
|
18
|
+
#### Installation
|
19
19
|
|
20
20
|
For DTK Client to work, following steps have to be done:
|
21
21
|
|
@@ -23,7 +23,7 @@ For DTK Client to work, following steps have to be done:
|
|
23
23
|
- RSA Keys Generated
|
24
24
|
|
25
25
|
To install DTK Client gem, execute:
|
26
|
-
|
26
|
+
|
27
27
|
`gem install dtk-client`
|
28
28
|
|
29
29
|
---
|
@@ -34,7 +34,7 @@ There are two ways for DTK Client to run
|
|
34
34
|
- via an interactive shell (<tt>dtk-shell</tt>)
|
35
35
|
- by executing DTK Client commands (ie. <tt>dtk service list</tt>)
|
36
36
|
|
37
|
-
If it is the first time that the DTK Client is being used (by either of the ways), following prompts will appear:
|
37
|
+
If it is the first time that the DTK Client is being used (by either of the ways), following prompts will appear:
|
38
38
|
|
39
39
|
```
|
40
40
|
Please enter the DTK server address (example: instance.dtk.io)
|
@@ -46,10 +46,10 @@ Password:
|
|
46
46
|
|
47
47
|
```
|
48
48
|
After entering the correct data, following message will appear:
|
49
|
-
|
49
|
+
|
50
50
|
`SSH key 'dtk-client' added successfully!`
|
51
51
|
|
52
|
-
This means that the DTK Server has successfully registered DTK Client and the client is ready for use.
|
52
|
+
This means that the DTK Server has successfully registered DTK Client and the client is ready for use.
|
53
53
|
|
54
54
|
---
|
55
55
|
#### DTK Client configuration
|
@@ -83,15 +83,24 @@ Component and Service modules that are installed, or modules that are imported a
|
|
83
83
|
---
|
84
84
|
|
85
85
|
## Advanced features
|
86
|
+
#### Development mode
|
87
|
+
|
88
|
+
When using DTK Client in Development mode, gems from `Gemfile_dev` must be installed and used when running DTK Client or DTK Client Shell:
|
89
|
+
|
90
|
+
```
|
91
|
+
bundle install --gemfile Gemfile_dev
|
92
|
+
BUNDLE_GEMFILE=Gemfile_dev bundle exec ruby ./bin/dtk-shell
|
93
|
+
```
|
94
|
+
|
86
95
|
#### DTK Repoman
|
87
96
|
|
88
|
-
DTK Repoman is a Git based repository for publishing and installing component modules and service modules. DTK Repoman has it's own users, known as catalog users. The inital setup should register the DTK Client to the Public Catalog users.
|
97
|
+
DTK Repoman is a Git based repository for publishing and installing component modules and service modules. DTK Repoman has it's own users, known as catalog users. The inital setup should register the DTK Client to the Public Catalog users.
|
89
98
|
|
90
99
|
Successfully registered DTK Client on DTK Repoman enables execution of commands such as:
|
91
100
|
|
92
101
|
`dtk service-module list --remote` - lists service moduels on remote visible to the catalog user
|
93
102
|
|
94
|
-
`dtk component-module install namespace/component-module-name` - install component module
|
103
|
+
`dtk component-module install namespace/component-module-name` - install component module
|
95
104
|
|
96
105
|
Switching from public user to a commercial user can be done with `dtk account set-catalog-credentials`. This will initate a prompt for catalog username and password
|
97
106
|
|
@@ -159,7 +159,7 @@ module DTK::Client
|
|
159
159
|
# import from Repo Manager
|
160
160
|
new_context_params = ::DTK::Shell::ContextParams.new([module_name])
|
161
161
|
new_context_params.override_method_argument!('option_2', version) if version && !version.eql?('master')
|
162
|
-
new_context_params.forward_options(:skip_cloning => false, :skip_auto_install => true, :module_type => module_type).merge!(opts)
|
162
|
+
new_context_params.forward_options(:skip_cloning => false, :skip_auto_install => true, :module_type => module_type, :ignore_component_error => true).merge!(opts)
|
163
163
|
response = ContextRouter.routeTask(module_type, 'install', new_context_params, @conn)
|
164
164
|
end
|
165
165
|
|
@@ -237,7 +237,7 @@ module DTK::Client
|
|
237
237
|
task_status_stream(assembly_or_workspace_id)
|
238
238
|
end
|
239
239
|
|
240
|
-
def converge_aux(context_params,opts={})
|
240
|
+
def converge_aux(context_params, opts = {})
|
241
241
|
assembly_or_workspace_id,task_action,task_params_string = context_params.retrieve_arguments([REQ_ASSEMBLY_OR_WS_ID,:option_1,:option_2],method_argument_names)
|
242
242
|
|
243
243
|
task_params = parse_params?(task_params_string)
|
@@ -248,7 +248,11 @@ module DTK::Client
|
|
248
248
|
if response.data and response.data.size > 0
|
249
249
|
error_message = "The following violations were found; they must be corrected before workspace can be converged"
|
250
250
|
OsUtil.print(error_message, :red)
|
251
|
-
|
251
|
+
if opts[:are_there_violations]
|
252
|
+
return response.render_table(:violation), true
|
253
|
+
else
|
254
|
+
return response.render_table(:violation)
|
255
|
+
end
|
252
256
|
end
|
253
257
|
|
254
258
|
post_body = PostBody.new(
|
@@ -619,6 +623,7 @@ module DTK::Client
|
|
619
623
|
}
|
620
624
|
|
621
625
|
post_body.merge!(:namespace => namespace) if namespace
|
626
|
+
post_body.merge!(:auto_complete_links => options.auto_complete) if options.auto_complete?
|
622
627
|
post rest_url("assembly/add_component"), post_body
|
623
628
|
end
|
624
629
|
|
@@ -1548,6 +1553,16 @@ module DTK::Client
|
|
1548
1553
|
end
|
1549
1554
|
|
1550
1555
|
def stage_aux(context_params)
|
1556
|
+
new_context_params = get_deploy_or_stage_context(context_params, options)
|
1557
|
+
ContextRouter.routeTask(:service_module, "stage", new_context_params, @conn)
|
1558
|
+
end
|
1559
|
+
|
1560
|
+
def deploy_aux(context_params)
|
1561
|
+
new_context_params = get_deploy_or_stage_context(context_params, options)
|
1562
|
+
ContextRouter.routeTask(:service_module, "deploy", new_context_params, @conn)
|
1563
|
+
end
|
1564
|
+
|
1565
|
+
def get_deploy_or_stage_context(context_params, options)
|
1551
1566
|
assembly_template_name, instance_name = context_params.retrieve_arguments([:option_1!, :option_2], method_argument_names)
|
1552
1567
|
|
1553
1568
|
service_module_name, assembly, assembly_name = assembly_template_name.split('/')
|
@@ -1565,19 +1580,59 @@ module DTK::Client
|
|
1565
1580
|
new_context_params.method_arguments = [assembly_name]
|
1566
1581
|
new_context_params.method_arguments << instance_name if instance_name
|
1567
1582
|
|
1568
|
-
fwd_opts
|
1569
|
-
in_target
|
1570
|
-
node_size
|
1571
|
-
os_type
|
1572
|
-
version
|
1583
|
+
fwd_opts = {}
|
1584
|
+
in_target = options["in-target"]
|
1585
|
+
node_size = options.node_size
|
1586
|
+
os_type = options.os_type
|
1587
|
+
version = options.version
|
1588
|
+
no_auto_complete = options.no_auto_complete
|
1589
|
+
is_target = options.is_target?
|
1590
|
+
parent_service = options.parent_service
|
1591
|
+
do_not_encode = options.do_not_encode
|
1592
|
+
stream_results = options['stream-results']
|
1573
1593
|
|
1574
1594
|
fwd_opts.merge!(:in_target => in_target) if in_target
|
1575
1595
|
fwd_opts.merge!(:node_size => node_size) if node_size
|
1576
1596
|
fwd_opts.merge!(:os_type => os_type) if os_type
|
1577
1597
|
fwd_opts.merge!(:version => version) if version
|
1598
|
+
fwd_opts.merge!(:no_auto_complete => no_auto_complete) if no_auto_complete
|
1599
|
+
fwd_opts.merge!(:is_target => is_target) if is_target
|
1600
|
+
fwd_opts.merge!(:parent_service => parent_service) if parent_service
|
1601
|
+
fwd_opts.merge!(:do_not_encode => do_not_encode) if do_not_encode
|
1602
|
+
fwd_opts.merge!('stream-results' => stream_results) if stream_results
|
1578
1603
|
new_context_params.forward_options(fwd_opts)
|
1579
1604
|
|
1580
|
-
|
1605
|
+
new_context_params
|
1606
|
+
end
|
1607
|
+
|
1608
|
+
def set_default_target_aux(context_params)
|
1609
|
+
target_instance_name = context_params.retrieve_arguments([:option_1!], method_argument_names)
|
1610
|
+
post_body = {
|
1611
|
+
:assembly_id => target_instance_name
|
1612
|
+
}
|
1613
|
+
post rest_url("assembly/set_default_target"), post_body
|
1614
|
+
end
|
1615
|
+
|
1616
|
+
def set_required_attributes_converge_aux(context_params, opts = {})
|
1617
|
+
assembly_or_workspace_id = context_params.retrieve_arguments([REQ_ASSEMBLY_OR_WS_ID], method_argument_names)
|
1618
|
+
|
1619
|
+
message = " You will have to converge service instance manually!"
|
1620
|
+
attributes_response = set_required_attributes_aux(assembly_or_workspace_id, :assembly, :instance, message)
|
1621
|
+
return attributes_response if attributes_response.is_a?(Response) && !attributes_response.ok?
|
1622
|
+
|
1623
|
+
response, violations = converge_aux(context_params, { :are_there_violations => true })
|
1624
|
+
return response unless response.ok?
|
1625
|
+
|
1626
|
+
if violations
|
1627
|
+
forwarded_options = context_params.get_forwarded_options()
|
1628
|
+
context_params.forward_options(forwarded_options.merge!(:violations => true))
|
1629
|
+
else
|
1630
|
+
instance_name = "/service/#{context_params.get_forwarded_options[:instance_name]}"
|
1631
|
+
opts[:instance_name] = instance_name
|
1632
|
+
DTK::Client::OsUtil.print("Service instance '#{instance_name}' deployment has been started. Changing context to '#{instance_name}'.", :green)
|
1633
|
+
end
|
1634
|
+
|
1635
|
+
response
|
1581
1636
|
end
|
1582
1637
|
end
|
1583
1638
|
end
|
@@ -17,7 +17,7 @@
|
|
17
17
|
#
|
18
18
|
module DTK::Client
|
19
19
|
module SetRequiredParamsMixin
|
20
|
-
def set_required_attributes_aux(id,type,subtype=nil)
|
20
|
+
def set_required_attributes_aux(id, type, subtype = nil, additional_message = nil)
|
21
21
|
id_field = "#{type}_id".to_sym
|
22
22
|
post_body = {
|
23
23
|
id_field => id,
|
@@ -32,7 +32,7 @@ module DTK::Client
|
|
32
32
|
response.set_data('Message' => "No parameters to set.")
|
33
33
|
response
|
34
34
|
else
|
35
|
-
param_bindings = DTK::Shell::InteractiveWizard.resolve_missing_params(missing_params)
|
35
|
+
param_bindings = DTK::Shell::InteractiveWizard.resolve_missing_params(missing_params, additional_message)
|
36
36
|
post_body = {
|
37
37
|
id_field => id,
|
38
38
|
:av_pairs_hash => param_bindings.inject(Hash.new){|h,r|h.merge(r[:id] => r[:value])}
|
@@ -201,16 +201,25 @@ module DTK::Client
|
|
201
201
|
response
|
202
202
|
end
|
203
203
|
|
204
|
-
desc "ASSEMBLY-NAME/ID stage [INSTANCE-NAME] [-t
|
205
|
-
method_option
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
#hidden
|
204
|
+
desc "ASSEMBLY-NAME/ID stage-target [INSTANCE-NAME] [-t PARENT-SERVICE-INSTANCE-NAME/ID] [-v VERSION] [--no-auto-complete]", "Stage assembly as target instance."
|
205
|
+
method_option :settings, :type => :string, :aliases => '-s'
|
206
|
+
method_option :no_auto_complete, :type => :boolean, :default => false, :aliases => '--no-ac'
|
207
|
+
method_option :parent_service, :type => :string, :aliases => '-t'
|
208
|
+
version_method_option
|
209
|
+
#hidden options
|
210
210
|
method_option "instance-bindings", :type => :string
|
211
|
+
method_option :is_target, :type => :boolean, :default => true
|
212
|
+
def stage_target(context_params)
|
213
|
+
end
|
214
|
+
|
215
|
+
|
216
|
+
desc "ASSEMBLY-NAME/ID stage [INSTANCE-NAME] [-t PARENT-SERVICE-INSTANCE-NAME/ID] [-v VERSION] [--no-auto-complete]", "Stage assembly in target."
|
217
|
+
method_option "in-target", :aliases => "-t", :type => :string, :banner => "TARGET-NAME/ID", :desc => "Target (id) to create assembly in"
|
211
218
|
method_option :settings, :type => :string, :aliases => '-s'
|
212
|
-
method_option :
|
213
|
-
method_option :
|
219
|
+
method_option :no_auto_complete, :type => :boolean, :default => false, :aliases => '--no-ac'
|
220
|
+
method_option :parent_service, :type => :string, :aliases => '-t'
|
221
|
+
version_method_option
|
222
|
+
method_option "instance-bindings", :type => :string
|
214
223
|
def stage(context_params)
|
215
224
|
assembly_template_id, service_module_id, name = context_params.retrieve_arguments([:assembly_id!, :service_module_id, :option_1],method_argument_names)
|
216
225
|
post_body = {
|
@@ -258,22 +267,24 @@ module DTK::Client
|
|
258
267
|
return response
|
259
268
|
end
|
260
269
|
|
270
|
+
desc "ASSEMBLY-NAME/ID deploy-target [INSTANCE-NAME] [-v VERSION] [--no-auto-complete] [--stream-results]", "Deploy assembly as target instance."
|
271
|
+
method_option 'stream-results', :aliases => '-s', :type => :boolean, :default => false, :desc => "Stream results"
|
272
|
+
method_option :no_auto_complete, :type => :boolean, :default => false, :aliases => '--no-ac'
|
273
|
+
version_method_option
|
274
|
+
#hidden options
|
275
|
+
method_option "instance-bindings", :type => :string
|
276
|
+
method_option :is_target, :type => :boolean, :default => true
|
277
|
+
# method_option :settings, :type => :string, :aliases => '-s'
|
278
|
+
def deploy_target(context_params)
|
279
|
+
end
|
261
280
|
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
# :type => :string,
|
270
|
-
# :banner => "TARGET-NAME/ID",
|
271
|
-
# :desc => "Target (id) to create assembly in"
|
272
|
-
method_option "commit_msg",:aliases => "-m" ,
|
273
|
-
:type => :string,
|
274
|
-
:banner => "COMMIT-MSG",
|
275
|
-
:desc => "Commit message"
|
276
|
-
method_option :settings, :type => :string, :aliases => '-s'
|
281
|
+
desc "ASSEMBLY-NAME/ID deploy [INSTANCE-NAME] [-t PARENT-SERVICE-INSTANCE-NAME/ID] [-v VERSION] [--no-auto-complete] [--stream-results]", "Deploy assembly in target."
|
282
|
+
method_option 'stream-results', :aliases => '-s', :type => :boolean, :default => false, :desc => "Stream results"
|
283
|
+
method_option :no_auto_complete, :type => :boolean, :default => false, :aliases => '--no-ac'
|
284
|
+
method_option :parent_service, :type => :string, :aliases => '-t'
|
285
|
+
version_method_option
|
286
|
+
#hidden options
|
287
|
+
method_option "instance-bindings", :type => :string
|
277
288
|
def deploy(context_params)
|
278
289
|
context_params.forward_options(options)
|
279
290
|
assembly_template_id, service_module_id, name = context_params.retrieve_arguments([:assembly_id!, :service_module_id, :option_1],method_argument_names)
|
data/lib/commands/thor/dtk.rb
CHANGED
@@ -26,14 +26,18 @@ module DTK::Client
|
|
26
26
|
['component','attribute','utils','node','task','component-template','assembly','remotes']
|
27
27
|
end
|
28
28
|
|
29
|
-
|
30
|
-
|
31
|
-
|
29
|
+
if ::DTK::Configuration.get(:development_mode)
|
30
|
+
desc "workspace","Sandbox for development and testing"
|
31
|
+
def workspace
|
32
|
+
# API descriptor, SYM_LINK!
|
33
|
+
end
|
32
34
|
end
|
33
35
|
|
34
|
-
|
35
|
-
|
36
|
-
|
36
|
+
if ::DTK::Configuration.get(:development_mode)
|
37
|
+
desc "target","Targets"
|
38
|
+
def target
|
39
|
+
# API descriptor, SYM_LINK!
|
40
|
+
end
|
37
41
|
end
|
38
42
|
|
39
43
|
|
@@ -70,9 +74,11 @@ module DTK::Client
|
|
70
74
|
# API descriptor
|
71
75
|
end
|
72
76
|
|
73
|
-
|
74
|
-
|
75
|
-
|
77
|
+
if ::DTK::Configuration.get(:development_mode)
|
78
|
+
desc "test-module", "DTK definitions for modeling/defining individual test components."
|
79
|
+
def test_module
|
80
|
+
# API descriptor
|
81
|
+
end
|
76
82
|
end
|
77
83
|
|
78
84
|
# desc "node", "Commands to list, query, and delete/destroy node instances."
|
@@ -85,9 +91,11 @@ module DTK::Client
|
|
85
91
|
# # API descriptor
|
86
92
|
# end
|
87
93
|
|
88
|
-
|
89
|
-
|
90
|
-
|
94
|
+
if ::DTK::Configuration.get(:development_mode)
|
95
|
+
desc "node-template", "Node Templates that map to machine images and containers."
|
96
|
+
def node_template
|
97
|
+
# API descriptor
|
98
|
+
end
|
91
99
|
end
|
92
100
|
|
93
101
|
# desc "component-template","Commands to list and query component templates."
|
@@ -130,10 +138,11 @@ module DTK::Client
|
|
130
138
|
end
|
131
139
|
end
|
132
140
|
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
141
|
+
if ::DTK::Configuration.get(:development_mode)
|
142
|
+
desc "provider", "Manage infrastructure providers and deployment targets (ie: EC2 and us-east)"
|
143
|
+
def provider
|
144
|
+
# API descriptor
|
145
|
+
end
|
137
146
|
end
|
138
147
|
|
139
148
|
# we do not need help here
|
@@ -710,7 +710,8 @@ TODO: will put in dot release and will rename to 'extend'
|
|
710
710
|
|
711
711
|
# only supported at node-level
|
712
712
|
# using HIDE_FROM_BASE to hide this command from base context (dtk:/assembly>)
|
713
|
-
desc "SERVICE-NAME/ID add-component COMPONENT", "Add a component to the service."
|
713
|
+
desc "SERVICE-NAME/ID add-component COMPONENT [--auto-complete]", "Add a component to the service. Use --auto-complete to link components automatically"
|
714
|
+
method_option :auto_complete, :type => :boolean, :default => true
|
714
715
|
def add_component(context_params)
|
715
716
|
response = create_component_aux(context_params)
|
716
717
|
|
@@ -830,17 +831,102 @@ TODO: will put in dot release and will rename to 'extend'
|
|
830
831
|
grep_aux(context_params)
|
831
832
|
end
|
832
833
|
|
833
|
-
desc "stage ASSEMBLY-TEMPLATE [INSTANCE-NAME] [-t
|
834
|
+
desc "stage ASSEMBLY-TEMPLATE [INSTANCE-NAME] [-t PARENT-SERVICE-INSTANCE-NAME/ID] [-v VERSION] [--no-auto-complete]", "Stage assembly in target."
|
834
835
|
method_option "in-target", :aliases => "-t", :type => :string, :banner => "TARGET-NAME/ID", :desc => "Target (id) to create assembly in"
|
835
|
-
method_option :
|
836
|
-
method_option :
|
836
|
+
method_option :no_auto_complete, :type => :boolean, :default => false, :aliases => '--no-ac'
|
837
|
+
method_option :parent_service, :type => :string, :aliases => '-t'
|
837
838
|
version_method_option
|
838
|
-
#hidden
|
839
|
+
#hidden option
|
839
840
|
method_option "instance-bindings", :type => :string
|
840
|
-
method_option :settings, :type => :string, :aliases => '-s'
|
841
841
|
def stage(context_params)
|
842
842
|
stage_aux(context_params)
|
843
843
|
end
|
844
844
|
|
845
|
+
desc "set-default-target INSTANCE-NAME/ID", "Set default target service instance."
|
846
|
+
def set_default_target(context_params)
|
847
|
+
set_default_target_aux(context_params)
|
848
|
+
end
|
849
|
+
|
850
|
+
desc "stage-target ASSEMBLY-TEMPLATE [INSTANCE-NAME] -t PARENT-SERVICE-INSTANCE-NAME/ID] [-v VERSION] [--no-auto-complete]", "Stage assembly as target instance."
|
851
|
+
method_option :settings, :type => :string, :aliases => '-s'
|
852
|
+
method_option :auto_complete, :type => :boolean, :default => true
|
853
|
+
method_option :no_auto_complete, :type => :boolean, :default => false, :aliases => '--no-ac'
|
854
|
+
method_option :parent_service, :type => :string, :aliases => '-t'
|
855
|
+
version_method_option
|
856
|
+
#hidden options
|
857
|
+
method_option "instance-bindings", :type => :string
|
858
|
+
method_option :is_target, :type => :boolean, :default => true
|
859
|
+
def stage_target(context_params)
|
860
|
+
response = stage_aux(context_params)
|
861
|
+
return response unless response.ok?
|
862
|
+
|
863
|
+
# when changing context send request for getting latest assemblies instead of getting from cache
|
864
|
+
@@invalidate_map << :service
|
865
|
+
@@invalidate_map << :assembly
|
866
|
+
|
867
|
+
return response
|
868
|
+
end
|
869
|
+
|
870
|
+
desc "deploy-target ASSEMBLY-TEMPLATE [INSTANCE-NAME] [-v VERSION] [--no-auto-complete] [--stream-results]", "Deploy assembly as target instance."
|
871
|
+
method_option 'stream-results', :aliases => '-s', :type => :boolean, :default => false, :desc => "Stream results"
|
872
|
+
method_option :no_auto_complete, :type => :boolean, :default => false, :aliases => '--no-ac'
|
873
|
+
version_method_option
|
874
|
+
#hidden options
|
875
|
+
method_option "instance-bindings", :type => :string
|
876
|
+
method_option :is_target, :type => :boolean, :default => true
|
877
|
+
# method_option :settings, :type => :string, :aliases => '-s'
|
878
|
+
def deploy_target(context_params)
|
879
|
+
response = deploy_aux(context_params)
|
880
|
+
return response unless response.ok?
|
881
|
+
|
882
|
+
@@invalidate_map << :service
|
883
|
+
@@invalidate_map << :assembly
|
884
|
+
|
885
|
+
response
|
886
|
+
end
|
887
|
+
|
888
|
+
desc "deploy ASSEMBLY-TEMPLATE [INSTANCE-NAME] [-t PARENT-SERVICE-INSTANCE-NAME/ID] [-v VERSION] [--no-auto-complete]", "Deploy assembly in target."
|
889
|
+
method_option 'stream-results', :aliases => '-s', :type => :boolean, :default => false, :desc => "Stream results"
|
890
|
+
method_option :no_auto_complete, :type => :boolean, :default => false, :aliases => '--no-ac'
|
891
|
+
method_option :parent_service, :type => :string, :aliases => '-t'
|
892
|
+
version_method_option
|
893
|
+
#hidden options
|
894
|
+
method_option "instance-bindings", :type => :string
|
895
|
+
# method_option :settings, :type => :string, :aliases => '-s'
|
896
|
+
def deploy(context_params)
|
897
|
+
response = deploy_aux(context_params)
|
898
|
+
return response unless response.ok?
|
899
|
+
|
900
|
+
@@invalidate_map << :service
|
901
|
+
@@invalidate_map << :assembly
|
902
|
+
|
903
|
+
response
|
904
|
+
end
|
905
|
+
|
906
|
+
desc "SERVICE-NAME/ID set-required-attributes-and-converge", "Interactive dialog to set required attributes that are not currently set", :hide => true
|
907
|
+
def set_required_attributes_and_converge(context_params)
|
908
|
+
begin
|
909
|
+
response = set_required_attributes_converge_aux(context_params)
|
910
|
+
rescue DTK::Client::DtkError::InteractiveWizardError => e
|
911
|
+
@@invalidate_map << :service
|
912
|
+
@@invalidate_map << :assembly
|
913
|
+
|
914
|
+
# if skip correction wizzard still go to newly created service instance
|
915
|
+
if instance_name = (context_params.get_forwarded_options()||{})[:instance_name]
|
916
|
+
MainContext.get_context.change_context(["/service/#{instance_name}"])
|
917
|
+
end
|
918
|
+
|
919
|
+
raise e
|
920
|
+
end
|
921
|
+
|
922
|
+
@@invalidate_map << :service
|
923
|
+
@@invalidate_map << :assembly
|
924
|
+
|
925
|
+
# if instance_name = opts[:instance_name]
|
926
|
+
# MainContext.get_context.change_context([instance_name])
|
927
|
+
# end
|
928
|
+
|
929
|
+
response
|
930
|
+
end
|
845
931
|
end
|
846
932
|
end
|
@@ -22,10 +22,12 @@ dtk_require_from_base("dtk_logger")
|
|
22
22
|
dtk_require_from_base("util/os_util")
|
23
23
|
dtk_require_from_base("commands/thor/assembly")
|
24
24
|
dtk_require_from_base('command_helpers/service_importer')
|
25
|
+
dtk_require_from_base('task_status')
|
25
26
|
dtk_require_common_commands('thor/common')
|
26
27
|
dtk_require_common_commands('thor/module')
|
27
28
|
dtk_require_common_commands('thor/poller')
|
28
29
|
dtk_require_common_commands('thor/assembly_template')
|
30
|
+
dtk_require_common_commands('thor/pull_clone_changes')
|
29
31
|
|
30
32
|
module DTK::Client
|
31
33
|
class ServiceModule < CommandBaseThor
|
@@ -38,6 +40,7 @@ module DTK::Client
|
|
38
40
|
include ModuleMixin
|
39
41
|
include Poller
|
40
42
|
include AssemblyTemplateMixin
|
43
|
+
include TaskStatusMixin
|
41
44
|
|
42
45
|
def get_service_module_name(service_module_id)
|
43
46
|
get_name_from_id_helper(service_module_id)
|
@@ -59,6 +62,101 @@ module DTK::Client
|
|
59
62
|
|
60
63
|
return name, version
|
61
64
|
end
|
65
|
+
|
66
|
+
def stage_aux(context_params)
|
67
|
+
if context_params.is_there_identifier?(:assembly)
|
68
|
+
service_module_id, service_module_name, assembly_template_name, name = context_params.retrieve_arguments([:service_module_id!, :service_module_name!, :assembly_name!, :option_2], method_argument_names)
|
69
|
+
else
|
70
|
+
service_module_id, service_module_name, assembly_template_name, name = context_params.retrieve_arguments([:service_module_id!, :service_module_name!, :option_1!, :option_2], method_argument_names)
|
71
|
+
end
|
72
|
+
|
73
|
+
post_body = { :assembly_id => assembly_template_name }
|
74
|
+
|
75
|
+
# special case when we need service module id
|
76
|
+
context_params.pure_cli_mode = true
|
77
|
+
post_body[:service_module_id] = service_module_id if context_params.pure_cli_mode
|
78
|
+
|
79
|
+
# using this to make sure cache will be invalidated after new assembly is created from other commands e.g.
|
80
|
+
# 'assembly-create', 'install' etc.
|
81
|
+
@@invalidate_map << :assembly
|
82
|
+
|
83
|
+
fwd_options = context_params.get_forwarded_options()
|
84
|
+
in_target = fwd_options[:in_target]||options["in-target"]
|
85
|
+
instance_bindings = options["instance-bindings"]
|
86
|
+
settings = parse_service_settings(options["settings"])
|
87
|
+
node_size = fwd_options[:node_size]||options.node_size
|
88
|
+
os_type = fwd_options[:os_type]||options.os_type
|
89
|
+
version = fwd_options[:version]||options.version
|
90
|
+
no_auto_complete = fwd_options[:no_auto_complete]||options.no_auto_complete
|
91
|
+
parent_service = fwd_options[:parent_service]||options.parent_service
|
92
|
+
is_target = fwd_options[:is_target]||options.is_target?
|
93
|
+
do_not_encode = fwd_options[:do_not_encode]
|
94
|
+
assembly_list = Assembly.assembly_list()
|
95
|
+
|
96
|
+
if assembly_template_name.to_s =~ /^[0-9]+$/
|
97
|
+
assembly_template_name = DTK::Client::Assembly.get_assembly_template_name_for_service(assembly_template_name, service_module_name)
|
98
|
+
assembly_template_name, version = get_name_and_version_from_assembly_template(assembly_template_name)
|
99
|
+
else
|
100
|
+
namespace, module_name = get_namespace_and_name(service_module_name, ':')
|
101
|
+
assembly_template_name = "#{module_name}/#{assembly_template_name}"
|
102
|
+
end
|
103
|
+
assembly_template_name.gsub!(/(::)|(\/)/,'-') if assembly_template_name
|
104
|
+
|
105
|
+
if name
|
106
|
+
raise DTK::Client::DtkValidationError, "Unable to stage service with name '#{name}'. Service with specified name exists already!" if assembly_list.include?(name)
|
107
|
+
else
|
108
|
+
name = get_assembly_stage_name(assembly_list, assembly_template_name)
|
109
|
+
end
|
110
|
+
|
111
|
+
post_body.merge!(:target_id => in_target) if in_target
|
112
|
+
post_body.merge!(:name => name) if name
|
113
|
+
post_body.merge!(:instance_bindings => instance_bindings) if instance_bindings
|
114
|
+
post_body.merge!(:settings_json_form => JSON.generate(settings)) if settings
|
115
|
+
post_body.merge!(:node_size => node_size) if node_size
|
116
|
+
post_body.merge!(:os_type => os_type) if os_type
|
117
|
+
post_body.merge!(:version => version) if version
|
118
|
+
post_body.merge!(:service_module_name => service_module_name) if service_module_name
|
119
|
+
post_body.merge!(:no_auto_complete => no_auto_complete) if no_auto_complete
|
120
|
+
post_body.merge!(:parent_service => parent_service) if parent_service
|
121
|
+
post_body.merge!(:is_target => is_target) if is_target
|
122
|
+
post_body.merge!(:do_not_encode => do_not_encode) if do_not_encode
|
123
|
+
|
124
|
+
response = post rest_url("assembly/stage"), post_body
|
125
|
+
end
|
126
|
+
|
127
|
+
def deploy_aux(context_params)
|
128
|
+
forwarded_options = context_params.get_forwarded_options()
|
129
|
+
context_params.forward_options(forwarded_options.merge!(:do_not_encode => true))
|
130
|
+
stage_response = stage_aux(context_params)
|
131
|
+
return stage_response unless stage_response.ok?
|
132
|
+
|
133
|
+
if service_instance = stage_response.data['new_service_instance']
|
134
|
+
instance_name = service_instance['name']
|
135
|
+
|
136
|
+
DTK::Client::OsUtil.print("Service instance '/service/#{instance_name}' has been created!",:yellow)
|
137
|
+
|
138
|
+
new_context_params = DTK::Shell::ContextParams.new
|
139
|
+
new_context_params.add_context_to_params("service", "service")
|
140
|
+
new_context_params.add_context_name_to_params("service", "service", instance_name)
|
141
|
+
new_context_params.forward_options(:instance_name => instance_name)
|
142
|
+
|
143
|
+
response = ContextRouter.routeTask("service", "set_required_attributes_and_converge", new_context_params, @conn)
|
144
|
+
|
145
|
+
# change context to newly created service instance
|
146
|
+
MainContext.get_context.change_context(["/service/#{instance_name}"])
|
147
|
+
|
148
|
+
return response unless response.ok?
|
149
|
+
|
150
|
+
if forwarded_options['stream-results'] || options['stream-results']
|
151
|
+
forwarded_options = new_context_params.get_forwarded_options()
|
152
|
+
task_status_stream(instance_name) unless forwarded_options[:violations]
|
153
|
+
end
|
154
|
+
|
155
|
+
response
|
156
|
+
else
|
157
|
+
fail DtkError.new('Service instance is not staged properly, please try again!')
|
158
|
+
end
|
159
|
+
end
|
62
160
|
end
|
63
161
|
|
64
162
|
def self.extended_context()
|
@@ -68,6 +166,21 @@ module DTK::Client
|
|
68
166
|
:endpoint => "service_module",
|
69
167
|
:url => "service_module/list_assemblies",
|
70
168
|
:opts => {}
|
169
|
+
},
|
170
|
+
:stage_target => {
|
171
|
+
:endpoint => "service_module",
|
172
|
+
:url => "service_module/list_assemblies",
|
173
|
+
:opts => {}
|
174
|
+
},
|
175
|
+
:deploy_target => {
|
176
|
+
:endpoint => "service_module",
|
177
|
+
:url => "service_module/list_assemblies",
|
178
|
+
:opts => {}
|
179
|
+
},
|
180
|
+
:deploy => {
|
181
|
+
:endpoint => "service_module",
|
182
|
+
:url => "service_module/list_assemblies",
|
183
|
+
:opts => {}
|
71
184
|
}
|
72
185
|
}
|
73
186
|
}
|
@@ -127,7 +240,11 @@ module DTK::Client
|
|
127
240
|
# ["stage", "stage [INSTANCE-NAME] [-t TARGET-NAME/ID] [--node-size NODE-SIZE-SPEC] [--os-type OS-TYPE] [-v VERSION]", "# Stage assembly in target."],
|
128
241
|
# ["deploy","deploy [-v VERSION] [INSTANCE-NAME] [-t TARGET-NAME/ID] [-m COMMIT-MSG]", "# Stage and deploy assembly in target."],
|
129
242
|
# ["deploy","deploy [INSTANCE-NAME] [-t TARGET-NAME/ID] [-m COMMIT-MSG]", "# Stage and deploy assembly in target."],
|
130
|
-
["deploy","deploy [INSTANCE-NAME] [-m COMMIT-MSG]", "# Stage and deploy assembly in target."],
|
243
|
+
# ["deploy","deploy [INSTANCE-NAME] [-m COMMIT-MSG]", "# Stage and deploy assembly in target."],
|
244
|
+
["stage-target","stage-target [INSTANCE-NAME] [-t PARENT-SERVICE-INSTANCE-NAME/ID] [-v VERSION] [--no-auto-complete]", "# Stage assembly as target instance."],
|
245
|
+
["stage","stage [INSTANCE-NAME] [-t PARENT-SERVICE-INSTANCE-NAME/ID] [-v VERSION] [--no-auto-complete]", "# Stage assembly in target."],
|
246
|
+
["deploy-target","deploy-target [INSTANCE-NAME] [-v VERSION] [--no-auto-complete]", "# Deploy assembly as target instance."],
|
247
|
+
["deploy","deploy [INSTANCE-NAME] [-t PARENT-SERVICE-INSTANCE-NAME/ID] [-v VERSION] [--no-auto-complete]", "# Deploy assembly in target."],
|
131
248
|
["list-nodes","list-nodes", "# List all nodes for given assembly."],
|
132
249
|
["list-components","list-components", "# List all components for given assembly."],
|
133
250
|
["list-settings","list-settings", "# List all settings for given assembly."]
|
@@ -483,68 +600,43 @@ module DTK::Client
|
|
483
600
|
if old_dir and (old_dir != module_final_dir)
|
484
601
|
FileUtils.rm_rf(old_dir) unless namespace
|
485
602
|
end
|
603
|
+
|
486
604
|
DTK::Client::OsUtil.print("Module '#{new_module_name}' has been created and module directory moved to #{repo_obj.repo_dir}",:yellow) unless namespace
|
487
605
|
|
488
606
|
response
|
489
607
|
end
|
490
608
|
|
491
|
-
desc "SERVICE-MODULE-NAME/ID stage ASSEMBLY-NAME [INSTANCE-NAME] [-
|
492
|
-
method_option "in-target", :aliases => "-t", :type => :string, :banner => "TARGET-NAME/ID", :desc => "Target (id) to create assembly in"
|
609
|
+
desc "SERVICE-MODULE-NAME/ID stage-target ASSEMBLY-NAME [INSTANCE-NAME] [-v VERSION] [--no-auto-complete]", "Stage assembly as target instance."
|
493
610
|
method_option :settings, :type => :string, :aliases => '-s'
|
494
|
-
method_option :
|
495
|
-
method_option :
|
611
|
+
method_option :no_auto_complete, :type => :boolean, :default => false, :aliases => '--no-ac'
|
612
|
+
# method_option :parent_service, :type => :string, :aliases => '-t'
|
496
613
|
version_method_option
|
497
|
-
#hidden
|
614
|
+
#hidden options
|
498
615
|
method_option "instance-bindings", :type => :string
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
}
|
504
|
-
|
505
|
-
# special case when we need service module id
|
506
|
-
context_params.pure_cli_mode = true
|
507
|
-
post_body[:service_module_id] = service_module_id if context_params.pure_cli_mode
|
616
|
+
method_option :is_target, :type => :boolean, :default => true
|
617
|
+
def stage_target(context_params)
|
618
|
+
response = stage_aux(context_params)
|
619
|
+
return response unless response.ok?
|
508
620
|
|
509
|
-
#
|
510
|
-
|
621
|
+
# when changing context send request for getting latest assemblies instead of getting from cache
|
622
|
+
@@invalidate_map << :service
|
511
623
|
@@invalidate_map << :assembly
|
512
624
|
|
513
|
-
|
514
|
-
|
515
|
-
instance_bindings = options["instance-bindings"]
|
516
|
-
settings = parse_service_settings(options["settings"])
|
517
|
-
node_size = fwd_options[:node_size]||options.node_size
|
518
|
-
os_type = fwd_options[:os_type]||options.os_type
|
519
|
-
version = fwd_options[:version]||options.version
|
520
|
-
assembly_list = Assembly.assembly_list()
|
521
|
-
|
522
|
-
if assembly_template_name.to_s =~ /^[0-9]+$/
|
523
|
-
assembly_template_name = DTK::Client::Assembly.get_assembly_template_name_for_service(assembly_template_name, service_module_name)
|
524
|
-
assembly_template_name, version = get_name_and_version_from_assembly_template(assembly_template_name)
|
525
|
-
else
|
526
|
-
namespace, module_name = get_namespace_and_name(service_module_name, ':')
|
527
|
-
assembly_template_name = "#{module_name}/#{assembly_template_name}"
|
528
|
-
end
|
529
|
-
assembly_template_name.gsub!(/(::)|(\/)/,'-') if assembly_template_name
|
530
|
-
|
531
|
-
if name
|
532
|
-
raise DTK::Client::DtkValidationError, "Unable to stage service with name '#{name}'. Service with specified name exists already!" if assembly_list.include?(name)
|
533
|
-
else
|
534
|
-
name = get_assembly_stage_name(assembly_list, assembly_template_name)
|
535
|
-
end
|
536
|
-
|
537
|
-
post_body.merge!(:target_id => in_target) if in_target
|
538
|
-
post_body.merge!(:name => name) if name
|
539
|
-
post_body.merge!(:instance_bindings => instance_bindings) if instance_bindings
|
540
|
-
post_body.merge!(:settings_json_form => JSON.generate(settings)) if settings
|
541
|
-
post_body.merge!(:node_size => node_size) if node_size
|
542
|
-
post_body.merge!(:os_type => os_type) if os_type
|
543
|
-
post_body.merge!(:version => version) if version
|
544
|
-
post_body.merge!(:service_module_name => service_module_name) if service_module_name
|
625
|
+
return response
|
626
|
+
end
|
545
627
|
|
546
|
-
|
628
|
+
desc "SERVICE-MODULE-NAME/ID stage ASSEMBLY-NAME [INSTANCE-NAME] [-t PARENT-SERVICE-INSTANCE-NAME/ID] [-v VERSION] [--no-auto-complete]", "Stage assembly in target."
|
629
|
+
method_option "in-target", :aliases => "-t", :type => :string, :banner => "TARGET-NAME/ID", :desc => "Target (id) to create assembly in"
|
630
|
+
method_option :settings, :type => :string, :aliases => '-s'
|
631
|
+
method_option :no_auto_complete, :type => :boolean, :default => false, :aliases => '--no-ac'
|
632
|
+
method_option :parent_service, :type => :string, :aliases => '-t'
|
633
|
+
version_method_option
|
634
|
+
#hidden option
|
635
|
+
method_option "instance-bindings", :type => :string
|
636
|
+
def stage(context_params)
|
637
|
+
response = stage_aux(context_params)
|
547
638
|
return response unless response.ok?
|
639
|
+
|
548
640
|
# when changing context send request for getting latest assemblies instead of getting from cache
|
549
641
|
@@invalidate_map << :service
|
550
642
|
@@invalidate_map << :assembly
|
@@ -716,6 +808,42 @@ module DTK::Client
|
|
716
808
|
create_new_version_aux(context_params)
|
717
809
|
end
|
718
810
|
|
811
|
+
desc "SERVICE-MODULE-NAME/ID deploy-target ASSEMBLY-NAME [INSTANCE-NAME] [-v VERSION] [--no-auto-complete] [--stream-results]", "Deploy assembly as target instance."
|
812
|
+
method_option :no_auto_complete, :type => :boolean, :default => false, :aliases => '--no-ac'
|
813
|
+
method_option 'stream-results', :aliases => '-s', :type => :boolean, :default => false, :desc => "Stream results"
|
814
|
+
version_method_option
|
815
|
+
#hidden options
|
816
|
+
method_option "instance-bindings", :type => :string
|
817
|
+
method_option :is_target, :type => :boolean, :default => true
|
818
|
+
# method_option :settings, :type => :string, :aliases => '-s'
|
819
|
+
def deploy_target(context_params)
|
820
|
+
response = deploy_aux(context_params)
|
821
|
+
return response unless response.ok?
|
822
|
+
|
823
|
+
@@invalidate_map << :service
|
824
|
+
@@invalidate_map << :assembly
|
825
|
+
|
826
|
+
response
|
827
|
+
end
|
828
|
+
|
829
|
+
desc "SERVICE-MODULE-NAME/ID deploy ASSEMBLY-NAME [INSTANCE-NAME] [-t PARENT-SERVICE-INSTANCE-NAME/ID] [-v VERSION] [--no-auto-complete] [--stream-results]", "Deploy assembly in target."
|
830
|
+
method_option :no_auto_complete, :type => :boolean, :default => false, :aliases => '--no-ac'
|
831
|
+
method_option :parent_service, :type => :string, :aliases => '-t'
|
832
|
+
method_option 'stream-results', :aliases => '-s', :type => :boolean, :default => false, :desc => "Stream results"
|
833
|
+
version_method_option
|
834
|
+
#hidden options
|
835
|
+
method_option "instance-bindings", :type => :string
|
836
|
+
# method_option :settings, :type => :string, :aliases => '-s'
|
837
|
+
def deploy(context_params)
|
838
|
+
response = deploy_aux(context_params)
|
839
|
+
return response unless response.ok?
|
840
|
+
|
841
|
+
@@invalidate_map << :service
|
842
|
+
@@invalidate_map << :assembly
|
843
|
+
|
844
|
+
response
|
845
|
+
end
|
846
|
+
|
719
847
|
#
|
720
848
|
# DEVELOPMENT MODE METHODS
|
721
849
|
#
|
@@ -324,7 +324,8 @@ module DTK::Client
|
|
324
324
|
|
325
325
|
#only supported at node-level
|
326
326
|
# using HIDE_FROM_BASE to hide this command from base context (dtk:/workspace>)
|
327
|
-
desc "WORKSPACE-NAME/ID add-component COMPONENT", "Add a component to a workspace."
|
327
|
+
desc "WORKSPACE-NAME/ID add-component COMPONENT [--auto-complete]", "Add a component to a workspace. Use --auto-complete to link components automatically"
|
328
|
+
method_option :auto_complete, :type => :boolean, :default => true
|
328
329
|
def add_component(context_params)
|
329
330
|
response = create_component_aux(context_params)
|
330
331
|
return response unless response.ok?
|
data/lib/dtk-client/version.rb
CHANGED
data/lib/dtk_error.rb
CHANGED
@@ -94,15 +94,21 @@ module DTK
|
|
94
94
|
super(:client)
|
95
95
|
end
|
96
96
|
end
|
97
|
+
|
97
98
|
class Server < InternalError
|
98
99
|
def initialize(error_msg,opts={})
|
99
100
|
super(error_msg,opts.merge(:where => :server))
|
100
101
|
end
|
101
102
|
def self.label(*args)
|
102
103
|
super(:server)
|
103
|
-
|
104
|
+
end
|
104
105
|
end
|
105
106
|
|
107
|
+
class InteractiveWizardError < self
|
108
|
+
def initialize(error_msg, opts={})
|
109
|
+
super(error_msg, opts)
|
110
|
+
end
|
111
|
+
end
|
106
112
|
end
|
107
113
|
end
|
108
114
|
end
|
data/lib/shell/context.rb
CHANGED
@@ -149,7 +149,7 @@ module DTK
|
|
149
149
|
warning_message = restricted[:message]
|
150
150
|
node_specific = restricted[:node_specific]
|
151
151
|
|
152
|
-
DTK::Client::OsUtil.print_warning(
|
152
|
+
DTK::Client::OsUtil.print_warning(warning_message) if warning_message
|
153
153
|
# end
|
154
154
|
|
155
155
|
# Validate and change context
|
@@ -138,7 +138,7 @@ module DTK
|
|
138
138
|
|
139
139
|
# takes hash maps with description of missing params and
|
140
140
|
# returns array of hash map with key, value for each missed param
|
141
|
-
def self.resolve_missing_params(param_list)
|
141
|
+
def self.resolve_missing_params(param_list, additional_message = nil)
|
142
142
|
begin
|
143
143
|
user_provided_params, checkup_hash = [], {}
|
144
144
|
|
@@ -156,7 +156,7 @@ module DTK
|
|
156
156
|
puts "Please enter #{string_identifier}:"
|
157
157
|
while line = Readline.readline(": ", true)
|
158
158
|
id = param_info['id']
|
159
|
-
user_provided_params << {:id => id, :value => line}
|
159
|
+
user_provided_params << {:id => id, :value => line, :display_name => param_info['display_name']}
|
160
160
|
checkup_hash[id] = {:value => line, :description => description}
|
161
161
|
break
|
162
162
|
end
|
@@ -177,7 +177,7 @@ module DTK
|
|
177
177
|
rescue Interrupt => e
|
178
178
|
puts
|
179
179
|
# TODO: Provide original error here
|
180
|
-
raise DTK::Client::DtkError, "You have decided to skip correction wizard
|
180
|
+
raise DTK::Client::DtkError::InteractiveWizardError, "You have decided to skip correction wizard.#{additional_message}"
|
181
181
|
end
|
182
182
|
|
183
183
|
return user_provided_params
|
data/lib/shell.rb
CHANGED
@@ -39,6 +39,20 @@ ALIAS_COMMANDS = {
|
|
39
39
|
'rm' => 'delete'
|
40
40
|
}
|
41
41
|
|
42
|
+
class MainContext
|
43
|
+
include Singleton
|
44
|
+
|
45
|
+
attr_accessor :context
|
46
|
+
|
47
|
+
def initialize
|
48
|
+
@context = DTK::Shell::Context.new
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.get_context
|
52
|
+
MainContext.instance.context
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
42
56
|
# METHODS
|
43
57
|
|
44
58
|
# support for alias commands (ls for list, cd for cc etc.)
|
@@ -74,7 +88,6 @@ def run_shell_command()
|
|
74
88
|
puts e.backtrace if ::DTK::Configuration.get(:development_mode)
|
75
89
|
retry
|
76
90
|
rescue Interrupt => e
|
77
|
-
#system('stty', stty_save) # Restore
|
78
91
|
retry
|
79
92
|
rescue Exception => e
|
80
93
|
client_internal_error = DTK::Client::DtkError::Client.label()
|
@@ -91,10 +104,11 @@ end
|
|
91
104
|
|
92
105
|
def init_shell_context()
|
93
106
|
begin
|
94
|
-
@context = DTK::Shell::Context.new
|
107
|
+
# @context = DTK::Shell::Context.new
|
95
108
|
@shell_header = DTK::Shell::HeaderShell.new
|
109
|
+
|
96
110
|
# loads root context
|
97
|
-
|
111
|
+
MainContext.get_context.load_context()
|
98
112
|
|
99
113
|
@t1 = nil
|
100
114
|
Readline.completion_append_character=''
|
@@ -124,7 +138,7 @@ def execute_shell_command(line, prompt)
|
|
124
138
|
return prompt
|
125
139
|
end
|
126
140
|
# when using help on root this is needed
|
127
|
-
line = 'dtk help' if (line == 'help' &&
|
141
|
+
line = 'dtk help' if (line == 'help' && MainContext.get_context.root?)
|
128
142
|
|
129
143
|
args = Shellwords.split(line)
|
130
144
|
cmd = args.shift
|
@@ -145,30 +159,30 @@ def execute_shell_command(line, prompt)
|
|
145
159
|
if ('cc' == cmd)
|
146
160
|
# in case there is no params we just reload command
|
147
161
|
args << "/" if args.empty?
|
148
|
-
prompt =
|
162
|
+
prompt = MainContext.get_context.change_context(args, cmd)
|
149
163
|
elsif ('popc' == cmd)
|
150
|
-
|
151
|
-
args << (
|
152
|
-
prompt =
|
164
|
+
MainContext.get_context.dirs.shift()
|
165
|
+
args << (MainContext.get_context.dirs.first.nil? ? '/' : MainContext.get_context.dirs.first)
|
166
|
+
prompt = MainContext.get_context.change_context(args, cmd)
|
153
167
|
elsif ('pushc' == cmd)
|
154
168
|
if args.empty?
|
155
|
-
args << (
|
156
|
-
|
157
|
-
|
158
|
-
prompt =
|
169
|
+
args << (MainContext.get_context.dirs[1].nil? ? '/' : MainContext.get_context.dirs[1])
|
170
|
+
MainContext.get_context.dirs.unshift(args.first)
|
171
|
+
MainContext.get_context.dirs.uniq!
|
172
|
+
prompt = MainContext.get_context.change_context(args, cmd)
|
159
173
|
else
|
160
|
-
prompt =
|
174
|
+
prompt = MainContext.get_context.change_context(args)
|
161
175
|
# using regex to remove dtk: and > from path returned by change_context
|
162
176
|
# e.g transform dtk:/assembly/node> to /assembly/node
|
163
177
|
full_path = prompt.match(/[dtk:](\/.*)[>]/)[1]
|
164
|
-
|
178
|
+
MainContext.get_context.dirs.unshift(full_path)
|
165
179
|
end
|
166
180
|
elsif ('dirs' == cmd)
|
167
|
-
puts
|
181
|
+
puts MainContext.get_context.dirs.inspect
|
168
182
|
else
|
169
183
|
|
170
184
|
# get all next-context-candidates (e.g. for assembly get all assembly_names)
|
171
|
-
context_candidates =
|
185
|
+
context_candidates = MainContext.get_context.get_ac_candidates_for_context(MainContext.get_context.active_context.last_context(), MainContext.get_context.active_context())
|
172
186
|
|
173
187
|
# this part of the code is used for calling of nested commands from base context (dtk:/>assembly/assembly_id converge)
|
174
188
|
# base_command is used to check if first command from n-level is valid e.g.
|
@@ -178,29 +192,29 @@ def execute_shell_command(line, prompt)
|
|
178
192
|
revert_context = false
|
179
193
|
|
180
194
|
if context_candidates.include?(base_command)
|
181
|
-
|
195
|
+
MainContext.get_context.change_context([cmd])
|
182
196
|
cmd = args.shift
|
183
197
|
revert_context = true
|
184
198
|
end
|
185
199
|
|
186
200
|
if cmd.nil?
|
187
|
-
prompt =
|
201
|
+
prompt = MainContext.get_context.change_context(["-"]) if revert_context
|
188
202
|
raise DTK::Client::DtkValidationError, "You have to provide command after context name. Usage: CONTEXT-TYPE/CONTEXT-NAME COMMAND [ARG1] .. [ARG2]."
|
189
203
|
end
|
190
204
|
|
191
205
|
# send monkey patch class information about context
|
192
|
-
Thor.set_context(
|
206
|
+
Thor.set_context(MainContext.get_context)
|
193
207
|
|
194
208
|
# we get command and hash params, will return Validation error if command is not valid
|
195
|
-
entity_name, method_name, context_params, thor_options, invalid_options =
|
209
|
+
entity_name, method_name, context_params, thor_options, invalid_options = MainContext.get_context.get_command_parameters(cmd,args)
|
196
210
|
|
197
211
|
# check if command is executed from parent context (e.g assembly_name list-nodes)
|
198
212
|
if context_candidates.include?(method_name)
|
199
213
|
context_params.add_context_to_params(method_name, entity_name, method_name)
|
200
214
|
method_name = context_params.method_arguments.shift if context_params.method_arguments.size > 0
|
201
215
|
else
|
202
|
-
unless
|
203
|
-
prompt =
|
216
|
+
unless MainContext.get_context.method_valid?(method_name)
|
217
|
+
prompt = MainContext.get_context.change_context(["-"]) if revert_context
|
204
218
|
raise DTK::Client::DtkValidationError, "Method '#{method_name}' is not valid in current context."
|
205
219
|
end
|
206
220
|
end
|
@@ -209,19 +223,25 @@ def execute_shell_command(line, prompt)
|
|
209
223
|
raise DTK::Client::DtkValidationError.new("Option '#{invalid_options.first||method_name}' is not valid for current command!", true) unless invalid_options.empty?
|
210
224
|
|
211
225
|
# execute command via Thor
|
226
|
+
current_contex_path = MainContext.get_context.active_context.full_path
|
212
227
|
top_level_execute(entity_name, method_name, context_params, thor_options, true)
|
213
228
|
|
214
229
|
# when 'delete' or 'delete-and-destroy' command is executed reload cached tasks with latest commands
|
215
230
|
unless (args.nil? || args.empty?)
|
216
|
-
|
231
|
+
MainContext.get_context.reload_cached_tasks(entity_name) if (method_name.include?('delete') || method_name.include?('import'))
|
217
232
|
end
|
218
233
|
|
219
234
|
# check execution status, prints status to sttout
|
220
235
|
DTK::Shell::StatusMonitor.check_status()
|
221
236
|
|
237
|
+
# if we change context while executing command, change prompt as well
|
238
|
+
unless current_contex_path.eql?(MainContext.get_context.active_context.full_path)
|
239
|
+
prompt = "dtk:#{MainContext.get_context.active_context.full_path}>"
|
240
|
+
end
|
241
|
+
|
222
242
|
# after nested command called from base context is executed successfully, return to context which command is executed from
|
223
243
|
# this is the same as 'cd -' command is executed
|
224
|
-
prompt =
|
244
|
+
prompt = MainContext.get_context.change_context(["-"]) if revert_context
|
225
245
|
end
|
226
246
|
rescue DTK::Client::DSLParsing => e
|
227
247
|
DTK::Client::OsUtil.print(e.message, :red)
|
metadata
CHANGED
@@ -1,41 +1,41 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dtk-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rich PELAVIN
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-04-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mime-types
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.25'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ~>
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.25'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: 1.2.4
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 1.2.4
|
41
41
|
- !ruby/object:Gem::Dependency
|
@@ -70,42 +70,42 @@ dependencies:
|
|
70
70
|
name: hirb
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - ~>
|
73
|
+
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: 0.7.0
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - ~>
|
80
|
+
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: 0.7.0
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: thor
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- - ~>
|
87
|
+
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
89
|
version: 0.15.4
|
90
90
|
type: :runtime
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- - ~>
|
94
|
+
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: 0.15.4
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: erubis
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
|
-
- - ~>
|
101
|
+
- - "~>"
|
102
102
|
- !ruby/object:Gem::Version
|
103
103
|
version: 2.7.0
|
104
104
|
type: :runtime
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
|
-
- - ~>
|
108
|
+
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: 2.7.0
|
111
111
|
- !ruby/object:Gem::Dependency
|
@@ -140,14 +140,14 @@ dependencies:
|
|
140
140
|
name: colorize
|
141
141
|
requirement: !ruby/object:Gem::Requirement
|
142
142
|
requirements:
|
143
|
-
- - ~>
|
143
|
+
- - "~>"
|
144
144
|
- !ruby/object:Gem::Version
|
145
145
|
version: 0.5.8
|
146
146
|
type: :runtime
|
147
147
|
prerelease: false
|
148
148
|
version_requirements: !ruby/object:Gem::Requirement
|
149
149
|
requirements:
|
150
|
-
- - ~>
|
150
|
+
- - "~>"
|
151
151
|
- !ruby/object:Gem::Version
|
152
152
|
version: 0.5.8
|
153
153
|
- !ruby/object:Gem::Dependency
|
@@ -382,17 +382,17 @@ require_paths:
|
|
382
382
|
- lib
|
383
383
|
required_ruby_version: !ruby/object:Gem::Requirement
|
384
384
|
requirements:
|
385
|
-
- -
|
385
|
+
- - ">="
|
386
386
|
- !ruby/object:Gem::Version
|
387
387
|
version: '0'
|
388
388
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
389
389
|
requirements:
|
390
|
-
- -
|
390
|
+
- - ">="
|
391
391
|
- !ruby/object:Gem::Version
|
392
392
|
version: '0'
|
393
393
|
requirements: []
|
394
394
|
rubyforge_project:
|
395
|
-
rubygems_version: 2.4.
|
395
|
+
rubygems_version: 2.4.1
|
396
396
|
signing_key:
|
397
397
|
specification_version: 4
|
398
398
|
summary: DTK CLI client for DTK server interaction.
|