Skip to content

Commit 69360c9

Browse files
author
Dan Koepke
committed
WIP PHP agent as LWRP
1 parent a526e74 commit 69360c9

File tree

8 files changed

+258
-5
lines changed

8 files changed

+258
-5
lines changed

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: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
module AppDynamicsCookbook
2+
module Helpers
3+
def platform(supported)
4+
case node['platform_family']
5+
when 'mac_os_x'
6+
plat = 'osx'
7+
when 'linux'
8+
plat = 'linux'
9+
else
10+
plat = node['platform_family']
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(supported)
19+
arch = node['kernel']['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+
end
30+
end
31+
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

libraries/provider_extract.rb

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
require 'chef/provider/lwrp_base'
2+
3+
class Chef
4+
class Provider
5+
class AppDynamicsExtract < Chef::Provider::LWRPBase
6+
provides :appdynamics_extract if defined?(provides)
7+
8+
use_inline_resources if defined?(use_inline_resources)
9+
10+
commands = {
11+
zip: ['unzip', '-qq'],
12+
tar_bz2: ['tar', 'xjf'],
13+
tar_gz: ['tar', 'xzf']
14+
}
15+
16+
def whyrun_supported?
17+
true
18+
end
19+
20+
action :run do
21+
tmp_dest = "#{Chef::Config[:file_cache_path]}/#{new_resource.name}"
22+
23+
install_type = new_resource.type || guess_type(new_resource.name)
24+
install_unzip if install_type == :zip
25+
26+
raise "Unsupported type #{install_type}" if commands[install_type].nil?
27+
install_command = commands[install_type] + [tmp_dest]
28+
29+
directory "#{new_resource.name} :create #{dest}" do
30+
recursive true
31+
owner new_resource.owner unless new_resource.owner.nil?
32+
group new_resource.group unless new_resource.group.nil?
33+
mode '0644'
34+
end
35+
36+
remote_file "#{new_resource.name} :create #{tmp_dest}" do
37+
source new_resource.source
38+
path tmp_dest
39+
owner new_resource.owner unless new_resource.owner.nil?
40+
group new_resource.group unless new_resource.group.nil?
41+
checksum new_resource.checksum unless new_resource.checksum.nil?
42+
notifies :run, "execute[#{new_resource.name} :run extract]", :immediately
43+
end
44+
45+
execute "#{new_resource.name} :run extract" do
46+
action :nothing
47+
48+
command install_command
49+
cwd new_resource.dest
50+
user new_resource.owner unless new_resource.owner.nil?
51+
group new_resource.group unless new_resource.group.nil?
52+
end
53+
end
54+
55+
def guess_type(name)
56+
if name.end_with? '.zip'
57+
return :zip
58+
elsif name.end_with? '.tar.bz2'
59+
return :tar_bz2
60+
elsif name.end_with? '.tar.gz'
61+
return :tar_gz
62+
end
63+
raise "Cannot guess archive type, please specify 'type' attribute"
64+
end
65+
66+
def install_unzip
67+
package 'unzip'
68+
end
69+
end
70+
end
71+
end

libraries/provider_php_agent.rb

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
require 'chef/provider/lwrp_base'
2+
require_relative 'helpers'
3+
4+
class Chef
5+
class Provider
6+
class AppDynamicsPHPAgent < Chef::Provider::LWRPBase
7+
include AppDynamicsCookbook::Helpers
8+
9+
provides :appdynamics_php_agent if defined?(provides)
10+
11+
use_inline_resources if defined?(use_inline_resources)
12+
13+
def whyrun_supported?
14+
true
15+
end
16+
17+
action :install do
18+
plat = platform %w(linux osx)
19+
arch = architecture %w(x86 x64)
20+
ver = new_resource.version
21+
22+
tarball_source = new_resource.source || default_source(plat, arch, ver)
23+
24+
appdynamics_extract "appdynamics-php-agent-#{ver}.tar.bz2" do
25+
source tarball_source
26+
dest new_resource.dest
27+
end
28+
29+
install_command = ["./install.sh"]
30+
install_command << '-s' if new_resource.controller_ssl
31+
install_command << "-a=#{new_resource.account}@#{new_resource.accesskey}"
32+
install_command << "--http-proxy-host=#{new_resoure.http_proxy_host}" if new_resource.http_proxy_host
33+
install_command << "--http-proxy-port=#{new_resoure.http_proxy_port}" if new_resource.http_proxy_port
34+
install_command << "--http-proxy-user=#{new_resoure.http_proxy_user}" if new_resource.http_proxy_user
35+
install_command << "--http-proxy-password-file=#{new_resoure.http_proxy_password_file}" if new_resource.http_proxy_password_file
36+
install_command << "#{new_resource.controller_host} #{new_resource.controller_port}"
37+
install_command << "#{new_resource.app_name} #{new_resource.tier_name} #{new_resource.node_name}"
38+
39+
execute 'install-php-agent' do
40+
action :nothing
41+
command install_command
42+
cwd "#{dest}/appdynamics-php-agent"
43+
user install_owner
44+
group install_group
45+
end
46+
47+
new_resource.updated_by_last_action(true)
48+
end
49+
50+
def default_source(plat, arch, version)
51+
"https://packages.appdynamics.com/#{version}/php/appdynamics-php-agent-#{plat}-#{arch}-#{version}.tar.bz2"
52+
end
53+
end
54+
end
55+
end

libraries/resource_extract.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
require 'chef/resource/lwrp_base'
2+
3+
class Chef
4+
class Resource
5+
class AppDynamicsExtract < Chef::Resource::LWRPBase
6+
provides :appdynamics_extract
7+
8+
self.resource_name = :appdynamics_extract
9+
actions :run
10+
default_action :run
11+
12+
attribute :name, kind_of: String, name_attribute: true, required: true
13+
attribute :source, kind_of: String, required: true
14+
attribute :dest, kind_of: String, required: true
15+
16+
attribute :type, kind_of: [Symbol, NilClass]
17+
attribute :owner, kind_of: [String, Integer, NilClass]
18+
attribute :group, kind_of: [String, Integer, NilClass]
19+
attribute :checksum, kind_of: [String, NilClass]
20+
end
21+
end
22+
end

libraries/resource_php_agent.rb

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
require 'chef/resource/lwrp_base'
2+
3+
class Chef
4+
class Resource
5+
class AppDynamicsPHPAgent < Chef::Resource::LWRPBase
6+
provides :appdynamics_php_agent
7+
8+
self.resource_name = :appdynamics_php_agent
9+
actions :install
10+
default_action :install
11+
12+
attribute :dest, kind_of: String, required: true
13+
attribute :version, kind_of: String, regex: /^\d+\.\d+.\d+.\d+/, required: true
14+
attribute :source, kind_of: [String, NilClass], default: nil
15+
attribute :checksum, kind_of: [String, NilClass], default: nil
16+
17+
attribute :app_name, kind_of: String, required: true
18+
attribute :tier_name, kind_of: String, required: true
19+
attribute :node_name, kind_of: String, required: true
20+
21+
attribute :controller_host, kind_of: String, required: true
22+
attribute :controller_port, kind_of: [String, Integer], default: 443
23+
attribute :controller_ssl, kind_of: [TrueClass, FalseClass], default: true
24+
attribute :account, kind_of: String, default: 'customer1'
25+
attribute :accesskey, kind_of: String, required: true
26+
27+
attribute :http_proxy_host, kind_of: [String, NilClass], default: nil
28+
attribute :http_proxy_port, kind_of: [String, Integer, NilClass], default: nil
29+
attribute :http_proxy_user, kind_of: [String, NilClass], default: nil
30+
attribute :http_proxy_password_file, kind_of: [String, NilClass], default: nil
31+
32+
attribute :owner, kind_of: [String, Integer, NilClass], default: nil
33+
attribute :group, kind_of: [String, Integer, NilClass], default: nil
34+
end
35+
end
36+
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'

0 commit comments

Comments
 (0)