Module: BpmManager::RedHat
- Defined in:
- lib/bpm_manager/red_hat.rb
Class Method Summary collapse
-
.assign_task(task_id, user_id) ⇒ Object
Assigns a Task for an User.
-
.calculate_sla(start_time, end_time = Time.now, sla_hours = 0.0, offset = 20) ⇒ Object
Private class methods.
-
.calculate_sla_percent(start_time, end_time = Time.now, sla_hours = 0.0, offset = 20) ⇒ Object
private_class_method :calculate_sla.
-
.clear_all_history ⇒ Object
Clears all the History –WARNING: Destructive action!–.
-
.complete_task(task_id, opts = {}) ⇒ Object
Completes a Task.
-
.complete_task_as_admin(task_id, opts = {}) ⇒ Object
Completes a Task as Administrator.
-
.create_process(deployment_id, process_definition_id, opts = {}) ⇒ Object
Creates a new Process.
-
.deployments ⇒ Object
Gets all server deployments.
-
.exit_task(task_id) ⇒ Object
Exits a Task.
-
.fail_task(task_id) ⇒ Object
Fails a Task.
-
.get_history(process_definition_id = "") ⇒ Object
Gets the Process History.
-
.get_process_sla(process_instance_id, process_sla_hours = 0, warning_offset_percent = 20) ⇒ Object
Gets the SLA for a Process Instance.
-
.get_task_sla(task_instance_id, process_sla_hours = 0, task_sla_hours = 0, warning_offset_percent = 20) ⇒ Object
Gets the SLA for a Task Instance.
-
.process_image(deployment_id, process_definition_id, process_id = '') ⇒ Object
Gets the Process image as SVG.
-
.process_instance(process_instance_id) ⇒ Object
Gets a Process Instance.
-
.process_instance_nodes(process_instance_id) ⇒ Object
Gets a Process Instance Nodes.
-
.process_instance_variables(process_instance_id) ⇒ Object
Gets a Process Instance Variables.
-
.process_instances ⇒ Object
Gets all Process Instances.
-
.processes ⇒ Object
Gets all available processes.
-
.processes_query_with_opts(opts = {}) ⇒ Object
Gets all the runtime processes with query options.
-
.release_task(task_id) ⇒ Object
Releases a Task.
-
.resume_task(task_id) ⇒ Object
Resumes a Task.
-
.skip_task(task_id) ⇒ Object
Skips a Task.
-
.start_task(task_id) ⇒ Object
Starts a Task.
-
.stop_task(task_id) ⇒ Object
Stops a Task.
-
.suspend_task(task_id) ⇒ Object
Suspends a Task.
-
.task_query(task_id) ⇒ Object
Gets all the information for a Task ID.
-
.tasks(user_id = '') ⇒ Object
Gets all tasks, optionally you could specify an user id.
-
.tasks_query_with_opts(opts = {}) ⇒ Object
Gets all the runtime Tasks with query options.
-
.tasks_with_opts(opts = {}) ⇒ Object
Gets all tasks with options.
Class Method Details
.assign_task(task_id, user_id) ⇒ Object
Assigns a Task for an User
82 83 84 |
# File 'lib/bpm_manager/red_hat.rb', line 82 def self.assign_task(task_id, user_id) BpmManager.server['/task/' + task_id.to_s + '/delegate'].post(:targetEntityId => user_id.to_s) end |
.calculate_sla(start_time, end_time = Time.now, sla_hours = 0.0, offset = 20) ⇒ Object
Private class methods
206 207 208 209 210 211 212 213 214 |
# File 'lib/bpm_manager/red_hat.rb', line 206 def self.calculate_sla(start_time, end_time = Time.now, sla_hours = 0.0, offset = 20) end_time = Time.now if end_time.nil? hours = sla_hours.to_f * 3600 # Converts to seconds and calculates warning offset warn = start_time.utc + hours * ((100.0 - offset) / 100) total = start_time.utc + hours # Returns the status end_time.utc <= warn ? 0 : ( warn < end_time.utc && end_time.utc <= total ? 1 : 2 ) end |
.calculate_sla_percent(start_time, end_time = Time.now, sla_hours = 0.0, offset = 20) ⇒ Object
private_class_method :calculate_sla
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 |
# File 'lib/bpm_manager/red_hat.rb', line 217 def self.calculate_sla_percent(start_time, end_time = Time.now, sla_hours = 0.0, offset = 20) end_time = Time.now if end_time.nil? sla_hours = sla_hours * 3600.0 # converts to seconds offset_pcg = (100.0 - offset) / 100.0 percent = OpenStruct.new unless sla_hours < 1 # it's zero or negative if end_time.utc > (start_time.utc + sla_hours) # Ruby Red total = (end_time.utc - start_time.utc).to_f percent.green = (sla_hours * offset_pcg / total * 100).round(2) percent.yellow = ((sla_hours / total * 100) - percent.green).round(2) percent.red = (100 - percent.yellow - percent.green).round(2) else # Still Green total = sla_hours percent.green = end_time.utc <= start_time.utc + total * offset_pcg ? ((100-offset) - (((start_time.utc + total * offset_pcg) - end_time.utc) * 100).to_f / (total * offset_pcg).to_f).round(2) : 100 - offset percent.yellow = end_time.utc <= start_time.utc + total * offset_pcg ? 0.0 : (offset - (start_time.utc + total - end_time.utc).to_f * 100 / (total * offset_pcg).to_f).round(2) percent.red = 0.0 end # Safe to 0.0 percent.green = percent.green < 0.0 ? 0.0 : percent.green percent.yellow = percent.yellow < 0.0 ? 0.0 : percent.yellow percent.red = percent.red < 0.0 ? 0.0 : percent.red else percent.green = 100.0 percent.yellow = 0.0 percent.red = 0.0 end return percent end |
.clear_all_history ⇒ Object
Clears all the History –WARNING: Destructive action!–
162 163 164 |
# File 'lib/bpm_manager/red_hat.rb', line 162 def self.clear_all_history() BpmManager.server['/history/clear'].post({}) end |
.complete_task(task_id, opts = {}) ⇒ Object
Completes a Task
131 132 133 |
# File 'lib/bpm_manager/red_hat.rb', line 131 def self.complete_task(task_id, opts = {}) BpmManager.server['/task/' + task_id.to_s + '/complete'].post(opts) end |
.complete_task_as_admin(task_id, opts = {}) ⇒ Object
Completes a Task as Administrator
136 137 138 139 140 |
# File 'lib/bpm_manager/red_hat.rb', line 136 def self.complete_task_as_admin(task_id, opts = {}) self.release_task(task_id) self.start_task(task_id) BpmManager.server['/task/' + task_id.to_s + '/complete'].post(opts) end |
.create_process(deployment_id, process_definition_id, opts = {}) ⇒ Object
Creates a new Process
18 19 20 |
# File 'lib/bpm_manager/red_hat.rb', line 18 def self.create_process(deployment_id, process_definition_id, opts = {}) BpmManager.server['/runtime/' + deployment_id.to_s + '/process/' + process_definition_id.to_s + '/start'].post(opts) end |
.deployments ⇒ Object
Gets all server deployments
8 9 10 |
# File 'lib/bpm_manager/red_hat.rb', line 8 def self.deployments() JSON.parse(BpmManager.server['/deployment'].get) end |
.exit_task(task_id) ⇒ Object
Exits a Task
148 149 150 |
# File 'lib/bpm_manager/red_hat.rb', line 148 def self.exit_task(task_id) BpmManager.server['/task/' + task_id.to_s + '/exit'].post({}) end |
.fail_task(task_id) ⇒ Object
Fails a Task
143 144 145 |
# File 'lib/bpm_manager/red_hat.rb', line 143 def self.fail_task(task_id) BpmManager.server['/task/' + task_id.to_s + '/fail'].post({}) end |
.get_history(process_definition_id = "") ⇒ Object
Gets the Process History
153 154 155 156 157 158 159 |
# File 'lib/bpm_manager/red_hat.rb', line 153 def self.get_history(process_definition_id = "") if process_definition_id.empty? JSON.parse(BpmManager.server['/history/instances'].get) else JSON.parse(BpmManager.server['/history/process/' + process_definition_id.to_s].get) end end |
.get_process_sla(process_instance_id, process_sla_hours = 0, warning_offset_percent = 20) ⇒ Object
Gets the SLA for a Process Instance
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 |
# File 'lib/bpm_manager/red_hat.rb', line 167 def self.get_process_sla(process_instance_id, process_sla_hours = 0, warning_offset_percent = 20) my_process = self.process_instance(process_instance_id) unless my_process.nil? sla = OpenStruct.new(:process => OpenStruct.new) start_time = Time.at(my_process['start']/1000) end_time = my_process['start'].nil? ? Time.now : Time.at(my_process['start']/1000) # Calculates the process sla sla.process.status = calculate_sla(start_time, end_time, process_sla_hours, warning_offset_percent) sla.process.status_name = (calculate_sla(start_time, end_time, process_sla_hours, warning_offset_percent) == 0) ? 'ok' : (calculate_sla(start_time, end_time, process_sla_hours, warning_offset_percent) == 1 ? 'warning' : 'due') sla.process.percentages = calculate_sla_percent(start_time, end_time, process_sla_hours, warning_offset_percent) end return sla end |
.get_task_sla(task_instance_id, process_sla_hours = 0, task_sla_hours = 0, warning_offset_percent = 20) ⇒ Object
Gets the SLA for a Task Instance
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 |
# File 'lib/bpm_manager/red_hat.rb', line 185 def self.get_task_sla(task_instance_id, process_sla_hours = 0, task_sla_hours = 0, warning_offset_percent = 20) my_task = self.tasks_with_opts('taskId' => task_instance_id).first unless my_task.nil? sla = OpenStruct.new(:task => OpenStruct.new, :process => OpenStruct.new) # Calculates the process sla sla.process.status = calculate_sla(my_task.process.start_on, my_task.process.end_on, process_sla_hours, warning_offset_percent) sla.process.status_name = (calculate_sla(my_task.process.start_on, my_task.process.end_on, process_sla_hours, warning_offset_percent) == 0) ? 'ok' : (calculate_sla(my_task.process.start_on, my_task.process.end_on, process_sla_hours, warning_offset_percent) == 1 ? 'warning' : 'due') sla.process.percentages = calculate_sla_percent(my_task.process.start_on, my_task.process.end_on, process_sla_hours, warning_offset_percent) # Calculates the task sla sla.task.status = calculate_sla(my_task.created_on, nil, task_sla_hours, warning_offset_percent) sla.task.status_name = (calculate_sla(my_task.created_on, nil, task_sla_hours, warning_offset_percent) == 0) ? 'ok' : (calculate_sla(my_task.created_on, nil, task_sla_hours, warning_offset_percent) == 1 ? 'warning' : 'due') sla.task.percentages = calculate_sla_percent(my_task.created_on, nil, task_sla_hours, warning_offset_percent) end return sla end |
.process_image(deployment_id, process_definition_id, process_id = '') ⇒ Object
Gets the Process image as SVG
63 64 65 66 67 68 69 |
# File 'lib/bpm_manager/red_hat.rb', line 63 def self.process_image(deployment_id, process_definition_id, process_id = '') begin BpmManager.server['/runtime/' + deployment_id.to_s + '/process/' + process_definition_id.to_s + '/image' + ((process_id.to_s.nil? || process_id.to_s.empty?) ? '' : '/' + process_id.to_s)].get rescue return '' # returns an empty string in case of error end end |
.process_instance(process_instance_id) ⇒ Object
Gets a Process Instance
33 34 35 36 37 38 39 |
# File 'lib/bpm_manager/red_hat.rb', line 33 def self.process_instance(process_instance_id) begin JSON.parse(BpmManager.server['/history/instance/' + process_instance_id.to_s].get) rescue Exception {} # returns nil string in case of error end end |
.process_instance_nodes(process_instance_id) ⇒ Object
Gets a Process Instance Nodes
42 43 44 45 46 47 48 |
# File 'lib/bpm_manager/red_hat.rb', line 42 def self.process_instance_nodes(process_instance_id) begin JSON.parse(BpmManager.server['/history/instance/' + process_instance_id.to_s + '/node'].get)['historyLogList'] rescue {} # returns nil string in case of error end end |
.process_instance_variables(process_instance_id) ⇒ Object
Gets a Process Instance Variables
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/bpm_manager/red_hat.rb', line 51 def self.process_instance_variables(process_instance_id) begin result = Hash.new JSON.parse(BpmManager.server['/history/instance/' + process_instance_id.to_s + '/variable'].get)['historyLogList'].each{|e| result[e.first.second['variable-id']] = e.first.second['value']} return result rescue return {} # same result as not found record in jbpm end end |
.process_instances ⇒ Object
Gets all Process Instances
23 24 25 |
# File 'lib/bpm_manager/red_hat.rb', line 23 def self.process_instances JSON.parse(BpmManager.server['/history/instances'].get) end |
.processes ⇒ Object
Gets all available processes
13 14 15 |
# File 'lib/bpm_manager/red_hat.rb', line 13 def self.processes() JSON.parse(BpmManager.server['/deployment/processes'].get)['processDefinitionList'] end |
.processes_query_with_opts(opts = {}) ⇒ Object
Gets all the runtime processes with query options
28 29 30 |
# File 'lib/bpm_manager/red_hat.rb', line 28 def self.processes_query_with_opts(opts = {}) JSON.parse(BpmManager.server['/query/runtime/process/' + (opts.empty? ? '' : '?' + opts.map{|k,v| (v.class == Array) ? v.map{|e| k.to_s + '=' + e.to_s}.join('&') : k.to_s + '=' + v.to_s}.join('&'))].get)['processInstanceInfoList'] end |
.release_task(task_id) ⇒ Object
Releases a Task
106 107 108 |
# File 'lib/bpm_manager/red_hat.rb', line 106 def self.release_task(task_id) BpmManager.server['/task/' + task_id.to_s + '/release'].post({}) end |
.resume_task(task_id) ⇒ Object
Resumes a Task
121 122 123 |
# File 'lib/bpm_manager/red_hat.rb', line 121 def self.resume_task(task_id) BpmManager.server['/task/' + task_id.to_s + '/resumes'].post({}) end |
.skip_task(task_id) ⇒ Object
Skips a Task
126 127 128 |
# File 'lib/bpm_manager/red_hat.rb', line 126 def self.skip_task(task_id) BpmManager.server['/task/' + task_id.to_s + '/skip'].post({}) end |
.start_task(task_id) ⇒ Object
Starts a Task
101 102 103 |
# File 'lib/bpm_manager/red_hat.rb', line 101 def self.start_task(task_id) BpmManager.server['/task/' + task_id.to_s + '/start'].post({}) end |
.stop_task(task_id) ⇒ Object
Stops a Task
111 112 113 |
# File 'lib/bpm_manager/red_hat.rb', line 111 def self.stop_task(task_id) BpmManager.server['/task/' + task_id.to_s + '/stop'].post({}) end |
.suspend_task(task_id) ⇒ Object
Suspends a Task
116 117 118 |
# File 'lib/bpm_manager/red_hat.rb', line 116 def self.suspend_task(task_id) BpmManager.server['/task/' + task_id.to_s + '/suspend'].post({}) end |
.task_query(task_id) ⇒ Object
Gets all the information for a Task ID
87 88 89 90 91 92 93 |
# File 'lib/bpm_manager/red_hat.rb', line 87 def self.task_query(task_id) begin JSON.parse(BpmManager.server['/task/' + task_id.to_s].get) rescue {} # returns nil string in case of error end end |
.tasks(user_id = '') ⇒ Object
Gets all tasks, optionally you could specify an user id
72 73 74 |
# File 'lib/bpm_manager/red_hat.rb', line 72 def self.tasks(user_id = '') self.structure_task_data(JSON.parse(BpmManager.server['/task/query?taskOwner=' + user_id].get)) end |
.tasks_query_with_opts(opts = {}) ⇒ Object
Gets all the runtime Tasks with query options
96 97 98 |
# File 'lib/bpm_manager/red_hat.rb', line 96 def self.tasks_query_with_opts(opts = {}) structure_task_query_data(JSON.parse(BpmManager.server['/query/runtime/task/' + (opts.empty? ? '' : '?' + opts.map{|k,v| (v.class == Array) ? v.map{|e| k.to_s + '=' + e.to_s}.join('&') : k.to_s + '=' + v.to_s}.join('&'))].get)) end |
.tasks_with_opts(opts = {}) ⇒ Object
Gets all tasks with options
77 78 79 |
# File 'lib/bpm_manager/red_hat.rb', line 77 def self.tasks_with_opts(opts = {}) self.structure_task_data(JSON.parse(BpmManager.server['/task/query' + (opts.empty? ? '' : '?' + opts.map{|k,v| (v.class == Array) ? v.map{|e| k.to_s + '=' + e.to_s}.join('&') : k.to_s + '=' + v.to_s}.join('&'))].get)) end |