torquebox-backstage 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. data/Gemfile +18 -0
  2. data/Gemfile.lock +69 -0
  3. data/README.md +164 -0
  4. data/Rakefile +32 -0
  5. data/TODO +9 -0
  6. data/TORQUEBOX_VERSION +1 -0
  7. data/VERSION +1 -0
  8. data/backstage.rb +84 -0
  9. data/bin/backstage +78 -0
  10. data/config.ru +3 -0
  11. data/config/torquebox.yml +14 -0
  12. data/lib/apps.rb +18 -0
  13. data/lib/apps/models/app.rb +33 -0
  14. data/lib/apps/routes.rb +18 -0
  15. data/lib/authentication.rb +64 -0
  16. data/lib/destinations.rb +21 -0
  17. data/lib/destinations/models/destination.rb +80 -0
  18. data/lib/destinations/models/message.rb +67 -0
  19. data/lib/destinations/models/queue.rb +33 -0
  20. data/lib/destinations/models/topic.rb +59 -0
  21. data/lib/destinations/routes.rb +44 -0
  22. data/lib/has_mbean.rb +59 -0
  23. data/lib/helpers.rb +142 -0
  24. data/lib/jobs.rb +19 -0
  25. data/lib/jobs/models/job.rb +35 -0
  26. data/lib/jobs/routes.rb +18 -0
  27. data/lib/message_processors.rb +18 -0
  28. data/lib/message_processors/models/message_processor.rb +40 -0
  29. data/lib/message_processors/routes.rb +18 -0
  30. data/lib/pools.rb +18 -0
  31. data/lib/pools/models/pool.rb +51 -0
  32. data/lib/pools/routes.rb +41 -0
  33. data/lib/resource.rb +53 -0
  34. data/lib/resource_helpers.rb +63 -0
  35. data/lib/runtimes.rb +19 -0
  36. data/lib/runtimes/models/job.rb +35 -0
  37. data/lib/runtimes/routes.rb +18 -0
  38. data/lib/services.rb +18 -0
  39. data/lib/services/models/service.rb +35 -0
  40. data/lib/services/routes.rb +17 -0
  41. data/lib/torquebox_managed.rb +36 -0
  42. data/lib/util.rb +33 -0
  43. data/spec/api_spec.rb +136 -0
  44. data/spec/auth_spec.rb +70 -0
  45. data/spec/spec_helper.rb +39 -0
  46. data/views/apps/index.haml +15 -0
  47. data/views/apps/show.haml +12 -0
  48. data/views/css/_mixins.sass +51 -0
  49. data/views/css/html5reset.sass +82 -0
  50. data/views/css/style.sass +152 -0
  51. data/views/destinations/index.haml +37 -0
  52. data/views/destinations/show.haml +18 -0
  53. data/views/jobs/index.haml +23 -0
  54. data/views/jobs/show.haml +13 -0
  55. data/views/layout.haml +31 -0
  56. data/views/message_processors/index.haml +28 -0
  57. data/views/message_processors/show.haml +12 -0
  58. data/views/messages/index.haml +20 -0
  59. data/views/messages/properties.haml +3 -0
  60. data/views/messages/show.haml +19 -0
  61. data/views/pools/index.haml +32 -0
  62. data/views/pools/show.haml +44 -0
  63. data/views/services/index.haml +21 -0
  64. data/views/services/show.haml +13 -0
  65. metadata +289 -0
