Class: Etna::Clients::Polyphemus

Inherits:
BaseClient show all
Defined in:
lib/etna/clients/polyphemus/client.rb,
lib/etna/clients/polyphemus/models.rb,
lib/etna/clients/polyphemus/workflows/set_configuration_workflow.rb

Defined Under Namespace

Classes: ConfigurationRequest, ConfigurationResponse, EnvironmentConfiguration, JobType, RedcapJobRequest, SetConfigurationWorkflow

Instance Attribute Summary

Attributes inherited from BaseClient

#host, #ignore_ssl, #token

Instance Method Summary collapse

Methods inherited from BaseClient

#initialize, #safe_parse, #token_expired?, #token_will_expire?

Constructor Details

This class inherits a constructor from Etna::Clients::BaseClient

Instance Method Details

#configuration(configuration_request = ConfigurationRequest.new) ⇒ Object



10
11
12
13
14
15
16
17
18
19
# File 'lib/etna/clients/polyphemus/client.rb', line 10

def configuration(configuration_request = ConfigurationRequest.new)
  json = nil
  @etna_client.get(
    "/configuration",
    configuration_request) do |res|
    json = JSON.parse(res.body, symbolize_names: true)
  end

  ConfigurationResponse.new(json)
end

#get_config(project_name, config_id, version_number) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/etna/clients/polyphemus/client.rb', line 37

def get_config(project_name, config_id, version_number)
  json = nil
  @etna_client.post("/api/workflows/#{project_name}/configs/#{config_id}", version_number: version_number) do |res|
    json = JSON.parse(res.body)
  end
  json
end

#get_previous_state(project_name, config_id, state: [], collect: false) ⇒ Object



81
82
83
84
85
86
87
88
89
90
# File 'lib/etna/clients/polyphemus/client.rb', line 81

def get_previous_state(project_name, config_id, state: [], collect: false)
  json = nil
  @etna_client.post("/api/workflows/#{project_name}/run/previous/#{config_id}",
    state: state,
    collect: collect
  ) do |res|
    json = JSON.parse(res.body)
  end
  json
end

#get_run(project_name, run_id) ⇒ Object



73
74
75
76
77
78
79
# File 'lib/etna/clients/polyphemus/client.rb', line 73

def get_run(project_name, run_id)
  json = nil
  @etna_client.get("/api/workflows/#{project_name}/run/#{run_id}") do |res|
    json = JSON.parse(res.body)
  end
  json
end

#get_run_metadata(project_name, config_id) ⇒ Object



107
108
109
110
111
112
113
# File 'lib/etna/clients/polyphemus/client.rb', line 107

def (project_name, config_id)
  json = nil
  @etna_client.get("/api/workflows/#{project_name}/runtime_config/#{config_id}") do |res|
    json = JSON.parse(res.body)
  end
  json
end

#get_runtime_config(project_name, config_id) ⇒ Object



45
46
47
48
49
50
51
# File 'lib/etna/clients/polyphemus/client.rb', line 45

def get_runtime_config(project_name, config_id)
  json = nil
  @etna_client.get("/api/workflows/#{project_name}/runtime_configs/#{config_id}") do |res|
    json = JSON.parse(res.body)
  end
  json
end

#job(job_request = JobRequest.new) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/etna/clients/polyphemus/client.rb', line 21

def job(job_request = JobRequest.new)
  # Because this is a streaming response, just yield the response back.
  #   The consumer will have to iterate over the response.read_body, like
  #
  # polyphemus_client.job(request) do |response|
  #   response.read_body do |fragment|
  #     <fragment contains a chunk of text streamed back from the server>
  #   end
  # end
  @etna_client.post(
    "/#{job_request.project_name}/job",
    job_request) do |res|
      yield res
  end
end

#log(project_name:, user:, event:, message:, payload:, signatory:, consolidate:, application: nil) ⇒ Object



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/etna/clients/polyphemus/client.rb', line 115

def log(project_name:, user:, event:, message:, payload:, signatory:, consolidate:, application:nil)
  params = {
    project_name: project_name,
    user: user,
    event: event,
    message: message,
    payload: payload,
    consolidate: consolidate,
    application: application,
    signatory: signatory
  }
  json = nil
  @etna_client.log_write(params) do |res|
    json = JSON.parse(res.body)
  end
  json
end

#update_run(project_name, run_id, updates) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/etna/clients/polyphemus/client.rb', line 53

def update_run(project_name, run_id, updates)
  payload = {
    run_id: run_id,
    workflow_name: updates[:workflow_name],
    name: updates[:name],
    config_id: updates[:config_id], 
    version_number: updates[:version_number],
    state: updates[:state],
    orchestrator_metadata: updates[:orchestrator_metadata],
    output: updates[:output],
    append_output: updates[:append_output]
  }.compact

  json = nil
  @etna_client.post("/api/workflows/#{project_name}/run/update/#{run_id}", payload) do |res|
    json = JSON.parse(res.body)
  end
  json
end

#update_runtime_config(project_name, config_id, updates) ⇒ Object



92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/etna/clients/polyphemus/client.rb', line 92

def update_runtime_config(project_name, config_id, updates)
  payload = {
    config_id: updates[:config_id],
    runtime_config: updates[:runtime_config],
    run_interval: updates[:run_interval],
    disabled: updates[:disabled]
  }.compact          

  json = nil
  @etna_client.post("/api/workflows/#{project_name}/runtime_config/#{config_id}", payload) do |res|
    json = JSON.parse(res.body)
  end
  json
end