Skip to content

Commit

Permalink
better ImageConsumer and BuildImage command
Browse files Browse the repository at this point in the history
  • Loading branch information
goldmann committed Mar 15, 2010
1 parent dbfebcd commit 13a9e41
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 44 deletions.
9 changes: 0 additions & 9 deletions .gitmodules

This file was deleted.

23 changes: 23 additions & 0 deletions bin/boxgrinder-node
@@ -0,0 +1,23 @@
#!/usr/bin/env ruby

# JBoss, Home of Professional Open Source
# Copyright 2009, Red Hat Middleware LLC, and individual contributors
# by the @authors tag. See the copyright.txt in the distribution for a
# full listing of individual contributors.
#
# This is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation; either version 2.1 of
# the License, or (at your option) any later version.
#
# This software is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this software; if not, write to the Free
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
# 02110-1301 USA, or see the FSF site: http://www.fsf.org.

require 'boxgrinder-node'
1 change: 0 additions & 1 deletion lib/boxgrinder-build
Submodule boxgrinder-build deleted from f50525
9 changes: 5 additions & 4 deletions boxgrinder-node-service.rb → lib/boxgrinder-node.rb
Expand Up @@ -18,10 +18,11 @@
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
# 02110-1301 USA, or see the FSF site: http://www.fsf.org.

$: << File.join( File.dirname( __FILE__ ), 'lib' )
$: << File.join( File.dirname( __FILE__ ), 'lib', 'boxgrinder-build', 'lib' )
$: << File.join( File.dirname( __FILE__ ), 'lib', 'boxgrinder-build', 'lib', 'boxgrinder-core', 'lib' )
require 'rubygems'

gem 'torquebox-messaging-container', '>= 1.0.0'
gem 'boxgrinder-build', '>= 0.0.1'

require 'boxgrinder-node/initializer'

BoxGrinder::Node::Initializer.new.listen
BoxGrinder::Node::Initializer.new.listen
28 changes: 9 additions & 19 deletions lib/boxgrinder-node/commands/build-image-command.rb
@@ -1,14 +1,16 @@
require 'boxgrinder-node/helpers/queue-helper'
require 'boxgrinder-core/helpers/exec-helper'
require 'fileutils'

module BoxGrinder
module Node
class BuildImageCommand

def initialize( task, options = {} )
def initialize( task, node_config, options = {} )
@task = task
@node_config = node_config

@log = options[:log] || Logger.new(STDOUT)
@queue_helper = options[:queue_helper] || QueueHelper.new( :log => @log )
@queue_helper = options[:queue_helper] || QueueHelper.new( @node_config, :log => @log )
@exec_helper = options[:exec_helper] || ExecHelper.new( :log => @log )

@appliance_config = @task.data[:appliance_config].init
Expand All @@ -34,28 +36,16 @@ def execute
@log.error "Not valid image format:' #{@format}'."
end

@queue_helper.enqueue( IMAGE_MANAGEMENT_QUEUE, { :id => @image_id, :status => :building }, "10.1.0.13" )
@queue_helper.enqueue( IMAGE_MANAGEMENT_QUEUE, { :id => @image_id, :status => :building } )

begin
@exec_helper.execute "rake #{command}"
#@exec_helper.execute "rake #{command}"

@log.info "Image for '#{@appliance_config.name}' (#{@appliance_config.hardware.arch}) appliance and '#{@format}' format was built successfully."
@queue_helper.enqueue( IMAGE_MANAGEMENT_QUEUE,
{
:id => @image_id,
:status => :built
},
"10.1.0.13"
)
@queue_helper.enqueue( IMAGE_MANAGEMENT_QUEUE, { :id => @image_id, :status => :built } )
rescue
@log.error "An error occurred while building image for '#{@appliance_config.name}' (#{@appliance_config.hardware.arch}) appliance and '#{@format}' format. Check logs for more info."
@queue_helper.enqueue( IMAGE_MANAGEMENT_QUEUE,
{
:id => @image_id,
:status => :error
},
"10.1.0.13"
)
@queue_helper.enqueue( IMAGE_MANAGEMENT_QUEUE, { :id => @image_id, :status => :error } )
end
end

Expand Down
26 changes: 18 additions & 8 deletions lib/boxgrinder-node/consumers/image-consumer.rb
@@ -1,23 +1,33 @@
require 'boxgrinder-node/commands/build-image-command'
require 'boxgrinder-node/commands/remove-image-command'
require 'boxgrinder-core/models/appliance-config'
require 'boxgrinder-core/models/task'

module BoxGrinder
module Node
class ImageConsumer
def on_object( payload )
@task = payload

@log = LOG
@task = payload
@log = LOG
@node_config = NODE_CONFIG

@log.info "Received new task."

case @task.action
when Image::ACTIONS[:build] then
BuildImageCommand.new( @task, :log => @log ).execute
when Image::ACTIONS[:remove] then
#RemoveImageCommand.new( @task.artifact, :log => @log ).execute
begin
case @task.action
when :build then
BuildImageCommand.new( @task, @node_config, :log => @log ).execute
when :remove then
#RemoveImageCommand.new( @task.artifact, :log => @log ).execute
end
rescue => e
@log.error e
@log.error "An error occurred while executing task. See above for more info."
# TODO resend information about error or put this task back into queue
end

@log.info "Task handled."

end
end
end
Expand Down
8 changes: 5 additions & 3 deletions lib/boxgrinder-node/helpers/queue-helper.rb
Expand Up @@ -23,15 +23,17 @@

module BoxGrinder
class QueueHelper
def initialize( options = {} )
def initialize( node_config, options = {} )
@node_config = node_config

@log = options[:log] || Logger.new(STDOUT)
end

def enqueue( queue_name, object, host = 'localhost', port = 1099 )
def enqueue( queue_name, object, host = @node_config.naming_host, port = @node_config.naming_port )
@log.info "Putting new message into queue '#{queue_name}'."
@log.debug "Message: #{object}."

TorqueBox::Messaging::Client.connect( :naming_provider_url => "jnp://#{host}:#{port}/" ) { |client| client.send( queue_name, :object => object ) }
TorqueBox::Messaging::Client.connect( :naming_provider_url => "jnp://#{host}:#{port}/" ) { |client| client.send( queue_name, :object => object ) }

@log.info "Message put into queue."
end
Expand Down

0 comments on commit 13a9e41

Please sign in to comment.