mio-config 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. checksums.yaml +7 -0
  2. data/#mio-config.gemspec# +23 -0
  3. data/Gemfile +16 -0
  4. data/Gemfile.lock +68 -0
  5. data/LICENCE.md +8 -0
  6. data/README.md +162 -0
  7. data/Rakefile +7 -0
  8. data/circle.yml +3 -0
  9. data/config/mio.yml +4 -0
  10. data/coverage/assets/0.10.0/application.css +799 -0
  11. data/coverage/assets/0.10.0/application.js +1707 -0
  12. data/coverage/assets/0.10.0/colorbox/border.png +0 -0
  13. data/coverage/assets/0.10.0/colorbox/controls.png +0 -0
  14. data/coverage/assets/0.10.0/colorbox/loading.gif +0 -0
  15. data/coverage/assets/0.10.0/colorbox/loading_background.png +0 -0
  16. data/coverage/assets/0.10.0/favicon_green.png +0 -0
  17. data/coverage/assets/0.10.0/favicon_red.png +0 -0
  18. data/coverage/assets/0.10.0/favicon_yellow.png +0 -0
  19. data/coverage/assets/0.10.0/loading.gif +0 -0
  20. data/coverage/assets/0.10.0/magnify.png +0 -0
  21. data/coverage/assets/0.10.0/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  22. data/coverage/assets/0.10.0/smoothness/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
  23. data/coverage/assets/0.10.0/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
  24. data/coverage/assets/0.10.0/smoothness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  25. data/coverage/assets/0.10.0/smoothness/images/ui-bg_glass_75_dadada_1x400.png +0 -0
  26. data/coverage/assets/0.10.0/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
  27. data/coverage/assets/0.10.0/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
  28. data/coverage/assets/0.10.0/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
  29. data/coverage/assets/0.10.0/smoothness/images/ui-icons_222222_256x240.png +0 -0
  30. data/coverage/assets/0.10.0/smoothness/images/ui-icons_2e83ff_256x240.png +0 -0
  31. data/coverage/assets/0.10.0/smoothness/images/ui-icons_454545_256x240.png +0 -0
  32. data/coverage/assets/0.10.0/smoothness/images/ui-icons_888888_256x240.png +0 -0
  33. data/coverage/assets/0.10.0/smoothness/images/ui-icons_cd0a0a_256x240.png +0 -0
  34. data/coverage/index.html +4884 -0
  35. data/lib/mio.rb +24 -0
  36. data/lib/mio/#model.rb# +130 -0
  37. data/lib/mio/client.rb +106 -0
  38. data/lib/mio/config.rb +14 -0
  39. data/lib/mio/errors.rb +18 -0
  40. data/lib/mio/migrations.rb +96 -0
  41. data/lib/mio/model.rb +133 -0
  42. data/lib/mio/model/autoload.rb +7 -0
  43. data/lib/mio/model/groovy_script.rb +40 -0
  44. data/lib/mio/model/groovy_script_wait.rb +44 -0
  45. data/lib/mio/model/hotfolder.rb +56 -0
  46. data/lib/mio/model/import_action.rb +69 -0
  47. data/lib/mio/model/s3.rb +37 -0
  48. data/lib/mio/model/workflow.rb +98 -0
  49. data/lib/mio/model/workflow/node.rb +35 -0
  50. data/lib/mio/model/workflow/transition.rb +20 -0
  51. data/lib/mio/requests.rb +16 -0
  52. data/lib/mio/search.rb +29 -0
  53. data/lib/mio/tasks.rb +5 -0
  54. data/lib/mio/tasks/migrations.rb +17 -0
  55. data/lib/mio/tasks/skeletons.rb +38 -0
  56. data/migrations/20160429130853_create-an-s3-bucket-for-ingestion.rb +11 -0
  57. data/mio-config.gemspec +24 -0
  58. data/notes +1 -0
  59. data/spec/factories/client_factories.rb +41 -0
  60. data/spec/factories/mio_factories.rb +9 -0
  61. data/spec/factories/model_factories.rb +128 -0
  62. data/spec/fixtures/vcr_cassettes/client.yml +2415 -0
  63. data/spec/fixtures/vcr_cassettes/client.yml~ +2141 -0
  64. data/spec/lib/mio/client_spec.rb +79 -0
  65. data/spec/lib/mio/config_spec.rb +11 -0
  66. data/spec/lib/mio/model/groovy_script_spec.rb +13 -0
  67. data/spec/lib/mio/model/groovy_script_wait_spec.rb +13 -0
  68. data/spec/lib/mio/model/hotfolder_spec.rb +13 -0
  69. data/spec/lib/mio/model/import_action_spec.rb +13 -0
  70. data/spec/lib/mio/model/s3_spec.rb +13 -0
  71. data/spec/lib/mio/model/workflow/node_spec.rb +35 -0
  72. data/spec/lib/mio/model/workflow/transition_spec.rb +12 -0
  73. data/spec/lib/mio/model/workflow_spec.rb +38 -0
  74. data/spec/lib/mio/search_spec.rb +37 -0
  75. data/spec/lib/mio_spec.rb +30 -0
  76. data/spec/spec_helper.rb +16 -0
  77. data/spec/support/factory_girl.rb +3 -0
  78. data/spec/support/shared_examples_for_client.rb +27 -0
  79. data/spec/support/shared_examples_for_model.rb +87 -0
  80. data/spec/support/vcr.rb +12 -0
  81. metadata +195 -0
