cnvrg 1.6.38 → 1.9.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -15,17 +15,6 @@ module Cnvrg
15
15
  end
16
16
  end
17
17
 
18
-
19
- desc 'start', description: '', hide: true
20
- def start(*logs)
21
- cli = Cnvrg::CLI.new
22
- cli.log_start(__method__, args, options)
23
- @project = Project.new(nil, owner: ENV['CNVRG_OWNER'], slug: ENV['CNVRG_PROJECT'])
24
- @executer = Helpers::Executer.new(project: @project, job_type: ENV['CNVRG_JOB_TYPE'], job_id: ENV['CNVRG_JOB_ID'])
25
- commands = @executer.fetch_commands
26
- @executer.execute_cmds(commands)
27
- end
28
-
29
18
  desc 'requirements', description: '', hide: true
30
19
  def requirements
31
20
  cli = Cnvrg::CLI.new
@@ -44,56 +33,42 @@ module Cnvrg
44
33
  @executer.execute_cmds(commands)
45
34
  end
46
35
 
47
- desc 'poll_commands', description: 'Poll waiting commands', hide: true
48
- def poll_commands
36
+
37
+ desc 'start', description: "Job Start!", hide: true
38
+ def start
49
39
  cli = Cnvrg::CLI.new
50
40
  cli.log_start(__method__, args, options)
51
- @project = Project.new(nil, owner: ENV['CNVRG_OWNER'], slug: ENV['CNVRG_PROJECT'])
52
- @executer = Helpers::Executer.new(project: @project, job_type: ENV['CNVRG_JOB_TYPE'], job_id: ENV['CNVRG_JOB_ID'])
53
- while true
54
- begin
55
- commands = @executer.get_commands
56
- @executer.execute_cmds(commands)
57
- rescue => e
58
- Cnvrg::Logger.log_error(e)
59
- end
60
- sleep 10
61
- end
41
+ cli.auth
42
+ poll_every = (ENV["CNVRG_AGENT_POLL_EVERY"] || '30').to_i
43
+ owner = ENV["CNVRG_OWNER"]
44
+ machine_activity_slug = ENV["CNVRG_MACHINE_ACTIVITY"]
45
+ job_id = ENV["CNVRG_JOB_ID"]
46
+ @executer = Cnvrg::Helpers::Executer.new(machine_activity: machine_activity_slug, poll_every: poll_every, owner: owner, job_id: job_id)
47
+ @executer.main_thread
62
48
  end
63
49
 
64
- desc 'run_command', description: 'Poll waiting commands', hide: true
65
- method_option :command_slug, :type => :string, :aliases => ["-s", "--slug"], :default => nil
66
- def run_command
67
- Cnvrg::Logger.info("in run command")
50
+ desc 'stats', description: 'stats of agent and slave', hide: true
51
+ def stats
68
52
  cli = Cnvrg::CLI.new
69
53
  cli.log_start(__method__, args, options)
70
- command_slug = options['command_slug']
71
- #TODO handle if missing
72
- @project = Project.new(nil, owner: ENV['CNVRG_OWNER'], slug: ENV['CNVRG_PROJECT'])
73
- @executer = Helpers::Executer.new(project: @project, job_type: ENV['CNVRG_JOB_TYPE'], job_id: ENV['CNVRG_JOB_ID'])
74
- command = @executer.get_command(command_slug)
75
- @executer.monitor_command(command, command_slug)
54
+ poll_every = (ENV["CNVRG_AGENT_POLL_EVERY"] || '30').to_i
55
+ owner = ENV["CNVRG_OWNER"]
56
+ machine_activity_slug = ENV["CNVRG_MACHINE_ACTIVITY"]
57
+ job_id = ENV["CNVRG_JOB_ID"]
58
+ @executer = Cnvrg::Helpers::Executer.new(machine_activity: machine_activity_slug, poll_every: poll_every, owner: owner, job_id: job_id)
59
+ @executer.executer_stats
76
60
  end
77
61
 
