Class: DTK::Client::Workspace

Inherits:
CommandBaseThor show all
Defined in:
lib/commands/thor/workspace.rb

Constant Summary

Constants inherited from CommandBaseThor

CommandBaseThor::ALT_IDENTIFIER_SEPARATOR, CommandBaseThor::EXTENDED_TIMEOUT, CommandBaseThor::HIDE_FROM_BASE_CONTEXT, CommandBaseThor::TIME_DIFF

Constants included from CommandHelperMixin

CommandHelperMixin::Loaded

Constants included from ReparseMixin

ReparseMixin::YamlDTKMetaFiles

Constants included from Poller

Poller::PERIOD_WAIT_TIME

Constants inherited from Thor

Thor::HIDE_FROM_BASE_CONTEXT_HELP

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from CommandBaseThor

action_on_revalidation_response, basename, create_context_arguments, execute_from_cli, generate_cached_id, get_cached_response, get_identifiers, get_usage_info, #help, #initialize, invalidate_entities, invisible_context_list, list_method_supported?, task_names, tiered_task_names, valid_id?

Methods included from CommandBase

#get, #get_connection, handle_argument_error, #post, #post_file, #rest_url, #rotate_args

Methods included from TaskStatusMixin

#list_task_info_aux, #task_status_aux, #task_status_stream

Methods included from Console

confirmation_prompt, confirmation_prompt_additional_options, confirmation_prompt_multiple_choice, confirmation_prompt_simple, unix_shell, wait_animation

Methods included from CommandHelperMixin

#Helper

Methods included from ReparseMixin

#reparse_aux

Methods included from PushCloneChangesMixin

#push_clone_changes_aux

Methods included from CommandBaseThor::CommonOptionDefs::ClassMixin

#version_method_option

Methods included from Poller

#poller_response, #print_response, #resolve_type

Methods inherited from Thor

get_alternative_identifiers, help, match_help_item_changes, overriden_help, printable_tasks, replace_if_matched!, set_context

Constructor Details

This class inherits a constructor from DTK::Client::CommandBaseThor

Class Method Details

.all_childrenObject

this includes children of children



120
121
122
123
# File 'lib/commands/thor/workspace.rb', line 120

def self.all_children()
  # [:node, :component, :attribute]
  [:node]
end

.extended_contextObject

using extended_context when we want to use autocomplete from other context e.g. we are in assembly/apache context and want to create-component we will use extended context to add component-templates to autocomplete



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/commands/thor/workspace.rb', line 65

def self.extended_context()
  {
    :context => {
      :add_component => "component_template",
      :create_node => "node_template",
      :create_node_group => "node_template",
      :add_component_dependency => "component_template",
      :set_target => 'target'
    },
    :command => {
      :edit_component_module => {
        :endpoint => "assembly",
        :url => "assembly/info_about",
        :opts => {:subtype=>"instance", :about=>"modules"}
      },
      :push_component_module_updates => {
        :endpoint => "assembly",
        :url => "assembly/info_about",
        :opts => {:subtype=>"instance", :about=>"modules"}
      },
      :delete_node => {
        :endpoint => "assembly",
        :url => "assembly/get_nodes_without_node_groups"
      },
      :delete_node_group => {
        :endpoint => "assembly",
        :url => "assembly/get_node_groups"
      },
      :pull_base_component_module => {
        :endpoint => "assembly",
        :url => "assembly/info_about",
        :opts => {:subtype=>"instance", :about=>"modules"}
      },
      :action_info => {
        :endpoint => "assembly",
        :url => "assembly/task_action_list"
      },
      :exec => {
        :endpoint => "assembly",
        :url => "assembly/list_actions"
      },
      :exec_sync => {
        :endpoint => "assembly",
        :url => "assembly/list_actions"
      }
      # TODO: DEPRECATE execute_workflow
      # :execute_workflow => {
      #   :endpoint => "assembly",
      #   :url => "assembly/task_action_list"
      # }
    }
  }
end

.invisible_contextObject



58
59
60
# File 'lib/commands/thor/workspace.rb', line 58

def self.invisible_context()
  [:node]
end

.multi_context_childrenObject



125
126
127
# File 'lib/commands/thor/workspace.rb', line 125

def self.multi_context_children()
  [[:utils],[:node, :utils]]
end

.override_allowed_methodsObject

:all => include both for commands with command and identifier :command_only => only on command level :identifier_only => only on identifier level for given entity (command)



144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
# File 'lib/commands/thor/workspace.rb', line 144

