class DTK::Client::Service

Public Class Methods

all_children() click to toggle source

this includes children of children

# File lib/commands/thor/service.rb, line 142
def self.all_children()
  # [:node, :component, :attribute]
  [:node]
end
extended_context() click to toggle source

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

# File lib/commands/thor/service.rb, line 84
def self.extended_context()
  {
    :context => {
      :create_node => "node_template",
      :create_node_group => "node_template",
      :add_component_dependency => "component_template"
    },
    :command => {
      :add_component => {
        :endpoint => "component_template",
        :url => "component/list",
        :opts => {:subtype=>"template", :ignore => "test_module", :hide_assembly_cmps => "true"}
      },
      :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_context() click to toggle source
# File lib/commands/thor/service.rb, line 77
def self.invisible_context()
  [:node]
end
multi_context_children() click to toggle source
# File lib/commands/thor/service.rb, line 147
def self.multi_context_children()
  [[:utils],[:node, :utils]]
end
override_allowed_methods() click to toggle source

: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)

# File lib/commands/thor/service.rb, line 166
    def self.override_allowed_methods()
      override_methods = {
        :all => {
          # :node => [
            # ['delete-component',"delete-component COMPONENT-ID","# Delete component from assembly's node"],
            # ['list-components',"list-components","# List components associated with assembly's node."],
            # ['list-attributes',"list-attributes","# List attributes associated with assembly'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 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 log from specified node. CTRL+C to quit."]
          ],
          :node_utils => [
            ['get-netstats',"get-netstats","# Get netstats."],
            ['get-ps',"get-ps [--filter PATTERN]","# Get ps."],
            ['grep',"grep LOG-PATH GREP-PATTERN [--first]","# Grep log from node. --first option returns first match (latest log entry)."],
            ['tail',"tail LOG-PATH [REGEX-PATTERN] [--more]","# Tail log from node. 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 service's node"],
            ['info',"info","# Return info about node instance belonging to given workspace."],
            ['list-attributes',"list-attributes","# List attributes associated with service's node."],
            ['list-components',"list-components","# List components associated with service'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."]
          ],
          :node_group => [
            ['start', "start", "# 2Start node instance."],
            ['stop', "stop", "# 2Stop node instance."],
            ['ssh', "ssh REMOTE-USER [-i PATH-TO-PEM]","# 2SSH 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."],
            ['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."]
          ],
          :attribute => [
            ['info',"info","# Return info about attribute instance belonging to given component."]
          ]
        }
      }

      if DTK::Configuration.get(:development_mode)
        override_methods[:identifier_only][:node] << ['test-action-agent', "test-action-agent BASH-COMMAND-LINE", "Run bash command on test action agent"]
      end

      return DTK::Shell::OverrideTasks.new(override_methods, [:utils])
    end
pretty_print_cols() click to toggle source
# File lib/commands/thor/service.rb, line 69
def self.pretty_print_cols()
  PPColumns.get(:assembly)
end
valid_child?(name_of_sub_context) click to toggle source
# File lib/commands/thor/service.rb, line 151
def self.valid_child?(name_of_sub_context)
  return Service.valid_children().include?(name_of_sub_context.to_sym)
end
valid_children() click to toggle source
# File lib/commands/thor/service.rb, line 73
def self.valid_children()
  [:utils]
end
validation_list(context_params) click to toggle source
# File lib/commands/thor/service.rb, line 155
def self.validation_list(context_params)
  get_cached_response(:service, "assembly/list", {})
end
whoami() click to toggle source
# File lib/commands/thor/service.rb, line 65
def self.whoami()
  return :service, "assembly/list", {:subtype  => 'instance'}
end

Public Instance Methods

action_info(context_params) click to toggle source
# File lib/commands/thor/service.rb, line 511
def action_info(context_params)
  action_info_aux(context_params)
end
add_component(context_params) click to toggle source
# File lib/commands/thor/service.rb, line 703
def add_component(context_params)
  response = create_component_aux(context_params)

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

  response
end
cancel_task(context_params) click to toggle source
# File lib/commands/thor/service.rb, line 261
def cancel_task(context_params)
  cancel_task_aux(context_params)
end
converge(context_params) click to toggle source
# File lib/commands/thor/service.rb, line 332
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) click to toggle source
# File lib/commands/thor/service.rb, line 269
def create_assembly(context_params)
  if options.description?
     if context_params.method_arguments.length > 2
       raise DtkError, "The number of arguments is invalid. If you are using -m with multiple words please put them under quotation marks"
     end
  end

  assembly_id, service_module_name, assembly_template_name = context_params.retrieve_arguments([:service_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}
  if description = options.description
    description = "#{description}"
    opts.merge!(:description => description)
  end

  response = promote_assembly_aux(:create,assembly_id,service_module_name,assembly_template_name,opts)
  return response unless response.ok?

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

  Response::Ok.new()
end
create_attribute(context_params) click to toggle source
# File lib/commands/thor/service.rb, line 651
def create_attribute(context_params)
  create_attribute_aux(context_params)
end
create_node(context_params) click to toggle source
# File lib/commands/thor/service.rb, line 659
def create_node(context_params)
  response = create_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 unless response.ok?

  message = "Created node '#{response.data["display_name"]}'."
  OsUtil.print(message, :yellow)
end
create_node_group(context_params) click to toggle source
# File lib/commands/thor/service.rb, line 679
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"]}'."
  OsUtil.print(message, :yellow)
end
create_workspace(context_params) click to toggle source
# File lib/commands/thor/service.rb, line 924
def create_workspace(context_params)
  response = create_workspace_aux(context_params)
  return response unless response.ok?

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

  yaml_response = YAML.load(response.data)
  if workspace_instance = yaml_response['new_workspace_instance']
    MainContext.get_context.change_context(["/service/#{workspace_instance['name']}"])
  else
    fail DtkError.new('Workspace instance is not staged properly, please try again!')
  end

  response
end
delete(context_params) click to toggle source
# File lib/commands/thor/service.rb, line 746
def delete(context_params)
  if context_params.is_last_command_eql_to?(:node)
    response = delete_node_aux(context_params)
    return response unless response.ok?
    @@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 << :assembly_node_component

    response
  end
end
delete_and_destroy(context_params) click to toggle source
# File lib/commands/thor/service.rb, line 621
def delete_and_destroy(context_params)
  response = delete_and_destroy_aux(context_params)
  @@invalidate_map << :assembly
  @@invalidate_map << :assembly_node
  @@invalidate_map << :service
  @@invalidate_map << :service_node
  @@invalidate_map << :service_module
  response
end
delete_component(context_params) click to toggle source
# File lib/commands/thor/service.rb, line 771
def delete_component(context_params)
  response = delete_component_aux(context_params)

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

  response
end
delete_node(context_params) click to toggle source
# File lib/commands/thor/service.rb, line 716
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) click to toggle source
# File lib/commands/thor/service.rb, line 732
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
deploy(context_params) click to toggle source