78
- desc 'set_pod_restart', description: 'Set pod restart', hide: true
79
- def set_pod_restart
80
- Cnvrg::CLI.new.log_start(__method__, args, options)
81
- @project = Project.new(owner: ENV['CNVRG_OWNER'], slug: ENV['CNVRG_PROJECT'])
82
- @project.set_job_pod_restart
83
- end
84
-
85
- desc 'pre_pod_restart', description: 'Pre pod restart actions', hide: true
86
- def pre_pod_restart
87
- Cnvrg::CLI.new.log_start(__method__, args, options)
88
- @project = Project.new(owner: ENV['CNVRG_OWNER'], slug: ENV['CNVRG_PROJECT'])
89
- @project.pre_job_pod_restart
90
- end
91
-
92
- desc 'started', description: 'set job status to started after job restart', hide: true
93
- def started
94
- Cnvrg::CLI.new.log_start(__method__, args, options)
95
- @project = Project.new(owner: ENV['CNVRG_OWNER'], slug: ENV['CNVRG_PROJECT'])
96
- @project.set_job_started
62
+ desc 'pre_pod_stop', description: 'test', hide: true
63
+ def pre_pod_stop
64
+ cli = Cnvrg::CLI.new
65
+ cli.log_start(__method__, args, options)
66
+ owner = ENV["CNVRG_OWNER"]
67
+ machine_activity = YAML.load_file("/conf/.machine_activity.yml") rescue {:slug => ENV["CNVRG_MACHINE_ACTIVITY"]}
68
+ machine_activity_slug = machine_activity[:slug]
69
+ job_id = ENV["CNVRG_JOB_ID"]
70
+ @executer = Cnvrg::Helpers::Executer.new(machine_activity: machine_activity_slug, owner: owner, job_id: job_id)
71
+ @executer.pre_pod_stop
97
72
  end
98
73
  end
99
74
  end
@@ -0,0 +1,47 @@
1
+ module Cnvrg
2
+ class JobSsh < SubCommandBase
3
+ desc 'ssh start', description: 'job_id', hide: false
4
+ method_option :port, :type => :numeric, :aliases => ["-p", "--port"], :desc => "Port to bind into", :default => 2222
5
+ method_option :username, :type => :string, :aliases => ["-u", "--username"], :desc => "Job container user name", :default => nil
6
+ method_option :password, :type => :string, :aliases => ["--password"], :desc =>"Job Conatainer user name, will be set by cnvrg", :default => nil
7
+ method_option :kubeconfig, :type => :string, :aliases => ["--kubeconfig"], :desc => "Path to kubeconfig, if blank default config will be used", :default => nil
8
+ def start(job_id)
9
+ Cnvrg::CLI.new.log_start(__method__, args, options)
10
+ @job_ssh = ConnectJobSsh.new(job_id)
11
+ @job_ssh.start(options['username'], options['password'])
12
+ pod_name = nil
13
+ namespace = "cnvrg"
14
+ ssh_ready = false
15
+ while not ssh_ready
16
+ resp = @job_ssh.status()
17
+ status = resp["ssh_status"]
18
+
19
+ if status == "in_progress"
20
+ puts("Waiting for ssh to start ...")
21
+ sleep(3)
22
+ next
23
+ elsif status == "finished"
24
+ password = resp["password"]
25
+ username = resp["username"]
26
+ pod_name = resp["pod_name"]
27
+ namespace = resp["namespace"]
28
+ ssh_ready = true
29
+ else
30
+ puts("Failed to start ssh")
31
+ break
32
+ end
33
+ end
34
+ if pod_name.blank? or password.blank? or username.blank?
35
+ puts("Failed to get required params")
36
+ return
37
+ end
38
+
39
+ puts("In order to connect to your job, define your ssh connection with the following params:")
40
+ puts("host: 127.0.0.1")
41
+ puts("port: #{options["port"]}")
42
+ puts("username: #{username}")
43
+ puts("password: #{password}")
44
+ @job_ssh.run_portforward_command(pod_name, options["port"], options["kubeconfig"], namespace)
45
+ end
46
+ end
47
+ end
@@ -75,6 +75,7 @@ module Cnvrg
75
75
 
76
76
  def log_error(e)
77
77
  Cnvrg::Logger.log_handler if $log.blank?
78
+ return if $log.blank?
78
79
  bc = ActiveSupport::BacktraceCleaner.new
79
80
  bc.add_silencer{|line| line =~ /thor/}
80
81
  $log.error message: "An exception #{e.class} was logged during running", type: "error"
@@ -84,16 +85,19 @@ module Cnvrg
84
85
 
85
86
  def log_error_message(msg)
86
87
  Cnvrg::Logger.log_handler if $log.blank?
88
+ return if $log.blank?
87
89
  $log.error message: msg, type: "error"
88
90
  end
89
91
 
90
92
  def log_info(msg)
91
93
  Cnvrg::Logger.log_handler if $log.blank?
94
+ return if $log.blank?
92
95
  $log.info message: msg, type: "info"
93
96
  end
94
97
 
95
98
  def log_json(json, msg: '')
96
99
  Cnvrg::Logger.log_handler if $log.blank?
100
+ return if $log.blank?
97
101
  $log.info message: msg, type: "info", data: json
98
102
  end
99
103
 
@@ -1,7 +1,6 @@
1
1
  require 'fileutils'
2
2
  require 'pathname'
3
3
 
4
-
5
4
  module Cnvrg
6
5
  class Project
