Class: Cnvrg::CLI
Constant Summary collapse
- INSTALLATION_URLS =
{docker: "https://docs.docker.com/engine/installation/", jupyter: "http://jupyter.readthedocs.io/en/latest/install.html"}
- IP =
"localhost"
- PORT =
7654
Class Method Summary collapse
-
.is_thor_reserved_word?(word, type) ⇒ Boolean
Hackery.Take the run method away from Thor so that we can redefine it.
Instance Method Summary collapse
- #auth ⇒ Object
- #build(*cmd) ⇒ Object
- #check_pod_restart ⇒ Object
- #check_spot ⇒ Object
- #clone(project_url) ⇒ Object
- #clone_data(dataset_url, only_tree = false, commit = nil, query = nil, read = false, remote = false, flatten: false, relative: false, soft: false, threads: 15, cache_link: false) ⇒ Object
- #clone_data_query(dataset_url, query = nil, flatten = false, soft: false) ⇒ Object
- #collect_metrics ⇒ Object
- #commit_before_termination ⇒ Object
- #commit_image ⇒ Object
- #compare_experiments ⇒ Object
- #create_volume ⇒ Object
- #data_init_container(owner, dataset_slug, dataset_name) ⇒ Object
- #data_jump(*commit_sha1) ⇒ Object
- #data_put(dataset_url, files: [], dir: '', commit: '', chunk_size: 1000, force: false, override: false, threads: 15, message: nil, auto_cache: false, external_disk: nil) ⇒ Object
- #data_rm(dataset_url, regex_list: [], commit: '', message: nil, auto_cache: false, external_disk: nil) ⇒ Object
- #delete_data(dataset_slug) ⇒ Object
- #deploy(file_to_run, function) ⇒ Object
- #download(sync = false, ignore_list = "", in_exp = false) ⇒ Object
- #download_built_image(image_name, image_slug) ⇒ Object
- #download_cnvrg_image(image_name, secret) ⇒ Object
- #download_data(verbose, sync, path = Dir.pwd, in_dir = true) ⇒ Object
- #download_data_new(verbose = false, new_branch = false, sync = false, commit = nil, all_files = true) ⇒ Object
- #download_file_data(file_path, *dataset_path) ⇒ Object
- #download_in_git(*commit_sha1) ⇒ Object
- #download_tags_yaml ⇒ Object
- #end_commit_data(commit, success: true, uploaded_files: 0, sync: false) ⇒ Object
- #exec(*cmd) ⇒ Object
- #exec_remote(*cmd) ⇒ Object
- #experiments ⇒ Object
- #file_exists(file) ⇒ Object
- #get_machine ⇒ Object
- #get_owner_slug(url_or_slug) ⇒ Object
- #get_utilization ⇒ Object
- #git_clone(slug, owner) ⇒ Object
- #init_data(public, bucket: nil, title: nil) ⇒ Object
-
#initialize(*args) ⇒ CLI
constructor
A new instance of CLI.
- #install_python_libraries(*lib) ⇒ Object
- #install_system_libraries(*command_to_run) ⇒ Object
- #jump(commit_sha1) ⇒ Object
- #link ⇒ Object
- #link_git(project_url) ⇒ Object
- #list_commits ⇒ Object
- #list_dataset ⇒ Object
- #list_dataset_commits(dataset_url, commit_sha1: nil) ⇒ Object
- #list_files_dataset ⇒ Object
- #list_images ⇒ Object
- #list_machines ⇒ Object
- #login ⇒ Object
- #logout ⇒ Object
- #logs ⇒ Object
- #me ⇒ Object
-
#new(project_name) ⇒ Object
Projects.
- #notebook ⇒ Object
- #notebook_stop(notebook_slug) ⇒ Object
- #push(*name) ⇒ Object
- #queries ⇒ Object
- #query_files(query) ⇒ Object
- #remote_notebook ⇒ Object
- #remote_notebook_old ⇒ Object
- #revert_exp ⇒ Object
- #run(*cmd) ⇒ Object
- #run_notebook ⇒ Object
- #scan_datasets ⇒ Object
- #search_libraries(library) ⇒ Object
- #set_api_url(url) ⇒ Object
- #set_compression_path(*compression_path) ⇒ Object
- #set_data_url(dataset_url) ⇒ Object
- #set_default_owner ⇒ Object
- #set_remote_api_url(owner, current_user, url) ⇒ Object
- #set_remote_login(current_user, owner, url, email, secret) ⇒ Object
- #show ⇒ Object
- #show_libraries ⇒ Object
- #snap_data ⇒ Object
- #start_commit_data ⇒ Object
- #status ⇒ Object
- #sync(direct = true) ⇒ Object
- #sync_data_new(new_branch, force, verbose, commit, all_files, tags, parallel, chunk_size, init, message) ⇒ Object
- #sync_image(docker = false) ⇒ Object
- #unlink ⇒ Object
- #update_job_commit ⇒ Object
- #update_jupyter_token ⇒ Object
- #upload(link = false, sync = false, direct = false, ignore_list = "", in_exp = false, force = false, output_dir = "output", job_type = nil, job_slug = nil, suppress_exceptions = true, chunk_size = 1000) ⇒ Object
- #upload_cnvrg_image(image_path, image_name, secret) ⇒ Object
- #upload_data(sync = false, direct = false) ⇒ Object
- #upload_data_files(new_commit, files_list: []) ⇒ Object
- #upload_data_new(new_branch, verbose, sync, force, tags, chunk_size, message: nil, total_deleted: 0, total_downloaded: 0) ⇒ Object
- #upload_data_tar(ignore, verbose, sync, no_compression) ⇒ Object
- #upload_log ⇒ Object
- #verify_datasets(dataset_titles, timeout = nil) ⇒ Object
- #version ⇒ Object
Constructor Details
#initialize(*args) ⇒ CLI
Returns a new instance of CLI.
193 194 195 196 |
# File 'lib/cnvrg/cli.rb', line 193 def initialize(*args) super self.log_handler end |
Class Method Details
.is_thor_reserved_word?(word, type) ⇒ Boolean
Hackery.Take the run method away from Thor so that we can redefine it.
168 169 170 171 |
# File 'lib/cnvrg/cli.rb', line 168 def is_thor_reserved_word?(word, type) return false if word == "run" super end |
Instance Method Details
#auth ⇒ Object
453 454 455 456 457 458 459 460 461 462 463 464 465 |
# File 'lib/cnvrg/cli.rb', line 453 def auth token = ENV['CNVRG_TOKEN'] || exit(1) owner = ENV['CNVRG_OWNER'] || exit(1) user = ENV['CNVRG_USER'] || exit(1) api = ENV['CNVRG_API'] || exit(1) email = ENV['CNVRG_EMAIL'] || exit(1) netrc = Netrc.read netrc[Cnvrg::Helpers.netrc_domain] = email, token netrc.save set_owner(owner, user, api) end |
#build(*cmd) ⇒ Object
4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 |
# File 'lib/cnvrg/cli.rb', line 4430 def build(*cmd) begin verify_logged_in(false) log_start(__method__, args, ) working_dir = is_cnvrg_dir install_file = ["install"] || nil if !install_file.nil? commands = File.open(install_file).read.chop.gsub!("\n", ",").split(",") else commands = [cmd.join(" ")] end image = is_project_with_docker(working_dir) if image and image.is_docker container = image.get_container if !container say "Couldn't create container with image #{image.image_name}:#{image.image_tag}", Thor::Shell::Color::RED exit(1) end else say "Project is not configured with any image", Thor::Shell::Color::RED exit(1) end commands.each do |c| if c.include? "pip" c.sub("pip", "/opt/ds/bin/pip") end if c.include? "pip3" c.sub("pip3", "/opt/ds3/bin/pip3") end say "Running #{c}", Thor::Shell::Color::BLUE command = ["/bin/bash", "-lc", "#{c}"] res = container.exec(command, tty: false) if res[2] != 0 say "Could not run command: #{c}, #{res[1][0]}", Thor::Shell::Color::RED container.stop() log_end(0) exit(1) end say res[0].join("\n") image.store_image_build_commands(working_dir, c) end checks = Helpers.checkmark() say "Updating image", Thor::Shell::Color::BLUE # image.create_custom_image("",working_dir) container.stop() say "#{checks} Done", Thor::Shell::Color::GREEN log_end(0) rescue => e log_end(-1, e.) say "Error occurred, aborting", Thor::Shell::Color::RED if container container.stop() end rescue SignalException log_End(-1) if container container.stop() end say "\nAborting" exit(1) end end |
#check_pod_restart ⇒ Object
5118 5119 5120 5121 5122 5123 5124 5125 |
# File 'lib/cnvrg/cli.rb', line 5118 def check_pod_restart Cnvrg::CLI.new.log_start(__method__, args, ) @project = Project.new(owner: ENV['CNVRG_OWNER'], slug: ENV['CNVRG_PROJECT']) @project.check_job_pod_restart rescue => e Cnvrg::Logger.log_error(e) [false, false] end |
#check_spot ⇒ Object
468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 |
# File 'lib/cnvrg/cli.rb', line 468 def check_spot log_start(__method__, args, ) project_home = get_project_home @project = Project.new(project_home) ('Checking Spot Instance Status', Thor::Shell::Color::YELLOW) will_terminate = @project.spot_will_terminate if not will_terminate ("Not spot termination detected", Thor::Shell::Color::YELLOW) return end job_type, job_id = ENV['CNVRG_JOB_TYPE'], ENV['CNVRG_JOB_ID'] machine_activity = @project.get_machine_activity notify_thread = Thread.new do res = @project.send_restart_request(job_type: job_type, job_id: job_id, ma_id: machine_activity) while res.blank? res = @project.send_restart_request(job_type: job_type, job_id: job_id, ma_id: machine_activity) sleep(10) end end sync_force = job_type == "NotebookSession" ? false : true upload(false, false, true, '', true, sync_force , ENV['CNVRG_OUTPUT_DIR'], job_type, job_id) ('Spot instance is going to be terminated', Thor::Shell::Color::YELLOW) notify_thread.join end |
#clone(project_url) ⇒ Object
1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 |
# File 'lib/cnvrg/cli.rb', line 1897 def clone(project_url) begin verify_logged_in(false) log_start(__method__, args, ) url_parts = project_url.split("/") project_index = Cnvrg::Helpers.look_for_in_path(project_url, "projects") slug = url_parts[project_index + 1] owner = url_parts[project_index - 1] remote = ["remote"] || false soft = ["soft"] || false threads = [:threads] || Cnvrg::Helpers.parallel_threads response = Cnvrg::API.request("users/#{owner}/projects/#{slug}/get_project", 'GET') Cnvrg::CLI.is_response_success(response) response = JSON.parse response["result"] project_name = response["title"] git = response["git"] || false commit_to_clone = ["commit"] || nil ("Cloning #{project_name}", Thor::Shell::Color::BLUE) clone_resp = false project_home = Dir.pwd Project.stop_if_project_present(project_home, project_name, owner) if soft if remote and !git clone_resp = Project.clone_dir_remote(slug, owner, project_name,git) elsif git if remote clone_resp = Project.clone_dir_remote(slug, owner, project_name,git) else project_home += "/#{project_name}" clone_resp = Project.clone_dir(slug, owner, project_name,git) end else if (Dir.exists? project_name) # project_name = "#{project_name}_#{rand(1 .. 5000000000)}" # puts project_name ("Error: Conflict with dir #{project_name}", Thor::Shell::Color::RED) if no? "Sync to repository anyway? (current data might lost)", Thor::Shell::Color::YELLOW ("Remove dir in order to clone #{project_name}", Thor::Shell::Color::RED) exit(1) end end clone_resp = Project.clone_dir(slug, owner, project_name,git) project_home = Dir.pwd + "/" + project_name end if clone_resp @project = Project.new(project_home) @files = Cnvrg::Files.new(@project.owner, slug, project_home: project_home, project: @project) response = @project.clone(remote, commit_to_clone) Cnvrg::CLI.is_response_success response commit_sha1 = response["result"]["commit"] files = response["result"]["tree"].keys idx = {commit: response["result"]["commit"], tree: response["result"]["tree"]} ("Downloading files", Thor::Shell::Color::BLUE) = @files.(files.size, "Clone Progress") @files.download_files(files, commit_sha1, progress: , threads: threads) .finish Project.verify_cnvrgignore_exist(project_name, remote) Cnvrg::Logger.log_info("Generating idx") @project.set_idx(idx) ("Done") ("Downloaded #{files.size} files") end end end |
#clone_data(dataset_url, only_tree = false, commit = nil, query = nil, read = false, remote = false, flatten: false, relative: false, soft: false, threads: 15, cache_link: false) ⇒ Object
873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 |
# File 'lib/cnvrg/cli.rb', line 873 def clone_data(dataset_url, only_tree=false, commit=nil, query=nil, read=false, remote=false, flatten: false, relative: false, soft: false, threads: 15, cache_link: false) begin verify_logged_in(false) log_start(__method__, args, ) commit = ["commit"] || commit only_tree = ["only_tree"] || only_tree read = ["read"] || read || false remote = ["remote"] || remote || false query = ['query'].presence || query.presence soft = ['soft'] || soft if query.present? return clone_data_query(dataset_url, query, flatten, soft: soft) end url_parts = dataset_url.split("/") project_index = Cnvrg::Helpers.look_for_in_path(dataset_url, "datasets") slug = url_parts[project_index + 1] owner = url_parts[project_index - 1] @dataset = Dataset.new(dataset_url: dataset_url) response = {} response["result"] = @dataset.get_dataset(commit: commit, query: query) dataset_name = response["result"]["name"] dataset_home = Dir.pwd+"/"+dataset_name Dataset.stop_if_dataset_present(dataset_home, dataset_name, commit: response["result"]["commit"]) if soft check = Helpers.checkmark if @dataset.init_home(remote:remote) ("Cloning #{dataset_name}", Thor::Shell::Color::BLUE) @files = Cnvrg::Datafiles.new(owner, slug, dataset: @dataset) ("Downloading files", Thor::Shell::Color::BLUE) if @dataset.softlinked? @files.cp_ds(relative: relative) ("#{check} Clone finished successfully", Thor::Shell::Color::GREEN) @dataset.write_success return end if only_tree Dataset.clone_tree(commit: commit, dataset_home: dataset_home) return end commit = response["result"]["commit"] files_count = response["result"]["file_count"] files = @files.get_clone_chunk(commit: commit, cache_link: cache_link) downloaded_files = 0 = ProgressBar.create(:title => "Download Progress", :progress_mark => '=', :format => "%b>>%i| %p%% %t", :starting_at => 0, :total => files_count, :autofinish => true) Dataset.clone_tree(commit: commit, dataset_home: dataset_home, progressbar: ) while files['keys'].length > 0 Cnvrg::Logger.log_info("download multiple files, #{downloaded_files.size} files downloaded") @files.download_multiple_files_s3(files, @dataset.local_path, progressbar: , read_only: read, flatten: flatten, threads: threads, cache_link: cache_link) downloaded_files += files['keys'].length files = @files.get_clone_chunk(commit: commit, latest_id: files['latest']) end .finish if downloaded_files == files_count Dataset.verify_cnvrgignore_exist(dataset_name, false) ("#{check} Clone finished successfully", Thor::Shell::Color::GREEN) @dataset.write_success ### if read, dont generate idx (but create idx.yml) if not read, generate idx. # TODO fix it for later... (check it in different cases) @dataset.write_idx(read ? {} : nil, commit) #nil means, generate idx end else ("Error: Couldn't create directory: #{dataset_name}", Thor::Shell::Color::RED) exit(1) end rescue Interrupt say "\nAborting", Thor::Shell::Color::RED exit(1) rescue SignalException say "\nAborting", Thor::Shell::Color::RED exit(1) end end |
#clone_data_query(dataset_url, query = nil, flatten = false, soft: false) ⇒ Object
962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 |
# File 'lib/cnvrg/cli.rb', line 962 def clone_data_query(dataset_url, query=nil, flatten=false, soft: false) begin verify_logged_in(false) #@executer = Cnvrg::Helpers::Executer.get_executer log_start(__method__, args, ) query = ["query"] || query soft = ["soft"] || soft if !query.present? ("Argument missing : query", Thor::Shell::Color::RED) exit(1) end url_parts = dataset_url.split("/") project_index = Cnvrg::Helpers.look_for_in_path(dataset_url, "datasets") slug = url_parts[project_index + 1] owner = url_parts[project_index - 1] response = Cnvrg::API.request("users/#{owner}/datasets/#{slug}/search/#{query}", 'GET') Cnvrg::CLI.is_response_success(response,true) dataset_name = response["results"]["name"] dataset_slug = response["results"]["slug"] dataset_home = Dir.pwd + "/" + dataset_slug Dataset.stop_if_dataset_present(dataset_home, dataset_name) if soft if Dataset.blank_clone(owner, dataset_name, dataset_slug) dataset = Dataset.new(dataset_home) downloader = dataset.get_storage_client ("Cloning #{dataset_name}", Thor::Shell::Color::BLUE) = { :progress => { :title => "Download Progress", :progress_mark => '=', :format => "%b>>%i| %p%% %t", :starting_at => 0, :total => response["results"]["query_files"].size, :autofinish => true }, in_threads: ParallelThreads } begin ("Downloading files", Thor::Shell::Color::BLUE) Parallel.map((response["results"]["query_files"]), ) do |f| relative_path = f["fullpath"].gsub(/^#{dataset_home}/, "").gsub(/^#{slug}/, "") relative_path_dir = relative_path.split("/") file_name = relative_path_dir.pop() relative_path_dir = relative_path_dir.join("/") abs_path = dataset_home + "/" + relative_path_dir abs_path = dataset_home if flatten fullpath = abs_path + "/" + file_name fullpath = fullpath.gsub("//", "/") begin FileUtils.mkdir_p(abs_path) unless File.exist? (fullpath) rescue ("Could not create directory: #{abs_path}", Thor::Shell::Color::RED) exit(1) end begin unless File.exist?(fullpath) downloader.safe_operation("#{abs_path}/#{file_name}") do download = open(f["url"],{ssl_verify_mode: OpenSSL::SSL::VERIFY_NONE}) IO.copy_stream(download, fullpath) end end rescue => e ("Could not download file: #{f["fullpath"]}", Thor::Shell::Color::RED) exit(1) end end #@executer.set_dataset_status(dataset: dataset.slug, status: "cloned") if @executer.present? rescue Interrupt ("Couldn't download", Thor::Shell::Color::RED) exit(1) end begin dataset.generate_idx() check = Helpers.checkmark ("#{check} Clone finished successfully", Thor::Shell::Color::GREEN) dataset.write_success(in_folder=true) rescue => e exit(1) end end rescue SignalException say "\nAborting", Thor::Shell::Color::RED exit(1) end end |
#collect_metrics ⇒ Object
4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 |
# File 'lib/cnvrg/cli.rb', line 4665 def collect_metrics @exp = Experiment.new(ENV['CNVRG_OWNER'], ENV['CNVRG_PROJECT'], job_id: ENV['CNVRG_JOB_ID']) prometheus_url = [:prometheus_url].ends_with?("/") ? [:prometheus_url] : "#{[:prometheus_url]}/" prom_user = [:prom_user] prom_password = [:prom_password] name = [:name] translate_result = Cnvrg::API_V2.request( "#{ENV['CNVRG_OWNER']}/resources/translate_metrics", 'GET', { gpu: [:gpu], gaudi: [:gaudi] } ) is_machine = [:machine] while true do begin stats = {} translate_result.each do |query_name, metric| if is_machine metric_query = metric['machine_query'].presence || metric['query'] query_content = metric_query.gsub('#JOB_SLUG#', ENV['CNVRG_JOB_ID']).gsub('#NODE_NAME#', [:node_name]) else metric_query = metric['cluster_query'].presence || metric['query'] pod_name = `hostname`.strip query_content = metric_query.gsub('#JOB_SLUG#', pod_name).gsub('#NODE_NAME#', [:node_name]) end if metric_query.blank? || query_content.blank? next end uri = URI("#{prometheus_url}api/v1/query?query=#{query_content}") http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = uri.scheme == "https" http.verify_mode = OpenSSL::SSL::VERIFY_NONE req = Net::HTTP::Get.new uri.request_uri if prom_user.present? req.basic_auth(Base64.decode64(prom_user), Base64.decode64(prom_password)) end resp = http.request(req) begin result = JSON.parse(resp.body) rescue JSON::ParserError => e log_error(e) next end data_result = result&.dig('data', 'result') next unless data_result if data_result.size > 1 stats[query_name] = {} unless query_name.include? 'block' data_result.each_with_index do |res, i| , value = res["value"] uuid = res["metric"]["UUID"].presence || i uuid = res["metric"]["device"] if query_name == "gaudi" stat_value = value.present? ? ("%.2f" % value) : 0 # converting 34.685929244444445 to 34.69 stat_value = stat_value.to_i == stat_value.to_f ? stat_value.to_i : stat_value.to_f # converting 34.00 to 34 if query_name.include? 'block' uuid = res["metric"]["interface"].presence || i uuid = "#{name}-#{uuid}" if name.present? stats['block_io'] = {} if stats['block_io'].blank? io_type = query_name.split('_')[1] stats['block_io'][io_type] = {} if stats['block_io'][io_type].blank? stats['block_io'][io_type].merge!({ uuid => stat_value }) else stats[query_name][uuid] = stat_value end end else begin , value = data_result&.first&.dig('value') stat_value = value.present? ? ("%.2f" % value) : 0 # converting 34.685929244444445 to 34.69 rescue => e Cnvrg::Logger.log_info("Failed converting string into float with error: #{e.}") Cnvrg::Logger.log_error(e) stat_value = 0 end stat_value = stat_value.to_i == stat_value.to_f ? stat_value.to_i : stat_value.to_f # converting 34.00 to 34 if query_name.include? 'block' stats['block_io'] = {} if stats['block_io'].blank? io_type = query_name.split('_')[1] if name.present? stats['block_io'][io_type] = {} if stats['block_io'][io_type].blank? stats['block_io'][io_type].merge!({ name => stat_value }) else stats['block_io'].merge!({ io_type => stat_value }) end else stats[query_name] = name.present? ? { name => stat_value } : stat_value end end end @exp.send_machine_stats [stats] unless stats.empty? rescue => e log_error(e) ("Failed to upload ongoing stats, continuing with experiment", Thor::Shell::Color::YELLOW) end sleep [:wait] end end |
#commit_before_termination ⇒ Object
2696 2697 2698 2699 2700 2701 2702 2703 |
# File 'lib/cnvrg/cli.rb', line 2696 def commit_before_termination() job_type = ENV['CNVRG_JOB_TYPE'] job_id = ENV['CNVRG_JOB_ID'] return unless job_type.present? and job_id.present? invoke :sync, [false], :job_slug => job_id, :job_type => job_type, :new_branch => true, :in_exp=> true rescue => e log_error(e) end |
#commit_image ⇒ Object
4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 |
# File 'lib/cnvrg/cli.rb', line 4505 def commit_image verify_logged_in(true) log_start(__method__, args, ) begin image = is_project_with_docker(Dir.pwd) if image and image.is_docker container = image.get_container if !container say "Couldn't create container with image #{image.image_name}:#{image.image_tag}", Thor::Shell::Color::RED exit(1) end else say "Project is not configured with any image", Thor::Shell::Color::RED exit(1) end project_home = get_project_home @project = Project.new(project_home) last_local_commit = @project.last_local_commit say "Commiting container into image", Thor::Shell::Color::BLUE new_image_name = "#{@project.slug}#{last_local_commit}:latest" image.update_image(new_image_name, container) new_image = container.commit('repo' => "#{@project.slug}#{last_local_commit}", 'tag' => "lastest") checks = Helpers.checkmark() say "#{checks} Done, image was updated", Thor::Shell::Color::GREEN log_end(0) return new_image.id rescue => e log_end(-1, e.) say "\nError occurred, aborting" exit(1) rescue SignalException log_end(-1) say "\nAborting" exit(1) end end |
#compare_experiments ⇒ Object
4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 |
# File 'lib/cnvrg/cli.rb', line 4972 def compare_experiments verify_logged_in(true) log_start(__method__, args, ) exps_map = {} copied_commits = [] if [:slugs].blank? and [:fetch_slugs].blank? ("No experiments slugs given", Thor::Shell::Color::RED) return false end if [:slugs].present? slugs = [:slugs].split(",") end frequency = [:frequency] || 5 namespace = [:namespace] project_dir = is_cnvrg_dir(Dir.pwd) @project = Project.new(project_home=project_dir, slug: [:project_slug], owner: [:project_owner]) fetch_slugs = [:fetch_slugs] webapp_slug = ENV["CNVRG_JOB_ID"] if fetch_slugs and webapp_slug.present? slugs = @project.fetch_webapp_slugs(webapp_slug) end if slugs.blank? ("No experiments slugs given", Thor::Shell::Color::RED) return false end ("compare is running") while true ("Comparing the following experiment slugs: #{slugs}") slugs.each do |exp_slug| begin if exps_map[exp_slug].blank? exp = @project.get_experiment(exp_slug)["experiment"] else exp = exps_map[exp_slug] ("Experiment '#{exp["title"]}' end commit already cloned, skipping it", Thor::Shell::Color::BLUE) next end exp_name = exp["title"] if exp["end_commit"].present? and exp["status"] != "Ongoing" ("Experiment '#{exp_name}' has ended, getting files from its end commit", Thor::Shell::Color::BLUE) num_of_new_files = Cnvrg::Helpers.get_experiment_events_log_from_server(exp, @project) exps_map[exp_slug] = exp else ("Experiment '#{exp_name}' is running, getting files from its last successful commit", Thor::Shell::Color::BLUE) num_of_new_files = Cnvrg::Helpers.get_experiment_events_log_from_server(exp, @project, commit: exp["last_successful_commit"]["sha1"]) copied_commits << exp["last_successful_commit"]["sha1"] end ("New .tfevent files downloaded", Thor::Shell::Color::BLUE) if num_of_new_files > 0 rescue => e Cnvrg::Logger.log_error(e) end end sleep frequency if fetch_slugs slugs = @project.fetch_webapp_slugs(webapp_slug, slugs: slugs) end end end |
#create_volume ⇒ Object
1731 1732 1733 1734 1735 1736 1737 1738 |
# File 'lib/cnvrg/cli.rb', line 1731 def create_volume verify_logged_in(false) log_start(__method__, args, ) dataset_dir = is_cnvrg_dir(Dir.pwd) @dataset = Dataset.new(dataset_dir) @dataset.create_volume() end |
#data_init_container(owner, dataset_slug, dataset_name) ⇒ Object
1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 |
# File 'lib/cnvrg/cli.rb', line 1075 def data_init_container(owner, dataset_slug, dataset_name) if Dataset.init_container(owner, dataset_slug, dataset_name) say "init finished successfully", Thor::Shell::Color::GREEN else say "error creating dataset, please contact support.", Thor::Shell::Color::RED exit(0) end end |
#data_jump(*commit_sha1) ⇒ Object
2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 |
# File 'lib/cnvrg/cli.rb', line 2968 def data_jump(*commit_sha1) begin verify_logged_in() log_start(__method__, args, ) dataset_dir = is_cnvrg_dir(Dir.pwd) @dataset = Dataset.new(dataset_dir) @files = Cnvrg::Datafiles.new(@dataset.owner, @dataset.slug) if commit_sha1.nil? or commit_sha1.empty? commit_sha1 = @dataset.last_local_commit end response = @dataset.compare_commits(commit_sha1) successful_changes = [] if !response["result"]["status"].nil? idx = {commit: response["result"]["commit"], tree: response["result"]["tree"]} File.open(dataset_dir + "/.cnvrg/idx.yml", "w+") {|f| f.write idx.to_yaml} status = response["result"]["status"] (status["delete"]).each do |f| relative_path = f[0].gsub(/^#{@dataset.local_path}/, "") FileUtils.rm_rf(relative_path) end # current_tree = Dir.entries(".").reject { |file| file.start_with? '.' } (status["dirs"]).each do |f| relative_path = f[0].gsub(/^#{@dataset.local_path}/, "") # dir if @files.download_dir(dataset_dir, relative_path) # current_tree.delete(relative_path[0, relative_path.size-1]) successful_changes << relative_path end end (status["download"]).each do |f| relative_path = f["name"].gsub(/^#{@dataset.local_path}/, "") # dir if @files.download_file_s3(f["name"], relative_path, dataset_dir, f["sha1"]) successful_changes << relative_path end end ("Done. Jumped to #{commit_sha1} completed successfully", Thor::Shell::Color::GREEN) end rescue => e ("Error occurred, Aborting", Thor::Shell::Color::RED) log_error(e) rescue SignalException exit(1) end end |
#data_put(dataset_url, files: [], dir: '', commit: '', chunk_size: 1000, force: false, override: false, threads: 15, message: nil, auto_cache: false, external_disk: nil) ⇒ Object
1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 |
# File 'lib/cnvrg/cli.rb', line 1217 def data_put(dataset_url, files: [], dir: '', commit: '', chunk_size: 1000, force: false, override: false, threads: 15, message: nil, auto_cache: false, external_disk: nil) begin verify_logged_in(false) log_start(__method__, args, ) if auto_cache && external_disk.blank? raise SignalException.new(1, "for auto caching external disk is required") end owner, slug = get_owner_slug(dataset_url) @dataset = Dataset.new(dataset_info: {:owner => owner, :slug => slug}) @datafiles = Cnvrg::Datafiles.new(owner, slug, dataset: @dataset) @files = @datafiles.verify_files_exists(files) @files = @files.uniq { |t| t.gsub('./', '')} if @files.blank? raise SignalException.new(1, "Cant find files to upload, exiting.") end ("Uploading #{@files.size} files", Thor::Shell::Color::GREEN) number_of_chunks = (@files.size.to_f / chunk_size).ceil if commit.blank? Cnvrg::Logger.info("Creating commit") response = @datafiles.start_commit(false, force, chunks: number_of_chunks, message: ) unless response #means we failed in the start commit. raise SignalException.new(1, "Cant put files into dataset, check the dataset id") end @commit = response['result']['commit_sha1'] elsif commit.eql? "latest" Cnvrg::Logger.info("Put files in latest commit") response = @datafiles.last_valid_commit() unless response #means we failed in the start commit. raise SignalException.new(1, "Cant put files into commit:#{commit}, check the dataset id and commit") end @commit = response['result']['sha1'] else @commit = commit end # dir shouldnt have starting or ending slash. dir = dir[0..-2] if dir.end_with? '/' dir = dir[1..-1] if dir.start_with? '/' @datafiles.upload_multiple_files_optimized( @files, @commit, override: override, chunk_size: chunk_size, prefix: dir, threads: threads, ) Cnvrg::Logger.info("Finished upload files") # This is for backwards compatibility only and should be removed in future versions: res = @datafiles.put_commit(@commit) unless res.is_success? raise SignalException.new(1, res.msg) end Cnvrg::Logger.info("Saving commit on server") res = @datafiles.end_commit(@commit,force, success: true, commit_type: "put", auto_cache: auto_cache, external_disk: external_disk) msg = res['result'] response = Cnvrg::Result.new(Cnvrg::CLI.is_response_success(res, true), msg) unless response.is_success? raise SignalException.new(1, res.msg) end ("Uploading files finished Successfully", Thor::Shell::Color::GREEN) if msg['cache_error'].present? ("Couldn't cache commit: #{msg['cache_error']}", Thor::Shell::Color::YELLOW) end rescue SignalException => e (e., Thor::Shell::Color::RED) return false end end |
#data_rm(dataset_url, regex_list: [], commit: '', message: nil, auto_cache: false, external_disk: nil) ⇒ Object
1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 |
# File 'lib/cnvrg/cli.rb', line 1290 def data_rm(dataset_url, regex_list: [], commit: '', message: nil, auto_cache: false, external_disk: nil) begin verify_logged_in(false) log_start(__method__, args, ) if auto_cache && external_disk.blank? raise SignalException.new(1, "for auto caching external disk is required") end owner, slug = get_owner_slug(dataset_url) @dataset = Dataset.new(dataset_info: {:owner => owner, :slug => slug}) @datafiles = Cnvrg::Datafiles.new(owner, slug, dataset: @dataset) # Init a new commit response = @datafiles.start_commit(false, false, chunks: 1, message: ) unless response #means we failed in the start commit. raise SignalException.new(1, "Cant put files into dataset, check the dataset id") end @commit = response['result']['commit_sha1'] # Server expects certain regex format with * so fix those that dont comply regex_list = regex_list.map do |regex| if regex.end_with? "/" # if user wants to delete entire folder add regex to delete contents as well [regex, "#{regex}*"] else regex end end.flatten files_to_delete, folders_to_delete, job_id = @datafiles.delete_multiple_files(@commit, regex_list) ("Deleting #{files_to_delete} files and #{folders_to_delete} folders", Thor::Shell::Color::GREEN) total_files = files_to_delete + folders_to_delete current_progress = 0 = @datafiles.("Delete Progress", total_files) chunk_size = 1000 offset = 0 while current_progress < total_files current_progress = @datafiles.delete_file_chunk(@commit, regex_list, chunk_size, offset) .progress = current_progress offset += chunk_size end res = @datafiles.end_commit(@commit,false, success: true, auto_cache: auto_cache, external_disk: external_disk) msg = res['result'] response = Cnvrg::Result.new(Cnvrg::CLI.is_response_success(res, true), msg) unless response.is_success? raise SignalException.new(1, res.msg) end ("Deleting files finished Successfully", Thor::Shell::Color::GREEN) if msg['cache_error'].present? ("Couldn't cache commit: #{msg['cache_error']}", Thor::Shell::Color::YELLOW) end rescue SignalException => e (e., Thor::Shell::Color::RED) return false end end |
#delete_data(dataset_slug) ⇒ Object
813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 |
# File 'lib/cnvrg/cli.rb', line 813 def delete_data(dataset_slug) begin verify_logged_in(false) log_start(__method__, args, ) owner = CLI.get_owner response = Dataset.delete(dataset_slug, owner) if Cnvrg::CLI.is_response_success(response) ("Successfully deleted dataset: #{dataset_slug}", Thor::Shell::Color::GREEN) else ("Error while tying to delete dataset: #{response["messages"]}", Thor::Shell::Color::RED) end rescue => e log_error(e) rescue SignalException say "\nAborting", Thor::Shell::Color::RED exit(1) end end |
#deploy(file_to_run, function) ⇒ Object
3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 |
# File 'lib/cnvrg/cli.rb', line 3711 def deploy(file_to_run, function) verify_logged_in(true) log_start(__method__, args, ) working_dir = is_cnvrg_dir begin instances = {"small" => ["small"], "medium" => ["medium"], "large" => ["large"], "gpu" => ["gpu"], "gpuxl" => ["gpuxl"], "gpuxxl" => ["gpuxxl"]} instance_type = get_instance_type(instances) schedule = ["schedule"] || "" title = ['title'] if !schedule.nil? and !schedule.empty? = get_schedule_date end project = Project.new(working_dir) commit_to_run = ["commit"] || nil workers = ["workers"] || nil begin num_workers = workers.to_i rescue ("Number of workers should be a number between 1 to 10", Thor::Shell::Color::RED) exit(1) end file_as_input = ["file_as_input"] || false image = is_project_with_docker(working_dir) image_slug = 'cnvrg' invoke :sync, [false], [] res = project.deploy(file_to_run, function, nil, commit_to_run, instance_type, image_slug, schedule, , num_workers, file_as_input, title) if Cnvrg::CLI.is_response_success(res) check = Helpers.checkmark() ("#{check} Deployment process is on: #{Cnvrg::Helpers.remote_url}/#{project.owner}/projects/#{project.slug}/endpoints/show/#{res["result"]["deploy_slug"]}", Thor::Shell::Color::GREEN) exit(0) # end end rescue => e ("Error occurred, Aborting", Thor::Shell::Color::RED) log_error(e) rescue SignalException exit_status = -1 end_commit = project.last_local_commit sleep(20) # end cycle res = @exp.end(log, exit_status, end_commit, "", "") say "\nAborting" exit(1) end end |
#download(sync = false, ignore_list = "", in_exp = false) ⇒ Object
2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 |
# File 'lib/cnvrg/cli.rb', line 2771 def download(sync = false, ignore_list = "", in_exp=false) begin verify_logged_in(true) log_start(__method__, args, ) project_home = get_project_home @project = Project.new(project_home) @files = Cnvrg::Files.new(@project.owner, @project.slug, project_home: project_home, project: @project) git = ["git"] commit = ["commit"] if git or @project.is_git return download_in_git(commit) end if commit.present? return jump(commit) end ignore = [:ignore] || "" if ignore.nil? or ignore.empty? ignore = ignore_list end data_ignore = data_dir_include() if !data_ignore.nil? if ignore.nil? or ignore.empty? ignore = data_ignore else ignore = "#{ignore},#{data_ignore}" end end if !@project.update_ignore_list(ignore) ("Couldn't append new ignore files to .cnvrgignore", Thor::Shell::Color::YELLOW) end new_branch = ["new_branch"] || @project.is_branch || false res = @project.compare_idx(new_branch, in_exp: in_exp, download: true)["result"] result = res["tree"] commit = res["commit"] #here im grouping the files by their current status. # # all the files that changed in the server (added + updated) changed_files = result['updated_on_server'] + result['added'] # non-conflicted files, all the files that changed remotely but not locally updated_files = changed_files - result["update_local"] # conflicted - files that changed remotely and locally conflicted_files = changed_files & result["update_local"] # all deleted files all_deleted = result['deleted'] # cant delete files - files that deleted on the server but changed locally conflicted_deleted = all_deleted & result["update_local"] # files to delete - files that deleted on the server and unchanged locally deleted_files = all_deleted - conflicted_deleted update_total = [all_deleted, changed_files ].flatten.size if update_total < 1 if !@project.last_local_commit.eql? commit Cnvrg::Logger.log_info("Finish commit, updating idx with commit") @project.update_idx_with_commit!(commit) end ("Project is up to date", Thor::Shell::Color::GREEN, ((["sync"] or sync) ? false : true)) return true end Cnvrg::Logger.log_info("Got #{update_total} changes from server") successful_changes = [] if update_total == 1 ("Downloading #{update_total} file", Thor::Shell::Color::BLUE, !["sync"]) elsif ["verbose"] ("Downloading #{update_total} files", Thor::Shell::Color::BLUE) else ("Syncing files", Thor::Shell::Color::BLUE, !["sync"]) end = ProgressBar.create(:title => "Download Progress", :progress_mark => '=', :format => "%b>>%i| %p%% %t", :starting_at => 0, :total => update_total, :autofinish => true) Cnvrg::Logger.log_info("Downloading updated files:#{updated_files.join(",")}") @files.download_files(updated_files, commit, progress: ) Cnvrg::Logger.log_info("Downloading conflicted files:#{conflicted_files.join(",")}") @files.download_files(conflicted_files, commit, postfix: ".conflict", progress: ) Cnvrg::Logger.log_info("Delete files: #{deleted_files.join(",")}") @files.delete_files_local(deleted_files, conflicted: conflicted_deleted, progress: ) # update idx with latest commit # the latest true its because if we define --commit in the cmd it will go to "def jump(options['commit'])" # so if we are downloads something, we have to stay here. @project.update_idx_with_commit!(commit, latest: true) #TODO Sync, remove idx, sync again and pray .finish check = Helpers.checkmark() Cnvrg::Logger.log_info("Finished downloading successfuly") if ["verbose"] ("#{check} Done, Downloaded:", Thor::Shell::Color::GREEN) (successful_changes.join("\n"), Thor::Shell::Color::GREEN) ("Total of #{successful_changes.size} / #{update_total} files.", Thor::Shell::Color::GREEN) else ("#{check} Downloaded changes successfully", Thor::Shell::Color::GREEN, ((sync or ["sync"]) ? false : true)) end rescue => e ("Error occurred, \nAborting", Thor::Shell::Color::BLUE) Cnvrg::Logger.log_error(e) exit(1) rescue Exception => e Cnvrg::Logger.log_error(e) ("Error occurred, \nAborting", Thor::Shell::Color::BLUE) exit(1) rescue SignalException ("\nAborting", Thor::Shell::Color::BLUE) exit(1) end end |
#download_built_image(image_name, image_slug) ⇒ Object
4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 |
# File 'lib/cnvrg/cli.rb', line 4797 def download_built_image(image_name, image_slug) begin verify_logged_in(false) log_start(__method__, args, ) owner = Cnvrg::CLI.get_owner() path = File.('~') + "/.cnvrg/tmp/#{image_name}.tar.gz" @files = Cnvrg::Files.new(owner, "") ("Downloading image file", Thor::Shell::Color::BLUE) begin if @files.download_image(path, image_slug, owner) gzipRes = system("gunzip -f #{path}") if !gzipRes ("Couldn't create tar file from image", Thor::Shell::Color::RED) exit(1) else path = path.gsub(".gz", "") return path end else ("Couldn't download image #{image_name}", Thor::Shell::Color::RED) return false end rescue Interrupt say "The user has exited to process, aborting", Thor::Shell::Color::BLUE exit(1) end rescue SignalException say "\nAborting" exit(1) end end |
#download_cnvrg_image(image_name, secret) ⇒ Object
4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 |
# File 'lib/cnvrg/cli.rb', line 4886 def download_cnvrg_image(image_name, secret) verify_logged_in(false) begin @files = Cnvrg::Files.new("", "") say "Downloading image file", Thor::Shell::Color::BLUE begin if @files.download_cnvrg_image(image_name, secret) say "Successfully downloaded image #{image_name}", Thor::Shell::Color::GREEN else say "Couldn't download image #{image_name}", Thor::Shell::Color::RED return false end rescue Interrupt say "The user has exited to process, aborting", Thor::Shell::Color::BLUE exit(1) end rescue SignalException say "\nAborting" exit(1) end end |
#download_data(verbose, sync, path = Dir.pwd, in_dir = true) ⇒ Object
1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 |
# File 'lib/cnvrg/cli.rb', line 1091 def download_data(verbose, sync, path = Dir.pwd, in_dir = true) begin verify_logged_in(in_dir) log_start(__method__, args, ) if path.nil? or path.empty? path = Dir.pwd end dataset_dir = is_cnvrg_dir(path) @dataset = Dataset.new(dataset_dir) @files = Cnvrg::Datafiles.new(@dataset.owner, @dataset.slug) new_branch = ["new_branch"] || false res = @dataset.compare_idx(new_branch)["result"] result = res["tree"] commit = res["commit"] if result["updated_on_server"].empty? and result["conflicts"].empty? and result["deleted"].empty? ("Project is up to date", Thor::Shell::Color::GREEN, ((["sync"] or sync)) ? false : true) return true end ("Downloading data", Thor::Shell::Color::BLUE) result = @dataset.downlowd_updated_data(@dataset.last_local_commit) delete = result["result"]["delete"] commits = result["result"]["commits"] updated_idx = result["result"]["idx"] = { :progress => { :title => "Download Progress", :progress_mark => '=', :format => "%b>>%i| %p%% %t", :starting_at => 0, :total => commits.size, :autofinish => true }, in_processes: ParallelProcesses, in_thread: ParallelThreads } begin tar_files = [] download_result = Parallel.map(commits, ) do |c| file_name = @files.download_data_file(c, dataset_dir) if file_name.eql? false or file_name.nil? count = 0 success_download = false while count < 3 and !success_download ("Couldn't download data files, retrying.. ", Thor::Shell::Color::BLUE) file_name = @files.download_data_file(c, dataset_dir) success_download = (file_name.eql? false or file_name.nil?) count += 1 end if count > 3 or !success_download ("Couldn't download data files,revoking", Thor::Shell::Color::RED) raise Parallel::Kill end end file_path = "#{dataset_dir}/#{file_name}" tar_files << file_path success = extarct_tar(file_path, dataset_dir) if !success ("Couldn't extract data files,revoking", Thor::Shell::Color::RED) raise Parallel::Kill end FileUtils.rm_rf([file_path]) end rescue Interrupt @files.revoke_download(tar_files, updated_idx[:tree].keys) return false end to_delete = [] delete.each do |d| to_delete << "#{dataset_dir}/#{d}" end FileUtils.rm_rf(to_delete) @dataset.update_idx(updated_idx) check = Helpers.checkmark() ("#{check} Downloaded changes successfully", Thor::Shell::Color::GREEN) return true end rescue => e ("Error occurd, \nAborting", Thor::Shell::Color::BLUE) log_error(e) @files.revoke_download(tar_files, updated_idx[:tree].keys) exit(1) rescue SignalException say "\nAborting", Thor::Shell::Color::BLUE exit(1) end |
#download_data_new(verbose = false, new_branch = false, sync = false, commit = nil, all_files = true) ⇒ Object
2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 |
# File 'lib/cnvrg/cli.rb', line 2595 def download_data_new(verbose=false, new_branch=false,sync=false, commit=nil,all_files=true) begin verify_logged_in(true) log_start(__method__, args, ) dataset_dir = is_cnvrg_dir(Dir.pwd) @dataset = Dataset.new(dataset_dir) @files = Cnvrg::Datafiles.new(@dataset.owner, @dataset.slug, dataset: @dataset) res = @dataset.compare_idx_download(all_files: all_files, desired_commit: commit) unless CLI.is_response_success(res, false) ("Cant find the desired commit, please check it or try to download without it.", Thor::Shell::Color::RED) exit(1) end result = res["result"] tree = result["tree"] commit = result["commit"] update_total = [tree['added'], tree["updated_on_server"], tree["conflicts"], tree["deleted"]].compact.flatten.size successful_changes = 0 if update_total == 0 ("Dataset is up to date", Thor::Shell::Color::GREEN, !sync) return 0, 0 else ("Downloading #{update_total} files", Thor::Shell::Color::BLUE, ["verbose"]) ("Syncing Dataset", Thor::Shell::Color::BLUE, !sync) end Cnvrg::Logger.log_info("Current commit: #{@dataset.last_local_commit}, destination commit: #{commit}") Cnvrg::Logger.log_info("Compare idx res: #{tree}") = ProgressBar.create(:title => "Download Progress", :progress_mark => '=', :format => "%b>>%i| %p%% %t", :starting_at => 0, :total => update_total, :autofinish => true) conflicts = @files.mark_conflicts(tree) ("Found some conflicts, check .conflict files.", Thor::Shell::Color::BLUE) if conflicts > 0 update_res = @files.download_files_in_chunks(tree["updated_on_server"], progress: ) if tree["updated_on_server"].present? added_res = @files.download_files_in_chunks(tree["added"], progress: ) if tree["added"].present? deleted = tree["deleted"].to_a delete_res = @files.delete_commit_files_local(deleted) if !delete_res ("Couldn't delete #{deleted.join(" ")}", Thor::Shell::Color::RED) ("Couldn't download, Rolling Back all changes.", Thor::Shell::Color::RED) exit(1) end .progress += deleted.size if .present? and deleted.size > 0 success = (update_res.blank? or update_res.is_success?) success &= (delete_res.blank? or delete_res.is_success?) success &= (added_res.blank? or added_res.is_success?) if success # update idx with latest commit @dataset.update_idx_with_commit!(commit) check = Helpers.checkmark() if ["verbose"] ("#{check} Done, Downloaded:", Thor::Shell::Color::GREEN) (successful_changes.join("\n"), Thor::Shell::Color::GREEN) ("Total of #{successful_changes.size} / #{update_total} files.", Thor::Shell::Color::GREEN) else ("#{check} Downloaded changes successfully", Thor::Shell::Color::GREEN, !sync) end total_deleted = deleted.try(:size) total_downloaded = tree["added"].try(:size) || 0 total_downloaded += tree["updated_on_server"].try(:size) if tree["updated_on_server"].present? return total_deleted, total_downloaded else return [] end rescue SignalException => e Cnvrg::Logger.log_error(e) say "\nAborting", Thor::Shell::Color::BLUE exit(1) rescue => e Cnvrg::Logger.log_error(e) ("Error occurred, \nAborting", Thor::Shell::Color::RED) exit(1) end end |
#download_file_data(file_path, *dataset_path) ⇒ Object
2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 |
# File 'lib/cnvrg/cli.rb', line 2534 def download_file_data(file_path, *dataset_path) verify_logged_in(true) log_start(__method__, args, ) begin if dataset_path.nil? or dataset_path.empty? dataset_path = Dir.pwd elsif dataset_path.is_a? Array dataset_path = dataset_path[0] end dataset_dir = is_cnvrg_dir(dataset_path) @dataset = Dataset.new(dataset_dir) @files = Cnvrg::Datafiles.new(@dataset.owner, @dataset.slug) commit_to_download = ["commit"] || nil as_link = ["link"] || false download_path = ["path"] remote = ["remote"] as_json = ["json"] if remote download_path = "/data/#{@dataset.title}/" else download_path = dataset_dir end if !as_json ("Downloading file", Thor::Shell::Color::BLUE) end res = @files.download_file_s3(file_path, file_path, download_path, conflict=false, commit_sha1=commit_to_download, as_link=as_link) if as_link puts res else if res if as_json response = {"status":"success"} puts response.to_json else ("#{Helpers.checkmark()} File #{file_path} was successfully downloaded", Thor::Shell::Color::GREEN) end end end rescue =>e ("Error occurred, \nAborting", Thor::Shell::Color::BLUE) log_error(e) exit(1) end end |
#download_in_git(*commit_sha1) ⇒ Object
2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 |
# File 'lib/cnvrg/cli.rb', line 2679 def download_in_git(*commit_sha1) begin verify_logged_in(true) log_start(__method__, args, ) project_home = get_project_home @project = Project.new(project_home) @files = Cnvrg::Files.new(@project.owner, @project.slug, project: @project, cli: self, options: ) commit_sha1 = commit_sha1.try(:first) if commit_sha1.is_a? Array @files.download_commit(commit_sha1) rescue => e log_error(e) ("Error while trying to download ", Thor::Shell::Color::RED) return end end |
#download_tags_yaml ⇒ Object
1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 |
# File 'lib/cnvrg/cli.rb', line 1775 def verify_logged_in(false) log_start(__method__, args, ) dataset_dir = is_cnvrg_dir(Dir.pwd) @dataset = Dataset.new(dataset_dir) status = @dataset.() if status ("Downloaded tags yaml successfully", Thor::Shell::Color::GREEN) else ("Unable to download", Thor::Shell::Color::RED) end end |
#end_commit_data(commit, success: true, uploaded_files: 0, sync: false) ⇒ Object
2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 |
# File 'lib/cnvrg/cli.rb', line 2190 def end_commit_data(commit, success: true, uploaded_files: 0, sync: false) begin verify_logged_in(true) log_start(__method__, args, ) dataset_dir = is_cnvrg_dir(Dir.pwd) @dataset = Dataset.new(dataset_dir) @files = Cnvrg::Datafiles.new(@dataset.owner, @dataset.slug, dataset: @dataset) force = ["force"] || false resp = @files.end_commit(commit, force, success: success, uploaded_files: uploaded_files) if (resp.present? and resp["result"]) check = Helpers.checkmark if resp["result"]["new_commit"].blank? @dataset.revert_next_commit #removes the next commit ("#{check} Dataset is up to date", Thor::Shell::Color::GREEN) else if sync = "#{check} Data sync finished" else = "#{check} Data upload finished" end (, Thor::Shell::Color::GREEN) @dataset.remove_next_commit #takes the next commit and put it as current commit @dataset.set_partial_commit(nil) @dataset.backup_idx end end end end |
#exec(*cmd) ⇒ Object
3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 |
# File 'lib/cnvrg/cli.rb', line 3230 def exec(*cmd) log = [] verify_logged_in(true) log_start(__method__, args, ) working_dir = is_cnvrg_dir script_path = get_cmd_path_in_dir(working_dir, Dir.pwd) sync_before = ["sync_before"] sync_after = ["sync_after"] print_log = ["log"] title = ["title"] commit = ["commit"] || nil image = ["image"] || nil indocker = ["indocker"] || false ignore = [:ignore] || "" force = [:force] sync_before_terminate = ["sync_before_terminate"] periodic_sync = ["periodic_sync"] email_notification = ["email_notification"] output_dir = ['output_dir'] || "output" project_home = get_project_home data_query = ["data_query"] docker_stats = ["docker_stats"] local = [:local] || false @project = Project.new(project_home) if @project.is_git sync_before = false end # is_new_branch = @project.compare_commit(commit) is_new_branch = false begin if !commit.nil? and !commit.empty? invoke :jump, [commit], [] else if sync_before # Sync before run invoke :sync, [false], :new_branch => is_new_branch, :ignore => ignore, :force => force end end #set image for the project if !image.nil? and !image.empty? invoke :set_image, [image] end if !indocker image_proj = is_project_with_docker(working_dir) if image_proj and image_proj.is_docker container = image_proj.get_container if !container ("Couldn't create container with image #{image_proj.image_name}:#{image_proj.image_tag}", Thor::Shell::Color::RED) exit(1) end exec_args = args.flatten.join(" ") = Hash[] .except!("image", "indocker") = .map {|x| "--#{x[0]}=#{x[1]}"}.flatten.join(" ") command_to_run = copy_args.join(" ") command = ["/bin/bash", "-lc", "cnvrg exec --indocker #{} #{command_to_run} #{exec_args}"] puts container.exec(command, tty: true) container.stop() exit(0) end end remote = ["remote"] if remote if ["docker_id"].present? docker_id = ["docker_id"] else docker_id = `cat /etc/hostname` docker_id = docker_id.strip() end end is_on_gpu = ["gpu"] start_commit = @project.last_local_commit cmd = cmd.join("\s") @exp = Experiment.new(@project.owner, @project.slug) platform = RUBY_PLATFORM machine_name = Socket.gethostname machine_activity_slug = ENV["CNVRG_MACHINE_ACTIVITY"] begin @exp.start(cmd, platform, machine_name, start_commit, title, email_notification, machine_activity_slug, script_path, sync_before_terminate, periodic_sync) ("Experiment's live results: #{Cnvrg::Helpers.remote_url}/#{@project.owner}/projects/#{@project.slug}/experiments/#{@exp.slug}", Thor::Shell::Color::GREEN) ("Running: #{cmd}\n", Thor::Shell::Color::BLUE) unless @exp.slug.nil? real = Time.now exp_success = true memory_total = [] cpu_total = [] start_loop = Time.now stdout, stderr = '', '' begin process_running = true if docker_stats stats_thread = Thread.new do while process_running do sleep 30 begin stats = remote ? usage_metrics_in_docker(docker_id) : Helpers.ubuntu? ? { memory: memory_usage, cpu: cpu_usage } : {} if is_on_gpu gu = gpu_util(take_from_docker: ["gpu_util_from_docker"], docker_id: docker_id) stats['gpu_util'] = gu[0] stats['gpu'] = gu[1] end @exp.send_machine_stats [stats] unless stats.empty? rescue => e log_error(e) ("Failed to upload ongoing stats, continuing with experiment", Thor::Shell::Color::YELLOW) end end end end start_time = Time.now if @exp.get_cmd.present? cmd = @exp.get_cmd end if local exec_local(cmd, print_log, start_commit, real, start_time) exit_status = $?.exitstatus else command_slug = (0...18).map { (65 + rand(26)).chr }.join result_file = "/conf/result-#{command_slug}" data = {cmd: cmd, async: true, format: true, file_name: result_file, use_script: true, use_bash: ["use_bash"]} conn = Cnvrg::Helpers::Executer.get_main_conn response = conn.post('command', data.to_json) if response.to_hash[:status].to_i != 200 exit_status = 129 raise StandardError.new("Cant send command to slave") end t = FileWatch::Tail.new filename = result_file lines = [] t.tail(filename) t.subscribe do |path, line| begin cur_log = JSON.parse(line) if cur_log["type"] == "endMessage" exit_status = cur_log["real"].to_i break else puts(cur_log.to_json) STDOUT.flush cur_log["time"] = Time.parse(cur_log["timestamp"]) cur_log["message"] = cur_log["message"].to_s + "\r\n" log << cur_log end if log.size >= 10 @exp.upload_temp_log(log) log = [] elsif (start_time + 15.seconds) <= Time.now @exp.upload_temp_log(log) unless log.empty? log = [] start_time = Time.now end rescue => e log_error(e) end end end end_time = Time.now process_running = false if !log.empty? temp_log = log @exp.upload_temp_log(temp_log) log -= temp_log end cpu_average = cpu_total.inject(0) {|sum, el| sum + el}.to_f / cpu_total.size memory_average = memory_total.inject(0) {|sum, el| sum + el}.to_f / memory_total.size if exit_status != 0 exp_success = false end if sync_after @exp.job_log(["Syncing Experiment"]) # Sync after run if @project.is_git output_dir = output_dir || @exp.output_dir if output_dir.present? upload(false, false, true, ignore, true, false, output_dir, "Experiment", @exp.slug, true ) end else upload(false, false, true, ignore, true, false, nil, "Experiment", @exp.slug, true ) end end end_commit = @project.last_local_commit # log_thread.join stats_thread.join if docker_stats res = @exp.end(log, exit_status, end_commit, cpu_average, memory_average, end_time: end_time) if !exp_success ("Experiment has failed, look at the log for more details or run cnvrg exec --log", Thor::Shell::Color::RED) else check = Helpers.checkmark() ("#{check} Done. Experiment's results were updated!", Thor::Shell::Color::GREEN) end rescue => e if container container.stop() end ("Couldn't run #{cmd}, check your input parameters", Thor::Shell::Color::RED) if @exp # log_thread.join Thread.kill(stats_thread) if docker_stats if exit_status.blank? exit_status = "-1" end res = @exp.end(log, exit_status, end_commit, cpu_average, memory_average) end log_error(e) # Thread.kill(log_thread) # Thread.kill(stats_thread) exit(1) end end end rescue SignalException exit_status = -1 end_commit = @project.last_local_commit process_running = false # log_thread.join stats_thread.join if docker_stats res = @exp.end(log, exit_status, end_commit, cpu_average, memory_average) if container container.stop() end say "\nAborting" exit(1) end end |
#exec_remote(*cmd) ⇒ Object
3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 |
# File 'lib/cnvrg/cli.rb', line 3514 def exec_remote(*cmd) verify_logged_in(true) log_start(__method__, args, ) working_dir = is_cnvrg_dir path_to_cmd = get_cmd_path_in_dir(working_dir, Dir.pwd) begin title = ["title"] || nil grid = ["grid"] || nil data = ["data"] || nil datasets = ["datasets"] || nil data_commit = ["data_commit"] || nil data_query = ["data_query"] || nil sync_before = ["sync_before"] force = ["force"] debug = ["debug"] prerun = ["prerun"] requirements = ["requirements"] email_notification_error = ["email_notification_error"] email_notification_success = ["email_notification_success"] emails = ["emails"] max_time = ["max_time"] if !max_time.nil? and !max_time.empty? max_time = max_time.to_i if max_time <=0 ("Max time for experiment should be more than 0 minutess", Thor::Shell::Color::RED) exit(1) end end periodic_sync = ["periodic_sync"] sync_before_terminate = ["sync_before_terminate"] dataset_only_tree = ["dataset_only_tree"] = 0 if dataset_only_tree = 1 end restart_if_stuck = ["restart_if_stuck"] instance_type = ["machine_type"] || nil schedule = ["schedule"] || "" recurring = ["recurring"] || "" upload_output = ["upload_output"] time_to_upload = calc_output_time(upload_output) if time_to_upload == 0 or time_to_upload == -1 upload_output_option = "--upload_output=1m" else upload_output_option = "--upload_output=#{upload_output}" end remote = "--remote=true" if !instance_type.nil? and instance_type.include? "gpu" remote = "#{remote} --gpu=true" end output_dir = ["output_dir"] || nil git_commit = ["git_commit"] git_branch = ["git_branch"] = Hash[] = ["local_folders"] .except!("schedule", "recurring", "machine_type", "image", "upload_output", "grid", "data", "data_commit", "title", "local", "small", "medium", "large", "gpu", "gpuxl", "gpuxxl","max_time","dataset_only_tree", "data_query", "git_commit","git_branch","restart_if_stuck","local_folders","output_dir", "commit", "datasets", "requirements", "prerun", "email_notification_error", "email_notification_success", "emails", "wait","debug") = .map {|x| "--#{x[0]}=#{x[1]}"}.flatten.join(" ") command = "#{} #{remote} #{upload_output_option} #{cmd.flatten.join(" ")}" commit_to_run = ["commit"] || nil if !schedule.nil? and !schedule.empty? = get_schedule_date end project = Project.new(working_dir) if project.is_git and output_dir.blank? output_dir = "output" end image = ["image"] || nil forced_commit = nil if sync_before and !project.is_git if force sync_result = invoke :sync, [false], :force => force, :return_id=> true begin forced_commit = JSON(sync_result)["commit_sha1"] rescue forced_commit = nil end else sync_result = invoke :sync, [false], :force => false end end #handle grid if it's git project if project.is_git and grid.present? if !File.exist? "#{project.local_path}/#{grid}" ("Hyper Search File:#{grid} couldn't be found", Thor::Shell::Color::RED) return end grid_content = YAML.load_file("#{project.local_path}/#{grid}") if grid_content.present? grid = grid_content else ("Hyper Search file:#{grid} has no content", Thor::Shell::Color::RED) return end end ("Running remote experiment", Thor::Shell::Color::BLUE) exp = Experiment.new(project.owner, project.slug) if forced_commit and (commit_to_run.nil? or commit_to_run.empty?) commit_to_run = forced_commit end commit_to_run = commit_to_run.presence || project.last_local_commit res = exp.exec_remote(command, commit_to_run, instance_type, image, schedule, , grid, path_to_cmd, data, data_commit, periodic_sync, sync_before_terminate, max_time, ,output_dir, data_query, git_commit, git_branch,debug, restart_if_stuck,, title, datasets, prerun: prerun, requirements: requirements, recurring: recurring, email_notification_error: email_notification_error, email_notification_success: email_notification_success, emails_to_notify: emails) if Cnvrg::CLI.is_response_success(res) check = Helpers.checkmark() str = "#{check} Experiment's is on: #{Cnvrg::Helpers.remote_url}/#{project.owner}/projects/#{project.slug}/experiments/#{res["result"]["exp_url"]}" if res["result"]["grid"] str = "Running grid search, follow here: #{Cnvrg::Helpers.remote_url}/#{project.owner}/projects/#{project.slug}/experiments?grid=#{res["result"]["exp_url"]}" end (str, Thor::Shell::Color::GREEN) exit_status = 0 if ['wait'] end_pos = 0 while true tries = 0 begin result = fetch_experiment_info(res,project,end_pos) exit_statuses = result.values.pluck('exit_status') if exit_statuses.include? nil if res["result"]["grid"] system("clear") || system("cls") msg = "#{Time.current}: waiting for all experiments to finish" puts msg else end_pos = result[res['result']['exp_url']]['end_pos'] logs = result[res['result']['exp_url']]['logs'] logs.each do |log| puts log['message'] end end sleep 3 else result.each do |slug, value| exit_status = value['exit_status'] puts "Experiment #{slug} was exited with status #{exit_status}" end break end rescue => e log_error(e) ("Error occurred, retrying", Thor::Shell::Color::RED) sleep 3 tries += 1 retry if tries <= 5 exit(1) end end end exit(exit_status.to_i) end rescue => e ("Error occurred, Aborting", Thor::Shell::Color::RED) log_error(e) rescue SignalException exit_status = -1 end_commit = project.last_local_commit sleep(20) # end cycle res = @exp.end(log, exit_status, end_commit, "", "") say "\nAborting" exit(1) end end |
#experiments ⇒ Object
5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 |
# File 'lib/cnvrg/cli.rb', line 5039 def experiments verify_logged_in(true) log_start(__method__, args, ) project_dir = is_cnvrg_dir(Dir.pwd) @project = Project.new(project_dir) unless ['id'].to_s.size > 5 result = @project.get_experiments() list = result["result"]["experiments"] if list and list.size > 1 print_table(list) else say "No experiments" end else result = @project.get_experiment(['id']) result = result.to_h['experiment'] if result if ["tag"].to_s.size == 0 list = [] list << result.keys list << result.values print_table(list) else if result.keys.include? ["tag"] say result[["tag"]] else say "No such tag" end end else say "No such experiment" end end end |
#file_exists(file) ⇒ Object
4789 4790 4791 4792 |
# File 'lib/cnvrg/cli.rb', line 4789 def file_exists(file) exit(0) if File.exists? file exit(1) end |
#get_machine ⇒ Object
5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 |
# File 'lib/cnvrg/cli.rb', line 5080 def get_machine() begin verify_logged_in(true) log_start(__method__, args, ) owner = Cnvrg::CLI.get_owner() working_dir = is_cnvrg_dir @image = Images.new(working_dir) if @image.nil? or !@image.is_docker say "Couldn't find image related to this project", Thor::Shell::Color::RED exit(0) end res = Cnvrg::API.request("users/#{owner}/machines/list", 'GET') if Cnvrg::CLI.is_response_success(res) if res["result"]["machines"].empty? create = yes? "No machines available, create new machine?", Thor::Shell::Color::YELLOW if create instance_type = (res["result"]["aws_options"]) else exit(0) end end printf "%-20s %-20s %-20s\n", "name", "created by", "last_used", "instance_type" res["result"]["machines"].each do |u| time = Time.parse(u["last_used"]) update_at = get_local_time(time) printf "%-20s %-20s %-20s\n", u["name"], u["created_by"], update_at, u["instance type"] end end rescue SignalException log_end(-1) say "\nAborting" exit(1) end end |
#get_owner_slug(url_or_slug) ⇒ Object
1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 |
# File 'lib/cnvrg/cli.rb', line 1201 def get_owner_slug(url_or_slug) if url_or_slug =~ URI::regexp # Find owner and slug in url url_parts = url_or_slug.split("/") project_index = Cnvrg::Helpers.look_for_in_path(url_or_slug, "datasets") slug = url_parts[project_index + 1] owner = url_parts[project_index - 1] else # Find owner in config file owner = CLI.get_owner slug = url_or_slug end return owner, slug end |
#get_utilization ⇒ Object
4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 |
# File 'lib/cnvrg/cli.rb', line 4633 def get_utilization() @exp = Experiment.new(ENV['CNVRG_OWNER'], ENV['CNVRG_PROJECT'], job_id: ENV['CNVRG_JOB_ID']) docker_id = ["docker_id"] while true do sleep 30 begin stats = usage_metrics_in_docker(docker_id) if ["is_on_gpu"] gu = gpu_util(take_from_docker: true, docker_id: docker_id) stats['gpu_util'] = gu[0] stats['gpu'] = gu[1] end stats['docker_id'] = docker_id @exp.send_machine_stats [stats] unless stats.empty? rescue => e log_error(e) ("Failed to upload ongoing stats, continuing with experiment", Thor::Shell::Color::YELLOW) end end end |
#git_clone(slug, owner) ⇒ Object
1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 |
# File 'lib/cnvrg/cli.rb', line 1846 def git_clone(slug, owner) verify_logged_in(false) log_start(__method__, args, ) project_home = Dir.pwd soft = ["soft"] || false Project.stop_if_project_present(project_home, slug, owner) if soft clone_resp = Project.clone_dir_remote(slug, owner, slug,true) exit 1 if not clone_resp idx_status = Project.new(get_project_home).generate_idx(files:[]) FileUtils.mkdir_p File.join(get_project_home, ENV['CNVRG_OUTPUT_DIR']) if ENV['CNVRG_OUTPUT_DIR'].present? end |
#init_data(public, bucket: nil, title: nil) ⇒ Object
772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 |
# File 'lib/cnvrg/cli.rb', line 772 def init_data(public, bucket: nil, title: nil) begin verify_logged_in(false) log_start(__method__, args, ) dataset_name = File.basename(Dir.getwd) if title.present? dataset_name = title end if File.directory?(Dir.getwd + "/.cnvrg") config = YAML.load_file("#{Dir.getwd}/.cnvrg/config.yml") ("Directory is already linked to #{config[:dataset_slug]}", Thor::Shell::Color::RED) exit(0) end ("Init dataset: #{dataset_name}", Thor::Shell::Color::BLUE) working_dir = Dir.getwd owner = CLI.get_owner if Dataset.init(owner, dataset_name, ["public"], bucket: bucket) path = Dir.pwd @dataset = Dataset.new(path) url = @dataset.url check = Helpers.checkmark ("#{check} Link finished successfully", Thor::Shell::Color::GREEN) ("#{dataset_name}'s location is: #{url}\n", Thor::Shell::Color::GREEN) else @dataset.revert(working_dir) unless @dataset.nil? ("Error creating dataset, please contact support.", Thor::Shell::Color::RED) exit(0) end rescue => e log_error(e) rescue SignalException say "\nAborting", Thor::Shell::Color::RED exit(1) end end |
#install_python_libraries(*lib) ⇒ Object
4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 |
# File 'lib/cnvrg/cli.rb', line 4368 def install_python_libraries(*lib) begin verify_logged_in(false) log_start(__method__, args, ) image = is_project_with_docker(Dir.pwd) if image and image.is_docker container = image.get_container if !container say "Couldn't create container with image #{image.image_name}:#{image.image_tag}", Thor::Shell::Color::RED exit(1) end else say "Project is not configured with any image", Thor::Shell::Color::RED exit(1) end req_file = ["requirement"] || nil if lib.nil? and not req_file.nil? if not File.exist? req_file say "Couldn't find #{req_file}", Thor::Shell::Color::RED exit(1) end command_to_run = "pip install -r #{req_file}" else command_to_run = lib.join(" ") end say "Running #{command_to_run} in container", Thor::Shell::Color::BLUE command = ["/bin/bash", "-lc", "#{command_to_run}"] res = container.exec(command, tty: false) say res[0].join("\n") checks = Helpers.checkmark() say "Updating image", Thor::Shell::Color::BLUE image.create_custom_image("") say "#{checks} Done, installing libraries completed", Thor::Shell::Color::GREEN container.stop() log_end(0) rescue => e log_end(-1, e.) say "Error occurred, aborting" if container container.stop() end rescue SignalException if container container.stop() end say "\nAborting" exit(1) end end |
#install_system_libraries(*command_to_run) ⇒ Object
4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 |
# File 'lib/cnvrg/cli.rb', line 4317 def install_system_libraries(*command_to_run) begin verify_logged_in(false) log_start(__method__, args, ) image = is_project_with_docker(Dir.pwd) if image and image.is_docker container = image.get_container if !container say "Couldn't create container with image #{image.image_name}:#{image.image_tag}", Thor::Shell::Color::RED exit(1) end else say "Project is not configured with any image", Thor::Shell::Color::RED exit(1) end command_to_run = command_to_run.join(" ") say "Running #{command_to_run} in container", Thor::Shell::Color::BLUE command = ["/bin/bash", "-lc", "#{command_to_run}"] res = container.exec(command, tty: false) say res[0].join("\n") checks = Helpers.checkmark() say "Updating image", Thor::Shell::Color::BLUE image.create_custom_image("") say "#{checks} Done, installing libraries completed", Thor::Shell::Color::GREEN container.stop() log_end(0) rescue => e log_end(-1, e.) say "Error occurred, aborting" if container container.stop() end rescue SignalException log_End(-1) if container container.stop() end say "\nAborting" exit(1) end end |
#jump(commit_sha1) ⇒ Object
2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 |
# File 'lib/cnvrg/cli.rb', line 2896 def jump(commit_sha1) begin verify_logged_in() log_start(__method__, args, ) project_home = get_project_home @project = Project.new(project_home) current_commit = @project.last_local_commit if current_commit.start_with? commit_sha1 #commit_sha1 can be partial. ("Project is already updated", Thor::Shell::Color::GREEN) exit(0) end ("Jumping to commit #{commit_sha1}") @files = Cnvrg::Files.new(@project.owner, @project.slug, project_home: project_home, project: @project) resp = @project.jump_idx(destination: commit_sha1) if resp.blank? ("Cant find the given commit", Thor::Shell::Color::RED) exit(0) end compare = resp['result']['compare'] latest = resp['result']['latest'] commit = resp['result']['commit'] updated_files = compare['updated_on_server'] + compare['added'] conflicted_files = compare['conflicts'] conflicted_deleted = compare['delete_conflicts'] || [] deleted_files = compare['deleted'] overall_changes = [updated_files, conflicted_files, deleted_files].flatten.size = @files.(overall_changes, "Download Progress") @files.download_files(updated_files, commit_sha1, progress: ) @files.download_files(conflicted_files, commit_sha1, progress: , postfix: '.conflicted') @files.delete_files_local(deleted_files, progress: , conflicted: conflicted_deleted) .finish @project.update_idx_with_commit!(commit, latest: latest) @project.generate_idx ("Jumped successfuly!", Thor::Shell::Color::GREEN) rescue => e Logger::log_error(e) ("Cant jump to the specified commit", Thor::Shell::Color::RED) end end |
#link ⇒ Object
717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 |
# File 'lib/cnvrg/cli.rb', line 717 def link begin verify_logged_in(false) log_start(__method__, args, ) docker_image = ["docker_image"] bucket = ["bucket"] if docker_image.present? docker = true else docker = false end sync = ["sync"] git = ["git"] || false project_name = ['title'] project_name ||= File.basename(Dir.getwd) ("Linking #{project_name}", Thor::Shell::Color::BLUE) if File.directory?(Dir.getwd + "/.cnvrg") config = YAML.load_file("#{Dir.getwd}/.cnvrg/config.yml") ("Directory is already linked to #{config[:project_slug]}", Thor::Shell::Color::RED) exit(0) end working_dir = Dir.getwd owner = CLI.get_owner if Project.link(owner, project_name, docker,git, bucket: bucket) path = Dir.pwd @project = Project.new(path) if sync @project.generate_idx() #DEV-741 ("Syncing project", Thor::Shell::Color::BLUE) upload(true) end url = @project.url check = Helpers.checkmark ("#{check} Link finished successfully", Thor::Shell::Color::GREEN) ("#{project_name}'s location is: #{url}\n", Thor::Shell::Color::GREEN) else @project.revert(working_dir) unless @project.nil? ("Error linking project, please contact support.", Thor::Shell::Color::RED) exit(0) end rescue => e log_error(e) rescue SignalException say "\nAborting", Thor::Shell::Color::RED exit(1) end end |
#link_git(project_url) ⇒ Object
1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 |
# File 'lib/cnvrg/cli.rb', line 1861 def link_git(project_url) begin verify_logged_in(false) log_start(__method__, args, ) url_parts = project_url.split("/") project_index = Cnvrg::Helpers.look_for_in_path(project_url, "projects") slug = url_parts[project_index + 1] owner = url_parts[project_index - 1] response = Cnvrg::API.request("users/#{owner}/projects/#{slug}/get_project", 'GET') Cnvrg::CLI.is_response_success(response) response = JSON.parse response["result"] project_name = response["title"] ("Linking #{project_name}", Thor::Shell::Color::BLUE) clone_resp = Project.clone_dir_remote(slug, owner, project_name, true) idx_status = Project.new(get_project_home).generate_idx ("Linking project #{project_name} successfully", Thor::Shell::Color::GREEN) return rescue => e ("Error occurred, \nAborting", Thor::Shell::Color::RED) log_error(e) return rescue SignalException say "\nAborting", Thor::Shell::Color::BLUE return end end |
#list_commits ⇒ Object
1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 |
# File 'lib/cnvrg/cli.rb', line 1819 def list_commits() verify_logged_in(true) log_start(__method__, args, ) project_dir = is_cnvrg_dir(Dir.pwd) @project = Project.new(project_dir) result = @project.list_commits() list = result["result"]["list"] print_table(list) end |
#list_dataset ⇒ Object
1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 |
# File 'lib/cnvrg/cli.rb', line 1742 def list_dataset verify_logged_in(false) log_start(__method__, args, ) dataset_dir = is_cnvrg_dir(Dir.pwd) @dataset = Dataset.new(dataset_dir) owner = @dataset.owner if owner.nil? or owner.empty? owner = CLI.get_owner() end result = @dataset.list(owner) Cnvrg::CLI.is_response_success(result) list = result["result"]["list"] print_table(list) end |
#list_dataset_commits(dataset_url, commit_sha1: nil) ⇒ Object
1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 |
# File 'lib/cnvrg/cli.rb', line 1800 def list_dataset_commits(dataset_url, commit_sha1: nil) verify_logged_in(false) log_start(__method__, args, ) if dataset_url == "." dataset_dir = is_cnvrg_dir(Dir.pwd) @dataset = Dataset.new(dataset_dir) else owner, slug = get_owner_slug(dataset_url) @dataset = Dataset.new(dataset_info: {:owner => owner, :slug => slug}) end result = @dataset.list_commits(commit_sha1:commit_sha1) list = result["result"]["list"] print_table(list) end |
#list_files_dataset ⇒ Object
2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 |
# File 'lib/cnvrg/cli.rb', line 2222 def list_files_dataset() begin verify_logged_in(true) log_start(__method__, args, ) commit = [:commit] as_json = [:json] dataset_dir = is_cnvrg_dir(Dir.pwd) @dataset = Dataset.new(dataset_dir) resp = @dataset.list_files(commit, as_json) if (resp and resp["result"]) if as_json puts resp["result"] else print_table(resp["result"]) end end rescue => e puts e rescue SignalException @dataset.set_next_commit(commit) ("Aborting", Thor::Shell::Color::YELLOW) exit(1) end end |
#list_images ⇒ Object
4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 |
# File 'lib/cnvrg/cli.rb', line 4914 def list_images begin verify_logged_in(false) log_start(__method__, args, ) owner = Cnvrg::CLI.get_owner() res = Cnvrg::API.request("users/#{owner}/images/list", 'GET') if Cnvrg::CLI.is_response_success(res) printf "%-20s %-20s %-30s %-20s %-20s\n", "name", "project", "created by", "is_public", "last updated" res["result"]["images"].each do |u| time = Time.parse(u["created_at"]) update_at = get_local_time(time) created_by = u["created_by"] printf "%-20s %-20s %-30s %-20s %-20s\n", u["name"], u["project"], created_by, u["is_public"], update_at end end return res["result"]["images"] rescue SignalException say "\nAborting" exit(1) end end |
#list_machines ⇒ Object
4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 |
# File 'lib/cnvrg/cli.rb', line 4940 def list_machines begin verify_logged_in(false) log_start(__method__, args, ) owner = Cnvrg::CLI.get_owner() res = Cnvrg::API.request("users/#{owner}/machines/list", 'GET') if Cnvrg::CLI.is_response_success(res) printf "%-20s %-20s %-20s\n", "name", "created by", "last_used" res["result"]["machines"].each do |u| time = Time.parse(u["last_used"]) update_at = get_local_time(time) printf "%-20s %-20s %-20s\n", u["name"], u["created_by"], update_at end end return res["result"]["images"] rescue SignalException say "\nAborting" exit(1) end end |
#login ⇒ Object
500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 |
# File 'lib/cnvrg/cli.rb', line 500 def login use_token = ["sso"] begin log_handler() log_start(__method__, args, ) cmd = HighLine.new say 'Authenticating with cnvrg', Thor::Shell::Color::YELLOW @auth = Cnvrg::Auth.new netrc = Netrc.read @email, token = netrc[Cnvrg::Helpers.netrc_domain] if @email and token ('Seems you\'re already logged in', Thor::Shell::Color::BLUE) exit(0) end @email = ask("Enter your email:") url = Cnvrg::API.endpoint_uri() use_token = true if url.include?("cloud.cnvrg.io") if use_token @token = cmd.ask("Enter your token (hidden):") {|q| q.echo = "*"} netrc[Cnvrg::Helpers.netrc_domain] = @email, @token netrc.save password = "" else password = cmd.ask("Enter your password (hidden):") {|q| q.echo = "*"} end result = @auth.sign_in(@email, password, token: @token) if !result["token"].nil? unless use_token netrc[Cnvrg::Helpers.netrc_domain] = @email, result["token"] netrc.save end ("Authenticated successfully as #{@email}", Thor::Shell::Color::GREEN) owners = result["owners"] choose_owner = result["username"] if owners.empty? choose_owner = result["username"] else choose_owner = owners[0] end if set_owner(choose_owner, result["username"]) ("Setting default owner: #{choose_owner}", Thor::Shell::Color::GREEN) else ("Setting default owenr has failed, logging out", Thor::Shell::Color::RED) return logout() end else ("Failed to authenticate, wrong email/password", Thor::Shell::Color::RED) exit(1) end rescue => e ("Error Occurred, aborting", Thor::Shell::Color::RED) log_error(e) logout() exit(1) rescue SignalException say "\nAborting",Thor::Shell::Color::RED logout() exit(1) end end |
#logout ⇒ Object
579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 |
# File 'lib/cnvrg/cli.rb', line 579 def logout begin log_handler() log_start(__method__, args, ) netrc = Netrc.read netrc.delete(Cnvrg::Helpers.netrc_domain) netrc.save ("Logged out successfully.\n", Thor::Shell::Color::GREEN) rescue => e puts e. puts e.backtrace rescue SignalException say "\nAborting",Thor::Shell::Color::RED exit(1) end end |
#logs ⇒ Object
634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 |
# File 'lib/cnvrg/cli.rb', line 634 def logs() begin lines = ["lines"] if lines.present? puts open($LOG.device.io.path).readlines.last(lines) else puts open($LOG.device.io.path).readlines.last(100) end rescue SignalException say "\nAborting", Thor::Shell::Color::RED exit(1) end end |
#me ⇒ Object
600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 |
# File 'lib/cnvrg/cli.rb', line 600 def me() begin home_dir = File.('~') config = YAML.load_file(home_dir+"/.cnvrg/config.yml") api = config[:api] verify_ssl = config[:verify_ssl] if api.present? ("API: #{api}", Thor::Shell::Color::BLUE) end if verify_ssl.present? ("SSL Verification: #{verify_ssl}", Thor::Shell::Color::BLUE) end ("Logs file located at: #{$LOG.device.io.path}", Thor::Shell::Color::BLUE) verify_logged_in(false) log_start(__method__, args, ) auth = Cnvrg::Auth.new if (email = auth.get_email) ("Logged in as: #{email}", Thor::Shell::Color::GREEN) else ("You're not logged in.", Thor::Shell::Color::RED) end rescue SignalException say "\nAborting", Thor::Shell::Color::RED exit(1) end end |
#new(project_name) ⇒ Object
Projects
652 |
# File 'lib/cnvrg/cli.rb', line 652 desc 'new', 'Create a new cnvrg project' |
#notebook ⇒ Object
3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 |
# File 'lib/cnvrg/cli.rb', line 3790 def notebook verify_logged_in(true) log_start(__method__, args, ) local = ["local"] notebook_dir = ["notebook_dir"] datasets = ["datasets"] kernel = ["kernel"] image = ["image"] || nil data = ["data"] data_commit = ["data_commit"] dataset_only_tree = ["dataset_only_tree"] data_query = ["data_query"] if !data.present? and data_query.present? ("Please provide data with data_query", Thor::Shell::Color::RED) exit(1) end if data_query.present? and (data_commit.present? or dataset_only_tree.present?) ("Please use only one option: --query(-q) or #{data_commit.present? ? '--data_commit' : '--dataset_only_tree'} ", Thor::Shell::Color::RED) exit(1) end if local invoke :run_notebook, [], :notebook_dir => notebook_dir, :remote => false, :kernel => kernel, :image => image return else instances = {"small" => ["small"], "medium" => ["medium"], "large" => ["large"], "gpu" => ["gpu"], "gpuxl" => ["gpuxl"], "gpuxxl" => ["gpuxxl"]} instance_type = get_instance_type(instances) invoke :remote_notebook, [], :notebook_dir => notebook_dir, :kernel => kernel, :machine_type => instance_type, :image => image, :data => data, :data_commit => data_commit , :dataset_only_tree => dataset_only_tree, :data_query => data_query, :datasets => datasets return end end |
#notebook_stop(notebook_slug) ⇒ Object
4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 |
# File 'lib/cnvrg/cli.rb', line 4279 def notebook_stop(notebook_slug) begin verify_logged_in(true) log_start(__method__, args, ) project_dir = is_cnvrg_dir() @project = Project.new(project_dir) @note = Experiment.new(@project.owner, @project.slug) ("Stoping notebook session: #{notebook_slug}", Thor::Shell::Color::BLUE) res = @note.end_notebook_session(notebook_slug) if res check = Helpers.checkmark() ("#{check} Notebook session has stopped successfully", Thor::Shell::Color::GREEN) exit(0) else ("Couldn't stop notebook session, try stopping via cnvrg web", Thor::Shell::Color::RED) exit(1) end rescue => e ("Error occurd, aborting", Thor::Shell::Color::RED) log_error(e) rescue SignalException ("Aborting", Thor::Shell::Color::BLUE) exit(1) end end |
#push(*name) ⇒ Object
4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 |
# File 'lib/cnvrg/cli.rb', line 4581 def push(*name) verify_logged_in(true) log_start(__method__, args, ) working_dir = is_cnvrg_dir() if !name.empty? and name == "cnvrg" ("can't create image with the name cnvrg", Thor::Shell::Color::RED) exit(1) end begin image = is_project_with_docker(working_dir) if !image or !image.is_docker ("Couldn't find image related to project", Thor::Shell::Color::RED) exit(0) end if !name.nil? and !name.empty? if name.include? " " name.gsub!(" ", "_") end end stored_commands = File.open(working_dir + "/.cnvrg/custom_image.txt").read.chop.gsub("\n", ",") if stored_commands.nil? or stored_commands.empty? ("Nothing to push", Thor::Shell::Color::BLUE) exit(0) end ("Pushing new image", Thor::Shell::Color::BLUE) if image.create_custom_image(name, working_dir, stored_commands) ("Image was updated successfully", Thor::Shell::Color::GREEN) end rescue => e ("error occurred, aborting", Thor::Shell::Color::RED) log_error(e) end end |
#queries ⇒ Object
1764 1765 1766 1767 1768 1769 1770 1771 |
# File 'lib/cnvrg/cli.rb', line 1764 def queries verify_logged_in(false) log_start(__method__, args, ) dataset_dir = is_cnvrg_dir(Dir.pwd) @dataset = Dataset.new(dataset_dir) result = @dataset.search_queries() print_table(result) end |
#query_files(query) ⇒ Object
1789 1790 1791 1792 1793 1794 1795 1796 1797 |
# File 'lib/cnvrg/cli.rb', line 1789 def query_files(query) verify_logged_in(false) log_start(__method__, args, ) dataset_dir = is_cnvrg_dir(Dir.pwd) @dataset = Dataset.new(dataset_dir) query = ["query"] || query result = @dataset.get_query_file(query) print_table(result) end |
#remote_notebook ⇒ Object
3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 |
# File 'lib/cnvrg/cli.rb', line 3926 def remote_notebook() verify_logged_in(true) log_start(__method__, args, ) working_dir = is_cnvrg_dir() instance_type = ["machine_type"] || nil datasets = ["datasets"] data = ["data"] data_commit = ["data_commit"] commit = ["commit"] notebook_type = ["notebook_type"] dataset_only_tree = ["dataset_only_tree"] image = ["image"] = 0 if dataset_only_tree = 1 end data_query = nil if data.present? data_query = ["data_query"] end if data_commit.present? and data_query.present? ("Please use only one option: --query(-q) or --data_commit ", Thor::Shell::Color::RED) exit(1) end begin project = Project.new(working_dir) exp = Experiment.new(project.owner, project.slug) if !notebook_type.nil? and !notebook_type.empty? notebook_type = "jupyter" end invoke :sync, [false], [] slug = "" res = exp.remote_notebook(instance_type, commit, data, data_commit, notebook_type,,data_query, image, datasets) if Cnvrg::CLI.is_response_success(res) slug = res["result"]["notebook_url"] ("#{Helpers.checkmark} Notebook is ready: #{Cnvrg::Helpers.remote_url}/#{project.owner}/projects/#{project.slug}/notebook_sessions/show/#{slug}", Thor::Shell::Color::GREEN) end rescue => e ("Error occurred, Aborting", Thor::Shell::Color::RED) log_error(e) rescue SignalException ("Aborting", Thor::Shell::Color::BLUE) notebook_stop(slug) unless slug.nil? or slug.empty? exit(1) end end |
#remote_notebook_old ⇒ Object
3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 |
# File 'lib/cnvrg/cli.rb', line 3835 def remote_notebook_old() verify_logged_in(true) log_start(__method__, args, ) working_dir = is_cnvrg_dir() notebook_dir = ["notebook_dir"] instance_type = ["machine_type"] || nil kernel = ["kernel"] || nil data = ["data"] data_commit = ["data_commit"] begin choose_image = ["image"] if !choose_image.nil? and !choose_image.empty? invoke :set_image, [choose_image] end invoke :sync, [false], [] res = @image.remote_notebook(notebook_dir, instance_type, kernel, data, data_commit) if Cnvrg::CLI.is_response_success(res) if res["result"]["machine"] == -1 ("There are no available machines", Thor::Shell::Color::BLUE) create = yes? "create new machine?", Thor::Shell::Color::YELLOW if create res = Cnvrg::API.request("users/#{@image.owner}/machines/list", 'GET') if Cnvrg::CLI.is_response_success(res) instance_type = (res["result"]["aws_options"]) if @image.new_machine(instance_type) res = @image.remote_notebook(notebook_dir, instance_type, kernel) if Cnvrg::CLI.is_response_success(res) url = res["result"]["url"] if !url.nil? and !url.empty? check = Helpers.checkmark() ("#{check} Notebook server started successfully: #{url}", Thor::Shell::Color::GREEN) else ("Couldn't run notebook server", Thor::Shell::Color::RED) end exit(0) end end else ("No machines are avilable", Thor::Shell::Color::RED) exit(0) end else ("Can't execute command on remote machine with local image", Thor::Shell::Color::RED) exit(1) end else note_url = res["result"]["notebook_url"] @image.set_note_url(note_url) check = Helpers.checkmark() ("#{check} Notebook is on: #{Cnvrg::Helpers.remote_url}/#{@image.owner}/projects/#{@image.project_slug}/notebook_sessions/show/#{note_url}", Thor::Shell::Color::GREEN) # Launchy.open(url) exit(0) end end rescue => e ("Error occurred, Aborting", Thor::Shell::Color::RED) log_error(e) rescue SignalException exit_status = -1 end_commit = @project.last_local_commit res = @exp.end(log, exit_status, end_commit, cpu_average, memory_average) say "\nAborting" exit(1) end end |
#revert_exp ⇒ Object
2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 |
# File 'lib/cnvrg/cli.rb', line 2033 def revert_exp begin log_start(__method__, args, ) @project = Project.new(get_project_home) ignore_list = @project.get_ignore_list() result = @project.compare_idx(false)["result"] result = result["tree"] if result["added"].size > 0 FileUtils.rm_rf(result["added"]) end say "Changes were removed successfully", Thor::Shell::Color::GREEN rescue SignalException log_end(-1) say "\nAborting" exit(1) end end |
#run(*cmd) ⇒ Object
3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 |
# File 'lib/cnvrg/cli.rb', line 3108 def run(*cmd) verify_logged_in(true) log_start(__method__, args, ) datasets = ["datasets"] sync_before = ["sync_before"] sync_after = ["sync_after"] log = ["log"] debug = ["debug"] title = ["title"] commit = ["commit"] || nil email_notification = ["email_notification"] upload_output = ["upload_output"] local = ["local"] schedule = ["schedule"] recurring = ["recurring"] image = ["image"] || nil grid = ["grid"] data = ["data"] data_commit = ["data_commit"] ignore = ["ignore"] sync_before_terminate = ["sync_before_terminate"] periodic_sync = ["periodic_sync"] force = ["force"] max_time = ["max_time"] dataset_only_tree = ["dataset_only_tree"] custom_machine = ["machine"] output_dir = ["output_dir"] data_query = ["data_query"] local_folders = ["local_folders"] prerun = ["prerun"] requirements = ["requirements"] email_notification_error = ["notify_on_error"] email_notification_success = ["notify_on_success"] emails = ["emails"] wait = ["wait"] if wait && local ("WARN: `wait` option is not valid for local experiment, ignoring it", Thor::Shell::Color::YELLOW) wait = false end if !data.present? and data_query.present? ("Please provide data with data_query", Thor::Shell::Color::RED) exit(1) end if data_query.present? and (data_commit.present? or dataset_only_tree.present?) ("Please use only one option: --query(-q) or #{data_commit.present? ? '--data_commit' : '--dataset_only_tree'} ", Thor::Shell::Color::RED) exit(1) end git_commit = ["git_commit"] git_branch = ["git_branch"] restart_if_stuck = ["restart_if_stuck"] = Hash[] if local if Cnvrg::Helpers.windows? say "Windows is currently not supported for running experiments locally" return else invoke :exec, [cmd], :sync_before => sync_before, :sync_after => sync_after, :title => title, :log => log, :email_notification => email_notification, :upload_output => upload_output, :commit => commit, :image => image, :data => data, :data_commit => data_commit, :ignore => ignore, :force => force, :output_dir=>output_dir, :data_query=>data_query, :local => local return end else if !periodic_sync.nil? and !periodic_sync.empty? if /^\d{2}$/ === periodic_sync if !["15","30","45","60"].include? periodic_sync ("periodic sync can only be every 15m, 30m, 45m or 60m", Thor::Shell::Color::RED) exit(1) end else ("periodic sync has to be one of the following values: 15m, 30m, 45m or 60m", Thor::Shell::Color::RED) exit(1) end end instances = { "small" => ["small"], "medium" => ["medium"], "large" => ["large"], "gpu" => ["gpu"], "gpuxl" => ["gpuxl"], "gpuxxl" => ["gpuxxl"], ["machine"] => !["machine"].blank? } instance_type = get_instance_type(instances) invoke :exec_remote, [cmd], :sync_before => sync_before, :sync_after => sync_after, :title => title, :machine_type => instance_type, :schedule => schedule, :recurring => recurring, :log => log, :email_notification => email_notification, :upload_output => upload_output, :commit => commit, :image => image, :grid => grid, :data => data, :data_commit => data_commit, :ignore => ignore, :force => force, :sync_before_terminate => sync_before_terminate, :max_time => max_time, :periodic_sync => periodic_sync, :dataset_only_tree=> dataset_only_tree, :output_dir=>output_dir, :data_query=>data_query, :git_commit =>git_commit, :git_branch=> git_branch, :debug => debug, :restart_if_stuck =>restart_if_stuck, :local_folders => local_folders, :datasets => datasets, :prerun => prerun, :requirements => requirements, :email_notification_error => email_notification_error, :email_notification_success => email_notification_success, :emails => emails, :wait => wait return end end |
#run_notebook ⇒ Object
4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 |
# File 'lib/cnvrg/cli.rb', line 4109 def run_notebook begin verify_logged_in(true) log_start(__method__, args, ) project_dir = is_cnvrg_dir() notebook_dir = ["notebook_dir"] remote = ["remote"] || false kernel = ["kernel"] || "" notebooks_pid = nil if notebook_dir.empty? notebook_dir = project_dir else notebook_dir = project_dir + notebook_dir end choose_image = ["image"] if !choose_image.nil? and !choose_image.empty? invoke :set_image, [choose_image] end image = is_project_with_docker(Dir.pwd) if !image jupyter_installed = `which jupyter` if !$?.success? say "Could not find jupyter, Is it installed?", Thor::Shell::Color::RED exit(1) end cmd = "jupyter-notebook --port=8888" PTY.spawn(cmd) do |stdout, stdin, pid, stderr| begin notebooks_pid = pid stdout.each do |line| puts line end rescue Errno::EIO => e # break rescue Errno::ENOENT log_end(1, "command #{cmd} isn't valid") say "command \"#{cmd}\" couldn't be executed, verify command is valid", Thor::Shell::Color::RED rescue PTY::ChildExited log_end(1, "proccess exited") say "The process exited!", Thor::Shell::Color::RED rescue => e log_end(-1, e.) say "Error occurred,aborting", Thor::Shell::Color::RED exit(0) end end end if image and image.is_docker and !remote container = image.get_container if !container say "Couldn't start docker container", Thor::Shell::Color::RED exit(1) end if ["verbose"] say "Syncing project before running", Thor::Shell::Color::BLUE say 'Checking for new updates from remote version', Thor::Shell::Color::BLUE end @project = Project.new(project_dir) start_commit = @project.last_local_commit if (note_slug = image.note_slug) say "There is a running notebook session in: https://cnvrg.io/#{@project.owner}/projects/#{@project.slug}/notebook_sessions/show/#{note_slug}", Thor::Shell::Color::BLUE new = yes? "Create a new session?", Thor::Shell::Color::YELLOW if !new exit(0) end end invoke :sync, [false], :verbose => ["verbose"] say "Done Syncing", Thor::Shell::Color::BLUE if ["verbose"] #replace url base_url = get_base_url() local_url = "/#{@project.owner}/projects/#{@project.slug}/notebook_sessions/view/local" command = ["/bin/bash", "-lc", "sed -i 's#c.NotebookApp.base_url = .*#c.NotebookApp.base_url = \"#{local_url}\"#' /home/ds/.jupyter/jupyter_notebook_config.py"] container.exec(command, tty: true) container.stop() container.start() sleep(7) @note = Experiment.new(@project.owner, @project.slug) port = image.container_port() command = ["/bin/bash", "-lc", "jupyter notebook list"] list = container.exec(command, tty: true)[0] if list.empty? or list.nil? say "Couldn't start notebook server", Thor::Shell::Color::RED log_end(1, "can't start notebook server") exit(1) end result = "" list.each do |r| if r.include? "http" result = r end end token = result.to_s.split("::")[0].to_s.match(/(token=)(.+)\s/)[2] # machine_activity = @note.get_machine_activity(project_dir) slug = @note.start_notebook_session(kernel, start_commit, token, port, false, notebook_dir) image.set_note_url(slug) note_url = "http://localhost:#{port}/#{@project.owner}/projects/#{@project.slug}/notebook_sessions/view/local/?token=#{token}" if !note_url.empty? check = Helpers.checkmark() say "#{check} Notebook server started successfully: #{note_url}", Thor::Shell::Color::GREEN else say "Couldn't start notebook server", Thor::Shell::Color::RED log_end(1, "can't start notebook server") exit(1) end end rescue => e log_end(-1, e.) say "Error occurred, aborting", Thor::Shell::Color::RED if container container.stop() end rescue SignalException if !notebooks_pid.nil? ::Process.kill(0, notebooks_pid) say "#{check} Notebook has stopped successfully", Thor::Shell::Color::GREEN invoke :sync, [false], [] else log_end(-1) if container container.stop() end end end end |
#scan_datasets ⇒ Object
856 857 858 859 860 861 862 863 864 |
# File 'lib/cnvrg/cli.rb', line 856 def scan_datasets() begin verify_logged_in(false) log_start(__method__, args, ) ("Scanning datasets", Thor::Shell::Color::BLUE) datasets = Dataset.scan_datasets() puts(datasets.to_json) end end |
#search_libraries(library) ⇒ Object
3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 |
# File 'lib/cnvrg/cli.rb', line 3983 def search_libraries(library) begin verify_logged_in(true) log_start(__method__, args, ) project_dir = is_cnvrg_dir() image = is_project_with_docker(project_dir) if image and image.is_docker container = image.get_container if !container say "Couldn't create container with image #{image.image_name}:#{image.image_tag}", Thor::Shell::Color::RED exit(1) end else say "Project is not configured with any image", Thor::Shell::Color::RED exit(1) end say "Searching for #{library}", Thor::Shell::Color::BLUE pip_arr = image.get_installed_packages("python") pip_arr = pip_arr.map(&:downcase) check = Helpers.checkmark() if !(p = pip_arr.map {|x| x.split("==")[0]}.index(library.downcase)).nil? say "#{check} Found it!", Thor::Shell::Color::GREEN printf "%-40s %-30s\n", "#{pip_arr[p].split("==")[0]}", "#{pip_arr[p].split("==")[1]}" else dpkg_arr = image.get_installed_packages("system") dpkg_arr = dpkg_arr.map(&:downcase) if !(p = dpkg_arr.map {|x| x.split("==")[0]}.index(library.downcase)).nil? say "#{check} Found!", Thor::Shell::Color::GREEN printf "%-40s %-30s\n", "#{dpkg_arr[p].split("==")[0]}", "#{dpkg_arr[p].split("==")[1]}" else say "Couldn't find #{library}, run cnvrg install_libraries to install", Thor::Shell::Color::RED exit(1) end end rescue => e log_end(-1, e.) say "Error occurred, aborting", Thor::Shell::Color::RED if container container.stop() end rescue SignalException log_end(-1) if container container.stop() end say "Aborting" exit(1) end end |
#set_api_url(url) ⇒ Object
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 |
# File 'lib/cnvrg/cli.rb', line 236 def set_api_url(url) log_handler() log_start(__method__, args, ) home_dir = File.('~') if url.end_with? "/" url = url.chomp("/") end if !url.end_with? "/api" url = url + "/api" end verify_ssl = ["verify_ssl"] || false begin if !File.directory? home_dir + "/.cnvrg" FileUtils.mkdir_p([home_dir + "/.cnvrg", home_dir + "/.cnvrg/tmp"]) end if !File.exist?(home_dir + "/.cnvrg/config.yml") FileUtils.touch [home_dir + "/.cnvrg/config.yml"] end compression_path = "#{File.('~')}/.cnvrg/tmp" begin config = YAML.load_file(home_dir+"/.cnvrg/config.yml") if !config config = {owner: "", username: "", version_last_check: get_start_day(), api: url, compression_path: compression_path ,verify_ssl: verify_ssl } end rescue config = {owner: "", username: "", version_last_check: get_start_day(), api: url, compression_path: compression_path ,verify_ssl: verify_ssl } end say "Setting default api to be: #{url}", Thor::Shell::Color::BLUE if config.empty? config = {owner: "", username: "", version_last_check: get_start_day(), api: url, compression_path: compression_path, verify_ssl: verify_ssl } else if !config.to_h[:compression_path].nil? compression_path = config.to_h[:compression_path] end config = {owner: config.to_h[:owner], username: config.to_h[:username], version_last_check: config.to_h[:version_last_check], api: url, compression_path: compression_path, verify_ssl: verify_ssl} end checks = Helpers.checkmark File.open(home_dir+"/.cnvrg/config.yml", "w+") { |f| f.write config.to_yaml } say "#{checks} Done", Thor::Shell::Color::GREEN rescue => e log_error(e) say "Couldn't set default api, contact [email protected]", Thor::Shell::Color::RED end end |
#set_compression_path(*compression_path) ⇒ Object
420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 |
# File 'lib/cnvrg/cli.rb', line 420 def set_compression_path(*compression_path) begin if (compression_path.nil? or compression_path.empty?) and ["reset"] compression_path = ["#{File.('~')}/.cnvrg/tmp"] end compression_path = compression_path.join(" ") if !Dir.exist? compression_path say "Couldn't find #{compression_path}, please make sure it exist", Thor::Shell::Color::RED exit(0) end home_dir = File.('~') path = "#{home_dir}/.cnvrg/config.yml" if !File.exist?(path) say "Couldn't find ~/.cnvrg/config.yml file, please logout and login again", Thor::Shell::Color::RED exit(0) end config = YAML.load_file(path) config_new = {owner: config.to_h[:owner], username: config.to_h[:username], version_last_check: config.to_h[:version_last_check], api: config.to_h[:api], compression_path: compression_path} File.open(home_dir + "/.cnvrg/config.yml", "w+") {|f| f.write config_new.to_yaml} checks = Helpers.checkmark say "#{checks} Done", Thor::Shell::Color::GREEN rescue SignalException say "\nAborting", Thor::Shell::Color::RED exit(1) end end |
#set_data_url(dataset_url) ⇒ Object
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 |
# File 'lib/cnvrg/cli.rb', line 207 def set_data_url(dataset_url) begin verify_logged_in(true) log_start(__method__, args, ) unless is_cnvrg_dir ("Not in cnvrg dir.", Thor::Shell::Color::RED) end url_parts = dataset_url.split("/") project_index = Cnvrg::Helpers.look_for_in_path(dataset_url, "datasets") slug = url_parts[project_index + 1] owner = url_parts[project_index - 1] res = Cnvrg::API.request("users/#{owner}/datasets/#{slug}", 'GET') unless Cnvrg::CLI.is_response_success(res, false) raise SignalException.new end @dataset = Dataset.new(Dir.pwd) result = res['result'] @dataset.change_url(result.symbolize_keys) ("Changed URL Succesfuly to #{dataset_url}", Thor::Shell::Color::GREEN) rescue => e ("Cant change the url to the given dataset url", Thor::Shell::Color::RED) end end |
#set_default_owner ⇒ Object
355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 |
# File 'lib/cnvrg/cli.rb', line 355 def set_default_owner begin path = File.('~') + "/.cnvrg/config.yml" if !File.exist?(path) say "Couldn't find ~/.cnvrg/config.yml file, please logout and login again", Thor::Shell::Color::RED exit(0) end config = YAML.load_file(path) username = config.to_h[:username] res = Cnvrg::API.request("/api/v1/users/#{username}/get_possible_owners", 'GET') if Cnvrg::CLI.is_response_success(res) owner = username result = res["result"] owners = result["owners"] urls = result["urls"] choose_owner = result["username"] if owners.empty? else chosen = false while !chosen owners_id = owners.each_with_index.map {|x, i| "#{i + 1}. #{x}"} choose_owner = ask("Choose default owner:\n" + owners_id.join("\n") + "\n") if choose_owner =~ /[[:digit:]]/ ow_index = choose_owner.to_i - 1 if ow_index < 0 or ow_index >= owners.size say "No such owner, please choose again", Thor::Shell::Color::BLUE chosen = false next end choose_owner = owners[choose_owner.to_i - 1] chosen = true else owners_lower = owners.map {|o| o.downcase} ow_index = owners_lower.index(choose_owner.downcase) if ow_index.nil? say "Could not find owner named #{choose_owner}", Thor::Shell::Color::RED else chosen = true end end end end if set_owner(choose_owner, result["username"]) say "Setting default owner: #{choose_owner}", Thor::Shell::Color::GREEN else say "Setting default owenr has failed, try to run cnvrg --config-default-owner", Thor::Shell::Color::RED end end rescue SignalException say "\nAborting", Thor::Shell::Color::RED exit(1) end end |
#set_remote_api_url(owner, current_user, url) ⇒ Object
328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 |
# File 'lib/cnvrg/cli.rb', line 328 def set_remote_api_url(owner, current_user, url) home_dir = File.('~') if !url.end_with? "/api" url = url + "/api" end begin if !File.directory? home_dir + "/.cnvrg" FileUtils.mkdir_p([home_dir + "/.cnvrg", home_dir + "/.cnvrg/tmp"]) end if !File.exist?(home_dir + "/.cnvrg/config.yml") FileUtils.touch [home_dir + "/.cnvrg/config.yml"] end config = YAML.load_file(home_dir + "/.cnvrg/config.yml") compression_path = "#{home_dir}/.cnvrg/tmp" config = {owner: owner, username: current_user, version_last_check: get_start_day(), api: url, compression_path: compression_path} File.open(home_dir + "/.cnvrg/config.yml", "w+") {|f| f.write config.to_yaml} say "Done", Thor::Shell::Color::GREEN rescue say "ERROR", Thor::Shell::Color::RED end end |
#set_remote_login(current_user, owner, url, email, secret) ⇒ Object
290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 |
# File 'lib/cnvrg/cli.rb', line 290 def set_remote_login(current_user, owner, url, email, secret) netrc = Netrc.read netrc[Cnvrg::Helpers.netrc_domain] = email, secret netrc.save home_dir = File.('~') if !url.end_with? "/api" url = url + "/api" end begin if !File.directory? home_dir + "/.cnvrg" FileUtils.mkdir_p([home_dir + "/.cnvrg", home_dir + "/.cnvrg/tmp"]) end if !File.exist?(home_dir + "/.cnvrg/config.yml") FileUtils.touch [home_dir + "/.cnvrg/config.yml"] end config = YAML.load_file(home_dir + "/.cnvrg/config.yml") compression_path = "#{home_dir}/.cnvrg/tmp" config = {owner: owner, username: current_user, version_last_check: get_start_day(), api: url, compression_path: compression_path} File.open(home_dir + "/.cnvrg/config.yml", "w+") {|f| f.write config.to_yaml} say "Done", Thor::Shell::Color::GREEN rescue say "ERROR", Thor::Shell::Color::RED File.open(home_dir+"/.cnvrg/config.yml", "w+") { |f| f.write config.to_yaml } say "#{checks} Done", Thor::Shell::Color::GREEN # else # say "Couldn't set default api, contact [email protected]", Thor::Shell::Color::RED # exit(1) # # end rescue => e say "Couldn't set default api, contact [email protected]", Thor::Shell::Color::RED end end |
#show ⇒ Object
2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 |
# File 'lib/cnvrg/cli.rb', line 2942 def show path = ['path'] commit = ['commit'] verify_logged_in(true) log_start(__method__, args, ) project_home = get_project_home @project = Project.new(project_home) @files = Cnvrg::Files.new(@project.owner, @project.slug, project: @project) begin file = @files.show_file_s3(path, commit) if file puts file else say "Couldn't find file" end end end |
#show_libraries ⇒ Object
4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 |
# File 'lib/cnvrg/cli.rb', line 4046 def show_libraries begin verify_logged_in(true) log_start(__method__, args, ) system = ["system"] || false project_dir = is_cnvrg_dir() image = is_project_with_docker(project_dir) if image and image.is_docker container = image.get_container if !container say "Couldn't create container with image #{image.image_name}:#{image.image_tag}", Thor::Shell::Color::RED exit(1) end else say "Project is not configured with any image", Thor::Shell::Color::RED exit(1) end say "Showing python installed libraries", Thor::Shell::Color::BLUE pip_arr = image.get_installed_packages("python") printf "%-40s %-30s\n", "name", "version" printf "%-40s %-30s\n", "====", "=======" pip_arr.each do |p| printf "%-40s %-30s\n", "#{p.split("==")[0]}", "#{p.split("==")[1]}" end if system say "Showing system installed libraries", Thor::Shell::Color::BLUE dpkg_arr = image.get_installed_packages("system") printf "%-40s %-30s\n", "name", "version" printf "%-40s %-30s\n", "====", "=======" dpkg_arr.each do |p| printf "%-40s %-30s\n", "#{p.split("==")[0]}", "#{p.split("==")[1]}" end end rescue => e log_end(-1, e.) say "Error occurred, aborting" if container container.stop() end rescue SignalException log_end(-1) say "Aborting" exit(1) end end |
#snap_data ⇒ Object
1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 |
# File 'lib/cnvrg/cli.rb', line 1054 def snap_data begin verify_logged_in(false) log_start(__method__, args, ) owner = CLI.get_owner path = Dir.pwd @dataset = Dataset.new(path) log_end(0) rescue SignalException log_end(-1) say "\nAborting", Thor::Shell::Color::RED exit(1) end end |
#start_commit_data ⇒ Object
2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 |
# File 'lib/cnvrg/cli.rb', line 2158 def start_commit_data() verify_logged_in(true) log_start(__method__, args, ) dataset_dir = is_cnvrg_dir(Dir.pwd) new_branch = ["new_branch"] || false force = ["force"] || false chunk_size = ["chunk_size"] || false = ["message"] @dataset = Dataset.new(dataset_dir) @dataset.backup_idx @files = Cnvrg::Datafiles.new(@dataset.owner, @dataset.slug, dataset: @dataset) next_commit = @dataset.get_next_commit #if there was a partial commit.. files_list = @dataset.list_all_files chunks = (files_list.length.to_f / chunk_size).ceil resp = @files.start_commit(new_branch, force, chunks: chunks, dataset: @dataset, message: ) if !resp['result']['can_commit'] ("Cant upload files because a new version of this dataset exists, please download it or upload with --force", Thor::Shell::Color::RED) exit(1) end commit_sha1 = resp["result"]["commit_sha1"] unless commit_sha1.eql? next_commit @dataset.set_partial_commit(next_commit) end @dataset.set_next_commit(commit_sha1) return commit_sha1, files_list end |
#status ⇒ Object
1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 |
# File 'lib/cnvrg/cli.rb', line 1974 def status begin verify_logged_in() log_start(__method__, args, ) @project = Project.new(get_project_home) new_branch = ["new_branch"] || false force = ["force"] || false result = @project.compare_idx(new_branch,force:force)["result"] commit = result["commit"] result = result["tree"] ("Comparing local changes with remote version:", Thor::Shell::Color::BLUE) if result["added"].empty? and result["updated_on_local"].empty? and result["updated_on_server"].empty? and result["deleted"].empty? and result["conflicts"].empty? ("Project is up to date", Thor::Shell::Color::GREEN) return true end if result["added"].size > 0 ("Added files:\n", Thor::Shell::Color::BLUE) result["added"].each do |a| ("\t\tA:\t#{a}", Thor::Shell::Color::GREEN) end end if result["deleted"].size > 0 ("Deleted files:\n", Thor::Shell::Color::BLUE) result["deleted"].each do |a| ("\t\tD:\t#{a}", Thor::Shell::Color::GREEN) end end if result["updated_on_local"].size > 0 ("Local changes:\n", Thor::Shell::Color::BLUE) result["updated_on_local"].each do |a| ("\t\tM:\t#{a}", Thor::Shell::Color::GREEN) end end if result["updated_on_server"].size > 0 ("Remote changes:\n", Thor::Shell::Color::BLUE) result["updated_on_server"].each do |a| ("\t\tM:\t#{a}", Thor::Shell::Color::GREEN) end end if result["conflicts"].size > 0 ("Conflicted changes:\n", Thor::Shell::Color::BLUE) result["conflicts"].each do |a| ("\t\tC:\t#{a}", Thor::Shell::Color::RED) end end rescue SignalException say "\nAborting" exit(1) end end |
#sync(direct = true) ⇒ Object
3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 |
# File 'lib/cnvrg/cli.rb', line 3037 def sync(direct = true) verify_logged_in(true) if direct @project = Project.new(get_project_home) log_start(__method__, args, ) ('Checking for new updates from remote version', Thor::Shell::Color::BLUE, ["verbose"]) ('Syncing project', Thor::Shell::Color::BLUE, !["verbose"]) job_slug = ['job_slug'] || ENV['CNVRG_JOB_ID'] job_type = ['job_type'] || ENV['CNVRG_JOB_TYPE'] is_git = ENV['CNVRG_GIT_PROJECT'] == "true" || @project.is_git in_exp = ["in_exp"] || (job_slug.present? and job_type.present?) in_exp = false if job_type.present? and job_type == "NotebookSession" output_dir = ["output_dir"] || ENV['CNVRG_OUTPUT_DIR'] run_download = true if (job_type == "NotebookSession" and is_git) or job_type == "Experiment" or ['force'] run_download = false end if run_download or ['debug_mode'] invoke :download, [true, "", in_exp ], :new_branch => ["new_branch"], :verbose => ["verbose"], :sync => true end invoke :upload, [false, true, direct, "", in_exp, [:force], output_dir, job_type, job_slug], :new_branch => ["new_branch"], :verbose => ["verbose"], :sync => true, :ignore => [:ignore], :force => [:force], :message => [:message], :deploy => ["deploy"], :return_id => ["return_id"], :files => ["files"], :output_dir => output_dir, :job_slug => job_slug, :job_type => job_type, :suppress_exceptions => ["suppress_exceptions"], :debug_mode => ['debug_mode'], :git_diff => ["git_diff"], :chunk_size => ["chunk_size"], :local => ["local"] end |
#sync_data_new(new_branch, force, verbose, commit, all_files, tags, parallel, chunk_size, init, message) ⇒ Object
2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 |
# File 'lib/cnvrg/cli.rb', line 2064 def sync_data_new(new_branch, force, verbose, commit, all_files, ,parallel, chunk_size, init, ) ("This method is deprecated, please use 'data put' instead. for more info visit our docs: https://app.cnvrg.io/docs/cli/install.html#upload-files-to-a-dataset", Thor::Shell::Color::BLUE, !["verbose"]) return verify_logged_in(true) log_start(__method__, args, ) ('Syncing dataset', Thor::Shell::Color::BLUE, !["verbose"]) if !force and !init # w(verbose=false, new_branch=false,sync=false, commit=nil,all_files=true) total_deleted, total_downloaded = invoke :download_data_new,[verbose, new_branch, true, commit, all_files], :new_branch=>new_branch, :direct=>false, :force =>force end invoke :upload_data_new,[new_branch, verbose, true, force, , chunk_size, message:, total_deleted: total_deleted, total_downloaded: total_downloaded], :new_branch=>new_branch, :direct=>false, :force =>force, :sync =>true, :tags =>, :parallel => parallel, :message => end |
#sync_image(docker = false) ⇒ Object
4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 |
# File 'lib/cnvrg/cli.rb', line 4550 def sync_image(docker = false) verify_logged_in(true) log_start(__method__, args, ) is_public = ["is_public"] || false is_base = ["is_base"] || false = ["message"] || "" image_id = commit_image if docker = "before running experiment" image = is_project_with_docker(Dir.pwd) if image and image.is_docker container = image.get_container if !container upload_image(image_id, is_public, is_base, ) else command = ["/bin/bash", "-lc", "cnvrg upload_image #{image_id} #{is_public} #{is_base} #{}"] puts "Running in contianer" container.exec(command, detach: false) end end else upload_image(image_id, is_public, is_base, ) end end |
#unlink ⇒ Object
1834 1835 1836 1837 1838 1839 1840 |
# File 'lib/cnvrg/cli.rb', line 1834 def unlink verify_logged_in(false) log_start(__method__, args, ) working_dir = is_cnvrg_dir() list_to_del = [working_dir + "/.cnvrg"] FileUtils.rm_rf list_to_del end |
#update_job_commit ⇒ Object
2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 |
# File 'lib/cnvrg/cli.rb', line 2706 def update_job_commit() job_type = ENV['CNVRG_JOB_TYPE'] job_id = ENV['CNVRG_JOB_ID'] return unless job_type.present? and job_id.present? verify_logged_in(true) log_start(__method__, args, ) project_home = get_project_home @project = Project.new(project_home) current_commit = @project.get_idx[:commit] rescue nil commit = @project.get_job_last_commit(job_type, job_id) if commit.present? and commit != current_commit invoke :download, [false, "", true ], :commit => commit end rescue end |
#update_jupyter_token ⇒ Object
2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 |
# File 'lib/cnvrg/cli.rb', line 2723 def update_jupyter_token() begin job_type = ENV['CNVRG_JOB_TYPE'] job_id = ENV['CNVRG_JOB_ID'] return unless job_type.present? and job_id.present? verify_logged_in(true) log_start(__method__, args, ) count = 0 token = nil while count < 20 res = `jupyter notebook list` match = res.match(/token=(\w+)/) if match.present? token = match[1] break end sleep(0.5) end if token.blank? ("Failed to find jupyter token", Thor::Shell::Color::RED) return end ("Found token #{token}", Thor::Shell::Color::BLUE) project_home = get_project_home @project = Project.new(project_home) puts(token) resp = @project.update_job_jupyter_token(job_type, job_id, token) if resp["status"] == 200 ("Updated jupter token successfully", Thor::Shell::Color::BLUE) else ("Failed to update jupyter token ", Thor::Shell::Color::RED) end rescue => e log_error(e) ("Error while trying to get jupyter token ", Thor::Shell::Color::RED) return end end |
#upload(link = false, sync = false, direct = false, ignore_list = "", in_exp = false, force = false, output_dir = "output", job_type = nil, job_slug = nil, suppress_exceptions = true, chunk_size = 1000) ⇒ Object
2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 |
# File 'lib/cnvrg/cli.rb', line 2333 def upload(link = false, sync = false, direct = false, ignore_list = "", in_exp = false, force = false, output_dir = "output", job_type = nil, job_slug = nil, suppress_exceptions = true,chunk_size=1000) begin # we are passing "force" twice.. doesnt really make sense :\\ verify_logged_in(true) log_start(__method__, args, ) @project = Project.new(get_project_home) chunk_size = chunk_size ? chunk_size : ["chunk_size"] # Enable local/experiment exception logging suppress_exceptions = suppress_exceptions ? suppress_exceptions : [:suppress_exceptions] if in_exp exp_obj = Experiment.new(@project.owner, @project.slug, job_id: job_slug) else exp_obj = nil end local = ["local"] commit_msg = ["message"] if commit_msg.nil? or commit_msg.empty? commit_msg = "" end return_id = ["return_id"] @files = Cnvrg::Files.new(@project.owner, @project.slug, project_home: get_project_home, project: @project) ignore = [:ignore] || "" force = [:force] || force || false spec_files_to_upload = ["files"] check = Helpers.checkmark() if !spec_files_to_upload.blank? spec_files_to_upload = spec_files_to_upload.split(",") end if @project.is_git list = [] git_output_dir = ["output_dir"] || output_dir if git_output_dir.present? if git_output_dir.ends_with? "/" git_output_dir = git_output_dir[0..-2] end list = @project.generate_output_dir(git_output_dir, local: local) end list += @project.generate_git_diff if ["git_diff"] spec_files_to_upload = list if spec_files_to_upload.blank? ("#{check} Project is up to date", Thor::Shell::Color::GREEN, (((["sync"] or sync) and !direct) ? false : true)) return true end end if ignore.nil? or ignore.empty? ignore = ignore_list end if job_type != "Experiment" data_ignore = data_dir_include() end if !data_ignore.nil? if ignore.nil? or ignore.empty? ignore = data_ignore else ignore = "#{ignore},#{data_ignore}" end end if !@project.update_ignore_list(ignore) ("Couldn't append new ignore files to .cnvrgignore", Thor::Shell::Color::YELLOW) end new_branch = ["new_branch"] || @project.is_branch result = @project.compare_idx(new_branch, force: force, deploy: ["deploy"], in_exp: in_exp, specific_files: spec_files_to_upload) commit = result["result"]["commit"] if !link if (result["result"]["new_version_exist"] and !force) or ((commit != @project.last_local_commit and !@project.last_local_commit.nil? and !result["result"]["tree"]["updated_on_server"].empty?) and !force) ("Remote server has an updated version, please run `cnvrg download` first, or alternatively: `cnvrg sync`", Thor::Shell::Color::BLUE) return false end ("Comparing local changes with remote version:", Thor::Shell::Color::BLUE, (["verbose"])) end result = result["result"]["tree"] if result["added"].empty? and result["updated_on_local"].empty? and result["deleted"].empty? msg = "#{check} Project is up to date" if return_id Cnvrg::Logger.(msg: msg, success: true) else (msg, Thor::Shell::Color::GREEN, (((["sync"] or sync) and !direct) ? false : true)) end return true end update_count = 0 update_total = result["added"].size + result["updated_on_local"].size + result["deleted"].size if ["verbose"] if update_total == 1 ("Updating #{update_total} file", Thor::Shell::Color::BLUE) else ("Updating #{update_total} files", Thor::Shell::Color::BLUE) end else ("Syncing files", Thor::Shell::Color::BLUE, ((["sync"] or sync)) ? false : true) end # Start commit current_commit = nil exp_start_commit = nil if in_exp || (job_slug.present? and job_type.present?) exp_start_commit = @project.last_local_commit else current_commit = @project.last_local_commit end job_type = ['job_type'] || job_type job_slug = ['job_slug'] || job_slug commit_sha1 = @files.start_commit( new_branch, force: force, exp_start_commit: exp_start_commit, job_type: job_type, job_slug: job_slug, start_commit: current_commit,message: ["message"], debug_mode: ["debug_mode"] )["result"]["commit_sha1"] # upload / update # delete to_upload = result["added"] + result["updated_on_local"] deleted = result["deleted"] = ProgressBar.create(:title => "Upload Progress", :progress_mark => '=', :format => "%b>>%i| %p%% %t", :starting_at => 0, :total => (to_upload.size + deleted.size), :autofinish => true) buffered_errors = @files.upload_multiple_files(to_upload, commit_sha1, progress: , suppress_exceptions: suppress_exceptions, chunk_size: chunk_size) @files.delete_files_from_server(deleted, commit_sha1, suppress_exceptions: suppress_exceptions) .finish if buffered_errors.is_a?(Hash) buffered_errors.keys.each do |file| to_upload.delete(file) Cnvrg::CLI.(buffered_errors[file], 'red') exp_obj.job_log([buffered_errors[file]]) unless exp_obj.nil? end end res = @files.end_commit(commit_sha1, force: force, message: commit_msg) unless Cnvrg::CLI.is_response_success(res, false) raise StandardError.new("Cant end commit") end # save idx @project.update_idx_with_files_commits!((to_upload + deleted), res["result"]["commit_time"]) @project.update_idx_with_commit!(commit_sha1) if ["verbose"] ("#{check} Done", Thor::Shell::Color::BLUE) ("Total of #{update_count} / #{update_total} files.", Thor::Shell::Color::GREEN) else if return_id puts "\n" print_res = { 'success' => "true", 'commit_sha1' => res["result"]["commit_id"] } puts JSON[print_res] return JSON[print_res] end if (["sync"] or sync) and direct ("#{check} Syncing project completed successfully", Thor::Shell::Color::GREEN) return true else ("#{check} Changes were updated successfully", Thor::Shell::Color::GREEN) return true end end rescue => e = "Error occured, #{e.}\nAborting" if e.is_a? SignalException say "\nAborting", Thor::Shell::Color::BLUE say "\nRolling back all changes", Thor::Shell::Color::BLUE exp_obj.job_log(["Aborting", "Rolling back all changes"]) unless exp_obj.nil? else (, Thor::Shell::Color::RED) log_error(e) exp_obj.job_log([, e]) unless exp_obj.nil? end @files.rollback_commit(commit_sha1) unless commit_sha1.nil? print_res = { 'success' => "false", 'message' => } puts "\n" puts JSON[print_res] if return_id return false end end |
#upload_cnvrg_image(image_path, image_name, secret) ⇒ Object
4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 |
# File 'lib/cnvrg/cli.rb', line 4766 def upload_cnvrg_image(image_path, image_name, secret) begin verify_logged_in(false) @files = Cnvrg::Files.new("", "") say "Uploading cnvrg image file", Thor::Shell::Color::BLUE res = @files.upload_cnvrg_image(image_path, image_name, secret) if res say "Successfully uploaded cnvrg image file", Thor::Shell::Color::GREEN else say "Couldn't upload cnvrg image file", Thor::Shell::Color::RED end rescue => e puts e puts e.backtrace end end |
#upload_data(sync = false, direct = false) ⇒ Object
1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 |
# File 'lib/cnvrg/cli.rb', line 1357 def upload_data(sync = false, direct = false) begin verify_logged_in(true) log_start(__method__, args, ) dataset_dir = is_cnvrg_dir(Dir.pwd) @dataset = Dataset.new(dataset_dir) @files = Cnvrg::Datafiles.new(@dataset.owner, @dataset.slug) ignore = [:ignore] || [] if !@dataset.update_ignore_list(ignore) ("Couldn't append new ignore files to .cnvrgignore", Thor::Shell::Color::YELLOW) end result = @dataset.compare_idx(false) commit = result["result"]["commit"] if commit != @dataset.last_local_commit and !@dataset.last_local_commit.nil? and !result["result"]["tree"]["updated_on_server"].empty? ("Remote server has an updated version, please run `cnvrg download` first, or alternatively: `cnvrg sync`", Thor::Shell::Color::BLUE) exit(1) end ("Comparing local changes with remote version:", Thor::Shell::Color::BLUE, ["verbose"] ? true : false) result = result["result"]["tree"] # if result["added"].any? {|x| x.include? ".conflict"} or !result["conflicts"].empty? # all = result["added"].select {|x| x.include? ".conflict"} +result["conflicts"].flatten # if all.size == 1 # num = "conflict" # else # num = "conflicts" # end # say "Project contains #{all.size} #{num}:", Thor::Shell::Color::RED # say "#{all.join("\n")}" # say "Please fix #{num}, and retry", Thor::Shell::Color::RED # exit(1) # # en check = Helpers.checkmark() if result["added"].empty? and result["updated_on_local"].empty? and result["deleted"].empty? ("#{check} Dataset is up to date", Thor::Shell::Color::GREEN, (((["sync"] or sync) and !direct) ? false : true)) return true end update_count = 0 update_total = result["added"].size + result["updated_on_local"].size + result["deleted"].size successful_updates = [] successful_deletions = [] if ["verbose"] if update_total == 1 ("Updating #{update_total} file", Thor::Shell::Color::BLUE) else ("Updating #{update_total} files", Thor::Shell::Color::BLUE) end else ("Syncing files", Thor::Shell::Color::BLUE, ((["sync"] or sync)) ? false : true) end # Start commit commit_sha1 = @files.start_commit(false)["result"]["commit_sha1"] # upload / update begin (result["added"] + result["updated_on_local"]).each do |f| absolute_path = "#{@dataset.local_path}/#{f}" relative_path = f.gsub(/^#{@dataset.local_path + "/"}/, "") if File.directory?(absolute_path) resDir = @files.create_dir(absolute_path, relative_path, commit_sha1) if resDir update_count += 1 successful_updates << relative_path end else res = @files.upload_file(absolute_path, relative_path, commit_sha1) if res update_count += 1 successful_updates << relative_path else @files.rollback_commit(commit_sha1) ("Couldn't upload, Rolling Back all changes.", Thor::Shell::Color::RED) exit(0) end end end # delete deleted = update_deleted(result["deleted"]) deleted.each do |f| relative_path = f.gsub(/^#{@dataset.local_path + "/"}/, "") if relative_path.end_with?("/") if @files.delete_dir(f, relative_path, commit_sha1) # update_count += 1 successful_updates << relative_path end else if @files.delete_file(f, relative_path, commit_sha1) # update_count += 1 successful_updates << relative_path end end end rescue SignalException @files.rollback_commit(commit_sha1) say "User aborted, Rolling Back all changes.", Thor::Shell::Color::RED exit(0) rescue => e ("Exception while trying to upload, Rolling back", Thor::Shell::Color::RED) log_error(e) @files.rollback_commit(commit_sha1) exit(0) end if !result["deleted"].nil? and !result["deleted"].empty? update_count += result["deleted"].size end if update_count == update_total res = @files.end_commit(commit_sha1,false) if (Cnvrg::CLI.is_response_success(res, false)) # save idx begin list_files = [] list_files.concat successful_deletions list_files.concat successful_updates @dataset.update_idx_with_files_commits!(list_files, res["result"]["commit_time"]) @dataset.update_idx_with_commit!(commit_sha1) rescue => e ("Couldn't commit updates, Rolling Back all changes.", Thor::Shell::Color::RED) log_error(e) @files.rollback_commit(commit_sha1) exit(1) end if ["verbose"] ("#{check} Done", Thor::Shell::Color::BLUE) if successful_updates.size > 0 ("Updated:", Thor::Shell::Color::GREEN) suc = successful_updates.map {|x| x = Helpers.checkmark() + " " + x} (suc.join("\n"), Thor::Shell::Color::GREEN) end if successful_deletions.size > 0 ("Deleted:", Thor::Shell::Color::GREEN) del = successful_updates.map {|x| x = Helpers.checkmark() + " " + x} (del.join("\n"), Thor::Shell::Color::GREEN) end ("Total of #{update_count} / #{update_total} files.", Thor::Shell::Color::GREEN) else if (["sync"] or sync) and direct ("#{check} Syncing dataset completed successfully", Thor::Shell::Color::GREEN) else ("#{check} Changes were updated successfully", Thor::Shell::Color::GREEN) end end else @files.rollback_commit(commit_sha1) ("Error: Couldn't commit. \nRolling Back all changes.", Thor::Shell::Color::RED) end else ("Error: Uploaded only #{update_count}/#{update_total} files, \nRolling back", Thor::Shell::Color::RED) @files.rollback_commit(commit_sha1) end rescue => e ("Error occurd, \nAborting", Thor::Shell::Color::RED) log_error(e) @files.rollback_commit(commit_sha1) exit(1) rescue SignalException say "\nAborting", Thor::Shell::Color::BLUE say "\nRolling back all changes", Thor::Shell::Color::BLUE @files.rollback_commit(commit_sha1) exit(1) end end |
#upload_data_files(new_commit, files_list: []) ⇒ Object
2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 |
# File 'lib/cnvrg/cli.rb', line 2263 def upload_data_files(new_commit, files_list: []) begin verify_logged_in(true) log_start(__method__, args, ) dataset_dir = is_cnvrg_dir(Dir.pwd) @dataset = Dataset.new(dataset_dir) @files = Cnvrg::Datafiles.new(@dataset.owner, @dataset.slug, dataset: @dataset) new_commit ||= @dataset.get_next_commit partial_commit = @dataset.get_partial_commit if new_commit.blank? ("You must specify commit, run start_commit to create new commit", Thor::Shell::Color::RED) return false end chunk_size = [:chunk_size] chunk_size = [chunk_size, 1].max new_branch = ["new_branch"] || false new_tree = {} force = ["force"] || false parallel_threads = ["parallel"] || ParallelThreads all_files = files_list all_files = @dataset.list_all_files if files_list.blank? files_uploaded = 0 upload_errors = [] all_files.each_slice(chunk_size).each do |list_files| Cnvrg::Logger.log_info("Uploading files into #{@dataset.slug}, #{files_uploaded} files uploaded") temp_tree = @dataset.generate_chunked_idx(list_files, threads: parallel_threads) upload_resp, upload_error_files = @files.upload_multiple_files(new_commit, temp_tree, threads: parallel_threads, force: force, new_branch: new_branch, partial_commit: partial_commit, total: all_files.length) files_uploaded += upload_resp upload_errors += upload_error_files if upload_error_files.present? temp_tree.each do |k, v| new_tree[k] = (v.present?) ? {sha1: v.try(:fetch, :sha1, nil), commit_time: nil} : nil end end @dataset.write_tree(new_tree) #we dont want to re-run it every time so just on finish. rescue => e Cnvrg::Logger.log_error(e) raise e end return files_uploaded, upload_errors.try(:flatten).try(:compact) end |
#upload_data_new(new_branch, verbose, sync, force, tags, chunk_size, message: nil, total_deleted: 0, total_downloaded: 0) ⇒ Object
2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 |
# File 'lib/cnvrg/cli.rb', line 2090 def upload_data_new(new_branch, verbose, sync, force, , chunk_size, message:nil, total_deleted: 0, total_downloaded: 0) ("This method is deprecated, please use 'data put' instead. for more info visit our docs: https://app.cnvrg.io/docs/cli/install.html#upload-files-to-a-dataset", Thor::Shell::Color::BLUE, !["verbose"]) return begin commit, files_list = invoke :start_commit_data,[], :new_branch=> new_branch, :direct=>false, :force =>force, :chunk_size => chunk_size, :message => files_to_upload, upload_errors = invoke :upload_data_files,[commit, files_list: files_list],:new_branch=>new_branch, :verbose =>verbose, :force =>force, :sync =>sync, :chunk_size => chunk_size upload_size = files_to_upload + upload_errors.try(:size) rescue 0 invoke :end_commit_data,[commit, success: true, uploaded_files: files_to_upload, sync: sync], :new_branch=>new_branch, :force =>force if ('Uploading Tags', Thor::Shell::Color::BLUE) dataset_dir = is_cnvrg_dir(Dir.pwd) @dataset = Dataset.new(dataset_dir) begin tag_file = File.open([:tags], "r+") status = @dataset.(tag_file) rescue ('Tags file not found', Thor::Shell::Color::RED) return end if status ('Tags are successfully uploaded', Thor::Shell::Color::GREEN) else ('There was some error in uploading Tags', Thor::Shell::Color::RED) end end if total_deleted > 0 ("#{total_deleted} files deleted successfully.", Thor::Shell::Color::GREEN) end if total_downloaded > 0 ("#{total_downloaded} files downloaded successfully.", Thor::Shell::Color::GREEN) end if upload_size > 0 ("#{files_to_upload}/#{upload_size} files uploaded successfully.", Thor::Shell::Color::GREEN) end if upload_errors.try(:size) > 0 ("#{upload_errors.try(:size)}/#{upload_size} files didn't upload:", Thor::Shell::Color::RED) upload_errors.each do |file_hash| ("#{file_hash[:absolute_path]}", Thor::Shell::Color::RED) end end rescue => e Cnvrg::CLI.(e., 'red') Cnvrg::Logger.log_error(e) say "\nAborting", Thor::Shell::Color::BLUE dataset_dir = is_cnvrg_dir(Dir.pwd) return false if dataset_dir.blank? @dataset = Dataset.new(dataset_dir) return false rescue SignalException => e Cnvrg::Logger.log_error(e) say "\nAborting", Thor::Shell::Color::BLUE dataset_dir = is_cnvrg_dir(Dir.pwd) return false if dataset_dir.blank? @dataset = Dataset.new(dataset_dir) return false end end |
#upload_data_tar(ignore, verbose, sync, no_compression) ⇒ Object
1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 |
# File 'lib/cnvrg/cli.rb', line 1548 def upload_data_tar(ignore, verbose, sync, no_compression) begin verify_logged_in(true) log_start(__method__, args, ) dataset_dir = is_cnvrg_dir(Dir.pwd) @dataset = Dataset.new(dataset_dir) @files = Cnvrg::Datafiles.new(@dataset.owner, @dataset.slug) if !@dataset.update_ignore_list(ignore) ("Couldn't append new ignore files to .cnvrgignore", Thor::Shell::Color::RED) exit(1) end ("Checking dataset", Thor::Shell::Color::BLUE) ignore_list = @dataset.get_ignore_list() local_idx = @dataset.generate_idx(ignore_list) result = @dataset.compare_idx(false, commit = @dataset.last_local_commit, local_idx = local_idx) commit = result["result"]["commit"] if commit != @dataset.last_local_commit and !@dataset.last_local_commit.nil? and !result["result"]["tree"]["updated_on_server"].empty? ("Remote server has an updated version, please run `cnvrg data download` first", Thor::Shell::Color::BLUE) exit(1) end ("Comparing local changes with remote version:", Thor::Shell::Color::BLUE, verbose) result = result["result"]["tree"] check = Helpers.checkmark() if result["added"].empty? and result["updated_on_local"].empty? and result["deleted"].empty? ("#{check} Dataset is up to date", Thor::Shell::Color::GREEN, (sync ? false : true)) return true end update_count = 0 update_total = result["added"].size + result["updated_on_local"].size + result["deleted"].size successful_updates = [] successful_deletions = [] # Start commit res = @files.start_commit(false)["result"] commit_sha1 = res["commit_sha1"] commit_time = res["commit_time"] # upload / update begin (result["added"] + result["updated_on_local"]).each do |f| relative_path = f.gsub(/^#{@dataset.local_path + "/"}/, "") successful_updates << relative_path update_count += 1 end # delete deleted = update_deleted(result["deleted"]) deleted.each do |f| relative_path = f.gsub(/^#{@dataset.local_path + "/"}/, "") successful_updates << relative_path end @dataset.update_idx_with_files_commits!((successful_deletions+successful_updates), commit_time) ("Compressing data", Thor::Shell::Color::BLUE) home_dir = File.('~') compression_path = get_compression_path tar_path = "#{compression_path}#{@dataset.slug}_#{commit_sha1}.tar.gz" tar_files_path = "#{home_dir}/.cnvrg/tmp/#{@dataset.slug}_#{commit_sha1}.txt" files_to_upload = result["added"] + result["updated_on_local"] if File.exist? (@dataset.local_path + "/.cnvrgignore") files_to_upload << ".cnvrgignore" end tar_files = (files_to_upload).join("\n") File.open(tar_files_path, 'w') {|f| f.write tar_files} ignore_files_path = nil if !ignore_list.nil? ignore_files_path = "#{home_dir}/.cnvrg/tmp/#{@dataset.slug}_#{commit_sha1}_ignore.txt" File.open(ignore_files_path, 'w') {|f| f.write ignore_list.join("\n")} end is_tar = create_tar(dataset_dir, tar_path, tar_files_path, no_compression, ignore_files_path) if !is_tar ("ERROR: Couldn't compress data", Thor::Shell::Color::RED) FileUtils.rm_rf([tar_path]) if File.exist? tar_path FileUtils.rm_rf([tar_files_path]) if File.exist? tar_files_path FileUtils.rm_rf([ignore_files_path]) if !ignore_files_path.nil? and File.exist? ignore_files_path @files.rollback_commit(commit_sha1) ("Rolling Back all changes.", Thor::Shell::Color::RED) exit(1) end ("Uploading data", Thor::Shell::Color::BLUE) log_file = "#{home_dir}/.cnvrg/tmp/upload_#{File.basename(tar_path)}.log" res = false res = @files.upload_tar_file(tar_path, tar_path, commit_sha1) if res ("Commiting data", Thor::Shell::Color::BLUE) cur_idx = @dataset.get_idx.to_h res = @files.end_commit_tar(commit_sha1, cur_idx) if !Cnvrg::CLI.is_response_success(res, false) FileUtils.rm_rf([tar_files_path]) if File.exist? tar_files_path FileUtils.rm_rf([tar_path]) if File.exist? tar_path @files.rollback_commit(commit_sha1) ("Can't commit, Rolling Back all changes.", Thor::Shell::Color::RED) exit(1) end else if File.exist? log_file @files.upload_data_log_file(log_file, log_file, commit_sha1) end FileUtils.rm_rf([tar_files_path]) if File.exist? tar_files_path FileUtils.rm_rf([tar_path]) if File.exist? tar_path @files.rollback_commit(commit_sha1) ("Can't upload, Rolling Back all changes.", Thor::Shell::Color::RED) ("Upload error log: #{log_file}", Thor::Shell::Color::RED) exit(1) end # delete FileUtils.rm_rf([tar_path, tar_files_path]) rescue SignalException FileUtils.rm_rf([tar_files_path]) if File.exist? tar_files_path FileUtils.rm_rf([tar_path]) if File.exist? tar_path if File.exist? log_file @files.upload_data_log_file(log_file, log_file, commit_sha1) end @files.rollback_commit(commit_sha1) say "User aborted, Rolling Back all changes.", Thor::Shell::Color::RED exit(0) rescue => e log_error(e) # if !Cnvrg::Helpers.internet_connection? # say "Seems there is no internet connection", Thor::Shell::Color::RED # # end if File.exist? log_file @files.upload_data_log_file(log_file, log_file, commit_sha1) end FileUtils.rm_rf([tar_files_path]) if File.exist? tar_files_path FileUtils.rm_rf([tar_path]) if File.exist? tar_path @files.rollback_commit(commit_sha1) ("Exception while trying to upload, \nRolling back,\n look at the log for more details", Thor::Shell::Color::RED) ("Error log: #{log_file}", Thor::Shell::Color::RED) exit(0) end ("#{check} Changes were updated successfully", Thor::Shell::Color::GREEN) rescue => e ("Error occurred, \nAborting", Thor::Shell::Color::RED) log_error(e) @files.rollback_commit(commit_sha1) exit(1) rescue SignalException say "\nAborting", Thor::Shell::Color::BLUE say "\nRolling back all changes", Thor::Shell::Color::BLUE @files.rollback_commit(commit_sha1) exit(1) end end |
#upload_log ⇒ Object
4623 4624 4625 4626 4627 4628 |
# File 'lib/cnvrg/cli.rb', line 4623 def upload_log() log_path = '/home/ds/app/uwsgi.log' loglines = File.new(log_path).readlines logs = loglines.select {|x| x.start_with? "cnvrg_app:"}.collect {|x| x.strip} end |
#verify_datasets(dataset_titles, timeout = nil) ⇒ Object
840 841 842 843 844 845 846 847 848 849 850 851 852 853 |
# File 'lib/cnvrg/cli.rb', line 840 def verify_datasets(dataset_titles, timeout=nil) begin verify_logged_in(false) log_start(__method__, args, ) ("Verifying datasets #{dataset_titles}", Thor::Shell::Color::BLUE) verified = Dataset.verify_datasets(dataset_titles, timeout) ("All datasets are verified", Thor::Shell::Color::BLUE) if verified ("Failed to verify datasets", Thor::Shell::Color::RED) if !verified exit(1) if !verified rescue SignalException say "\nAborting", Thor::Shell::Color::RED exit(1) end end |