vagrant-ec-sandbox 0.1.0.Preview

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 (98) hide show
  1. checksums.yaml +7 -0
  2. data/lib/vagrant-ec-sandbox/action/base.rb +53 -0
  3. data/lib/vagrant-ec-sandbox/action/check_dir.rb +41 -0
  4. data/lib/vagrant-ec-sandbox/action/check_file.rb +41 -0
  5. data/lib/vagrant-ec-sandbox/action/code/install.rb +0 -0
  6. data/lib/vagrant-ec-sandbox/action/code/prepare_dist.rb +37 -0
  7. data/lib/vagrant-ec-sandbox/action/code/remove.rb +0 -0
  8. data/lib/vagrant-ec-sandbox/action/code.rb +15 -0
  9. data/lib/vagrant-ec-sandbox/action/dist/check_artifact.rb +26 -0
  10. data/lib/vagrant-ec-sandbox/action/dist/check_wildfly_installer.rb +28 -0
  11. data/lib/vagrant-ec-sandbox/action/dist/clear_contents.rb +34 -0
  12. data/lib/vagrant-ec-sandbox/action/dist/config_ec.rb +92 -0
  13. data/lib/vagrant-ec-sandbox/action/dist/deploy_ecapp.rb +44 -0
  14. data/lib/vagrant-ec-sandbox/action/dist/get_vbuild.rb +39 -0
  15. data/lib/vagrant-ec-sandbox/action/dist/get_vnexus.rb +65 -0
  16. data/lib/vagrant-ec-sandbox/action/dist/install_wildfly.rb +40 -0
  17. data/lib/vagrant-ec-sandbox/action/dist/make_contents.rb +36 -0
  18. data/lib/vagrant-ec-sandbox/action/dist.rb +44 -0
  19. data/lib/vagrant-ec-sandbox/action/init/env_config_confirm.rb +18 -0
  20. data/lib/vagrant-ec-sandbox/action/init/init_dir.rb +31 -0
  21. data/lib/vagrant-ec-sandbox/action/init/init_vagrant.rb +67 -0
  22. data/lib/vagrant-ec-sandbox/action/init.rb +11 -0
  23. data/lib/vagrant-ec-sandbox/action/select_db.rb +51 -0
  24. data/lib/vagrant-ec-sandbox/action/up_vagrant.rb +23 -0
  25. data/lib/vagrant-ec-sandbox/action/use_app_server.rb +27 -0
  26. data/lib/vagrant-ec-sandbox/action/wildfly/get_isinstalled.rb +50 -0
  27. data/lib/vagrant-ec-sandbox/action/wildfly/redirect_dirs.rb +56 -0
  28. data/lib/vagrant-ec-sandbox/action/wildfly/reload.rb +45 -0
  29. data/lib/vagrant-ec-sandbox/action/wildfly/reload_admin.rb +38 -0
  30. data/lib/vagrant-ec-sandbox/action/wildfly/remove.rb +32 -0
  31. data/lib/vagrant-ec-sandbox/action/wildfly/start.rb +42 -0
  32. data/lib/vagrant-ec-sandbox/action/wildfly/start_admin.rb +36 -0
  33. data/lib/vagrant-ec-sandbox/action/wildfly/status.rb +36 -0
  34. data/lib/vagrant-ec-sandbox/action/wildfly/stop.rb +42 -0
  35. data/lib/vagrant-ec-sandbox/action/wildfly/switch_db.rb +48 -0
  36. data/lib/vagrant-ec-sandbox/action/wildfly.rb +79 -0
  37. data/lib/vagrant-ec-sandbox/action.rb +129 -0
  38. data/lib/vagrant-ec-sandbox/command/as/config_db.rb +34 -0
  39. data/lib/vagrant-ec-sandbox/command/as/install.rb +34 -0
  40. data/lib/vagrant-ec-sandbox/command/as/restart.rb +33 -0
  41. data/lib/vagrant-ec-sandbox/command/as/show_status.rb +32 -0
  42. data/lib/vagrant-ec-sandbox/command/as/start.rb +33 -0
  43. data/lib/vagrant-ec-sandbox/command/as/stop.rb +32 -0
  44. data/lib/vagrant-ec-sandbox/command/as/test.rb +32 -0
  45. data/lib/vagrant-ec-sandbox/command/base.rb +52 -0
  46. data/lib/vagrant-ec-sandbox/command/init.rb +29 -0
  47. data/lib/vagrant-ec-sandbox/command/root.rb +101 -0
  48. data/lib/vagrant-ec-sandbox/communicator_extender.rb +45 -0
  49. data/lib/vagrant-ec-sandbox/config/sandbox_config.rb +235 -0
  50. data/lib/vagrant-ec-sandbox/db_selector/db_info.rb +8 -0
  51. data/lib/vagrant-ec-sandbox/db_selector/db_selector.rb +20 -0
  52. data/lib/vagrant-ec-sandbox/db_selector/direct_selector.rb +30 -0
  53. data/lib/vagrant-ec-sandbox/db_selector/direct_selector_config.rb +37 -0
  54. data/lib/vagrant-ec-sandbox/db_selector/manual_input_selector.rb +32 -0
  55. data/lib/vagrant-ec-sandbox/db_selector/oracle_db_info.rb +19 -0
  56. data/lib/vagrant-ec-sandbox/db_selector/selector_config.rb +22 -0
  57. data/lib/vagrant-ec-sandbox/dir_structure.rb +306 -0
  58. data/lib/vagrant-ec-sandbox/errors.rb +33 -0
  59. data/lib/vagrant-ec-sandbox/helpers.rb +11 -0
  60. data/lib/vagrant-ec-sandbox/plugin.rb +29 -0
  61. data/lib/vagrant-ec-sandbox/resource/hg_clone_provider.rb +46 -0
  62. data/lib/vagrant-ec-sandbox/resource/hg_clone_provider_config.rb +29 -0
  63. data/lib/vagrant-ec-sandbox/resource/local_provider.rb +19 -0
  64. data/lib/vagrant-ec-sandbox/resource/local_provider_config.rb +20 -0
  65. data/lib/vagrant-ec-sandbox/resource/maven_provider.rb +51 -0
  66. data/lib/vagrant-ec-sandbox/resource/maven_provider_config.rb +20 -0
  67. data/lib/vagrant-ec-sandbox/resource/provider_config.rb +10 -0
  68. data/lib/vagrant-ec-sandbox/resource/resource_provider.rb +20 -0
  69. data/lib/vagrant-ec-sandbox/server/app_server/as.rb +18 -0
  70. data/lib/vagrant-ec-sandbox/server/app_server/as_config.rb +38 -0
  71. data/lib/vagrant-ec-sandbox/server/server.rb +18 -0
  72. data/lib/vagrant-ec-sandbox/session.rb +146 -0
  73. data/lib/vagrant-ec-sandbox/util/host/dir_util.rb +39 -0
  74. data/lib/vagrant-ec-sandbox/util/host/file_util.rb +67 -0
  75. data/lib/vagrant-ec-sandbox/util/host/hg_clone.rb +32 -0
  76. data/lib/vagrant-ec-sandbox/util/host/mvn.rb +54 -0
  77. data/lib/vagrant-ec-sandbox/util/name.rb +22 -0
  78. data/lib/vagrant-ec-sandbox/util/output_buffer.rb +58 -0
  79. data/lib/vagrant-ec-sandbox/util/sandbox/get_user_processes.rb +85 -0
  80. data/lib/vagrant-ec-sandbox/util/sandbox/system_command.rb +91 -0
  81. data/lib/vagrant-ec-sandbox/util/sandbox/wildfly/add-user.rb +48 -0
  82. data/lib/vagrant-ec-sandbox/util/sandbox/wildfly/deploy.rb +34 -0
  83. data/lib/vagrant-ec-sandbox/util/sandbox/wildfly/response.rb +32 -0
  84. data/lib/vagrant-ec-sandbox/util/sandbox/wildfly/run_cli.rb +86 -0
  85. data/lib/vagrant-ec-sandbox/version.rb +5 -0
  86. data/lib/vagrant-ec-sandbox.rb +113 -0
  87. data/templates/action/dist/install_wildfly.sh.erb +23 -0
  88. data/templates/action/hello.sh.erb +1 -0
  89. data/templates/action/init/Vagrantfile.erb +91 -0
  90. data/templates/action/init/provision.sh.erb +71 -0
  91. data/templates/action/init/resources/settings.xml.erb +118 -0
  92. data/templates/action/wildfly/config_ec.sh.erb +5 -0
  93. data/templates/action/wildfly/deloy.cli.erb +0 -0
  94. data/templates/action/wildfly/open_interface.cli.erb +3 -0
  95. data/templates/action/wildfly/redirect_log.cli.erb +3 -0
  96. data/templates/action/wildfly/switch_db.cli.erb +43 -0
  97. data/templates/locales/en.yml +35 -0
  98. metadata +168 -0
