def get(self): """ Retrieves the cached information about applications running in this AppScale deployment as a JSON-encoded dict. """ is_cloud_admin = AppDashboardHelper().is_user_cloud_admin() apps_user_is_admin_on = AppDashboardHelper().get_application_info() if not is_cloud_admin: apps_user_owns = AppDashboardHelper().get_owned_apps() new_app_dict = {} for app_name in apps_user_owns: if app_name in apps_user_is_admin_on: new_app_dict[app_name] = apps_user_is_admin_on.get(app_name) apps_user_is_admin_on = new_app_dict self.response.out.write(json.dumps(apps_user_is_admin_on))
def test_update_cookie_app_list(self): fake_user = flexmock() fake_user.should_receive('email').and_return('*****@*****.**') flexmock(users).should_receive('get_current_user') \ .and_return(fake_user) flexmock(AppDashboardHelper).should_receive('get_cookie_app_list') \ .and_return(['app1', 'app2']) flexmock(AppDashboardHelper).should_receive('set_appserver_cookie') \ .once() self.assertTrue(AppDashboardHelper().update_cookie_app_list( ['app1', 'app2', 'app3'], flexmock(), flexmock())) self.assertFalse(AppDashboardHelper().update_cookie_app_list( ['app1', 'app2'], flexmock(), flexmock()))
def get(self): """ Retrieves the cached information about applications running in this AppScale deployment as a JSON-encoded dict. """ is_cloud_admin = AppDashboardHelper().is_user_cloud_admin() all_versions = AppDashboardHelper().get_version_info() if is_cloud_admin: apps_user_owns = {version.split('_')[0] for version in all_versions} else: apps_user_owns = AppDashboardHelper().get_owned_apps() versions_user_is_admin_on = { version: all_versions[version] for version in all_versions if version.split('_')[0] in apps_user_owns} self.response.out.write(json.dumps(versions_user_is_admin_on))
def test_get_user_app_list(self): flexmock(AppDashboardHelper).should_receive('query_user_data') \ .and_return('\napplications:app1:app2\n') output = AppDashboardHelper().get_user_app_list('*****@*****.**') self.assertTrue(len(output) == 2) self.assertEquals('app1', output[0]) self.assertEquals('app2', output[1])
def get_status_info(self): """ Queries our local AppController to get server-level information about every server running in this AppScale deployment. Returns: A list of dicts, where each dict contains VM-level info (e.g., CPU, memory, disk usage) about that machine. The empty list is returned if there was a problem retrieving this information. """ cluster_stats = self.setUpClusterStats() statuses = AppDashboardHelper().get_status_info() test_statuses = [] for node in cluster_stats: cpu_usage = 100.0 - node['cpu']['idle'] total_memory = node['memory']['available'] + node['memory']['used'] memory_usage = round(100.0 * node['memory']['used'] / total_memory, 1) total_disk = 0 total_used = 0 for disk in node['disk']: for _, disk_info in disk.iteritems(): total_disk += disk_info['free'] + disk_info['used'] total_used += disk_info['used'] disk_usage = round(100.0 * total_used / total_disk, 1) test_statuses.append({'ip': node['public_ip'], 'cpu': str(cpu_usage), 'memory': str(memory_usage), 'disk': str(disk_usage), 'roles': node['roles'], 'key': str(node['public_ip']).translate(None, '.')}) self.assertEqual(statuses, test_statuses)
def test_get_cookie_app_list(self): request = flexmock() request.cookies = { AppDashboardHelper.DEV_APPSERVER_LOGIN_COOKIE : urllib.quote('[email protected]:a:app1,app2:FAKEHASH') } output = AppDashboardHelper().get_cookie_app_list(request) self.assertTrue( len(output) == 2 ) self.assertEquals('app1', output[0] ) self.assertEquals('app2', output[1] )
def __init__(self, helper=None): """ Creates a new AppDashboard, which will cache SOAP-exposed information provided to us by the AppDashboardHelper. Args: helper: An AppDashboardHelper, which will perform SOAP calls to the AppController whenever the AppDashboardData needs to update its caches. If None is provided here, then the AppDashboardData will create a new AppDashboardHelper to talk to the AppController. """ self.helper = helper or AppDashboardHelper()
def __init__(self, request, response): """ Constructor. Args: request: The webapp2.Request object that contains information about the current web request. response: The webapp2.Response object that contains the response to be sent back to the browser. """ self.initialize(request, response) self.helper = AppDashboardHelper() self.dstore = AppDashboardData(self.helper)
def get_instance_info(self, app_id): """ Queries the AppController to get instance information for a given app_id """ self.setUpInstanceStats() instance_info = AppDashboardHelper().get_instance_info('test1') test1_instance_stats = [{ 'host': '1.1.1.1', 'port': 0000, 'language': 'python' }, { 'host': '1.1.1.1', 'port': 0001, 'language': 'python' }, { 'host': '1.1.1.1', 'port': 0002, 'language': 'python' }]
def get_version_info(self): """ Queries the AppController for information about active versions. Returns: A dictionary mapping version keys to serving URLs. A None value indicates that the version is still loading. """ version_info = { 'test1_default_v1': ['http://1.1.1.1:1', 'https://1.1.1.1:1'], 'test2_default_v1': ['http://1.1.1.1:2', 'https://1.1.1.1:2'] } flexmock(AppDashboardHelper) AppDashboardHelper.should_receive('get_login_host').and_return('1.1.1.1') AppDashboardHelper.should_receive('get_version_ports').and_return([1, 1])\ .and_return([2, 2]) self.setUpClusterStats() app_info = AppDashboardHelper().get_version_info() self.assertEqual(app_info, version_info)
def get_application_info(self): """ Queries the AppController for information about which Google App Engine applications are currently running, and if they are done loading, the URL that they can be accessed at. Returns: A dict, where each key is a str indicating the name of a Google App Engine application running in this deployment, and each value is either a str indicating the URL that the app can be found at, or None, if the application is still loading. """ application_info = { "test1": ["http://1.1.1.1:1", "https://1.1.1.1:1"], "test2": ["http://1.1.1.1:2", "https://1.1.1.1:2"] } flexmock(AppDashboardHelper) AppDashboardHelper.should_receive('get_login_host').and_return( '1.1.1.1') AppDashboardHelper.should_receive('get_version_ports').and_return([1, 1])\ .and_return([2, 2]) self.setUpClusterStats() app_info = AppDashboardHelper().get_application_info() self.assertEqual(app_info, application_info)
def get(self): """ Retrieves the cached information about machine-level statistics as a JSON-encoded dict. """ self.response.out.write(json.dumps(AppDashboardHelper().get_status_info()))