Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a60422e

Browse files
author
Joshua Timberman
committed
Merge pull request poise#1 from jcam/master
COOK-1680 application_java: deploy action missing from java_remote_file resource
2 parents 43cf049 + 0e46daa commit a60422e

File tree

9 files changed

+162
-13
lines changed

9 files changed

+162
-13
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
## v1.0.2:
2+
3+
* Support deploying local files
4+
5+
## v1.0.1:
6+
7+
* [COOK-1680] - Add deploy action (alias for create) to java_remote_file
8+
19
## v1.0.0:
210

311
* [COOK-1243] - Initial release - relates to COOK-634.

README.md

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ The LWRPs provided by this cookbook are not meant to be used by themselves; make
2929
java_webapp
3030
-----------
3131

32-
The `java_webapp` sub-resource LWRP deals with deploying Java webapps delivered as WAR files which will be retrieved from a remote URL.
32+
The `java_webapp` sub-resource LWRP deals with deploying Java webapps delivered as WAR files which will either be retrieved from a remote URL or fetched by some other method and referenced locally.
3333

3434
NOTICE: the `application` cookbook was designed around frameworks running on interpreted languages that are deployed in source code, checked out of an SCM using the `deploy_revision` resource. While this cookbook tries to map those concepts to a binary distribution mechanism, it may not map exactly.
3535

@@ -60,6 +60,19 @@ tomcat
6060

6161
The `tomcat` sub-resource LWRP configures Tomcat to run the application by creating a symbolic link to the context file.
6262

63+
Attributes
64+
==========
65+
66+
strategy: required to be one of
67+
:java_remote_file allows downloading from a remote http url
68+
:java_local_file allows using a package on the filesystem
69+
path: the target location for the application distribution. This should be outside of the tomcat deployment tree.
70+
repository:
71+
- java_remote_file uses repository as the remote URL
72+
- java_local_file uses repository as the source file location on the disk
73+
revision: name of the war file on disk, should change with each new version
74+
75+
6376
Usage
6477
=====
6578

@@ -69,6 +82,7 @@ A sample application that needs a database connection:
6982
path "/usr/local/my-app"
7083
repository "..."
7184
revision "..."
85+
strategy :java_local_file
7286

7387
java_webapp do
7488
database_master_role "database_master"
@@ -96,6 +110,7 @@ context file for other reasons), you can specify your own template:
96110
group node["tomcat"]["group"]
97111
repository "http://mirrors.jenkins-ci.org/war/latest/jenkins.war"
98112
revision "6facd94e958ecf68ffd28be371b5efcb5584c885b5f32a906e477f5f62bdb518-1"
113+
strategy :java_remote_file
99114

100115
java_webapp do
101116
context_template "jenkins-context.xml.erb"
@@ -132,7 +147,8 @@ License and Author
132147
==================
133148

134149
Author:: Adam Jacob (<[email protected]>)
135-
Author:: Andrea Campi (<[email protected]>)
150+
Author:: Andrea Campi (<[email protected]>)
151+
Author:: Jesse Campbell (<[email protected]>)
136152
Author:: Joshua Timberman (<[email protected]>)
137153
Author:: Seth Chisamore (<[email protected]>)
138154

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#
2+
# Cookbook Name:: application_java
3+
# Library:: provider_java_local_file
4+
#
5+
# Copyright 2012, ZephirWorks
6+
#
7+
# Licensed under the Apache License, Version 2.0 (the "License");
8+
# you may not use this file except in compliance with the License.
9+
# You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS,
15+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
# See the License for the specific language governing permissions and
17+
# limitations under the License.
18+
#
19+
20+
require 'chef/provider/file'
21+
22+
class Chef
23+
class Provider
24+
class File
25+
class JavaLocalFile < Chef::Provider::File
26+
27+
def load_current_resource
28+
@new_resource.path @new_resource.release_path
29+
super
30+
end
31+
32+
def action_deploy
33+
action_create
34+
end
35+
36+
def action_force_deploy
37+
action_create
38+
end
39+
40+
def set_content
41+
unless compare_content
42+
backup @new_resource.path if ::File.exists?(@new_resource.path)
43+
::FileUtils.cp_r(@new_resource.content, @new_resource.path)
44+
Chef::Log.info("#{@new_resource.content} copied to #{@new_resource.path}")
45+
@new_resource.updated_by_last_action(true)
46+
end
47+
end
48+
49+
def compare_content
50+
checksum(@current_resource.path) == checksum(@new_resource.content)
51+
end
52+
end
53+
end
54+
end
55+
end

