class DTK::Client::Developer
Constants
- GIT_LOG_LOCATION
- MATCH_FILE_NAME
- PROJECT_ROOT
Public Instance Methods
apply_param_set(context_params)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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 options.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)
click to toggle source
# 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)
click to toggle source
# 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