cirras-management 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,165 @@
1
+ GNU LESSER GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+
9
+ This version of the GNU Lesser General Public License incorporates
10
+ the terms and conditions of version 3 of the GNU General Public
11
+ License, supplemented by the additional permissions listed below.
12
+
13
+ 0. Additional Definitions.
14
+
15
+ As used herein, "this License" refers to version 3 of the GNU Lesser
16
+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
17
+ General Public License.
18
+
19
+ "The Library" refers to a covered work governed by this License,
20
+ other than an Application or a Combined Work as defined below.
21
+
22
+ An "Application" is any work that makes use of an interface provided
23
+ by the Library, but which is not otherwise based on the Library.
24
+ Defining a subclass of a class defined by the Library is deemed a mode
25
+ of using an interface provided by the Library.
26
+
27
+ A "Combined Work" is a work produced by combining or linking an
28
+ Application with the Library. The particular version of the Library
29
+ with which the Combined Work was made is also called the "Linked
30
+ Version".
31
+
32
+ The "Minimal Corresponding Source" for a Combined Work means the
33
+ Corresponding Source for the Combined Work, excluding any source code
34
+ for portions of the Combined Work that, considered in isolation, are
35
+ based on the Application, and not on the Linked Version.
36
+
37
+ The "Corresponding Application Code" for a Combined Work means the
38
+ object code and/or source code for the Application, including any data
39
+ and utility programs needed for reproducing the Combined Work from the
40
+ Application, but excluding the System Libraries of the Combined Work.
41
+
42
+ 1. Exception to Section 3 of the GNU GPL.
43
+
44
+ You may convey a covered work under sections 3 and 4 of this License
45
+ without being bound by section 3 of the GNU GPL.
46
+
47
+ 2. Conveying Modified Versions.
48
+
49
+ If you modify a copy of the Library, and, in your modifications, a
50
+ facility refers to a function or data to be supplied by an Application
51
+ that uses the facility (other than as an argument passed when the
52
+ facility is invoked), then you may convey a copy of the modified
53
+ version:
54
+
55
+ a) under this License, provided that you make a good faith effort to
56
+ ensure that, in the event an Application does not supply the
57
+ function or data, the facility still operates, and performs
58
+ whatever part of its purpose remains meaningful, or
59
+
60
+ b) under the GNU GPL, with none of the additional permissions of
61
+ this License applicable to that copy.
62
+
63
+ 3. Object Code Incorporating Material from Library Header Files.
64
+
65
+ The object code form of an Application may incorporate material from
66
+ a header file that is part of the Library. You may convey such object
67
+ code under terms of your choice, provided that, if the incorporated
68
+ material is not limited to numerical parameters, data structure
69
+ layouts and accessors, or small macros, inline functions and templates
70
+ (ten or fewer lines in length), you do both of the following:
71
+
72
+ a) Give prominent notice with each copy of the object code that the
73
+ Library is used in it and that the Library and its use are
74
+ covered by this License.
75
+
76
+ b) Accompany the object code with a copy of the GNU GPL and this license
77
+ document.
78
+
79
+ 4. Combined Works.
80
+
81
+ You may convey a Combined Work under terms of your choice that,
82
+ taken together, effectively do not restrict modification of the
83
+ portions of the Library contained in the Combined Work and reverse
84
+ engineering for debugging such modifications, if you also do each of
85
+ the following:
86
+
87
+ a) Give prominent notice with each copy of the Combined Work that
88
+ the Library is used in it and that the Library and its use are
89
+ covered by this License.
90
+
91
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
92
+ document.
93
+
94
+ c) For a Combined Work that displays copyright notices during
95
+ execution, include the copyright notice for the Library among
96
+ these notices, as well as a reference directing the user to the
97
+ copies of the GNU GPL and this license document.
98
+
99
+ d) Do one of the following:
100
+
101
+ 0) Convey the Minimal Corresponding Source under the terms of this
102
+ License, and the Corresponding Application Code in a form
103
+ suitable for, and under terms that permit, the user to
104
+ recombine or relink the Application with a modified version of
105
+ the Linked Version to produce a modified Combined Work, in the
106
+ manner specified by section 6 of the GNU GPL for conveying
107
+ Corresponding Source.
108
+
109
+ 1) Use a suitable shared library mechanism for linking with the
110
+ Library. A suitable mechanism is one that (a) uses at run time
111
+ a copy of the Library already present on the user's computer
112
+ system, and (b) will operate properly with a modified version
113
+ of the Library that is interface-compatible with the Linked
114
+ Version.
115
+
116
+ e) Provide Installation Information, but only if you would otherwise
117
+ be required to provide such information under section 6 of the
118
+ GNU GPL, and only to the extent that such information is
119
+ necessary to install and execute a modified version of the
120
+ Combined Work produced by recombining or relinking the
121
+ Application with a modified version of the Linked Version. (If
122
+ you use option 4d0, the Installation Information must accompany
123
+ the Minimal Corresponding Source and Corresponding Application
124
+ Code. If you use option 4d1, you must provide the Installation
125
+ Information in the manner specified by section 6 of the GNU GPL
126
+ for conveying Corresponding Source.)
127
+
128
+ 5. Combined Libraries.
129
+
130
+ You may place library facilities that are a work based on the
131
+ Library side by side in a single library together with other library
132
+ facilities that are not Applications and are not covered by this
133
+ License, and convey such a combined library under terms of your
134
+ choice, if you do both of the following:
135
+
136
+ a) Accompany the combined library with a copy of the same work based
137
+ on the Library, uncombined with any other library facilities,
138
+ conveyed under the terms of this License.
139
+
140
+ b) Give prominent notice with the combined library that part of it
141
+ is a work based on the Library, and explaining where to find the
142
+ accompanying uncombined form of the same work.
143
+
144
+ 6. Revised Versions of the GNU Lesser General Public License.
145
+
146
+ The Free Software Foundation may publish revised and/or new versions
147
+ of the GNU Lesser General Public License from time to time. Such new
148
+ versions will be similar in spirit to the present version, but may
149
+ differ in detail to address new problems or concerns.
150
+
151
+ Each version is given a distinguishing version number. If the
152
+ Library as you received it specifies that a certain numbered version
153
+ of the GNU Lesser General Public License "or any later version"
154
+ applies to it, you have the option of following the terms and
155
+ conditions either of that published version or of any later version
156
+ published by the Free Software Foundation. If the Library as you
157
+ received it does not specify a version number of the GNU Lesser
158
+ General Public License, you may choose any version of the GNU Lesser
159
+ General Public License ever published by the Free Software Foundation.
160
+
161
+ If the Library as you received it specifies that a proxy can decide
162
+ whether future versions of the GNU Lesser General Public License shall
163
+ apply, that proxy's public statement of acceptance of any version is
164
+ permanent authorization for you to choose that version for the
165
+ Library.
data/README ADDED
@@ -0,0 +1,2 @@
1
+ Required gems to run this project:
2
+ - thin >= 1.0.0
@@ -0,0 +1,15 @@
1
+ require 'rubygems'
2
+ require 'restclient'
3
+
4
+ $: << 'lib'
5
+
6
+ require 'cirras-management/manager'
7
+ require 'cirras-management/helper/log-helper'
8
+
9
+ module CirrASManagement
10
+ Manager.new
11
+ use Rack::CommonLogger
12
+ RestClient.log = LogHelper.instance.client_log_file
13
+ end
14
+
15
+ run Sinatra::Application
@@ -0,0 +1,14 @@
1
+ ---
2
+ environment: production
3
+ chdir: /usr/share/cirras-management
4
+ address: 0.0.0.0
5
+ user: root
6
+ group: root
7
+ port: 4545
8
+ pid: /var/lock/cirras-management.pid
9
+ rackup: config.ru
10
+ log: /var/log/cirras-management/thin.log
11
+ max_conns: 100
12
+ timeout: 30
13
+ max_persistent_conns: 100
14
+ daemonize: true
@@ -0,0 +1,46 @@
1
+ # JBoss, Home of Professional Open Source
2
+ # Copyright 2009, Red Hat Middleware LLC, and individual contributors
3
+ # by the @authors tag. See the copyright.txt in the distribution for a
4
+ # full listing of individual contributors.
5
+ #
6
+ # This is free software; you can redistribute it and/or modify it
7
+ # under the terms of the GNU Lesser General Public License as
8
+ # published by the Free Software Foundation; either version 2.1 of
9
+ # the License, or (at your option) any later version.
10
+ #
11
+ # This software is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
+ # Lesser General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU Lesser General Public
17
+ # License along with this software; if not, write to the Free
18
+ # Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
19
+ # 02110-1301 USA, or see the FSF site: http://www.fsf.org.
20
+
21
+ require 'cirras-management/helper/log-helper'
22
+
23
+ module CirrASManagement
24
+ APPLIANCE_TYPE = {
25
+ :backend => "back-end",
26
+ :frontend => "front-end",
27
+ :management => "management",
28
+ :postgis => "postgis"
29
+ }
30
+
31
+ APIS = [ "2009-05-18" ]
32
+
33
+ DEFAULT_FRONT_END_PORT = 80
34
+ MANAGEMENT_PORT = 4545
35
+ JBOSS_HOME = "/opt/jboss-as6"
36
+ JBOSS_SERVICE_NAME = "jboss-as6"
37
+ JBOSS_SYSCONFIG_FILE = "/etc/sysconfig/jboss-as6"
38
+ BOXGRINDER_CONFIG_FILE = "/etc/sysconfig/boxgrinder"
39
+ RACK_CONFIG_FILE = "config/config.yaml"
40
+ LEASES_FILE = "/var/lib/dhcpd/dhcpd.leases"
41
+ RHQ_AGENT_SYSCONF_FILE = "/etc/sysconfig/rhq-agent"
42
+
43
+ LOG_DEFAULT_FILE = "/var/log/cirras-management/default.log"
44
+ LOG_WEB_FILE = "/var/log/cirras-management/web.log"
45
+ LOG_CLIENT_FILE = "/var/log/cirras-management/client.log"
46
+ end
@@ -0,0 +1,170 @@
1
+ # JBoss, Home of Professional Open Source
2
+ # Copyright 2009, Red Hat Middleware LLC, and individual contributors
3
+ # by the @authors tag. See the copyright.txt in the distribution for a
4
+ # full listing of individual contributors.
5
+ #
6
+ # This is free software; you can redistribute it and/or modify it
7
+ # under the terms of the GNU Lesser General Public License as
8
+ # published by the Free Software Foundation; either version 2.1 of
9
+ # the License, or (at your option) any later version.
10
+ #
11
+ # This software is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
+ # Lesser General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU Lesser General Public
17
+ # License along with this software; if not, write to the Free
18
+ # Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
19
+ # 02110-1301 USA, or see the FSF site: http://www.fsf.org.
20
+
21
+ require 'yaml'
22
+
23
+ require 'cirras-management/model/config'
24
+ require 'cirras-management/helper/ip-helper'
25
+ require 'cirras-management/helper/log-helper'
26
+ require 'cirras-management/node/aws-node-manager'
27
+ require 'cirras-management/node/default-node-manager'
28
+ require 'cirras-management/event/event-manager'
29
+ require 'cirras-management/model/handler-to'
30
+ require 'cirras-management/defaults'
31
+
32
+ require 'sinatra'
33
+
34
+ module CirrASManagement
35
+ class Manager
36
+ def initialize
37
+
38
+ @log = Logger.new(STDOUT)
39
+
40
+ configure :production do
41
+ @log = LogHelper.instance.log
42
+ end
43
+
44
+ @config = ConfigHelper.new( :log => @log ).config
45
+ @@config = @config
46
+ @@event_manager = EventManager.new( :log => @log )
47
+
48
+ @log.info "Setting up management environment for #{@config.appliance_name}"
49
+
50
+ if @config.is_management_appliance?
51
+ @log.info "Setting up node managers..."
52
+
53
+ if @config.running_on_ec2
54
+ @node_manager = AWSNodeManager.new( @config, :log => @log )
55
+ else
56
+ @node_manager = DefaultNodeManager.new( @config, :log => @log )
57
+ end
58
+
59
+ @@node_manager = @node_manager
60
+ else
61
+ create_client
62
+ end
63
+
64
+ # sinatra parameters
65
+ enable :raise_errors
66
+ disable :logging
67
+ disable :lock
68
+
69
+ helpers do
70
+ def prefix
71
+ request.path_info.match( /^\/([\w\-]+)\// )[1]
72
+ end
73
+
74
+ def notify( event, *args )
75
+ Manager.event_manager.notify( false, prefix, event, *args )
76
+ end
77
+
78
+ def notify_threaded( event, *args )
79
+ Manager.event_manager.notify( true, prefix, event, *args )
80
+ end
81
+ end
82
+
83
+ for api in APIS
84
+ bind_handler( api )
85
+ end
86
+
87
+ bind_handler( APIS.first, "latest" )
88
+
89
+ get '/' do
90
+ apis = "latest\n"
91
+ for api in APIS
92
+ apis += api + "\n"
93
+ end
94
+
95
+ apis
96
+ end
97
+
98
+ get '/*' do
99
+ status 404
100
+ "Not found"
101
+ end
102
+
103
+ wait_for_web_server
104
+ end
105
+
106
+ def bind_handler( api_version, prefix = nil )
107
+ prefix = api_version if prefix.nil?
108
+
109
+ @log.debug "Binding new request handler helper for API version '#{api_version}' and prefix '#{prefix}'..."
110
+
111
+ Dir["lib/cirras-management/api/#{api_version}/handler/*/*"].each {|file| require file if File.exists?( file ) }
112
+
113
+ to = HandlerTO.new( prefix, api_version, @config, @log )
114
+
115
+ if @config.is_management_appliance?
116
+ handler_helper = ManagementApplianceRequestHandlerHelper.new( to )
117
+ else
118
+ handler_helper = DefaultRequestHandlerHelper.new( to )
119
+ end
120
+
121
+ Manager.event_manager.register( api_version, prefix, handler_helper.handlers )
122
+ end
123
+
124
+ def wait_for_web_server
125
+ t = Thread.new do
126
+ while true do
127
+ @log.info "Waiting for web server..."
128
+ break if IPHelper.new.is_port_open?( "localhost", @config.port )
129
+ sleep 1
130
+ end
131
+ @log.info "Web server is running and ready for requests!"
132
+ discover_nodes if @config.is_management_appliance?
133
+ end
134
+ end
135
+
136
+ # this is a client
137
+
138
+ def create_client
139
+ end
140
+
141
+ def nodes
142
+ @node_manager.nodes
143
+ end
144
+
145
+ def self.config
146
+ @@config
147
+ end
148
+
149
+ def self.node_manager
150
+ @@node_manager
151
+ end
152
+
153
+ def discover_nodes
154
+ t = Thread.new do
155
+ while true do
156
+ @log.debug "Begining node discovery..."
157
+ @node_manager.register_nodes
158
+ @node_manager.push_management_address
159
+ @log.debug "Waiting #{@config.sleep} seconds before next node discovery..."
160
+ sleep @config.sleep # check after 30 sec if there are changes in nodes (new added, removed, etc)
161
+ end
162
+ end
163
+ end
164
+
165
+ def self.event_manager
166
+ @@event_manager
167
+ end
168
+
169
+ end
170
+ end
@@ -0,0 +1,35 @@
1
+ #/bin/sh
2
+
3
+ address=`ip addr list eth0 | grep "inet " | cut -d' ' -f6 | cut -d/ -f1`
4
+ appliance_name=`awk -F= '{ print $2 }' /etc/sysconfig/boxgrinder`
5
+ network_script="$0"
6
+
7
+ if [ "$address" == "" ]; then
8
+ if [ "$appliance_name" == "management" ]; then
9
+ # prepare network card
10
+ echo -e "DEVICE=eth0\nBOOTPROTO=none\nONBOOT=yes\nNETWORK=192.168.192.0\nNETMASK=255.255.255.0\nIPADDR=192.168.192.1\nUSERCTL=no" > /etc/sysconfig/network-scripts/ifcfg-eth0
11
+
12
+ # nameserver information
13
+ echo -e "nameserver 208.67.222.222\nnameserver 208.67.220.220" > /etc/resolv.conf
14
+
15
+ # enable forwarding
16
+ echo "FORWARD_IPV4=yes" >> /etc/sysconfig/network
17
+ echo "1" > /proc/sys/net/ipv4/ip_forward
18
+
19
+ # restarting network
20
+ /etc/init.d/network restart
21
+
22
+ # DHCP
23
+ echo -e "subnet 192.168.192.0 netmask 255.255.255.0 {\noption domain-name-servers 208.67.222.222, 208.67.220.220;\nrange dynamic-bootp 192.168.192.5 192.168.192.200;\noption subnet-mask 255.255.255.0;\noption broadcast-address 192.168.192.255;\noption routers 192.168.192.1;\n}" > /etc/dhcpd.conf
24
+
25
+ # restarting DHCP server
26
+ /etc/init.d/dhcpd restart
27
+ else
28
+ /etc/init.d/network restart
29
+ sleep 10
30
+ sh $network_script
31
+ exit
32
+ fi
33
+ fi
34
+
35
+ service cirras-management start
data/thin ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+ # Thin command line interface script.
3
+ # Run <tt>thin -h</tt> to get more usage.
4
+
5
+ require 'additional-libs'
6
+ require 'rubygems'
7
+ require 'thin'
8
+
9
+ Thin::Runner.new(ARGV).run!
metadata ADDED
@@ -0,0 +1,137 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cirras-management
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - CirrAS Project
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-05-26 00:00:00 +02:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rest-client
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 1
29
+ - 5
30
+ - 1
31
+ version: 1.5.1
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: amazon-ec2
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 0
43
+ - 9
44
+ - 14
45
+ version: 0.9.14
46
+ type: :runtime
47
+ version_requirements: *id002
48
+ - !ruby/object:Gem::Dependency
49
+ name: nokogiri
50
+ prerelease: false
51
+ requirement: &id003 !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ segments:
56
+ - 1
57
+ - 4
58
+ - 2
59
+ version: 1.4.2
60
+ type: :runtime
61
+ version_requirements: *id003
62
+ - !ruby/object:Gem::Dependency
63
+ name: thin
64
+ prerelease: false
65
+ requirement: &id004 !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ segments:
70
+ - 1
71
+ - 2
72
+ - 7
73
+ version: 1.2.7
74
+ type: :runtime
75
+ version_requirements: *id004
76
+ - !ruby/object:Gem::Dependency
77
+ name: sinatra
78
+ prerelease: false
79
+ requirement: &id005 !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ segments:
84
+ - 1
85
+ - 0
86
+ version: "1.0"
87
+ type: :runtime
88
+ version_requirements: *id005
89
+ description:
90
+ email:
91
+ executables: []
92
+
93
+ extensions: []
94
+
95
+ extra_rdoc_files: []
96
+
97
+ files:
98
+ - lib/cirras-management/defaults.rb
99
+ - lib/cirras-management/manager.rb
100
+ - README
101
+ - LICENSE
102
+ - thin
103
+ - src/network-setup.sh
104
+ - config.ru
105
+ - config/config.yaml
106
+ has_rdoc: true
107
+ homepage: http://www.jboss.org/stormgrind/projects/cirras.html
108
+ licenses: []
109
+
110
+ post_install_message:
111
+ rdoc_options: []
112
+
113
+ require_paths:
114
+ - lib
115
+ required_ruby_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ segments:
120
+ - 0
121
+ version: "0"
122
+ required_rubygems_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ segments:
127
+ - 0
128
+ version: "0"
129
+ requirements: []
130
+
131
+ rubyforge_project:
132
+ rubygems_version: 1.3.6
133
+ signing_key:
134
+ specification_version: 3
135
+ summary: CirrAS is an effort to automatically deploy a clustered JBoss AS server in the Cloud.
136
+ test_files: []
137
+