Updated DeleteHost/DeleteIso/deletePool/UpdateDiskOffering/updateIso/updateTemplate/updateDomain to new api framework

This commit is contained in:
alena 2010-09-15 20:07:01 -07:00
parent ec47f83a4a
commit 6fef440732
11 changed files with 143 additions and 296 deletions

View File

@ -661,12 +661,7 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory {
throw new InvalidParameterValueException("Host with id " + id.toString() + " doesn't exist");
}
if (deleteHost(id)) {
return true;
}
else {
return false;
}
return deleteHost(id);
}

View File

@ -22,8 +22,11 @@ import org.apache.log4j.Logger;
import com.cloud.api.BaseCmd;
import com.cloud.api.BaseCmd.Manager;
import com.cloud.api.response.SuccessResponse;
import com.cloud.api.Implementation;
import com.cloud.api.Parameter;
import com.cloud.api.ServerApiException;
import com.cloud.serializer.SerializerHelper;
@Implementation(method="deleteHost", manager=Manager.AgentManager)
@ -56,31 +59,18 @@ public class DeleteHostCmd extends BaseCmd {
@Override
public String getName() {
return s_name;
}
@Override
public String getResponse() {
SuccessResponse response = new SuccessResponse();
Boolean responseObject = (Boolean)getResponseObject();
if (responseObject != null) {
response.setSuccess(responseObject);
} else {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete host");
}
return SerializerHelper.toSerializedString(responseObject);
}
// @Override
// public List<Pair<String, Object>> execute(Map<String, Object> params) {
// Long hostId = (Long)params.get(BaseCmd.Properties.ID.getName());
//
// //verify input parameters
// HostVO host = getManagementServer().getHostBy(hostId);
// if (host == null) {
// throw new ServerApiException(BaseCmd.PARAM_ERROR, "Host with id " + hostId.toString() + " doesn't exist");
// }
//
// boolean success = false;
// try {
// success = getManagementServer().deleteHost(hostId);
// } catch (Exception ex) {
// s_logger.warn("Unable to delete host " + hostId, ex);
// throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete the host " + hostId.toString() + ". Current host status is " + host.getStatus());
// }
//
// if (success == false) {
// throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete the host with id " + hostId.toString());
// }
// List<Pair<String, Object>> returnValues = new ArrayList<Pair<String, Object>>();
// returnValues.add(new Pair<String, Object>(BaseCmd.Properties.SUCCESS.getName(), Boolean.valueOf(success).toString()));
// return returnValues;
// }
}

View File

