[hg] galaxy 3076: Fixed refreshing of the status of an instance ...
details: http://www.bx.psu.edu/hg/galaxy/rev/022ac0f64679 changeset: 3076:022ac0f64679 user: Enis Afgan <afgane@gmail.com> date: Wed Oct 28 16:35:36 2009 -0400 description: Fixed refreshing of the status of an instance and assocaited Galaxy web server on main Galaxy Cloud web page. diffstat: lib/galaxy/web/controllers/cloud.py | 54 +++++++++++---------------- templates/cloud/configure_cloud.mako | 55 ++++++++++++++------------- 2 files changed, 50 insertions(+), 59 deletions(-) diffs (194 lines): diff -r 7b642483d18c -r 022ac0f64679 lib/galaxy/web/controllers/cloud.py --- a/lib/galaxy/web/controllers/cloud.py Wed Oct 28 12:28:57 2009 -0400 +++ b/lib/galaxy/web/controllers/cloud.py Wed Oct 28 16:35:36 2009 -0400 @@ -3,6 +3,7 @@ import pkg_resources pkg_resources.require( "simplejson" ) import simplejson +import urllib2 from galaxy.tools.parameters import * from galaxy.tools import DefaultToolState @@ -597,30 +598,18 @@ except ValueError: pass - # Check if Amazon EC2 has already been registered by this user - ec2_registered = trans.sa_session.query( model.CloudProvider ).filter_by( user=user, type='ec2' ).first() - if region_name or region_endpoint or name or is_secure or port or proxy or debug or path: - log.debug (" in if ") if trans.app.model.CloudProvider \ .filter_by (user=user, name=name) \ .first(): - log.debug (" in if 2 ") error['name_error'] = "A provider with that name already exist." elif name=='' or len( name ) > 255: - log.debug (" in if 3") error['name_error'] = "Provider name must be between 1 and 255 characters long." elif type=='': - log.debug (" in if 4") error['type_error'] = "Provider type must be selected." - elif ec2_registered: - log.debug (" in if 5") - error['type_error'] = "Amazon EC2 has already been registered as a provider." elif not (is_secure == 0 or is_secure == 1): - log.debug (" in if 6") error['is_secure_error'] = "Field 'is secure' can only take on a value '0' or '1'" else: - log.debug (" in else ") provider = model.CloudProvider() provider.user = user provider.type = type @@ -712,26 +701,8 @@ @web.require_login( "add Amazon EC2 provider" ) def add_ec2( self, trans ): """ Default provider setup for Amazon's EC2. """ - user = trans.get_user() - # Check if EC2 has already been registered by this user. - exists = trans.sa_session.query( model.CloudProvider ) \ - .filter_by( user=user, type='ec2' ).first() - - if not exists: - self.add_provider( trans, name='Amazon EC2', type='ec2', region_name='us-east-1', region_endpoint='us-east-1.ec2.amazonaws.com', is_secure=1, path='/' ) - return self.add( trans ) -# providers = trans.sa_session.query( model.CloudProvider ).filter_by( user=user ).all() -# return trans.fill_template( "cloud/add_credentials.mako", -# credName = '', -# providerName = '', -# accessKey = '', -# secretKey = '', -# error = {}, -# providers = providers -# ) - - trans.show_error_message( "EC2 is already registered as a cloud provider under name '%s'." % exists.name ) - return self.list( trans ) + self.add_provider( trans, name='Amazon EC2', type='ec2', region_name='us-east-1', region_endpoint='us-east-1.ec2.amazonaws.com', is_secure=1, path='/' ) + return self.add( trans ) @web.json def json_update( self, trans ): @@ -751,6 +722,25 @@ insd[uci.name] = dict return insd + @web.json + def link_update( self, trans, uci_id=0 ): + ild = {} # instance-link-dict + dict = {} + dict['uci_id'] = uci_id + try: + user = trans.get_user() + # TODO: This query can assumes only one instance under given UCI can be running (i.e., started). + inst = trans.sa_session.query( model.CloudInstance ).filter_by( user=user, uci_id=uci_id, state=uci_states.RUNNING ).first() + urllib2.urlopen( "http://" + inst.public_dns ) + dict['public_dns'] = inst.public_dns + dict['inst_id'] = inst.id + ild['data'] = dict + return ild + except urllib2.URLError: + dict['public_dns'] = False + ild['data'] = dict + return ild + ## ---- Utility methods ------------------------------------------------------- def get_provider( trans, name ): diff -r 7b642483d18c -r 022ac0f64679 templates/cloud/configure_cloud.mako --- a/templates/cloud/configure_cloud.mako Wed Oct 28 12:28:57 2009 -0400 +++ b/templates/cloud/configure_cloud.mako Wed Oct 28 16:35:36 2009 -0400 @@ -23,13 +23,13 @@ function update_state() { $.getJSON( "${h.url_for( action='json_update' )}", {}, function ( data ) { for (var i in data) { - var elem = '#' + data[i].id; + var elem = '#' + data[i].id; // Because of different list managing 'live' vs. 'available' instances, refresh entire // page on necessary state change. old_state = $(elem + "-state").text(); new_state = data[i].state; - console.log( "old_state[%d] = %s", i, old_state ); - console.log( "new_state[%d] = %s", i, new_state ); + //console.log( "old_state[%d] = %s", i, old_state ); + //console.log( "new_state[%d] = %s", i, new_state ); if ( old_state=='pending' && new_state=='running' ) { location.reload(true); } @@ -51,11 +51,27 @@ else if ( new_state=='shutting-down' || new_state=='shutting-downUCI' ) { $(elem + "-link").text( "" ); } - // In order to show 'Access Galaxy' button, the whole page needs to be refreshed. So, while Galaxy is starting, - // keep refreshing the page. Should be handled better... - else if ( $(elem+"-link").text().search('starting') && old_state=='running' && new_state=='running' ) { - //location.reload(true); - $(elem + "-link").text("Still starting..."); + + // Check if Galaxy website is accessible on given instance; if so, provide link. Otherwise, wait more. + else if ( ( $(elem+"-link").text().match('starting') || $(elem+"-link").text()=='' ) && new_state=='running' ) { + //console.log ( 'elem.text: ' + $(elem+"-link").text() ); + $.getJSON( "${h.url_for( action='link_update' )}", { uci_id: data[i].id }, function ( data ) { + for (var i in data) { + var dns = data[i].public_dns; + var uci = '#' + data[i].uci_id; + if( !dns ) { + $(uci+"-link").text( 'Galaxy starting...' ); + // http://stackoverflow.com/questions/275931/how-do-you-make-an-element-flash-i... + $(uci+"-link").stop().animate({ fontSize: "14px" }, 1000).animate({ fontSize: "12px" }, 1000); + } + else { + $(uci+"-link").html( '<div align="right"><a class="action-button" href="http://'+dns+'" target="_blank">' + + '<span>Access Galaxy</span>'+ + '<img src="' + "${h.url_for( '/static/images/silk/resultset_next.png' )}" + '" /></div>' ); + $(uci+"-link").stop().animate({ fontSize: "14px" }, 1000).animate({ fontSize: "12px" }, 1000); + } + } + }); } // Update 'state' and 'time alive' fields @@ -67,6 +83,7 @@ $(elem + "-launch_time").text( "N/A" ); } } + console.log(''); }); setTimeout("update_state()", 15000); } @@ -74,6 +91,7 @@ $(function() { update_state(); }); + </script> </%def> @@ -176,25 +194,8 @@ context.write( ')' ) %> </td> - <td id="${ liveInstance.id }-link"><div align="right"> - %for j, instance in enumerate( liveInstance.instance ): - ## TODO: Once more instances will be running under the same liveInstance, additional logic will need to be added to account for that - %if instance.state == "running": - ## Wait until Galaxy server starts to show 'Access Galaxy' button - <% - import urllib2 - try: - urllib2.urlopen("http://"+instance.public_dns) - context.write( '<a class="action-button" href="http://'+instance.public_dns+'" target="_blank">' ) - context.write( '<span>Access Galaxy</span>' ) - context.write( '<img src="'+h.url_for('/static/images/silk/resultset_next.png')+'" /></a></div>' ) - except urllib2.URLError: - context.write( 'Galaxy starting...' ) - %> - - %endif - %endfor - </td> + ## Handled by JavaScript function + <td id="${ liveInstance.id }-link"></td> <td> <div popupmenu="li-${i}-popup"> <a class="action-button" confirm="Are you sure you want to stop instance '${liveInstance.name}'? Please note that this may take up to 1 minute during which time the page will not refresh." href="${h.url_for( action='stop', id=trans.security.encode_id(liveInstance.id) )}">Stop</a>
participants (1)
-
Greg Von Kuster