Skip to content

Commit 102f460

Browse files
Alena ProkharchykAlena Prokharchyk
authored andcommitted
Fixed updateConfiguration - updateHostDetails used to swallow the exceptions
1 parent cd95760 commit 102f460

5 files changed

Lines changed: 28 additions & 30 deletions

File tree

‎api/src/com/cloud/api/commands/CreateAccountCmd.java‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public class CreateAccountCmd extends BaseCmd {
7979
private String networkDomain;
8080

8181
@Parameter(name = ApiConstants.ACCOUNT_DETAILS, type = CommandType.MAP, description = "details for account used to store specific parameters")
82-
private Map details;
82+
private Map<String, String> details;
8383
/////////////////////////////////////////////////////
8484
/////////////////// Accessors ///////////////////////
8585
/////////////////////////////////////////////////////
@@ -124,13 +124,13 @@ public String getNetworkDomain() {
124124
return networkDomain;
125125
}
126126

127-
public Map getDetails() {
127+
public Map<String, String> getDetails() {
128128
if (details == null || details.isEmpty()) {
129129
return null;
130130
}
131131

132-
Collection paramsCollection = details.values();
133-
Map params = (Map) (paramsCollection.toArray())[0];
132+
Collection<String> paramsCollection = details.values();
133+
Map<String, String> params = (Map<String, String>) (paramsCollection.toArray())[0];
134134
return params;
135135
}
136136

‎api/src/com/cloud/user/AccountService.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public interface AccountService {
4545
*
4646
* @return the user if created successfully, null otherwise
4747
*/
48-
UserAccount createUserAccount(String userName, String password, String firstName, String lastName, String email, String timezone, String accountName, short accountType, Long domainId, String networkDomain, Map details);
48+
UserAccount createUserAccount(String userName, String password, String firstName, String lastName, String email, String timezone, String accountName, short accountType, Long domainId, String networkDomain, Map<String, String> details);
4949

5050
/**
5151
* Deletes a user by userId

‎server/src/com/cloud/configuration/ConfigurationManagerImpl.java‎

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -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

‎server/src/com/cloud/user/AccountManagerImpl.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,7 @@ private boolean doDisableAccount(long accountId) throws ConcurrentOperationExcep
605605
@Override
606606
@DB
607607
@ActionEvent(eventType = EventTypes.EVENT_ACCOUNT_CREATE, eventDescription = "creating Account")
608-
public UserAccount createUserAccount(String userName, String password, String firstName, String lastName, String email, String timezone, String accountName, short accountType, Long domainId, String networkDomain, Map details) {
608+
public UserAccount createUserAccount(String userName, String password, String firstName, String lastName, String email, String timezone, String accountName, short accountType, Long domainId, String networkDomain, Map<String, String> details) {
609609

610610
if (accountName == null) {
611611
accountName = userName;

‎server/test/com/cloud/user/MockAccountManagerImpl.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ public boolean lockAccount(long accountId) {
265265
public UserAccount createUserAccount(String userName, String password,
266266
String firstName, String lastName, String email, String timezone,
267267
String accountName, short accountType, Long domainId,
268-
String networkDomain, Map details) {
268+
String networkDomain, Map<String, String> details) {
269269
// TODO Auto-generated method stub
270270
return null;
271271
}

0 commit comments

Comments
 (0)