Class: Aliyun::Odps::Instance

Inherits:
Struct::Base show all
Extended by:
Modelable
Defined in:
lib/aliyun/odps/model/instance.rb

Constant Summary collapse

NAME_PATTERN =
/^([a-z]|[A-Z]){1,}([a-z]|[A-Z]|[\d]|_)*/

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Modelable

has_many

Methods inherited from Struct::Base

#client, #initialize, property, #update_attrs

Constructor Details

This class inherits a constructor from Aliyun::Odps::Struct::Base

Instance Attribute Details

#commentString

Returns:

  • (String)


12
# File 'lib/aliyun/odps/model/instance.rb', line 12

property :comment, String

#end_timeDateTime

Returns:

  • (DateTime)


17
# File 'lib/aliyun/odps/model/instance.rb', line 17

property :end_time, DateTime

#locationString

Returns:

  • (String)


18
# File 'lib/aliyun/odps/model/instance.rb', line 18

property :location, String

#nameString

Returns:

  • (String)


10
# File 'lib/aliyun/odps/model/instance.rb', line 10

property :name, String, required: true

#ownerString

Returns:

  • (String)


11
# File 'lib/aliyun/odps/model/instance.rb', line 11

property :owner, String

#priorityInteger

Returns:

  • (Integer)


13
# File 'lib/aliyun/odps/model/instance.rb', line 13

property :priority, Integer

#projectProject

Returns:



8
# File 'lib/aliyun/odps/model/instance.rb', line 8

property :project, Project, required: true

#start_timeDateTime

Returns:

  • (DateTime)


16
# File 'lib/aliyun/odps/model/instance.rb', line 16

property :start_time, DateTime

#statusString

Returns:

  • (String)


15
# File 'lib/aliyun/odps/model/instance.rb', line 15

property :status, String

#tasksArray

Returns:

  • (Array)


14
# File 'lib/aliyun/odps/model/instance.rb', line 14

property :tasks, Array

Instance Method Details

#get_statusString

Get status

Returns:

  • (String)

    Instance status: Suspended, Running, Terminated

See Also:



105
106
107
108
109
# File 'lib/aliyun/odps/model/instance.rb', line 105

def get_status
  path = "/projects/#{project.name}/instances/#{name}"
  result = client.get(path).parsed_response
  Utils.dig_value(result, 'Instance', 'Status')
end

#list_tasksList

Get tasks of instance

Returns:

See Also:



75
76
77
78
79
80
81
82
83
84
# File 'lib/aliyun/odps/model/instance.rb', line 75

def list_tasks
  path = "/projects/#{project.name}/instances/#{name}"
  query = { taskstatus: true }
  result = client.get(path, query: query).parsed_response

  keys = %w(Instance Tasks Task)
  Utils.wrap(Utils.dig_value(result, *keys)).map do |hash|
    InstanceTask.new(hash)
  end
end

#task_detail(task_name) ⇒ Hash

Get task detail of instance

Returns:

  • (Hash)

See Also:



27
28
29
30
31
# File 'lib/aliyun/odps/model/instance.rb', line 27

def task_detail(task_name)
  path = "/projects/#{project.name}/instances/#{name}"
  query = { instancedetail: true, taskname: task_name }
  client.get(path, query: query).parsed_response
end

#task_progress(task_name) ⇒ Hash

Get task progress of instance

Returns:

  • (Hash)

See Also:



40
41
42
43
44
# File 'lib/aliyun/odps/model/instance.rb', line 40

def task_progress(task_name)
  path = "/projects/#{project.name}/instances/#{name}"
  query = { instanceprogress: true, taskname: task_name }
  client.get(path, query: query).parsed_response['Progress']
end

#task_resultsHash<name, TaskResult>

Get task results

Returns:



62
63
64
65
66
67
68
# File 'lib/aliyun/odps/model/instance.rb', line 62

def task_results
  path = "/projects/#{project.name}/instances/#{name}"
  query = { result: true }
  result = client.get(path, query: query).parsed_response
  task_results = Utils.dig_value(result, 'Instance', 'Tasks', 'Task')
  Hash[Utils.wrap(task_results).map { |v| [v['Name'], Aliyun::Odps::TaskResult.new(v)] }]
end

#task_summary(task_name) ⇒ Hash

Get task summary of instance

Returns:

  • (Hash)

See Also:



53
54
55
56
57
# File 'lib/aliyun/odps/model/instance.rb', line 53

def task_summary(task_name)
  path = "/projects/#{project.name}/instances/#{name}"
  query = { instancesummary: true, taskname: task_name }
  client.get(path, query: query).parsed_response
end

#terminateObject

Terminate the instance

Returns:

  • true

See Also:



91
92
93
94
95
96
97
98
# File 'lib/aliyun/odps/model/instance.rb', line 91

def terminate
  path = "/projects/#{project.name}/instances/#{name}"

  body = Utils.to_xml(
    'Instance' => { 'Status' => 'Terminated' }
  )
  !!client.put(path, body: body)
end

#wait_for_success(interval = 0.01) ⇒ Object

Block process until instance success

Raises:



114
115
116
117
118
119
120
121
122
# File 'lib/aliyun/odps/model/instance.rb', line 114

def wait_for_success(interval = 0.01)
  wait_for_terminated(interval)

  list_tasks.each do |task|
    if task.status.upcase != 'SUCCESS'
      fail InstanceTaskNotSuccessError.new(task.name, task.status, task_results[task.name].result)
    end
  end
end

#wait_for_terminated(interval = 0.01) ⇒ Object

Block process until instance terminated



125
126
127
# File 'lib/aliyun/odps/model/instance.rb', line 125

def wait_for_terminated(interval = 0.01)
  sleep interval while get_status != 'Terminated'
end