@@ -0,0 +1,7 @@
1
+ Dir[File.join(File.dirname(__FILE__), '*.rb')].each do |file|
2
+ require File.join('mio', 'model', File.basename(file, File.extname(file)))
3
+ end
4
+
5
+ Dir[File.join(File.dirname(__FILE__), 'workflow', '*.rb')].each do |file|
6
+ require File.join('mio', 'model', 'workflow', File.basename(file, File.extname(file)))
7
+ end
@@ -0,0 +1,40 @@
1
+ class Mio
2
+ class Model
3
+ class GroovyScript < Model
4
+ set_resource :actions
5
+
6
+ field :name, String, 'Script name'
7
+ field :displayName, String, 'Script Display name'
8
+ field :key, String, 'AWS API Key with access to S3'
9
+ field :secret, String, 'AWS secret'
10
+ field :visibility, Array, 'Ids of the accounts which may see the import action'
11
+ field :script, String, 'The groovy script (inline) ', '"File.read(/path/to/script.groovy)"'
12
+ field :jars, Array, 'JARs to load on remote, empty for none', []
13
+ field :imports, Array, 'Imports to reference within groovy script, empty for none', []
14
+
15
+ field :enable, Symbol, ':true or :false', :true
16
+ field :start, Symbol, ':true or :false', :true
17
+
18
+ def create_hash
19
+ plugin = 'tv.nativ.mio.plugins.actions.script.GroovyScriptCommand'
20
+ {name: @args.name,
21
+ pluginClass: plugin,
22
+ visibilityIds: @args.visibility,
23
+ type: 'script',
24
+ runRuleExpression: ''
25
+ }
26
+ end
27
+
28
+ def config_hash
29
+ {'script-contents': {
30
+ script: @args.script
31
+ },
32
+ imports: {
33
+ 'jar-url': @args.jars.map{|jar| {value: jar, isExpression: false}},
34
+ import: @args.imports.map{|import| {value: import, isExpression: false}}
35
+ }
36
+ }
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,44 @@
1
+ class Mio
2
+ class Model
3
+ class GroovyScriptWait < Model
4
+ set_resource :actions
5
+
6
+ field :name, String, 'Script name'
7
+ field :displayName, String, 'Script Display name'
8
+ field :key, String, 'AWS API Key with access to S3'
9
+ field :secret, String, 'AWS secret'
10
+ field :visibility, Array, 'Ids of the accounts which may see the import action'
11
+ field :script, String, 'The groovy script (inline) ', '"File.read(/path/to/script.groovy)"'
12
+ field :jars, Array, 'JARs to load on remote, empty for none', []
13
+ field :imports, Array, 'Imports to reference within groovy script, empty for none', []
14
+ field :timeout, Fixnum, 'Time to give up waiting', 0
15
+ field :polling_time, Fixnum, 'Time to wait between script invocation', 100000
16
+
17
+ field :enable, Symbol, ':true or :false', :true
18
+ field :start, Symbol, ':true or :false', :true
19
+
20
+ def create_hash
21
+ plugin = 'tv.nativ.mio.plugins.actions.wait.ScriptedWaitCommand'
22
+ {name: @args.name,
23
+ pluginClass: plugin,
24
+ visibilityIds: @args.visibility,
25
+ type: 'script',
26
+ runRuleExpression: ''
27
+ }
28
+ end
29
+
30
+ def config_hash
31
+ {"script_type": {
32
+ "script": @args.script
33
+ },
34
+ "imports": {
35
+ 'jar-url': @args.jars.map{|j| {value: j, isExpression: false}},
36
+ import: @args.imports.map{|i| {value: i, isExpression: false}}
37
+ },
38
+ "timeout": @args.timeout,
39
+ "polling-time-period": @args.polling_time
40
+ }
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,56 @@
1
+ class Mio
2
+ class Model
3
+ class Hotfolder < Model
4
+ set_resource :resources
5
+
6
+ field :storage_name, String, 'The name of the resource to be watched'
7
+ field :workflow_name, String, 'The workflow this hotfolder kicks off'
8
+ field :owner, String, 'The owner of the hotfolder', 'masteruser masteruser'
9
+
10
+ field :name, String, 'Name of the hotfolder'
11
+ field :visibility, Array, 'IDs of accounts that may see this', [4]
12
+
13
+ field :enable, Symbol, ':true or :false', :true
14
+ field :start, Symbol, ':true or :false - :enable must be :true', :false
15
+
16
+ def create_hash
17
+ plugin = 'tv.nativ.mio.enterprise.resources.impl.capacity.folder.hotfolder.MioHotFolderResource'
18
+
19
+ {name: @args.name,
20
+ pluginClass: plugin,
21
+ visibilityIds: @args.visibility}
22
+ end
23
+
24
+ def config_hash
25
+ # Get the s3 resource id
26
+ storage = @search.find_resources_by_name(@args.storage_name).first
27
+ raise Mio::Model::NoSuchResource, "Could not find #{@args.storage_name}" unless storage
28
+
29
+ # Get the workflow name
30
+ workflow = @search.find_workflowDefinitions_by_name(@args.workflow_name).first
31
+ raise Mio::Model::NoSuchResource, "Could not find #{@args.workflow_name}" unless workflow
32
+
33
+ owner = @search.find_users_by_displayName(@args.owner).first
34
+ raise Mio::Model::NoSuchResource, "Could not find #{@args.owner}" unless owner
35
+
36
+ {
37
+ 'housekeeping-period' => 5139767606400000000,
38
+ 'inactivity-timeout' => 30000000,
39
+ 'storage-resources' => {
40
+ 'Storage Resource' => [
41
+ {'id' => storage['id'] }
42
+ ]
43
+ },
44
+ 'use-md5' => false,
45
+ 'workflow-definition' => {
46
+ 'id' => workflow['id']
47
+ },
48
+ 'owner' => {
49
+ 'id' => owner['id']
50
+ }
51
+ }
52
+ end
53
+
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,69 @@
1
+ class Mio
2
+ class Model
3
+ class ImportAction < Model
4
+ set_resource :actions
5
+ field :name, String, 'Name of the Import Action'
6
+ field :key, String, 'AWS API Key with access to S3'
7
+ field :secret, String, 'AWS secret'
8
+ field :bucket, String, 'AWS bucket name'
9
+ field :visibility, Array, 'Ids of the accounts which may see the import action'
10
+
11
+ field :enable, Symbol, ':true or :false', :true
12
+ field :start, Symbol, ':true or :false', :true
13
+
14
+ def create_hash
15
+ plugin = 'tv.nativ.mio.enterprise.execution.action.file.impl.objectimport.vfs.AssetImportCommand'
16
+ {name: @args.name,
17
+ pluginClass: plugin,
18
+ visibilityIds: @args.visibility,
19
+ 'type': 'import',
20
+ 'runRuleExpression': ''
21
+ }
22
+ end
23
+
24
+ def config_hash
25
+ {
26
+ "source-file": {
27
+ "source": {
28
+ "vfs-source-file-path": {
29
+ "protocol": {
30
+ "value": "S3",
31
+ "isExpression": false
32
+ },
33
+ "path": {
34
+ "value": "/${variables.externalFileName}",
35
+ "isExpression": false
36
+ },
37
+ "key": {
38
+ "value": @args['key'],
39
+ "isExpression": false
40
+ },
41
+ "secret": {
42
+ "value": @args.secret,
43
+ "isExpression": false
44
+ },
45
+ "bucket": {
46
+ "value": @args.bucket,
47
+ "isExpression": false
48
+
49
+ }
50
+ }
51
+ },
52
+ "keep-source-filename": false
53
+ },
54
+ "asset-details": {
55
+ "title": {
56
+ "value": "${variables.externalFilename}",
57
+ "isExpression": false
58
+
59
+ },
60
+ "creation-context": {
61
+ "value": "IMPORT",
62
+ "isExpression": false
63
+ }
64
+ }
65
+ }
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,37 @@
1
+ class Mio
2
+ class Model
3
+ class S3 < Model
4
+ set_resource :resources
5
+
6
+ field :name, String, 'Name of the S3 resource'
7
+ field :visibility, Array,'IDs of accounts that may see this', [4]
8
+ field :key, String, 'AWS API Key with access to bucket'
9
+ field :secret, String, 'Secret key associated to :key'
10
+ field :bucket, String, 'Bucket with which to interact'
11
+
12
+ field :enable, Symbol, ':true or :false', :true
13
+ field :start, Symbol, ':true or :false', :true
14
+
15
+ def create_hash
16
+ plugin = 'tv.nativ.mio.enterprise.resources.impl.capacity.storage.vfs.VFSStorageResource'
17
+
18
+ {name: @args.name,
19
+ pluginClass: plugin,
20
+ visibilityIds: @args.visibility}
21
+ end
22
+
23
+ def config_hash
24
+ {
25
+ 'vfs-location' => {
26
+ protocol: "S3",
27
+ path: "/",
28
+ key: @args['key'],
29
+ secret: @args.secret,
30
+ bucket: @args.bucket
31
+ }
32
+ }
33
+ end
34
+
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,98 @@
1
+ class Mio
2
+ class Model
3
+ class Workflow < Model
4
+ set_resource :workflowDefinitions
5
+
6
+ field :name, String, 'Name of the S3 resource'
7
+ field :visibility, Array,'IDs of accounts that may see this', [4]
8
+ field :transitions, Array, 'List of transitions'
9
+ field :nodes, Array, 'List of nodes'
10
+
11
+ field :enable, Symbol, ':true or :false', :true
12
+
13
+ def create_hash
14
+ {name: @args.name,
15
+ visibilityIds: @args.visibility}
16
+ end
17
+
18
+ def normalize_node n
19
+ {
20
+ id: n['id'],
21
+ name: n['name'],
22
+ path: n['path']
23
+ }
24
+ end
25
+
26
+ def set_node_layouts
27
+ x = @spacing
28
+ y = @spacing
29
+
30
+ @args.nodes.map do |n|
31
+ n[:layout] = {
32
+ width: @icon_width,
33
+ height: @icon_height,
34
+ x: x,
35
+ y: y
36
+ }
37
+ x += (@icon_width + @spacing)
38
+ if x > @width - (@icon_width + @spacing)
39
+ x = 0
40
+ y += (@icon_height + @spacing)
41
+ end
42
+ n
43
+ end
44
+ end
45
+
46
+ def transition_lookup structure
47
+ @args.transitions.map do |t|
48
+ from = structure['nodes'].find{|n| n['name'] == t[:from]}
49
+ to = structure['nodes'].find{|n| n['name'] == t[:to]}
50
+
51
+ raise Mio::Model::DataValueError, "#{t[:from]} to #{t[:to]} is an invalid transition" if from.nil? or to.nil?
52
+
53
+ { name: t[:name],
54
+ from: normalize_node(from),
55
+ to: normalize_node(to)}
56
+ end
57
+ end
58
+
59
+ def structure_hash nodes, transitions=[]
60
+ {nodes: nodes,
61
+ transitions: transitions,
62
+ width: @width,
63
+ height: @height}
64
+ end
65
+
66
+ def go
67
+ if @args.nodes.empty? or @args.transitions.empty?
68
+ raise Mio::Model::EmptyField, 'Field nodes to Mio::Model::Workflow must contain at least one node and one transition'
69
+ end
70
+
71
+ @width = 900
72
+ @height = 1024
73
+ @icon_width = 120
74
+ @icon_height = 45
75
+ @spacing = 100
76
+
77
+ unless look_up
78
+ @object = create
79
+ else
80
+ @object = look_up
81
+ set_start :stop
82
+ end
83
+ @structure_path = "#{self.class.resource_name}/#{@object['id']}/structure"
84
+
85
+ laid_out_nodes = set_node_layouts
86
+ # Create structure minus transitions
87
+ structure = @client.update @structure_path, structure_hash(laid_out_nodes)
88
+
89
+ # Create structre with transitions
90
+ @client.update @structure_path, structure_hash(laid_out_nodes, transition_lookup(structure))
91
+
92
+ set_enable
93
+ return @object
94
+ end
95
+
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,35 @@
1
+ class Mio
2
+ class Model
3
+ class Workflow
4
+ class Node < Model
5
+ set_resource :workflows
6
+
7
+ field :name, String, 'Nodal Name'
8
+ field :action, String, 'Name of the action, empty for none', 'Load S3'
9
+ field :type, String, 'Action Type', 'ACTION'
10
+
11
+ nested true
12
+
13
+ def create_hash
14
+ h = {name: @args.name,
15
+ path: "/#{@args.path}",
16
+ type: @args.type.upcase,
17
+ }
18
+ if @args.type.upcase == 'ACTION'
19
+ action = @search.find_actions_by_name(@args.action).first
20
+ h[:action] = normalize_action action
21
+
22
+ end
23
+ h
24
+ end
25
+
26
+ def normalize_action a
27
+ {id: a['id'],
28
+ name: a['name'],
29
+ pluginClass: a['pluginClass']}
30
+ end
31
+
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,20 @@
1
+ class Mio
2
+ class Model
3
+ class Workflow
4
+ class Transition < Model
5
+ set_resource :workflowDefinitions
6
+
7
+ field :from, String, 'Starting node name'
8
+ field :to, String,'Destination node name'
9
+
10
+ nested true
11
+
12
+ def create_hash
13
+ {name: "from #{@args.from} to #{@args.to}",
14
+ from: @args.from,
15
+ to: @args.to}
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,16 @@
1
+ class Mio
2
+ module Requests
3
+ @@content_type = 'application/vnd.nativ.mio.v1+json'
4
+
5
+ def self.make_request type, agent, url, opts, body=nil
6
+ agent.method(type).call do |r|
7
+ r.url url
8
+ unless body.nil?
9
+ r.body = body.to_json
10
+ end
11
+ r.headers[:content_type] = @@content_type
12
+ end
13
+ end
14
+
15
+ end
16
+ end
data/lib/mio/search.rb ADDED
@@ -0,0 +1,29 @@
1
+ class Mio
2
+ class Search
3
+ def initialize client
4
+ @client = client
5
+ end
6
+
7
+ def all resource, key, value
8
+ @client.find_all(resource)[resource].select{|o| o[key] == value}
9
+ end
10
+
11
+ def method_missing method_sym, *arguments, &block
12
+ # the first argument is a Symbol, so you need to_s it if you want to pattern match
13
+ if method_sym.to_s =~ /^find_(.*)_by_(.*)$/
14
+ all($1, $2, arguments.first)
15
+ else
16
+ super
17
+ end
18
+ end
19
+
20
+ def respond_to? method_sym, include_private=false
21
+ if method_sym.to_s =~ /^find_(.*)_by_(.*)$/
22
+ true
23
+ else
24
+ super
25
+ end
26
+ end
27
+
28
+ end
29
+ end