Author: arkurth
Date: Thu May  3 13:28:24 2012
New Revision: 1333452

URL: http://svn.apache.org/viewvc?rev=1333452&view=rev
Log:
VCL-463
Changed update_reservation_accounts to use "INSERT IGNORE" instead of just 
"INSERT" for adding entries to the reservationaccounts table. A unique index 
has been added to the reservationid and userid columns of this table. The SQL 
command would generate an error if the row already exists without IGNORE.

VCL-503
Uncommented call to OS.pm::execute_new in run_ssh_command. This causes 
execute_new to be used for all SSH calls.

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

Modified: incubator/vcl/trunk/managementnode/lib/VCL/utils.pm
URL: 
http://svn.apache.org/viewvc/incubator/vcl/trunk/managementnode/lib/VCL/utils.pm?rev=1333452&r1=1333451&r2=1333452&view=diff
==============================================================================
--- incubator/vcl/trunk/managementnode/lib/VCL/utils.pm (original)
+++ incubator/vcl/trunk/managementnode/lib/VCL/utils.pm Thu May  3 13:28:24 2012
@@ -2298,71 +2298,78 @@ sub get_reservation_accounts {
        return ();
 
 }
-       
+
+#/////////////////////////////////////////////////////////////////////////////
+
+=head2 update_reservation_accounts
+
+ Parameters  : $reservation_id, $userid, $password, $mode
+ Returns     : boolean
+ Description : 
+
+=cut
+
 sub update_reservation_accounts {
-       my $resid = shift;
-       my $userid = shift;
+       my $reservation_id = shift;
+       my $user_id = shift;
        my $password = shift;
        my $mode = shift;
        
-       if(!$mode) {
-               notify($ERRORS{'WARNING'}, 0, "mode argument was not specified, 
either add or delete");
-      return;
+       if (!$mode) {
+               notify($ERRORS{'WARNING'}, 0, "mode argument was not specified, 
it must be either add or delete");
+               return;
        }
-
-       if ( !$resid ) {
-               notify($ERRORS{'WARNING'}, 0, "resid argument was not 
specified");
-                return;
+       
+       if (!$reservation_id) {
+               notify($ERRORS{'WARNING'}, 0, "reservation ID argument was not 
specified");
+               return;
        }
        
-       if ( !$userid ) {
-               notify($ERRORS{'WARNING'}, 0, "userid argument was not 
specified");
-                return;
-        }
+       if (!$user_id) {
+               notify($ERRORS{'WARNING'}, 0, "user ID argument was not 
specified");
+               return;
+       }
        
-       if ( !$password ) {
+       if (!$password) {
                $password = '';
        }
        
        my $statement;
-       
-       #ADD
-       if($mode =~ /add/i) {
-                         $statement = "
-                         INSERT INTO 
-                         reservationaccounts
-                         (
-                                 reservationid,
-                                 userid,
-                                 password
-                         )
-                         VALUES
-                         (
-                                 '$resid',
-                                 '$userid',
-                                 '$password'
-                         )
-                         ";
-       }
-       elsif( $mode =~ /delete/i ) {
-                       $statement = "
-                       DELETE 
-                       reservationaccounts
-                       FROM
-                       reservationaccounts
-                       WHERE
-                       reservationid = '$resid' AND
-                       userid = '$userid'
-                       "
-       
+       if ($mode =~ /add/i) {
+               $statement = <<EOF;
+INSERT IGNORE INTO 
+reservationaccounts
+(
+       reservationid,
+       userid,
+       password
+)
+VALUES
+(
+       '$reservation_id',
+       '$user_id',
+       '$password'
+)
+EOF
        }
-
-       if(database_execute($statement) ) {
-               #notify($ERRORS{'OK'}, 0, "executed $statement $resid $userid");
+       elsif ($mode =~ /delete/i) {
+               $statement = <<EOF;
+DELETE 
+reservationaccounts
+FROM
+reservationaccounts
+WHERE
+reservationid = '$reservation_id' AND
+userid = '$user_id'
+EOF
+       }
+       
+       if (database_execute($statement)) {
+               #notify($ERRORS{'OK'}, 0, "executed $statement $reservation_id 
$user_id");
                return 1;
        }
        else {
-               notify($ERRORS{'OK'}, 0, "failed to to execute statement= 
$statement");
+               notify($ERRORS{'OK'}, 0, "failed to to execute statement to 
update reservationaccounts table:\n$statement");
                return 0;
        }
 }
@@ -5121,7 +5128,7 @@ sub run_ssh_command {
        $timeout_seconds = 0 if (!$timeout_seconds);
        $identity_paths = get_management_node_info()->{keys} if (!defined 
$identity_paths || length($identity_paths) == 0);
        
-#return VCL::Module::OS::execute_new($node, $command, $output_level, 
$timeout_seconds, $max_attempts, $port, $user);
+return VCL::Module::OS::execute_new($node, $command, $output_level, 
$timeout_seconds, $max_attempts, $port, $user);
        
        # TODO: Add ssh path to config file and set global variable
        # Locate the path to the ssh binary


Reply via email to