Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add undeploy_first parameter to wildfly_deployment #259

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/puppet/provider/wildfly_deployment/http_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ def content

def content=(value)
debug "Updating deploy #{@resource[:name]} with content from #{@resource[:source]}"
cli.update_deploy(@resource[:name], @resource[:source], @resource[:server_group], @resource[:operation_headers])
if @resource[:undeploy_first]
destroy
create
else
cli.update_deploy(@resource[:name], @resource[:source], @resource[:server_group], @resource[:operation_headers])
end
end

def server_group_address
Expand Down
8 changes: 7 additions & 1 deletion lib/puppet/type/wildfly_deployment.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'digest'
require 'puppet/parameter/boolean'

Puppet::Type.newtype(:wildfly_deployment) do
desc 'Manages JBoss deployment'
Expand Down Expand Up @@ -39,7 +40,7 @@
end

newparam(:timeout) do
desc 'Operation timeout. Defaults to 120'
desc 'Operation timeout. Defaults to 300'
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Completely unrelated, but now the desc matches the defaultto below.

defaultto 300

munge(&:to_i)
Expand All @@ -54,6 +55,11 @@
end
end

newparam(:undeploy_first, :boolean => true, :parent => Puppet::Parameter::Boolean) do
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Naming things is hard! undeploy_first was the best I came up with. Open to suggestions. :)

desc 'Whether to perform an undeploy before redeploying'
defaultto :false # rubocop:disable Lint/BooleanSymbol
end

newproperty(:content) do
desc 'SHA1 of deployed content'
defaultto ''
Expand Down
19 changes: 11 additions & 8 deletions manifests/deployment.pp
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,18 @@
# @param password The password for Wildfly's management user.
# @param host The IP address or FQDN of the JBoss Management service.
# @param port The port of the JBoss Management service.
# @param undeploy_first Instead of 'updating' a deployment, should the existing deployment be undeployed and then redeployed?
define wildfly::deployment(
Variant[Pattern[/^file:\/\//], Pattern[/^puppet:\/\//], Stdlib::Httpsurl, Stdlib::Httpurl] $source,
Enum[present, absent] $ensure = present,
Optional[Integer] $timeout = undef,
Optional[String] $server_group = undef,
$operation_headers = {},
String $username = $wildfly::mgmt_user['username'],
String $password = $wildfly::mgmt_user['password'],
String $host = $wildfly::properties['jboss.bind.address.management'],
String $port = $wildfly::properties['jboss.management.http.port'],
Enum[present, absent] $ensure = present,
Optional[Integer] $timeout = undef,
Optional[String] $server_group = undef,
$operation_headers = {},
String $username = $wildfly::mgmt_user['username'],
String $password = $wildfly::mgmt_user['password'],
String $host = $wildfly::properties['jboss.bind.address.management'],
String $port = $wildfly::properties['jboss.management.http.port'],
Optional[Boolean] $undeploy_first = undef,
) {
$file_name = basename($source)

Expand All @@ -42,6 +44,7 @@
timeout => $timeout,
source => "${wildfly::deploy_cache_dir}/${file_name}",
operation_headers => $operation_headers,
undeploy_first => $undeploy_first,
require => [Service['wildfly'], File["${wildfly::deploy_cache_dir}/${file_name}"]],
}

Expand Down
4 changes: 2 additions & 2 deletions spec/types/wildfly_deployment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
end

it 'has expected parameters' do
expect(deployment.parameters).to include(:name, :source, :server_group, :username, :password, :host, :port, :timeout, :operation_headers)
expect(deployment.parameters).to include(:name, :source, :server_group, :username, :password, :host, :port, :timeout, :operation_headers, :undeploy_first)
end

describe 'when testing wheter content checksum is in sync' do
describe 'when testing whether content checksum is in sync' do
let(:resource) { described_class.new(:name => 'app.ear') }

it 'is if deployed content SHA1 checksum matches source checksum' do
Expand Down
45 changes: 45 additions & 0 deletions spec/unit/puppet/provider/wildfly_deployment/http_api_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
require 'spec_helper'

provider_class = Puppet::Type.type(:wildfly_deployment).provider(:http_api)

describe provider_class do
let :resource do
Puppet::Type.type(:wildfly_deployment).new(
:name => 'test.ear',
:source => '/tmp/test.ear',
:operation_headers => {},
:provider => :http_api)
end

let :provider do
resource.provider
end

describe 'content=' do
describe 'undeploy_first' do
context 'by default' do
it 'undeploy_first is false' do
expect(resource[:undeploy_first]).to be(false)
end
it 'calls `update_deploy`' do
expect(provider).not_to receive(:destroy)
expect(provider).not_to receive(:create)

cli = double
allow(provider).to receive(:cli).and_return(cli)

expect(provider.cli).to receive(:update_deploy).with('test.ear', '/tmp/test.ear', nil, {})
provider.content = 'unused'
end
end
context 'when undeploy_first => true' do
it 'calls `destroy` followed by `create`' do
resource[:undeploy_first] = true
expect(provider).to receive(:destroy).ordered
expect(provider).to receive(:create).ordered
provider.content = 'unused'
end
end
end
end
end