Class: DTK::Client::Developer
- Inherits:
-
CommandBaseThor
- Object
- Thor
- CommandBaseThor
- DTK::Client::Developer
- Defined in:
- lib/commands/thor/developer.rb
Constant Summary collapse
- MATCH_FILE_NAME =
/[a-zA-Z0-9_]+\.[a-zA-Z]+$/- GIT_LOG_LOCATION =
File.('../../../lib/git-logs/git.log', File.dirname(__FILE__))
- PROJECT_ROOT =
File.('../../../', File.dirname(__FILE__))
Constants inherited from CommandBaseThor
CommandBaseThor::ALT_IDENTIFIER_SEPARATOR, CommandBaseThor::EXTENDED_TIMEOUT, CommandBaseThor::HIDE_FROM_BASE_CONTEXT, CommandBaseThor::TIME_DIFF
Constants included from CommandHelperMixin
Constants included from ReparseMixin
ReparseMixin::YamlDTKMetaFiles
Constants included from Poller
Constants inherited from Thor
Thor::HIDE_FROM_BASE_CONTEXT_HELP
Instance Method Summary collapse
- #apply_param_set(context_params) ⇒ Object
- #commits(context_params) ⇒ Object
- #content(context_params) ⇒ Object
- #remove_from_system(context_params) ⇒ Object
- #run_agent(context_params) ⇒ Object
- #upload_agent(context_params) ⇒ Object
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
Methods included from ReparseMixin
Methods included from PushCloneChangesMixin
Methods included from CommandBaseThor::CommonOptionDefs::ClassMixin
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
Instance Method Details
#apply_param_set(context_params) ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/commands/thor/developer.rb', line 95 def apply_param_set(context_params) assembly_id,path = context_params.retrieve_arguments([:option_1!,:option_2!],method_argument_names) av_pairs = JSON.parse(File.open(path).read) av_pairs.each do |a,v| post_body = { :assembly_id => assembly_id, :pattern => a, :value => v } response = post rest_url("assembly/set_attributes"), post_body if response.ok? pp response.data else return response end end Response::Ok.new() end |
#commits(context_params) ⇒ Object
116 117 118 119 120 121 122 123 124 |
# File 'lib/commands/thor/developer.rb', line 116 def commits(context_params) unless File.file?(GIT_LOG_LOCATION) raise DTK::Client::DtkError, "Git log file not found, contact DTK support team." end File.readlines(GIT_LOG_LOCATION).reverse.each do |line| puts line end end |
#content(context_params) ⇒ Object
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/commands/thor/developer.rb', line 127 def content(context_params) file_name = context_params.retrieve_arguments([:option_1!],method_argument_names) found_files = Dir["#{PROJECT_ROOT}/**/*.*"].select { |fname| fname.end_with?(file_name) } if found_files.empty? raise DTK::Client::DtkValidationError, "No files found with name '#{file_name}'." else found_files.each do |fname| header = "*********************** #{fname} ***********************" DTK::Client::OsUtil.print(header, :yellow) puts File.open(fname).readlines DTK::Client::OsUtil.print("*"*header.size, :yellow) end end end |
#remove_from_system(context_params) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/commands/thor/developer.rb', line 80 def remove_from_system(context_params) assembly_id = context_params.retrieve_arguments([:option_1!],method_argument_names) unless .force? # Ask user if really want to delete assembly, if not then return to dtk-shell without deleting what = "service" return unless Console.confirmation_prompt("Are you sure you want to remove #{what} '#{assembly_id}' and its nodes from the system"+'?') end response = post rest_url("assembly/remove_from_system"), {:assembly_id => assembly_id} # when changing context send request for getting latest assemblies instead of getting from cache @@invalidate_map << :service return response end |
#run_agent(context_params) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/commands/thor/developer.rb', line 63 def run_agent(context_params) service_name, agent_name, agent_method, action_params = context_params.retrieve_arguments([:option_1!, :option_2!, :option_3!, :option_4!], method_argument_names) action_params ||= "{}" action_params.gsub!("'",'"') response = post_file rest_url("developer/run_agent"), { :service_name => service_name, :agent_name => agent_name, :agent_method => agent_method, :agent_params => action_params } return response unless response.ok? action_results_id = response.data(:action_results_id) print_simple_results(action_results_id) nil end |
#upload_agent(context_params) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/commands/thor/developer.rb', line 33 def upload_agent(context_params) agent, node_pattern = context_params.retrieve_arguments([:option_1!, :option_2!], method_argument_names) nodes = post rest_url("node/list"), { :is_list_all => true } ids = [] # get all nodes which id starts with node_pattern nodes["data"].collect{|a| ids<<a["id"].to_i if a["id"].to_s.match(Regexp.new(node_pattern.to_s)) } raise DTK::Client::DtkValidationError, "Unable to find nodes to match this pattern: '#{node_pattern}'." if ids.empty? # if it doesn't contain extension upload both *.rb and *.ddl files = (agent.match(MATCH_FILE_NAME) ? [agent] : ["#{agent}.rb","#{agent}.ddl"]) # read require files and encode them request_body = {} files.each do |file_name| raise DTK::Client::DtkError, "Unable to load file: #{file_name}" unless File.exists?(file_name) # reason for this to file dues to previus match agent_name = file_name.match(MATCH_FILE_NAME)[0] File.open(file_name) { |file| request_body.store(agent_name,Base64.encode64(file.read)) } end # send as binary post request response = post_file rest_url("developer/inject_agent"), { :agent_files => request_body, :node_pattern => node_pattern, :node_list => ids } puts "Agent uploaded successfully!";return if response.ok? return response end |