diff --git a/env/sunstone/public/js/user-plugins/apptools.appenv-dashboard.js b/env/sunstone/public/js/user-plugins/apptools.appenv-dashboard.js index b8fa374a71..2dfcf4dfdb 100644 --- a/env/sunstone/public/js/user-plugins/apptools.appenv-dashboard.js +++ b/env/sunstone/public/js/user-plugins/apptools.appenv-dashboard.js @@ -13,22 +13,67 @@ // limitations under the License. // //--------------------------------------------------------------------------// +function updateAppEnvDashboard(what, json_info){ + var db = $('#appenv_dashboard_tab',main_tabs_context); + switch (what){ + case "environments": + var total_envs=json_info.length; + $('#appenv_total_environments',db).html(total_envs); + break; + }; +} + var appenv_dashboard_tmpl = '\ \ \ -\ +
\ +\ +\ + \ + \ + \ + \ + \ + \ +
\ +
\ +

' + tr("Summary of AppEnv resources") + '

\ +
\ +\ + \ + \ + \ + \ + \ +
Environments
\ +\ +
\ +
\ +
\ +
\ +

' + tr("Quickstart") + '

\ +
\ + \ +
\ +
\ +
\ +
\ \ \ \ diff --git a/env/sunstone/public/js/user-plugins/apptools.appenv.js b/env/sunstone/public/js/user-plugins/apptools.appenv.js index 8c6b582a5d..36de017c9e 100644 --- a/env/sunstone/public/js/user-plugins/apptools.appenv.js +++ b/env/sunstone/public/js/user-plugins/apptools.appenv.js @@ -417,7 +417,7 @@ var appenv_info_panel = { } var appenvs_tab = { - title: "AppEnv", + title: "Environments", content: appenv_tab_content, buttons: appenv_buttons, tabClass: 'subTab', @@ -479,6 +479,7 @@ function updateAppEnvsView(request, appenvs_list){ updateView(appenv_list_array,dataTable_appenvs); //updateVResDashboard("images",images_list); + updateAppEnvDashboard('environments', appenv_list_array); } // Callback to update the information panel tabs and pop it up diff --git a/flow/controllers/appflow-server.rb b/flow/controllers/appflow-server.rb index b009ed50eb..4ea16b95d9 100644 --- a/flow/controllers/appflow-server.rb +++ b/flow/controllers/appflow-server.rb @@ -121,7 +121,7 @@ get '/service' do end status 200 - #body Parser.render(service_pool) + body service_pool.to_json end @@ -135,7 +135,7 @@ get '/service/:id' do end status 200 - #body Parser.render(service) + body service.to_json end @@ -246,7 +246,6 @@ get '/service_template' do status 200 - #body Parser.render(s_template_pool) body s_template_pool.to_json end @@ -260,7 +259,6 @@ get '/service_template/:id' do status 200 - #body Parser.render(rc) body service_template.to_json end @@ -273,22 +271,9 @@ delete '/service_template/:id' do end status 201 - - #body Parser.render(rc) - #body service_template.to_json end post '/service_template' do - #template = Parser.json_to_hash(request.body.read) - - #begin - # Validator.validate(template) - #rescue - # error 403, - #end - - #template_xml = Parser.hash_to_xml(template) - s_template = OpenNebula::ServiceTemplate.new( OpenNebula::ServiceTemplate.build_xml, @client) @@ -332,7 +317,6 @@ post '/service_template/:id/action' do service.info - #body Parser.render(rc) body service.to_json when 'chown' if opts && opts['uid'] diff --git a/flow/install.sh b/flow/install.sh index 3d1aa2de19..3cef318c58 100755 --- a/flow/install.sh +++ b/flow/install.sh @@ -98,6 +98,7 @@ copy_files "sunstone/routes/*" "$SUNSTONE_LOCATION/routes" # Do not link the ETC files LINK="no" +copy_files "sunstone/etc/sunstone-appflow.conf" "$ETC_LOCATION" copy_files "config/appflow-server.conf" "$ETC_LOCATION" diff --git a/flow/lib/log.rb b/flow/lib/log.rb index 47a0dad4d5..9d6f4b70dc 100644 --- a/flow/lib/log.rb +++ b/flow/lib/log.rb @@ -22,6 +22,8 @@ class Log # Log.info("LCM", "Service 3 started", 3), it will be written in a # specific log for service number 3 + LOG_COMP = "LOG" + DEBUG_LEVEL = [ Logger::ERROR, # 0 Logger::WARN, # 1 @@ -129,13 +131,17 @@ class Log return true end - # TBD capture exception - open("#{LOG_LOCATION}/appflow/#{service_id}.log", 'a') do |f| - f << MSG_FORMAT % [ - Time.now.strftime(DATE_FORMAT), - Logger::SEV_LABEL[severity][0..0], - component, - message ] + begin + open("#{LOG_LOCATION}/appflow/#{service_id}.log", 'a') do |f| + f << MSG_FORMAT % [ + Time.now.strftime(DATE_FORMAT), + Logger::SEV_LABEL[severity][0..0], + component, + message ] + end + rescue => e + message = "Could not log into #{LOG_LOCATION}/appflow/#{service_id}.log: #{e.message}" + error LOG_COMP, message end end diff --git a/flow/sunstone/etc/sunstone-appflow.conf b/flow/sunstone/etc/sunstone-appflow.conf new file mode 100644 index 0000000000..188a091b56 --- /dev/null +++ b/flow/sunstone/etc/sunstone-appflow.conf @@ -0,0 +1,7 @@ +################################################################################ +# Appflow +################################################################################ + +# Appflow endpoint +# +:appflow_server: http://localhost:2474/ \ No newline at end of file diff --git a/flow/sunstone/public/js/user-plugins/apptools.appflow-dashboard.js b/flow/sunstone/public/js/user-plugins/apptools.appflow-dashboard.js index 41100d112a..0699e81ab9 100644 --- a/flow/sunstone/public/js/user-plugins/apptools.appflow-dashboard.js +++ b/flow/sunstone/public/js/user-plugins/apptools.appflow-dashboard.js @@ -13,22 +13,73 @@ // limitations under the License. // //--------------------------------------------------------------------------// +function updateAppFlowDashboard(what, json_info){ + var db = $('#appflow_dashboard_tab',main_tabs_context); + switch (what){ + case "templates": + $('#appflow_total_templates',db).html(json_info.length); + break; + case "services": + $('#appflow_total_services',db).html(json_info.length); + break; + }; +} + var appflow_dashboard_tmpl = '\
\
\ -

' + tr("AppEnv - A tool to manage environments") + '

\ +

' + tr("AppEnv") + '

\
\ -\ -

appenv logoAppEnv performs the automatic installation and configuration of the software stack that constitutes an application environment. With AppEnv you can easily define software configurations for your VMs and share them with other users.

\ -

 

\ -

 

\ -

 

\ -

 

\ +

\ + appenv logo\ + AppEnv performs the automatic installation and configuration of the software stack that constitutes an application environment. With AppEnv you can easily define software configurations for your VMs and share them with other users.\ +

\ +

'+tr("You can find further information on the following links:")+'

\ + \
\
\
\ \ -\ +
\ +\ +\ + \ + \ + \ + \ + \ + \ +
\ +
\ +

' + tr("Summary of AppFlow resources") + '

\ +
\ +\ + \ + \ + \ + \ + \ + \ + \ + \ + \ +
Templates
Services
\ +\ +
\ +
\ +
\ +
\ +

' + tr("Quickstart") + '

\ + \ +
\ +
\ +
\ \ \ \ diff --git a/flow/sunstone/public/js/user-plugins/apptools.appflow.services.js b/flow/sunstone/public/js/user-plugins/apptools.appflow.services.js index 132010b09d..8bba09a124 100644 --- a/flow/sunstone/public/js/user-plugins/apptools.appflow.services.js +++ b/flow/sunstone/public/js/user-plugins/apptools.appflow.services.js @@ -429,6 +429,7 @@ function updateServicesView(request, services_list){ updateView(service_list_array,dataTable_services); //updateVResDashboard("images",images_list); + updateAppFlowDashboard('services', service_list_array); } // Callback to refresh the list of Virtual Machines diff --git a/flow/sunstone/public/js/user-plugins/apptools.appflow.templates.js b/flow/sunstone/public/js/user-plugins/apptools.appflow.templates.js index 61fdd3edc1..0b76aa9a3e 100644 --- a/flow/sunstone/public/js/user-plugins/apptools.appflow.templates.js +++ b/flow/sunstone/public/js/user-plugins/apptools.appflow.templates.js @@ -435,6 +435,7 @@ function updateServiceTemplatesView(request, service_templates_list){ updateView(service_template_list_array,dataTable_service_templates); //updateVResDashboard("images",images_list); + updateAppFlowDashboard('templates', service_template_list_array); } // Callback to update the information panel tabs and pop it up diff --git a/flow/sunstone/routes/appflow.rb b/flow/sunstone/routes/appflow.rb index 87b5730278..acaba258ab 100644 --- a/flow/sunstone/routes/appflow.rb +++ b/flow/sunstone/routes/appflow.rb @@ -1,24 +1,36 @@ +APPFLOW_CONF_FILE = ETC_LOCATION + "/sunstone-appflow.conf" + $: << RUBY_LIB_LOCATION+"/apptools/flow" require 'appflow_client' +begin + appflow_conf = YAML.load_file(APPFLOW_CONF_FILE) +rescue Exception => e + STDERR.puts "Error parsing config file #{APPFLOW_CONF_FILE}: #{e.message}" + exit 1 +end + +set :appflow_config, appflow_conf + helpers do - def build_client + def af_build_client flow_client = settings.cloud_auth.client(session[:user]) split_array = flow_client.one_auth.split(':') Service::Client.new( - :url => settings.config[:appflow_server], + :url => settings.appflow_config[:appflow_server], :user_agent => "Sunstone", :username => split_array.shift, :password => split_array.join(':')) end - def format_response(resp) + def af_format_response(resp) if CloudClient::is_error?(resp) logger.error("[AppFlow] " + resp.to_s) - # TBD format error messages in JSON - error 500, resp.to_s + + error = Error.new(resp.to_s) + error resp.code.to_i, error.to_json else body resp.body.to_s end @@ -30,35 +42,35 @@ end ############################################################################## get '/service' do - client = build_client + client = af_build_client resp = client.get('/service') - format_response(resp) + af_format_response(resp) end get '/service/:id' do - client = build_client + client = af_build_client resp = client.get('/service/' + params[:id]) - format_response(resp) + af_format_response(resp) end delete '/service/:id' do - client = build_client + client = af_build_client resp = client.delete('/service/' + params[:id]) - format_response(resp) + af_format_response(resp) end post '/service/:id/action' do - client = build_client + client = af_build_client resp = client.post('/service/' + params[:id] + '/action', request.body.read) - format_response(resp) + af_format_response(resp) end ############################################################################## @@ -66,41 +78,41 @@ end ############################################################################## get '/service_template' do - client = build_client + client = af_build_client resp = client.get('/service_template') - format_response(resp) + af_format_response(resp) end get '/service_template/:id' do - client = build_client + client = af_build_client resp = client.get('/service_template/' + params[:id]) - format_response(resp) + af_format_response(resp) end delete '/service_template/:id' do - client = build_client + client = af_build_client resp = client.delete('/service_template/' + params[:id]) - format_response(resp) + af_format_response(resp) end post '/service_template/:id/action' do - client = build_client + client = af_build_client resp = client.post('/service_template/' + params[:id] + '/action', request.body.read) - format_response(resp) + af_format_response(resp) end post '/service_template' do - client = build_client + client = af_build_client resp = client.post('/service_template', request.body.read) - format_response(resp) + af_format_response(resp) end \ No newline at end of file diff --git a/market/client/lib/appplace_client.rb b/market/client/lib/appmarket_client.rb similarity index 100% rename from market/client/lib/appplace_client.rb rename to market/client/lib/appmarket_client.rb diff --git a/market/install.sh b/market/install.sh index 925673d947..a7b47b2c18 100755 --- a/market/install.sh +++ b/market/install.sh @@ -96,5 +96,6 @@ copy_files "sunstone/routes/*" "$SUNSTONE_LOCATION/routes" # Do not link the ETC files LINK="no" +copy_files "sunstone/etc/sunstone-appmarket.conf" "$ETC_LOCATION" copy_files "config/appmarket-server.conf" "$ETC_LOCATION" diff --git a/market/sunstone/etc/sunstone-appmarket.conf b/market/sunstone/etc/sunstone-appmarket.conf new file mode 100644 index 0000000000..6a5a3b1086 --- /dev/null +++ b/market/sunstone/etc/sunstone-appmarket.conf @@ -0,0 +1,13 @@ +################################################################################ +# AppMarket +################################################################################ + +# AppMarket username and password +# If no credentials are provided, an anonymous client will be used +# +#:appmarket_username: +#:appmarket_password: + +# AppMarket endpoint +# +:appmarket_url: https://localhost:6242 \ No newline at end of file diff --git a/market/sunstone/public/js/user-plugins/appmarket.js b/market/sunstone/public/js/user-plugins/appmarket.js deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/market/sunstone/public/js/user-plugins/apptools.appmarket-dashboard.js b/market/sunstone/public/js/user-plugins/apptools.appmarket-dashboard.js index 31e26774af..a59c44d38b 100644 --- a/market/sunstone/public/js/user-plugins/apptools.appmarket-dashboard.js +++ b/market/sunstone/public/js/user-plugins/apptools.appmarket-dashboard.js @@ -13,22 +13,54 @@ // limitations under the License. // //--------------------------------------------------------------------------// +function updateAppMarketDashboard(what, json_info){ + var db = $('#appmarket_dashboard_tab',main_tabs_context); + switch (what){ + case "appliances": + $('#appmarket_total_appliances',db).html(json_info.length); + break; + }; +} + var appmarket_dashboard_tmpl = '\
\
\ -

' + tr("Appflow - A tool to manage environments") + '

\ +

' + tr("Appflow - A tool to manage environments") + '

\
\ -\ -

appflow logoAppFlow enables the automatic execution of multi-tiered applications. With AppFlow you can define multi-tier applications composed of interconnected VMs and manage them as a single entity.

\ -

 

\ -

 

\ -

 

\ -

 

\ +

\ + appflow logo\ + AppFlow enables the automatic execution of multi-tiered applications. With AppFlow you can define multi-tier applications composed of interconnected VMs and manage them as a single entity.\ +

\ +

'+tr("You can find further information on the following links:")+'

\ + \
\
\
\ \ -\ +
\ +\ +\ + \ + \ + \ +
\ +
\ +

' + tr("Summary of AppMarket resources") + '

\ +
\ +\ + \ + \ + \ + \ + \ +
Appliances
\ +\ +
\ +
\ +
\ +
\ \ \ \ diff --git a/market/sunstone/public/js/user-plugins/apptools.appmarket.appliances.js b/market/sunstone/public/js/user-plugins/apptools.appmarket.appliances.js new file mode 100644 index 0000000000..c8a4f3ad4f --- /dev/null +++ b/market/sunstone/public/js/user-plugins/apptools.appmarket.appliances.js @@ -0,0 +1,316 @@ +/* -------------------------------------------------------------------------- */ +/* Copyright 2010-2012, C12G Labs S.L */ +/* */ +/* Licensed under the Apache License, Version 2.0 (the "License"); you may */ +/* not use this file except in compliance with the License. You may obtain */ +/* a copy of the License at */ +/* */ +/* http://www.apache.org/licenses/LICENSE-2.0 */ +/* */ +/* Unless required by applicable law or agreed to in writing, software */ +/* distributed under the License is distributed on an "AS IS" BASIS, */ +/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */ +/* See the License for the specific language governing permissions and */ +/* limitations under the License. */ +/* -------------------------------------------------------------------------- */ + +/* Marketpplace tab plugin */ +var dataTable_appmarket; + +var AppMarket = { + "resource" : "APPMARKET", + + "show" : function(params){ + OpenNebula.Action.show(params,AppMarket.resource); + }, + "list" : function(params){ + //Custom list request function, since the contents do not come + //in the same format as the rest of opennebula resources. + var callback = params.success; + var callback_error = params.error; + var timeout = params.timeout || false; + var request = OpenNebula.Helper.request('APPMARKET','list'); + + $.ajax({ + url: 'appmarket', + type: 'GET', + data: {timeout: timeout}, + dataType: "json", + success: function(response){ + return callback ? + callback(request, response) : null; + }, + error: function(res){ + return callback_error ? callback_error(request, OpenNebula.Error(res)) : null; + } + }); + } +} +var appmarket_actions = { + "AppMarket.list" : { + type: "list", + call: AppMarket.list, + callback: function(req,res){ + //data can be added to the table directly, without further + //processing + updateView(res.appliances,dataTable_appmarket); + updateAppMarketDashboard('appliances', res.appliances); + }, + error: onError + }, + "AppMarket.refresh" : { + type: "custom", + call: function () { + waitingNodes(dataTable_appmarket); + Sunstone.runAction('AppMarket.list'); + } + }, + "AppMarket.import" : { + //fetches images information and fills in the image creation + //dialog with it. + type: "multiple", + elements: appmarketplaceElements, + call: AppMarket.show, + callback: function(request,response){ + $('#img_name', $create_image_dialog).val(response['name']); + $('#img_path', $create_image_dialog).val(response['links']['download']['href']); + $('#src_path_select input[value="path"]', $create_image_dialog).trigger('click'); + $('select#img_type', $create_image_dialog).val('OS'); + $('select#img_type', $create_image_dialog).trigger('change'); + + //remove any options from the custom vars dialog box + $("#custom_var_image_box",$create_image_dialog).empty(); + + var md5 = response['files'][0]['md5'] + if ( md5 ) { + option = ''; + $("#custom_var_image_box",$create_image_dialog).append(option); + } + + var sha1 = response['files'][0]['sha1'] + if ( sha1 ) { + option = ''; + $("#custom_var_image_box",$create_image_dialog).append(option); + } + + popUpCreateImageDialog(); + }, + error: onError + }, + "AppMarket.showinfo" : { + type: "single", + call: AppMarket.show, + callback: updateMarketInfo, + error: onError + } +} + +var appmarket_buttons = { + "AppMarket.refresh" : { + type: "action", + text: '', + alwaysActive: true + }, + "AppMarket.import" : { + type: "action", + text: tr('Import to local infrastructure') + } +}; + +var appmarketplace_tab_content = '\ +

'+tr("OpenNebula AppMarket")+'

\ +
\ +
\ +
\ +
\
\ -

' + tr("AppEnv - Image repository") + '

\ +

' + tr("AppMarket") + '

\
\ -\ -

appflow logoAppMarket builds a centralized catalog of cloud applications. With AppMarket you can build a private repository to share and distribute virtual appliances across OpenNebula instances.

\ -

 

\ -

 

\ -

 

\ -

 

\ +

\ + appmarket logo\ + AppMarket builds a centralized catalog of cloud applications. With AppMarket you can build a private repository to share and distribute virtual appliances across OpenNebula instances.\ +

\ +

'+tr("You can find further information on the following links:")+'

\ + \
\
\
\ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ +
'+tr("ID")+''+tr("Name")+''+tr("Publisher")+''+tr("Hypervisor")+''+tr("Arch")+''+tr("Format")+''+tr("Tags")+'
\ +'; + + +var appmarketplace_tab = { + title: "Appliances", + content: appmarketplace_tab_content, + buttons: appmarket_buttons, + tabClass: 'subTab', + parentTab: 'appmarket_dashboard_tab' +} + +Sunstone.addMainTab('appmarketplace_tab', appmarketplace_tab); +Sunstone.addActions(appmarket_actions); + + +/* + * INFO PANEL + */ + +var appmarketplace_info_panel = { + "appmarketplace_info_tab" : { + title: tr("Appliance information"), + content:"" + } +}; + +Sunstone.addInfoPanel("appmarketplace_info_panel", appmarketplace_info_panel); + +function appmarketplaceElements(){ + return getSelectedNodes(dataTable_appmarket); +} + +function updateMarketInfo(request,app){ + var info_tab = { + title : tr("Appliance information"), + content : + '\ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ +
'+tr("Appliance information")+'
' + tr("ID") + ''+app['_id']["$oid"]+'
' + tr("URL") + ''+config_response.system_config.appmarketplace_url+'/'+app['_id']["$oid"]+'
' + tr("Publisher") + ''+app['publisher']+'
' + tr("Downloads") + ''+app['downloads']+'
' + tr("OS") + ''+app['files'][0]['os-id']+' '+app['files'][0]['os-release']+'
' + tr("Arch") + ''+app['files'][0]['os-arch']+'
' + tr("Size") + ''+humanize_size(app['files'][0]['size'],true)+'
' + tr("Hypervisor") + ''+app['files'][0]['hypervisor']+'
\ + \ + \ + \ + \ + \ + \ + \ + \ + \ +
'+tr("Description")+'
'+app['description'].replace(/\n/g, "
")+'
' + }; + + Sunstone.updateInfoPanelTab("appmarketplace_info_panel", "appmarketplace_info_tab", info_tab); + Sunstone.popUpInfoPanel("appmarketplace_info_panel"); +}; + +function infoListenerMarket(dataTable){ + $('tbody tr',dataTable).live("click",function(e){ + if ($(e.target).is('input')) {return true;} + + var aData = dataTable.fnGetData(this); + var id = aData["_id"]["$oid"]; + if (!id) return true; + + var count = $('tbody .check_item:checked', dataTable).length; + + //If ctrl is pressed we check the column instead of + //doing showinfo() + if (e.ctrlKey || count >= 1){ + $('.check_item',this).trigger('click'); + return false; + } + + popDialogLoading(); + + Sunstone.runAction('AppMarket.showinfo',id); + return false; + }); +} + + +/* + * onlyOneCheckboxListener: Only one box can be checked + */ + +function onlyOneCheckboxListener(dataTable) { + $('tbody input.check_item', dataTable).live("change", function(){ + var checked = $(this).is(':checked'); + $('input.check_item:checked', dataTable).removeAttr('checked'); + $(this).attr('checked', checked); + }); +} + +/* + * Document + */ + +$(document).ready(function(){ + dataTable_appmarket = $("#datatable_appmarketplace", main_tabs_context).dataTable({ + "bJQueryUI": true, + "bSortClasses": false, + "sPaginationType": "full_numbers", + "sDom" : '<"H"lfrC>t<"F"ip>', + "bAutoWidth":false, + "aoColumns": [ + { "bSortable": false, + "fnRender": function ( o, val ) { + //we render 1st column as a checkbox directly + return '' + }, + "sWidth" : "60px" + }, + { "mDataProp": "_id.$oid", "bVisible": false, "sWidth" : "200px" }, + { "mDataProp": "name" }, + { "mDataProp": "publisher" }, + { "mDataProp": "files.0.hypervisor", "sWidth" : "100px"}, + { "mDataProp": "files.0.os-arch", "sWidth" : "100px"}, + { "mDataProp": "files.0.format", "sWidth" : "100px"}, + { "mDataProp": "tags", "bVisible": false} + ], + "oLanguage": (datatable_lang != "") ? + { + sUrl: "locale/"+lang+"/"+datatable_lang + } : "" + }); + + + tableCheckboxesListener(dataTable_appmarket); + onlyOneCheckboxListener(dataTable_appmarket); + + infoListenerMarket(dataTable_appmarket); + + Sunstone.runAction('AppMarket.list'); +}); \ No newline at end of file diff --git a/market/sunstone/routes/appmarket.rb b/market/sunstone/routes/appmarket.rb index e69de29bb2..e725f4071c 100644 --- a/market/sunstone/routes/appmarket.rb +++ b/market/sunstone/routes/appmarket.rb @@ -0,0 +1,49 @@ +APPMARKET_CONF_FILE = ETC_LOCATION + "/sunstone-appmarket.conf" + +$: << RUBY_LIB_LOCATION+"/apptools/market" + +require 'appmarket_client' + +begin + appmarket_conf = YAML.load_file(APPMARKET_CONF_FILE) +rescue Exception => e + STDERR.puts "Error parsing config file #{APPMARKET_CONF_FILE}: #{e.message}" + exit 1 +end + +set :appmarket_config, appmarket_conf + +helpers do + def am_build_client + Market::ApplianceClient.new( + settings.appmarket_config[:appmarket_username], + settings.appmarket_config[:appmarket_password], + settings.appmarket_config[:appmarket_url], + "Sunstone") + end + + def am_format_response(response) + if CloudClient::is_error?(response) + error = Error.new(response.to_s) + [response.code.to_i, error.to_json] + else + [200, response.body] + end + end +end + +get '/appmarket' do + client = am_build_client + + response = client.list + + am_format_response(response) +end + +get '/appmarket/:id' do + client = am_build_client + + response = client.show(params[:id]) + + am_format_response(response) +end \ No newline at end of file