Skip to content

Commit

Permalink
Fix many of the rubocop / foodcritic errors
Browse files Browse the repository at this point in the history
  • Loading branch information
rdoorn committed Sep 11, 2014
1 parent b3b91e3 commit d3b0d2d
Show file tree
Hide file tree
Showing 16 changed files with 85 additions and 103 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
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 @@ -10,6 +10,6 @@

supports 'centos'

supports 'apt'
depends 'apt'
depends 'yum'
depends 'java', '~> 1.22'
15 changes: 6 additions & 9 deletions providers/attribute.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,13 @@ 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
#`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
45 changes: 22 additions & 23 deletions providers/deploy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def whyrun_supported?
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)
deploy_install('', @current_resource.name, @current_resource.runtime_name)
end
else
Chef::Log.info "#{ @new_resource.name } resource does not exist yet, cannot enable."
Expand All @@ -77,7 +77,7 @@ 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
Expand All @@ -89,61 +89,60 @@ def load_current_resource
private

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

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

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

def deploy_install(source, name, runtime_name)
Chef::Log.info "Deploying #{name}"
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'])
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, keep_content = false)
deployments = read_deployment_details
deployments[runtime_name].each do | deployed |
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)}"
Chef::Log.info "Undeploying #{deployed.keys.first} with runtime name #{runtime_name}"
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
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(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'])
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
return @deployment_details
@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
32 changes: 12 additions & 20 deletions providers/property.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

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

# Support whyrun
def whyrun_supported?
Expand Down Expand Up @@ -66,34 +67,25 @@ def notify?
end

def property_value_exists?
`su #{node['wildfly']['user']} -c "#{node['wildfly']['base']}/bin/jboss-cli.sh -c '/system-property=#{current_resource.property}:read-attribute(name=value)'"`.include? " \"#{current_resource.value}\""
result = shell_out("bin/jboss-cli.sh -c '/system-property=#{current_resource.property}:read-attribute(name=value)'", user: node['wildfly']['user'], cwd: node['wildfly']['base'])
result.stdout.include? " \"#{current_resource.value}\""
end

def property_exists?
`su #{node['wildfly']['user']} -c "#{node['wildfly']['base']}/bin/jboss-cli.sh -c '/system-property=#{current_resource.property}:read-resource' >/dev/null"`
$?.exitstatus == 0
result = shell_out("bin/jboss-cli.sh -c '/system-property=#{current_resource.property}:read-resource'", user: node['wildfly']['user'], cwd: node['wildfly']['base'])
result.exitstatus == 0
end

def property_set
bash 'property_set' do
user node['wildfly']['user']
cwd node['wildfly']['base']
code <<-EOH
if $(bin/jboss-cli.sh -c '/system-property=#{current_resource.property}:read-resource' >/dev/null); then
bin/jboss-cli.sh -c "/system-property=#{current_resource.property}:write-attribute(name=value,value=#{Shellwords.escape(current_resource.value)})"
else
bin/jboss-cli.sh -c "/system-property=#{current_resource.property}:add(value=#{Shellwords.escape(current_resource.value)})"
fi
EOH
if property_exists?
result = shell_out("bin/jboss-cli.sh -c '/system-property=#{current_resource.property}:write-attribute(name=value,value=#{Shellwords.escape(current_resource.value)})'", user: node['wildfly']['user'], cwd: node['wildfly']['base'])
else
result = shell_out("bin/jboss-cli.sh -c '/system-property=#{current_resource.property}:add(value=#{Shellwords.escape(current_resource.value)})'", user: node['wildfly']['user'], cwd: node['wildfly']['base'])
end
result.exitstatus == 0
end

def property_delete
bash 'property_delete' do
user node['wildfly']['user']
cwd node['wildfly']['base']
code <<-EOH
bin/jboss-cli.sh -c "/system-property=#{current_resource.property}:remove()"
EOH
end
result = shell_out("bin/jboss-cli.sh -c '/system-property=#{current_resource.property}:remove()'", user: node['wildfly']['user'], cwd: node['wildfly']['base'])
result.exitstatus == 0
end
2 changes: 1 addition & 1 deletion recipes/mysql_datasources.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
mysql = node['wildfly']['mysql']

mysql['jndi']['datasources'].each do |source|
# => Configure MySQL Datasource
# => Configure MySQL Datasource
template ::File.join(wildfly['base'], 'standalone', 'deployments', "#{::File.basename(source['jndi_name'])}-ds.xml") do
source 'mysql-ds.xml.erb'
user wildfly['user']
Expand Down
12 changes: 6 additions & 6 deletions resources/loghandler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@

attribute :name, :kind_of => String, :required => true, :name_attribute => true
attribute :type, :kind_of => String, :required => true
attribute :hostname, :kind_of => String, :default => "localhost"
attribute :server_address, :kind_of => String, :default => "localhost"
attribute :port, :kind_of => String, :default => "514"
attribute :level, :kind_of => String, :default => "ALL"
attribute :syslog_format, :kind_of => String, :default => "RFC5424"
attribute :enabled, :kind_of => String, :default => "true"
attribute :hostname, :kind_of => String, :default => 'localhost'
attribute :server_address, :kind_of => String, :default => 'localhost'
attribute :port, :kind_of => String, :default => '514'
attribute :level, :kind_of => String, :default => 'ALL'
attribute :syslog_format, :kind_of => String, :default => 'RFC5424'
attribute :enabled, :kind_of => String, :default => 'true'
attribute :app_name, :kind_of => String, :required => true

attr_accessor :exists
2 changes: 1 addition & 1 deletion resources/property.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@
attribute :value, :kind_of => String
attribute :restart, :kind_of => [TrueClass, FalseClass], :default => true

attr_accessor :exists
attr_accessor :exists
2 changes: 1 addition & 1 deletion templates/default/standalone-full-ha-aws.xml.erb
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@
<transport type="TCP" socket-binding="jgroups-tcp"/>
<protocol type="TCPPING">
<property name="initial_hosts">
<%= node[:fqdn] %>[7600]
<%= node['fqdn'] %>[7600]
</property>
<property name="port_range">
0
Expand Down

0 comments on commit d3b0d2d

Please sign in to comment.