#NEWLINE# @ classmethod #NEWLINE# def upload_app( cls , options ) : #NEWLINE# #INDENT# 'Uploads the given App Engine application into AppScale.\n\n    Args:\n      options: A Namespace that has fields for each parameter that can be\n        passed in via the command-line interface.\n    Returns:\n      A tuple containing the host and port where the application is serving\n        traffic from.\n    ' #NEWLINE# if cls . TAR_GZ_REGEX . search ( options . file ) : #NEWLINE# #INDENT# file_location = LocalState . extract_tgz_app_to_dir ( options . file , options . verbose ) #NEWLINE# created_dir = True #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if cls . ZIP_REGEX . search ( options . file ) : #NEWLINE# #INDENT# file_location = LocalState . extract_zip_app_to_dir ( options . file , options . verbose ) #NEWLINE# created_dir = True #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if os . path . isdir ( options . file ) : #NEWLINE# #INDENT# file_location = options . file #NEWLINE# created_dir = False #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise AppEngineConfigException ( '{0} is not a tar.gz file, a zip file, or a directory. Please try uploading either a tar.gz file, a zip file, or a directory.' . format ( options . file ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# try : #NEWLINE# #INDENT# app_id = AppEngineHelper . get_app_id_from_app_config ( file_location ) #NEWLINE# #UNINDENT# except AppEngineConfigException as config_error : #NEWLINE# #INDENT# AppScaleLogger . log ( config_error ) #NEWLINE# if ( 'yaml' in str ( config_error ) ) : #NEWLINE# #INDENT# raise config_error #NEWLINE# #UNINDENT# file_location = ( ( file_location + os . sep ) + '..' ) #NEWLINE# app_id = AppEngineHelper . get_app_id_from_app_config ( file_location ) #NEWLINE# #UNINDENT# app_language = AppEngineHelper . get_app_runtime_from_app_config ( file_location ) #NEWLINE# AppEngineHelper . validate_app_id ( app_id ) #NEWLINE# if ( app_language == 'java' ) : #NEWLINE# #INDENT# if AppEngineHelper . is_sdk_mismatch ( file_location ) : #NEWLINE# #INDENT# AppScaleLogger . warn ( ( ( ( ( 'AppScale did not find the correct SDK jar ' + 'versions in your app. The current supported ' ) + 'SDK version is ' ) + AppEngineHelper . SUPPORTED_SDK_VERSION ) + '.' ) ) #NEWLINE# #UNINDENT# #UNINDENT# login_host = LocalState . get_login_host ( options . keyname ) #NEWLINE# secret_key = LocalState . get_secret_key ( options . keyname ) #NEWLINE# acc = AppControllerClient ( login_host , secret_key ) #NEWLINE# if options . test : #NEWLINE# #INDENT# username = LocalState . DEFAULT_USER #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if options . email : #NEWLINE# #INDENT# username = options . email #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# username = LocalState . get_username_from_stdin ( is_admin = False ) #NEWLINE# #UNINDENT# #UNINDENT# if ( not acc . does_user_exist ( username ) ) : #NEWLINE# #INDENT# password = LocalState . get_password_from_stdin ( ) #NEWLINE# RemoteHelper . create_user_accounts ( username , password , login_host , options . keyname , clear_datastore = False ) #NEWLINE# #UNINDENT# app_exists = acc . does_app_exist ( app_id ) #NEWLINE# app_admin = acc . get_app_admin ( app_id ) #NEWLINE# if ( ( app_admin is not None ) and ( username != app_admin ) ) : #NEWLINE# #INDENT# raise AppScaleException ( ( ( "The given user doesn't own this application" + ", so they can't upload an app with that application ID. Please " ) + 'change the application ID and try again.' ) ) #NEWLINE# #UNINDENT# if app_exists : #NEWLINE# #INDENT# AppScaleLogger . log ( 'Uploading new version of app {0}' . format ( app_id ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# AppScaleLogger . log ( 'Uploading initial version of app {0}' . format ( app_id ) ) #NEWLINE# acc . reserve_app_id ( username , app_id , app_language ) #NEWLINE# #UNINDENT# if ( app_language == 'python27' ) : #NEWLINE# #INDENT# AppScaleLogger . log ( 'Ignoring .pyc files' ) #NEWLINE# #UNINDENT# remote_file_path = RemoteHelper . copy_app_to_host ( file_location , options . keyname , options . verbose ) #NEWLINE# acc . done_uploading ( app_id , remote_file_path ) #NEWLINE# acc . update ( [ app_id ] ) #NEWLINE# AppScaleLogger . log ( 'Please wait for your app to start serving.' ) #NEWLINE# if app_exists : #NEWLINE# #INDENT# time . sleep ( 20 ) #NEWLINE# #UNINDENT# sleep_time = ( 2 * cls . SLEEP_TIME ) #NEWLINE# current_app = None #NEWLINE# for i in range ( cls . MAX_RETRIES ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# result = acc . get_all_stats ( ) #NEWLINE# json_result = json . loads ( result ) #NEWLINE# apps_result = json_result [ 'apps' ] #NEWLINE# current_app = apps_result [ app_id ] #NEWLINE# http_port = current_app [ 'http' ] #NEWLINE# break #NEWLINE# #UNINDENT# except ValueError : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# except KeyError : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# AppScaleLogger . verbose ( 'Waiting {0} second(s) for a port to be assigned to {1}' . format ( sleep_time , app_id ) , options . verbose ) #NEWLINE# time . sleep ( sleep_time ) #NEWLINE# #UNINDENT# if ( not current_app ) : #NEWLINE# #INDENT# raise AppScaleException ( 'Unable to get the serving port for the application.' ) #NEWLINE# #UNINDENT# RemoteHelper . sleep_until_port_is_open ( login_host , http_port , options . verbose ) #NEWLINE# AppScaleLogger . success ( ( 'Your app can be reached at the following URL: ' + 'http://{0}:{1}' . format ( login_host , http_port ) ) ) #NEWLINE# if created_dir : #NEWLINE# #INDENT# shutil . rmtree ( file_location ) #NEWLINE# #UNINDENT# return ( login_host , http_port )