def self.override_allowed_methods()
  return DTK::Shell::OverrideTasks.new({
    :all => {
      :node      => [
        # ['delete-component',"delete-component COMPONENT-ID [-y]","# Delete component from assembly's node"],
        # ['list-attributes',"list-attributes","# List attributes associated with workspace's node."],
        # ['list-components',"list-components","# List components associated with workspace's node."]
      ],
      :component => [
        ['list-attributes',"list-attributes","# List attributes associated with given component."]
      ]
    },
    :command_only => {
      :attribute => [
        ['list-attributes',"list-attributes","# List attributes."]
      ],
      :node => [
        # ['delete',"delete NAME/ID [-y] ","# Delete component from workspace."],
        ['delete',"delete NODE-NAME/ID [-y] ","# Delete node, terminating it if the node has been spun up."],
        ['list',"list","# List nodes."]
      ],
      :component => [
        ['delete',"delete COMPONENT-NAME/ID [-y] ","# Delete component from workspace."],
        ['list-components',"list-components","# List components."]
      ],
      :utils => [
# TODO: DTK-2027 might subsume by the dtk actions; currently server changes does not support this command
#            ['execute-tests',"execute-tests [--component COMPONENT-NAME] [--timeout TIMEOUT]","# Execute tests. --component filters execution per component, --timeout changes default execution timeout."],
        ['get-netstats',"get-netstats","# Get netstats."],
        ['get-ps',"get-ps [--filter PATTERN]","# Get ps."],
        ['grep',"grep LOG-PATH NODE-ID-PATTERN GREP-PATTERN [--first]","# Grep log from multiple nodes. --first option returns first match (latest log entry)."],
        ['tail',"tail LOG-PATH NODE-NAME  [REGEX-PATTERN] [--more]","# Tail specified number of lines from log. CTRL+C to quit."]
      ]
    },
    :identifier_only => {
      :node => [
        ['add-component',"add-component COMPONENT","# Add a component to the node."],
        ['delete-component',"delete-component COMPONENT-NAME [-y]","# Delete component from workspace's node"],
        ['info',"info","# Return info about node instance belonging to given workspace."],
        # ['link-attributes', "link-attributes TARGET-ATTR-TERM SOURCE-ATTR-TERM", "# Set TARGET-ATTR-TERM to SOURCE-ATTR-TERM."],
        ['list-attributes',"list-attributes","# List attributes associated with workspace's node."],
        ['list-components',"list-components","# List components associated with workspace's node."],
        ['set-attribute',"set-attribute ATTRIBUTE-NAME [VALUE] [-u]","# (Un)Set attribute value. The option -u will unset the attribute's value."],
        ['start', "start", "# Start node instance."],
        ['stop', "stop", "# Stop node instance."],
        ['ssh', "ssh REMOTE-USER [-i PATH-TO-PEM]","# SSH into node, optional parameters are path to identity file."]
      ],

      :component => [
        ['info',"info","# Return info about component instance belonging to given node."],
        ['edit',"edit","# Edit component module related to given component."],
        # ['edit-dsl',"edit-dsl","# Edit component module dsl file related to given component."],
        ['link-components',"link-components ANTECEDENT-CMP-NAME [DEPENDENCY-NAME]","#Link components to satisfy component dependency relationship."],
        ['list-component-links',"list-component-links","# List component's links to other components."]
        #['unlink-components',"unlink-components SERVICE-TYPE","# Delete service link on component."]
        # ['create-attribute',"create-attribute SERVICE-TYPE DEP-ATTR ARROW BASE-ATTR","# Create an attribute to service link."],
      ],
      :attribute => [
        ['info',"info","# Return info about attribute instance belonging to given component."]
      ]
    }
  }, [:utils])
end

.pretty_print_colsObject



50
51
52
# File 'lib/commands/thor/workspace.rb', line 50

def self.pretty_print_cols()
  PPColumns.get(:assembly)
end

.valid_child?(name_of_sub_context) ⇒ Boolean

Returns:

  • (Boolean)


129
130
131
# File 'lib/commands/thor/workspace.rb', line 129

def self.valid_child?(name_of_sub_context)
  return Workspace.valid_children().include?(name_of_sub_context.to_sym)
end

.valid_childrenObject



54
55
56
# File 'lib/commands/thor/workspace.rb', line 54

def self.valid_children()
  [:utils]
end

.validation_list(context_params) ⇒ Object



133
134
135
# File 'lib/commands/thor/workspace.rb', line 133

def self.validation_list(context_params)
  get_cached_response(:workspace, "assembly/list_with_workspace", {})
end

.whoamiObject



46
47
48
# File 'lib/commands/thor/workspace.rb', line 46

def self.whoami()
  return :workspace, "assembly/list", {:subtype  => 'instance'}
