Class: Aspera::Plugins::Orchestrator::WorkflowChecker

Inherits:
Object
  • Object
show all
Defined in:
lib/aspera/plugins/orchestrator/workflow_checker.rb

Overview

Check of an Orchestrator workflow file (.yml) or package (.wkf), before import.

Orchestrator 4.1.6 does not validate the graph on import (import_workflow, import_with_constraints): an invalid workflow is imported, then fails to publish, or at run time. These checks follow the rules of the designer (Whiteboard#parse_workflow). With the specifications of plugins (plugins.yml of the plugin documentation), action templates and inputs of steps are also checked: attributes and their values, required inputs, inputs and outputs that the plugin does not have with its template. Not checked: availability of plugins on the server.

The interface is that of a REST operation, so that it can be replaced by a call to Orchestrator when one exists:

  • request: the fields of import_workflow: file_name (import_file_name) and content (import_file, bytes), and the specifications of plugins (specs), that Orchestrator would not need
  • response: a Hash (JSON compatible) valid: true if there is no issue with severity error file_name: name of the checked file issues: list of Hash severity: error (the workflow will not import, publish or run correctly) or warning code: stable identifier of the rule, for programs, e.g. graph.step_orphan file: file of the package where the issue is (absent for a single .yml file) path: where in the file, e.g. graph/Step[Say hello] message: description for humans

The file is parsed without instantiating Ruby objects.

Constant Summary collapse

ERROR =
'error'
WARNING =
'warning'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_name, specs = nil) ⇒ WorkflowChecker

Returns a new instance of WorkflowChecker.

Parameters:

  • file_name (String) —

    Name of the file

  • specs (Hash, nil) (defaults to: nil) —

    Specifications of plugins: class name => attributes, inputs, outputs



102
103
104
105
106
107
108
109
110
# File 'lib/aspera/plugins/orchestrator/workflow_checker.rb', line 102

def initialize(file_name, specs = nil)
  @file_name = file_name
  @specs = specs
  @issues = []
  # file of the package being checked
  @member = nil
  # attributes of the action templates of the workflow being checked, by key <StepType>__<N>
  @template_attributes = {}
end

Instance Attribute Details

#issues ⇒ Object (readonly)

Returns the value of attribute issues.



98
99
100
# File 'lib/aspera/plugins/orchestrator/workflow_checker.rb', line 98

def issues
  @issues
end

Class Method Details

.check(file_name:, content:, specs: nil) ⇒ Hash

Returns Response, see class description.

Parameters:

  • file_name (String) —

    Name of the file, ending with yml or wkf

  • content (String) —

    Bytes of the file

  • specs (Hash, nil) (defaults to: nil) —

    Specifications of plugins (plugins.yml), to check templates and inputs of steps, or nil

Returns:

  • (Hash) —

    Response, see class description



87
88
89
90
91
92
93
94
95
# File 'lib/aspera/plugins/orchestrator/workflow_checker.rb', line 87

def check(file_name:, content:, specs: nil)
  checker = new(file_name, specs)
  checker.run(content)
  {
    'valid'     => checker.issues.none? { |issue| issue['severity'].eql?(ERROR) },
    'file_name' => file_name,
    'issues'    => checker.issues
  }
end

Instance Method Details

#run(content) ⇒ Object

Parameters:

  • content (String) —

    Bytes of the file



113
114
115
116
117
118
119
# File 'lib/aspera/plugins/orchestrator/workflow_checker.rb', line 113

def run(content)
  case File.extname(@file_name)
  when '.yml' then check_yaml(content)
  when '.wkf' then check_package(content)
  else add(ERROR, 'file.extension', 'file', "extension must be yml or wkf: #{@file_name}")
  end
end