Class: Hpe3parSdk::TaskManager

Inherits:
Object
  • Object
show all
Defined in:
lib/Hpe3parSdk/task_manager.rb

Overview

Task Manager Rest API methods

Instance Method Summary collapse

Constructor Details

#initialize(http) ⇒ TaskManager

Returns a new instance of TaskManager.



18
19
20
# File 'lib/Hpe3parSdk/task_manager.rb', line 18

def initialize(http)
  @http = http
end

Instance Method Details

#_wait_for_task_to_end_loop(task_id, poll_rate_secs) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/Hpe3parSdk/task_manager.rb', line 58

def _wait_for_task_to_end_loop(task_id, poll_rate_secs)
  task = get_task(task_id)

  while task != nil do #loop begin
    state = task.status
    if state == Hpe3parSdk::TaskStatus::DONE
      break
    end

    if state == Hpe3parSdk::TaskStatus::CANCELLED
      Hpe3parSdk.logger.info("Task #{task.task_id} was CANCELLED!!!")
      break
    end

    if state == Hpe3parSdk::TaskStatus::FAILED
      msg = "Task '#{task.task_id}' has FAILED!!!"
      Hpe3parSdk.logger.info(msg)
      raise Hpe3parSdk::HPE3PARException.new(message: msg)
    end

    if state == Hpe3parSdk::TaskStatus::ACTIVE
      sleep(poll_rate_secs)
      task = get_task(task.task_id);
      Hpe3parSdk.logger
          .info("Polling task #{task.task_id} current status: #{Hpe3parSdk::TaskStatus.get_string(task.status)}")
    end

  end #loop end

  #Return the Task Result
  if task != nil && task.status != nil && task.status == 'DONE'
    return true

  else
    return false
  end

end

#cancel_task(task_id) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/Hpe3parSdk/task_manager.rb', line 42

def cancel_task(task_id)
  if task_id.is_a? Integer
    _body = Hash.new
    _body['action'] = Hpe3parSdk::TaskAction::CANCEL_TASK
    @http.put("/tasks/#{task_id}", body: _body)
  else
    raise HPE3PARException.new(
        nil, "Task id #{task_id} is not of type integer"
    )
  end
end

#get_all_tasksObject



22
23
24
25
26
27
28
29
# File 'lib/Hpe3parSdk/task_manager.rb', line 22

def get_all_tasks
  tasks = Array[]
  response = @http.get('/tasks')
  response[1]['members'].each do |member|
    tasks.push(Task.new(member))
  end
  tasks
end

#get_task(task_id) ⇒ Object



31
32
33
34
35
36
37
38
39
40
# File 'lib/Hpe3parSdk/task_manager.rb', line 31

def get_task(task_id)
  if task_id.is_a? Integer
    response = @http.get("/tasks/#{task_id}")
    Task.new(response[1])
  else
    raise Hpe3parSdk::HTTPBadRequest.new(
        nil, "Task id '#{task_id}' is not of type integer"
    )
  end
end

#wait_for_task_to_end(task_id, poll_rate_secs) ⇒ Object



54
55
56
# File 'lib/Hpe3parSdk/task_manager.rb', line 54

def wait_for_task_to_end(task_id, poll_rate_secs)
  _wait_for_task_to_end_loop(task_id, poll_rate_secs)
end