legion-data-java 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.circleci/config.yml +171 -0
- data/.gitignore +12 -0
- data/.rspec +1 -0
- data/.rubocop.yml +33 -0
- data/CHANGELOG.md +16 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +99 -0
- data/README.md +37 -0
- data/Rakefile +55 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/bitbucket-pipelines.yml +26 -0
- data/legion-data.gemspec +50 -0
- data/lib/legion/data.rb +60 -0
- data/lib/legion/data/connection.rb +61 -0
- data/lib/legion/data/migration.rb +15 -0
- data/lib/legion/data/migrations/001_add_schema_columns.rb +17 -0
- 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/model.rb +36 -0
- data/lib/legion/data/models/chain.rb +11 -0
- data/lib/legion/data/models/datacenter.rb +11 -0
- data/lib/legion/data/models/environment.rb +11 -0
- data/lib/legion/data/models/extension.rb +11 -0
- data/lib/legion/data/models/function.rb +15 -0
- data/lib/legion/data/models/group.rb +10 -0
- data/lib/legion/data/models/node.rb +13 -0
- data/lib/legion/data/models/relationship.rb +16 -0
- 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 +16 -0
- data/lib/legion/data/models/task_log.rb +12 -0
- data/lib/legion/data/models/user.rb +10 -0
- data/lib/legion/data/settings.rb +68 -0
- data/lib/legion/data/version.rb +5 -0
- data/sonar-project.properties +12 -0
- metadata +295 -0
@@ -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
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Legion
|
2
|
+
module Data
|
3
|
+
module Models
|
4
|
+
class << self
|
5
|
+
attr_reader :loaded_models
|
6
|
+
|
7
|
+
def models
|
8
|
+
%w[user group extension chain relationship function task runner task_log datacenter environment node setting]
|
9
|
+
end
|
10
|
+
|
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
|
17
|
+
|
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
|
22
|
+
|
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
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'relationship'
|
4
|
+
|
5
|
+
module Legion
|
6
|
+
module Data
|
7
|
+
module Model
|
8
|
+
class Function < Sequel::Model
|
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
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'function'
|
4
|
+
|
5
|
+
module Legion
|
6
|
+
module Data
|
7
|
+
module Model
|
8
|
+
class Relationship < Sequel::Model
|
9
|
+
many_to_one :chain
|
10
|
+
one_to_many :task
|
11
|
+
many_to_one :trigger, class: Legion::Data::Model::Function
|
12
|
+
many_to_one :action, class: Legion::Data::Model::Function
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
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,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Legion
|
4
|
+
module Data
|
5
|
+
module Model
|
6
|
+
class Task < Sequel::Model
|
7
|
+
many_to_one :relationship
|
8
|
+
one_to_many :task_log
|
9
|
+
many_to_one :parent, class: self
|
10
|
+
one_to_many :children, key: :parent_id, class: self
|
11
|
+
many_to_one :master, class: self
|
12
|
+
one_to_many :slave, key: :master_id, class: self
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
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
|
+
}
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.creds
|
43
|
+
{
|
44
|
+
username: 'legion',
|
45
|
+
password: 'legion',
|
46
|
+
database: 'legion',
|
47
|
+
host: '127.0.0.1',
|
48
|
+
port: 3306,
|
49
|
+
debug: false
|
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
|