@@ -0,0 +1,146 @@
1
+ require "vagrant/registry"
2
+ require_relative 'resource/local_provider'
3
+ require_relative 'resource/local_provider_config'
4
+
5
+ module VagrantPlugins
6
+ module ECSandbox
7
+ class Session
8
+ def self.default
9
+ return @__default
10
+ end
11
+
12
+ def self.init_default(env)
13
+ config = env.vagrantfile.config.ec
14
+ config ||= VagrantPlugins::ECSandbox::Config::SandboxConfig.new
15
+
16
+ @__default = new(config, env.cwd)
17
+ end
18
+
19
+ def self.create_machine(machine)
20
+ raise "default is not initialized" unless default
21
+
22
+ config = machine.config.ec
23
+ config ||= VagrantPlugins::ECSandbox::Config::SandboxConfig.new
24
+ session = Session.new(config, default.cwd)
25
+
26
+ return default.merge(session)
27
+ end
28
+
29
+ attr_reader :servers
30
+ attr_reader :server_ids
31
+ attr_reader :db_selectors
32
+ attr_reader :db_selector_ids
33
+ attr_reader :dir_structures
34
+ attr_reader :config
35
+ attr_reader :cwd
36
+
37
+ def initialize(config, cwd, opts=nil)
38
+ opts = {
39
+ skip_init: false
40
+ }.merge(opts || {})
41
+
42
+ @resource_providers = Vagrant::Registry.new
43
+ @servers = Vagrant::Registry.new
44
+ @server_ids = {}
45
+ @db_selectors = Vagrant::Registry.new
46
+ @db_selector_ids = {}
47
+ @cwd = cwd
48
+ @config = config
49
+ @dir_structures = {
50
+ host: DirStructure.of(:host, working_dir:cwd),
51
+ sandbox: DirStructure.of(:sandbox, working_dir:cwd)
52
+ }
53
+
54
+ return if opts[:skip_init]
55
+
56
+ config.get_resources.each do |category, name|
57
+ internal_name = __get_resource_internal_name(category, name)
58
+ @resource_providers.register(internal_name) do
59
+ provider_name = config.get_resource_provider_name(category, name)
60
+ provider_config = config.get_resource_config(category, name)
61
+
62
+ klazz = VagrantPlugins::ECSandbox.resource_provider_defs[provider_name]
63
+ raise "resource provider for #{provider_name} is not registered" unless klazz
64
+ new_resource_provider = klazz.new(category, name, provider_config)
65
+ new_resource_provider
66
+ end
67
+ end
68
+
69
+ config.get_servers.each do |id, name|
70
+ # register server
71
+ @servers.register(id) do
72
+ server_config = config.get_server_config(id)
73
+ klazz = VagrantPlugins::ECSandbox.server_defs[name]
74
+ new_server = klazz.new(id, server_config)
75
+ new_server
76
+ end
77
+
78
+ # register server id
79
+ ids = @server_ids[name] || []
80
+ ids << id
81
+ @server_ids[name] = ids
82
+ end
83
+
84
+ config.get_db_selectors.each do |id, name|
85
+ # register db-selector
86
+ @db_selectors.register(id) do
87
+ selector_config = config.get_db_selector_config(id)
88
+ klazz = VagrantPlugins::ECSandbox.db_selector_defs[name]
89
+ new_db_selector = klazz.new(id, selector_config)
90
+ new_db_selector
91
+ end
92
+
93
+ # register db-selector id
94
+ ids = @db_selector_ids[name] || []
95
+ ids << id
96
+ @db_selector_ids[name] = ids
97
+ end
98
+ end
99
+
100
+ def resource_provider(category, name)
101
+ provider = @resource_providers.get(__get_resource_internal_name(category, name))
102
+ unless provider
103
+ config = VagrantPlugins::ECSandbox::Resource::LocalProviderConfig.new
104
+ config.path = @dir_structures[:host].resource(category, name)
105
+ provider = VagrantPlugins::ECSandbox::Resource::LocalProvider.new(category, name, config)
106
+ end
107
+
108
+ provider
109
+ end
110
+
111
+ # Merge one session with another and return a completely new
112
+ # session.
113
+ def merge(other)
114
+ self.class.new(other.config, other.cwd, skip_init: true).tap do |result|
115
+ result.merge!(self)
116
+ result.merge!(other)
117
+ end
118
+ end
119
+
120
+ # Like #{merge} but merges into self.
121
+ def merge!(other)
122
+ @resource_providers.merge!(other.instance_variable_get(:@resource_providers))
123
+ @servers.merge!(other.servers)
124
+ @db_selectors.merge!(other.db_selectors)
125
+ @dir_structures.merge!(other.dir_structures)
126
+ @server_ids.merge!(other.server_ids) { |key, old_val, new_val|
127
+ (old_val || []) | (new_val || [])
128
+ }
129
+ @db_selector_ids.merge!(other.db_selector_ids) { |key, old_val, new_val|
130
+ (old_val || []) | (new_val || [])
131
+ }
132
+
133
+ self
134
+ end
135
+
136
+ def __get_resource_internal_name(category, name)
137
+ category = category.to_s if category.is_a?(Symbol)
138
+ name = name.to_s if name.is_a?(Symbol)
139
+ name = "#{category}_#{name}"
140
+
141
+ name.to_sym
142
+ end
143
+
144
+ end
145
+ end
146
+ end
@@ -0,0 +1,39 @@
1
+ require "fileutils"
2
+
3
+
4
+ module VagrantPlugins
5
+ module ECSandbox
6
+ module Util
7
+ module Host
8
+ class DirUtil
9
+ def self.create(dir, contents, opts=nil)
10
+ path.mkdir unless path.exist?
11
+ end
12
+
13
+ def self.delete(path)
14
+ path.delete if path.exist?
15
+ end
16
+
17
+ def self.using(contents, env, opts=nil, &block)
18
+ tmpfile_opts = {
19
+ make_parents: true,
20
+ delete_existing: true,
21
+ file_name_base: nil,
22
+ category: nil
23
+ }.merge(opts || {}) do |key, oldval, newval|
24
+ oldval || newval
25
+ end
26
+
27
+ name = ::VagrantPlugins::ECSandbox::Util::Name.unique(base:tmpfile_opts[:file_name_base])
28
+ dir = ::VagrantPlugins::ECSandbox::Util::DirUtil.tmp(category)
29
+ path = Pathname.new(File.expand_path(name, dir))
30
+
31
+ create(path, contents, tmpfile_opts)
32
+ block.call(path)
33
+ delete(path)
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,67 @@
1
+ require "log4r"
2
+ require "vagrant/plugin/manager"
3
+ require "vagrant/util/platform"
4
+ require_relative "../name"
5
+ require_relative "dir_util"
6
+
7
+ module VagrantPlugins
8
+ module ECSandbox
9
+ module Util
10
+ module Host
11
+ class FileUtil
12
+ def self.create(dest, contents, opts=nil)
13
+ new_opts = {
14
+ make_dir: true,
15
+ delete_existing: true,
16
+ use_unit_line_ending: true
17
+ }.merge(opts || {}) do |key, oldval, newval|
18
+ oldval || newval
19
+ end
20
+
21
+ if !dest
22
+ return
23
+ end
24
+
25
+ if new_opts[:delete_existing] && dest.exist?
26
+ dest.delete
27
+ end
28
+
29
+ FileUtils.mkdir_p(dest.dirname) if new_opts[:make_dir] && !dest.dirname.exist?
30
+
31
+ if new_opts[:use_unit_line_ending] && Vagrant::Util::Platform.windows?
32
+ contents = contents.gsub(/\r\n?/,"\n")
33
+ end
34
+
35
+ if dest.open("wb+") do |f|
36
+ f.write(contents)
37
+ end
38
+ end
39
+ end
40
+
41
+ def self.delete(path)
42
+ path.delete if path.exist?
43
+ end
44
+
45
+ # def self.using(contents, tmp_root, opts=nil, &block)
46
+ # tmpfile_opts = {
47
+ # make_parents: true,
48
+ # delete_existing: true,
49
+ # file_name_base: nil,
50
+ # category: nil
51
+ # }.merge(opts || {}) do |key, oldval, newval|
52
+ # oldval || newval
53
+ # end
54
+
55
+ # name = ::VagrantPlugins::ECSandbox::Util::Name.unique(base:tmpfile_opts[:file_name_base])
56
+ # path = Pathname.new(File.expand_path(name, tmp_root))
57
+
58
+ # create(path, contents, tmpfile_opts)
59
+ # block.call(path)
60
+ # # TODO: windows permission issue when deleting a file
61
+ # #delete(path)
62
+ # end
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,32 @@
1
+ require "log4r"
2
+ require "vagrant/plugin/manager"
3
+ require "vagrant/util/platform"
4
+
5
+
6
+ module VagrantPlugins
7
+ module ECSandbox
8
+ module Util
9
+ module Host
10
+ class HgClone
11
+ def self.execute(source, target, branch, env)
12
+ new(source, target, branch).execute(env)
13
+ end
14
+
15
+ def initialize(source, target, branch)
16
+ @source = source
17
+ @target = target
18
+ @branch = branch || 'default'
19
+ end
20
+
21
+ def execute(env)
22
+ Vagrant::Util::Subprocess.execute("hg", "clone", "-b#{@branch}", @source.to_s, @target.to_s, notify:[:stdout, :stderr]) do |type, data|
23
+ if type == :stderr
24
+ raise "failed to clone, detailed message - " << data
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,54 @@
1
+ require "log4r"
2
+ require "vagrant/plugin/manager"
3
+ require "vagrant/util/platform"
4
+ require_relative "../output_buffer"
5
+
6
+
7
+ module VagrantPlugins
8
+ module ECSandbox
9
+ module Util
10
+ module Host
11
+ class Mvn
12
+ def self.execute(dir, env, *phases, &block)
13
+ new(dir).execute(env, phases, &block)
14
+ end
15
+
16
+ def self.install(dir, env, &block)
17
+ new(dir).execute(env, "clean", "install", &block)
18
+ end
19
+
20
+ def self.copy()
21
+ end
22
+
23
+
24
+ def initialize(dir)
25
+ @dir = dir.to_s
26
+ end
27
+
28
+ def execute(env, *phases, &block)
29
+ commands = ["mvn"].concat(phases || [])
30
+ listener = nil
31
+
32
+ if block
33
+ listener = VagrantPlugins::ECSandbox::Util::OutputBuffer.listen do |io_name, data|
34
+ if (match=data.match(/(Downloading: )(.*)/i))
35
+ block.call(:downloading, match.captures[1].strip)
36
+ # elsif (match=data.match(/(\[INFO\] )(Building )(.*)( )(.*)/i))
37
+ # block.call(:start_build, {artifact:match.captures[2].strip, version:match.captures[4].strip})
38
+ elsif (match=data.match(/(\[INFO\] )(BUILD SUCCESS)(.*)/i))
39
+ block.call(:result, :success)
40
+ elsif (match=data.match(/(\[INFO\] )(BUILD FAILURE)(.*)/i))
41
+ block.call(:result, :failure)
42
+ elsif (match=data.match(/(\[INFO\] )(Installing )(.*)( )(.*)/i))
43
+ block.call(:installing, {local:match.captures[2].strip, repo:match.captures[4].strip})
44
+ end
45
+ end
46
+ end
47
+
48
+ Vagrant::Util::Subprocess.execute(*commands, notify:[:stdout, :stderr], workdir:@dir, &listener)
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,22 @@
1
+ require "log4r"
2
+ require "vagrant/plugin/manager"
3
+ require "vagrant/util/platform"
4
+
5
+ module VagrantPlugins
6
+ module ECSandbox
7
+ module Util
8
+ class Name
9
+ def self.unique(opts=nil)
10
+ new_opts = {
11
+ base:nil,
12
+ suffix:nil
13
+ }.merge(opts || {}) do |key, oldval, newval|
14
+ oldval || newval
15
+ end
16
+
17
+ (new_opts[:base] || 'any') << "#" << DateTime.now.strftime('%Q') << "#" << SecureRandom.random_number(1000).to_s << (new_opts[:suffix] || '')
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,58 @@
1
+ module VagrantPlugins
2
+ module ECSandbox
3
+ module Util
4
+ class OutputBuffer
5
+ def initialize(opts=nil, &block)
6
+ opts = {
7
+ skip_all:false
8
+ }.merge(opts || {})
9
+ @block = block;
10
+ @skip_all = (opts[:skip_all] || false) || !@block
11
+ end
12
+
13
+ def self.listen(opts=nil, &block)
14
+ new(opts, &block).method(:on_output)
15
+ end
16
+
17
+ def on_output(io_name, data)
18
+ if @skip_all
19
+ return
20
+ end
21
+
22
+ @pending ||= {}
23
+ io_name_sym = io_name.to_sym
24
+
25
+ data.lines.map {|l|
26
+ if l.size == 0
27
+ return
28
+ end
29
+
30
+ if l[l.size-1].ord != 10 #line feed
31
+ @pending[io_name_sym] ||= ""
32
+ @pending[io_name_sym] << l
33
+ return
34
+ end
35
+
36
+ if @pending[io_name_sym]
37
+ l = @pending[io_name_sym] << l
38
+ @pending[io_name_sym] = nil
39
+ end
40
+
41
+ l = l.strip
42
+ @block.call(io_name_sym, l)
43
+ }
44
+ end
45
+
46
+ def skip_all
47
+ @skip_all = true
48
+ end
49
+
50
+ def reset
51
+ @result = nil
52
+ @pending = nil
53
+ @skip_all = true if @block
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,85 @@
1
+ require "log4r"
2
+ require "vagrant/plugin/manager"
3
+ require "vagrant/util/platform"
4
+ require_relative "system_command"
5
+ require_relative "../../errors"
6
+
7
+
8
+ module VagrantPlugins
9
+ module ECSandbox
10
+ module Util
11
+ module Sandbox
12
+ class GetUserProcesses < SystemCommand
13
+ def self.execute(username, env)
14
+ new(username).execute(env)
15
+ end
16
+
17
+ def initialize(username)
18
+ @username = username
19
+ super("ps -u #{username} -o pid,cmd --no-header", {good_exit: [0, 1]})
20
+ end
21
+
22
+ def on_line(type, line)
23
+ if type == :stderr
24
+ if line.match(/(user name does not exist)/i)
25
+ skip_outputs
26
+ @error = 1
27
+ end
28
+ else
29
+ @result ||= []
30
+
31
+ seperator_idx = line.index(' ')
32
+
33
+ if !seperator_idx
34
+ return
35
+ end
36
+
37
+ pid = line[0..seperator_idx-1]
38
+ command = line[seperator_idx+1..line.size]
39
+ info = find_info(command)
40
+
41
+ @result << {:pid=>pid, :command=>command, :info=>info}
42
+ end
43
+ end
44
+
45
+
46
+ def on_end(result_code)
47
+ if @error == 1
48
+ raise VagrantPlugins::ECSandbox::Errors::UserNameNotFoundError, username: @username
49
+ end
50
+
51
+ @result ||= []
52
+ end
53
+
54
+ def find_info(command)
55
+ info = {}
56
+
57
+ name = ""
58
+ type = nil
59
+
60
+ if (match=command.match(/(\/bin\/sh .*bin\/domain\.sh)/i))
61
+ type = :wildfly_domain_sh
62
+ name = "Wildfly Domain Executable"
63
+ elsif (match=command.match(/(java -D\[)(.*)(\])/i))
64
+ name = match.captures[1].strip
65
+
66
+ if name.start_with?("Process Controller")
67
+ type = :wildfly_process_controller
68
+ elsif name.start_with?("Host Controller")
69
+ type = :wildfly_host_controller
70
+ elsif name.start_with?("Server:")
71
+ type = :wildfly_server
72
+ info[:server_name] = name[7,name.size]
73
+ end
74
+ end
75
+
76
+ info[:name] = name
77
+ info[:type] = type
78
+
79
+ info
80
+ end
81
+ end
82
+ end
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,91 @@
1
+ require "log4r"
2
+ require "vagrant/plugin/manager"
3
+ require "vagrant/util/platform"
4
+
5
+
6
+ module VagrantPlugins
7
+ module ECSandbox
8
+ module Util
9
+ module Sandbox
10
+ class SystemCommand
11
+ def initialize(command, opts=nil)
12
+ @command = command
13
+ @opts = {
14
+ sudo: false
15
+ }.merge(opts || {})
16
+ end
17
+
18
+ def execute(env)
19
+ ext_logger = VagrantPlugins::ECSandbox.logger("parser::base")
20
+ ext_logger.debug("To run command #{@command} with parser.")
21
+ communicate = env[:machine].communicate
22
+
23
+ if (@opts[:sudo])
24
+ r = communicate.sudo(@command, @opts.merge(@opts || {})) do |type, data|
25
+ on_output(type, data)
26
+ end
27
+ else
28
+ r = communicate.execute(@command, @opts.merge(@opts || {})) do |type, data|
29
+ on_output(type, data)
30
+ end
31
+ end
32
+
33
+ begin
34
+ on_end(r)
35
+ result = @result
36
+ @result = nil
37
+ ensure
38
+ reset
39
+ end
40
+
41
+ result
42
+ end
43
+
44
+ def on_output(type, data)
45
+ if @skip_outputs
46
+ return
47
+ end
48
+
49
+ @pending ||= {}
50
+ type_sym = type.to_sym
51
+
52
+ data.lines.map {|l|
53
+ if l.size == 0
54
+ return
55
+ end
56
+
57
+ if l[l.size-1].ord != 10 #line feed
58
+ @pending[type_sym] ||= ""
59
+ @pending[type_sym] << l
60
+ return
61
+ end
62
+
63
+ if @pending[type_sym]
64
+ l = @pending[type_sym] << l
65
+ @pending[type_sym] = nil
66
+ end
67
+
68
+ l = l.strip
69
+ on_line(type_sym, l)
70
+ }
71
+ end
72
+
73
+ def skip_outputs
74
+ @skip_outputs = true
75
+ end
76
+
77
+ def on_line(type, line)
78
+ end
79
+
80
+ def on_end(result_code)
81
+ end
82
+
83
+ def reset
84
+ @result = nil
85
+ @skip_outputs = nil
86
+ end
87
+ end
88
+ end
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,48 @@
1
+ require "log4r"
2
+ require "vagrant/plugin/manager"
3
+ require "vagrant/util/platform"
4
+ require_relative "../system_command"
5
+
6
+
7
+ module VagrantPlugins
8
+ module ECSandbox
9
+ module Util
10
+ module Sandbox
11
+ module Wildfly
12
+ class AddUser < VagrantPlugins::ECSandbox::Util::Sandbox::SystemCommand
13
+ def self.execute(env, user_name, password, opts=nil)
14
+ new(env[:sandbox_session], user_name, password, opts).execute(env)
15
+ end
16
+
17
+ def initialize(session, user_name, password, opts=nil)
18
+ new_opts = {
19
+ user_type: :management
20
+ }.merge(opts || {})
21
+
22
+ @user_name = user_name
23
+ @password = password
24
+ @user_type = opts[:user_type] || :management
25
+ @adduser_bin = session.dir_structures[:sandbox].internal(:app, :as, "wildfly-8.1.0.Final", "bin", "add-user.sh")
26
+
27
+ additional_param = ''
28
+ case @user_type
29
+ when :management
30
+ additional_param = ''
31
+ when :application
32
+ additional_param = '-a'
33
+ else
34
+ raise "unkonwn user type #{@user_type.to_s}"
35
+ end
36
+
37
+ super("sudo -u wildfly #{@adduser_bin} --user #{user_name} --password #{password} --enable --confirm-warning --silent #{additional_param}",
38
+ {good_exit: [0]})
39
+ end
40
+
41
+ def on_line(type, line)
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,34 @@
1
+ require "log4r"
2
+ require "vagrant/plugin/manager"
3
+ require "vagrant/util/platform"
4
+ require_relative "../system_command"
5
+
6
+
7
+ module VagrantPlugins
8
+ module ECSandbox
9
+ module Util
10
+ module Sandbox
11
+ module Wildfly
12
+ class Deploy < VagrantPlugins::ECSandbox::Util::Sandbox::SystemCommand
13
+ def self.execute(wildfly_home, artifact_path, server_group, env)
14
+ new(wildfly_home, artifact_path, server_group).execute(env)
15
+ end
16
+
17
+ def initialize(wildfly_home, artifact_path, server_group)
18
+ super("sudo -u wildfly #{wildfly_home}/bin/jboss-cli.sh --connect --command=\"deploy --server-groups=#{server_group} #{artifact_path}\"")
19
+ end
20
+
21
+ def on_line(type, line)
22
+ @result ||= []
23
+ puts line
24
+ end
25
+
26
+ def on_end(result_code)
27
+ @result ||= []
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end