@ -22,8 +22,11 @@ import org.apache.log4j.Logger;
import com.cloud.api.BaseCmd;
import com.cloud.api.BaseCmd.Manager;
import com.cloud.api.response.SuccessResponse;
import com.cloud.api.Implementation;
import com.cloud.api.Parameter;
import com.cloud.api.ServerApiException;
import com.cloud.serializer.SerializerHelper;
@Implementation(method="deleteIso", manager=Manager.TemplateManager)
public class DeleteIsoCmd extends BaseCmd {
@ -66,60 +69,17 @@ public class DeleteIsoCmd extends BaseCmd {
public static String getStaticName() {
return s_name;
}
// @Override
// public List<Pair<String, Object>> execute(Map<String, Object> params) {
// Account account = (Account) params.get(BaseCmd.Properties.ACCOUNT_OBJ.getName());
// Long userId = (Long)params.get(BaseCmd.Properties.USER_ID.getName());
// Long isoId = (Long)params.get(BaseCmd.Properties.ID.getName());
// Long zoneId = (Long)params.get(BaseCmd.Properties.ZONE_ID.getName());
//
// if (userId == null) {
// userId = Long.valueOf(1);
// }
//
// VMTemplateVO iso = getManagementServer().findTemplateById(isoId);
// if (iso == null) {
// throw new ServerApiException(BaseCmd.PARAM_ERROR, "Failed to find ISO with given parameters.");
// }
//
// if (account != null) {
// if (!isAdmin(account.getType())) {
// if (iso.getAccountId() != account.getId().longValue()) {
// throw new ServerApiException(BaseCmd.ACCOUNT_ERROR, "Unable to delete ISO with id " + isoId);
// }
// } else {
// Account isoOwner = getManagementServer().findAccountById(iso.getAccountId());
// if (!getManagementServer().isChildDomain(account.getDomainId(), isoOwner.getDomainId())) {
// throw new ServerApiException(BaseCmd.ACCOUNT_ERROR, "Unable to delete ISO with id " + isoId + ", permission denied.");
// }
// }
// }
//
// try {
// long jobId = getManagementServer().deleteIsoAsync(userId, isoId, zoneId);
//
// if (jobId == 0) {
// s_logger.warn("Unable to schedule async-job for DeleteIso command");
// } else {
// if (s_logger.isDebugEnabled()) {
// s_logger.debug("DeleteIso command has been accepted, job id: " + jobId);
// }
// }
//
// List<Pair<String, Object>> returnValues = new ArrayList<Pair<String, Object>>();
// returnValues.add(new Pair<String, Object>(BaseCmd.Properties.JOB_ID.getName(), Long.valueOf(jobId)));
// returnValues.add(new Pair<String, Object>(BaseCmd.Properties.ISO_ID.getName(), Long.valueOf(isoId)));
//
// return returnValues;
// } catch (Exception ex) {
// throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete template: " + ex.getMessage());
// }
// }
@Override
public String getResponse() {
// TODO Auto-generated method stub
return null;
}
@Override
public String getResponse() {
SuccessResponse response = new SuccessResponse();
Boolean responseObject = (Boolean)getResponseObject();
if (responseObject != null) {
response.setSuccess(responseObject);
} else {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete iso");
}
return SerializerHelper.toSerializedString(responseObject);
}
}

View File

@ -6,8 +6,11 @@ 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.api.response.SuccessResponse;
import com.cloud.serializer.SerializerHelper;
@Implementation(method="deleteHost", manager=Manager.StorageManager)
@Implementation(method="deletePool", manager=Manager.StorageManager)
public class DeletePoolCmd extends BaseCmd {
public static final Logger s_logger = Logger.getLogger(DeletePoolCmd.class.getName());
private static final String s_name = "deletepoolresponse";
@ -28,7 +31,7 @@ public class DeletePoolCmd extends BaseCmd {
return id;
}
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
@ -37,36 +40,17 @@ public class DeletePoolCmd extends BaseCmd {
public String getName() {
return s_name;
}
// @Override
// public List<Pair<String, Object>> execute(Map<String, Object> params) {
// Long poolId = (Long) params.get(BaseCmd.Properties.ID.getName());
//
// //verify parameters
// StoragePoolVO sPool = getManagementServer().findPoolById(poolId);
// if (sPool == null) {
// throw new ServerApiException(BaseCmd.PARAM_ERROR, "Unable to find pool by id " + poolId);
// }
//
// if (sPool.getPoolType().equals(StoragePoolType.LVM)) {
// throw new ServerApiException(BaseCmd.UNSUPPORTED_ACTION_ERROR, "Unable to delete local storage id: " + poolId);
// }
//
// boolean deleted = true;
// try {
// deleted = getManagementServer().deletePool(poolId);
//
// } catch (Exception ex) {
// s_logger.error("Exception deleting pool", ex);
// throw new ServerApiException(BaseCmd.INTERNAL_ERROR, ex.getMessage());
// }
// if (!deleted) {
// throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Volumes exist on primary storage, unable to delete");
// }
//
// List<Pair<String, Object>> returnValues = new ArrayList<Pair<String, Object>>();
// returnValues.add(new Pair<String, Object>(BaseCmd.Properties.SUCCESS.getName(), "true"));
//
// return returnValues;
// }
@Override
public String getResponse() {
SuccessResponse response = new SuccessResponse();
Boolean responseObject = (Boolean)getResponseObject();
if (responseObject != null) {
response.setSuccess(responseObject);
} else {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete pool");
}
return SerializerHelper.toSerializedString(responseObject);
}
}

View File

@ -19,6 +19,7 @@
package com.cloud.api.commands;
import org.apache.log4j.Logger;
import com.cloud.api.ApiDBUtils;
import com.cloud.api.BaseCmd;
import com.cloud.api.BaseCmd.Manager;
import com.cloud.api.Implementation;
@ -80,7 +81,6 @@ public class UpdateDiskOfferingCmd extends BaseCmd{
return s_name;
}
public String getResponse() {
DiskOfferingResponse response = new DiskOfferingResponse();
if (responseObject != null) {
@ -91,8 +91,8 @@ public class UpdateDiskOfferingCmd extends BaseCmd{
response.setDomainId(responseObject.getDomainId());
response.setName(responseObject.getName());
response.setTags(responseObject.getTags());
// FIXME: domain name in the response
// response.setDomain(responseObject.getDomain());
response.setDomainId(ApiDBUtils.findDomainById(responseObject.getDomainId()).getId());
response.setDomain(ApiDBUtils.findDomainById(responseObject.getDomainId()).getName());
} else {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update disk offering");
}

View File

@ -24,6 +24,9 @@ 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.api.response.SuccessResponse;
import com.cloud.serializer.SerializerHelper;
@Implementation(method="updateDomain", manager=Manager.ManagementServer)
public class UpdateDomainCmd extends BaseCmd{
@ -59,50 +62,18 @@ public class UpdateDomainCmd extends BaseCmd{
@Override
public String getName() {
return s_name;
}
@Override
public String getResponse() {
SuccessResponse response = new SuccessResponse();
Boolean responseObject = (Boolean)getResponseObject();
if (responseObject != null) {
response.setSuccess(responseObject);
} else {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update domain");
}
return SerializerHelper.toSerializedString(responseObject);
}
// @Override
// public List<Pair<String, Object>> execute(Map<String, Object> params) {
// Account account = (Account)params.get(BaseCmd.Properties.ACCOUNT_OBJ.getName());
// Long domainId = (Long)params.get(BaseCmd.Properties.ID.getName());
// String newName = (String)params.get(BaseCmd.Properties.NAME.getName());
// Boolean editDomainResult = false;
//
// //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);
// } else if (domain.getParent() == null) {
// //check if domain is ROOT domain - and deny to edit it
// throw new ServerApiException(BaseCmd.PARAM_ERROR, "ROOT domain can not be edited");
// }
//
// // check permissions
// if ((account != null) && !getManagementServer().isChildDomain(account.getDomainId(), domain.getId())) {
// throw new ServerApiException(BaseCmd.ACCOUNT_ERROR, "Unable to update domain " + domainId + ", permission denied");
// }
//
// if (newName == null) {
// newName = domain.getName();
// }
//
// try {
// getManagementServer().updateDomain(domainId, newName);
// domain = getManagementServer().findDomainIdById(domainId);
// if (domain.getName().equals(newName)) {
// editDomainResult = true;
// }
// } catch (Exception ex) {
// s_logger.error("Exception editing domain", ex);
// throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update domain " + domainId + ": internal error.");
// }
//
// List<Pair<String, Object>> returnValues = new ArrayList<Pair<String, Object>>();
// if (editDomainResult == true) {
// returnValues.add(new Pair<String, Object>(BaseCmd.Properties.SUCCESS.getName(), new Boolean(true)));
// } else {
// throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update domain " + domainId);
// }
// return returnValues;
// }
}

View File

@ -20,8 +20,13 @@ package com.cloud.api.commands;
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.ServerApiException;
import com.cloud.api.response.TemplateResponse;
import com.cloud.serializer.SerializerHelper;
import com.cloud.storage.VMTemplateVO;
@Implementation(method="updateTemplate", manager=Manager.ManagementServer)
public class UpdateIsoCmd extends UpdateTemplateOrIsoCmd {
@ -48,60 +53,24 @@ public class UpdateIsoCmd extends UpdateTemplateOrIsoCmd {
@Override
public String getName() {
return s_name;
}
public String getResponse() {
TemplateResponse response = new TemplateResponse();
VMTemplateVO responseObject = (VMTemplateVO)getResponseObject();
if (responseObject != null) {
response.setId(responseObject.getId());
response.setName(responseObject.getName());
response.setDisplayText(responseObject.getDisplayText());
response.setPublic(responseObject.isPublicTemplate());
response.setCreated(responseObject.getCreated());
response.setFormat(responseObject.getFormat());
response.setOsTypeId(responseObject.getGuestOSId());
response.setBootable(responseObject.isBootable());
} else {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update iso");
}
return SerializerHelper.toSerializedString(responseObject);
}
// @Override
// public List<Pair<String, Object>> execute(Map<String, Object> params) {
// Account account = (Account)params.get(BaseCmd.Properties.ACCOUNT_OBJ.getName());
// String displayText = (String)params.get(BaseCmd.Properties.DISPLAY_TEXT.getName());
// String name = (String)params.get(BaseCmd.Properties.NAME.getName());
// Long isoId = (Long)params.get(BaseCmd.Properties.ID.getName());
// Long guestOSId = (Long) params.get(BaseCmd.Properties.OS_TYPE_ID.getName());
// Boolean bootable = (Boolean) params.get(BaseCmd.Properties.BOOTABLE.getName());
//
// VMTemplateVO iso = getManagementServer().findTemplateById(isoId.longValue());
// if ((iso == null) || iso.getFormat() != Storage.ImageFormat.ISO) {
// throw new ServerApiException(BaseCmd.PARAM_ERROR, "Unable to find ISO with id " + isoId);
// }
//
// // do a permission check
// if (account != null) {
// Long isoOwner = iso.getAccountId();
// if (!isAdmin(account.getType())) {
// if ((isoOwner == null) || (account.getId().longValue() != isoOwner.longValue())) {
// throw new ServerApiException(BaseCmd.ACCOUNT_ERROR, "Unable to modify ISO with id " + isoId);
// }
// } else if (account.getType() != Account.ACCOUNT_TYPE_ADMIN) {
// Long isoOwnerDomainId = getManagementServer().findDomainIdByAccountId(isoOwner);
// if (!getManagementServer().isChildDomain(account.getDomainId(), isoOwnerDomainId)) {
// throw new ServerApiException(BaseCmd.ACCOUNT_ERROR, "Unable to modify ISO with id " + isoId);
// }
// }
// }
//
// // do the update
// boolean success = false;
// try {
// success = getManagementServer().updateTemplate(isoId, name, displayText, null, guestOSId, null, bootable);
// } catch (Exception ex) {
// s_logger.error("Exception editing ISO", ex);
// throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update ISO " + isoId + ": " + ex.getMessage());
// }
//
// VMTemplateVO updatedIso = getManagementServer().findTemplateById(isoId);
// if (success) {
// List<Pair<String, Object>> isoData = new ArrayList<Pair<String, Object>>();
// isoData.add(new Pair<String, Object>(BaseCmd.Properties.ID.getName(), updatedIso.getId().toString()));
// isoData.add(new Pair<String, Object>(BaseCmd.Properties.NAME.getName(), updatedIso.getName()));
// isoData.add(new Pair<String, Object>(BaseCmd.Properties.DISPLAY_TEXT.getName(), updatedIso.getDisplayText()));
// isoData.add(new Pair<String, Object>(BaseCmd.Properties.IS_PUBLIC.getName(), Boolean.valueOf(updatedIso.isPublicTemplate()).toString()));
// isoData.add(new Pair<String, Object>(BaseCmd.Properties.CREATED.getName(), getDateString(updatedIso.getCreated())));
// isoData.add(new Pair<String, Object>(BaseCmd.Properties.FORMAT.getName(), updatedIso.getFormat()));
// isoData.add(new Pair<String, Object>(BaseCmd.Properties.OS_TYPE_ID.getName(), updatedIso.getGuestOSId()));
// isoData.add(new Pair<String, Object>(BaseCmd.Properties.BOOTABLE.getName(), updatedIso.isBootable()));
// return isoData;
// } else {
// throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "internal error updating ISO");
// }
// }
}

View File

@ -20,8 +20,13 @@ package com.cloud.api.commands;
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.ServerApiException;
import com.cloud.api.response.TemplateResponse;
import com.cloud.serializer.SerializerHelper;
import com.cloud.storage.VMTemplateVO;
@Implementation(method="updateTemplate", manager=Manager.ManagementServer)
public class UpdateTemplateCmd extends UpdateTemplateOrIsoCmd {
@ -35,64 +40,32 @@ public class UpdateTemplateCmd extends UpdateTemplateOrIsoCmd {
public Boolean isBootable() {
return null;
}
// @Override
// public List<Pair<String, Object>> execute(Map<String, Object> params) {
// Long templateId = (Long)params.get(BaseCmd.Properties.ID.getName());
// Account account = (Account)params.get(BaseCmd.Properties.ACCOUNT_OBJ.getName());
// String name = (String)params.get(BaseCmd.Properties.NAME.getName());
// String displayText = (String)params.get(BaseCmd.Properties.DISPLAY_TEXT.getName());
// String format = (String)params.get(BaseCmd.Properties.FORMAT.getName());
// Long guestOSId = (Long) params.get(BaseCmd.Properties.OS_TYPE_ID.getName());
// Boolean passwordEnabled = (Boolean)params.get(BaseCmd.Properties.PASSWORD_ENABLED.getName());
//
// VMTemplateVO template = getManagementServer().findTemplateById(templateId.longValue());
// if (template == null) {
// throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "unable to find template with id " + templateId);
// }
//
// if (account != null) {
// if (!isAdmin(account.getType())) {
// if (template.getAccountId() != account.getId()) {
// throw new ServerApiException(BaseCmd.ACCOUNT_ERROR, "unable to edit template with id " + templateId);
// }
// } else if (account.getType() != Account.ACCOUNT_TYPE_ADMIN) {
// Long templateOwnerDomainId = getManagementServer().findDomainIdByAccountId(template.getAccountId());
// if (!getManagementServer().isChildDomain(account.getDomainId(), templateOwnerDomainId)) {
// throw new ServerApiException(BaseCmd.ACCOUNT_ERROR, "Unable to modify template with id " + templateId);
// }
// }
// }
//
// if (templateId == Long.valueOf(1)) {
// throw new ServerApiException(BaseCmd.PARAM_ERROR, "unable to update template with id " + templateId);
// }
//
//
// boolean success = false;
// try {
// success = getManagementServer().updateTemplate(templateId, name, displayText, format, guestOSId, passwordEnabled, null);
// } catch (Exception ex) {
// s_logger.error("Exception editing template", ex);
// throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update template " + templateId + ": " + ex.getMessage());
// }
//
// VMTemplateVO updatedTemplate = getManagementServer().findTemplateById(templateId);
// if (success) {
// List<Pair<String, Object>> templateData = new ArrayList<Pair<String, Object>>();
// templateData.add(new Pair<String, Object>(BaseCmd.Properties.ID.getName(), updatedTemplate.getId().toString()));
// templateData.add(new Pair<String, Object>(BaseCmd.Properties.NAME.getName(), updatedTemplate.getName()));
// templateData.add(new Pair<String, Object>(BaseCmd.Properties.DISPLAY_TEXT.getName(), updatedTemplate.getDisplayText()));
// templateData.add(new Pair<String, Object>(BaseCmd.Properties.IS_PUBLIC.getName(), Boolean.valueOf(updatedTemplate.isPublicTemplate()).toString()));
// templateData.add(new Pair<String, Object>(BaseCmd.Properties.CREATED.getName(), getDateString(updatedTemplate.getCreated())));
// templateData.add(new Pair<String, Object>(BaseCmd.Properties.FORMAT.getName(), updatedTemplate.getFormat()));
// templateData.add(new Pair<String, Object>(BaseCmd.Properties.OS_TYPE_ID.getName(), updatedTemplate.getGuestOSId()));
// templateData.add(new Pair<String, Object>(BaseCmd.Properties.PASSWORD_ENABLED.getName(), updatedTemplate.getEnablePassword()));
// templateData.add(new Pair<String, Object>(BaseCmd.Properties.CROSS_ZONES.getName(), Boolean.valueOf(updatedTemplate.isCrossZones()).toString()));
// return templateData;
// } else {
// throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "internal error updating template");
// }
// }
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
@Override
public String getName() {
return s_name;
}
public String getResponse() {
TemplateResponse response = new TemplateResponse();
VMTemplateVO responseObject = (VMTemplateVO)getResponseObject();
if (responseObject != null) {
response.setId(responseObject.getId());
response.setName(responseObject.getName());
response.setDisplayText(responseObject.getDisplayText());
response.setPublic(responseObject.isPublicTemplate());
response.setCreated(responseObject.getCreated());
response.setFormat(responseObject.getFormat());
response.setOsTypeId(responseObject.getGuestOSId());
response.setPasswordEnabled(responseObject.getEnablePassword());
response.setCrossZones(responseObject.isCrossZones());
} else {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update template");
}
return SerializerHelper.toSerializedString(responseObject);
}
}

View File

@ -627,8 +627,9 @@ public interface ManagementServer {
* Creates a new template
* @param cmd
* @return success/failure
* @throws InvalidParameterValueException, PermissionDeniedException
*/
boolean updateTemplate(UpdateTemplateOrIsoCmd cmd) throws InvalidParameterValueException;
boolean updateTemplate(UpdateTemplateOrIsoCmd cmd) throws InvalidParameterValueException, PermissionDeniedException;
/**
* Copies a template from one secondary storage server to another
@ -867,10 +868,11 @@ public interface ManagementServer {
/**
* update an existing domain
* @param domainId the id of the domain to be updated
* @param domainName the new name of the domain
* @param cmd - the command containing domainId and new domainName
* @return true if domain is updated, false otherwise
* @throws InvalidParameterValueException, PermissionDeniedException
*/
void updateDomain(UpdateDomainCmd cmd) throws InvalidParameterValueException;
boolean updateDomain(UpdateDomainCmd cmd) throws InvalidParameterValueException, PermissionDeniedException;
/**
* find the domain Id associated with the given account

View File

@ -3394,7 +3394,7 @@ public class ManagementServerImpl implements ManagementServer {
}
@Override
public boolean updateTemplate(UpdateTemplateOrIsoCmd cmd) throws InvalidParameterValueException {
public boolean updateTemplate(UpdateTemplateOrIsoCmd cmd) throws InvalidParameterValueException, PermissionDeniedException {
Long id = cmd.getId();
String name = cmd.getName();
String displayText = cmd.getDisplayText();
@ -3407,12 +3407,12 @@ public class ManagementServerImpl implements ManagementServer {
//verify that template exists
VMTemplateVO template = findTemplateById(id);
if (template == null) {
throw new InvalidParameterValueException("unable to find template with id " + id);
throw new InvalidParameterValueException("unable to find template/iso with id " + id);
}
//Don't allow to modify system template
if (id == Long.valueOf(1)) {
throw new InvalidParameterValueException("Unable to update template with id " + id);
throw new InvalidParameterValueException("Unable to update template/iso with id " + id);
}
//do a permission check
@ -3420,12 +3420,12 @@ public class ManagementServerImpl implements ManagementServer {
Long templateOwner = template.getAccountId();
if (!BaseCmd.isAdmin(account.getType())) {
if ((templateOwner == null) || (account.getId().longValue() != templateOwner.longValue())) {
throw new InvalidParameterValueException("Unable to modify template with id " + id);
throw new PermissionDeniedException("Unable to modify template/iso with id " + id + ", permission denied.");
}
} else if (account.getType() != Account.ACCOUNT_TYPE_ADMIN) {
Long templateOwnerDomainId = findDomainIdByAccountId(templateOwner);
if (!isChildDomain(account.getDomainId(), templateOwnerDomainId)) {
throw new InvalidParameterValueException("Unable to modify template with id " + id);
throw new PermissionDeniedException("Unable to modify template/iso with id " + id + ", permission denied");
}
}
}
@ -4927,7 +4927,7 @@ public class ManagementServerImpl implements ManagementServer {
return success && deleteDomainSuccess;
}
public void updateDomain(UpdateDomainCmd cmd) throws InvalidParameterValueException{
public boolean updateDomain(UpdateDomainCmd cmd) throws InvalidParameterValueException, PermissionDeniedException{
Long domainId = cmd.getId();
String domainName = cmd.getName();
@ -4943,14 +4943,13 @@ public class ManagementServerImpl implements ManagementServer {
// check permissions
Account account = (Account)UserContext.current().getAccountObject();
if ((account != null) && !isChildDomain(account.getDomainId(), domain.getId())) {
throw new ServerApiException(BaseCmd.ACCOUNT_ERROR, "Unable to update domain " + domainId + ", permission denied");
throw new PermissionDeniedException("Unable to update domain " + domainId + ", permission denied");
}
if (domainName == null) {
domainName = domain.getName();
}
SearchCriteria<DomainVO> sc = _domainDao.createSearchCriteria();
sc.addAnd("name", SearchCriteria.Op.EQ, domainName);
List<DomainVO> domains = _domainDao.search(sc, null);
@ -4958,9 +4957,11 @@ public class ManagementServerImpl implements ManagementServer {
_domainDao.update(domainId, domainName);
domain = _domainDao.findById(domainId);
EventUtils.saveEvent(new Long(1), domain.getOwner(), EventVO.LEVEL_INFO, EventTypes.EVENT_DOMAIN_UPDATE, "Domain, " + domainName + " was updated");
return true;
} else {
domain = _domainDao.findById(domainId);
EventUtils.saveEvent(new Long(1), domain.getOwner(), EventVO.LEVEL_ERROR, EventTypes.EVENT_DOMAIN_UPDATE, "Failed to update domain " + domain.getName() + " with name " + domainName + ", name in use.");
return false;
}
}

View File

@ -153,6 +153,8 @@ public interface TemplateManager extends Manager {
/**
* Deletes a template
* @param cmd - the command specifying isoId
* @return true if deletion is successful, false otherwise
* @throws InvalidParameterValueException, InternalErrorException, PermissionDeniedException
*/
boolean deleteIso(DeleteIsoCmd cmd) throws InvalidParameterValueException, InternalErrorException, PermissionDeniedException;