Skip to content

Commit 0386d13

Browse files
author
Dan Koepke
committed
WIP PHP agent as LWRP
1 parent a526e74 commit 0386d13

File tree

14 files changed

+388
-5
lines changed

14 files changed

+388
-5
lines changed

.kitchen.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,21 @@ suites:
9696
accesskey: controller-accesskey
9797
java_agent:
9898
source: http://10.0.72.177:10000/JavaAppAgent.zip
99+
- name: php_agent
100+
run_list:
101+
- recipe[apt::default]
102+
- recipe[php::default]
103+
- recipe[appdynamics::php_agent]
104+
attributes:
105+
appdynamics:
106+
app_name: test-app
107+
tier_name: test-tier
108+
node_name: test-node
109+
controller:
110+
host: controller-host
111+
port: 1234
112+
ssl: true
113+
user: controller-user
114+
accesskey: controller-accesskey
115+
php_agent:
116+
source: http://10.0.72.177:10000/appdynamics-php-agent.tar.bz2

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ gem 'chefspec'
55
gem 'rubocop'
66
gem 'rspec'
77
gem 'foodcritic'
8+
gem 'fauxhai'
89

910
group :dev do
1011
gem 'test-kitchen'

Gemfile.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ PLATFORMS
244244
DEPENDENCIES
245245
berkshelf
246246
chefspec
247+
fauxhai
247248
foodcritic
248249
kitchen-vagrant
249250
rspec

attributes/php_agent.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
default['appdynamics']['php_agent']['source'] = nil
2+
default['appdynamics']['php_agent']['owner'] = nil
3+
default['appdynamics']['php_agent']['group'] = nil
4+
default['appdynamics']['php_agent']['dest'] = '/opt/appdynamics'
5+
default['appdynamics']['php_agent']['checksum'] = nil

libraries/helpers.rb

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
module AppDynamicsCookbook
2+
module Helpers
3+
def platform(family, supported)
4+
plat = family
5+
6+
case family
7+
when 'mac_os_x'
8+
plat = 'osx'
9+
when 'GNU/Linux'
10+
plat = 'linux'
11+
end
12+
13+
raise "Unsupported OS family #{plat}" if supported and not supported.include? plat
14+
15+
plat
16+
end
17+
18+
def architecture(machine, supported)
19+
arch = machine
20+
21+
case arch
22+
when 'i386'
23+
arch = 'x86'
24+
when 'x86_64'
25+
arch = 'x64'
26+
end
27+
28+
raise "Unsupported CPU architecture" if supported and not supported.include? arch
29+
30+
arch
31+
end
32+
end
33+
end

libraries/matchers.rb

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#
2+
# Author:: Dan Koepke <[email protected]>
3+
# Cookbook Name:: appdynamics
4+
# Library:: ChefSpec matchers
5+
#
6+
# Copyright:: 2015, AppDynamics, Inc and its affiliates
7+
#
8+
# Licensed under the Apache License, Version 2.0 (the "License");
9+
# you may not use this file except in compliance with the License.
10+
# You may obtain a copy of the License at
11+
#
12+
# http://www.apache.org/licenses/LICENSE-2.0
13+
#
14+
# Unless required by applicable law or agreed to in writing, software
15+
# distributed under the License is distributed on an "AS IS" BASIS,
16+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
# See the License for the specific language governing permissions and
18+
# limitations under the License.
19+
#
20+
21+
if defined?(ChefSpec)
22+
ChefSpec.define_matcher :appdynamics_extract
23+
ChefSpec.define_matcher :appdynamics_php_agent
24+
25+
def run_appdynamics_extract(resource_name)
26+
ChefSpec::Matchers::ResourceMatcher.new(:appdynamics_extract, :run, resource_name)
27+
end
28+
29+
def install_appdynamics_php_agent(resource_name)
30+
ChefSpec::Matchers::ResourceMatcher.new(:appdynamics_php_agent, :install, resource_name)
31+
end
32+
end

