def cartridge_post
raise OpenShift::UserException.new("Invalid user", 99) if @cloud_user.nil?
case @req.action
when 'configure'
apps = @cloud_user.applications
domain = @cloud_user.domains.first
app = Application.new(@cloud_user, @req.app_name, nil, @req.node_profile, @req.cartridge, nil, false, domain)
check_cartridge_type(@req.cartridge, "standalone")
if (@cloud_user.consumed_gears >= @cloud_user.max_gears)
raise OpenShift::UserException.new("#{@login} has already reached the gear limit of #{@cloud_user.max_gears}", 104)
end
raise OpenShift::UserException.new("The supplied application name '#{app.name}' is not allowed", 105) if OpenShift::ApplicationContainerProxy.blacklisted? app.name
if app.valid?
begin
app.user_agent = request.headers["User-Agent"]
Rails.logger.debug "Creating application #{app.name}"
@reply.append app.create
Rails.logger.debug "Configuring dependencies #{app.name}"
@reply.append app.configure_dependencies
app.execute_connections
begin
@reply.append app.create_dns
case app.framework_cartridge
when 'php'
page = 'health_check.php'
when 'perl'
page = 'health_check.pl'
else
page = 'health'
end
@reply.data = {:health_check_path => page, :uuid => app.uuid}.to_json
rescue Exception => e
@reply.append app.destroy_dns
raise
end
rescue Exception => e
log_action(@request_id, @cloud_user.uuid, @login, "LEGACY_CREATE_APP", false, "Failed to create application #{app.name}: #{e.message}")
@reply.append app.destroy
if app.persisted?
app.delete
end
@reply.resultIO = StringIO.new(e.message)
raise
end
log_action(@request_id, @cloud_user.uuid, @login, "LEGACY_CREATE_APP", true, "Created application #{app.name}")
@reply.resultIO << "Successfully created application: #{app.name}" if @reply.resultIO.length == 0
else
log_action(@request_id, @cloud_user.uuid, @login, "LEGACY_CREATE_APP", false, "Invalid application: #{app.errors.first[1][:message]}")
@reply.resultIO << app.errors.first[1][:message]
@reply.exitcode = app.errors.first[1][:exit_code]
render :json => @reply, :status => :bad_request
return
end
when 'deconfigure'
app = get_app_from_request(@cloud_user)
@reply.append app.cleanup_and_delete
@reply.resultIO << "Successfully destroyed application: #{app.name}"
when 'start'
app = get_app_from_request(@cloud_user)
@reply.append app.start(app.framework)
when 'stop'
app = get_app_from_request(@cloud_user)
@reply.append app.stop(app.framework)
when 'restart'
app = get_app_from_request(@cloud_user)
@reply.append app.restart(app.framework)
when 'force-stop'
app = get_app_from_request(@cloud_user)
@reply.append app.force_stop(app.framework)
when 'reload'
app = get_app_from_request(@cloud_user)
@reply.append app.reload(app.framework)
when 'status'
app = get_app_from_request(@cloud_user)
@reply.append app.status(app.framework)
when 'tidy'
app = get_app_from_request(@cloud_user)
@reply.append app.tidy(app.framework)
when 'add-alias'
app = get_app_from_request(@cloud_user)
@reply.append app.add_alias @req.server_alias
when 'remove-alias'
app = get_app_from_request(@cloud_user)
@reply.append app.remove_alias @req.server_alias
when 'threaddump'
app = get_app_from_request(@cloud_user)
@reply.append app.threaddump(app.framework)
when 'expose-port'
app = get_app_from_request(@cloud_user)
@reply.append app.expose_port(app.framework)
when 'conceal-port'
app = get_app_from_request(@cloud_user)
@reply.append app.conceal_port(app.framework)
when 'show-port'
app = get_app_from_request(@cloud_user)
@reply.append app.show_port(app.framework)
when 'system-messages'
app = get_app_from_request(@cloud_user)
@reply.append app.system_messages
else
raise OpenShift::UserException.new("Invalid action #{@req.action}", 111)
end
@reply.resultIO << 'Success' if @reply.resultIO.length == 0
log_action(@request_id, @cloud_user.uuid, @login, "LEGACY_CARTRIDGE_POST", true, "Processed event #{@req.action} for application #{app.name}")
render :json => @reply
end