method_option :settings, :type => :string, :aliases => '-s'

# File lib/commands/thor/service.rb, line 886
def deploy(context_params)
  response = deploy_aux(context_params)
  return response unless response.ok?

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

  response
end
deploy_target(context_params) click to toggle source

method_option :settings, :type => :string, :aliases => '-s'

# File lib/commands/thor/service.rb, line 868
def deploy_target(context_params)
  response = deploy_aux(context_params)
  return response unless response.ok?

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

  response
end
destroy_and_reset_nodes(context_params) click to toggle source
# File lib/commands/thor/service.rb, line 244
def destroy_and_reset_nodes(context_params)
  destroy_and_reset_nodes_aux(context_params)
end
edit_action(context_params) click to toggle source
# File lib/commands/thor/service.rb, line 394
def edit_action(context_params)
  edit_or_create_workflow_aux(context_params)
end
edit_attributes(context_params) click to toggle source
# File lib/commands/thor/service.rb, line 402
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

  response
end
edit_component_module(context_params) click to toggle source
# File lib/commands/thor/service.rb, line 383
def edit_component_module(context_params)
  edit_module_aux(context_params)
end
exec(context_params) click to toggle source
# File lib/commands/thor/service.rb, line 298
def exec(context_params)
  exec_aux(context_params)
end
exec_sync(context_params) click to toggle source
# File lib/commands/thor/service.rb, line 303
def exec_sync(context_params)
  exec_sync_aux(context_params)
end
get_assembly_name(assembly_id) click to toggle source
# File lib/commands/thor/service.rb, line 44
def get_assembly_name(assembly_id)
  get_name_from_id_helper(assembly_id)