end

Instance Method Details

#action_info(context_params) ⇒ Object



581
582
583
# File 'lib/commands/thor/workspace.rb', line 581

def action_info(context_params)
  action_info_aux(context_params)
end

#add_component(context_params) ⇒ Object



329
330
331
332
333
334
335
336
337
# File 'lib/commands/thor/workspace.rb', line 329

def add_component(context_params)
  response = create_component_aux(context_params)
  return response unless response.ok?

  @@invalidate_map << :service
  @@invalidate_map << :service_node

  response
end

#cancel_task(context_params) ⇒ Object



209
210
211
# File 'lib/commands/thor/workspace.rb', line 209

def cancel_task(context_params)
  cancel_task_aux(context_params)
end

#converge(context_params) ⇒ Object



254
255
256
257
258
# File 'lib/commands/thor/workspace.rb', line 254

def converge(context_params)
  opts = {}
  opts.merge!(:mode => :stream) if context_params.pure_cli_mode or options['stream-results']
  converge_aux(context_params, opts)
end

#create_assembly(context_params) ⇒ Object



293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
# File 'lib/commands/thor/workspace.rb', line 293

def create_assembly(context_params)
  workspace_id, service_module_full_name, assembly_template_name = context_params.retrieve_arguments([:workspace_id!,:option_1!,:option_2!],method_argument_names)

  # need default_namespace for create-assembly because need to check if local service-module directory existst in promote_assembly_aux
  resp = post rest_url("namespace/default_namespace_name")
  return resp unless resp.ok?
  default_namespace = resp.data

  opts = {:default_namespace => default_namespace}
  opts.merge!(:description => options.description) if options.description
  response = promote_assembly_aux(:create,workspace_id,service_module_full_name,assembly_template_name,opts)
  return response unless response.ok?

  if options.purge?
    response = purge_aux(context_params)
    return response unless response.ok?
  end

  @@invalidate_map << :assembly
  @@invalidate_map << :service

  Response::Ok.new()
end

#create_attribute(context_params) ⇒ Object



321
322
323
# File 'lib/commands/thor/workspace.rb', line 321

def create_attribute(context_params)
  create_attribute_aux(context_params)
end

#create_node(context_params) ⇒ Object



341
342
343
344
345
346
347
348
349
350
351
352
353
354
# File 'lib/commands/thor/workspace.rb', line 341

def create_node(context_params)
  response = create_node_aux(context_params)
  return response unless response.ok?

  @@invalidate_map << :assembly
  @@invalidate_map << :assembly_node
  @@invalidate_map << :service
  @@invalidate_map << :service_node
  @@invalidate_map << :workspace
  @@invalidate_map << :workspace_node

  message = "Created node '#{response.data["display_name"]}'."
  DTK::Client::OsUtil.print(message, :yellow)
end

#create_node_group(context_params) ⇒ Object



358
359
360
361
362
363
364
365
366
367
368
369
370
371
# File 'lib/commands/thor/workspace.rb', line 358

def create_node_group(context_params)
  response = create_node_group_aux(context_params)
  return response unless response.ok?

  @@invalidate_map << :assembly
  @@invalidate_map << :assembly_node
  @@invalidate_map << :service
  @@invalidate_map << :service_node
  @@invalidate_map << :workspace
  @@invalidate_map << :workspace_node

  message = "Created node group '#{response.data["display_name"]}'."
  DTK::Client::OsUtil.print(message, :yellow)
end

#delete(context_params) ⇒ Object



380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
# File 'lib/commands/thor/workspace.rb', line 380

def delete(context_params)
  if context_params.is_last_command_eql_to?(:node)
    response = delete_node_aux(context_params)
    @@invalidate_map << :service_node

    response
  elsif context_params.is_last_command_eql_to?(:component)
    response = delete_component_aux(context_params)
    return response unless response.ok?
    @@invalidate_map << :service_node_component

    response
  end
  # delete_aux(context_params)
end

#delete_component(context_params) ⇒ Object



399
400
401
402
403
404
405
406
407
# File 'lib/commands/thor/workspace.rb', line 399

def delete_component(context_params)
  response = delete_component_aux(context_params)

  @@invalidate_map << :service
  @@invalidate_map << :service_node
  @@invalidate_map << :service_node_component

  return response
end

#delete_node(context_params) ⇒ Object



412
413
414
415
416
417
418
419
420
421
422
423
# File 'lib/commands/thor/workspace.rb', line 412

