Fixed updateConfiguration - updateHostDetails used to swallow the exceptions

This commit is contained in:
Alena Prokharchyk 2011-11-28 11:21:32 -08:00
parent cd957604b3
commit 102f460458
5 changed files with 28 additions and 30 deletions

View File

@ -79,7 +79,7 @@ public class CreateAccountCmd extends BaseCmd {
private String networkDomain;
@Parameter(name = ApiConstants.ACCOUNT_DETAILS, type = CommandType.MAP, description = "details for account used to store specific parameters")
private Map details;
private Map<String, String> details;
/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
@ -124,13 +124,13 @@ public class CreateAccountCmd extends BaseCmd {
return networkDomain;
}
public Map getDetails() {
public Map<String, String> getDetails() {
if (details == null || details.isEmpty()) {
return null;
}
Collection paramsCollection = details.values();
Map params = (Map) (paramsCollection.toArray())[0];
Collection<String> paramsCollection = details.values();
Map<String, String> params = (Map<String, String>) (paramsCollection.toArray())[0];
return params;
}

View File

@ -45,7 +45,7 @@ public interface AccountService {
*
* @return the user if created successfully, null otherwise
*/
UserAccount createUserAccount(String userName, String password, String firstName, String lastName, String email, String timezone, String accountName, short accountType, Long domainId, String networkDomain, Map details);
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);
/**
* Deletes a user by userId

View File

@ -322,74 +322,71 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
throw new InvalidParameterValueException(validationMsg);
}
//Execute all updates in a single transaction
Transaction txn = Transaction.currentTxn();
txn.start();
if (!_configDao.update(name, value)) {
s_logger.error("Failed to update configuration option, name: " + name + ", value:" + value);
throw new CloudRuntimeException("Failed to update configuration value. Please contact Cloud Support.");
}
if (Config.XenGuestNetwork.key().equals(name)) {
PreparedStatement pstmt = null;
if (Config.XenGuestNetwork.key().equalsIgnoreCase(name)) {
String sql = "update host_details set value=? where name=?";
Transaction txn = Transaction.currentTxn();
PreparedStatement pstmt = null;
try {
pstmt = txn.prepareAutoCloseStatement(sql);
pstmt.setString(1, DBEncryptionUtil.encrypt(value));
pstmt.setString(2, "guest.network.device");
pstmt.executeUpdate();
} catch (SQLException e) {
} catch (Throwable e) {
throw new CloudRuntimeException("Failed to update guest.network.device in host_details due to exception ", e);
}
} else if (Config.XenPrivateNetwork.key().equals(name)) {
} else if (Config.XenPrivateNetwork.key().equalsIgnoreCase(name)) {
String sql = "update host_details set value=? where name=?";
Transaction txn = Transaction.currentTxn();
PreparedStatement pstmt = null;
try {
pstmt = txn.prepareAutoCloseStatement(sql);
pstmt.setString(1, DBEncryptionUtil.encrypt(value));
pstmt.setString(2, "private.network.device");
pstmt.executeUpdate();
} catch (SQLException e) {
} catch (Throwable e) {
throw new CloudRuntimeException("Failed to update private.network.device in host_details due to exception ", e);
}
} else if (Config.XenPublicNetwork.key().equals(name)) {
} else if (Config.XenPublicNetwork.key().equalsIgnoreCase(name)) {
String sql = "update host_details set value=? where name=?";
Transaction txn = Transaction.currentTxn();
PreparedStatement pstmt = null;
try {
pstmt = txn.prepareAutoCloseStatement(sql);
pstmt.setString(1, DBEncryptionUtil.encrypt(value));
pstmt.setString(2, "public.network.device");
pstmt.executeUpdate();
} catch (SQLException e) {
} catch (Throwable e) {
throw new CloudRuntimeException("Failed to update public.network.device in host_details due to exception ", e);
}
} else if (Config.XenStorageNetwork1.key().equals(name)) {
} else if (Config.XenStorageNetwork1.key().equalsIgnoreCase(name)) {
String sql = "update host_details set value=? where name=?";
Transaction txn = Transaction.currentTxn();
PreparedStatement pstmt = null;
try {
pstmt = txn.prepareAutoCloseStatement(sql);
pstmt.setString(1, DBEncryptionUtil.encrypt(value));
pstmt.setString(2, "storage.network.device1");
pstmt.executeUpdate();
} catch (SQLException e) {
} catch (Throwable e) {
throw new CloudRuntimeException("Failed to update storage.network.device1 in host_details due to exception ", e);
}
} else if (Config.XenStorageNetwork2.key().equals(name)) {
String sql = "update host_details set value=? where name=?";
Transaction txn = Transaction.currentTxn();
PreparedStatement pstmt = null;
try {
pstmt = txn.prepareAutoCloseStatement(sql);
pstmt.setString(1, DBEncryptionUtil.encrypt(value));
pstmt.setString(2, "storage.network.device2");
pstmt.executeUpdate();
} catch (SQLException e) {
} catch (Throwable e) {
throw new CloudRuntimeException("Failed to update storage.network.device2 in host_details due to exception ", e);
}
} else if (Config.SystemVMUseLocalStorage.key().equalsIgnoreCase(name)) {
if (s_logger.isDebugEnabled()) {
@ -400,7 +397,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
if (serviceOffering != null) {
serviceOffering.setUseLocalStorage(useLocalStorage);
if (!_serviceOfferingDao.update(serviceOffering.getId(), serviceOffering)) {
s_logger.error("Failed to update ConsoleProxy offering's use_local_storage option to value:" + useLocalStorage);
throw new CloudRuntimeException("Failed to update ConsoleProxy offering's use_local_storage option to value:" + useLocalStorage);
}
}
@ -408,7 +405,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
if (serviceOffering != null) {
serviceOffering.setUseLocalStorage(useLocalStorage);
if (!_serviceOfferingDao.update(serviceOffering.getId(), serviceOffering)) {
s_logger.error("Failed to update SoftwareRouter offering's use_local_storage option to value:" + useLocalStorage);
throw new CloudRuntimeException("Failed to update SoftwareRouter offering's use_local_storage option to value:" + useLocalStorage);
}
}
@ -416,11 +413,12 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
if (serviceOffering != null) {
serviceOffering.setUseLocalStorage(useLocalStorage);
if (!_serviceOfferingDao.update(serviceOffering.getId(), serviceOffering)) {
s_logger.error("Failed to update SecondaryStorage offering's use_local_storage option to value:" + useLocalStorage);
throw new CloudRuntimeException("Failed to update SecondaryStorage offering's use_local_storage option to value:" + useLocalStorage);
}
}
}
txn.commit();
}
@Override

View File

@ -605,7 +605,7 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
@Override
@DB
@ActionEvent(eventType = EventTypes.EVENT_ACCOUNT_CREATE, eventDescription = "creating Account")
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) {
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) {
if (accountName == null) {
accountName = userName;

View File

@ -265,7 +265,7 @@ public class MockAccountManagerImpl implements Manager, AccountManager {
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) {
String networkDomain, Map<String, String> details) {
// TODO Auto-generated method stub
return null;
}