end
get_netstats(context_params) click to toggle source
# File lib/commands/thor/service.rb, line 783
def get_netstats(context_params)
  get_netstats_aux(context_params)
end
get_ps(context_params) click to toggle source
# File lib/commands/thor/service.rb, line 801
def get_ps(context_params)
  get_ps_aux(context_params)
end
grant_access(context_params) click to toggle source
# File lib/commands/thor/service.rb, line 592
def grant_access(context_params)
  grant_access_aux(context_params)
end
grep(context_params) click to toggle source
# File lib/commands/thor/service.rb, line 821
def grep(context_params)
  grep_aux(context_params)
end
info(context_params) click to toggle source
# File lib/commands/thor/service.rb, line 608
def info(context_params)
  info_aux(context_params)
end
list(context_params) click to toggle source
# File lib/commands/thor/service.rb, line 521
def list(context_params)
  assembly_id, node_id, component_id, attribute_id, about = context_params.retrieve_arguments([:service_id,:node_id,:component_id,:attribute_id,:option_1],method_argument_names)
  detail_to_include = nil

  if about
    case about
      when "nodes"
        data_type = :node
      when "components"
        data_type = :component
        detail_to_include = [:component_dependencies]
      when "attributes"
        data_type = :attribute
        detail_to_include = [:attribute_links]
      when "tasks"
        data_type = :task
      else
        raise_validation_error_method_usage('list')
    end
  end

  post_body = {
    :assembly_id => assembly_id,
    :node_id => node_id,
    :component_id => component_id,
    :subtype     => 'instance'
  }
  post_body.merge!(:detail_to_include => detail_to_include) if detail_to_include
  rest_endpoint = "assembly/info_about"

  if context_params.is_last_command_eql_to?(:attribute)
    raise DtkError, "Not supported command for current context level." if attribute_id
    about, data_type = get_type_and_raise_error_if_invalid(about, "attributes", ["attributes"])
  elsif context_params.is_last_command_eql_to?(:component)
    if component_id
      about, data_type = get_type_and_raise_error_if_invalid(about, "attributes", ["attributes"])
    else
      about, data_type = get_type_and_raise_error_if_invalid(about, "components", ["attributes", "components"])
    end
  elsif context_params.is_last_command_eql_to?(:node)
    if node_id
      about, data_type = get_type_and_raise_error_if_invalid(about, "components", ["attributes", "components"])
    else
      about, data_type = get_type_and_raise_error_if_invalid(about, "nodes", ["attributes", "components", "nodes"])
    end
  else
    if assembly_id
      about, data_type = get_type_and_raise_error_if_invalid(about, "nodes", ["attributes", "components", "nodes", "tasks"])
    else
      data_type = :assembly
      post_body = { :subtype  => 'instance', :detail_level => 'nodes',:include_namespaces => true}
      rest_endpoint = "assembly/list"
    end
  end

  post_body[:about] = about
  response = post rest_url(rest_endpoint), post_body

  # set render view to be used
  response.render_table(data_type)

  return response
end
list_actions(context_params) click to toggle source
# File lib/commands/thor/service.rb, line 345
def list_actions(context_params)
  list_actions_aux(context_params)
end
list_attributes(context_params) click to toggle source
# File lib/commands/thor/service.rb, line 485
def list_attributes(context_params)
  list_attributes_aux(context_params)
end
list_component_modules(context_params) click to toggle source
# File lib/commands/thor/service.rb, line 490
def list_component_modules(context_params)
  list_modules_aux(context_params)
end
list_components(context_params) click to toggle source
# File lib/commands/thor/service.rb, line 474
def list_components(context_params)
  list_components_aux(context_params)
end
list_diffs(context_params) click to toggle source
# File lib/commands/thor/service.rb, line 586
def list_diffs(context_params)
  list_remote_module_diffs(context_params)
end
list_nodes(context_params) click to toggle source
# File lib/commands/thor/service.rb, line 463
def list_nodes(context_params)
  list_nodes_aux(context_params)
end
list_ssh_access(context_params) click to toggle source
# File lib/commands/thor/service.rb, line 603
def list_ssh_access(context_params)
  list_ssh_access_aux(context_params)
