mirror of https://github.com/apache/cloudstack.git
Refactoring deleteDomain to new API framework. Cleaning up some compilation errors that resulted from previous refactoring, namely there was a requirement to keep the old manager method around for createDiskOffering and createZone in order for the ConfigurationServer to work.
This commit is contained in:
parent
dbb2897626
commit
a53cb4aab0
|
|
@ -26,12 +26,4 @@ public interface NetworkGroupRulesDao extends GenericDao<NetworkGroupRulesVO, Lo
|
|||
* @return the list of network groups with associated ingress rules
|
||||
*/
|
||||
List<NetworkGroupRulesVO> listNetworkGroupRules();
|
||||
|
||||
/**
|
||||
* List network groups and associated ingress rules for a particular domain
|
||||
* @param domainId the id of the domain for which to list groups and associated rules
|
||||
* @param recursive whether or not to recursively search the domain for network groups
|
||||
* @return the list of network groups with associated ingress rules
|
||||
*/
|
||||
List<NetworkGroupRulesVO> listNetworkGroupRulesByDomain(long domainId, boolean recursive);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,11 +4,8 @@ import java.util.List;
|
|||
|
||||
import javax.ejb.Local;
|
||||
|
||||
import com.cloud.domain.DomainVO;
|
||||
import com.cloud.domain.dao.DomainDao;
|
||||
import com.cloud.network.security.NetworkGroupRulesVO;
|
||||
import com.cloud.server.ManagementServer;
|
||||
import com.cloud.utils.component.ComponentLocator;
|
||||
import com.cloud.utils.db.Filter;
|
||||
import com.cloud.utils.db.GenericDaoBase;
|
||||
import com.cloud.utils.db.SearchBuilder;
|
||||
|
|
@ -58,34 +55,4 @@ public class NetworkGroupRulesDaoImpl extends GenericDaoBase<NetworkGroupRulesVO
|
|||
|
||||
return listActiveBy(sc, searchFilter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<NetworkGroupRulesVO> listNetworkGroupRulesByDomain(long domainId, boolean recursive) {
|
||||
|
||||
if (_domainDao == null) {
|
||||
ComponentLocator locator = ComponentLocator.getLocator(ManagementServer.Name);
|
||||
_domainDao = locator.getDao(DomainDao.class);
|
||||
|
||||
DomainSearch = createSearchBuilder();
|
||||
DomainSearch.and("domainId", DomainSearch.entity().getDomainId(), SearchCriteria.Op.EQ);
|
||||
SearchBuilder<DomainVO> domainSearch = _domainDao.createSearchBuilder();
|
||||
domainSearch.and("path", domainSearch.entity().getPath(), SearchCriteria.Op.LIKE);
|
||||
DomainSearch.join("domainSearch", domainSearch, DomainSearch.entity().getDomainId(), domainSearch.entity().getId());
|
||||
DomainSearch.done();
|
||||
}
|
||||
|
||||
Filter searchFilter = new Filter(NetworkGroupRulesVO.class, "id", true, null, null);
|
||||
SearchCriteria<NetworkGroupRulesVO> sc = DomainSearch.create();
|
||||
|
||||
if (!recursive) {
|
||||
sc.setParameters("domainId", domainId);
|
||||
}
|
||||
|
||||
DomainVO domain = _domainDao.findById(domainId);
|
||||
if (domain != null) {
|
||||
sc.setJoinParameters("domainSearch", "path", domain.getPath() + "%");
|
||||
}
|
||||
|
||||
return listActiveBy(sc, searchFilter);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ public class SerializerHelper {
|
|||
}
|
||||
return null;
|
||||
} catch(RuntimeException e) {
|
||||
s_logger.error("Caught runtime exception when doing GSON descrialization on: " + result);
|
||||
s_logger.error("Caught runtime exception when doing GSON deserialization on: " + result);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,29 +18,18 @@
|
|||
|
||||
package com.cloud.api.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.api.BaseCmd;
|
||||
import com.cloud.api.BaseAsyncCmd;
|
||||
import com.cloud.api.Implementation;
|
||||
import com.cloud.api.Parameter;
|
||||
import com.cloud.api.ServerApiException;
|
||||
import com.cloud.domain.DomainVO;
|
||||
import com.cloud.user.Account;
|
||||
import com.cloud.utils.Pair;
|
||||
|
||||
public class DeleteDomainCmd extends BaseCmd{
|
||||
import com.cloud.api.response.DeleteDomainResponse;
|
||||
import com.cloud.serializer.SerializerHelper;
|
||||
|
||||
@Implementation(method="deleteDomain")
|
||||
public class DeleteDomainCmd extends BaseAsyncCmd {
|
||||
public static final Logger s_logger = Logger.getLogger(DeleteDomainCmd.class.getName());
|
||||
private static final String s_name = "deletedomainresponse";
|
||||
private static final List<Pair<Enum, Boolean>> s_properties = new ArrayList<Pair<Enum, Boolean>>();
|
||||
|
||||
static {
|
||||
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.ACCOUNT_OBJ, Boolean.FALSE));
|
||||
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.ID, Boolean.TRUE));
|
||||
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.CLEANUP, Boolean.FALSE));
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
//////////////// API parameters /////////////////////
|
||||
|
|
@ -73,43 +62,15 @@ public class DeleteDomainCmd extends BaseCmd{
|
|||
@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) {
|
||||
Long domainId = (Long)params.get(BaseCmd.Properties.ID.getName());
|
||||
Account account = (Account)params.get(BaseCmd.Properties.ACCOUNT_OBJ.getName());
|
||||
Boolean cleanup = (Boolean)params.get(BaseCmd.Properties.CLEANUP.getName());
|
||||
public String getResponse() {
|
||||
String deleteResult = (String)getResponseObject();
|
||||
|
||||
// If account is null, consider System as an owner for this action
|
||||
if (account == null) {
|
||||
account = getManagementServer().findAccountById(Long.valueOf(1L));
|
||||
}
|
||||
|
||||
if ((domainId.longValue() == DomainVO.ROOT_DOMAIN) || !getManagementServer().isChildDomain(account.getDomainId(), domainId)) {
|
||||
throw new ServerApiException(BaseCmd.ACCOUNT_ERROR, "Unable to delete domain " + domainId + ", permission denied.");
|
||||
}
|
||||
|
||||
// check if domain exists in the system
|
||||
DomainVO domain = getManagementServer().findDomainIdById(domainId);
|
||||
if (domain == null) {
|
||||
throw new ServerApiException(BaseCmd.PARAM_ERROR, "unable to find domain " + domainId);
|
||||
}
|
||||
|
||||
long jobId = getManagementServer().deleteDomainAsync(domainId, account.getId(), cleanup); // default owner is 'system'
|
||||
if (jobId == 0) {
|
||||
s_logger.warn("Unable to schedule async-job for DeleteDomain comamnd");
|
||||
} else {
|
||||
if (s_logger.isDebugEnabled())
|
||||
s_logger.debug("DeleteDomain command has been accepted, job id: " + jobId);
|
||||
}
|
||||
DeleteDomainResponse response = new DeleteDomainResponse();
|
||||
response.setResult(deleteResult);
|
||||
|
||||
List<Pair<String, Object>> returnValues = new ArrayList<Pair<String, Object>>();
|
||||
returnValues.add(new Pair<String, Object>(BaseCmd.Properties.JOB_ID.getName(), Long.valueOf(jobId)));
|
||||
return returnValues;
|
||||
return SerializerHelper.toSerializedString(response);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,17 @@
|
|||
package com.cloud.api.response;
|
||||
|
||||
import com.cloud.api.ResponseObject;
|
||||
import com.cloud.serializer.Param;
|
||||
|
||||
public class DeleteDomainResponse implements ResponseObject {
|
||||
@Param(name="result")
|
||||
private String result;
|
||||
|
||||
public String getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
public void setResult(String result) {
|
||||
this.result = result;
|
||||
}
|
||||
}
|
||||
|
|
@ -141,7 +141,18 @@ public interface ConfigurationManager extends Manager {
|
|||
* @return ID
|
||||
*/
|
||||
DiskOfferingVO createDiskOffering(CreateDiskOfferingCmd cmd) throws InvalidParameterValueException;
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new disk offering
|
||||
* @param domainId
|
||||
* @param name
|
||||
* @param description
|
||||
* @param numGibibytes
|
||||
* @param tags
|
||||
* @return newly created disk offering
|
||||
*/
|
||||
DiskOfferingVO createDiskOffering(long domainId, String name, String description, int numGibibytes, String tags) throws InvalidParameterValueException;
|
||||
|
||||
/**
|
||||
* Creates a new pod
|
||||
* @param userId
|
||||
|
|
@ -193,7 +204,23 @@ public interface ConfigurationManager extends Manager {
|
|||
* @throws InternalErrorException
|
||||
*/
|
||||
DataCenterVO createZone(CreateZoneCmd cmd) throws InvalidParameterValueException, InternalErrorException;
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new zone
|
||||
* @param userId
|
||||
* @param zoneName
|
||||
* @param dns1
|
||||
* @param dns2
|
||||
* @param internalDns1
|
||||
* @param internalDns2
|
||||
* @param vnetRange
|
||||
* @param guestCidr
|
||||
* @return
|
||||
* @throws InvalidParameterValueException
|
||||
* @throws InternalErrorException
|
||||
*/
|
||||
DataCenterVO createZone(long userId, String zoneName, String dns1, String dns2, String internalDns1, String internalDns2, String vnetRange, String guestCidr) throws InvalidParameterValueException, InternalErrorException;
|
||||
|
||||
/**
|
||||
* Edits a zone in the database. Will not allow you to edit DNS values if there are VMs in the specified zone.
|
||||
* @param UpdateZoneCmd
|
||||
|
|
|
|||
|
|
@ -775,8 +775,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager {
|
|||
}
|
||||
|
||||
@Override
|
||||
public DataCenterVO editZone(UpdateZoneCmd cmd) throws InvalidParameterValueException, InternalErrorException
|
||||
{
|
||||
public DataCenterVO editZone(UpdateZoneCmd cmd) throws InvalidParameterValueException, InternalErrorException {
|
||||
//Parameter validation as from execute() method in V1
|
||||
Long zoneId = cmd.getId();
|
||||
String zoneName = cmd.getZoneName();
|
||||
|
|
@ -885,8 +884,54 @@ public class ConfigurationManagerImpl implements ConfigurationManager {
|
|||
|
||||
return zone;
|
||||
}
|
||||
|
||||
@DB
|
||||
|
||||
@Override @DB
|
||||
public DataCenterVO createZone(long userId, String zoneName, String dns1, String dns2, String internalDns1, String internalDns2, String vnetRange, String guestCidr) throws InvalidParameterValueException, InternalErrorException {
|
||||
int vnetStart, vnetEnd;
|
||||
if (vnetRange != null) {
|
||||
String[] tokens = vnetRange.split("-");
|
||||
|
||||
try {
|
||||
vnetStart = Integer.parseInt(tokens[0]);
|
||||
if (tokens.length == 1) {
|
||||
vnetEnd = vnetStart + 1;
|
||||
} else {
|
||||
vnetEnd = Integer.parseInt(tokens[1]);
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
throw new InvalidParameterValueException("Please specify valid integers for the vlan range.");
|
||||
}
|
||||
} else {
|
||||
String networkType = _configDao.getValue("network.type");
|
||||
if (networkType != null && networkType.equals("vnet")) {
|
||||
vnetStart = 1000;
|
||||
vnetEnd = 2000;
|
||||
} else {
|
||||
throw new InvalidParameterValueException("Please specify a vlan range.");
|
||||
}
|
||||
}
|
||||
|
||||
//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.isValidCIDR(guestCidr)) {
|
||||
throw new InvalidParameterValueException("Please enter a valid guest cidr");
|
||||
}
|
||||
|
||||
checkZoneParameters(zoneName, dns1, dns2, internalDns1, internalDns2, true);
|
||||
|
||||
// Create the new zone in the database
|
||||
DataCenterVO zone = new DataCenterVO(null, zoneName, null, dns1, dns2, internalDns1, internalDns2, vnetRange, guestCidr);
|
||||
zone = _zoneDao.persist(zone);
|
||||
|
||||
// Add vnet entries for the new zone
|
||||
_zoneDao.addVnet(zone.getId(), vnetStart, vnetEnd);
|
||||
|
||||
saveConfigurationEvent(userId, null, EventTypes.EVENT_ZONE_CREATE, "Successfully created new zone with name: " + zoneName + ".", "dcId=" + zone.getId(), "dns1=" + dns1, "dns2=" + dns2, "internalDns1=" + internalDns1, "internalDns2=" + internalDns2, "vnetRange=" + vnetRange, "guestCidr=" + guestCidr);
|
||||
|
||||
return zone;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataCenterVO createZone(CreateZoneCmd cmd) throws InvalidParameterValueException, InternalErrorException {
|
||||
// grab parameters from the command
|
||||
Long userId = UserContext.current().getUserId();
|
||||
|
|
@ -902,48 +947,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager {
|
|||
userId = User.UID_SYSTEM;
|
||||
}
|
||||
|
||||
int vnetStart, vnetEnd;
|
||||
if (vnetRange != null) {
|
||||
String[] tokens = vnetRange.split("-");
|
||||
|
||||
try {
|
||||
vnetStart = Integer.parseInt(tokens[0]);
|
||||
if (tokens.length == 1) {
|
||||
vnetEnd = vnetStart + 1;
|
||||
} else {
|
||||
vnetEnd = Integer.parseInt(tokens[1]);
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
throw new InvalidParameterValueException("Please specify valid integers for the vlan range.");
|
||||
}
|
||||
} else {
|
||||
String networkType = _configDao.getValue("network.type");
|
||||
if (networkType != null && networkType.equals("vnet")) {
|
||||
vnetStart = 1000;
|
||||
vnetEnd = 2000;
|
||||
} else {
|
||||
throw new InvalidParameterValueException("Please specify a vlan range.");
|
||||
}
|
||||
}
|
||||
|
||||
//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.isValidCIDR(guestCidr)) {
|
||||
throw new InvalidParameterValueException("Please enter a valid guest cidr");
|
||||
}
|
||||
|
||||
checkZoneParameters(zoneName, dns1, dns2, internalDns1, internalDns2,true);
|
||||
|
||||
// Create the new zone in the database
|
||||
DataCenterVO zone = new DataCenterVO(null, zoneName, null, dns1, dns2, internalDns1, internalDns2, vnetRange, guestCidr);
|
||||
zone = _zoneDao.persist(zone);
|
||||
|
||||
// Add vnet entries for the new zone
|
||||
_zoneDao.addVnet(zone.getId(), vnetStart, vnetEnd);
|
||||
|
||||
saveConfigurationEvent(userId, null, EventTypes.EVENT_ZONE_CREATE, "Successfully created new zone with name: " + zoneName + ".", "dcId=" + zone.getId(), "dns1=" + dns1, "dns2=" + dns2, "internalDns1=" + internalDns1, "internalDns2=" + internalDns2, "vnetRange=" + vnetRange, "guestCidr=" + guestCidr);
|
||||
|
||||
return zone;
|
||||
return createZone(userId, zoneName, dns1, dns2, internalDns1, internalDns2, vnetRange, guestCidr);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -1084,8 +1088,21 @@ public class ConfigurationManagerImpl implements ConfigurationManager {
|
|||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@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.");
|
||||
}
|
||||
|
||||
long diskSize = numGibibytes * 1024;
|
||||
tags = cleanupTags(tags);
|
||||
DiskOfferingVO newDiskOffering = new DiskOfferingVO(domainId, name, description, diskSize,tags);
|
||||
return _diskOfferingDao.persist(newDiskOffering);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DiskOfferingVO createDiskOffering(CreateDiskOfferingCmd cmd) throws InvalidParameterValueException {
|
||||
Long domainId = cmd.getDomainId();
|
||||
|
|
@ -1098,16 +1115,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager {
|
|||
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);
|
||||
return createDiskOffering(domainId, name, description, numGibibytes, tags);
|
||||
}
|
||||
|
||||
public DiskOfferingVO updateDiskOffering(UpdateDiskOfferingCmd cmd) throws InvalidParameterValueException{
|
||||
|
|
@ -1321,13 +1329,12 @@ public class ConfigurationManagerImpl implements ConfigurationManager {
|
|||
if (!vlanId.equals(Vlan.UNTAGGED)) {
|
||||
throw new InvalidParameterValueException("Direct Attached IP ranges for a pod must be untagged.");
|
||||
}
|
||||
|
||||
|
||||
// Check that the pod ID is valid
|
||||
HostPodVO pod = null;
|
||||
if (podId != null && ((pod = _podDao.findById(podId)) == null)) {
|
||||
if (podId != null && ((_podDao.findById(podId)) == null)) {
|
||||
throw new InvalidParameterValueException("Please specify a valid pod.");
|
||||
}
|
||||
|
||||
|
||||
// Make sure there aren't any account VLANs in this zone
|
||||
List<AccountVlanMapVO> accountVlanMaps = _accountVlanMapDao.listAll();
|
||||
for (AccountVlanMapVO accountVlanMap : accountVlanMaps) {
|
||||
|
|
@ -1336,7 +1343,6 @@ public class ConfigurationManagerImpl implements ConfigurationManager {
|
|||
throw new InvalidParameterValueException("Zone " + zone.getName() + " already has account-wide IP ranges. A zone may contain either pod-wide IP ranges or account-wide IP ranges, but not both.");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
} else {
|
||||
throw new InvalidParameterValueException("Please specify a valid IP range type. Valid types are: " + VlanType.values().toString());
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ import com.cloud.api.commands.CreateDomainCmd;
|
|||
import com.cloud.api.commands.CreatePortForwardingServiceCmd;
|
||||
import com.cloud.api.commands.CreatePortForwardingServiceRuleCmd;
|
||||
import com.cloud.api.commands.CreateUserCmd;
|
||||
import com.cloud.api.commands.DeleteDomainCmd;
|
||||
import com.cloud.api.commands.DeletePortForwardingServiceCmd;
|
||||
import com.cloud.api.commands.DeleteUserCmd;
|
||||
import com.cloud.api.commands.DeployVMCmd;
|
||||
|
|
@ -958,12 +959,13 @@ public interface ManagementServer {
|
|||
|
||||
/**
|
||||
* delete a domain with the given domainId
|
||||
* @param domainId
|
||||
* @param ownerId
|
||||
* @param cleanup - whether or not to delete all accounts/VMs/sub-domains when deleting the domain
|
||||
* @param cmd the command wrapping the delete parameters
|
||||
* - domainId
|
||||
* - ownerId
|
||||
* - cleanup: whether or not to delete all accounts/VMs/sub-domains when deleting the domain
|
||||
*/
|
||||
String deleteDomain(Long domainId, Long ownerId, Boolean cleanup);
|
||||
long deleteDomainAsync(Long domainId, Long ownerId, Boolean cleanup);
|
||||
String deleteDomain(DeleteDomainCmd cmd) throws InvalidParameterValueException, PermissionDeniedException;
|
||||
|
||||
/**
|
||||
* update an existing domain
|
||||
* @param domainId the id of the domain to be updated
|
||||
|
|
@ -1379,7 +1381,7 @@ public interface ManagementServer {
|
|||
* @return comma separated list of tags
|
||||
*/
|
||||
String getStoragePoolTags(long poolId);
|
||||
|
||||
|
||||
/**
|
||||
* Checks if a host has running VMs that are using its local storage pool.
|
||||
* @return true if local storage is active on the host
|
||||
|
|
@ -1387,9 +1389,7 @@ public interface ManagementServer {
|
|||
boolean isLocalStorageActiveOnHost(HostVO host);
|
||||
|
||||
public List<PreallocatedLunVO> getPreAllocatedLuns(ListPreallocatedLunsCmd cmd);
|
||||
|
||||
public String getNetworkGroupsNamesForVm(long vmId);
|
||||
|
||||
|
||||
boolean checkLocalStorageConfigVal();
|
||||
|
||||
boolean updateUser(UpdateUserCmd cmd) throws InvalidParameterValueException;
|
||||
|
|
|
|||
|
|
@ -59,6 +59,7 @@ import com.cloud.api.commands.CreateDomainCmd;
|
|||
import com.cloud.api.commands.CreatePortForwardingServiceCmd;
|
||||
import com.cloud.api.commands.CreatePortForwardingServiceRuleCmd;
|
||||
import com.cloud.api.commands.CreateUserCmd;
|
||||
import com.cloud.api.commands.DeleteDomainCmd;
|
||||
import com.cloud.api.commands.DeletePortForwardingServiceCmd;
|
||||
import com.cloud.api.commands.DeleteUserCmd;
|
||||
import com.cloud.api.commands.DeployVMCmd;
|
||||
|
|
@ -123,7 +124,6 @@ import com.cloud.async.AsyncJobResult;
|
|||
import com.cloud.async.AsyncJobVO;
|
||||
import com.cloud.async.BaseAsyncJobExecutor;
|
||||
import com.cloud.async.dao.AsyncJobDao;
|
||||
import com.cloud.async.executor.DeleteDomainParam;
|
||||
import com.cloud.async.executor.NetworkGroupIngressParam;
|
||||
import com.cloud.async.executor.SecurityGroupParam;
|
||||
import com.cloud.async.executor.VMOperationParam;
|
||||
|
|
@ -4965,24 +4965,19 @@ public class ManagementServerImpl implements ManagementServer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public long deleteDomainAsync(Long domainId, Long ownerId, Boolean cleanup) {
|
||||
DeleteDomainParam param = new DeleteDomainParam(domainId, ownerId, cleanup);
|
||||
Gson gson = GsonHelper.getBuilder().create();
|
||||
public String deleteDomain(DeleteDomainCmd cmd) throws InvalidParameterValueException, PermissionDeniedException {
|
||||
Account account = (Account)UserContext.current().getAccountObject();
|
||||
Long domainId = cmd.getId();
|
||||
Boolean cleanup = cmd.getCleanup();
|
||||
|
||||
AsyncJobVO job = new AsyncJobVO();
|
||||
job.setUserId(UserContext.current().getUserId());
|
||||
job.setAccountId(UserContext.current().getAccountId());
|
||||
job.setCmd("DeleteDomain");
|
||||
job.setCmdInfo(gson.toJson(param));
|
||||
return _asyncMgr.submitAsyncJob(job);
|
||||
}
|
||||
if ((domainId == DomainVO.ROOT_DOMAIN) || ((account != null) && !_domainDao.isChildDomain(account.getDomainId(), domainId))) {
|
||||
throw new PermissionDeniedException("Unable to delete domain " + domainId + ", permission denied.");
|
||||
}
|
||||
|
||||
// FIXME: need userId so the event can be saved with proper id
|
||||
@Override
|
||||
public String deleteDomain(Long domainId, Long ownerId, Boolean cleanup) {
|
||||
try {
|
||||
DomainVO domain = _domainDao.findById(domainId);
|
||||
if (domain != null) {
|
||||
long ownerId = domain.getOwner();
|
||||
if ((cleanup != null) && cleanup.booleanValue()) {
|
||||
boolean success = cleanupDomain(domainId, ownerId);
|
||||
if (!success) {
|
||||
|
|
@ -4997,8 +4992,12 @@ public class ManagementServerImpl implements ManagementServer {
|
|||
EventUtils.saveEvent(new Long(1), ownerId, EventVO.LEVEL_INFO, EventTypes.EVENT_DOMAIN_DELETE, "Domain with id " + domainId + " was deleted");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
throw new InvalidParameterValueException("Failed to delete domain nable " + domainId + ", domain not found");
|
||||
}
|
||||
return null;
|
||||
return "success";
|
||||
} catch (InvalidParameterValueException ex) {
|
||||
throw ex;
|
||||
} catch (Exception ex) {
|
||||
s_logger.error("Exception deleting domain with id " + domainId, ex);
|
||||
return "Delete failed on domain with id " + domainId + " due to an internal server error.";
|
||||
|
|
|
|||
Loading…
Reference in New Issue