<s> import libinit <EOL> import probedb . standalone <EOL> import probedb . cluster . models as Cluster <EOL> import probedb . probedata2 . models as Probe <EOL> import os , os . path , time , subprocess , datetime <EOL> from optparse import OptionParser <EOL> from probedb . cluster . models import ClusterAction <EOL> from django . db import connection <EOL> """<STR_LIT>""" <EOL> computername = os . environ . get ( '<STR_LIT>' , "<STR_LIT>" ) . lower ( ) <EOL> if computername == "<STR_LIT>" : <EOL> computername = os . environ . get ( '<STR_LIT>' , "<STR_LIT>" ) . lower ( ) <EOL> if computername == "<STR_LIT>" : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> computername = computername . partition ( '<STR_LIT:.>' ) [ <NUM_LIT:0> ] <EOL> options_config = OptionParser ( ) <EOL> options_config . add_option ( "<STR_LIT>" , action = "<STR_LIT:store_true>" , dest = "<STR_LIT>" ) <EOL> options_config . add_option ( "<STR_LIT>" , action = "<STR_LIT:store_true>" , dest = "<STR_LIT>" ) <EOL> options_config . add_option ( "<STR_LIT>" , action = "<STR_LIT:store_true>" , dest = "<STR_LIT>" ) <EOL> options_config . add_option ( "<STR_LIT>" , action = "<STR_LIT:store_true>" , dest = "<STR_LIT>" ) <EOL> ( options , args ) = options_config . parse_args ( ) <EOL> while True : <EOL> terminate = False <EOL> master_configuration , created = Cluster . ClusterNode . objects . get_or_create ( hostname = "<STR_LIT>" , defaults = { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : True , <EOL> } ) <EOL> configuration , created = Cluster . ClusterNode . objects . get_or_create ( hostname = computername , defaults = { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : True , <EOL> } ) <EOL> configuration . save ( ) <EOL> for run in Cluster . ClusterRun . objects . filter ( enabled = True ) . order_by ( "<STR_LIT>" , "<STR_LIT>" ) . iterator ( ) : <EOL> """<STR_LIT>""" <EOL> if run . perform_run . probequeue_set . filter ( state = Probe . ProbeQueue . PROBEQ_IDLE ) . count ( ) == <NUM_LIT:0> : <EOL> run . enabled = False <EOL> run . save ( ) <EOL> continue <EOL> if run . perform_run . branch : <EOL> terminate = True <EOL> processes = [ ] <EOL> process_index = <NUM_LIT:0> <EOL> topped_out = False <EOL> check_queue_frequency = <NUM_LIT:1> <EOL> checked_count = <NUM_LIT:0> <EOL> checked_count_git = <NUM_LIT:0> <EOL> last_count = Probe . ProbeQueue . objects . filter ( part_of_run = run . perform_run_id , state = Probe . ProbeQueue . PROBEQ_IDLE ) . count ( ) <EOL> if last_count > <NUM_LIT> : <EOL> check_queue_frequency = <NUM_LIT:30> <EOL> elif last_count > <NUM_LIT> : <EOL> check_queue_frequency = <NUM_LIT:10> <EOL> while ( Cluster . ClusterRun . objects . filter ( enabled = True , priority__gt = run . priority ) . count ( ) == <NUM_LIT:0> and <EOL> Cluster . ClusterRun . objects . get ( id = run . id ) . enabled ) : <EOL> master_configuration = Cluster . ClusterNode . objects . get ( hostname = "<STR_LIT>" ) <EOL> configuration = Cluster . ClusterNode . objects . get ( hostname = computername ) <EOL> if not configuration . active_node or not master_configuration . active_node : <EOL> break ; <EOL> configuration . save ( ) <EOL> if not processes : <EOL> subprocess . call ( [ "<STR_LIT>" , "<STR_LIT>" , ] ) <EOL> subprocess . call ( [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> subprocess . call ( [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:.>" ] , cwd = os . path . join ( "<STR_LIT>" , "<STR_LIT>" ) ) <EOL> checked_count += <NUM_LIT:1> <EOL> if checked_count >= check_queue_frequency : <EOL> qlen = Probe . ProbeQueue . objects . filter ( part_of_run = run . perform_run_id , state = Probe . ProbeQueue . PROBEQ_IDLE ) . count ( ) <EOL> if qlen <= <NUM_LIT:0> : <EOL> break ; <EOL> if qlen < <NUM_LIT> : <EOL> check_queue_frequency = <NUM_LIT:0> <EOL> elif qlen < <NUM_LIT> : <EOL> check_queue_frequency = <NUM_LIT:10> <EOL> last_count = qlen <EOL> checked_count = <NUM_LIT:0> <EOL> checked_count_git += <NUM_LIT:1> ; <EOL> if checked_count_git >= <NUM_LIT:10> : <EOL> subprocess . call ( [ "<STR_LIT>" , "<STR_LIT>" , ] ) <EOL> subprocess . call ( [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> subprocess . call ( [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:.>" ] , cwd = os . path . join ( "<STR_LIT>" , "<STR_LIT>" ) ) <EOL> checked_count_git = <NUM_LIT:0> ; <EOL> run_config = OptionParser ( ) <EOL> run_config . add_option ( "<STR_LIT>" , action = "<STR_LIT:store>" , type = "<STR_LIT:int>" , dest = "<STR_LIT>" , default = <NUM_LIT:1> ) <EOL> run_config . add_option ( "<STR_LIT>" , action = "<STR_LIT:store>" , type = "<STR_LIT:int>" , dest = "<STR_LIT>" , default = <NUM_LIT> ) <EOL> ( run_options , args ) = run_config . parse_args ( configuration . probe_parameters . split ( ) ) <EOL> if int ( run_options . process_count ) == <NUM_LIT:0> : <EOL> break <EOL> started_proc = <NUM_LIT:0> ; <EOL> Q = Cluster . ClusterAction . objects . filter ( cluster_run = run ) <EOL> current_time = datetime . datetime . now ( ) <EOL> delta = datetime . timedelta ( minutes = <NUM_LIT:10> ) <EOL> Q3 = Q . filter ( completed_time__range = ( current_time - delta , current_time - datetime . timedelta ( minutes = <NUM_LIT:5> ) ) ) <EOL> all_count_5min = Q3 . count ( ) <EOL> if all_count_5min > <NUM_LIT:4> : <EOL> Q1 = Q . filter ( completed_time__range = ( current_time - delta , current_time ) ) <EOL> node_count_10min = Q1 . filter ( cluster_node = configuration ) . count ( ) <EOL> all_count_10min = Q1 . count ( ) <EOL> if node_count_10min > <NUM_LIT:4> : <EOL> factor = all_count_10min / node_count_10min <EOL> iterations = int ( ( last_count * factor ) / int ( run_options . process_count ) ) <EOL> if run_options . iteration_count > iterations : <EOL> run_options . iteration_count = max ( <NUM_LIT:15> , iterations ) <EOL> proc_limit = int ( run_options . process_count ) <EOL> if last_count < <NUM_LIT> and proc_limit > <NUM_LIT:20> and run_options . iteration_count > <NUM_LIT:50> : <EOL> run_options . iteration_count = <NUM_LIT:15> <EOL> if last_count < <NUM_LIT> and proc_limit > <NUM_LIT:50> : <EOL> proc_limit /= <NUM_LIT:3> <EOL> proc_limit = max ( <NUM_LIT> , proc_limit ) <EOL> if last_count < run_options . iteration_count * proc_limit : <EOL> proc_limit = max ( min ( <NUM_LIT> , proc_limit ) , min ( <NUM_LIT> , last_count / run_options . iteration_count , proc_limit ) ) <EOL> if last_count < proc_limit * run_options . iteration_count : <EOL> proc_limit = max ( <NUM_LIT:10> , last_count / run_options . iteration_count ) <EOL> if proc_limit > <NUM_LIT> and len ( processes ) > <NUM_LIT:0> and len ( processes ) < <NUM_LIT> and all_count_5min < <NUM_LIT:50> : <EOL> time . sleep ( <NUM_LIT> ) ; <EOL> continue ; <EOL> start_proc = max ( <NUM_LIT:10> , min ( <EOL> <NUM_LIT:30> if proc_limit * <NUM_LIT> > len ( processes ) or ( proc_limit > <NUM_LIT:200> and len ( processes ) < <NUM_LIT:100> ) else <NUM_LIT:50> , <EOL> proc_limit / <NUM_LIT:10> ) ) <EOL> if proc_limit > <NUM_LIT> and len ( processes ) < <NUM_LIT:30> : <EOL> start_proc = <NUM_LIT:5> <EOL> while len ( processes ) < proc_limit and started_proc < start_proc : <EOL> process_index += <NUM_LIT:1> <EOL> new_process = subprocess . Popen ( <EOL> ( [ "<STR_LIT>" ] if os . name == "<STR_LIT>" else [ ] ) + <EOL> [ "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , str ( process_index ) , <EOL> "<STR_LIT>" , str ( run . perform_run . id ) , <EOL> "<STR_LIT>" , '<STR_LIT:">' + run . perform_run . source_name + '<STR_LIT:">' , <EOL> "<STR_LIT>" , '<STR_LIT:">' + run . perform_run . description + '<STR_LIT:">' , <EOL> "<STR_LIT>" , str ( run_options . iteration_count ) , <EOL> ] + <EOL> ( [ "<STR_LIT>" ] if options . verbose or options . register_performance else [ ] ) + <EOL> ( [ "<STR_LIT>" ] if options . use_testbase2 else [ ] ) + <EOL> ( [ "<STR_LIT>" ] if last_count > <NUM_LIT> else [ ] ) + <EOL> ( [ "<STR_LIT>" ] if last_count < <NUM_LIT> else [ ] ) <EOL> , shell = False ) <EOL> started_proc += <NUM_LIT:1> <EOL> if new_process : <EOL> processes . append ( new_process ) <EOL> if options . verbose : <EOL> print "<STR_LIT>" , process_index , "<STR_LIT>" , len ( processes ) , "<STR_LIT:/>" , proc_limit <EOL> time . sleep ( <NUM_LIT:0.5> ) <EOL> try : <EOL> connection . close ( ) <EOL> except : <EOL> pass <EOL> if not topped_out and len ( processes ) >= int ( run_options . process_count ) : <EOL> topped_out = True <EOL> if ( start_proc < <NUM_LIT:10> and not topped_out ) or ( proc_limit > <NUM_LIT:200> and len ( processes ) < proc_limit * <NUM_LIT> ) : <EOL> time . sleep ( <NUM_LIT> ) <EOL> elif last_count < <NUM_LIT> and proc_limit > <NUM_LIT:20> and not topped_out : <EOL> time . sleep ( <NUM_LIT> ) <EOL> elif len ( processes ) > <NUM_LIT> and len ( processes ) < proc_limit * <NUM_LIT> : <EOL> time . sleep ( <NUM_LIT> ) <EOL> elif len ( processes ) > <NUM_LIT:200> and len ( processes ) < proc_limit * <NUM_LIT> : <EOL> time . sleep ( <NUM_LIT> ) <EOL> else : <EOL> time . sleep ( <NUM_LIT:30> if len ( processes ) > proc_limit * <NUM_LIT> else <NUM_LIT:15> ) <EOL> if options . verbose : <EOL> Q = ClusterAction . objects . filter ( cluster_run = run ) <EOL> current_time = datetime . datetime . now ( ) <EOL> delta = datetime . timedelta ( hours = <NUM_LIT:1> ) <EOL> Q1 = Q . filter ( completed_time__range = ( current_time - delta , current_time ) ) <EOL> all_count_hour = Q1 . count ( ) <EOL> node_count_hour = Q1 . filter ( cluster_node = configuration ) . count ( ) <EOL> delta = datetime . timedelta ( minutes = <NUM_LIT:10> ) <EOL> Q1 = Q . filter ( completed_time__range = ( current_time - delta , current_time ) ) <EOL> all_count_10min = Q1 . count ( ) * <NUM_LIT:6> <EOL> node_count_10min = Q1 . filter ( cluster_node = configuration ) . count ( ) * <NUM_LIT:6> <EOL> delta = datetime . timedelta ( minutes = <NUM_LIT:1> ) <EOL> Q1 = Q . filter ( completed_time__range = ( current_time - delta , current_time ) ) <EOL> all_count_1min = Q1 . count ( ) * <NUM_LIT> <EOL> node_count_1min = Q1 . filter ( cluster_node = configuration ) . count ( ) * <NUM_LIT> <EOL> print "<STR_LIT>" , node_count_1min , "<STR_LIT:U+0020>" , node_count_10min , "<STR_LIT:U+0020>" , node_count_hour <EOL> print "<STR_LIT>" , all_count_1min , "<STR_LIT:U+0020>" , all_count_10min , "<STR_LIT:U+0020>" , all_count_hour , "<STR_LIT>" , Probe . ProbeQueue . objects . filter ( part_of_run = run . perform_run_id , state = Probe . ProbeQueue . PROBEQ_IDLE ) . count ( ) , "<STR_LIT>" <EOL> next_process_list = [ ] <EOL> for proc in processes : <EOL> if proc . poll ( ) == None : <EOL> next_process_list . append ( proc ) <EOL> processes = next_process_list <EOL> while processes : <EOL> try : <EOL> connection . close ( ) <EOL> except : <EOL> pass <EOL> time . sleep ( <NUM_LIT:30> ) <EOL> if options . verbose : <EOL> Q = ClusterAction . objects . filter ( cluster_run = run ) <EOL> current_time = datetime . datetime . now ( ) <EOL> delta = datetime . timedelta ( hours = <NUM_LIT:1> ) <EOL> Q1 = Q . filter ( completed_time__range = ( current_time - delta , current_time ) ) <EOL> all_count_hour = Q1 . count ( ) <EOL> node_count_hour = Q1 . filter ( cluster_node = configuration ) . count ( ) <EOL> delta = datetime . timedelta ( minutes = <NUM_LIT:10> ) <EOL> Q1 = Q . filter ( completed_time__range = ( current_time - delta , current_time ) ) <EOL> all_count_10min = Q1 . count ( ) * <NUM_LIT:6> <EOL> node_count_10min = Q1 . filter ( cluster_node = configuration ) . count ( ) * <NUM_LIT:6> <EOL> delta = datetime . timedelta ( minutes = <NUM_LIT:1> ) <EOL> Q1 = Q . filter ( completed_time__range = ( current_time - delta , current_time ) ) <EOL> all_count_1min = Q1 . count ( ) * <NUM_LIT> <EOL> node_count_1min = Q1 . filter ( cluster_node = configuration ) . count ( ) * <NUM_LIT> <EOL> print "<STR_LIT>" , node_count_1min , "<STR_LIT:U+0020>" , node_count_10min , "<STR_LIT:U+0020>" , node_count_hour <EOL> print "<STR_LIT>" , all_count_1min , "<STR_LIT:U+0020>" , all_count_10min , "<STR_LIT:U+0020>" , all_count_hour , "<STR_LIT>" , Probe . ProbeQueue . objects . filter ( part_of_run = run . perform_run_id , state = Probe . ProbeQueue . PROBEQ_IDLE ) . count ( ) , "<STR_LIT>" <EOL> next_process_list = [ ] <EOL> for proc in processes : <EOL> if proc . poll ( ) == None : <EOL> next_process_list . append ( proc ) <EOL> processes = next_process_list <EOL> if options . verbose : <EOL> print "<STR_LIT>" , len ( processes ) , "<STR_LIT:/>" , run_options . process_count <EOL> if options . verbose : <EOL> print "<STR_LIT>" <EOL> break ; <EOL> if terminate : <EOL> break ; <EOL> master_configuration = Cluster . ClusterNode . objects . get ( hostname = "<STR_LIT>" ) <EOL> configuration = Cluster . ClusterNode . objects . get ( hostname = computername ) <EOL> configuration . save ( ) <EOL> run_config = OptionParser ( ) <EOL> run_config . add_option ( "<STR_LIT>" , action = "<STR_LIT:store>" , dest = "<STR_LIT>" , default = <NUM_LIT:1> ) <EOL> run_config . add_option ( "<STR_LIT>" , action = "<STR_LIT:store>" , dest = "<STR_LIT>" , default = <NUM_LIT> ) <EOL> ( run_options , args ) = run_config . parse_args ( configuration . probe_parameters . split ( ) ) <EOL> if ( not master_configuration . active_node or not configuration . active_node or <EOL> int ( run_options . process_count ) == <NUM_LIT:0> or Cluster . ClusterRun . objects . filter ( enabled = True ) . count ( ) == <NUM_LIT:0> ) : <EOL> if options . managed and Cluster . ClusterRun . objects . filter ( enabled = True ) . count ( ) == <NUM_LIT:0> : <EOL> break ; <EOL> connection . close ( ) <EOL> time . sleep ( <NUM_LIT> ) </s>