7
6
  attr_reader :slug, :owner, :title, :local_path, :working_dir, :is_git, :is_branch, :machines
@@ -270,18 +269,19 @@ module Cnvrg
270
269
  end
271
270
 
272
271
  def self.clone_dir_remote(project_slug, project_owner, project_name, is_git = false)
273
- list_dirs = [
274
- ".cnvrg"
275
- ]
272
+ cli = Cnvrg::CLI.new()
273
+ begin
274
+ list_dirs = [
275
+ ".cnvrg"
276
+ ]
276
277
 
277
278
 
278
- list_files = [
279
- ".cnvrg/config.yml",
279
+ list_files = [
280
+ ".cnvrg/config.yml",
280
281
 
281
- ]
282
+ ]
282
283
 
283
284
 
284
- begin
285
285
  config = {project_name: project_name,
286
286
  project_slug: project_slug,
287
287
  owner: project_owner,
@@ -300,11 +300,12 @@ module Cnvrg
300
300
 
301
301
 
302
302
  end
303
-
304
- rescue
305
- return false
303
+ true
304
+ rescue => e
305
+ cli.log_message(e.message)
306
+ cli.log_error(e)
307
+ false
306
308
  end
307
- return true
308
309
  end
309
310
 
310
311
  def update_is_new_branch(new_branch)
@@ -396,6 +397,7 @@ module Cnvrg
396
397
  Cnvrg::Logger.log_info("Uploading: #{upload_list.join(", ")}")
397
398
  upload_list
398
399
  end
400
+
399
401
  def generate_output_dir_tmp(output_dir)
400
402
  upload_list = []
401
403
  list = Dir.glob("#{output_dir}/**/*", File::FNM_DOTMATCH)
@@ -449,11 +451,18 @@ module Cnvrg
449
451
 
450
452
  tree_idx[label + "/"] = nil
451
453
  else
452
- sha1 = OpenSSL::Digest::SHA1.file(e).hexdigest
454
+ file_in_idx = old_idx[:tree][label] rescue nil
455
+ last_modified = File.mtime(e).to_f
456
+ if file_in_idx.present? and last_modified == file_in_idx[:last_modified]
457
+ sha1 = file_in_idx[:sha1]
458
+ else
459
+ sha1 = OpenSSL::Digest::SHA1.file(e).hexdigest
460
+ end
461
+
453
462
  if old_idx.nil? or old_idx.to_h[:tree].nil?
454
- tree_idx[label] = {sha1: sha1, commit_time: nil}
455
- elsif old_idx[:tree][label].nil? or old_idx[:tree][label][:sha1] != sha1
456
- tree_idx[label] = {sha1: sha1, commit_time: nil}
463
+ tree_idx[label] = {sha1: sha1, commit_time: nil, last_modified: last_modified}
464
+ elsif file_in_idx.nil? or file_in_idx[:sha1] != sha1 or file_in_idx[:last_modified].blank? or file_in_idx[:last_modified] != last_modified
465
+ tree_idx[label] = {sha1: sha1, commit_time: nil, last_modified: last_modified}
457
466
  else
458
467
  tree_idx[label] = old_idx[:tree][label]
459
468
  end
@@ -634,6 +643,13 @@ module Cnvrg
634
643
  return response
635
644
  end
636
645
 
646
+ def fetch_webapp_slugs(webapp_slug, slugs: nil)
647
+ response = Cnvrg::API_V2.request("#{self.owner}/projects/#{self.slug}/webapps/#{webapp_slug}" , 'GET')
648
+ return response["experiments"]
649
+ rescue
650
+ slugs
651
+ end
652
+
637
653
  def update_idx_with_commit!(commit, latest: nil)
638
654
  idx_hash = self.get_idx
639
655
  idx_hash[:commit] = commit
@@ -789,5 +805,18 @@ module Cnvrg
789
805
  end
790
806
  Cnvrg::API.request("users/#{@owner}/projects/#{@slug}/jobs/#{job_type.underscore}/#{job_id}/set_started", "POST", {job_type: job_type, job_id: job_id})
791
807
  end
808
+
809
+ def self.stop_if_project_present(project_home, project_name)
810
+ cli = Cnvrg::CLI.new()
811
+ config = YAML.load_file(project_home + "/.cnvrg/config.yml")
812
+ local_commit = YAML.load_file(project_home + "/.cnvrg/idx.yml")[:commit] rescue nil
813
+ return if local_commit.blank?
814
+ if config[:project_name] == project_name
815
+ cli.log_message("Project already present, clone aborted")
816
+ exit(0)
817
+ end
818
+ rescue => e
819
+ nil
820
+ end
792
821
  end
793
822
  end
@@ -1,6 +1,5 @@
1
1
  require 'fileutils'
2
2
  require 'cnvrg/files'
3
- require 'docker'
4
3
  require 'net/ssh'
5
4
 
6
5
 
@@ -1,3 +1,3 @@
1
1
  module Cnvrg
2
- VERSION = '1.6.38'
2
+ VERSION = '1.9.5'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cnvrg
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.38
4
+ version: 1.9.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yochay Ettun
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2020-06-23 00:00:00.000000000 Z
13
+ date: 2020-07-09 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler
@@ -210,14 +210,14 @@ dependencies:
210
210
  requirements:
211
211
  - - "~>"
212
212
  - !ruby/object:Gem::Version
213
- version: 2.11.417
213
+ version: '3.0'
214
214
  type: :runtime
215
215
  prerelease: false
216
216
  version_requirements: !ruby/object:Gem::Requirement
217
217
  requirements:
218
218
  - - "~>"
219
219
  - !ruby/object:Gem::Version
220
- version: 2.11.417
220
+ version: '3.0'
221
221
  - !ruby/object:Gem::Dependency
222
222
  name: signet
223
223
  requirement: !ruby/object:Gem::Requirement
@@ -344,20 +344,6 @@ dependencies:
344
344
  - - "~>"
345
345
  - !ruby/object:Gem::Version
346
346
  version: 0.22.1
347
- - !ruby/object:Gem::Dependency
348
- name: docker-api
349
- requirement: !ruby/object:Gem::Requirement
350
- requirements:
351
- - - "~>"
352
- - !ruby/object:Gem::Version
353
- version: '1.33'
354
- type: :runtime
355
- prerelease: false
356
- version_requirements: !ruby/object:Gem::Requirement
357
- requirements:
358
- - - "~>"
359
- - !ruby/object:Gem::Version
360
- version: '1.33'
361
347
  - !ruby/object:Gem::Dependency
362
348
  name: activesupport
363
349
  requirement: !ruby/object:Gem::Requirement
@@ -386,20 +372,6 @@ dependencies:
386
372
  - - ">="
387
373
  - !ruby/object:Gem::Version
388
374
  version: '0'
389
- - !ruby/object:Gem::Dependency
390
- name: net-ssh
391
- requirement: !ruby/object:Gem::Requirement
392
- requirements:
393
- - - ">="
394
- - !ruby/object:Gem::Version
395
- version: '0'
396
- type: :runtime
397
- prerelease: false
398
- version_requirements: !ruby/object:Gem::Requirement
399
- requirements:
400
- - - ">="
401
- - !ruby/object:Gem::Version
402
- version: '0'
403
375
  - !ruby/object:Gem::Dependency
404
376
  name: down
405
377
  requirement: !ruby/object:Gem::Requirement
@@ -427,6 +399,7 @@ files:
427
399
  - lib/cnvrg.rb
428
400
  - lib/cnvrg/Images.rb
429
401
  - lib/cnvrg/api.rb
402
+ - lib/cnvrg/api_v2.rb
430
403
  - lib/cnvrg/auth.rb
431
404
  - lib/cnvrg/cli.rb
432
405
  - lib/cnvrg/cli/flow.rb
@@ -434,6 +407,7 @@ files:
434
407
  - lib/cnvrg/cli/subcommand.rb
435
408
  - lib/cnvrg/cli/task.rb
436
409
  - lib/cnvrg/colors.rb
410
+ - lib/cnvrg/connect_job_ssh.rb
437
411
  - lib/cnvrg/data.rb
438
412
  - lib/cnvrg/datafiles.rb
439
413
  - lib/cnvrg/dataset.rb
@@ -445,11 +419,13 @@ files:
445
419
  - lib/cnvrg/files.rb
446
420
  - lib/cnvrg/flow.rb
447
421
  - lib/cnvrg/helpers.rb
422
+ - lib/cnvrg/helpers/agent.rb
448
423
  - lib/cnvrg/helpers/executer.rb
449
424
  - lib/cnvrg/hyper.rb
450
425
  - lib/cnvrg/image.rb
451
426
  - lib/cnvrg/image_cli.rb
452
427
  - lib/cnvrg/job_cli.rb
428
+ - lib/cnvrg/job_ssh.rb
453
429
  - lib/cnvrg/logger.rb
454
430
  - lib/cnvrg/org_helpers.rb
455
431
  - lib/cnvrg/project.rb
@@ -477,7 +453,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
477
453
  - !ruby/object:Gem::Version
478
454
  version: '0'
479
455
  requirements: []
480
- rubygems_version: 3.0.4
456
+ rubygems_version: 3.1.2
481
457
  signing_key:
482
458
  specification_version: 4
483
459
  summary: A CLI tool for interacting with cnvrg.io.