Author: fapeeler
Date: Thu Jan 21 15:02:02 2010
New Revision: 901732

URL: http://svn.apache.org/viewvc?rev=901732&view=rev
Log:
VCL-254

added better processing of the block requests, if number of allocated
nodes is less than number requested. Attempt several more times to make
it happen.


Modified:
    incubator/vcl/trunk/managementnode/lib/VCL/blockrequest.pm
    incubator/vcl/trunk/managementnode/lib/VCL/utils.pm

Modified: incubator/vcl/trunk/managementnode/lib/VCL/blockrequest.pm
URL: 
http://svn.apache.org/viewvc/incubator/vcl/trunk/managementnode/lib/VCL/blockrequest.pm?rev=901732&r1=901731&r2=901732&view=diff
==============================================================================
--- incubator/vcl/trunk/managementnode/lib/VCL/blockrequest.pm (original)
+++ incubator/vcl/trunk/managementnode/lib/VCL/blockrequest.pm Thu Jan 21 
15:02:02 2010
@@ -155,26 +155,47 @@
                        notify($ERRORS{'OK'}, 0, "updated process flag on 
blocktime_id= $blocktime_id");
                }
 
-               my $xmlcall = process_block_time($blocktime_id);
+               my $completed = 0;
+               my $loop_control = 0;
+               my $xmlcall;
+
+               my($allocated,$unallocated) = 0;
+
+               while(!($completed)){
+                       if($loop_control < 6){
+                               $loop_control++;
+                               notify($ERRORS{'DEBUG'}, 0, "processing 
blocktime_id= $blocktime_id  pass $loop_control");
+                               $xmlcall = process_block_time($blocktime_id);
+                       }
+                       else{
+                               $completed=1;
+                               notify($ERRORS{'CRITICAL'}, 0, "attempted 
$loop_control passes to complete block_request $blockrequest_id\n allocated= 
$allocated \nblockrequest_number_machines= $blockrequest_number_machines");
+                               last;
+                       }
 
-               if ($xmlcall->{status} =~ /success/) {
-                       notify($ERRORS{'OK'}, 0, "success blockTimes id 
$blocktime_id processed and allocated $xmlcall->{allocated} nodes");
-               }
-               elsif ($xmlcall->{status} =~ /completed/) {
-                       notify($ERRORS{'OK'}, 0, "success blockTimes id 
$blocktime_id already processed");
-               }
-               elsif ($xmlcall->{status} =~ /warning/) {
-                       my $warningmsg  = $xmlcall->{warningmsg}  if 
(defined($xmlcall->{warningmsg}));
-                       my $allocated   = $xmlcall->{allocated}   if 
(defined($xmlcall->{allocated}));
-                       my $unallocated = $xmlcall->{unallocated} if 
(defined($xmlcall->{unallocated}));
-                       notify($ERRORS{'CRITICAL'}, 0, "xmlrpc warning: 
$warningmsg allocated= $allocated unallocated= $unallocated");
-               }
-               elsif ($xmlcall->{status} =~ /error/) {
-                       my $errormsg = $xmlcall->{errormsg} if 
(defined($xmlcall->{errormsg}));
-                       notify($ERRORS{'CRITICAL'}, 0, "xmlrpc error on 
blockrequest_id=$blockrequest_id blocktime_id=$blocktime_id : $errormsg");
-               }
-               else {
-                       notify($ERRORS{'CRITICAL'}, 0, "xmlrpc status unknown 
status=  $xmlcall->{status} blockrequest_id=$blockrequest_id 
blocktime_id=$blocktime_id");
+                       $allocated   = $xmlcall->{allocated}   if 
(defined($xmlcall->{allocated}));
+                       $unallocated = $xmlcall->{unallocated} if 
(defined($xmlcall->{unallocated}));
+
+                       if($allocated >= $blockrequest_number_machines){
+                               $completed=1;
+                               notify($ERRORS{'OK'}, 0, "success blockTimes id 
$blocktime_id processed and allocated $xmlcall->{allocated} nodes \nstatus= 
$xmlcall->{status}");
+                               last;
+                       }
+
+                       if ($xmlcall->{status} =~ /warning|fault/) {
+                               my $warningmsg  = $xmlcall->{warningmsg}  if 
(defined($xmlcall->{warningmsg}));
+                               notify($ERRORS{'CRITICAL'}, 0, "xmlrpc warning: 
$warningmsg allocated= $allocated unallocated= $unallocated");
+                       }
+                       if ($xmlcall->{status} =~ /error/) {
+                               my $errormsg = $xmlcall->{errormsg} if 
(defined($xmlcall->{errormsg}));
+                               notify($ERRORS{'CRITICAL'}, 0, "xmlrpc error on 
blockrequest_id=$blockrequest_id blocktime_id=$blocktime_id : $errormsg");
+                       }
+                       if ($xmlcall->{status} =~ /completed/) {
+                               $completed=1;
+                               notify($ERRORS{'OK'}, 0, "success blockTimes id 
$blocktime_id already processed");
+                       }
+
+                       sleep 5 if(!$completed);
                }
 
                #pause
@@ -228,6 +249,219 @@
 
 } ## end sub process
 
+#/////////////////////////////////////////////////////////////////////////////
+
+=head2 process_block_time
+
+ Parameters  : $blockTimesid
+ Returns     : hash references
+ Description : calls xmlrpc_call routine with specificed method and args
+
+=cut
+
+sub process_block_time {
+       my $blockTimesid = $_[0];
+
+       if(!$blockTimesid){
+               notify($ERRORS{'WARNING'}, 0, "blockTimesid argument was not 
passed");
+               return 0;
+       }
+
+       my $method = "XMLRPCprocessBlockTime";
+       my $ignoreprivileges = 1;
+       my @argument_string = ($method,$blockTimesid, $ignoreprivileges); 
+
+       my $xml_ret = xmlrpc_call(@argument_string);
+
+       my %info;
+       if( ref($xml_ret) =~ /STRUCT/i){
+       $info{status} = $xml_ret->value->{status};
+                $info{allocated} = $xml_ret->value->{allocated} 
if(defined($xml_ret->value->{allocated})) ;
+       $info{unallocated} = $xml_ret->value->{unallocated} 
if(defined($xml_ret->value->{unallocated}));
+                #error
+                $info{errorcode} = $xml_ret->value->{errorcode} 
if(defined($xml_ret->value->{errorcode}));
+                $info{errormsg} = $xml_ret->value->{errormsg} 
if(defined($xml_ret->value->{errormsg}));
+                #warning
+                $info{warningcode} = $xml_ret->value->{warningcode} 
if(defined($xml_ret->value->{warningcode}));
+                $info{warningmsg} = $xml_ret->value->{warningmsg} 
if(defined($xml_ret->value->{warningmsg}));
+                #$info{reqidlists} = $xml_ret->value->{requestids};
+       }
+       else {
+               notify($ERRORS{'WARNING'}, 0, "return argument 
XMLRPCprocessBlockTime was not a STRUCT as expected" . ref($xml_ret) );
+               if(ref($xml_ret) =~ /fault/){
+                       $info{status} = "fault";
+               }
+               else {
+                $info{status} = ref($xml_ret);
+               }
+       }
+
+       return \%info;
+}
+
+#/////////////////////////////////////////////////////////////////////////////
+
+=head2 update_blockTimes_processing
+
+ Parameters  : $blockTimes_id, $processing
+ Returns     : 0 or 1
+ Description : Updates the processed flag in blockTimes table
+
+=cut
+
+sub update_blockTimes_processing {
+       my ($blockTimes_id, $processing) = @_;
+
+       my ($package, $filename, $line, $sub) = caller(0);
+
+       # Check the arguments
+       if (!defined($blockTimes_id)) {
+               notify($ERRORS{'WARNING'}, 0, "blockTimes ID was not 
specified");
+               return 0;
+       }
+       if (!defined($processing)) {
+               notify($ERRORS{'WARNING'}, 0, "processing was not specified");
+               return 0;
+       }
+
+       # Construct the update statement
+       my $update_statement = "
+      UPDATE
+               blockTimes
+               SET
+               blockTimes.processed = $processing
+               WHERE
+               blockTimes.id = $blockTimes_id
+   ";
+
+       # Call the database execute subroutine
+       if (database_execute($update_statement)) {
+               return 1;
+       }
+       else {
+               notify($ERRORS{'WARNING'}, 0, "unable to update blockTimes 
table, id=$blockTimes_id, processing=$processing");
+               return 0;
+       }
+} ## end sub update_blockTimes_processing
+
+#/////////////////////////////////////////////////////////////////////////////
+
+=head2 delete_block_request
+
+ Parameters  : $blockrequest_id
+ Returns     : 0 or 1
+ Description : removes an expired blockrequest from the blockrequest table 
+
+=cut
+
+sub delete_block_request {
+       my ($blockrequest_id) = @_;
+
+       # Check the arguments
+       if (!defined($blockrequest_id)) {
+               notify($ERRORS{'WARNING'}, 0, "blockrequest ID was not 
specified");
+               return 0;
+       }
+       # Construct the update statement
+       my $delete_statement = "
+      DELETE
+               blockRequest
+               FROM blockRequest
+               WHERE
+               blockRequest.id = $blockrequest_id
+   ";
+
+       # Call the database execute subroutine
+       if (database_execute($delete_statement)) {
+               return 1;
+       }
+       else {
+               notify($ERRORS{'WARNING'}, 0, "unable to deleted blockrequest 
$blockrequest_id blockRequest table ");
+               return 0;
+       }
+
+}
+
+#/////////////////////////////////////////////////////////////////////////////
+
+=head2 clear_blockTimes
+
+ Parameters  : $blockTimes_id
+ Returns     : 0 or 1
+ Description : Removes blockTimes id from blockTimes table
+
+=cut
+
+sub clear_blockTimes {
+       my ($blockTimes_id) = @_;
+
+       my ($package, $filename, $line, $sub) = caller(0);
+
+       # Check the arguments
+       if (!defined($blockTimes_id)) {
+               notify($ERRORS{'WARNING'}, 0, "blockTimes ID was not 
specified");
+               return 0;
+       }
+
+       # Construct the update statement
+       my $delete_statement = "
+      DELETE
+               blockTimes
+               FROM blockTimes
+               WHERE
+               blockTimes.id = $blockTimes_id
+   ";
+
+       # Call the database execute subroutine
+       if (database_execute($delete_statement)) {
+               return 1;
+       }
+       else {
+               notify($ERRORS{'WARNING'}, 0, "unable to deleted blockTimes_id 
$blockTimes_id blockTimes table ");
+               return 0;
+       }
+} ## end sub clear_blockTimes
+
+#/////////////////////////////////////////////////////////////////////////////
+
+=head2 clear_blockComputers
+
+ Parameters  : $blockTimes_id, $processing
+ Returns     : 0 or 1
+ Description : Clears blockcomputers from an expired BlockTimesid
+
+=cut
+
+sub clear_blockComputers {
+       my ($blockTimes_id) = @_;
+
+       my ($package, $filename, $line, $sub) = caller(0);
+
+       # Check the arguments
+       if (!defined($blockTimes_id)) {
+               notify($ERRORS{'WARNING'}, 0, "blockTimes ID was not 
specified");
+               return 0;
+       }
+
+       # Construct the update statement
+       my $delete_statement = "
+      DELETE
+               blockComputers
+               FROM blockComputers
+               WHERE
+               blockTimeid = $blockTimes_id
+   ";
+
+       # Call the database execute subroutine
+       if (database_execute($delete_statement)) {
+               return 1;
+       }
+       else {
+               notify($ERRORS{'WARNING'}, 0, "unable to delete blockComputers 
for id=$blockTimes_id, ");
+               return 0;
+       }
+} ## end sub clear_blockComputers
+
 =pod
 
////////////////////////////////////////////////////////////////////////////////
 ///

Modified: incubator/vcl/trunk/managementnode/lib/VCL/utils.pm
URL: 
http://svn.apache.org/viewvc/incubator/vcl/trunk/managementnode/lib/VCL/utils.pm?rev=901732&r1=901731&r2=901732&view=diff
==============================================================================
--- incubator/vcl/trunk/managementnode/lib/VCL/utils.pm (original)
+++ incubator/vcl/trunk/managementnode/lib/VCL/utils.pm Thu Jan 21 15:02:02 2010
@@ -92,8 +92,6 @@
   check_uptime
   checkonprocess
   clearfromblockrequest
-  clear_blockComputers
-  clear_blockTimes
   collectsshkeys
   construct_image_name
   controlVM
@@ -103,7 +101,6 @@
   database_select
   delete_computerloadlog_reservation
   delete_request
-  delete_block_request
   disablesshd
   firewall_compare_update
   format_data
@@ -164,7 +161,6 @@
   notify_via_msg
   notify_via_wall
   preplogfile
-  process_block_time
   read_file_to_array
   rename_vcld_process
   reservation_being_processed
@@ -187,7 +183,6 @@
   timefloor15interval
   unlockfile
   update_blockrequest_processing
-  update_blockTimes_processing
   update_cluster_info
   update_computer_address
   update_computer_state
@@ -7318,6 +7313,50 @@
        }
 } ## end sub delete_request
 
+#/////////////////////////////////////////////////////////////////////////////
+
+=head2 update_blockrequest_processing
+
+ Parameters  : $blockrequest_id, $processing
+ Returns     : 0 or 1
+ Description : Updates the processing flag in the blockRequest table
+
+=cut
+
+sub update_blockrequest_processing {
+       my ($blockrequest_id, $processing) = @_;
+
+       my ($package, $filename, $line, $sub) = caller(0);
+
+       # Check the arguments
+       if (!defined($blockrequest_id)) {
+               notify($ERRORS{'WARNING'}, 0, "blockrequest ID was not 
specified");
+               return 0;
+       }
+       if (!defined($processing)) {
+               notify($ERRORS{'WARNING'}, 0, "processing was not specified");
+               return 0;
+       }
+
+       # Construct the update statement
+       my $update_statement = "
+      UPDATE
+               blockRequest
+               SET
+               blockRequest.processing = $processing
+               WHERE
+               blockRequest.id = $blockrequest_id
+   ";
+
+       # Call the database execute subroutine
+       if (database_execute($update_statement)) {
+               return 1;
+       }
+       else {
+               notify($ERRORS{'WARNING'}, 0, "unable to update blockRequest 
table, id=$blockrequest_id, processing=$processing");
+               return 0;
+       }
+} ## end sub update_blockrequest_processing
 
 #/////////////////////////////////////////////////////////////////////////////
 
@@ -7870,212 +7909,6 @@
 
 #/////////////////////////////////////////////////////////////////////////////
 
-=head2 update_blockrequest_processing
-
- Parameters  : $blockrequest_id, $processing
- Returns     : 0 or 1
- Description : Updates the processing flag in the blockRequest table
-
-=cut
-
-sub update_blockrequest_processing {
-       my ($blockrequest_id, $processing) = @_;
-
-       my ($package, $filename, $line, $sub) = caller(0);
-
-       # Check the arguments
-       if (!defined($blockrequest_id)) {
-               notify($ERRORS{'WARNING'}, 0, "blockrequest ID was not 
specified");
-               return 0;
-       }
-       if (!defined($processing)) {
-               notify($ERRORS{'WARNING'}, 0, "processing was not specified");
-               return 0;
-       }
-
-       # Construct the update statement
-       my $update_statement = "
-      UPDATE
-               blockRequest
-               SET
-               blockRequest.processing = $processing
-               WHERE
-               blockRequest.id = $blockrequest_id
-   ";
-
-       # Call the database execute subroutine
-       if (database_execute($update_statement)) {
-               return 1;
-       }
-       else {
-               notify($ERRORS{'WARNING'}, 0, "unable to update blockRequest 
table, id=$blockrequest_id, processing=$processing");
-               return 0;
-       }
-} ## end sub update_blockrequest_processing
-
-#/////////////////////////////////////////////////////////////////////////////
-
-=head2 update_blockTimes_processing
-
- Parameters  : $blockTimes_id, $processing
- Returns     : 0 or 1
- Description : Updates the processed flag in blockTimes table
-
-=cut
-
-sub update_blockTimes_processing {
-       my ($blockTimes_id, $processing) = @_;
-
-       my ($package, $filename, $line, $sub) = caller(0);
-
-       # Check the arguments
-       if (!defined($blockTimes_id)) {
-               notify($ERRORS{'WARNING'}, 0, "blockTimes ID was not 
specified");
-               return 0;
-       }
-       if (!defined($processing)) {
-               notify($ERRORS{'WARNING'}, 0, "processing was not specified");
-               return 0;
-       }
-
-       # Construct the update statement
-       my $update_statement = "
-      UPDATE
-               blockTimes
-               SET
-               blockTimes.processed = $processing
-               WHERE
-               blockTimes.id = $blockTimes_id
-   ";
-
-       # Call the database execute subroutine
-       if (database_execute($update_statement)) {
-               return 1;
-       }
-       else {
-               notify($ERRORS{'WARNING'}, 0, "unable to update blockTimes 
table, id=$blockTimes_id, processing=$processing");
-               return 0;
-       }
-} ## end sub update_blockTimes_processing
-
-#/////////////////////////////////////////////////////////////////////////////
-
-=head2 delete_block_request
-
- Parameters  : $blockrequest_id
- Returns     : 0 or 1
- Description : removes blockrequest 
-
-=cut
-
-sub delete_block_request {
-       my ($blockrequest_id) = @_;
-
-       # Check the arguments
-       if (!defined($blockrequest_id)) {
-               notify($ERRORS{'WARNING'}, 0, "blockrequest ID was not 
specified");
-               return 0;
-       }
-       # Construct the update statement
-       my $delete_statement = "
-      DELETE
-               blockRequest
-               FROM blockRequest
-               WHERE
-               blockRequest.id = $blockrequest_id
-   ";
-
-       # Call the database execute subroutine
-       if (database_execute($delete_statement)) {
-               return 1;
-       }
-       else {
-               notify($ERRORS{'WARNING'}, 0, "unable to deleted blockrequest 
$blockrequest_id blockRequest table ");
-               return 0;
-       }
-
-}
-#/////////////////////////////////////////////////////////////////////////////
-
-=head2 clear_blockTimes
-
- Parameters  : $blockTimes_id
- Returns     : 0 or 1
- Description : Removes blockTimes id from blockTimes table
-
-=cut
-
-sub clear_blockTimes {
-       my ($blockTimes_id) = @_;
-
-       my ($package, $filename, $line, $sub) = caller(0);
-
-       # Check the arguments
-       if (!defined($blockTimes_id)) {
-               notify($ERRORS{'WARNING'}, 0, "blockTimes ID was not 
specified");
-               return 0;
-       }
-
-       # Construct the update statement
-       my $delete_statement = "
-      DELETE
-               blockTimes
-               FROM blockTimes
-               WHERE
-               blockTimes.id = $blockTimes_id
-   ";
-
-       # Call the database execute subroutine
-       if (database_execute($delete_statement)) {
-               return 1;
-       }
-       else {
-               notify($ERRORS{'WARNING'}, 0, "unable to deleted blockTimes_id 
$blockTimes_id blockTimes table ");
-               return 0;
-       }
-} ## end sub update_blockTimes_processing
-#/////////////////////////////////////////////////////////////////////////////
-
-=head2 clear_blockComputers
-
- Parameters  : $blockTimes_id, $processing
- Returns     : 0 or 1
- Description : Updates the processed flag in blockTimes table
-
-=cut
-
-sub clear_blockComputers {
-       my ($blockTimes_id) = @_;
-
-       my ($package, $filename, $line, $sub) = caller(0);
-
-       # Check the arguments
-       if (!defined($blockTimes_id)) {
-               notify($ERRORS{'WARNING'}, 0, "blockTimes ID was not 
specified");
-               return 0;
-       }
-
-       # Construct the update statement
-       my $delete_statement = "
-      DELETE
-               blockComputers
-               FROM blockComputers
-               WHERE
-               blockTimeid = $blockTimes_id
-   ";
-
-       # Call the database execute subroutine
-       if (database_execute($delete_statement)) {
-               return 1;
-       }
-       else {
-               notify($ERRORS{'WARNING'}, 0, "unable to delete blockComputers 
for id=$blockTimes_id, ");
-               return 0;
-       }
-} ## end sub update_blockTimes_processing
-
-#/////////////////////////////////////////////////////////////////////////////
-
 =head2 get_management_node_blockrequests
 
  Parameters  : $managementnode_id
@@ -9475,50 +9308,6 @@
 
 #/////////////////////////////////////////////////////////////////////////////
 
-=head2 process_block_time
-
- Parameters  : $blockTimesid
- Returns     : hash references
- Description : calls xmlrpc_call routine with specificed method and args
-
-=cut
-
-sub process_block_time {
-       my $blockTimesid = $_[0];
-
-       if(!$blockTimesid){
-               notify($ERRORS{'WARNING'}, 0, "blockTimesid argument was not 
passed");
-               return 0;
-       }
-
-       my $method = "XMLRPCprocessBlockTime";
-
-       my $xml_ret = xmlrpc_call($method, $blockTimesid);
-
-       my %info;
-       if( ref($xml_ret) =~ /STRUCT/i){
-       $info{status} = $xml_ret->value->{status};
-                $info{allocated} = $xml_ret->value->{allocated} 
if(defined($xml_ret->value->{allocated})) ;
-       $info{unallocated} = $xml_ret->value->{unallocated} 
if(defined($xml_ret->value->{unallocated}));
-                #error
-                $info{errorcode} = $xml_ret->value->{errorcode} 
if(defined($xml_ret->value->{errorcode}));
-                $info{errormsg} = $xml_ret->value->{errormsg} 
if(defined($xml_ret->value->{errormsg}));
-                #warning
-                $info{warningcode} = $xml_ret->value->{warningcode} 
if(defined($xml_ret->value->{warningcode}));
-                $info{warningmsg} = $xml_ret->value->{warningmsg} 
if(defined($xml_ret->value->{warningmsg}));
-                #$info{reqidlists} = $xml_ret->value->{requestids};
-       }
-       else {
-               notify($ERRORS{'WARNING'}, 0, "return argument 
XMLRPCprocessBlockTime was not a STRUCT as expected" . ref($xml_ret) );
-               return 0;
-
-       }
-
-       return \%info;
-}
-
-#/////////////////////////////////////////////////////////////////////////////
-
 =head2 xmlrpc_call
 
  Parameters  : statement
@@ -9527,15 +9316,14 @@
 
 =cut
 sub xmlrpc_call {
-       my ($method,$args) = @_;
+       my @argument_string = @_;
+
+       notify($ERRORS{'DEBUG'}, 0, "argument_string= @argument_string ");
 
        # Make sure method and args were passed
-       if (!$method) {
-               notify($ERRORS{'WARNING'}, 0, "method argument was not passed");
-               return 0;
-       }
-       if (!$args) {
-               notify($ERRORS{'WARNING'}, 0, "args argument was not passed");
+       my $number_of_args = @argument_string;
+       if ($number_of_args == 0) {
+               notify($ERRORS{'WARNING'}, 0, "argument string is empty 
number_of_args= $number_of_args argument_string= @argument_string ");
                return 0;
        }
 
@@ -9544,10 +9332,10 @@
        $cli->{'__request'}{'_headers'}->push_header('X-Pass' => $XMLRPC_PASS);
        $cli->{'__request'}{'_headers'}->push_header('X-APIVERSION' => 2);
 
-       my $response = $cli->send_request($method,$args);
+       my $response = $cli->send_request(@argument_string);
 
        if($response->type =~ /fault/){
-               notify($ERRORS{'WARNING'}, 0, "fault occured on $method,$args 
\n faultCode= $response->code->{faultCode} \n faultString= 
$response->string->{faultString}");
+               notify($ERRORS{'WARNING'}, 0, "fault occured on 
@argument_string \n faultCode= $response->code->{faultCode} \n faultString= 
$response->string->{faultString}");
                return 0;
        }
 


Reply via email to