Class: Etna::Clients::Magma::AttributeActionsFromJsonWorkflow

Inherits:
Struct
  • Object
show all
Defined in:
lib/etna/clients/magma/workflows/attribute_actions_from_json_workflow.rb

Overview

Note! These workflows are not perfectly atomic, nor perfectly synchronized due to nature of the backend. These primitives are best effort locally synchronized, but cannot defend the backend or simultaneous system updates.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**params) ⇒ AttributeActionsFromJsonWorkflow

Returns a new instance of AttributeActionsFromJsonWorkflow.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/etna/clients/magma/workflows/attribute_actions_from_json_workflow.rb', line 22

def initialize(**params)
  super({}.update(params))

  actions_json = JSON.parse(File.read(filepath))

  converter = Etna::Clients::Magma::AttributeActionsConverter.new(actions_json)
  @actions = converter.convert

  validator = Etna::Clients::Magma::AttributeActionsValidator.new(
    actions,
    project_models)
  validator.validate

  raise "Attributes JSON has errors:\n  * #{format_errors(validator.errors)}" unless validator.valid?
end

Instance Attribute Details

#actionsObject (readonly)

Returns the value of attribute actions.



21
22
23
# File 'lib/etna/clients/magma/workflows/attribute_actions_from_json_workflow.rb', line 21

def actions
  @actions
end

#filepathObject

Returns the value of attribute filepath

Returns:

  • (Object)

    the current value of filepath



20
21
22
# File 'lib/etna/clients/magma/workflows/attribute_actions_from_json_workflow.rb', line 20

def filepath
  @filepath
end

#magma_clientObject

Returns the value of attribute magma_client

Returns:

  • (Object)

    the current value of magma_client



20
21
22
# File 'lib/etna/clients/magma/workflows/attribute_actions_from_json_workflow.rb', line 20

def magma_client
  @magma_client
end

#project_nameObject

Returns the value of attribute project_name

Returns:

  • (Object)

    the current value of project_name



20
21
22
# File 'lib/etna/clients/magma/workflows/attribute_actions_from_json_workflow.rb', line 20

def project_name
  @project_name
end

Instance Method Details

#execute_actionsObject



48
49
50
51
52
# File 'lib/etna/clients/magma/workflows/attribute_actions_from_json_workflow.rb', line 48

def execute_actions
  magma_client.update_model(Etna::Clients::Magma::UpdateModelRequest.new(
    project_name: project_name,
    actions: actions))
end

#format_errors(errors) ⇒ Object



38
39
40
# File 'lib/etna/clients/magma/workflows/attribute_actions_from_json_workflow.rb', line 38

def format_errors(errors)
  errors.map { |e| e.gsub("\n", "\n\t") }.join("\n  * ")
end

#project_modelsObject



42
43
44
45
46
# File 'lib/etna/clients/magma/workflows/attribute_actions_from_json_workflow.rb', line 42

def project_models
  @project_models ||= magma_client.retrieve(Etna::Clients::Magma::RetrievalRequest.new(
    project_name: project_name,
    model_name: 'all')).models
end

#run!Object



54
55
56
57
58
# File 'lib/etna/clients/magma/workflows/attribute_actions_from_json_workflow.rb', line 54

def run!
  puts "Executing the attribute actions against Magma."
  execute_actions
  puts "All complete!"
end