@@ -0,0 +1,3 @@
1
+ require 'backstage'
2
+
3
+ run Backstage::Application
@@ -0,0 +1,14 @@
1
+ web:
2
+ context: /backstage
3
+
4
+ tasks:
5
+ Backgroundable:
6
+ concurrency: 0
7
+
8
+ ruby:
9
+ version: 1.9
10
+
11
+ environment:
12
+ # Add users to $JBOSS_HOME/server/default/conf/props/torquebox-users.properties
13
+ # or just call rake torquebox:auth:adduser CREDENTIALS=user:pass from the command line
14
+ # REQUIRE_AUTHENTICATION: true
@@ -0,0 +1,18 @@
1
+ #
2
+ # Copyright 2011 Red Hat, Inc.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require 'apps/models/app'
18
+ require 'apps/routes'
@@ -0,0 +1,33 @@
1
+ #
2
+ # Copyright 2011 Red Hat, Inc.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ module Backstage
18
+ class App
19
+ include HasMBean
20
+ include TorqueBoxManaged
21
+ include Resource
22
+
23
+ def self.filter
24
+ "torquebox.apps:*"
25
+ end
26
+
27
+ def self.to_hash_attributes
28
+ super + [:name, :environment_name, :root_path, :deployed_at]
29
+ end
30
+
31
+ end
32
+ end
33
+
@@ -0,0 +1,18 @@
1
+ #
2
+ # Copyright 2011 Red Hat, Inc.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ Backstage::Application.resource :app
18
+
@@ -0,0 +1,64 @@
1
+ #
2
+ # Copyright 2011 Red Hat, Inc.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require 'torquebox'
18
+ require 'org/torquebox/auth/authentication'
19
+
20
+ module Backstage
21
+ module Authentication
22
+
23
+ def auth
24
+ @auth ||= Rack::Auth::Basic::Request.new(request.env)
25
+ end
26
+
27
+ def unauthorized!(realm=request.host)
28
+ headers 'WWW-Authenticate' => %(Basic realm="#{realm}")
29
+ throw :halt, [ 401, 'Authentication Required' ]
30
+ end
31
+
32
+ def bad_request!
33
+ throw :halt, [ 400, 'Bad Request' ]
34
+ end
35
+
36
+ def login_path
37
+ "#{request.script_name}/login"
38
+ end
39
+
40
+ def authenticated?
41
+ !request.env['REMOTE_USER'].nil?
42
+ end
43
+
44
+ def authenticate(username, password)
45
+ return false if username.nil? || password.nil?
46
+ authenticator = TorqueBox::Authentication.default
47
+ authenticator.authenticate(username, password)
48
+ end
49
+
50
+ def skip_authentication
51
+ request.env['SKIP_AUTH'] = true
52
+ end
53
+
54
+ def require_authentication
55
+ return if request.env['SKIP_AUTH']
56
+ return if authenticated?
57
+ unauthorized! unless auth.provided?
58
+ bad_request! unless auth.basic?
59
+ unauthorized! unless authenticate(*auth.credentials)
60
+ request.env['REMOTE_USER'] = auth.username
61
+ end
62
+
63
+ end
64
+ end
@@ -0,0 +1,21 @@
1
+ #
2
+ # Copyright 2011 Red Hat, Inc.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require 'destinations/models/destination'
18
+ require 'destinations/models/queue'
19
+ require 'destinations/models/topic'
20
+ require 'destinations/models/message'
21
+ require 'destinations/routes'
@@ -0,0 +1,80 @@
1
+ #
2
+ # Copyright 2011 Red Hat, Inc.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require 'json'
18
+
19
+ module Backstage
20
+ class Destination
21
+ include Enumerable
22
+ include HasMBean
23
+ include Resource
24
+
25
+ attr_accessor :enumerable_options
26
+
27
+ def self.filter
28
+ "org.hornetq:address=\"#{jms_prefix}\",*,type=Queue"
29
+ end
30
+
31
+ def self.to_hash_attributes
32
+ super + [:display_name, :app, :app_name, :status, :message_count, :delivering_count, :scheduled_count, :messages_added, :consumer_count]
33
+ end
34
+
35
+ def jms_destination
36
+ TorqueBox::Messaging::Queue.new( jndi_name, nil, enumerable_options )
37
+ end
38
+
39
+ def each
40
+ jms_destination.each do |message|
41
+ message = Message.new( message )
42
+ message.parent = self
43
+ yield message
44
+ end
45
+ end
46
+
47
+ def display_name
48
+ self.class.display_name( name )
49
+ end
50
+
51
+ def jndi_name
52
+ jndi_name = name.gsub( self.class.jms_prefix, '' )
53
+ jndi_name = "/queue/#{jndi_name}" if %w{ DLQ ExpiryQueue }.include?( jndi_name )
54
+ jndi_name
55
+ end
56
+
57
+ def self.display_name(name)
58
+ display_name = name.gsub( /jms\..*?\./, '' )
59
+ display_name = 'Backgroundable' if display_name =~ %r{/queues/torquebox/.*/backgroundable}
60
+ display_name = "#{$1.classify}Task" if display_name =~ %r{/queues/torquebox/.*/tasks/(.*)$}
61
+ display_name
62
+ end
63
+
64
+ def app
65
+ name =~ %r{/queues/torquebox/(.*?)/} ? App.find( "torquebox.apps:app=#{$1}" ) : nil
66
+ end
67
+
68
+ def app_name
69
+ name =~ %r{/queues/torquebox/(.*)} ? $1 : 'n/a'
70
+ end
71
+
72
+ def status
73
+ mbean.paused ? 'Paused' : 'Running'
74
+ end
75
+
76
+ def available_actions
77
+ status == 'Running' ? %w{ pause } : %w{ resume }
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,67 @@
1
+ #
2
+ # Copyright 2011 Red Hat, Inc.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require 'torquebox/messaging/javax_jms_text_message'
18
+
19
+ module Backstage
20
+ class Message
21
+ include Resource
22
+
23
+ attr_reader :jms_message
24
+
25
+ IGNORED_PROPERTIES = %w{ torquebox_encoding JMSXDeliveryCount }
26
+ def initialize(message)
27
+ @jms_message = message
28
+ end
29
+
30
+ def content
31
+ jms_message.decode.inspect
32
+ rescue Exception => ex
33
+ # we may not have access to a serialized class. Just show the
34
+ # Marshal string in that case
35
+ jms_message.get_string_property( 'torquebox_encoding' ) ? Base64.decode64( jms_message.text ) : jms_message.text
36
+ end
37
+
38
+ def jms_id
39
+ jms_message.jms_message_id
40
+ end
41
+ alias_method :full_name, :jms_id
42
+
43
+ def properties
44
+ @properties ||= jms_message.property_names.inject( {} ) do |properties, name|
45
+ properties[name] = jms_message.get_string_property( name ) unless IGNORED_PROPERTIES.include?( name )
46
+ properties
47
+ end
48
+ end
49
+
50
+ JMS_PROPERTIES = %w{ JMS_Correlation_ID JMS_Priority JMS_Type JMS_Reply_To JMS_Redelivered }
51
+ def jms_properties
52
+ @jms_properties ||= JMS_PROPERTIES.inject( {} ) do |props,name|
53
+ value = jms_message.send(name.downcase)
54
+ props[name.gsub('_',' ')] = value.to_s if value # Ignore empty values
55
+ props
56
+ end
57
+ end
58
+
59
+ def delivery_count
60
+ jms_message.get_string_property( 'JMSXDeliveryCount' )
61
+ end
62
+
63
+ def self.to_hash_attributes
64
+ super + [:jms_id, :delivery_count, :properties, :content]
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,33 @@
1
+ #
2
+ # Copyright 2011 Red Hat, Inc.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ module Backstage
18
+ class Queue < Destination
19
+
20
+ def self.jms_prefix
21
+ 'jms.queue.'
22
+ end
23
+
24
+ def self.filter
25
+ 'org.hornetq:address="jms.queue.*",*,type=Queue'
26
+ end
27
+
28
+ def self.to_hash_attributes
29
+ super + [:durable]
30
+ end
31
+
32
+ end
33
+ end
@@ -0,0 +1,59 @@
1
+ #
2
+ # Copyright 2011 Red Hat, Inc.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ module Backstage
18
+ class Topic < Destination
19
+ attr_accessor :consumer_topic
20
+
21
+ def self.jms_prefix
22
+ 'jms.topic.'
23
+ end
24
+
25
+ def self.filter
26
+ 'org.hornetq:address="jms.topic.*",*,name="jms.topic.*",type=Queue'
27
+ end
28
+
29
+ def consumer_topics
30
+ unless @consumer_topics
31
+ @consumer_topics = self.class.all( %Q{org.hornetq:address="#{name}",*,type=Queue} )
32
+ @consumer_topics = @consumer_topics.reject { |t| t.full_name == full_name }
33
+ @consumer_topics.each { |t| t.consumer_topic = true }
34
+ end
35
+ @consumer_topics
36
+ end
37
+
38
+ %w{ message_count delivering_count scheduled_count messages_added }.each do |method|
39
+ define_method method do
40
+ if consumer_topic
41
+ super
42
+ else
43
+ consumer_topics.collect(&(method.to_sym)).max || 0
44
+ end
45
+ end
46
+ end
47
+
48
+ def consumer_count
49
+ consumer_topics.size
50
+ end
51
+
52
+ %w{ pause resume }.each do |action|
53
+ define_method action do
54
+ super
55
+ consumer_topics.each { |t| t.__send__( action ) } unless consumer_topic
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,44 @@
1
+ #
2
+ # Copyright 2011 Red Hat, Inc.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+
18
+ module Backstage
19
+ class Application < Sinatra::Base
20
+ resource :queue, :topic, :view_path => :destinations, :actions => [:pause, :resume]
21
+
22
+ get "/queue/:name/messages" do
23
+ @destination = Queue.find( Util.decode_name( params[:name] ) )
24
+ if html_requested?
25
+ haml :'messages/index'
26
+ else
27
+ content_type :json
28
+ collection_to_json( @destination.entries )
29
+ end
30
+ end
31
+
32
+ get "/queue/:name/message/:id" do
33
+ @destination = Queue.find( Util.decode_name( params[:name] ) )
34
+ @object = @destination.find { |m| m.jms_id == Util.decode_name( params[:id] ) }
35
+ if html_requested?
36
+ haml :'messages/show'
37
+ else
38
+ object_to_json( @object )
39
+ end
40
+ end
41
+
42
+ end
43
+ end
44
+