Class: Dag::Job

Inherits:
Model show all
Defined in:
lib/dag/client/model/job.rb

Instance Attribute Summary collapse

Attributes inherited from Model

#api

Instance Method Summary collapse

Constructor Details

#initialize(api, job_info) ⇒ Job

Returns a new instance of Job.



3
4
5
6
# File 'lib/dag/client/model/job.rb', line 3

def initialize(api, job_info)
  super(api)
  update_parameters(job_info)
end

Instance Attribute Details

#access_key_idObject (readonly)

Returns the value of attribute access_key_id.



8
9
10
# File 'lib/dag/client/model/job.rb', line 8

def access_key_id
  @access_key_id
end

#clusterObject (readonly)

Returns the value of attribute cluster.



8
9
10
# File 'lib/dag/client/model/job.rb', line 8

def cluster
  @cluster
end

#cluster_rebootedObject (readonly)

Returns the value of attribute cluster_rebooted.



8
9
10
# File 'lib/dag/client/model/job.rb', line 8

def cluster_rebooted
  @cluster_rebooted
end

#dslObject (readonly)

Returns the value of attribute dsl.



8
9
10
# File 'lib/dag/client/model/job.rb', line 8

def dsl
  @dsl
end

#idObject (readonly)

Returns the value of attribute id.



8
9
10
# File 'lib/dag/client/model/job.rb', line 8

def id
  @id
end

#input_formatObject (readonly)

Returns the value of attribute input_format.



8
9
10
# File 'lib/dag/client/model/job.rb', line 8

def input_format
  @input_format
end

#input_object_keysObject (readonly)

Returns the value of attribute input_object_keys.



8
9
10
# File 'lib/dag/client/model/job.rb', line 8

def input_object_keys
  @input_object_keys
end

#job_idObject (readonly)

Returns the value of attribute job_id.



8
9
10
# File 'lib/dag/client/model/job.rb', line 8

def job_id
  @job_id
end

#labelObject (readonly)

Returns the value of attribute label.



8
9
10
# File 'lib/dag/client/model/job.rb', line 8

def label
  @label
end

#output_databaseObject (readonly)

Returns the value of attribute output_database.



8
9
10
# File 'lib/dag/client/model/job.rb', line 8

def output_database
  @output_database
end

#output_formatObject (readonly)

Returns the value of attribute output_format.



8
9
10
# File 'lib/dag/client/model/job.rb', line 8

def output_format
  @output_format
end

#output_resource_pathObject (readonly)

Returns the value of attribute output_resource_path.



8
9
10
# File 'lib/dag/client/model/job.rb', line 8

def output_resource_path
  @output_resource_path
end

#output_tableObject (readonly)

Returns the value of attribute output_table.



8
9
10
# File 'lib/dag/client/model/job.rb', line 8

def output_table
  @output_table
end

#process_engineObject (readonly)

Returns the value of attribute process_engine.



8
9
10
# File 'lib/dag/client/model/job.rb', line 8

def process_engine
  @process_engine
end

#progressObject (readonly)

Returns the value of attribute progress.



8
9
10
# File 'lib/dag/client/model/job.rb', line 8

def progress
  @progress
end

#queryObject (readonly)

Returns the value of attribute query.



8
9
10
# File 'lib/dag/client/model/job.rb', line 8

def query
  @query
end

#schemaObject (readonly)

Returns the value of attribute schema.



8
9
10
# File 'lib/dag/client/model/job.rb', line 8

def schema
  @schema
end

#stageObject (readonly)

Returns the value of attribute stage.



8
9
10
# File 'lib/dag/client/model/job.rb', line 8

def stage
  @stage
end

#start_atObject (readonly)

Returns the value of attribute start_at.



8
9
10
# File 'lib/dag/client/model/job.rb', line 8

def start_at
  @start_at
end

#statusObject (readonly)

Returns the value of attribute status.



8
9
10
# File 'lib/dag/client/model/job.rb', line 8

def status
  @status
end

#typeObject (readonly)

Returns the value of attribute type.



8
9
10
# File 'lib/dag/client/model/job.rb', line 8

def type
  @type
end

Instance Method Details

#cluster_rebooted?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/dag/client/model/job.rb', line 28

def cluster_rebooted?
  !!@cluster_rebooted
end

#download_urls(time_limit = 30) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/dag/client/model/job.rb', line 44

def download_urls(time_limit = 30)
  raise Dag::Client::StatusInvalid.new("job status is not finished") unless finished?
  expire_at = time_limit.minutes.since.to_i
  object_uri = URI.parse(@output_resource_path)
  bucket = object_uri.host
  object_path = object_uri.path[1..-1]
  object_path += '/' unless object_path.end_with? '/'
  bucket_objects = @api.objects(bucket, prefix: object_path).objects
  bucket_objects.map do |object|
    path = if @api.force_path_style?
             "/#{bucket}/#{object}"
           else
             "/#{object}"
           end

    parameters = {
      "Expires" => expire_at,
      "IIJGIOAccessKeyId" => @api.apikey,
      "Signature" => @api.download_signature(expire_at, bucket, path)
    }

    uri = URI.parse(@api.storage_api)
    url = if @api.force_path_style?
            "http://#{uri.host}"
          else
            "http://#{bucket}.#{uri.host}"
          end
    url += ":#{uri.port}" unless uri.port == 80 || uri.port == 443

    File.join(url, "#{path}?#{parameters.to_param}")
  end
end

#finished?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/dag/client/model/job.rb', line 12

def finished?
  @status == 'finished'
end

#hive?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/dag/client/model/job.rb', line 24

def hive?
  @type == 'select'
end

#killObject Also known as: cancel



37
38
39
40
# File 'lib/dag/client/model/job.rb', line 37

def kill
  validate_cancel_condition
  @api.query_cancel(@id)
end

#logObject



77
78
79
80
81
# File 'lib/dag/client/model/job.rb', line 77

def log
  validate_log_condition
  log_info = @api.query_log(@id)
  log_info ? log_info['log'] : ''
end

#reloadObject



32
33
34
35
# File 'lib/dag/client/model/job.rb', line 32

def reload
  job_info = @api.query_info(@id)
  update_parameters(job_info)
end

#running?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/dag/client/model/job.rb', line 16

def running?
  @status == 'running'
end

#split?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/dag/client/model/job.rb', line 20

def split?
  @type == 'split'
end

#validate_cancel_conditionObject



93
94
95
96
97
# File 'lib/dag/client/model/job.rb', line 93

def validate_cancel_condition
  unless running?
    raise Dag::Client::StatusInvalid.new("job status is not running")
  end
end

#validate_log_conditionObject



83
84
85
86
87
88
89
90
91
# File 'lib/dag/client/model/job.rb', line 83

def validate_log_condition
  if split?
    raise Dag::Client::JobTypeInvalid.new("job type is not select")
  end

  if cluster_rebooted?
    raise Dag::Client::ClusterRebooted.new("cluster is rebooted")
  end
end