diff --git a/core/src/com/cloud/server/ManagementServer.java b/core/src/com/cloud/server/ManagementServer.java index 43b42952e23..dffeee100a6 100644 --- a/core/src/com/cloud/server/ManagementServer.java +++ b/core/src/com/cloud/server/ManagementServer.java @@ -1826,18 +1826,6 @@ public interface ManagementServer { */ List searchForDiskOfferings(Criteria c); - /** - * Create a disk offering - * @param domainId the id of the domain in which the disk offering is valid - * @param name the name of the disk offering - * @param description a string description of the disk offering - * @param numGibibytes the number of gibibytes in the disk offering (1 gibibyte = 1024 MB) - * @param mirrored boolean value of whether or not the offering provides disk mirroring - * @param tags Comma separated string to indicate special tags for the disk offering. - * @return the created disk offering, null if failed to create - */ - DiskOfferingVO createDiskOffering(long domainId, String name, String description, int numGibibytes, String tags) throws InvalidParameterValueException; - /** * Delete a disk offering * @param id id of the disk offering to delete diff --git a/server/src/com/cloud/api/ApiDispatcher.java b/server/src/com/cloud/api/ApiDispatcher.java index 13e4acd707a..f785fb544f2 100644 --- a/server/src/com/cloud/api/ApiDispatcher.java +++ b/server/src/com/cloud/api/ApiDispatcher.java @@ -13,6 +13,7 @@ import java.util.StringTokenizer; import org.apache.log4j.Logger; import com.cloud.api.BaseCmd.CommandType; +import com.cloud.configuration.ConfigurationManager; import com.cloud.network.NetworkManager; import com.cloud.server.ManagementServer; import com.cloud.storage.StorageManager; @@ -27,6 +28,7 @@ import com.cloud.vm.UserVmManager; public class ApiDispatcher { private static final Logger s_logger = Logger.getLogger(ApiDispatcher.class.getName()); + private ConfigurationManager _configMgr; private ManagementServer _mgmtServer; private NetworkManager _networkMgr; private StorageManager _storageMgr; @@ -35,6 +37,7 @@ public class ApiDispatcher { public ApiDispatcher() { ComponentLocator locator = ComponentLocator.getLocator(ManagementServer.Name); _mgmtServer = (ManagementServer)ComponentLocator.getComponent(ManagementServer.Name); + _configMgr = locator.getManager(ConfigurationManager.class); _networkMgr = locator.getManager(NetworkManager.class); _storageMgr = locator.getManager(StorageManager.class); _userVmMgr = locator.getManager(UserVmManager.class); @@ -80,6 +83,9 @@ public class ApiDispatcher { String methodName = impl.method(); Object mgr = _mgmtServer; switch (impl.manager()) { + case ConfigManager: + mgr = _configMgr; + break; case NetworkManager: mgr = _networkMgr; break; diff --git a/server/src/com/cloud/api/BaseCmd.java b/server/src/com/cloud/api/BaseCmd.java index 47883becbc3..c2148e40744 100644 --- a/server/src/com/cloud/api/BaseCmd.java +++ b/server/src/com/cloud/api/BaseCmd.java @@ -48,7 +48,7 @@ public abstract class BaseCmd { } public enum Manager { - ManagementServer, NetworkManager, StorageManager, UserVmManager + ConfigManager, ManagementServer, NetworkManager, StorageManager, UserVmManager } // FIXME: Extract these out into a separate file diff --git a/server/src/com/cloud/api/commands/AssignToLoadBalancerRuleCmd.java b/server/src/com/cloud/api/commands/AssignToLoadBalancerRuleCmd.java index b77fe11bad8..0b510013f44 100644 --- a/server/src/com/cloud/api/commands/AssignToLoadBalancerRuleCmd.java +++ b/server/src/com/cloud/api/commands/AssignToLoadBalancerRuleCmd.java @@ -15,20 +15,19 @@ * along with this program. If not, see . * */ - package com.cloud.api.commands; import java.util.List; import org.apache.log4j.Logger; -import com.cloud.api.BaseCmd; +import com.cloud.api.BaseAsyncCmd; import com.cloud.api.BaseCmd.Manager; import com.cloud.api.Implementation; import com.cloud.api.Parameter; @Implementation(method="assignToLoadBalancer", manager=Manager.NetworkManager) -public class AssignToLoadBalancerRuleCmd extends BaseCmd { +public class AssignToLoadBalancerRuleCmd extends BaseAsyncCmd { public static final Logger s_logger = Logger.getLogger(AssignToLoadBalancerRuleCmd.class.getName()); private static final String s_name = "assigntoloadbalancerruleresponse"; diff --git a/server/src/com/cloud/api/commands/CreateDiskOfferingCmd.java b/server/src/com/cloud/api/commands/CreateDiskOfferingCmd.java index 745b7fcf2ce..731a2ed9b60 100644 --- a/server/src/com/cloud/api/commands/CreateDiskOfferingCmd.java +++ b/server/src/com/cloud/api/commands/CreateDiskOfferingCmd.java @@ -18,36 +18,24 @@ package com.cloud.api.commands; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; +import java.util.Date; import org.apache.log4j.Logger; import com.cloud.api.BaseCmd; +import com.cloud.api.BaseCmd.Manager; +import com.cloud.api.Implementation; import com.cloud.api.Parameter; import com.cloud.api.ServerApiException; -import com.cloud.domain.DomainVO; -import com.cloud.exception.InvalidParameterValueException; +import com.cloud.serializer.Param; +import com.cloud.serializer.SerializerHelper; import com.cloud.storage.DiskOfferingVO; -import com.cloud.utils.Pair; - + +@Implementation(method="createDiskOffering", manager=Manager.ConfigManager) public class CreateDiskOfferingCmd extends BaseCmd { public static final Logger s_logger = Logger.getLogger(CreateDiskOfferingCmd.class.getName()); private static final String s_name = "creatediskofferingresponse"; - private static final List> s_properties = new ArrayList>(); - - static { - s_properties.add(new Pair(BaseCmd.Properties.NAME, Boolean.TRUE)); - s_properties.add(new Pair(BaseCmd.Properties.DISPLAY_TEXT, Boolean.TRUE)); - s_properties.add(new Pair(BaseCmd.Properties.DISK_SIZE, Boolean.TRUE)); -// s_properties.add(new Pair(BaseCmd.Properties.IS_MIRRORED, Boolean.FALSE)); - s_properties.add(new Pair(BaseCmd.Properties.ACCOUNT_OBJ, Boolean.FALSE)); - s_properties.add(new Pair(BaseCmd.Properties.USER_ID, Boolean.FALSE)); - s_properties.add(new Pair(BaseCmd.Properties.DOMAIN_ID, Boolean.FALSE)); - s_properties.add(new Pair(BaseCmd.Properties.TAGS, Boolean.FALSE)); - } ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// @@ -68,7 +56,6 @@ public class CreateDiskOfferingCmd extends BaseCmd { @Parameter(name="tags", type=CommandType.STRING) private String tags; - ///////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// ///////////////////////////////////////////////////// @@ -93,60 +80,128 @@ public class CreateDiskOfferingCmd extends BaseCmd { return tags; } - ///////////////////////////////////////////////////// /////////////// API Implementation/////////////////// ///////////////////////////////////////////////////// + private DiskOfferingVO responseObject = null; + @Override public String getName() { return s_name; } + @Override - public List> getProperties() { - return s_properties; + public String getResponse() { + DiskOfferingResponse response = new DiskOfferingResponse(); + if (responseObject != null) { + response.setId(responseObject.getId()); + response.setCreated(responseObject.getCreated()); + response.setDiskSize(responseObject.getDiskSize()); + response.setDisplayText(responseObject.getDisplayText()); + response.setDomainId(responseObject.getDomainId()); + // FIXME: domain name in the response +// response.setDomain(responseObject.getDomain()); + response.setName(responseObject.getName()); + response.setTags(responseObject.getTags()); + } else { + throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create disk offering"); + } + return SerializerHelper.toSerializedString(responseObject); + } + + public void setResponseObject(DiskOfferingVO diskOffering) { + responseObject = diskOffering; } - - @Override - public List> execute(Map params) { - // FIXME: add domain-private disk offerings -// Account account = (Account)params.get(BaseCmd.Properties.ACCOUNT_OBJ.getName()); -// Long userId = (Long)params.get(BaseCmd.Properties.USER_ID.getName()); - Long domainId = (Long)params.get(BaseCmd.Properties.DOMAIN_ID.getName()); - String name = (String)params.get(BaseCmd.Properties.NAME.getName()); - String displayText = (String)params.get(BaseCmd.Properties.DISPLAY_TEXT.getName()); - Long numGB = (Long) params.get(BaseCmd.Properties.DISK_SIZE.getName()); -// Boolean isMirrored = (Boolean)params.get(BaseCmd.Properties.IS_MIRRORED.getName()); - String tags = (String)params.get(BaseCmd.Properties.TAGS.getName()); - -// if (isMirrored == null) { -// isMirrored = Boolean.FALSE; -// } - if (domainId == null) { - domainId = DomainVO.ROOT_DOMAIN; - } - - DiskOfferingVO diskOffering = null; - try { - diskOffering = getManagementServer().createDiskOffering(domainId.longValue(), name, displayText, numGB.intValue(),tags); - } catch (InvalidParameterValueException ex) { - throw new ServerApiException (BaseCmd.VM_INVALID_PARAM_ERROR, ex.getMessage()); - } - - if (diskOffering == null) { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create disk offering"); - } - - List> returnValues = new ArrayList>(); - returnValues.add(new Pair(BaseCmd.Properties.ID.getName(), Long.toString(diskOffering.getId()))); - returnValues.add(new Pair(BaseCmd.Properties.DOMAIN_ID.getName(), diskOffering.getDomainId())); - returnValues.add(new Pair(BaseCmd.Properties.DOMAIN.getName(), getManagementServer().findDomainIdById(diskOffering.getDomainId()).getName())); - returnValues.add(new Pair(BaseCmd.Properties.NAME.getName(), diskOffering.getName())); - returnValues.add(new Pair(BaseCmd.Properties.DISPLAY_TEXT.getName(), diskOffering.getDisplayText())); - returnValues.add(new Pair(BaseCmd.Properties.DISK_SIZE.getName(), diskOffering.getDiskSizeInBytes())); -// returnValues.add(new Pair(BaseCmd.Properties.IS_MIRRORED.getName(), diskOffering.isMirrored())); - returnValues.add(new Pair(BaseCmd.Properties.CREATED.getName(), diskOffering.getCreated())); - returnValues.add(new Pair(BaseCmd.Properties.TAGS.getName(), diskOffering.getTags())); - return returnValues; + + // helper class for the response object + private class DiskOfferingResponse { + @Param(name="id") + private Long id; + + @Param(name="domainid") + private Long domainId; + + @Param(name="domain") + private String domain; + + @Param(name="name") + private String name; + + @Param(name="displaytext") + private String displayText; + + @Param(name="disksize") + private Long diskSize; + + @Param(name="created") + private Date created; + + @Param(name="tags") + private String tags; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Long getDomainId() { + return domainId; + } + + public void setDomainId(Long domainId) { + this.domainId = domainId; + } + + public String getDomain() { + return domain; + } + + public void setDomain(String domain) { + this.domain = domain; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getDisplayText() { + return displayText; + } + + public void setDisplayText(String displayText) { + this.displayText = displayText; + } + + public Long getDiskSize() { + return diskSize; + } + + public void setDiskSize(Long diskSize) { + this.diskSize = diskSize; + } + + public Date getCreated() { + return created; + } + + public void setCreated(Date created) { + this.created = created; + } + + public String getTags() { + return tags; + } + + public void setTags(String tags) { + this.tags = tags; + } } } diff --git a/server/src/com/cloud/configuration/ConfigurationManager.java b/server/src/com/cloud/configuration/ConfigurationManager.java index 2acf9ee9e27..ad923e7c15d 100644 --- a/server/src/com/cloud/configuration/ConfigurationManager.java +++ b/server/src/com/cloud/configuration/ConfigurationManager.java @@ -19,10 +19,11 @@ package com.cloud.configuration; import java.util.List; +import com.cloud.api.commands.CreateDiskOfferingCmd; import com.cloud.dc.DataCenterVO; import com.cloud.dc.HostPodVO; -import com.cloud.dc.VlanVO; import com.cloud.dc.Vlan.VlanType; +import com.cloud.dc.VlanVO; import com.cloud.exception.InternalErrorException; import com.cloud.exception.InvalidParameterValueException; import com.cloud.service.ServiceOfferingVO; @@ -99,7 +100,7 @@ public interface ConfigurationManager extends Manager { * @param size * @return ID */ - DiskOfferingVO createDiskOffering(long domainId, String name, String description, int numGibibytes, String tags); + DiskOfferingVO createDiskOffering(CreateDiskOfferingCmd cmd) throws InvalidParameterValueException; /** * Creates a new pod diff --git a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java index 52a7b58dfc3..96422fc9854 100644 --- a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java +++ b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java @@ -22,7 +22,6 @@ import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; -import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -32,20 +31,22 @@ import javax.naming.ConfigurationException; import org.apache.log4j.Logger; +import com.cloud.api.commands.CreateDiskOfferingCmd; import com.cloud.configuration.dao.ConfigurationDao; import com.cloud.dc.AccountVlanMapVO; import com.cloud.dc.DataCenterVO; import com.cloud.dc.HostPodVO; import com.cloud.dc.PodVlanMapVO; import com.cloud.dc.Vlan; -import com.cloud.dc.VlanVO; import com.cloud.dc.Vlan.VlanType; +import com.cloud.dc.VlanVO; import com.cloud.dc.dao.AccountVlanMapDao; import com.cloud.dc.dao.DataCenterDao; import com.cloud.dc.dao.DataCenterIpAddressDaoImpl; import com.cloud.dc.dao.HostPodDao; import com.cloud.dc.dao.PodVlanMapDao; import com.cloud.dc.dao.VlanDao; +import com.cloud.domain.DomainVO; import com.cloud.event.EventTypes; import com.cloud.event.EventVO; import com.cloud.event.dao.EventDao; @@ -61,6 +62,7 @@ import com.cloud.user.AccountVO; import com.cloud.user.UserVO; import com.cloud.user.dao.AccountDao; import com.cloud.user.dao.UserDao; +import com.cloud.utils.NumbersUtil; import com.cloud.utils.component.Inject; import com.cloud.utils.db.DB; import com.cloud.utils.db.Transaction; @@ -91,14 +93,21 @@ public class ConfigurationManagerImpl implements ConfigurationManager { @Inject EventDao _eventDao; @Inject UserDao _userDao; public boolean _premium; - + + private int _maxVolumeSizeInGb; + @Override public boolean configure(final String name, final Map params) throws ConfigurationException { _name = name; Object premium = params.get("premium"); _premium = (premium != null) && ((String) premium).equals("true"); - + + String maxVolumeSizeInGbString = _configDao.getValue("max.volume.size.gb"); + int maxVolumeSizeGb = NumbersUtil.parseInt(maxVolumeSizeInGbString, 2000); + + _maxVolumeSizeInGb = maxVolumeSizeGb; + return true; } @@ -897,9 +906,26 @@ public class ConfigurationManagerImpl implements ConfigurationManager { return false; } } - - public DiskOfferingVO createDiskOffering(long domainId, String name, String description, int numGibibytes, String tags) { - long diskSize = numGibibytes * 1024; + + @Override + public DiskOfferingVO createDiskOffering(CreateDiskOfferingCmd cmd) throws InvalidParameterValueException { + Long domainId = cmd.getDomainId(); + String name = cmd.getOfferingName(); + String description = cmd.getDisplayText(); + int numGibibytes = cmd.getDiskSize().intValue(); + String tags = cmd.getTags(); + + if (domainId == null) { + domainId = Long.valueOf(DomainVO.ROOT_DOMAIN); + } + + if ((numGibibytes != 0) && (numGibibytes < 1)) { + throw new InvalidParameterValueException("Please specify a disk size of at least 1 Gb."); + } else if (numGibibytes > _maxVolumeSizeInGb) { + throw new InvalidParameterValueException("The maximum size for a disk is " + _maxVolumeSizeInGb + " Gb."); + } + + long diskSize = numGibibytes * 1024; tags = cleanupTags(tags); DiskOfferingVO newDiskOffering = new DiskOfferingVO(domainId, name, description, diskSize,tags); return _diskOfferingDao.persist(newDiskOffering); diff --git a/server/src/com/cloud/server/ManagementServerImpl.java b/server/src/com/cloud/server/ManagementServerImpl.java index 774d7087276..7596e44b68d 100755 --- a/server/src/com/cloud/server/ManagementServerImpl.java +++ b/server/src/com/cloud/server/ManagementServerImpl.java @@ -355,7 +355,6 @@ public class ManagementServerImpl implements ManagementServer { private final int _proxyRamSize; private final int _ssRamSize; - private final int _maxVolumeSizeInGb; private final Map _availableIdsMap; private boolean _networkGroupsEnabled = false; @@ -457,11 +456,6 @@ public class ManagementServerImpl implements ManagementServer { // Parse the max number of UserVMs and public IPs from server-setup.xml, // and set them in the right places - String maxVolumeSizeInGbString = _configs.get("max.volume.size.gb"); - int maxVolumeSizeGb = NumbersUtil.parseInt(maxVolumeSizeInGbString, 2000); - - _maxVolumeSizeInGb = maxVolumeSizeGb; - _routerRamSize = NumbersUtil.parseInt(_configs.get("router.ram.size"),NetworkManager.DEFAULT_ROUTER_VM_RAMSIZE); _proxyRamSize = NumbersUtil.parseInt(_configs.get("consoleproxy.ram.size"), ConsoleProxyManager.DEFAULT_PROXY_VM_RAMSIZE); _ssRamSize = NumbersUtil.parseInt(_configs.get("secstorage.ram.size"), SecondaryStorageVmManager.DEFAULT_SS_VM_RAMSIZE); @@ -6733,17 +6727,6 @@ public class ManagementServerImpl implements ManagementServer { return _diskOfferingDao.search(sc, searchFilter); } - @Override - public DiskOfferingVO createDiskOffering(long domainId, String name, String description, int numGibibytes, String tags) throws InvalidParameterValueException { - if (numGibibytes!=0 && numGibibytes < 1) { - throw new InvalidParameterValueException("Please specify a disk size of at least 1 Gb."); - } else if (numGibibytes > _maxVolumeSizeInGb) { - throw new InvalidParameterValueException("The maximum size for a disk is " + _maxVolumeSizeInGb + " Gb."); - } - - return _configMgr.createDiskOffering(domainId, name, description, numGibibytes, tags); - } - @Override public DiskOfferingVO updateDiskOffering(long userId, long diskOfferingId, String name, String description, String tags) { return _configMgr.updateDiskOffering(userId, diskOfferingId, name, description, tags);