Class: Eso::Conductor
Constant Summary
Constants inherited from Service
Instance Attribute Summary
Attributes inherited from Service
Instance Method Summary collapse
-
#create_workflow(name:, steps:) ⇒ Eso::Workflow
Create a new workflow on this conductor.
-
#delete_all_workflows ⇒ Object
Delete all current workflows on the conductor.
-
#delete_workflow(workflow_id:) ⇒ Object
Delete an existing workflow from the conductor.
-
#get_translation_key(step_type, label) ⇒ String
Returns the metadata key for a specified translated string.
-
#get_translation_label(step_type, key) ⇒ String
Returns the translated value of the specified key for a step type (defined in Eso::StepNames).
-
#initialize(host:, port: 3780, nsc:) ⇒ Eso::Conductor
constructor
Constructor for Conductor.
-
#start_all_workflows ⇒ Hash
Start all workflows that exist on the conductor.
-
#start_workflow(workflow_id:) ⇒ Object
Start the specified workflow.
-
#stop_all_workflows ⇒ Hash
Stop all workflows that exist on the conductor.
-
#stop_workflow(workflow_id:) ⇒ Object
Stop the specified workflow.
-
#update_workflow(updated_workflow:) ⇒ Object
Update an existing workflow on the conductor to have the configuration of the workflow object passed into this method.
-
#workflow_histories(starttime, endtime) ⇒ Array[Eso::Workflow::History]
Return the workflow histories with only the state histories for the given date range.
-
#workflow_state(workflow_id:) ⇒ String
Get the state of the specified workflow.
-
#workflow_states ⇒ Hash
Retrieve the states for all of the workflows created on the conductor.
-
#workflows ⇒ Array
Return all of the workflows that currently exist on this conductor.
-
#workflows_state_count(state) ⇒ Integer
Get the count of items in a state of the specified workflow.
Methods inherited from Service
#add_nexpose_session, #delete, #get, #http, #https, #post, #put, #request
Constructor Details
#initialize(host:, port: 3780, nsc:) ⇒ Eso::Conductor
Constructor for Conductor.
13 14 15 16 |
# File 'lib/eso/conductor.rb', line 13 def initialize(host:, port: 3780, nsc:) super(host: host, port: port, nsc: nsc) @url = "https://#{@host}:#{@port}/eso/conductor-service/api/" end |
Instance Method Details
#create_workflow(name:, steps:) ⇒ Eso::Workflow
Create a new workflow on this conductor.
128 129 130 131 132 133 134 135 |
# File 'lib/eso/conductor.rb', line 128 def create_workflow(name:, steps:) workflow = Workflow.new(name: name, steps: steps) resp = post(url: "#{@url}workflows/", payload: workflow.to_json) created_workflow = Workflow.load(self, resp[:id]) created_workflow end |
#delete_all_workflows ⇒ Object
Delete all current workflows on the conductor.
156 157 158 159 |
# File 'lib/eso/conductor.rb', line 156 def delete_all_workflows wfs = workflows wfs.each { |wf| delete_workflow(workflow_id: wf.id) } end |
#delete_workflow(workflow_id:) ⇒ Object
Delete an existing workflow from the conductor.
150 151 152 |
# File 'lib/eso/conductor.rb', line 150 def delete_workflow(workflow_id:) delete(url: "#{@url}workflows/#{workflow_id}") end |
#get_translation_key(step_type, label) ⇒ String
Returns the metadata key for a specified translated string. The translated value needs to be in language that the user has configured.
220 221 222 223 224 225 |
# File 'lib/eso/conductor.rb', line 220 def get_translation_key(step_type, label) json_data = get(url: "#{@url}services/nexpose/metadata/#{step_type}") target_hash = json_data[:labels].values.find { |label_hash| label_hash.values.include?(label) } target_hash.key(label).to_s if target_hash end |
#get_translation_label(step_type, key) ⇒ String
Returns the translated value of the specified key for a step type (defined in Eso::StepNames). The translated value will be based on the language settings the user has configured.
206 207 208 209 210 211 |
# File 'lib/eso/conductor.rb', line 206 def get_translation_label(step_type, key) json_data = get(url: "#{@url}services/nexpose/metadata/#{step_type}") target_hash = json_data[:labels].values.find { |label_hash| label_hash.has_key?(key) } target_hash[key] if target_hash end |
#start_all_workflows ⇒ Hash
Start all workflows that exist on the conductor.
181 182 183 184 185 186 |
# File 'lib/eso/conductor.rb', line 181 def start_all_workflows wf_states = workflow_states wf_states.each { |wf_id, state| start_workflow(workflow_id: wf_id) if state[:workflow_state] == "STOPPED" } workflow_states end |
#start_workflow(workflow_id:) ⇒ Object
Start the specified workflow.
165 166 167 |
# File 'lib/eso/conductor.rb', line 165 def start_workflow(workflow_id:) post(url: "#{@url}workflows/#{workflow_id}/state") end |
#stop_all_workflows ⇒ Hash
Stop all workflows that exist on the conductor.
192 193 194 195 196 197 |
# File 'lib/eso/conductor.rb', line 192 def stop_all_workflows wf_states = workflow_states wf_states.each { |wf_id, state| stop_workflow(workflow_id: wf_id) if state[:workflow_state] == "RUNNING" } workflow_states end |
#stop_workflow(workflow_id:) ⇒ Object
Stop the specified workflow.
173 174 175 |
# File 'lib/eso/conductor.rb', line 173 def stop_workflow(workflow_id:) delete(url: "#{@url}workflows/#{workflow_id}/state") end |
#update_workflow(updated_workflow:) ⇒ Object
Update an existing workflow on the conductor to have the configuration of the workflow object passed into this method.
141 142 143 144 |
# File 'lib/eso/conductor.rb', line 141 def update_workflow(updated_workflow:) payload = updated_workflow.to_json put(url: "#{@url}workflows/#{updated_workflow.id}", payload: payload) end |
#workflow_histories(starttime, endtime) ⇒ Array[Eso::Workflow::History]
Return the workflow histories with only the state histories for the given date range.
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 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/eso/conductor.rb', line 49 def workflow_histories(starttime, endtime) histories = [] json_data = get(url: "#{@url}workflows/history/#{starttime}/#{endtime}") json_data.each do |wf| # Initialize WorkflowHistory elements workflow_steps = [] state_histories = [] # Create a new WorkflowHistory with the details we already know workflow_history = Eso::Workflow::History.new(id: wf[:id], name: wf[:name], timeCreated: wf[:timeCreated], state: wf[:state], message: wf[:message], steps: workflow_steps, history: state_histories ) # Parse the steps out of the response to be returned with the WorkflowHistory wf[:steps].each do |step| workflow_steps << Step.new(uuid: step[:uuid], service_name: step[:serviceName], workflow: workflow_history, type_name: step[:stepConfiguration][:typeName], previous_type_name: step[:stepConfiguration][:previousTypeName], configuration_params: step[:stepConfiguration][:configurationParams]) end workflow_history.steps = workflow_steps # Parse the histories out of the response, to be returned with the WorkflowHistory. For some reason. # this failed with named parameters. For now I returned it to positional. wf[:history].each do |history| state_histories << Eso::Workflow::StateHistory.new(history[:message], history[:state], history[:startTime]) end workflow_history.state_histories = state_histories # Add the Workflow History we just built to the list to be returned. histories << workflow_history end histories end |
#workflow_state(workflow_id:) ⇒ String
Get the state of the specified workflow.
98 99 100 |
# File 'lib/eso/conductor.rb', line 98 def workflow_state(workflow_id:) get(url: "#{@url}workflows/#{workflow_id}/state") end |
#workflow_states ⇒ Hash
Retrieve the states for all of the workflows created on the conductor.
115 116 117 118 119 120 |
# File 'lib/eso/conductor.rb', line 115 def workflow_states wfs = workflows states = {} wfs.each { |wf| states[wf.id] = workflow_state(workflow_id: wf.id) } states end |
#workflows ⇒ Array
Return all of the workflows that currently exist on this conductor.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/eso/conductor.rb', line 22 def workflows rv = [] json_data = get(url: "#{@url}workflows/") json_data.each do |wf| workflow = Workflow.new(id: wf[:id], name: wf[:name]) steps = wf[:steps] steps.each do |step| workflow_step = Step.new(uuid: step[:uuid], service_name: step[:serviceName], workflow: workflow, type_name: step[:stepConfiguration][:typeName], previous_type_name: step[:stepConfiguration][:previousTypeName], configuration_params: step[:stepConfiguration][:configurationParams]) workflow.steps << workflow_step end rv << workflow end rv end |
#workflows_state_count(state) ⇒ Integer
Get the count of items in a state of the specified workflow.
107 108 109 |
# File 'lib/eso/conductor.rb', line 107 def workflows_state_count(state) get(url: "#{@url}workflows/count/#{state}") end |