metadata.rb

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
name 'appdynamics'
2-
version '0.0.0'
2+
version '0.2.0'
33

4-
depends 'windows'
5-
depends 'python'
6-
depends 'nodejs'
7-
depends 'java'
84
depends 'apt'
5+
depends 'java'
6+
depends 'nodejs'
7+
depends 'php'
8+
depends 'python'
9+
depends 'windows'

providers/extract.rb

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#
2+
# Author:: Dan Koepke <[email protected]>
3+
# Cookbook Name:: appdynamics
4+
# Provider:: extract
5+
#
6+
# Copyright:: 2015, AppDynamics, Inc and its affiliates
7+
#
8+
# Licensed under the Apache License, Version 2.0 (the "License");
9+
# you may not use this file except in compliance with the License.
10+
# You may obtain a copy of the License at
11+
#
12+
# http://www.apache.org/licenses/LICENSE-2.0
13+
#
14+
# Unless required by applicable law or agreed to in writing, software
15+
# distributed under the License is distributed on an "AS IS" BASIS,
16+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
# See the License for the specific language governing permissions and
18+
# limitations under the License.
19+
#
20+
21+
commands = { :zip => ['unzip', '-qq'], :tar_bz2 => ['tar', 'xjf'], :tar_gz => ['tar', 'xzf'] }
22+
23+
def whyrun_supported?
24+
true
25+
end
26+
27+
use_inline_resources
28+
29+
action :run do
30+
tmp_dest = "#{Chef::Config[:file_cache_path]}/#{new_resource.name}"
31+
32+
install_type = new_resource.type || guess_type(new_resource.basename)
33+
package 'unzip' if install_type == :zip
34+
35+
raise "Unsupported type #{install_type}" if commands[install_type].nil?
36+
install_command = commands[install_type] + [tmp_dest]
37+
38+
directory "#{new_resource.name} :create #{new_resource.dest}" do
39+
recursive true
40+
path new_resource.dest
41+
owner new_resource.owner unless new_resource.owner.nil?
42+
group new_resource.group unless new_resource.group.nil?
43+
mode '0644'
44+
end
45+
46+
remote_file "#{new_resource.name} :create #{tmp_dest}" do
47+
source new_resource.source
48+
path tmp_dest
49+
owner new_resource.owner unless new_resource.owner.nil?
50+
group new_resource.group unless new_resource.group.nil?
51+
checksum new_resource.checksum unless new_resource.checksum.nil?
52+
notifies :run, "execute[#{new_resource.name} :run extract]", :immediately
53+
end
54+
55+
new_resource.updated_by_last_action(true)
56+
57+
execute "#{new_resource.name} :run extract" do
58+
action :nothing
59+
60+
command install_command
61+
cwd new_resource.dest
62+
user new_resource.owner unless new_resource.owner.nil?
63+
group new_resource.group unless new_resource.group.nil?
64+
end
65+
66+
new_resource.updated_by_last_action(true)
67+
end
68+
69+
def guess_type(name)
70+
if name.end_with? '.zip'
71+
return :zip
72+
elsif name.end_with? '.tar.bz2'
73+
return :tar_bz2
74+
elsif name.end_with? '.tar.gz'
75+
return :tar_gz
76+
end
77+
raise "Cannot guess archive type, please specify 'type' attribute"
78+
end