libraries/provider_java_remote_file.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ def load_current_resource
2828
super
2929
end
3030

31+
def action_deploy
32+
action_create
33+
end
34+
35+
def action_force_deploy
36+
action_create
37+
end
38+
3139
end
3240
end
3341
end
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#
2+
# Cookbook Name:: application_java
3+
# Library:: resource_java_local_file
4+
#
5+
# Copyright 2012, ZephirWorks
6+
#
7+
# Licensed under the Apache License, Version 2.0 (the "License");
8+
# you may not use this file except in compliance with the License.
9+
# You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS,
15+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
# See the License for the specific language governing permissions and
17+
# limitations under the License.
18+
#
19+
20+
require 'chef/resource/file'
21+
22+
class Chef
23+
class Resource
24+
class JavaLocalFile < Chef::Resource::File
25+
26+
alias :user :owner
27+
alias :repository :content
28+
29+
def initialize(name, run_context=nil)
30+
super
31+
@resource_name = :java_local_file
32+
@provider = Chef::Provider::File::JavaLocalFile
33+
@deploy_to = nil
34+
@allowed_actions.push(:deploy,:force_deploy)
35+
end
36+
37+
def provider
38+
Chef::Provider::File::JavaLocalFile
39+
end
40+
41+
def deploy_to(args=nil)
42+
set_or_return(
43+
:deploy_to,
44+
args,
45+
:kind_of => String
46+
)
47+
end
48+
49+
def revision(arg=nil)
50+
set_or_return(
51+
:checksum,
52+
arg,
53+
:kind_of => String
54+
)
55+
end
56+
57+
def release_path
58+
@release_path ||= @deploy_to + "/releases/#{revision}.war"
59+
end
60+
61+
def method_missing(name, *args, &block)
62+
Chef::Log.info "java_local_file missing(#{name}, #{args.inspect}), ignoring it"
63+
end
64+
65+
end
66+
end
67+
end

libraries/resource_java_remote_file.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ def initialize(name, run_context=nil)
3232
@resource_name = :java_remote_file
3333
@provider = Chef::Provider::JavaRemoteFile
3434
@deploy_to = nil
35+
@allowed_actions.push(:deploy,:force_deploy)
3536
end
3637

3738
def provider

metadata.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
license "Apache 2.0"
55
description "Deploys and configures Java-based applications"
66
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
7-
version "1.0.0"
7+
version "1.0.2"
88

99
%w{ application java tomcat }.each do |cb|
1010
depends cb

providers/java_webapp.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@
2020
include Chef::Mixin::LanguageIncludeRecipe
2121

2222
action :before_compile do
23-
24-
# include_recipe 'java'
25-
26-
new_resource.strategy :java_remote_file
2723
end
2824

2925
action :before_deploy do

providers/tomcat.rb

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,16 @@
4343
not_if "test -L #{node['tomcat']['context_dir']}/ROOT.xml"
4444
end
4545

46+
link "#{node['tomcat']['context_dir']}/#{new_resource.application.name}.xml" do
47+
to "#{new_resource.application.path}/shared/#{new_resource.application.name}.xml"
48+
notifies :restart, resources(:service => "tomcat")
49+
end
4650
end
4751

4852
action :before_migrate do
4953
end
5054

5155
action :before_symlink do
52-
53-
link "#{node['tomcat']['context_dir']}/ROOT.xml" do
54-
to "#{new_resource.application.path}/shared/#{new_resource.application.name}.xml"
55-
notifies :restart, resources(:service => "tomcat")
56-
end
57-
5856
end
5957

6058
action :before_restart do

0 commit comments

Comments
 (0)