def delete_node(context_params)
  response = delete_node_aux(context_params)

  @@invalidate_map << :assembly
  @@invalidate_map << :assembly_node
  @@invalidate_map << :service
  @@invalidate_map << :service_node
  @@invalidate_map << :workspace
  @@invalidate_map << :workspace_node

  return response
end

#delete_node_group(context_params) ⇒ Object



427
428
429
430
431
432
433
434
435
436
437
438
# File 'lib/commands/thor/workspace.rb', line 427

def delete_node_group(context_params)
  response = delete_node_group_aux(context_params)

  @@invalidate_map << :assembly
  @@invalidate_map << :assembly_node
  @@invalidate_map << :service
  @@invalidate_map << :service_node
  @@invalidate_map << :workspace
  @@invalidate_map << :workspace_node

  return response
end

#destroy_and_reset_nodes(context_params) ⇒ Object



614
615
616
# File 'lib/commands/thor/workspace.rb', line 614

def destroy_and_reset_nodes(context_params)
  destroy_and_reset_nodes_aux(context_params)
end

#edit_action(context_params) ⇒ Object



457
458
459
# File 'lib/commands/thor/workspace.rb', line 457

def edit_action(context_params)
  edit_or_create_workflow_aux(context_params)
end

#edit_attributes(context_params) ⇒ Object



465
466
467
468
469
470
471
472
473
474
475
476
# File 'lib/commands/thor/workspace.rb', line 465

def edit_attributes(context_params)
  response = edit_attributes_aux(context_params)

  @@invalidate_map << :assembly
  @@invalidate_map << :assembly_node
  @@invalidate_map << :service
  @@invalidate_map << :service_node
  @@invalidate_map << :workspace
  @@invalidate_map << :workspace_node

  response
end

#edit_component_module(context_params) ⇒ Object



446
447
448
# File 'lib/commands/thor/workspace.rb', line 446

def edit_component_module(context_params)
  edit_module_aux(context_params)
end

#exec(context_params) ⇒ Object



219
220
221
# File 'lib/commands/thor/workspace.rb', line 219

def exec(context_params)
  exec_aux(context_params)
end

#exec_sync(context_params) ⇒ Object



224
225
226
# File 'lib/commands/thor/workspace.rb', line 224

def exec_sync(context_params)
  exec_sync_aux(context_params)
end

#get_netstats(context_params) ⇒ Object



480
481
482
# File 'lib/commands/thor/workspace.rb', line 480

def get_netstats(context_params)
  get_netstats_aux(context_params)
end

#get_ps(context_params) ⇒ Object



498
499
500
# File 'lib/commands/thor/workspace.rb', line 498

def get_ps(context_params)
  get_ps_aux(context_params)
end

#grant_access(context_params) ⇒ Object



511
512
513
# File 'lib/commands/thor/workspace.rb', line 511

def grant_access(context_params)
  grant_access_aux(context_params)
end

#grep(context_params) ⇒ Object



505
506
507
# File 'lib/commands/thor/workspace.rb', line 505

def grep(context_params)
  grep_aux(context_params)
end

#info(context_params) ⇒ Object



527
528
529
# File 'lib/commands/thor/workspace.rb', line 527

def info(context_params)
  info_aux(context_params)
end


532
533
534
# File 'lib/commands/thor/workspace.rb', line 532

def link_attributes(context_params)
  link_attributes_aux(context_params)
end


374
375
376
# File 'lib/commands/thor/workspace.rb', line 374

def link_components(context_params)
  link_components_aux(context_params)
end

#list(context_params) ⇒ Object



537
538
539
540
541
# File 'lib/commands/thor/workspace.rb', line 537

def list(context_params)
  if context_params.is_last_command_eql_to?(:node)
    list_nodes_aux(context_params)
  end
end

#list_actions(context_params) ⇒ Object



587
588
589
# File 'lib/commands/thor/workspace.rb', line 587

def list_actions(context_params)
  list_actions_aux(context_params)
end

#list_attributes(context_params) ⇒ Object



550
551
552
# File 'lib/commands/thor/workspace.rb', line 550

def list_attributes(context_params)
  list_attributes_aux(context_params)
end


566
567
568
# File 'lib/commands/thor/workspace.rb', line 566

def list_component_links(context_params)
  list_component_links_aux(context_params)
end

#list_component_modules(context_params) ⇒ Object



571
572
573
# File 'lib/commands/thor/workspace.rb', line 571

def list_component_modules(context_params)
  list_modules_aux(context_params)
end

#list_components(context_params) ⇒ Object



556
557
558
# File 'lib/commands/thor/workspace.rb', line 556

def list_components(context_params)
  list_components_aux(context_params)
end

#list_nodes(context_params) ⇒ Object



