You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by da...@apache.org on 2015/05/26 12:14:06 UTC
[2/3] git commit: updated refs/heads/master to 7546335
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/75463356/server/src/com/cloud/configuration/ConfigurationManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java
index 182c67c..6c22ded 100644
--- a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java
+++ b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java
@@ -37,7 +37,6 @@ import javax.ejb.Local;
import javax.inject.Inject;
import javax.naming.ConfigurationException;
-import org.apache.log4j.Logger;
import org.apache.cloudstack.acl.SecurityChecker;
import org.apache.cloudstack.affinity.AffinityGroup;
import org.apache.cloudstack.affinity.AffinityGroupService;
@@ -86,6 +85,7 @@ import org.apache.cloudstack.region.dao.RegionDao;
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
import org.apache.cloudstack.storage.datastore.db.StoragePoolDetailsDao;
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
+import org.apache.log4j.Logger;
import com.cloud.alert.AlertManager;
import com.cloud.api.ApiDBUtils;
@@ -340,10 +340,10 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
@Override
public boolean configure(final String name, final Map<String, Object> params) throws ConfigurationException {
- String maxVolumeSizeInGbString = _configDao.getValue(Config.MaxVolumeSize.key());
+ final String maxVolumeSizeInGbString = _configDao.getValue(Config.MaxVolumeSize.key());
_maxVolumeSizeInGb = NumbersUtil.parseInt(maxVolumeSizeInGbString, Integer.parseInt(Config.MaxVolumeSize.getDefaultValue()));
- String defaultPageSizeString = _configDao.getValue(Config.DefaultPageSize.key());
+ final String defaultPageSizeString = _configDao.getValue(Config.DefaultPageSize.key());
_defaultPageSize = NumbersUtil.parseLong(defaultPageSizeString, Long.parseLong(Config.DefaultPageSize.getDefaultValue()));
populateConfigValuesForValidationSet();
@@ -416,10 +416,10 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
// As it is so common for people to forget about configuring
// management.network.cidr,
- String mgtCidr = _configDao.getValue(Config.ManagementNetwork.key());
+ final String mgtCidr = _configDao.getValue(Config.ManagementNetwork.key());
if (mgtCidr == null || mgtCidr.trim().isEmpty()) {
- String[] localCidrs = NetUtils.getLocalCidrs();
- if (localCidrs != null && (localCidrs.length > 0)) {
+ final String[] localCidrs = NetUtils.getLocalCidrs();
+ if (localCidrs != null && localCidrs.length > 0) {
s_logger.warn("Management network CIDR is not configured originally. Set it default to " + localCidrs[0]);
_alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_MANAGMENT_NODE, 0, new Long(0), "Management network CIDR is not configured originally. Set it default to "
@@ -442,8 +442,8 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
@Override
@DB
- public String updateConfiguration(long userId, String name, String category, String value, String scope, Long resourceId) {
- String validationMsg = validateConfigurationValue(name, value, scope);
+ public String updateConfiguration(final long userId, final String name, final String category, final String value, final String scope, final Long resourceId) {
+ final String validationMsg = validateConfigurationValue(name, value, scope);
if (validationMsg != null) {
s_logger.error("Invalid configuration option, name: " + name + ", value:" + value);
@@ -457,14 +457,14 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
if (scope != null && !scope.isEmpty() && !ConfigKey.Scope.Global.toString().equalsIgnoreCase(scope)) {
switch (ConfigKey.Scope.valueOf(scope)) {
case Zone:
- DataCenterVO zone = _zoneDao.findById(resourceId);
+ final DataCenterVO zone = _zoneDao.findById(resourceId);
if (zone == null) {
throw new InvalidParameterValueException("unable to find zone by id " + resourceId);
}
_dcDetailsDao.addDetail(resourceId, name, value, true);
break;
case Cluster:
- ClusterVO cluster = _clusterDao.findById(resourceId);
+ final ClusterVO cluster = _clusterDao.findById(resourceId);
if (cluster == null) {
throw new InvalidParameterValueException("unable to find cluster by id " + resourceId);
}
@@ -479,7 +479,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
break;
case StoragePool:
- StoragePoolVO pool = _storagePoolDao.findById(resourceId);
+ final StoragePoolVO pool = _storagePoolDao.findById(resourceId);
if (pool == null) {
throw new InvalidParameterValueException("unable to find storage pool by id " + resourceId);
}
@@ -494,7 +494,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
break;
case Account:
- AccountVO account = _accountDao.findById(resourceId);
+ final AccountVO account = _accountDao.findById(resourceId);
if (account == null) {
throw new InvalidParameterValueException("unable to find account by id " + resourceId);
}
@@ -514,7 +514,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
}
// Execute all updates in a single transaction
- TransactionLegacy txn = TransactionLegacy.currentTxn();
+ final TransactionLegacy txn = TransactionLegacy.currentTxn();
txn.start();
if (!_configDao.update(name, category, value)) {
@@ -524,65 +524,65 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
PreparedStatement pstmt = null;
if (Config.XenServerGuestNetwork.key().equalsIgnoreCase(name)) {
- String sql = "update host_details set value=? where name=?";
+ final String sql = "update host_details set value=? where name=?";
try {
pstmt = txn.prepareAutoCloseStatement(sql);
pstmt.setString(1, value);
pstmt.setString(2, "guest.network.device");
pstmt.executeUpdate();
- } catch (Throwable e) {
+ } catch (final Throwable e) {
throw new CloudRuntimeException("Failed to update guest.network.device in host_details due to exception ", e);
}
} else if (Config.XenServerPrivateNetwork.key().equalsIgnoreCase(name)) {
- String sql = "update host_details set value=? where name=?";
+ final String sql = "update host_details set value=? where name=?";
try {
pstmt = txn.prepareAutoCloseStatement(sql);
pstmt.setString(1, value);
pstmt.setString(2, "private.network.device");
pstmt.executeUpdate();
- } catch (Throwable e) {
+ } catch (final Throwable e) {
throw new CloudRuntimeException("Failed to update private.network.device in host_details due to exception ", e);
}
} else if (Config.XenServerPublicNetwork.key().equalsIgnoreCase(name)) {
- String sql = "update host_details set value=? where name=?";
+ final String sql = "update host_details set value=? where name=?";
try {
pstmt = txn.prepareAutoCloseStatement(sql);
pstmt.setString(1, value);
pstmt.setString(2, "public.network.device");
pstmt.executeUpdate();
- } catch (Throwable e) {
+ } catch (final Throwable e) {
throw new CloudRuntimeException("Failed to update public.network.device in host_details due to exception ", e);
}
} else if (Config.XenServerStorageNetwork1.key().equalsIgnoreCase(name)) {
- String sql = "update host_details set value=? where name=?";
+ final String sql = "update host_details set value=? where name=?";
try {
pstmt = txn.prepareAutoCloseStatement(sql);
pstmt.setString(1, value);
pstmt.setString(2, "storage.network.device1");
pstmt.executeUpdate();
- } catch (Throwable e) {
+ } catch (final Throwable e) {
throw new CloudRuntimeException("Failed to update storage.network.device1 in host_details due to exception ", e);
}
} else if (Config.XenServerStorageNetwork2.key().equals(name)) {
- String sql = "update host_details set value=? where name=?";
+ final String sql = "update host_details set value=? where name=?";
try {
pstmt = txn.prepareAutoCloseStatement(sql);
pstmt.setString(1, value);
pstmt.setString(2, "storage.network.device2");
pstmt.executeUpdate();
- } catch (Throwable e) {
+ } catch (final Throwable e) {
throw new CloudRuntimeException("Failed to update storage.network.device2 in host_details due to exception ", e);
}
} else if (Config.SecStorageSecureCopyCert.key().equalsIgnoreCase(name)) {
//FIXME - Ideally there should be a listener model to listen to global config changes and be able to take action gracefully.
//Expire the download urls
- String sqlTemplate = "update template_store_ref set download_url_created=?";
- String sqlVolume = "update volume_store_ref set download_url_created=?";
+ final String sqlTemplate = "update template_store_ref set download_url_created=?";
+ final String sqlVolume = "update volume_store_ref set download_url_created=?";
try {
// Change for templates
pstmt = txn.prepareAutoCloseStatement(sqlTemplate);
@@ -594,7 +594,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
pstmt.executeUpdate();
// Cleanup the download urls
_storageManager.cleanupDownloadUrls();
- } catch (Throwable e) {
+ } catch (final Throwable e) {
throw new CloudRuntimeException("Failed to clean up download URLs in template_store_ref or volume_store_ref due to exception ", e);
}
}
@@ -605,25 +605,25 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
@Override
@ActionEvent(eventType = EventTypes.EVENT_CONFIGURATION_VALUE_EDIT, eventDescription = "updating configuration")
- public Configuration updateConfiguration(UpdateCfgCmd cmd) throws InvalidParameterValueException {
- Long userId = CallContext.current().getCallingUserId();
- String name = cmd.getCfgName();
+ public Configuration updateConfiguration(final UpdateCfgCmd cmd) throws InvalidParameterValueException {
+ final Long userId = CallContext.current().getCallingUserId();
+ final String name = cmd.getCfgName();
String value = cmd.getValue();
- Long zoneId = cmd.getZoneId();
- Long clusterId = cmd.getClusterId();
- Long storagepoolId = cmd.getStoragepoolId();
- Long accountId = cmd.getAccountId();
- CallContext.current().setEventDetails(" Name: " + name + " New Value: " + (((name.toLowerCase()).contains("password")) ? "*****" : (((value == null) ? "" : value))));
+ final Long zoneId = cmd.getZoneId();
+ final Long clusterId = cmd.getClusterId();
+ final Long storagepoolId = cmd.getStoragepoolId();
+ final Long accountId = cmd.getAccountId();
+ CallContext.current().setEventDetails(" Name: " + name + " New Value: " + (name.toLowerCase().contains("password") ? "*****" : value == null ? "" : value));
// check if config value exists
- ConfigurationVO config = _configDao.findByName(name);
+ final ConfigurationVO config = _configDao.findByName(name);
String catergory = null;
// FIX ME - All configuration parameters are not moved from config.java to configKey
if (config == null) {
if (_configDepot.get(name) == null) {
s_logger.warn("Probably the component manager where configuration variable " + name + " is defined needs to implement Configurable interface");
- throw new InvalidParameterValueException("Config parameter with name " + name + " doesn't exist");
- }
+ throw new InvalidParameterValueException("Config parameter with name " + name + " doesn't exist");
+ }
catergory = _configDepot.get(name).category();
} else {
catergory = config.getCategory();
@@ -668,23 +668,23 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
throw new InvalidParameterValueException("cannot handle multiple IDs, provide only one ID corresponding to the scope");
}
- String updatedValue = updateConfiguration(userId, name, catergory, value, scope, id);
- if ((value == null && updatedValue == null) || updatedValue.equalsIgnoreCase(value)) {
+ final String updatedValue = updateConfiguration(userId, name, catergory, value, scope, id);
+ if (value == null && updatedValue == null || updatedValue.equalsIgnoreCase(value)) {
return _configDao.findByName(name);
} else {
throw new CloudRuntimeException("Unable to update configuration parameter " + name);
}
}
- private String validateConfigurationValue(String name, String value, String scope) {
+ private String validateConfigurationValue(final String name, String value, final String scope) {
- ConfigurationVO cfg = _configDao.findByName(name);
+ final ConfigurationVO cfg = _configDao.findByName(name);
if (cfg == null) {
s_logger.error("Missing configuration variable " + name + " in configuration table");
return "Invalid configuration variable.";
}
- String configScope = cfg.getScope();
+ final String configScope = cfg.getScope();
if (scope != null) {
if (!configScope.contains(scope)) {
s_logger.error("Invalid scope id provided for the parameter " + name);
@@ -692,10 +692,10 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
}
}
Class<?> type = null;
- Config c = Config.getConfig(name);
+ final Config c = Config.getConfig(name);
if (c == null) {
s_logger.warn("Did not find configuration " + name + " in Config.java. Perhaps moved to ConfigDepot");
- ConfigKey<?> configKey = _configDepot.get(name);
+ final ConfigKey<?> configKey = _configDepot.get(name);
if(configKey == null) {
s_logger.warn("Did not find configuration " + name + " in ConfigDepot too.");
return null;
@@ -714,7 +714,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
errMsg = "There was error in trying to parse value: " + value + ". Please enter a valid float value for parameter " + name;
Float.parseFloat(value);
}
- } catch (Exception e) {
+ } catch (final Exception e) {
// catching generic exception as some throws NullPointerException and some throws NumberFormatExcpeion
s_logger.error(errMsg);
return errMsg;
@@ -725,7 +725,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
return "Please enter either 'true' or 'false'.";
}
if (overprovisioningFactorsForValidation.contains(name)) {
- String msg = "value cannot be null for the parameter " + name;
+ final String msg = "value cannot be null for the parameter " + name;
s_logger.error(msg);
return msg;
}
@@ -734,13 +734,13 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
value = value.trim();
try {
- if (overprovisioningFactorsForValidation.contains(name) && (Float.parseFloat(value) < 1f)) {
- String msg = name + " should be greater than or equal to 1";
+ if (overprovisioningFactorsForValidation.contains(name) && Float.parseFloat(value) < 1f) {
+ final String msg = name + " should be greater than or equal to 1";
s_logger.error(msg);
throw new InvalidParameterValueException(msg);
}
- } catch (NumberFormatException e) {
- String msg = "There was an error trying to parse the float value for: " + name;
+ } catch (final NumberFormatException e) {
+ final String msg = "There was an error trying to parse the float value for: " + name;
s_logger.error(msg);
throw new InvalidParameterValueException(msg);
}
@@ -755,7 +755,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
if (type.equals(Integer.class) && configValuesForValidation.contains(name)) {
try {
- int val = Integer.parseInt(value);
+ final int val = Integer.parseInt(value);
if (val <= 0) {
throw new InvalidParameterValueException("Please enter a positive value for the configuration parameter:" + name);
}
@@ -763,7 +763,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
if ("vm.password.length".equalsIgnoreCase(name) && val < 6) {
throw new InvalidParameterValueException("Please enter a value greater than 6 for the configuration parameter:" + name);
}
- } catch (NumberFormatException e) {
+ } catch (final NumberFormatException e) {
s_logger.error("There was an error trying to parse the integer value for:" + name);
throw new InvalidParameterValueException("There was an error trying to parse the integer value for:" + name);
}
@@ -771,11 +771,11 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
if (type.equals(Float.class)) {
try {
- Float val = Float.parseFloat(value);
+ final Float val = Float.parseFloat(value);
if (weightBasedParametersForValidation.contains(name) && (val < 0f || val > 1f)) {
throw new InvalidParameterValueException("Please enter a value between 0 and 1 for the configuration parameter: " + name);
}
- } catch (NumberFormatException e) {
+ } catch (final NumberFormatException e) {
s_logger.error("There was an error trying to parse the float value for:" + name);
throw new InvalidParameterValueException("There was an error trying to parse the float value for:" + name);
}
@@ -787,7 +787,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
return null;
}
- String range = c.getRange();
+ final String range = c.getRange();
if (range == null) {
return null;
}
@@ -799,7 +799,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
s_logger.error("privateip range " + value + " is not a site local address for configuration variable " + name);
return "Please enter a site local IP address.";
}
- } catch (NullPointerException e) {
+ } catch (final NullPointerException e) {
s_logger.error("Error parsing ip address for " + name);
throw new InvalidParameterValueException("Error parsing ip address");
}
@@ -809,11 +809,11 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
return "Please enter a valid netmask.";
}
} else if (range.equals("hypervisorList")) {
- String[] hypervisors = value.split(",");
+ final String[] hypervisors = value.split(",");
if (hypervisors == null) {
return "Please enter hypervisor list, separated by comma";
}
- for (String hypervisor : hypervisors) {
+ for (final String hypervisor : hypervisors) {
if (HypervisorType.getType(hypervisor) == HypervisorType.Any || HypervisorType.getType(hypervisor) == HypervisorType.None) {
return "Please enter a valid hypervisor type";
}
@@ -832,10 +832,10 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
return "Please enter a valid string for domain name, prefixed with '*.' if applicable";
}
} else if (range.equals("routes")) {
- String[] routes = value.split(",");
- for (String route : routes) {
+ final String[] routes = value.split(",");
+ for (final String route : routes) {
if (route != null) {
- String routeToVerify = route.trim();
+ final String routeToVerify = route.trim();
if (!NetUtils.isValidCIDR(routeToVerify)) {
throw new InvalidParameterValueException("Invalid value for blacklisted route: " + route + ". Valid format is list"
+ " of cidrs separated by coma. Example: 10.1.1.0/24,192.168.0.0/24");
@@ -843,8 +843,8 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
}
}
} else {
- String[] options = range.split(",");
- for (String option : options) {
+ final String[] options = range.split(",");
+ for (final String option : options) {
if (option.trim().equalsIgnoreCase(value)) {
return null;
}
@@ -854,15 +854,15 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
}
} else if (type.equals(Integer.class)) {
- String[] options = range.split("-");
+ final String[] options = range.split("-");
if (options.length != 2) {
- String msg = "configuration range " + range + " for " + name + " is invalid";
+ final String msg = "configuration range " + range + " for " + name + " is invalid";
s_logger.error(msg);
return msg;
}
- int min = Integer.parseInt(options[0]);
- int max = Integer.parseInt(options[1]);
- int val = Integer.parseInt(value);
+ final int min = Integer.parseInt(options[0]);
+ final int max = Integer.parseInt(options[1]);
+ final int val = Integer.parseInt(value);
if (val < min || val > max) {
s_logger.error("configuration value for " + name + " is invalid");
return "Please enter : " + range;
@@ -871,51 +871,51 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
return null;
}
- private boolean podHasAllocatedPrivateIPs(long podId) {
- HostPodVO pod = _podDao.findById(podId);
- int count = _privateIpAddressDao.countIPs(podId, pod.getDataCenterId(), true);
- return (count > 0);
+ private boolean podHasAllocatedPrivateIPs(final long podId) {
+ final HostPodVO pod = _podDao.findById(podId);
+ final int count = _privateIpAddressDao.countIPs(podId, pod.getDataCenterId(), true);
+ return count > 0;
}
@DB
- protected void checkIfPodIsDeletable(long podId) {
- List<List<String>> tablesToCheck = new ArrayList<List<String>>();
+ protected void checkIfPodIsDeletable(final long podId) {
+ final List<List<String>> tablesToCheck = new ArrayList<List<String>>();
- HostPodVO pod = _podDao.findById(podId);
+ final HostPodVO pod = _podDao.findById(podId);
// Check if there are allocated private IP addresses in the pod
if (_privateIpAddressDao.countIPs(podId, pod.getDataCenterId(), true) != 0) {
throw new CloudRuntimeException("There are private IP addresses allocated for this pod");
}
- List<String> volumes = new ArrayList<String>();
+ final List<String> volumes = new ArrayList<String>();
volumes.add(0, "volumes");
volumes.add(1, "pod_id");
volumes.add(2, "there are storage volumes for this pod");
tablesToCheck.add(volumes);
- List<String> host = new ArrayList<String>();
+ final List<String> host = new ArrayList<String>();
host.add(0, "host");
host.add(1, "pod_id");
host.add(2, "there are servers running in this pod");
tablesToCheck.add(host);
- List<String> vmInstance = new ArrayList<String>();
+ final List<String> vmInstance = new ArrayList<String>();
vmInstance.add(0, "vm_instance");
vmInstance.add(1, "pod_id");
vmInstance.add(2, "there are virtual machines running in this pod");
tablesToCheck.add(vmInstance);
- List<String> cluster = new ArrayList<String>();
+ final List<String> cluster = new ArrayList<String>();
cluster.add(0, "cluster");
cluster.add(1, "pod_id");
cluster.add(2, "there are clusters in this pod");
tablesToCheck.add(cluster);
- for (List<String> table : tablesToCheck) {
- String tableName = table.get(0);
- String column = table.get(1);
- String errorMsg = table.get(2);
+ for (final List<String> table : tablesToCheck) {
+ final String tableName = table.get(0);
+ final String column = table.get(1);
+ final String errorMsg = table.get(2);
String dbName;
if (tableName.equals("event") || tableName.equals("cloud_usage") || tableName.equals("usage_vm_instance") || tableName.equals("usage_ip_address")
@@ -935,22 +935,22 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
selectSql += " and removed IS NULL";
}
- TransactionLegacy txn = TransactionLegacy.currentTxn();
+ final TransactionLegacy txn = TransactionLegacy.currentTxn();
try {
- PreparedStatement stmt = txn.prepareAutoCloseStatement(selectSql);
+ final PreparedStatement stmt = txn.prepareAutoCloseStatement(selectSql);
stmt.setLong(1, podId);
- ResultSet rs = stmt.executeQuery();
+ final ResultSet rs = stmt.executeQuery();
if (rs != null && rs.next()) {
throw new CloudRuntimeException("The pod cannot be deleted because " + errorMsg);
}
- } catch (SQLException ex) {
+ } catch (final SQLException ex) {
throw new CloudRuntimeException("The Management Server failed to detect if pod is deletable. Please contact Cloud Support.");
}
}
}
- private void checkPodAttributes(long podId, String podName, long zoneId, String gateway, String cidr, String startIp, String endIp, String allocationStateStr,
- boolean checkForDuplicates, boolean skipGatewayOverlapCheck) {
+ private void checkPodAttributes(final long podId, final String podName, final long zoneId, final String gateway, final String cidr, final String startIp, final String endIp, final String allocationStateStr,
+ final boolean checkForDuplicates, final boolean skipGatewayOverlapCheck) {
if (checkForDuplicates) {
// Check if the pod already exists
if (validPod(podName, zoneId)) {
@@ -992,7 +992,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
}
}
- String checkPodCIDRs = _configDao.getValue("check.pod.cidrs");
+ final String checkPodCIDRs = _configDao.getValue("check.pod.cidrs");
if (checkPodCIDRs == null || checkPodCIDRs.trim().isEmpty() || Boolean.parseBoolean(checkPodCIDRs)) {
checkPodCidrSubnets(zoneId, podId, cidr);
/*
@@ -1006,7 +1006,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
if (allocationStateStr != null && !allocationStateStr.isEmpty()) {
try {
Grouping.AllocationState.valueOf(allocationStateStr);
- } catch (IllegalArgumentException ex) {
+ } catch (final IllegalArgumentException ex) {
throw new InvalidParameterValueException("Unable to resolve Allocation State '" + allocationStateStr + "' to a supported state");
}
}
@@ -1014,7 +1014,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
@Override
@DB
- public boolean deletePod(DeletePodCmd cmd) {
+ public boolean deletePod(final DeletePodCmd cmd) {
final Long podId = cmd.getId();
// Make sure the pod exists
@@ -1028,44 +1028,44 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
Transaction.execute(new TransactionCallbackNoReturn() {
@Override
- public void doInTransactionWithoutResult(TransactionStatus status) {
- // Delete private ip addresses for the pod if there are any
- List<DataCenterIpAddressVO> privateIps = _privateIpAddressDao.listByPodIdDcId(podId, pod.getDataCenterId());
- if (!privateIps.isEmpty()) {
- if (!(_privateIpAddressDao.deleteIpAddressByPod(podId))) {
- throw new CloudRuntimeException("Failed to cleanup private ip addresses for pod " + podId);
- }
- }
+ public void doInTransactionWithoutResult(final TransactionStatus status) {
+ // Delete private ip addresses for the pod if there are any
+ final List<DataCenterIpAddressVO> privateIps = _privateIpAddressDao.listByPodIdDcId(podId, pod.getDataCenterId());
+ if (!privateIps.isEmpty()) {
+ if (!_privateIpAddressDao.deleteIpAddressByPod(podId)) {
+ throw new CloudRuntimeException("Failed to cleanup private ip addresses for pod " + podId);
+ }
+ }
- // Delete link local ip addresses for the pod
- List<DataCenterLinkLocalIpAddressVO> localIps = _linkLocalIpAllocDao.listByPodIdDcId(podId, pod.getDataCenterId());
- if (!localIps.isEmpty()) {
- if (!(_linkLocalIpAllocDao.deleteIpAddressByPod(podId))) {
- throw new CloudRuntimeException("Failed to cleanup private ip addresses for pod " + podId);
- }
- }
+ // Delete link local ip addresses for the pod
+ final List<DataCenterLinkLocalIpAddressVO> localIps = _linkLocalIpAllocDao.listByPodIdDcId(podId, pod.getDataCenterId());
+ if (!localIps.isEmpty()) {
+ if (!_linkLocalIpAllocDao.deleteIpAddressByPod(podId)) {
+ throw new CloudRuntimeException("Failed to cleanup private ip addresses for pod " + podId);
+ }
+ }
- // Delete vlans associated with the pod
- List<? extends Vlan> vlans = _networkModel.listPodVlans(podId);
- if (vlans != null && !vlans.isEmpty()) {
- for (Vlan vlan : vlans) {
- _vlanDao.remove(vlan.getId());
- }
- }
+ // Delete vlans associated with the pod
+ final List<? extends Vlan> vlans = _networkModel.listPodVlans(podId);
+ if (vlans != null && !vlans.isEmpty()) {
+ for (final Vlan vlan : vlans) {
+ _vlanDao.remove(vlan.getId());
+ }
+ }
- // Delete corresponding capacity records
- _capacityDao.removeBy(null, null, podId, null, null);
+ // Delete corresponding capacity records
+ _capacityDao.removeBy(null, null, podId, null, null);
- // Delete the pod
- if (!(_podDao.remove(podId))) {
- throw new CloudRuntimeException("Failed to delete pod " + podId);
- }
+ // Delete the pod
+ if (!_podDao.remove(podId)) {
+ throw new CloudRuntimeException("Failed to delete pod " + podId);
+ }
- // remove from dedicated resources
- DedicatedResourceVO dr = _dedicatedDao.findByPodId(podId);
- if (dr != null) {
- _dedicatedDao.remove(dr.getId());
- }
+ // remove from dedicated resources
+ final DedicatedResourceVO dr = _dedicatedDao.findByPodId(podId);
+ if (dr != null) {
+ _dedicatedDao.remove(dr.getId());
+ }
}
});
@@ -1073,7 +1073,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
}
@Override
- public Pod editPod(UpdatePodCmd cmd) {
+ public Pod editPod(final UpdatePodCmd cmd) {
return editPod(cmd.getId(), cmd.getPodName(), cmd.getStartIp(), cmd.getEndIp(), cmd.getGateway(), cmd.getNetmask(), cmd.getAllocationState());
}
@@ -1088,7 +1088,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
throw new InvalidParameterValueException("Unable to find pod by id " + id);
}
- String[] existingPodIpRange = pod.getDescription().split("-");
+ final String[] existingPodIpRange = pod.getDescription().split("-");
String[] leftRangeToAdd = null;
String[] rightRangeToAdd = null;
boolean allowToDownsize = false;
@@ -1098,8 +1098,8 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
if (podHasAllocatedPrivateIPs(id)) {
if (netmask != null) {
- long newCidr = NetUtils.getCidrSize(netmask);
- long oldCidr = pod.getCidrSize();
+ final long newCidr = NetUtils.getCidrSize(netmask);
+ final long oldCidr = pod.getCidrSize();
if (newCidr > oldCidr) {
throw new CloudRuntimeException("The specified pod has allocated private IP addresses, so its IP address range can be extended only");
@@ -1111,7 +1111,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
throw new CloudRuntimeException("The specified pod has allocated private IP addresses, so its IP address range can be extended only");
} else {
leftRangeToAdd = new String[2];
- long endIpForUpdate = NetUtils.ip2Long(existingPodIpRange[0]) - 1;
+ final long endIpForUpdate = NetUtils.ip2Long(existingPodIpRange[0]) - 1;
leftRangeToAdd[0] = startIp;
leftRangeToAdd[1] = NetUtils.long2Ip(endIpForUpdate);
}
@@ -1122,7 +1122,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
throw new CloudRuntimeException("The specified pod has allocated private IP addresses, so its IP address range can be extended only");
} else {
rightRangeToAdd = new String[2];
- long startIpForUpdate = NetUtils.ip2Long(existingPodIpRange[1]) + 1;
+ final long startIpForUpdate = NetUtils.ip2Long(existingPodIpRange[1]) + 1;
rightRangeToAdd[0] = NetUtils.long2Ip(startIpForUpdate);
rightRangeToAdd[1] = endIp;
}
@@ -1140,7 +1140,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
netmask = NetUtils.getCidrNetmask(pod.getCidrSize());
}
- String oldPodName = pod.getName();
+ final String oldPodName = pod.getName();
if (name == null) {
name = oldPodName;
}
@@ -1163,7 +1163,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
// Verify pod's attributes
final String cidr = NetUtils.ipAndNetMaskToCidr(gateway, netmask);
- boolean checkForDuplicates = !oldPodName.equals(name);
+ final boolean checkForDuplicates = !oldPodName.equals(name);
checkPodAttributes(id, name, pod.getDataCenterId(), gateway, cidr, startIp, endIp, allocationStateStr, checkForDuplicates, false);
try {
@@ -1179,8 +1179,8 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
final String gatewayFinal = gateway;
Transaction.execute(new TransactionCallbackNoReturn() {
@Override
- public void doInTransactionWithoutResult(TransactionStatus status) {
- long zoneId = pod.getDataCenterId();
+ public void doInTransactionWithoutResult(final TransactionStatus status) {
+ final long zoneId = pod.getDataCenterId();
String startIp = startIpFinal;
String endIp = endIpFinal;
@@ -1188,46 +1188,46 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
if (!allowToDownsizeFinal) {
if (leftRangeToAddFinal != null) {
_zoneDao.addPrivateIpAddress(zoneId, pod.getId(), leftRangeToAddFinal[0], leftRangeToAddFinal[1]);
- }
+ }
if (rightRangeToAddFinal != null) {
_zoneDao.addPrivateIpAddress(zoneId, pod.getId(), rightRangeToAddFinal[0], rightRangeToAddFinal[1]);
- }
+ }
- } else {
- // delete the old range
- _zoneDao.deletePrivateIpAddressByPod(pod.getId());
+ } else {
+ // delete the old range
+ _zoneDao.deletePrivateIpAddressByPod(pod.getId());
- // add the new one
- if (startIp == null) {
+ // add the new one
+ if (startIp == null) {
startIp = existingPodIpRangeFinal[0];
- }
+ }
- if (endIp == null) {
+ if (endIp == null) {
endIp = existingPodIpRangeFinal[1];
- }
+ }
- _zoneDao.addPrivateIpAddress(zoneId, pod.getId(), startIp, endIp);
- }
+ _zoneDao.addPrivateIpAddress(zoneId, pod.getId(), startIp, endIp);
+ }
pod.setName(nameFinal);
- pod.setDataCenterId(zoneId);
+ pod.setDataCenterId(zoneId);
pod.setGateway(gatewayFinal);
- pod.setCidrAddress(getCidrAddress(cidr));
- pod.setCidrSize(getCidrSize(cidr));
-
- String ipRange = startIp + "-" + endIp;
- pod.setDescription(ipRange);
- Grouping.AllocationState allocationState = null;
- if (allocationStateStrFinal != null && !allocationStateStrFinal.isEmpty()) {
- allocationState = Grouping.AllocationState.valueOf(allocationStateStrFinal);
- pod.setAllocationState(allocationState);
- }
+ pod.setCidrAddress(getCidrAddress(cidr));
+ pod.setCidrSize(getCidrSize(cidr));
+
+ final String ipRange = startIp + "-" + endIp;
+ pod.setDescription(ipRange);
+ Grouping.AllocationState allocationState = null;
+ if (allocationStateStrFinal != null && !allocationStateStrFinal.isEmpty()) {
+ allocationState = Grouping.AllocationState.valueOf(allocationStateStrFinal);
+ pod.setAllocationState(allocationState);
+ }
- _podDao.update(id, pod);
+ _podDao.update(id, pod);
}
});
- } catch (Exception e) {
+ } catch (final Exception e) {
s_logger.error("Unable to edit pod due to " + e.getMessage(), e);
throw new CloudRuntimeException("Failed to edit pod. Please contact Cloud Support.");
}
@@ -1236,7 +1236,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
}
@Override
- public Pod createPod(long zoneId, String name, String startIp, String endIp, String gateway, String netmask, String allocationState) {
+ public Pod createPod(final long zoneId, final String name, final String startIp, final String endIp, final String gateway, final String netmask, String allocationState) {
// Check if the gateway is a valid IP address
if (!NetUtils.isValidIp(gateway)) {
throw new InvalidParameterValueException("The gateway is invalid");
@@ -1246,9 +1246,9 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
throw new InvalidParameterValueException("The netmask is invalid");
}
- String cidr = NetUtils.ipAndNetMaskToCidr(gateway, netmask);
+ final String cidr = NetUtils.ipAndNetMaskToCidr(gateway, netmask);
- Long userId = CallContext.current().getCallingUserId();
+ final Long userId = CallContext.current().getCallingUserId();
if (allocationState == null) {
allocationState = Grouping.AllocationState.Enabled.toString();
@@ -1258,8 +1258,8 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
@Override
@DB
- public HostPodVO createPod(long userId, String podName, final long zoneId, String gateway, String cidr, final String startIp, String endIp, String allocationStateStr,
- boolean skipGatewayOverlapCheck) {
+ public HostPodVO createPod(final long userId, final String podName, final long zoneId, final String gateway, final String cidr, final String startIp, String endIp, final String allocationStateStr,
+ final boolean skipGatewayOverlapCheck) {
// Check if the zone is valid
if (!validZone(zoneId)) {
@@ -1267,15 +1267,15 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
}
// Check if zone is disabled
- DataCenterVO zone = _zoneDao.findById(zoneId);
- Account account = CallContext.current().getCallingAccount();
+ final DataCenterVO zone = _zoneDao.findById(zoneId);
+ final Account account = CallContext.current().getCallingAccount();
if (Grouping.AllocationState.Disabled == zone.getAllocationState()
&& !_accountMgr.isRootAdmin(account.getId())) {
throw new PermissionDeniedException("Cannot perform this operation, Zone is currently disabled: " + zoneId);
}
- String cidrAddress = getCidrAddress(cidr);
- int cidrSize = getCidrSize(cidr);
+ final String cidrAddress = getCidrAddress(cidr);
+ final int cidrSize = getCidrSize(cidr);
// endIp is an optional parameter; if not specified - default it to the
// end ip of the pod's cidr
@@ -1307,82 +1307,82 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
final String endIpFinal = endIp;
return Transaction.execute(new TransactionCallback<HostPodVO>() {
@Override
- public HostPodVO doInTransaction(TransactionStatus status) {
+ public HostPodVO doInTransaction(final TransactionStatus status) {
- HostPodVO pod = _podDao.persist(podFinal);
+ final HostPodVO pod = _podDao.persist(podFinal);
- if (startIp != null) {
+ if (startIp != null) {
_zoneDao.addPrivateIpAddress(zoneId, pod.getId(), startIp, endIpFinal);
- }
+ }
- String[] linkLocalIpRanges = getLinkLocalIPRange();
- if (linkLocalIpRanges != null) {
- _zoneDao.addLinkLocalIpAddress(zoneId, pod.getId(), linkLocalIpRanges[0], linkLocalIpRanges[1]);
- }
+ final String[] linkLocalIpRanges = getLinkLocalIPRange();
+ if (linkLocalIpRanges != null) {
+ _zoneDao.addLinkLocalIpAddress(zoneId, pod.getId(), linkLocalIpRanges[0], linkLocalIpRanges[1]);
+ }
- return pod;
- }
+ return pod;
+ }
});
}
@DB
- protected void checkIfZoneIsDeletable(long zoneId) {
- List<List<String>> tablesToCheck = new ArrayList<List<String>>();
+ protected void checkIfZoneIsDeletable(final long zoneId) {
+ final List<List<String>> tablesToCheck = new ArrayList<List<String>>();
- List<String> host = new ArrayList<String>();
+ final List<String> host = new ArrayList<String>();
host.add(0, "host");
host.add(1, "data_center_id");
host.add(2, "there are servers running in this zone");
tablesToCheck.add(host);
- List<String> hostPodRef = new ArrayList<String>();
+ final List<String> hostPodRef = new ArrayList<String>();
hostPodRef.add(0, "host_pod_ref");
hostPodRef.add(1, "data_center_id");
hostPodRef.add(2, "there are pods in this zone");
tablesToCheck.add(hostPodRef);
- List<String> privateIP = new ArrayList<String>();
+ final List<String> privateIP = new ArrayList<String>();
privateIP.add(0, "op_dc_ip_address_alloc");
privateIP.add(1, "data_center_id");
privateIP.add(2, "there are private IP addresses allocated for this zone");
tablesToCheck.add(privateIP);
- List<String> publicIP = new ArrayList<String>();
+ final List<String> publicIP = new ArrayList<String>();
publicIP.add(0, "user_ip_address");
publicIP.add(1, "data_center_id");
publicIP.add(2, "there are public IP addresses allocated for this zone");
tablesToCheck.add(publicIP);
- List<String> vmInstance = new ArrayList<String>();
+ final List<String> vmInstance = new ArrayList<String>();
vmInstance.add(0, "vm_instance");
vmInstance.add(1, "data_center_id");
vmInstance.add(2, "there are virtual machines running in this zone");
tablesToCheck.add(vmInstance);
- List<String> volumes = new ArrayList<String>();
+ final List<String> volumes = new ArrayList<String>();
volumes.add(0, "volumes");
volumes.add(1, "data_center_id");
volumes.add(2, "there are storage volumes for this zone");
tablesToCheck.add(volumes);
- List<String> physicalNetworks = new ArrayList<String>();
+ final List<String> physicalNetworks = new ArrayList<String>();
physicalNetworks.add(0, "physical_network");
physicalNetworks.add(1, "data_center_id");
physicalNetworks.add(2, "there are physical networks in this zone");
tablesToCheck.add(physicalNetworks);
- List<String> vmwareDcs = new ArrayList<String>();
+ final List<String> vmwareDcs = new ArrayList<String>();
vmwareDcs.add(0, "vmware_data_center_zone_map");
vmwareDcs.add(1, "zone_id");
vmwareDcs.add(2, "there are VMware datacenters associated with this zone. Remove VMware DC from this zone.");
tablesToCheck.add(vmwareDcs);
- for (List<String> table : tablesToCheck) {
- String tableName = table.get(0);
- String column = table.get(1);
- String errorMsg = table.get(2);
+ for (final List<String> table : tablesToCheck) {
+ final String tableName = table.get(0);
+ final String column = table.get(1);
+ final String errorMsg = table.get(2);
- String dbName = "cloud";
+ final String dbName = "cloud";
String selectSql = "SELECT * FROM `" + dbName + "`.`" + tableName + "` WHERE " + column + " = ?";
@@ -1406,23 +1406,23 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
selectSql += " AND state != '" + VirtualMachine.State.Expunging.toString() + "' AND removed IS NULL";
}
- TransactionLegacy txn = TransactionLegacy.currentTxn();
+ final TransactionLegacy txn = TransactionLegacy.currentTxn();
try {
- PreparedStatement stmt = txn.prepareAutoCloseStatement(selectSql);
+ final PreparedStatement stmt = txn.prepareAutoCloseStatement(selectSql);
stmt.setLong(1, zoneId);
- ResultSet rs = stmt.executeQuery();
+ final ResultSet rs = stmt.executeQuery();
if (rs != null && rs.next()) {
throw new CloudRuntimeException("The zone is not deletable because " + errorMsg);
}
- } catch (SQLException ex) {
+ } catch (final SQLException ex) {
throw new CloudRuntimeException("The Management Server failed to detect if zone is deletable. Please contact Cloud Support.");
}
}
}
- private void checkZoneParameters(String zoneName, String dns1, String dns2, String internalDns1, String internalDns2, boolean checkForDuplicates, Long domainId,
- String allocationStateStr, String ip6Dns1, String ip6Dns2) {
+ private void checkZoneParameters(final String zoneName, final String dns1, final String dns2, final String internalDns1, final String internalDns2, final boolean checkForDuplicates, final Long domainId,
+ final String allocationStateStr, final String ip6Dns1, final String ip6Dns2) {
if (checkForDuplicates) {
// Check if a zone with the specified name already exists
if (validZone(zoneName)) {
@@ -1432,7 +1432,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
// check if valid domain
if (domainId != null) {
- DomainVO domain = _domainDao.findById(domainId);
+ final DomainVO domain = _domainDao.findById(domainId);
if (domain == null) {
throw new InvalidParameterValueException("Please specify a valid domain id");
@@ -1449,7 +1449,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
throw new InvalidParameterValueException("Please enter a valid IP address for DNS2");
}
- if ((internalDns1 != null && internalDns1.length() > 0 && !NetUtils.isValidIp(internalDns1))) {
+ if (internalDns1 != null && internalDns1.length() > 0 && !NetUtils.isValidIp(internalDns1)) {
throw new InvalidParameterValueException("Please enter a valid IP address for internal DNS1");
}
@@ -1468,13 +1468,13 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
if (allocationStateStr != null && !allocationStateStr.isEmpty()) {
try {
Grouping.AllocationState.valueOf(allocationStateStr);
- } catch (IllegalArgumentException ex) {
+ } catch (final IllegalArgumentException ex) {
throw new InvalidParameterValueException("Unable to resolve Allocation State '" + allocationStateStr + "' to a supported state");
}
}
}
- private void checkIpRange(String startIp, String endIp, String cidrAddress, long cidrSize) {
+ private void checkIpRange(final String startIp, final String endIp, final String cidrAddress, final long cidrSize) {
if (!NetUtils.isValidIp(startIp)) {
throw new InvalidParameterValueException("The start address of the IP range is not a valid IP address.");
}
@@ -1497,28 +1497,30 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
}
- private void checkOverlapPublicIpRange(Long zoneId, String startIp, String endIp) {
- long privateStartIp = NetUtils.ip2Long(startIp);
- long privateEndIp = NetUtils.ip2Long(endIp);
+ private void checkOverlapPublicIpRange(final Long zoneId, final String startIp, final String endIp) {
+ final long privateStartIp = NetUtils.ip2Long(startIp);
+ final long privateEndIp = NetUtils.ip2Long(endIp);
- List<IPAddressVO> existingPublicIPs = _publicIpAddressDao.listByDcId(zoneId);
- for (IPAddressVO publicIPVO : existingPublicIPs) {
- long publicIP = NetUtils.ip2Long(publicIPVO.getAddress().addr());
- if ((publicIP >= privateStartIp) && (publicIP <= privateEndIp)) {
+ final List<IPAddressVO> existingPublicIPs = _publicIpAddressDao.listByDcId(zoneId);
+ for (final IPAddressVO publicIPVO : existingPublicIPs) {
+ final long publicIP = NetUtils.ip2Long(publicIPVO.getAddress().addr());
+ if (publicIP >= privateStartIp && publicIP <= privateEndIp) {
throw new InvalidParameterValueException("The Start IP and endIP address range overlap with Public IP :" + publicIPVO.getAddress().addr());
}
}
}
- private void checkOverlapPrivateIpRange(Long zoneId, String startIp, String endIp) {
+ private void checkOverlapPrivateIpRange(final Long zoneId, final String startIp, final String endIp) {
- List<HostPodVO> podsInZone = _podDao.listByDataCenterId(zoneId);
- for (HostPodVO hostPod : podsInZone) {
- String[] IpRange = hostPod.getDescription().split("-");
- if (IpRange[0] == null || IpRange[1] == null)
+ final List<HostPodVO> podsInZone = _podDao.listByDataCenterId(zoneId);
+ for (final HostPodVO hostPod : podsInZone) {
+ final String[] IpRange = hostPod.getDescription().split("-");
+ if (IpRange[0] == null || IpRange[1] == null) {
continue;
- if (!NetUtils.isValidIp(IpRange[0]) || !NetUtils.isValidIp(IpRange[1]))
+ }
+ if (!NetUtils.isValidIp(IpRange[0]) || !NetUtils.isValidIp(IpRange[1])) {
continue;
+ }
if (NetUtils.ipRangesOverlap(startIp, endIp, IpRange[0], IpRange[1])) {
throw new InvalidParameterValueException("The Start IP and endIP address range overlap with private IP :" + IpRange[0] + ":" + IpRange[1]);
}
@@ -1528,7 +1530,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
@Override
@DB
@ActionEvent(eventType = EventTypes.EVENT_ZONE_DELETE, eventDescription = "deleting zone", async = false)
- public boolean deleteZone(DeleteZoneCmd cmd) {
+ public boolean deleteZone(final DeleteZoneCmd cmd) {
final Long zoneId = cmd.getId();
@@ -1541,33 +1543,33 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
return Transaction.execute(new TransactionCallback<Boolean>() {
@Override
- public Boolean doInTransaction(TransactionStatus status) {
- // delete vlans for this zone
- List<VlanVO> vlans = _vlanDao.listByZone(zoneId);
- for (VlanVO vlan : vlans) {
- _vlanDao.remove(vlan.getId());
- }
-
- boolean success = _zoneDao.remove(zoneId);
-
- if (success) {
- // delete all capacity records for the zone
- _capacityDao.removeBy(null, zoneId, null, null, null);
- // remove from dedicated resources
- DedicatedResourceVO dr = _dedicatedDao.findByZoneId(zoneId);
- if (dr != null) {
- _dedicatedDao.remove(dr.getId());
- // find the group associated and check if there are any more
- // resources under that group
- List<DedicatedResourceVO> resourcesInGroup = _dedicatedDao.listByAffinityGroupId(dr.getAffinityGroupId());
- if (resourcesInGroup.isEmpty()) {
- // delete the group
- _affinityGroupService.deleteAffinityGroup(dr.getAffinityGroupId(), null, null, null);
+ public Boolean doInTransaction(final TransactionStatus status) {
+ // delete vlans for this zone
+ final List<VlanVO> vlans = _vlanDao.listByZone(zoneId);
+ for (final VlanVO vlan : vlans) {
+ _vlanDao.remove(vlan.getId());
+ }
+
+ final boolean success = _zoneDao.remove(zoneId);
+
+ if (success) {
+ // delete all capacity records for the zone
+ _capacityDao.removeBy(null, zoneId, null, null, null);
+ // remove from dedicated resources
+ final DedicatedResourceVO dr = _dedicatedDao.findByZoneId(zoneId);
+ if (dr != null) {
+ _dedicatedDao.remove(dr.getId());
+ // find the group associated and check if there are any more
+ // resources under that group
+ final List<DedicatedResourceVO> resourcesInGroup = _dedicatedDao.listByAffinityGroupId(dr.getAffinityGroupId());
+ if (resourcesInGroup.isEmpty()) {
+ // delete the group
+ _affinityGroupService.deleteAffinityGroup(dr.getAffinityGroupId(), null, null, null);
+ }
+ }
}
- }
- }
- return success;
+ return success;
}
});
}
@@ -1575,7 +1577,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
@Override
@DB
@ActionEvent(eventType = EventTypes.EVENT_ZONE_EDIT, eventDescription = "editing zone", async = false)
- public DataCenter editZone(UpdateZoneCmd cmd) {
+ public DataCenter editZone(final UpdateZoneCmd cmd) {
// Parameter validation as from execute() method in V1
final Long zoneId = cmd.getId();
String zoneName = cmd.getZoneName();
@@ -1586,23 +1588,23 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
String internalDns1 = cmd.getInternalDns1();
String internalDns2 = cmd.getInternalDns2();
String guestCidr = cmd.getGuestCidrAddress();
- List<String> dnsSearchOrder = cmd.getDnsSearchOrder();
+ final List<String> dnsSearchOrder = cmd.getDnsSearchOrder();
final Boolean isPublic = cmd.isPublic();
final String allocationStateStr = cmd.getAllocationState();
final String dhcpProvider = cmd.getDhcpProvider();
- Map<?, ?> detailsMap = cmd.getDetails();
- String networkDomain = cmd.getDomain();
- Boolean localStorageEnabled = cmd.getLocalStorageEnabled();
+ final Map<?, ?> detailsMap = cmd.getDetails();
+ final String networkDomain = cmd.getDomain();
+ final Boolean localStorageEnabled = cmd.getLocalStorageEnabled();
final Map<String, String> newDetails = new HashMap<String, String>();
if (detailsMap != null) {
- Collection<?> zoneDetailsCollection = detailsMap.values();
- Iterator<?> iter = zoneDetailsCollection.iterator();
+ final Collection<?> zoneDetailsCollection = detailsMap.values();
+ final Iterator<?> iter = zoneDetailsCollection.iterator();
while (iter.hasNext()) {
- HashMap<?, ?> detail = (HashMap<?, ?>)iter.next();
- String key = (String)detail.get("key");
- String value = (String)detail.get("value");
- if ((key == null) || (value == null)) {
+ final HashMap<?, ?> detail = (HashMap<?, ?>)iter.next();
+ final String key = (String)detail.get("key");
+ final String value = (String)detail.get("value");
+ if (key == null || value == null) {
throw new InvalidParameterValueException(
"Invalid Zone Detail specified, fields 'key' and 'value' cannot be null, please specify details in the form: details[0].key=XXX&details[0].value=YYY");
}
@@ -1618,7 +1620,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
// add the domain prefix list to details if not null
if (dnsSearchOrder != null) {
- for (String dom : dnsSearchOrder) {
+ for (final String dom : dnsSearchOrder) {
if (!NetUtils.verifyDomainName(dom)) {
throw new InvalidParameterValueException(
"Invalid network domain suffixes. Total length shouldn't exceed 190 chars. Each domain label must be between 1 and 63 characters long, can contain ASCII letters 'a' through 'z', the digits '0' through '9', "
@@ -1637,7 +1639,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
zoneName = zone.getName();
}
- if ((guestCidr != null) && !NetUtils.validateGuestCidr(guestCidr)) {
+ if (guestCidr != null && !NetUtils.validateGuestCidr(guestCidr)) {
throw new InvalidParameterValueException("Please enter a valid guest cidr");
}
@@ -1646,7 +1648,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
throw new InvalidParameterValueException("A zone with ID: " + zoneId + " does not exist.");
}
- String oldZoneName = zone.getName();
+ final String oldZoneName = zone.getName();
if (zoneName == null) {
zoneName = oldZoneName;
@@ -1689,10 +1691,10 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
}
}
- boolean checkForDuplicates = !zoneName.equals(oldZoneName);
+ final boolean checkForDuplicates = !zoneName.equals(oldZoneName);
checkZoneParameters(zoneName, dns1, dns2, internalDns1, internalDns2, checkForDuplicates, null, allocationStateStr, ip6Dns1, ip6Dns2);// not allowing updating
- // domain associated with
- // a zone, once created
+ // domain associated with
+ // a zone, once created
zone.setName(zoneName);
zone.setDns1(dns1);
@@ -1716,78 +1718,78 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
Transaction.execute(new TransactionCallbackNoReturn() {
@Override
- public void doInTransactionWithoutResult(TransactionStatus status) {
- Map<String, String> updatedDetails = new HashMap<String, String>();
- _zoneDao.loadDetails(zone);
- if (zone.getDetails() != null) {
- updatedDetails.putAll(zone.getDetails());
- }
- updatedDetails.putAll(newDetails);
- zone.setDetails(updatedDetails);
-
- if (allocationStateStr != null && !allocationStateStr.isEmpty()) {
- Grouping.AllocationState allocationState = Grouping.AllocationState.valueOf(allocationStateStr);
-
- if (allocationState == Grouping.AllocationState.Enabled) {
- // check if zone has necessary trafficTypes before enabling
- try {
- PhysicalNetwork mgmtPhyNetwork;
- // zone should have a physical network with management
- // traffiType
+ public void doInTransactionWithoutResult(final TransactionStatus status) {
+ final Map<String, String> updatedDetails = new HashMap<String, String>();
+ _zoneDao.loadDetails(zone);
+ if (zone.getDetails() != null) {
+ updatedDetails.putAll(zone.getDetails());
+ }
+ updatedDetails.putAll(newDetails);
+ zone.setDetails(updatedDetails);
+
+ if (allocationStateStr != null && !allocationStateStr.isEmpty()) {
+ final Grouping.AllocationState allocationState = Grouping.AllocationState.valueOf(allocationStateStr);
+
+ if (allocationState == Grouping.AllocationState.Enabled) {
+ // check if zone has necessary trafficTypes before enabling
+ try {
+ PhysicalNetwork mgmtPhyNetwork;
+ // zone should have a physical network with management
+ // traffiType
mgmtPhyNetwork = _networkModel.getDefaultPhysicalNetworkByZoneAndTrafficType(zoneId, TrafficType.Management);
- if (NetworkType.Advanced == zone.getNetworkType() && !zone.isSecurityGroupEnabled()) {
- // advanced zone without SG should have a physical
- // network with public Thpe
- _networkModel.getDefaultPhysicalNetworkByZoneAndTrafficType(zoneId, TrafficType.Public);
- }
+ if (NetworkType.Advanced == zone.getNetworkType() && !zone.isSecurityGroupEnabled()) {
+ // advanced zone without SG should have a physical
+ // network with public Thpe
+ _networkModel.getDefaultPhysicalNetworkByZoneAndTrafficType(zoneId, TrafficType.Public);
+ }
- try {
- _networkModel.getDefaultPhysicalNetworkByZoneAndTrafficType(zoneId, TrafficType.Storage);
- } catch (InvalidParameterValueException noStorage) {
- PhysicalNetworkTrafficTypeVO mgmtTraffic = _trafficTypeDao.findBy(mgmtPhyNetwork.getId(), TrafficType.Management);
+ try {
+ _networkModel.getDefaultPhysicalNetworkByZoneAndTrafficType(zoneId, TrafficType.Storage);
+ } catch (final InvalidParameterValueException noStorage) {
+ final PhysicalNetworkTrafficTypeVO mgmtTraffic = _trafficTypeDao.findBy(mgmtPhyNetwork.getId(), TrafficType.Management);
_networkSvc.addTrafficTypeToPhysicalNetwork(mgmtPhyNetwork.getId(), TrafficType.Storage.toString(), "vlan", mgmtTraffic.getXenNetworkLabel(),
mgmtTraffic.getKvmNetworkLabel(), mgmtTraffic.getVmwareNetworkLabel(), mgmtTraffic.getSimulatorNetworkLabel(), mgmtTraffic.getVlan(),
mgmtTraffic.getHypervNetworkLabel(), mgmtTraffic.getOvm3NetworkLabel());
s_logger.info("No storage traffic type was specified by admin, create default storage traffic on physical network " + mgmtPhyNetwork.getId()
+ " with same configure of management traffic type");
+ }
+ } catch (final InvalidParameterValueException ex) {
+ throw new InvalidParameterValueException("Cannot enable this Zone since: " + ex.getMessage());
+ }
}
- } catch (InvalidParameterValueException ex) {
- throw new InvalidParameterValueException("Cannot enable this Zone since: " + ex.getMessage());
+ zone.setAllocationState(allocationState);
}
- }
- zone.setAllocationState(allocationState);
- }
-
- if (dhcpProvider != null) {
- zone.setDhcpProvider(dhcpProvider);
- }
-
- // update a private zone to public; not vice versa
- if (isPublic != null && isPublic) {
- zone.setDomainId(null);
- zone.setDomain(null);
- // release the dedication for this zone
- DedicatedResourceVO resource = _dedicatedDao.findByZoneId(zoneId);
- Long resourceId = null;
- if (resource != null) {
- resourceId = resource.getId();
- if (!_dedicatedDao.remove(resourceId)) {
- throw new CloudRuntimeException("Failed to delete dedicated Zone Resource " + resourceId);
+ if (dhcpProvider != null) {
+ zone.setDhcpProvider(dhcpProvider);
}
- // find the group associated and check if there are any more
- // resources under that group
- List<DedicatedResourceVO> resourcesInGroup = _dedicatedDao.listByAffinityGroupId(resource.getAffinityGroupId());
- if (resourcesInGroup.isEmpty()) {
- // delete the group
- _affinityGroupService.deleteAffinityGroup(resource.getAffinityGroupId(), null, null, null);
+
+ // update a private zone to public; not vice versa
+ if (isPublic != null && isPublic) {
+ zone.setDomainId(null);
+ zone.setDomain(null);
+
+ // release the dedication for this zone
+ final DedicatedResourceVO resource = _dedicatedDao.findByZoneId(zoneId);
+ Long resourceId = null;
+ if (resource != null) {
+ resourceId = resource.getId();
+ if (!_dedicatedDao.remove(resourceId)) {
+ throw new CloudRuntimeException("Failed to delete dedicated Zone Resource " + resourceId);
+ }
+ // find the group associated and check if there are any more
+ // resources under that group
+ final List<DedicatedResourceVO> resourcesInGroup = _dedicatedDao.listByAffinityGroupId(resource.getAffinityGroupId());
+ if (resourcesInGroup.isEmpty()) {
+ // delete the group
+ _affinityGroupService.deleteAffinityGroup(resource.getAffinityGroupId(), null, null, null);
+ }
+ }
}
- }
- }
- if (!_zoneDao.update(zoneId, zone)) {
- throw new CloudRuntimeException("Failed to edit zone. Please contact Cloud Support.");
- }
+ if (!_zoneDao.update(zoneId, zone)) {
+ throw new CloudRuntimeException("Failed to edit zone. Please contact Cloud Support.");
+ }
}
});
@@ -1796,14 +1798,14 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
@Override
@DB
- public DataCenterVO createZone(long userId, String zoneName, String dns1, String dns2, String internalDns1, String internalDns2, String guestCidr, String domain,
- final Long domainId, NetworkType zoneType, String allocationStateStr, String networkDomain, boolean isSecurityGroupEnabled, boolean isLocalStorageEnabled,
- String ip6Dns1, String ip6Dns2) {
+ public DataCenterVO createZone(final long userId, final String zoneName, final String dns1, final String dns2, final String internalDns1, final String internalDns2, final String guestCidr, final String domain,
+ final Long domainId, final NetworkType zoneType, final String allocationStateStr, final String networkDomain, final boolean isSecurityGroupEnabled, final boolean isLocalStorageEnabled,
+ final String ip6Dns1, final String ip6Dns2) {
// checking the following params outside checkzoneparams method as we do
// not use these params for updatezone
// hence the method below is generic to check for common params
- if ((guestCidr != null) && !NetUtils.validateGuestCidr(guestCidr)) {
+ if (guestCidr != null && !NetUtils.validateGuestCidr(guestCidr)) {
throw new InvalidParameterValueException("Please enter a valid guest cidr");
}
@@ -1818,42 +1820,42 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
checkZoneParameters(zoneName, dns1, dns2, internalDns1, internalDns2, true, domainId, allocationStateStr, ip6Dns1, ip6Dns2);
- byte[] bytes = (zoneName + System.currentTimeMillis()).getBytes();
- String zoneToken = UUID.nameUUIDFromBytes(bytes).toString();
+ final byte[] bytes = (zoneName + System.currentTimeMillis()).getBytes();
+ final String zoneToken = UUID.nameUUIDFromBytes(bytes).toString();
- // Create the new zone in the database
+ // Create the new zone in the database
final DataCenterVO zoneFinal = new DataCenterVO(zoneName, null, dns1, dns2, internalDns1, internalDns2, guestCidr, domain, domainId, zoneType, zoneToken, networkDomain,
isSecurityGroupEnabled, isLocalStorageEnabled, ip6Dns1, ip6Dns2);
- if (allocationStateStr != null && !allocationStateStr.isEmpty()) {
- Grouping.AllocationState allocationState = Grouping.AllocationState.valueOf(allocationStateStr);
+ if (allocationStateStr != null && !allocationStateStr.isEmpty()) {
+ final Grouping.AllocationState allocationState = Grouping.AllocationState.valueOf(allocationStateStr);
zoneFinal.setAllocationState(allocationState);
- } else {
- // Zone will be disabled since 3.0. Admin should enable it after
- // physical network and providers setup.
+ } else {
+ // Zone will be disabled since 3.0. Admin should enable it after
+ // physical network and providers setup.
zoneFinal.setAllocationState(Grouping.AllocationState.Disabled);
- }
+ }
return Transaction.execute(new TransactionCallback<DataCenterVO>() {
@Override
- public DataCenterVO doInTransaction(TransactionStatus status) {
- DataCenterVO zone = _zoneDao.persist(zoneFinal);
- if (domainId != null) {
- // zone is explicitly dedicated to this domain
- // create affinity group associated and dedicate the zone.
- AffinityGroup group = createDedicatedAffinityGroup(null, domainId, null);
- DedicatedResourceVO dedicatedResource = new DedicatedResourceVO(zone.getId(), null, null, null, domainId, null, group.getId());
- _dedicatedDao.persist(dedicatedResource);
- }
+ public DataCenterVO doInTransaction(final TransactionStatus status) {
+ final DataCenterVO zone = _zoneDao.persist(zoneFinal);
+ if (domainId != null) {
+ // zone is explicitly dedicated to this domain
+ // create affinity group associated and dedicate the zone.
+ final AffinityGroup group = createDedicatedAffinityGroup(null, domainId, null);
+ final DedicatedResourceVO dedicatedResource = new DedicatedResourceVO(zone.getId(), null, null, null, domainId, null, group.getId());
+ _dedicatedDao.persist(dedicatedResource);
+ }
- // Create default system networks
- createDefaultSystemNetworks(zone.getId());
+ // Create default system networks
+ createDefaultSystemNetworks(zone.getId());
- return zone;
- }
+ return zone;
+ }
});
}
- private AffinityGroup createDedicatedAffinityGroup(String affinityGroupName, Long domainId, Long accountId) {
+ private AffinityGroup createDedicatedAffinityGroup(String affinityGroupName, final Long domainId, final Long accountId) {
if (affinityGroupName == null) {
// default to a groupname with account/domain information
affinityGroupName = "ZoneDedicatedGrp-domain-" + domainId + (accountId != null ? "-acct-" + accountId : "");
@@ -1863,7 +1865,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
String accountName = null;
if (accountId != null) {
- AccountVO account = _accountDao.findById(accountId);
+ final AccountVO account = _accountDao.findById(accountId);
accountName = account.getAccountName();
group = _affinityGroupDao.findByAccountAndName(accountId, affinityGroupName);
@@ -1885,19 +1887,19 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
}
@Override
- public void createDefaultSystemNetworks(long zoneId) throws ConcurrentOperationException {
- DataCenterVO zone = _zoneDao.findById(zoneId);
- String networkDomain = null;
+ public void createDefaultSystemNetworks(final long zoneId) throws ConcurrentOperationException {
+ final DataCenterVO zone = _zoneDao.findById(zoneId);
+ final String networkDomain = null;
// Create public, management, control and storage networks as a part of
// the zone creation
if (zone != null) {
- List<NetworkOfferingVO> ntwkOff = _networkOfferingDao.listSystemNetworkOfferings();
+ final List<NetworkOfferingVO> ntwkOff = _networkOfferingDao.listSystemNetworkOfferings();
- for (NetworkOfferingVO offering : ntwkOff) {
- DataCenterDeployment plan = new DataCenterDeployment(zone.getId(), null, null, null, null, null);
- NetworkVO userNetwork = new NetworkVO();
+ for (final NetworkOfferingVO offering : ntwkOff) {
+ final DataCenterDeployment plan = new DataCenterDeployment(zone.getId(), null, null, null, null, null);
+ final NetworkVO userNetwork = new NetworkVO();
- Account systemAccount = _accountDao.findById(Account.ACCOUNT_ID_SYSTEM);
+ final Account systemAccount = _accountDao.findById(Account.ACCOUNT_ID_SYSTEM);
BroadcastDomainType broadcastDomainType = null;
if (offering.getTrafficType() == TrafficType.Management) {
@@ -1905,7 +1907,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
} else if (offering.getTrafficType() == TrafficType.Control) {
broadcastDomainType = BroadcastDomainType.LinkLocal;
} else if (offering.getTrafficType() == TrafficType.Public) {
- if ((zone.getNetworkType() == NetworkType.Advanced && !zone.isSecurityGroupEnabled()) || zone.getNetworkType() == NetworkType.Basic) {
+ if (zone.getNetworkType() == NetworkType.Advanced && !zone.isSecurityGroupEnabled() || zone.getNetworkType() == NetworkType.Basic) {
broadcastDomainType = BroadcastDomainType.Vlan;
} else {
continue; // so broadcastDomainType remains null! why have None/Undecided/UnKnown?
@@ -1923,36 +1925,36 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
@Override
@ActionEvent(eventType = EventTypes.EVENT_ZONE_CREATE, eventDescription = "creating zone", async = false)
- public DataCenter createZone(CreateZoneCmd cmd) {
+ public DataCenter createZone(final CreateZoneCmd cmd) {
// grab parameters from the command
- Long userId = CallContext.current().getCallingUserId();
- String zoneName = cmd.getZoneName();
- String dns1 = cmd.getDns1();
- String dns2 = cmd.getDns2();
- String ip6Dns1 = cmd.getIp6Dns1();
- String ip6Dns2 = cmd.getIp6Dns2();
- String internalDns1 = cmd.getInternalDns1();
- String internalDns2 = cmd.getInternalDns2();
- String guestCidr = cmd.getGuestCidrAddress();
- Long domainId = cmd.getDomainId();
- String type = cmd.getNetworkType();
+ final Long userId = CallContext.current().getCallingUserId();
+ final String zoneName = cmd.getZoneName();
+ final String dns1 = cmd.getDns1();
+ final String dns2 = cmd.getDns2();
+ final String ip6Dns1 = cmd.getIp6Dns1();
+ final String ip6Dns2 = cmd.getIp6Dns2();
+ final String internalDns1 = cmd.getInternalDns1();
+ final String internalDns2 = cmd.getInternalDns2();
+ final String guestCidr = cmd.getGuestCidrAddress();
+ final Long domainId = cmd.getDomainId();
+ final String type = cmd.getNetworkType();
Boolean isBasic = false;
String allocationState = cmd.getAllocationState();
- String networkDomain = cmd.getDomain();
+ final String networkDomain = cmd.getDomain();
boolean isSecurityGroupEnabled = cmd.getSecuritygroupenabled();
- boolean isLocalStorageEnabled = cmd.getLocalStorageEnabled();
+ final boolean isLocalStorageEnabled = cmd.getLocalStorageEnabled();
if (allocationState == null) {
allocationState = Grouping.AllocationState.Disabled.toString();
}
- if (!(type.equalsIgnoreCase(NetworkType.Basic.toString())) && !(type.equalsIgnoreCase(NetworkType.Advanced.toString()))) {
+ if (!type.equalsIgnoreCase(NetworkType.Basic.toString()) && !type.equalsIgnoreCase(NetworkType.Advanced.toString())) {
throw new InvalidParameterValueException("Invalid zone type; only Advanced and Basic values are supported");
} else if (type.equalsIgnoreCase(NetworkType.Basic.toString())) {
isBasic = true;
}
- NetworkType zoneType = isBasic ? NetworkType.Basic : NetworkType.Advanced;
+ final NetworkType zoneType = isBasic ? NetworkType.Basic : NetworkType.Advanced;
// error out when the parameter specified for Basic zone
if (zoneType == NetworkType.Basic && guestCidr != null) {
@@ -1975,22 +1977,22 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
@Override
@ActionEvent(eventType = EventTypes.EVENT_SERVICE_OFFERING_CREATE, eventDescription = "creating service offering")
- public ServiceOffering createServiceOffering(CreateServiceOfferingCmd cmd) {
- Long userId = CallContext.current().getCallingUserId();
+ public ServiceOffering createServiceOffering(final CreateServiceOfferingCmd cmd) {
+ final Long userId = CallContext.current().getCallingUserId();
- String name = cmd.getServiceOfferingName();
- if ((name == null) || (name.length() == 0)) {
+ final String name = cmd.getServiceOfferingName();
+ if (name == null || name.length() == 0) {
throw new InvalidParameterValueException("Failed to create service offering: specify the name that has non-zero length");
}
- String displayText = cmd.getDisplayText();
- if ((displayText == null) || (displayText.length() == 0)) {
+ final String displayText = cmd.getDisplayText();
+ if (displayText == null || displayText.length() == 0) {
throw new InvalidParameterValueException("Failed to create service offering " + name + ": specify the display text that has non-zero length");
}
- Integer cpuNumber = cmd.getCpuNumber();
- Integer cpuSpeed = cmd.getCpuSpeed();
- Integer memory = cmd.getMemory();
+ final Integer cpuNumber = cmd.getCpuNumber();
+ final Integer cpuSpeed = cmd.getCpuSpeed();
+ final Integer memory = cmd.getMemory();
//restricting the createserviceoffering to allow setting all or none of the dynamic parameters to null
if (cpuNumber == null || cpuSpeed == null || memory == null) {
@@ -1999,13 +2001,13 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
}
}
- if ((cpuNumber != null) && ((cpuNumber.intValue() <= 0) || (cpuNumber.longValue() > Integer.MAX_VALUE))) {
+ if (cpuNumber != null && (cpuNumber.intValue() <= 0 || cpuNumber.longValue() > Integer.MAX_VALUE)) {
throw new InvalidParameterValueException("Failed to create service offering " + name + ": specify the cpu number value between 1 and " + Integer.MAX_VALUE);
}
- if ((cpuSpeed != null) && ((cpuSpeed.intValue() < 0) || (cpuSpeed.longValue() > Integer.MAX_VALUE))) {
+ if (cpuSpeed != null && (cpuSpeed.intValue() < 0 || cpuSpeed.longValue() > Integer.MAX_VALUE)) {
throw new InvalidParameterValueException("Failed to create service offering " + name + ": specify the cpu speed value between 0 and " + Integer.MAX_VALUE);
}
- if ((memory != null) && ((memory.intValue() < 32) || (memory.longValue() > Integer.MAX_VALUE))) {
+ if (memory != null && (memory.intValue() < 32 || memory.longValue() > Integer.MAX_VALUE)) {
throw new InvalidParameterValueException("Failed to create service offering " + name + ": specify the memory value between 32 and " + Integer.MAX_VALUE + " MB");
}
@@ -2014,10 +2016,10 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
throw new InvalidParameterValueException("Please specify a valid domain id");
}
- Boolean offerHA = cmd.getOfferHa();
+ final Boolean offerHA = cmd.getOfferHa();
boolean localStorageRequired = false;
- String storageType = cmd.getStorageType();
+ final String storageType = cmd.getStorageType();
if (storageType != null) {
if (storageType.equalsIgnoreCase(ServiceOffering.StorageType.local.toString())) {
if(offerHA) {
@@ -2029,10 +2031,10 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
}
}
- Boolean limitCpuUse = cmd.GetLimitCpuUse();
- Boolean volatileVm = cmd.getVolatileVm();
+ final Boolean limitCpuUse = cmd.GetLimitCpuUse();
+ final Boolean volatileVm = cmd.getVolatileVm();
- String vmTypeString = cmd.getSystemVmType();
+ final String vmTypeString = cmd.getSystemVmType();
VirtualMachine.Type vmType = null;
boolean allowNetworkRate = false;
if (cmd.getIsSystem()) {
@@ -2063,7 +2065,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
}
if (cmd.getDeploymentPlanner() != null) {
- List<String> planners = _mgr.listDeploymentPlanners();
+ final List<String> planners = _mgr.listDeploymentPlanners();
if (planners != null && !planners.isEmpty()) {
if (!planners.contains(cmd.getDeploymentPlanner())) {
throw new InvalidParameterValueException("Invalid name for Deployment Planner specified, please use listDeploymentPlanners to get the valid set");
@@ -2079,18 +2081,18 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
cmd.getBytesReadRate(), cmd.getBytesWriteRate(), cmd.getIopsReadRate(), cmd.getIopsWriteRate(), cmd.getHypervisorSnapshotReserve());
}
- protected ServiceOfferingVO createServiceOffering(long userId, boolean isSystem, VirtualMachine.Type vmType,
- String name, Integer cpu, Integer ramSize, Integer speed, String displayText, String provisioningType, boolean localStorageRequired,
- boolean offerHA, boolean limitResourceUse, boolean volatileVm, String tags, Long domainId, String hostTag,
- Integer networkRate, String deploymentPlanner, Map<String, String> detai
<TRUNCATED>