end
list_tasks(context_params) click to toggle source
# File lib/commands/thor/service.rb, line 495
def list_tasks(context_params)
  list_tasks_aux(context_params)
end
list_violations(context_params) click to toggle source
# File lib/commands/thor/service.rb, line 501
def list_violations(context_params)
  list_violations_aux(context_params)
end
print_includes(context_params) click to toggle source
pull_base_component_module(context_params) click to toggle source
# File lib/commands/thor/service.rb, line 372
def pull_base_component_module(context_params)
  pull_base_component_module_aux(context_params)
end
push_assembly_updates(context_params) click to toggle source
# File lib/commands/thor/service.rb, line 350
def push_assembly_updates(context_params)
  assembly_id, qualified_assembly_name = context_params.retrieve_arguments([:service_id!, :option_1], method_argument_names)
  service_module_name, assembly_template_name =
    if qualified_assembly_name
      if qualified_assembly_name =~ /(^[^\/]*)\/([^\/]*$)/
        [$1,$2]
      else
        raise DtkError, "The term (#{qualified_assembly_name}) must have form SERVICE-MODULE-NAME/ASSEMBLY-NAME"
      end
    else
      [nil, nil]
    end

  response = promote_assembly_aux(:update, assembly_id, service_module_name, assembly_template_name, :use_module_namespace => true)
  return response unless response.ok?
  @@invalidate_map << :assembly
  Response::Ok.new()
end
push_component_module_updates(context_params) click to toggle source
# File lib/commands/thor/service.rb, line 378
def push_component_module_updates(context_params)
  push_module_updates_aux(context_params)
end
revoke_access(context_params) click to toggle source
# File lib/commands/thor/service.rb, line 598
def revoke_access(context_params)
  revoke_access_aux(context_params)
end
set_attribute(context_params) click to toggle source
# File lib/commands/thor/service.rb, line 635
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

  response
end
set_default_target(context_params) click to toggle source
# File lib/commands/thor/service.rb, line 836
def set_default_target(context_params)
  set_default_target_aux(context_params)
end
set_required_attributes(context_params) click to toggle source
# File lib/commands/thor/service.rb, line 806
def set_required_attributes(context_params)
  assembly_id = context_params.retrieve_arguments([:service_id!],method_argument_names)
  set_required_attributes_aux(assembly_id,:assembly,:instance)
end
set_required_attributes_and_converge(context_params) click to toggle source
# File lib/commands/thor/service.rb, line 897
def set_required_attributes_and_converge(context_params)
  begin
    response = set_required_attributes_converge_aux(context_params)
  rescue DtkError::InteractiveWizardError => e
    @@invalidate_map << :service
    @@invalidate_map << :assembly

    # if skip correction wizzard still go to newly created service instance
    if instance_name = (context_params.get_forwarded_options()||{})[:instance_name]
      MainContext.get_context.change_context(["/service/#{instance_name}"])
    end

    raise e
  end

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

  # if instance_name = opts[:instance_name]
  #   MainContext.get_context.change_context([instance_name])
  # end

  response
end
stage(context_params) click to toggle source
# File lib/commands/thor/service.rb, line 831
def stage(context_params)
  stage_aux(context_params)
end
stage_target(context_params) click to toggle source
# File lib/commands/thor/service.rb, line 849
def stage_target(context_params)
  response = stage_aux(context_params)
  return response unless response.ok?

  # when changing context send request for getting latest assemblies instead of getting from cache
  @@invalidate_map << :service
  @@invalidate_map << :assembly

  return response
end
start(context_params) click to toggle source
# File lib/commands/thor/service.rb, line 249
def start(context_params)
  start_aux(context_params)
end
stop(context_params) click to toggle source
# File lib/commands/thor/service.rb, line 255
def stop(context_params)
  stop_aux(context_params)
end
tail(context_params) click to toggle source
# File lib/commands/thor/service.rb, line 814
def tail(context_params)
  tail_aux(context_params)
end
task_action_detail(context_params) click to toggle source
# File lib/commands/thor/service.rb, line 458
def task_action_detail(context_params)
  task_action_detail_aw_aux(context_params)
end
task_status(context_params) click to toggle source
# File lib/commands/thor/service.rb, line 450
def task_status(context_params)
  response = task_status_aw_aux(context_params)
  @@invalidate_map << :service
  @@invalidate_map << :service_node
  response
end