legion-data 0.1.0 → 1.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +98 -71
- data/.gitignore +0 -1
- data/.rubocop.yml +10 -7
- data/CHANGELOG.md +16 -0
- data/Gemfile +0 -3
- data/Gemfile.lock +100 -0
- data/README.md +13 -11
- data/legion-data.gemspec +22 -10
- data/lib/legion/data.rb +51 -33
- data/lib/legion/data/connection.rb +55 -19
- data/lib/legion/data/migration.rb +7 -20
- data/lib/legion/data/migrations/001_add_schema_columns.rb +1 -1
- data/lib/legion/data/migrations/002_add_users.rb +17 -0
- data/lib/legion/data/migrations/003_add_groups.rb +16 -0
- data/lib/legion/data/migrations/004_add_chains.rb +25 -0
- data/lib/legion/data/migrations/005_add_envs.rb +24 -0
- data/lib/legion/data/migrations/006_add_dcs.rb +24 -0
- data/lib/legion/data/migrations/007_add_nodes.rb +26 -0
- data/lib/legion/data/migrations/008_add_settings.rb +18 -0
- data/lib/legion/data/migrations/009_add_extensions.rb +25 -0
- data/lib/legion/data/migrations/010_add_runners.rb +21 -0
- data/lib/legion/data/migrations/011_add_functions.rb +29 -0
- data/lib/legion/data/migrations/012_add_tasks.rb +28 -0
- data/lib/legion/data/migrations/013_add_task_logs.rb +23 -0
- data/lib/legion/data/migrations/014_add_relationships.rb +27 -0
- data/lib/legion/data/migrations/015_add_default_extensions.rb +24 -0
- data/lib/legion/data/migrations/016_change_task_args.rb +7 -0
- data/lib/legion/data/migrations/017_add_payload_task.rb +7 -0
- data/lib/legion/data/migrations/018_add_migration_column.rb +7 -0
- data/lib/legion/data/model.rb +26 -25
- data/lib/legion/data/models/chain.rb +0 -1
- data/lib/legion/data/models/datacenter.rb +0 -1
- data/lib/legion/data/models/environment.rb +0 -1
- data/lib/legion/data/models/extension.rb +11 -0
- data/lib/legion/data/models/function.rb +5 -4
- data/lib/legion/data/models/group.rb +10 -0
- data/lib/legion/data/models/node.rb +1 -1
- data/lib/legion/data/models/relationship.rb +1 -1
- data/lib/legion/data/models/runner.rb +15 -0
- data/lib/legion/data/models/setting.rb +10 -0
- data/lib/legion/data/models/task.rb +0 -1
- data/lib/legion/data/models/task_log.rb +0 -1
- data/lib/legion/data/models/user.rb +10 -0
- data/lib/legion/data/settings.rb +68 -0
- data/lib/legion/data/version.rb +1 -1
- data/sonar-project.properties +12 -0
- metadata +119 -54
- data/lib/legion/data/connections/base.rb +0 -45
- data/lib/legion/data/connections/jdbc.rb +0 -21
- data/lib/legion/data/connections/mysql.rb +0 -26
- data/lib/legion/data/connections/mysql2.rb +0 -26
- data/lib/legion/data/connections/mysql_base.rb +0 -19
- data/lib/legion/data/migrations/002_add_chains_table.rb +0 -21
- data/lib/legion/data/migrations/003_add_datacenters_table.rb +0 -21
- data/lib/legion/data/migrations/004_add_envs_table.rb +0 -21
- data/lib/legion/data/migrations/005_add_functions_table.rb +0 -25
- data/lib/legion/data/migrations/006_add_namespaces_table.rb +0 -24
- data/lib/legion/data/migrations/007_add_nodes_table.rb +0 -22
- data/lib/legion/data/migrations/008_add_relationships_table.rb +0 -28
- data/lib/legion/data/migrations/009_add_task_logs_table.rb +0 -17
- data/lib/legion/data/migrations/010_add_tasks_table.rb +0 -20
- data/lib/legion/data/migrations/011_add_users_and_groups.rb +0 -28
- data/lib/legion/data/migrations/012_foreign_keys_users_and_groups.rb +0 -42
- data/lib/legion/data/migrations/013_function_foreign_keys.rb +0 -10
- data/lib/legion/data/migrations/014_nodes_foreign_keys.rb +0 -12
- data/lib/legion/data/migrations/015_relationships_foreign_keys.rb +0 -14
- data/lib/legion/data/migrations/016_tasks_foreign_keys.rb +0 -22
- data/lib/legion/data/migrations/017_add_relationship_to_tasks.rb +0 -14
- data/lib/legion/data/models/namespace.rb +0 -12
@@ -0,0 +1,21 @@
|
|
1
|
+
Sequel.migration do
|
2
|
+
up do
|
3
|
+
run "CREATE TABLE `runners` (
|
4
|
+
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
|
5
|
+
`extension_id` int(11) unsigned NOT NULL,
|
6
|
+
`name` varchar(256) NOT NULL DEFAULT '',
|
7
|
+
`namespace` varchar(256) NOT NULL DEFAULT '',
|
8
|
+
`active` tinyint(1) unsigned NOT NULL DEFAULT '1',
|
9
|
+
`queue` varchar(256) DEFAULT NULL,
|
10
|
+
`uri` varchar(256) DEFAULT NULL,
|
11
|
+
`created` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
12
|
+
`updated` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
|
13
|
+
PRIMARY KEY (`id`),
|
14
|
+
CONSTRAINT `runner_extension_id` FOREIGN KEY (`extension_id`) REFERENCES `extensions` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
|
15
|
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;"
|
16
|
+
end
|
17
|
+
|
18
|
+
down do
|
19
|
+
drop_table :runners
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
Sequel.migration do
|
2
|
+
up do
|
3
|
+
run "CREATE TABLE `functions` (
|
4
|
+
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
|
5
|
+
`name` varchar(128) NOT NULL,
|
6
|
+
`active` tinyint(1) unsigned NOT NULL DEFAULT '1',
|
7
|
+
`runner_id` int(11) unsigned NOT NULL,
|
8
|
+
`args` text,
|
9
|
+
`user_owner` int(11) unsigned DEFAULT NULL,
|
10
|
+
`group_owner` int(11) unsigned DEFAULT NULL,
|
11
|
+
`created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
12
|
+
`updated` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
|
13
|
+
PRIMARY KEY (`id`),
|
14
|
+
UNIQUE KEY `runner_id` (`runner_id`,`name`),
|
15
|
+
KEY `active` (`active`),
|
16
|
+
KEY `namespace` (`runner_id`),
|
17
|
+
KEY `name` (`name`),
|
18
|
+
KEY `functions_user_owner` (`user_owner`),
|
19
|
+
KEY `functions_group_owner` (`group_owner`),
|
20
|
+
CONSTRAINT `function_runner_id` FOREIGN KEY (`runner_id`) REFERENCES `runners` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
21
|
+
CONSTRAINT `functions_group_owner` FOREIGN KEY (`group_owner`) REFERENCES `groups` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
22
|
+
CONSTRAINT `functions_user_owner` FOREIGN KEY (`user_owner`) REFERENCES `users` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
|
23
|
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;"
|
24
|
+
end
|
25
|
+
|
26
|
+
down do
|
27
|
+
drop_table :functions
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
Sequel.migration do
|
2
|
+
up do
|
3
|
+
run "CREATE TABLE `tasks` (
|
4
|
+
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
|
5
|
+
`relationship_id` int(11) unsigned DEFAULT NULL,
|
6
|
+
`function_id` int(11) unsigned DEFAULT NULL,
|
7
|
+
`status` varchar(255) NOT NULL,
|
8
|
+
`parent_id` int(11) unsigned DEFAULT NULL,
|
9
|
+
`master_id` int(11) unsigned DEFAULT NULL,
|
10
|
+
`args` text,
|
11
|
+
`results` text,
|
12
|
+
`created` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
13
|
+
`updated` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
|
14
|
+
PRIMARY KEY (`id`),
|
15
|
+
KEY `status` (`status`),
|
16
|
+
KEY `parent_id` (`parent_id`),
|
17
|
+
KEY `master_id` (`master_id`),
|
18
|
+
KEY `relationship_id` (`relationship_id`),
|
19
|
+
KEY `function_id` (`function_id`),
|
20
|
+
CONSTRAINT `parent_id` FOREIGN KEY (`parent_id`) REFERENCES `tasks` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
21
|
+
CONSTRAINT `master_id` FOREIGN KEY (`master_id`) REFERENCES `tasks` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
|
22
|
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;"
|
23
|
+
end
|
24
|
+
|
25
|
+
down do
|
26
|
+
drop_table :tasks
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
Sequel.migration do
|
2
|
+
up do
|
3
|
+
run "CREATE TABLE `task_logs` (
|
4
|
+
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
|
5
|
+
`task_id` int(11) unsigned NOT NULL,
|
6
|
+
`function_id` int(11) unsigned,
|
7
|
+
`node_id` int(11) unsigned,
|
8
|
+
`entry` text NOT NULL,
|
9
|
+
`created` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
10
|
+
`updated` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
|
11
|
+
PRIMARY KEY (`id`),
|
12
|
+
KEY (`created`),
|
13
|
+
KEY (`updated`),
|
14
|
+
CONSTRAINT `task_log_task_id` FOREIGN KEY (`task_id`) REFERENCES `tasks` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
15
|
+
CONSTRAINT `task_log_functions` FOREIGN KEY (`function_id`) REFERENCES `functions` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
16
|
+
CONSTRAINT `task_log_nodes` FOREIGN KEY (`node_id`) REFERENCES `nodes` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
|
17
|
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;"
|
18
|
+
end
|
19
|
+
|
20
|
+
down do
|
21
|
+
drop_table :task_logs
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
Sequel.migration do
|
2
|
+
up do
|
3
|
+
run "CREATE TABLE `relationships` (
|
4
|
+
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
|
5
|
+
`name` varchar(255) DEFAULT NULL,
|
6
|
+
`active` tinyint(1) unsigned NOT NULL DEFAULT '1',
|
7
|
+
`chain_id` int(11) unsigned DEFAULT NULL,
|
8
|
+
`trigger_id` int(11) unsigned NOT NULL,
|
9
|
+
`action_id` int(11) unsigned NOT NULL,
|
10
|
+
`delay` int(11) unsigned NOT NULL DEFAULT '0',
|
11
|
+
`allow_new_chains` tinyint(1) unsigned NOT NULL DEFAULT '1',
|
12
|
+
`conditions` text,
|
13
|
+
`transformation` text,
|
14
|
+
`created` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
15
|
+
`updated` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
|
16
|
+
PRIMARY KEY (`id`),
|
17
|
+
KEY `chain_id` (`chain_id`),
|
18
|
+
CONSTRAINT `function_chain_id` FOREIGN KEY (`chain_id`) REFERENCES `chains` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
19
|
+
CONSTRAINT `relationship_action_id` FOREIGN KEY (`action_id`) REFERENCES `functions` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
20
|
+
CONSTRAINT `relationship_trigger_id` FOREIGN KEY (`trigger_id`) REFERENCES `functions` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
|
21
|
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;"
|
22
|
+
end
|
23
|
+
|
24
|
+
down do
|
25
|
+
drop_table :relationships
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
Sequel.migration do
|
2
|
+
up do
|
3
|
+
lex = from(:extensions).insert(namespace: 'Legion::Extensions::Lex', name: 'lex', exchange: 'lex', uri: 'lex')
|
4
|
+
[
|
5
|
+
{ extension_id: lex, namespace: 'Legion::Extensions::Lex::Runners::Register', name: 'register', queue: 'register', uri: 'register' },
|
6
|
+
{ extension_id: lex, namespace: 'Legion::Extensions::Lex::Runners::Function', name: 'function', queue: 'function', uri: 'function' },
|
7
|
+
{ extension_id: lex, namespace: 'Legion::Extensions::Lex::Runners::Runner', name: 'runner', queue: 'runner', uri: 'runner' },
|
8
|
+
{ extension_id: lex, namespace: 'Legion::Extensions::Lex::Runners::Extension', name: 'extension', queue: 'extension', uri: 'extension' }
|
9
|
+
].each do |row|
|
10
|
+
from(:runners).insert row
|
11
|
+
end
|
12
|
+
|
13
|
+
lex = from(:extensions).insert(namespace: 'Legion::Extensions::Node', name: 'node', exchange: 'node', uri: 'node')
|
14
|
+
[
|
15
|
+
{ extension_id: lex, namespace: 'Legion::Extensions::Node::Runners::Crypt', name: 'crypt', queue: 'crypt', uri: 'crypt' }
|
16
|
+
].each do |row|
|
17
|
+
from(:runners).insert row
|
18
|
+
end
|
19
|
+
end
|
20
|
+
down do
|
21
|
+
from(:extensions).where(namespace: 'Legion::Extensions::Lex').delete
|
22
|
+
from(:extensions).where(namespace: 'Legion::Extensions::Node').delete
|
23
|
+
end
|
24
|
+
end
|
data/lib/legion/data/model.rb
CHANGED
@@ -1,34 +1,35 @@
|
|
1
1
|
module Legion
|
2
2
|
module Data
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
options.merge!(default_options) { |_key, v1, _v2| v1 }
|
7
|
-
@loaded_models = []
|
8
|
-
require_sequel_models if options[:auto_load]
|
9
|
-
end
|
3
|
+
module Models
|
4
|
+
class << self
|
5
|
+
attr_reader :loaded_models
|
10
6
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
end
|
7
|
+
def models
|
8
|
+
%w[user group extension chain relationship function task runner task_log datacenter environment node setting]
|
9
|
+
end
|
15
10
|
|
16
|
-
|
17
|
-
|
18
|
-
|
11
|
+
def load
|
12
|
+
Legion::Logging.info 'Loading Legion::Data::Models'
|
13
|
+
@loaded_models ||= []
|
14
|
+
require_sequel_models(models)
|
15
|
+
Legion::Settings[:data][:models][:loaded] = true
|
16
|
+
end
|
19
17
|
|
20
|
-
|
21
|
-
|
22
|
-
|
18
|
+
def require_sequel_models(files = models)
|
19
|
+
Dir["#{File.dirname(__FILE__)}models/*.rb"].each { |file| puts file }
|
20
|
+
files.each { |file| load_sequel_model(file) }
|
21
|
+
end
|
23
22
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
23
|
+
def load_sequel_model(model)
|
24
|
+
Legion::Logging.debug("Trying to load #{model}.rb")
|
25
|
+
require_relative "models/#{model}"
|
26
|
+
@loaded_models << model
|
27
|
+
Legion::Logging.debug("Successfully loaded #{model}")
|
28
|
+
model
|
29
|
+
rescue LoadError => e
|
30
|
+
Legion::Logging.fatal("Failed to load #{model}")
|
31
|
+
raise e unless Legion::Settings[:data][:models][:continue_on_fail]
|
32
|
+
end
|
32
33
|
end
|
33
34
|
end
|
34
35
|
end
|
@@ -1,13 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative 'relationship'
|
4
|
+
|
3
5
|
module Legion
|
4
6
|
module Data
|
5
7
|
module Model
|
6
|
-
# Used for accessing legion.functions
|
7
8
|
class Function < Sequel::Model
|
8
|
-
many_to_one :
|
9
|
-
one_to_many :
|
10
|
-
one_to_many :
|
9
|
+
many_to_one :runner
|
10
|
+
one_to_many :trigger_relationships, class: 'Legion::Data::Model::Relationship', key: :trigger_id
|
11
|
+
one_to_many :action_relationships, class: 'Legion::Data::Model::Relationship', key: :action_id
|
11
12
|
end
|
12
13
|
end
|
13
14
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'function'
|
4
|
+
module Legion
|
5
|
+
module Data
|
6
|
+
module Model
|
7
|
+
class Runner < Sequel::Model
|
8
|
+
many_to_one :chain
|
9
|
+
one_to_many :task
|
10
|
+
one_to_many :functions
|
11
|
+
many_to_one :extension
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
module Legion
|
2
|
+
module Data
|
3
|
+
module Settings
|
4
|
+
def self.default
|
5
|
+
{
|
6
|
+
connected: false,
|
7
|
+
cache: cache,
|
8
|
+
connection: connection,
|
9
|
+
creds: creds,
|
10
|
+
migrations: migrations,
|
11
|
+
models: models,
|
12
|
+
connect_on_start: true
|
13
|
+
}
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.models
|
17
|
+
{
|
18
|
+
continue_on_load_fail: false,
|
19
|
+
autoload: true
|
20
|
+
}
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.migrations
|
24
|
+
{
|
25
|
+
continue_on_fail: false,
|
26
|
+
auto_migrate: true,
|
27
|
+
ran: false,
|
28
|
+
version: nil
|
29
|
+
}
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.connection
|
33
|
+
{
|
34
|
+
log: false,
|
35
|
+
log_connection_info: false,
|
36
|
+
log_warn_duration: 1,
|
37
|
+
sql_log_level: 'debug',
|
38
|
+
max_connections: 10,
|
39
|
+
preconnect: false
|
40
|
+
}
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.creds
|
44
|
+
{
|
45
|
+
username: 'legion',
|
46
|
+
password: 'legion',
|
47
|
+
database: 'legion',
|
48
|
+
host: '127.0.0.1',
|
49
|
+
port: 3306
|
50
|
+
}
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.cache
|
54
|
+
{
|
55
|
+
connected: false,
|
56
|
+
auto_enable: Legion::Settings[:cache][:connected],
|
57
|
+
ttl: 60
|
58
|
+
}
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
begin
|
65
|
+
Legion::Settings.merge_settings('data', Legion::Data::Settings.default) if Legion.const_defined?('Settings')
|
66
|
+
rescue StandardError => e
|
67
|
+
Legion::Logging.fatal(e.message) if Legion::Logging.method_defined?(:fatal)
|
68
|
+
end
|