561
562
563
# File 'lib/commands/thor/workspace.rb', line 561

def list_nodes(context_params)
  list_nodes_aux(context_params)
end

#list_ssh_access(context_params) ⇒ Object



522
523
524
# File 'lib/commands/thor/workspace.rb', line 522

def list_ssh_access(context_params)
  list_ssh_access_aux(context_params)
end

#list_tasks(context_params) ⇒ Object



576
577
578
# File 'lib/commands/thor/workspace.rb', line 576

def list_tasks(context_params)
  list_tasks_aux(context_params)
end

#list_violations(context_params) ⇒ Object



597
598
599
# File 'lib/commands/thor/workspace.rb', line 597

def list_violations(context_params)
  list_violations_aux(context_params)
end


602
603
604
# File 'lib/commands/thor/workspace.rb', line 602

def print_includes(context_params)
  print_includes_aux(context_params)
end

#pull_base_component_module(context_params) ⇒ Object



269
270
271
# File 'lib/commands/thor/workspace.rb', line 269

def pull_base_component_module(context_params)
  pull_base_component_module_aux(context_params)
end

#purge(context_params) ⇒ Object



608
609
610
# File 'lib/commands/thor/workspace.rb', line 608

def purge(context_params)
  purge_aux(context_params)
end

#push_assembly_updates(context_params) ⇒ Object



274
275
276
277
278
279
280
281
282
283
284
285
# File 'lib/commands/thor/workspace.rb', line 274

def push_assembly_updates(context_params)
  workspace_id, qualified_assembly_name = context_params.retrieve_arguments([:workspace_id!,:option_1!],method_argument_names)
  if qualified_assembly_name =~ /(^[^\/]*)\/([^\/]*$)/
    service_module_name, assembly_template_name = [$1,$2]
  else
    raise DtkError,"The term (#{qualified_assembly_name}) must have form SERVICE-MODULE-NAME/ASSEMBLY-NAME"
  end
  response = promote_assembly_aux(:update,workspace_id, service_module_name, assembly_template_name)
  return response unless response.ok?
  @@invalidate_map << :assembly
  Response::Ok.new()
end

#push_component_module_updates(context_params) ⇒ Object



262
263
264
# File 'lib/commands/thor/workspace.rb', line 262

def push_component_module_updates(context_params)
  push_module_updates_aux(context_params)
end

#revoke_access(context_params) ⇒ Object



517
518
519
# File 'lib/commands/thor/workspace.rb', line 517

def revoke_access(context_params)
  revoke_access_aux(context_params)
end

#set_attribute(context_params) ⇒ Object



627
628
629
630
631
632
633
634
635
636
637
638
639
# File 'lib/commands/thor/workspace.rb', line 627

def set_attribute(context_params)
  response = set_attribute_aux(context_params)
  return response unless response.ok?

  @@invalidate_map << :assembly
  @@invalidate_map << :assembly_node
  @@invalidate_map << :service
  @@invalidate_map << :service_node
  @@invalidate_map << :workspace
  @@invalidate_map << :workspace_node

  response
end

#set_required_attributes(context_params) ⇒ Object



642
643
644
645
# File 'lib/commands/thor/workspace.rb', line 642

def set_required_attributes(context_params)
  workspace_id = context_params.retrieve_arguments([:workspace_id!],method_argument_names)
  set_required_attributes_aux(workspace_id,:assembly,:instance)
end

#set_target(context_params) ⇒ Object



619
620
621
# File 'lib/commands/thor/workspace.rb', line 619

def set_target(context_params)
  set_target_aux(context_params)
end

#start(context_params) ⇒ Object



649
650
651
# File 'lib/commands/thor/workspace.rb', line 649

def start(context_params)
  start_aux(context_params)
end

#stop(context_params) ⇒ Object



655
656
657
# File 'lib/commands/thor/workspace.rb', line 655

def stop(context_params)
  stop_aux(context_params)
end

#tail(context_params) ⇒ Object



662
663
664
# File 'lib/commands/thor/workspace.rb', line 662

def tail(context_params)
  tail_aux(context_params)
end

#task_action_detail(context_params) ⇒ Object



681
682
683
# File 'lib/commands/thor/workspace.rb', line 681

def task_action_detail(context_params)
  task_action_detail_aw_aux(context_params)
end

#task_status(context_params) ⇒ Object



676
677
678
# File 'lib/commands/thor/workspace.rb', line 676

def task_status(context_params)
  task_status_aw_aux(context_params)
end


441
442
443
# File 'lib/commands/thor/workspace.rb', line 441

def unlink_components(context_params)
  unlink_components_aux(context_params)
end