Skip to content

Commit

Permalink
Merge pull request #14 from rdoorn/master
Browse files Browse the repository at this point in the history
add enable/disable deploy provider, and minor warnings fixed
  • Loading branch information
bdwyertech committed Sep 11, 2014
2 parents 8f8fdc4 + dd3237c commit bd5606b
Show file tree
Hide file tree
Showing 18 changed files with 133 additions and 117 deletions.
2 changes: 2 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Metrics/LineLength:
Max: 99
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# encoding: UTF-8
source 'https://rubygems.org'

gem 'berkshelf'
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ wildfly_deploy 'my-app-1.0.war' do
end
```

Example 4 undeploy
Example 4 undeploy (use :disable to keep the contents, and :enable to re-deploy previously kept contents)
```ruby
wildfly_deploy 'jboss.jdbc-driver.sqljdbc4_jar' do
action :remove
Expand Down
33 changes: 16 additions & 17 deletions Vagrantfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
# encoding: UTF-8
# -*- mode: ruby -*-
# vi: set ft=ruby :

# Set the default provider to VMware Workstation
ENV['VAGRANT_DEFAULT_PROVIDER'] = 'vmware_workstation'

Vagrant.configure("2") do |config|
Vagrant.configure('2') do |config|
# All Vagrant configuration is done here. The most common configuration
# options are documented and commented below. For a complete reference,
# please see the online documentation at vagrantup.com.

config.vm.hostname = "chef-wildfly-berkshelf"
config.vm.hostname = 'chef-wildfly-berkshelf'

# Every Vagrant virtual environment requires a box to build off of.
config.vm.box = "CentOS6.5_x64"
config.vm.box = 'CentOS6.5_x64'

# The url from where the 'config.vm.box' box will be fetched if it
# doesn't already exist on the user's system.
Expand All @@ -37,8 +38,6 @@ Vagrant.configure("2") do |config|

config.vm.network :public_network



# Share an additional folder to the guest VM. The first argument is
# the path on the host to the actual folder. The second argument is
# the path on the guest to mount the folder. And the optional third
Expand All @@ -60,11 +59,11 @@ Vagrant.configure("2") do |config|
# View the documentation for the provider you're using for more
# information on available options.

#config.ssh.max_tries = 40
#config.ssh.timeout = 120
# config.ssh.max_tries = 40
# config.ssh.timeout = 120

# The path to the Berksfile to use with Vagrant Berkshelf
config.berkshelf.berksfile_path = "./Berksfile"
config.berkshelf.berksfile_path = './Berksfile'

