@@ -322,74 +322,71 @@ public void updateConfiguration(long userId, String name, String value) {
322322 throw new InvalidParameterValueException (validationMsg );
323323 }
324324
325+ //Execute all updates in a single transaction
326+ Transaction txn = Transaction .currentTxn ();
327+ txn .start ();
328+
325329 if (!_configDao .update (name , value )) {
326330 s_logger .error ("Failed to update configuration option, name: " + name + ", value:" + value );
327331 throw new CloudRuntimeException ("Failed to update configuration value. Please contact Cloud Support." );
328332 }
329- if (Config .XenGuestNetwork .key ().equals (name )) {
333+
334+
335+ PreparedStatement pstmt = null ;
336+ if (Config .XenGuestNetwork .key ().equalsIgnoreCase (name )) {
330337 String sql = "update host_details set value=? where name=?" ;
331- Transaction txn = Transaction .currentTxn ();
332- PreparedStatement pstmt = null ;
333338 try {
334339 pstmt = txn .prepareAutoCloseStatement (sql );
335340 pstmt .setString (1 , DBEncryptionUtil .encrypt (value ));
336341 pstmt .setString (2 , "guest.network.device" );
337342
338343 pstmt .executeUpdate ();
339- } catch (SQLException e ) {
340344 } catch (Throwable e ) {
345+ throw new CloudRuntimeException ("Failed to update guest.network.device in host_details due to exception " , e );
341346 }
342- } else if (Config .XenPrivateNetwork .key ().equals (name )) {
347+ } else if (Config .XenPrivateNetwork .key ().equalsIgnoreCase (name )) {
343348 String sql = "update host_details set value=? where name=?" ;
344- Transaction txn = Transaction .currentTxn ();
345- PreparedStatement pstmt = null ;
346349 try {
347350 pstmt = txn .prepareAutoCloseStatement (sql );
348351 pstmt .setString (1 , DBEncryptionUtil .encrypt (value ));
349352 pstmt .setString (2 , "private.network.device" );
350353
351354 pstmt .executeUpdate ();
352- } catch (SQLException e ) {
353355 } catch (Throwable e ) {
356+ throw new CloudRuntimeException ("Failed to update private.network.device in host_details due to exception " , e );
354357 }
355- } else if (Config .XenPublicNetwork .key ().equals (name )) {
358+ } else if (Config .XenPublicNetwork .key ().equalsIgnoreCase (name )) {
356359 String sql = "update host_details set value=? where name=?" ;
357- Transaction txn = Transaction .currentTxn ();
358- PreparedStatement pstmt = null ;
359360 try {
360361 pstmt = txn .prepareAutoCloseStatement (sql );
361362 pstmt .setString (1 , DBEncryptionUtil .encrypt (value ));
362363 pstmt .setString (2 , "public.network.device" );
363364
364365 pstmt .executeUpdate ();
365- } catch (SQLException e ) {
366366 } catch (Throwable e ) {
367+ throw new CloudRuntimeException ("Failed to update public.network.device in host_details due to exception " , e );
367368 }
368- } else if (Config .XenStorageNetwork1 .key ().equals (name )) {
369+ } else if (Config .XenStorageNetwork1 .key ().equalsIgnoreCase (name )) {
369370 String sql = "update host_details set value=? where name=?" ;
370- Transaction txn = Transaction .currentTxn ();
371- PreparedStatement pstmt = null ;
372371 try {
373372 pstmt = txn .prepareAutoCloseStatement (sql );
374373 pstmt .setString (1 , DBEncryptionUtil .encrypt (value ));
375374 pstmt .setString (2 , "storage.network.device1" );
376375
377376 pstmt .executeUpdate ();
378- } catch (SQLException e ) {
379377 } catch (Throwable e ) {
378+ throw new CloudRuntimeException ("Failed to update storage.network.device1 in host_details due to exception " , e );
380379 }
381380 } else if (Config .XenStorageNetwork2 .key ().equals (name )) {
382381 String sql = "update host_details set value=? where name=?" ;
383- Transaction txn = Transaction .currentTxn ();
384- PreparedStatement pstmt = null ;
385382 try {
386383 pstmt = txn .prepareAutoCloseStatement (sql );
387384 pstmt .setString (1 , DBEncryptionUtil .encrypt (value ));
388385 pstmt .setString (2 , "storage.network.device2" );
389386
390387 pstmt .executeUpdate ();
391- } catch (SQLException e ) {
392388 } catch (Throwable e ) {
389+ throw new CloudRuntimeException ("Failed to update storage.network.device2 in host_details due to exception " , e );
393390 }
394391 } else if (Config .SystemVMUseLocalStorage .key ().equalsIgnoreCase (name )) {
395392 if (s_logger .isDebugEnabled ()) {
@@ -400,27 +397,28 @@ public void updateConfiguration(long userId, String name, String value) {
400397 if (serviceOffering != null ) {
401398 serviceOffering .setUseLocalStorage (useLocalStorage );
402399 if (!_serviceOfferingDao .update (serviceOffering .getId (), serviceOffering )) {
403- s_logger . error ("Failed to update ConsoleProxy offering's use_local_storage option to value:" + useLocalStorage );
400+ throw new CloudRuntimeException ("Failed to update ConsoleProxy offering's use_local_storage option to value:" + useLocalStorage );
404401 }
405402 }
406403
407404 serviceOffering = _serviceOfferingDao .findByName ("Cloud.Com-SoftwareRouter" );
408405 if (serviceOffering != null ) {
409406 serviceOffering .setUseLocalStorage (useLocalStorage );
410407 if (!_serviceOfferingDao .update (serviceOffering .getId (), serviceOffering )) {
411- s_logger . error ("Failed to update SoftwareRouter offering's use_local_storage option to value:" + useLocalStorage );
408+ throw new CloudRuntimeException ("Failed to update SoftwareRouter offering's use_local_storage option to value:" + useLocalStorage );
412409 }
413410 }
414411
415412 serviceOffering = _serviceOfferingDao .findByName ("Cloud.com-SecondaryStorage" );
416413 if (serviceOffering != null ) {
417414 serviceOffering .setUseLocalStorage (useLocalStorage );
418415 if (!_serviceOfferingDao .update (serviceOffering .getId (), serviceOffering )) {
419- s_logger . error ("Failed to update SecondaryStorage offering's use_local_storage option to value:" + useLocalStorage );
416+ throw new CloudRuntimeException ("Failed to update SecondaryStorage offering's use_local_storage option to value:" + useLocalStorage );
420417 }
421418 }
422419 }
423-
420+
421+ txn .commit ();
424422 }
425423
426424 @ Override
0 commit comments