providers/php_agent.rb

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#
2+
# Author:: Dan Koepke <[email protected]>
3+
# Cookbook Name:: appdynamics
4+
# Provider:: php_agent
5+
#
6+
# Copyright:: 2015, AppDynamics, Inc and its affiliates
7+
#
8+
# Licensed under the Apache License, Version 2.0 (the "License");
9+
# you may not use this file except in compliance with the License.
10+
# You may obtain a copy of the License at
11+
#
12+
# http://www.apache.org/licenses/LICENSE-2.0
13+
#
14+
# Unless required by applicable law or agreed to in writing, software
15+
# distributed under the License is distributed on an "AS IS" BASIS,
16+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
# See the License for the specific language governing permissions and
18+
# limitations under the License.
19+
#
20+
21+
require_relative '../libraries/helpers'
22+
include AppDynamicsCookbook::Helpers
23+
24+
def whyrun_supported?
25+
true
26+
end
27+
28+
use_inline_resources
29+
30+
action :install do
31+
version = new_resource.version
32+
tarball_source = new_resource.source || default_source(version)
33+
34+
appdynamics_extract "#{new_resource.name} :run extract" do
35+
basename "appdynamics-php-agent-#{version}.tar.bz2"
36+
type :tar_bz2
37+
source tarball_source
38+
dest new_resource.dest
39+
owner new_resource.owner unless new_resource.owner.nil?
40+
group new_resource.group unless new_resource.group.nil?
41+
notifies :run, "execute[#{new_resource.name} :run install.sh]", :immediately
42+
end
43+
44+
new_resource.updated_by_last_action(true)
45+
46+
install_command = ["./install.sh"]
47+
install_command << '-s' if new_resource.controller_ssl
48+
install_command << "-a=#{new_resource.account}@#{new_resource.accesskey}"
49+
install_command << "--http-proxy-host=#{new_resoure.http_proxy_host}" if new_resource.http_proxy_host
50+
install_command << "--http-proxy-port=#{new_resoure.http_proxy_port}" if new_resource.http_proxy_port
51+
install_command << "--http-proxy-user=#{new_resoure.http_proxy_user}" if new_resource.http_proxy_user
52+
install_command << "--http-proxy-password-file=#{new_resoure.http_proxy_password_file}" if new_resource.http_proxy_password_file
53+
install_command << "#{new_resource.controller_host} #{new_resource.controller_port}"
54+
install_command << "#{new_resource.app_name} #{new_resource.tier_name} #{new_resource.node_name}"
55+
56+
execute "#{new_resource.name} :run install.sh" do
57+
action :nothing
58+
command install_command
59+
cwd "#{new_resource.dest}/appdynamics-php-agent"
60+
user new_resource.owner unless new_resource.owner.nil?
61+
group new_resource.group unless new_resource.group.nil?
62+
end
63+
64+
new_resource.updated_by_last_action(true)
65+
end
66+
67+
def default_source(version)
68+
plat = platform(node['kernel']['os'], %w(linux osx))
69+
arch = architecture(node['kernel']['machine'], %w(x86 x64))
70+
"https://packages.appdynamics.com/#{version}/php/appdynamics-php-agent-#{plat}-#{arch}-#{version}.tar.bz2"
71+
end

recipes/php_agent.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
appdynamics_php_agent node['appdynamics']['node_name'] do
2+
version node['appdynamics']['php_agent']['version']
3+
source node['appdynamics']['php_agent']['source']
4+
dest node['appdynamics']['php_agent']['dest']
5+
6+
app_name node['appdynamics']['app_name']
7+
tier_name node['appdynamics']['tier_name']
8+
9+
controller_host node['appdynamics']['controller']['host']
10+
controller_port node['appdynamics']['controller']['port']
11+
controller_ssl node['appdynamics']['controller']['ssl']
12+
account node['appdynamics']['controller']['user']
13+
accesskey node['appdynamics']['controller']['accesskey']
14+
15+
http_proxy_host node['appdynamics']['http_proxy']['host']
16+
http_proxy_port node['appdynamics']['http_proxy']['port']
17+
http_proxy_user node['appdynamics']['http_proxy']['user']
18+
http_proxy_password_file node['appdynamics']['http_proxy']['password_file']
19+
20+
dest node['appdynamics']['php_agent']['dest']
21+
owner node['appdynamics']['php_agent']['owner']
22+
group node['appdynamics']['php_agent']['group']
23+
checksum node['appdynamics']['php_agent']['checksum']
24+
end

0 commit comments

Comments
 (0)