# Enabling the Berkshelf plugin. To enable this globally, add this configuration
# option to your ~/.vagrant.d/Vagrantfile file
Expand All @@ -81,20 +80,20 @@ Vagrant.configure("2") do |config|
config.vm.provision :chef_solo do |chef|
chef.log_level = :debug
chef.json = {
:mysql => {
:server_root_password => 'rootpass',
:server_debian_password => 'debpass',
:server_repl_password => 'replpass'
mysql: {
server_root_password: 'rootpass',
server_debian_password: 'debpass',
server_repl_password: 'replpass'
}
}

chef.run_list = [
"recipe[wildfly::default]"
'recipe[wildfly::default]'
]
end

config.vm.provider "vmware_workstation" do |v|
v.vmx["memsize"] = "4096"
v.vmx["numvcpus"] = "4"
config.vm.provider 'vmware_workstation' do |v|
v.vmx['memsize'] = '4096'
v.vmx['numvcpus'] = '4'
end
end
end
10 changes: 5 additions & 5 deletions attributes/java.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
#

# => Java Configuration
default['java']['install_flavor'] = 'oracle'
default['java']['oracle']['accept_oracle_download_terms'] = true
default['java']['jdk_version'] = '7'
default['java']['jdk']['7']['x86_64']['url'] = 'http://download.oracle.com/otn-pub/java/jdk/7u67-b01/jdk-7u67-linux-x64.tar.gz'
default['java']['jdk']['7']['x86_64']['checksum'] = '54dd1e13edf18c64941a55da9c91210b53dc5cf48f1a8f4538c863049e346335'
default['java']['install_flavor'] = 'oracle'
default['java']['oracle']['accept_oracle_download_terms'] = true
default['java']['jdk_version'] = '7'
default['java']['jdk']['7']['x86_64']['url'] = 'http://download.oracle.com/otn-pub/java/jdk/7u67-b01/jdk-7u67-linux-x64.tar.gz'
default['java']['jdk']['7']['x86_64']['checksum'] = '54dd1e13edf18c64941a55da9c91210b53dc5cf48f1a8f4538c863049e346335'
6 changes: 3 additions & 3 deletions attributes/system_properties.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
# => Simply add properties to this array of hashes

default['wildfly']['system_properties'] = [
# { name: 'JdbcUrl', value: 'jdbc:mysql://12.34.56.78:3306/testdb' },
# { name: 'JdbcUsername', value: 'testuser' },
# { name: 'JdbcPassword', value: 'testpass' }
# { name: 'JdbcUrl', value: 'jdbc:mysql://12.34.56.78:3306/testdb' },
# { name: 'JdbcUsername', value: 'testuser' },
# { name: 'JdbcPassword', value: 'testpass' }
]
2 changes: 1 addition & 1 deletion metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
license 'Apache License, Version 2.0'
description 'Installs/Configures wildfly'
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
version '0.1.11'
version '0.1.12'

supports 'centos'

Expand Down
14 changes: 5 additions & 9 deletions providers/attribute.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#

require 'etc'
include Chef::Mixin::ShellOut

# Support whyrun
def whyrun_supported?
Expand Down Expand Up @@ -56,16 +57,11 @@ def load_current_resource
private

def attribute_exists?
`su #{node['wildfly']['user']} -c "#{node['wildfly']['base']}/bin/jboss-cli.sh -c '#{current_resource.path}:read-attribute(name=#{current_resource.parameter})' | grep ' #{current_resource.value}'"`
$?.exitstatus == 0
result = shell_out("bin/jboss-cli.sh -c '#{current_resource.path}:read-attribute(name=#{current_resource.parameter})'", user: node['wildfly']['user'], cwd: node['wildfly']['base'])
result.stdout.include? " #{current_resource.value}"
end

def attribute_set
bash 'attribute_set' do
user node['wildfly']['user']
cwd node['wildfly']['base']
code <<-EOH
bin/jboss-cli.sh -c "#{current_resource.path}:write-attribute(name=#{current_resource.parameter},value=#{current_resource.value})"
EOH
end
result = shell_out("bin/jboss-cli.sh -c '#{current_resource.path}:write-attribute(name=#{current_resource.parameter},value=#{current_resource.value})'", user: node['wildfly']['user'], cwd: node['wildfly']['base'])
result.exitstatus == 0
end
6 changes: 2 additions & 4 deletions providers/datasource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,8 @@ def load_current_resource
@current_resource.jndiname(@new_resource.jndiname)
@current_resource.drivername(@new_resource.drivername)
@current_resource.connectionurl(@new_resource.connectionurl)
if datasource_exists?(@current_resource.name)
# TODO: Set @current_resource port properties from command output
@current_resource.exists = true
end
@current_resource.exists = true if datasource_exists?(@current_resource.name)
# TODO: Set @current_resource port properties from command output
end

private
Expand Down
101 changes: 67 additions & 34 deletions providers/deploy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,50 @@ def whyrun_supported?
end

action :install do
if deploy_exists?(@current_resource.runtime_name)
if runtime_exists?
Chef::Log.info "#{ @new_resource.runtime_name } already exists"
if deploy_name_exists?(@current_resource.runtime_name, @current_resource.name)
if deploy_exists?
Chef::Log.info "#{ @new_resource.name } already enabled - nothing to do."
else
Chef::Log.info "#{ @new_resource.name } is not the active resource."
deploy_remove(@current_resource.runtime_name)
deploy_install(@current_resource.name, @current_resource.runtime_name)
deploy_remove(@current_resource.runtime_name, false)
read_deployment_details(true)
deploy_install(@current_resource.cli, @current_resource.name, @current_resource.runtime_name)
end
else
deploy_install(@current_resource.name, @current_resource.runtime_name)
deploy_install(@current_resource.cli, @current_resource.name, @current_resource.runtime_name)
end
end

action :remove do
if deploy_exists?(@current_resource.runtime_name)
deploy_remove(@current_resource.runtime_name)
if runtime_exists?
deploy_remove(@current_resource.runtime_name, false)
else
Chef::Log.info "#{ @new_resource.runtime_name } does not exist - nothing to do."
end
end

action :enable do
if runtime_exists?
Chef::Log.info "#{ @new_resource.runtime_name } already exists"
if deploy_exists?
if deploy_enabled?(@current_resource.name)
Chef::Log.info "#{ @new_resource.name } resource is already enabled."
else
Chef::Log.info "#{ @new_resource.name } activating previously loaded resource."
deploy_install('', @current_resource.name, @current_resource.runtime_name)
end
else
Chef::Log.info "#{ @new_resource.name } resource does not exist yet, cannot enable."
end
else
Chef::Log.info "#{ @new_resource.runtime_name } resource does not exist yet, cannot enable."
end
end

action :disable do
if runtime_exists?
deploy_remove(@current_resource.runtime_name, true)
else
Chef::Log.info "#{ @new_resource.runtime_name } does not exist - nothing to do."
end
Expand All @@ -50,66 +77,72 @@ def whyrun_supported?
def load_current_resource
@current_resource = Chef::Resource::WildflyDeploy.new(@new_resource.name)
@current_resource.name(@new_resource.name)
@current_resource.runtime_name( @new_resource.runtime_name == 'noname' ? @new_resource.name : @new_resource.runtime_name )
@current_resource.runtime_name(@new_resource.runtime_name == 'noname' ? @new_resource.name : @new_resource.runtime_name)
@current_resource.path(@new_resource.path)
@current_resource.url(@new_resource.url)
@current_resource.exists = false
@current_resource.cli(" #{@new_resource.path}")
@current_resource.exists = true if deploy_exists?(@current_resource.name)
@current_resource.exists = true if runtime_exists?
@current_resource.cli("--url=#{@new_resource.url}") if @current_resource.url != 'nourl'
end

private

def deploy_exists?(runtime_name)
return read_deployment_details.has_key?(runtime_name)
def runtime_exists?
read_deployment_details.key?(@current_resource.runtime_name)
end

def deploy_exists?
read_deployment_details[@current_resource.runtime_name].any? { |h| h[@current_resource.name] }
end

def deploy_name_exists?(runtime_name, name)
return read_deployment_details[runtime_name].any? { |h| h[name] }
def deploy_enabled?(name)
read_deployment_details[@current_resource.runtime_name].any? { |h| h[name]['enabled'] }
end

def deploy_install(name, runtime_name)
def deploy_install(source, name, runtime_name)
Chef::Log.info "Deploying #{name}"
converge_by("Deploying #{ detailed_name(runtime_name,name) }") do
result = shell_out("bin/jboss-cli.sh -c ' deploy #{current_resource.cli} --name=#{name} --runtime-name=#{runtime_name}'", :user => node['wildfly']['user'], :cwd => node['wildfly']['base'])
converge_by((source == '' ? 'Enabling' : 'Deploying') + " #{ detailed_name(runtime_name, name) }") do
result = shell_out("bin/jboss-cli.sh -c ' deploy #{source} --name=#{name} --runtime-name=#{runtime_name}'", user: node['wildfly']['user'], cwd: node['wildfly']['base'])
result.error! if result.exitstatus != 0
end
return true
true
end

def deploy_remove(runtime_name)
def deploy_remove(runtime_name, keep_content = false)
deployments = read_deployment_details
deployments[runtime_name].each do | deployed |
converge_by("Removing #{ detailed_name(runtime_name, deployed.keys.first) }") do
Chef::Log.info "Undeploying #{detailed_name(runtime_name, deployed.keys.first)}"
Chef::Log.info "Undeploying #{deployed.keys.first} with runtime name #{runtime_name}"
result = shell_out("bin/jboss-cli.sh -c ' undeploy #{deployed.keys.first}'", :user => node['wildfly']['user'], :cwd => node['wildfly']['base'])
result.error! if result.exitstatus != 0
converge_by((keep_content ? 'Disabling' : 'Removing') + " #{ detailed_name(runtime_name, deployed.keys.first) }") do
Chef::Log.info 'Undeploying #{detailed_name(runtime_name, deployed.keys.first)}'
result = shell_out("bin/jboss-cli.sh -c ' undeploy #{deployed.keys.first} #{keep_content ? '--keep-content' : ''}'", user: node['wildfly']['user'], cwd: node['wildfly']['base'])
result.error! if result.exitstatus != 0
end
end
return true
true
end

def read_deployment_details
Chef::Log.info "Getting list of deployed applications"
data = shell_out("bin/jboss-cli.sh -c ' deployment-info '", :user => node['wildfly']['user'], :cwd => node['wildfly']['base'])
return format_output(data.stdout)
def read_deployment_details(refresh = false)
if !@deployment_details || refresh
Chef::Log.info 'Getting list of deployed applications'
data = shell_out("bin/jboss-cli.sh -c ' deployment-info '", user: node['wildfly']['user'], cwd: node['wildfly']['base'])
@deployment_details = format_output(data.stdout)
end
@deployment_details
end

def detailed_name(runtime_name,name)
return runtime_name==name ? "#{runtime_name}" : "#{runtime_name} (#{name})"
def detailed_name(runtime_name, name)
runtime_name == name ? runtime_name : "#{runtime_name} (#{name})"
end

def format_output(data)
result = {}
data.split(/\n/).each do | item |
output = item.split(/\s+/)
if result.has_key?(output[1])
result[output[1]] << { output[0] => { :persistent => output[2], :enabled => output[3], :status => output[4] } }
if result.key?(output[1])
result[output[1]] << { output[0] => { persistent: output[2], enabled: output[3], status: output[4] } }
else
result = { output[1] => [ output[0] => { :persistent => output[2], :enabled => output[3], :status => output[4] } ] }.merge(result)
result = { output[1] => [output[0] => { persistent: output[2], enabled: output[3], status: output[4] }] }.merge(result)
end
end
return result
result
end
14 changes: 5 additions & 9 deletions providers/logcategory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,9 @@ def load_current_resource
@current_resource.name(@new_resource.name)
@current_resource.use_parent_handlers(@new_resource.use_parent_handlers)
@current_resource.level(@new_resource.level)
# @current_resource.handlers(@new_resource.handlers)
if logcategory_exists?(@current_resource.name)
# TODO: Set @current_resource port properties from command output
@current_resource.exists = true
end
# @current_resource.handlers(@new_resource.handlers)
@current_resource.exists = true if logcategory_exists?(@current_resource.name)
# TODO: Set @current_resource port properties from command output
end

private
Expand All @@ -65,11 +63,9 @@ def logcategory_exists?(name)
def create_logcategory
handlers = '['
unless new_resource.handlers.nil? || new_resource.handlers.empty?
new_resource.handlers.each_with_index do |item, index|
new_resource.handlers.each_with_index do |_item, index|
handlers += '"' + new_resource.handlers[index] + '"'
if new_resource.handlers.length-1 != index
handlers += ', '
end
handlers += ', ' if new_resource.handlers.length - 1 != index
end
end
handlers += ']'
Expand Down
4 changes: 1 addition & 3 deletions providers/loghandler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ def whyrun_supported?
end

def load_current_resource
if loghandler_exists?(@new_resource.name)
@current_resource_exists = true
end
@current_resource_exists = true if loghandler_exists?(@new_resource.name)
end

private
Expand Down
Loading

0 comments on commit bd5606b

Please sign in to comment.