mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
Moving createDiskOffering to configurationManager, make AssignToLoadBalancer async
This commit is contained in:
parent
06881fa28f
commit
96f76062f9
@ -1826,18 +1826,6 @@ public interface ManagementServer {
|
||||
*/
|
||||
List<DiskOfferingVO> 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
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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
|
||||
|
||||
@ -15,20 +15,19 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
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";
|
||||
|
||||
@ -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<Pair<Enum, Boolean>> s_properties = new ArrayList<Pair<Enum, Boolean>>();
|
||||
|
||||
static {
|
||||
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.NAME, Boolean.TRUE));
|
||||
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.DISPLAY_TEXT, Boolean.TRUE));
|
||||
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.DISK_SIZE, Boolean.TRUE));
|
||||
// s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.IS_MIRRORED, Boolean.FALSE));
|
||||
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.ACCOUNT_OBJ, Boolean.FALSE));
|
||||
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.USER_ID, Boolean.FALSE));
|
||||
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.DOMAIN_ID, Boolean.FALSE));
|
||||
s_properties.add(new Pair<Enum, Boolean>(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<Pair<Enum, Boolean>> getProperties() {
|
||||
return s_properties;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Pair<String, Object>> execute(Map<String, Object> 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) {
|
||||
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);
|
||||
}
|
||||
|
||||
List<Pair<String, Object>> returnValues = new ArrayList<Pair<String, Object>>();
|
||||
returnValues.add(new Pair<String, Object>(BaseCmd.Properties.ID.getName(), Long.toString(diskOffering.getId())));
|
||||
returnValues.add(new Pair<String, Object>(BaseCmd.Properties.DOMAIN_ID.getName(), diskOffering.getDomainId()));
|
||||
returnValues.add(new Pair<String, Object>(BaseCmd.Properties.DOMAIN.getName(), getManagementServer().findDomainIdById(diskOffering.getDomainId()).getName()));
|
||||
returnValues.add(new Pair<String, Object>(BaseCmd.Properties.NAME.getName(), diskOffering.getName()));
|
||||
returnValues.add(new Pair<String, Object>(BaseCmd.Properties.DISPLAY_TEXT.getName(), diskOffering.getDisplayText()));
|
||||
returnValues.add(new Pair<String, Object>(BaseCmd.Properties.DISK_SIZE.getName(), diskOffering.getDiskSizeInBytes()));
|
||||
// returnValues.add(new Pair<String, Object>(BaseCmd.Properties.IS_MIRRORED.getName(), diskOffering.isMirrored()));
|
||||
returnValues.add(new Pair<String, Object>(BaseCmd.Properties.CREATED.getName(), diskOffering.getCreated()));
|
||||
returnValues.add(new Pair<String, Object>(BaseCmd.Properties.TAGS.getName(), diskOffering.getTags()));
|
||||
return returnValues;
|
||||
public void setResponseObject(DiskOfferingVO diskOffering) {
|
||||
responseObject = diskOffering;
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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;
|
||||
@ -92,6 +94,8 @@ public class ConfigurationManagerImpl implements ConfigurationManager {
|
||||
@Inject UserDao _userDao;
|
||||
public boolean _premium;
|
||||
|
||||
private int _maxVolumeSizeInGb;
|
||||
|
||||
@Override
|
||||
public boolean configure(final String name, final Map<String, Object> params) throws ConfigurationException {
|
||||
_name = name;
|
||||
@ -99,6 +103,11 @@ public class ConfigurationManagerImpl implements ConfigurationManager {
|
||||
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;
|
||||
}
|
||||
|
||||
@ -898,7 +907,24 @@ public class ConfigurationManagerImpl implements ConfigurationManager {
|
||||
}
|
||||
}
|
||||
|
||||
public DiskOfferingVO createDiskOffering(long domainId, String name, String description, int numGibibytes, String tags) {
|
||||
@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);
|
||||
|
||||
@ -355,7 +355,6 @@ public class ManagementServerImpl implements ManagementServer {
|
||||
private final int _proxyRamSize;
|
||||
private final int _ssRamSize;
|
||||
|
||||
private final int _maxVolumeSizeInGb;
|
||||
private final Map<String, Boolean> _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);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user