Refactoring addConfig/deleteDiskOffering/deletePod/getCloudIdentifier/enableAccount/enableUser/enableAccount/updateUser/updateDiskOffering/updateConfig commands to new API framework

This commit is contained in:
alena 2010-09-15 16:41:38 -07:00
parent dc6e07ad75
commit b49f63c28e
15 changed files with 243 additions and 349 deletions

View File

@ -25,6 +25,10 @@ import com.cloud.api.BaseCmd;
import com.cloud.api.BaseCmd.Manager; import com.cloud.api.BaseCmd.Manager;
import com.cloud.api.Implementation; import com.cloud.api.Implementation;
import com.cloud.api.Parameter; import com.cloud.api.Parameter;
import com.cloud.api.ServerApiException;
import com.cloud.api.response.ConfigurationResponse;
import com.cloud.configuration.ConfigurationVO;
import com.cloud.serializer.SerializerHelper;
@Implementation(method="addConfig", manager=Manager.ConfigManager) @Implementation(method="addConfig", manager=Manager.ConfigManager)
public class AddConfigCmd extends BaseCmd { public class AddConfigCmd extends BaseCmd {
@ -92,35 +96,19 @@ public class AddConfigCmd extends BaseCmd {
public String getName() { public String getName() {
return s_name; return s_name;
} }
/*
@Override @Override
public List<Pair<String, Object>> execute(Map<String, Object> params) { public String getResponse() {
String instance = (String) params.get(BaseCmd.Properties.INSTANCE.getName()); ConfigurationResponse response = new ConfigurationResponse();
String component = (String) params.get(BaseCmd.Properties.COMPONENT.getName()); ConfigurationVO responseObject = (ConfigurationVO)getResponseObject();
String category = (String) params.get(BaseCmd.Properties.CATEGORY.getName()); if (responseObject != null) {
String name = (String) params.get(BaseCmd.Properties.NAME.getName()); response.setName(responseObject.getName());
String value = (String) params.get(BaseCmd.Properties.VALUE.getName()); response.setValue(responseObject.getValue());
String description = (String) params.get(BaseCmd.Properties.DESCRIPTION.getName()); //TODO - return description and category if needed (didn't return in 2.1 release)
try
{
boolean status = getManagementServer().addConfig(instance, component, category, name, value, description);
List<Pair<String, Object>> returnValues = new ArrayList<Pair<String, Object>>();
if(status)
{
returnValues.add(new Pair<String, Object>(BaseCmd.Properties.NAME.getName(), name));
returnValues.add(new Pair<String, Object>(BaseCmd.Properties.VALUE.getName(), value));
}
return returnValues;
}
catch (Exception ex) {
s_logger.error("Exception adding config value: ", ex);
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to add config value : " + ex.getMessage());
}
} else {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to add config");
}
return SerializerHelper.toSerializedString(responseObject);
} }
*/
} }

View File

@ -22,8 +22,11 @@ import org.apache.log4j.Logger;
import com.cloud.api.BaseCmd; import com.cloud.api.BaseCmd;
import com.cloud.api.BaseCmd.Manager; import com.cloud.api.BaseCmd.Manager;
import com.cloud.api.response.SuccessResponse;
import com.cloud.api.Implementation; import com.cloud.api.Implementation;
import com.cloud.api.Parameter; import com.cloud.api.Parameter;
import com.cloud.api.ServerApiException;
import com.cloud.serializer.SerializerHelper;
@Implementation(method="deleteDiskOffering", manager=Manager.ConfigManager) @Implementation(method="deleteDiskOffering", manager=Manager.ConfigManager)
public class DeleteDiskOfferingCmd extends BaseCmd { public class DeleteDiskOfferingCmd extends BaseCmd {
@ -58,8 +61,14 @@ public class DeleteDiskOfferingCmd extends BaseCmd {
@Override @Override
public String getResponse() { public String getResponse() {
// There's no specific response for this command, if the command failed an exception would have been thrown. If we are here, then it succeeded. SuccessResponse response = new SuccessResponse();
// Seems like we should return success/true as the response though, so this will probably have to change. Boolean responseObject = (Boolean)getResponseObject();
return null;
if (responseObject != null) {
response.setSuccess(responseObject);
} else {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete disk offering");
}
return SerializerHelper.toSerializedString(responseObject);
} }
} }

View File

@ -22,8 +22,11 @@ import org.apache.log4j.Logger;
import com.cloud.api.BaseCmd; import com.cloud.api.BaseCmd;
import com.cloud.api.BaseCmd.Manager; import com.cloud.api.BaseCmd.Manager;
import com.cloud.api.response.SuccessResponse;
import com.cloud.api.Implementation; import com.cloud.api.Implementation;
import com.cloud.api.Parameter; import com.cloud.api.Parameter;
import com.cloud.api.ServerApiException;
import com.cloud.serializer.SerializerHelper;
@Implementation(method="deletePod", manager=Manager.ConfigManager) @Implementation(method="deletePod", manager=Manager.ConfigManager)
public class DeletePodCmd extends BaseCmd { public class DeletePodCmd extends BaseCmd {
@ -54,32 +57,17 @@ public class DeletePodCmd extends BaseCmd {
public String getName() { public String getName() {
return s_name; return s_name;
} }
// @Override @Override
// public List<Pair<String, Object>> execute(Map<String, Object> params) { public String getResponse() {
// Long podId = (Long) params.get(BaseCmd.Properties.ID.getName()); SuccessResponse response = new SuccessResponse();
// Long userId = (Long)params.get(BaseCmd.Properties.USER_ID.getName()); Boolean responseObject = (Boolean)getResponseObject();
//
// if (userId == null) { if (responseObject != null) {
// userId = Long.valueOf(User.UID_SYSTEM); response.setSuccess(responseObject);
// } } else {
// throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete pod");
// //verify parameters }
// HostPodVO pod = getManagementServer().findHostPodById(podId); return SerializerHelper.toSerializedString(responseObject);
// if (pod == null) { }
// throw new ServerApiException(BaseCmd.PARAM_ERROR, "Unable to find pod by id " + podId);
// }
//
// try {
// getManagementServer().deletePod(userId, podId);
// } catch (Exception ex) {
// s_logger.error("Exception deleting pod", ex);
// throw new ServerApiException(BaseCmd.INTERNAL_ERROR, ex.getMessage());
// }
//
// List<Pair<String, Object>> returnValues = new ArrayList<Pair<String, Object>>();
// returnValues.add(new Pair<String, Object>(BaseCmd.Properties.SUCCESS.getName(), "true"));
//
// return returnValues;
// }
} }

View File

@ -22,8 +22,11 @@ import org.apache.log4j.Logger;
import com.cloud.api.BaseCmd; import com.cloud.api.BaseCmd;
import com.cloud.api.BaseCmd.Manager; import com.cloud.api.BaseCmd.Manager;
import com.cloud.api.response.SuccessResponse;
import com.cloud.api.Implementation; import com.cloud.api.Implementation;
import com.cloud.api.Parameter; import com.cloud.api.Parameter;
import com.cloud.api.ServerApiException;
import com.cloud.serializer.SerializerHelper;
@Implementation(method="enableAccount", manager=Manager.ManagementServer) @Implementation(method="enableAccount", manager=Manager.ManagementServer)
public class EnableAccountCmd extends BaseCmd { public class EnableAccountCmd extends BaseCmd {
@ -63,36 +66,16 @@ public class EnableAccountCmd extends BaseCmd {
return s_name; return s_name;
} }
// @Override @Override
// public List<Pair<String, Object>> execute(Map<String, Object> params) { public String getResponse() {
// Account adminAccount = (Account)params.get(BaseCmd.Properties.ACCOUNT_OBJ.getName()); SuccessResponse response = new SuccessResponse();
// Long domainId = (Long)params.get(BaseCmd.Properties.DOMAIN_ID.getName()); Boolean responseObject = (Boolean)getResponseObject();
// String accountName = (String)params.get(BaseCmd.Properties.ACCOUNT.getName());
// if (responseObject != null) {
// if ((adminAccount != null) && !getManagementServer().isChildDomain(adminAccount.getDomainId(), domainId)) { response.setSuccess(responseObject);
// throw new ServerApiException(BaseCmd.ACCOUNT_ERROR, "Failed to enable account " + accountName + " in domain " + domainId + ", permission denied."); } else {
// } throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to enable account");
// }
// Account account = getManagementServer().findActiveAccount(accountName, domainId); return SerializerHelper.toSerializedString(responseObject);
// if (account == null) { }
// throw new ServerApiException (BaseCmd.PARAM_ERROR, "Unable to find active account with name " + accountName + " in domain " + domainId);
// }
//
// // don't allow modify system account
// if (account.getId().longValue() == Account.ACCOUNT_ID_SYSTEM) {
// throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "can not enable system account");
// }
//
// boolean success = true;
// try {
// success = getManagementServer().enableAccount(account.getId().longValue());
// } catch (Exception ex) {
// s_logger.error("error enabling account " + accountName + " in domain " + domainId, ex);
// throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Internal error enabling account " + accountName + " in domain " + domainId);
// }
//
// 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

@ -24,6 +24,9 @@ import com.cloud.api.BaseCmd;
import com.cloud.api.BaseCmd.Manager; import com.cloud.api.BaseCmd.Manager;
import com.cloud.api.Implementation; import com.cloud.api.Implementation;
import com.cloud.api.Parameter; import com.cloud.api.Parameter;
import com.cloud.api.ServerApiException;
import com.cloud.api.response.SuccessResponse;
import com.cloud.serializer.SerializerHelper;
@Implementation(method="enableUser", manager=Manager.ManagementServer) @Implementation(method="enableUser", manager=Manager.ManagementServer)
public class EnableUserCmd extends BaseCmd { public class EnableUserCmd extends BaseCmd {
@ -53,42 +56,18 @@ public class EnableUserCmd extends BaseCmd {
@Override @Override
public String getName() { public String getName() {
return s_name; 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 enable user");
}
return SerializerHelper.toSerializedString(responseObject);
} }
// @Override
// public List<Pair<String, Object>> execute(Map<String, Object> params) {
// Account adminAccount = (Account)params.get(BaseCmd.Properties.ACCOUNT_OBJ.getName());
// Long id = (Long)params.get(BaseCmd.Properties.ID.getName());
//
// // Check if user with id exists in the system
// User user = getManagementServer().findUserById(id);
// if (user == null) {
// throw new ServerApiException(BaseCmd.ACCOUNT_ERROR, "Unable to find user by id");
// } else if (user.getRemoved() != null) {
// throw new ServerApiException(BaseCmd.ACCOUNT_ERROR, "Unable to find user by id");
// }
//
// // If the user is a System user, return an error. We do not allow this
// Account account = getManagementServer().findAccountById(user.getAccountId());
// if ((account != null) && (account.getId() == Account.ACCOUNT_ID_SYSTEM)) {
// throw new ServerApiException(BaseCmd.ACCOUNT_ERROR, "user id : " + id + " is a system user, enabling is not allowed");
// }
//
// if ((adminAccount != null) && !getManagementServer().isChildDomain(adminAccount.getDomainId(), account.getDomainId())) {
// throw new ServerApiException(BaseCmd.ACCOUNT_ERROR, "Failed to enable user " + id + ", permission denied.");
// }
//
// boolean success = true;
// try {
// success = getManagementServer().enableUser(id.longValue());
// } catch (Exception ex) {
// s_logger.error("error enabling user with id: " + id, ex);
// success = false;
// }
//
// 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

@ -18,12 +18,17 @@
package com.cloud.api.commands; package com.cloud.api.commands;
import java.util.ArrayList;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import com.cloud.api.BaseCmd; import com.cloud.api.BaseCmd;
import com.cloud.api.BaseCmd.Manager; import com.cloud.api.BaseCmd.Manager;
import com.cloud.api.Implementation; import com.cloud.api.Implementation;
import com.cloud.api.Parameter; import com.cloud.api.Parameter;
import com.cloud.api.ServerApiException;
import com.cloud.api.response.CloudIdentifierResponse;
import com.cloud.serializer.SerializerHelper;
@Implementation(method="getCloudIdentifierResponse", manager=Manager.ManagementServer) @Implementation(method="getCloudIdentifierResponse", manager=Manager.ManagementServer)
public class GetCloudIdentifierCmd extends BaseCmd { public class GetCloudIdentifierCmd extends BaseCmd {
@ -54,19 +59,18 @@ public class GetCloudIdentifierCmd extends BaseCmd {
public String getName() { public String getName() {
return s_name; return s_name;
} }
// @Override
// public List<Pair<String, Object>> execute(Map<String, Object> params) {
// Long userId = (Long)params.get(BaseCmd.Properties.USER_ID.getName());
//
// ArrayList<String> signedResponse = getManagementServer().getCloudIdentifierResponse(userId);
//
// List<Pair<String, Object>> returnValues = new ArrayList<Pair<String, Object>>();
//
// returnValues.add(new Pair<String, Object>(BaseCmd.Properties.CLOUD_IDENTIFIER.getName(),signedResponse.get(0)));
// returnValues.add(new Pair<String, Object>(BaseCmd.Properties.SIGNATURE.getName(),signedResponse.get(1)));
// return returnValues;
// }
@Override
public String getResponse() {
CloudIdentifierResponse response = new CloudIdentifierResponse();
ArrayList<String> responseObject = (ArrayList<String>)getResponseObject();
if (responseObject != null) {
response.setCloudIdentifier(responseObject.get(0));
response.setSignature(responseObject.get(1));
} else {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to add config");
}
return SerializerHelper.toSerializedString(responseObject);
}
} }

View File

@ -22,8 +22,11 @@ import org.apache.log4j.Logger;
import com.cloud.api.BaseCmd; import com.cloud.api.BaseCmd;
import com.cloud.api.BaseCmd.Manager; import com.cloud.api.BaseCmd.Manager;
import com.cloud.api.response.SuccessResponse;
import com.cloud.api.Implementation; import com.cloud.api.Implementation;
import com.cloud.api.Parameter; import com.cloud.api.Parameter;
import com.cloud.api.ServerApiException;
import com.cloud.serializer.SerializerHelper;
@Implementation(method="updateAccount", manager=Manager.ManagementServer) @Implementation(method="updateAccount", manager=Manager.ManagementServer)
public class UpdateAccountCmd extends BaseCmd{ public class UpdateAccountCmd extends BaseCmd{
@ -67,48 +70,17 @@ public class UpdateAccountCmd extends BaseCmd{
public String getName() { public String getName() {
return s_name; return s_name;
} }
// @Override @Override
// public List<Pair<String, Object>> execute(Map<String, Object> params) { public String getResponse() {
// Long domainId = (Long)params.get(BaseCmd.Properties.DOMAIN_ID.getName()); SuccessResponse response = new SuccessResponse();
// String accountName = (String)params.get(BaseCmd.Properties.ACCOUNT.getName()); Boolean responseObject = (Boolean)getResponseObject();
// String newAccountName = (String)params.get(BaseCmd.Properties.NEW_NAME.getName());
// Account adminAccount = (Account)params.get(BaseCmd.Properties.ACCOUNT_OBJ.getName());; if (responseObject != null) {
// Boolean updateAccountResult = false; response.setSuccess(responseObject);
// Account account = null; } else {
// throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update account");
// // check if account exists in the system }
// account = getManagementServer().findAccountByName(accountName, domainId); return SerializerHelper.toSerializedString(responseObject);
// if (account == null) { }
// throw new ServerApiException(BaseCmd.PARAM_ERROR, "unable to find account " + accountName + " in domain " + domainId);
// }
//
// if ((adminAccount != null) && !getManagementServer().isChildDomain(adminAccount.getDomainId(), account.getDomainId())) {
// throw new ServerApiException(BaseCmd.PARAM_ERROR, "Invalid account " + accountName + " in domain " + domainId + " given, unable to update account.");
// }
//
// // don't allow modify system account
// if (account.getId().longValue() == Account.ACCOUNT_ID_SYSTEM) {
// throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "can not modify system account");
// }
//
// try {
// getManagementServer().updateAccount(account.getId(), newAccountName);
// account = getManagementServer().findAccountById(account.getId());
// if (account.getAccountName().equals(newAccountName)) {
// updateAccountResult = true;
// }
// } catch (Exception ex) {
// s_logger.error("Exception updating account", ex);
// throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update account " + accountName + " in domain " + domainId + ": internal error.");
// }
//
// List<Pair<String, Object>> returnValues = new ArrayList<Pair<String, Object>>();
// if (updateAccountResult == true) {
// returnValues.add(new Pair<String, Object>(BaseCmd.Properties.SUCCESS.getName(), new Boolean(true)));
// } else {
// throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update account " + accountName + " in domain " + domainId);
// }
// return returnValues;
// }
} }

View File

@ -24,6 +24,9 @@ import com.cloud.api.BaseCmd;
import com.cloud.api.BaseCmd.Manager; import com.cloud.api.BaseCmd.Manager;
import com.cloud.api.Implementation; import com.cloud.api.Implementation;
import com.cloud.api.Parameter; import com.cloud.api.Parameter;
import com.cloud.api.ServerApiException;
import com.cloud.api.response.SuccessResponse;
import com.cloud.serializer.SerializerHelper;
@Implementation(method="updateConfiguration", manager=Manager.ConfigManager) @Implementation(method="updateConfiguration", manager=Manager.ConfigManager)
public class UpdateCfgCmd extends BaseCmd { public class UpdateCfgCmd extends BaseCmd {
@ -59,27 +62,17 @@ public class UpdateCfgCmd extends BaseCmd {
public String getName() { public String getName() {
return s_name; return s_name;
} }
// @Override @Override
// public List<Pair<String, Object>> execute(Map<String, Object> params) { public String getResponse() {
// String name = (String) params.get(BaseCmd.Properties.NAME.getName()); SuccessResponse response = new SuccessResponse();
// String value = (String) params.get(BaseCmd.Properties.VALUE.getName()); Boolean responseObject = (Boolean)getResponseObject();
// Long userId = (Long)params.get(BaseCmd.Properties.USER_ID.getName());
// if (responseObject != null) {
// if (userId == null) { response.setSuccess(responseObject);
// userId = Long.valueOf(User.UID_SYSTEM); } else {
// } throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update config");
// }
// try { return SerializerHelper.toSerializedString(responseObject);
// getManagementServer().updateConfiguration(userId, name, value); }
// } catch (Exception ex) {
// throw new ServerApiException(BaseCmd.INTERNAL_ERROR, ex.getMessage());
// }
//
// List<Pair<String, Object>> returnValues = new ArrayList<Pair<String, Object>>();
// returnValues.add(new Pair<String, Object>(BaseCmd.Properties.SUCCESS.getName(), "true"));
// returnValues.add(new Pair<String, Object>(BaseCmd.Properties.DISPLAY_TEXT.getName(), "Successfully updated configuration value."));
//
// return returnValues;
// }
} }

View File

@ -17,8 +17,6 @@
*/ */
package com.cloud.api.commands; package com.cloud.api.commands;
import java.util.Date;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import com.cloud.api.BaseCmd; import com.cloud.api.BaseCmd;
@ -26,7 +24,7 @@ import com.cloud.api.BaseCmd.Manager;
import com.cloud.api.Implementation; import com.cloud.api.Implementation;
import com.cloud.api.Parameter; import com.cloud.api.Parameter;
import com.cloud.api.ServerApiException; import com.cloud.api.ServerApiException;
import com.cloud.serializer.Param; import com.cloud.api.response.DiskOfferingResponse;
import com.cloud.serializer.SerializerHelper; import com.cloud.serializer.SerializerHelper;
import com.cloud.storage.DiskOfferingVO; import com.cloud.storage.DiskOfferingVO;
@ -91,109 +89,14 @@ public class UpdateDiskOfferingCmd extends BaseCmd{
response.setDiskSize(responseObject.getDiskSize()); response.setDiskSize(responseObject.getDiskSize());
response.setDisplayText(responseObject.getDisplayText()); response.setDisplayText(responseObject.getDisplayText());
response.setDomainId(responseObject.getDomainId()); response.setDomainId(responseObject.getDomainId());
// FIXME: domain name in the response
// response.setDomain(responseObject.getDomain());
response.setName(responseObject.getName()); response.setName(responseObject.getName());
response.setTags(responseObject.getTags()); response.setTags(responseObject.getTags());
// FIXME: domain name in the response
// response.setDomain(responseObject.getDomain());
} else { } else {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update disk offering"); throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update disk offering");
} }
return SerializerHelper.toSerializedString(responseObject); return SerializerHelper.toSerializedString(responseObject);
}
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;
}
} }
} }

View File

@ -0,0 +1,41 @@
package com.cloud.api.response;
import com.cloud.api.ResponseObject;
import com.cloud.serializer.Param;
public class CloudIdentifierResponse implements ResponseObject{
@Param(name="userid")
private Long userId;
@Param(name="cloudidentifier")
private String cloudIdentifier;
@Param(name="signature")
private String signature;
public Long getUserId() {
return userId;
}
public void setUserId(Long userId) {
this.userId = userId;
}
public String getCloudIdentifier() {
return cloudIdentifier;
}
public void setCloudIdentifier(String cloudIdentifier) {
this.cloudIdentifier = cloudIdentifier;
}
public String getSignature() {
return signature;
}
public void setSignature(String signature) {
this.signature = signature;
}
}

View File

@ -0,0 +1,18 @@
package com.cloud.api.response;
import com.cloud.api.ResponseObject;
import com.cloud.serializer.Param;
public class SuccessResponse implements ResponseObject{
@Param(name="success")
private Boolean success;
public Boolean getSuccess() {
return success;
}
public void setSuccess(Boolean success) {
this.success = success;
}
}

View File

@ -63,11 +63,11 @@ public interface ConfigurationManager extends Manager {
/** /**
* Updates a configuration entry with a new value * Updates a configuration entry with a new value
* @param userId * @param cmd - the command wrapping name and value parameters
* @param name * @return true or false
* @param value * @throws InvalidParameterValueException, InternalErrorException
*/ */
void updateConfiguration(UpdateCfgCmd cmd) throws InvalidParameterValueException, InternalErrorException; boolean updateConfiguration(UpdateCfgCmd cmd) throws InvalidParameterValueException, InternalErrorException;
/** /**
* Creates a new service offering * Creates a new service offering
@ -107,19 +107,17 @@ public interface ConfigurationManager extends Manager {
/** /**
* Updates a disk offering * Updates a disk offering
* @param userId * @param cmd - the command specifying diskOfferingId, name, description, tags
* @param diskOfferingId
* @param name
* @param description
* @param tags
* @return updated disk offering * @return updated disk offering
* @throws InvalidParameterValueException
*/ */
DiskOfferingVO updateDiskOffering(UpdateDiskOfferingCmd cmd) throws InvalidParameterValueException; DiskOfferingVO updateDiskOffering(UpdateDiskOfferingCmd cmd) throws InvalidParameterValueException;
/** /**
* Deletes a disk offering * Deletes a disk offering
* @param userId * @param cmd - the command specifying disk offering id
* @param diskOfferingId * @return true or false
* @throws InvalidParameterValueException
*/ */
boolean deleteDiskOffering(DeleteDiskOfferingCmd cmd) throws InvalidParameterValueException; boolean deleteDiskOffering(DeleteDiskOfferingCmd cmd) throws InvalidParameterValueException;
@ -187,14 +185,15 @@ public interface ConfigurationManager extends Manager {
* @throws InternalErrorException * @throws InternalErrorException
* @throws InvalidParameterValueException * @throws InvalidParameterValueException
*/ */
// HostPodVO editPod(long userId, long podId, String newPodName, String gateway, String cidr, String startIp, String endIp) throws InvalidParameterValueException, InternalErrorException;
HostPodVO editPod(UpdatePodCmd cmd) throws InvalidParameterValueException, InternalErrorException; HostPodVO editPod(UpdatePodCmd cmd) throws InvalidParameterValueException, InternalErrorException;
/** /**
* Deletes a pod from the database. Will not allow you to delete pods that are being used anywhere in the system. * Deletes a pod from the database. Will not allow you to delete pods that are being used anywhere in the system.
* @param userId * @param cmd - the command containing podId
* @param podId * @return true or false
* @throws InvalidParameterValueException, InternalErrorException
*/ */
void deletePod(DeletePodCmd cmd) throws InvalidParameterValueException, InternalErrorException; boolean deletePod(DeletePodCmd cmd) throws InvalidParameterValueException, InternalErrorException;
/** /**
* Creates a new zone * Creates a new zone
@ -308,13 +307,9 @@ public interface ConfigurationManager extends Manager {
/** /**
* Persists a config value via the API call * Persists a config value via the API call
* @param instance * @param cmd - the command that wraps instance, component, category, name, value, description parameters
* @param component * @throws InvalidParameterValueException, InternalErrorException
* @param category * @return true or false
* @param name
* @param value
* @param description
* @return
*/ */
public boolean addConfig(AddConfigCmd cmd); boolean addConfig(AddConfigCmd cmd);
} }

View File

@ -182,11 +182,15 @@ public class ConfigurationManagerImpl implements ConfigurationManager {
saveConfigurationEvent(userId, null, EventTypes.EVENT_CONFIGURATION_VALUE_EDIT, "Successfully edited configuration value.", "name=" + name, "value=" + value); saveConfigurationEvent(userId, null, EventTypes.EVENT_CONFIGURATION_VALUE_EDIT, "Successfully edited configuration value.", "name=" + name, "value=" + value);
} }
public void updateConfiguration(UpdateCfgCmd cmd) throws InvalidParameterValueException, InternalErrorException{ public boolean updateConfiguration(UpdateCfgCmd cmd) throws InvalidParameterValueException, InternalErrorException{
Long userId = UserContext.current().getUserId(); Long userId = UserContext.current().getUserId();
String name = cmd.getName(); String name = cmd.getName();
String value = cmd.getValue(); String value = cmd.getValue();
updateConfiguration (userId, name, value); updateConfiguration (userId, name, value);
if (_configDao.getValue(name).equalsIgnoreCase(value))
return true;
else
return false;
} }
@ -387,7 +391,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager {
} }
@DB @DB
public void deletePod(DeletePodCmd cmd) throws InvalidParameterValueException, InternalErrorException { public boolean deletePod(DeletePodCmd cmd) throws InvalidParameterValueException, InternalErrorException {
Long podId = cmd.getId(); Long podId = cmd.getId();
Long userId = 1L; Long userId = 1L;
@ -403,13 +407,15 @@ public class ConfigurationManagerImpl implements ConfigurationManager {
HostPodVO pod = _podDao.findById(podId); HostPodVO pod = _podDao.findById(podId);
DataCenterVO zone = _zoneDao.findById(pod.getDataCenterId()); DataCenterVO zone = _zoneDao.findById(pod.getDataCenterId());
_podDao.delete(podId);
// Delete private IP addresses in the pod //Delete the pod and private IP addresses in the pod
_privateIpAddressDao.deleteIpAddressByPod(podId); if (_podDao.delete(podId) && _privateIpAddressDao.deleteIpAddressByPod(podId)) {
saveConfigurationEvent(userId, null, EventTypes.EVENT_POD_DELETE, "Successfully deleted pod with name: " + pod.getName() + " in zone: " + zone.getName() + ".", "podId=" + podId, "dcId=" + zone.getId());
saveConfigurationEvent(userId, null, EventTypes.EVENT_POD_DELETE, "Successfully deleted pod with name: " + pod.getName() + " in zone: " + zone.getName() + ".", "podId=" + podId, "dcId=" + zone.getId()); return true;
} else {
return false;
}
} }
@DB @DB

View File

@ -223,8 +223,9 @@ public interface ManagementServer {
* Enables an account by accountId * Enables an account by accountId
* @param cmd - the enableAccount command defining the accountId to be deleted. * @param cmd - the enableAccount command defining the accountId to be deleted.
* @return true if enable was successful, false otherwise * @return true if enable was successful, false otherwise
* @throws InvalidParameterValueException, PermissionDeniedException
*/ */
boolean enableAccount(EnableAccountCmd cmd) throws InvalidParameterValueException; boolean enableAccount(EnableAccountCmd cmd) throws InvalidParameterValueException, PermissionDeniedException;
/** /**
* Locks an account by accountId. A locked account cannot access the API, but will still have running VMs/IP addresses allocated/etc. * Locks an account by accountId. A locked account cannot access the API, but will still have running VMs/IP addresses allocated/etc.
@ -235,18 +236,20 @@ public interface ManagementServer {
/** /**
* Updates an account name * Updates an account name
* @param cmd * @param cmd - the parameter containing accountId
* @return true if update was successful, false otherwise * @return true if update was successful, false otherwise
* @throws InvalidParameterValueException, PermissionDeniedException
*/ */
boolean updateAccount(UpdateAccountCmd cmd) throws InvalidParameterValueException; boolean updateAccount(UpdateAccountCmd cmd) throws InvalidParameterValueException, PermissionDeniedException;
/** /**
* Enables a user * Enables a user
* @param cmd * @param cmd - the command containing userId
* @return true if enable was successful, false otherwise * @return true if enable was successful, false otherwise
* @throws InvalidParameterValueException
*/ */
boolean enableUser(EnableUserCmd cmd) throws InvalidParameterValueException; boolean enableUser(EnableUserCmd cmd) throws InvalidParameterValueException, PermissionDeniedException;
/** /**
* Locks a user by userId. A locked user cannot access the API, but will still have running VMs/IP addresses allocated/etc. * Locks a user by userId. A locked user cannot access the API, but will still have running VMs/IP addresses allocated/etc.

View File

@ -983,7 +983,7 @@ public class ManagementServerImpl implements ManagementServer {
} }
@Override @Override
public boolean enableUser(EnableUserCmd cmd) throws InvalidParameterValueException{ public boolean enableUser(EnableUserCmd cmd) throws InvalidParameterValueException, PermissionDeniedException{
Long userId = cmd.getId(); Long userId = cmd.getId();
Account adminAccount = (Account)UserContext.current().getAccountObject(); Account adminAccount = (Account)UserContext.current().getAccountObject();
boolean success = false; boolean success = false;
@ -1000,7 +1000,7 @@ public class ManagementServerImpl implements ManagementServer {
} }
if ((adminAccount != null) && !isChildDomain(adminAccount.getDomainId(), account.getDomainId())) { if ((adminAccount != null) && !isChildDomain(adminAccount.getDomainId(), account.getDomainId())) {
throw new InvalidParameterValueException("Failed to enable user " + userId + ", permission denied."); throw new PermissionDeniedException("Failed to enable user " + userId + ", permission denied.");
} }
success = doSetUserStatus(userId, Account.ACCOUNT_STATE_ENABLED); success = doSetUserStatus(userId, Account.ACCOUNT_STATE_ENABLED);
@ -1108,7 +1108,7 @@ public class ManagementServerImpl implements ManagementServer {
} }
@Override @Override
public boolean updateAccount(UpdateAccountCmd cmd) throws InvalidParameterValueException{ public boolean updateAccount(UpdateAccountCmd cmd) throws InvalidParameterValueException, PermissionDeniedException{
Long domainId = cmd.getDomainId(); Long domainId = cmd.getDomainId();
String accountName = cmd.getAccountName(); String accountName = cmd.getAccountName();
String newAccountName = cmd.getNewName(); String newAccountName = cmd.getNewName();
@ -1134,7 +1134,7 @@ public class ManagementServerImpl implements ManagementServer {
//Check if user performing the action is allowed to modify this account //Check if user performing the action is allowed to modify this account
Account adminAccount = (Account)UserContext.current().getAccountObject(); Account adminAccount = (Account)UserContext.current().getAccountObject();
if ((adminAccount != null) && isChildDomain(adminAccount.getDomainId(), account.getDomainId())) { if ((adminAccount != null) && isChildDomain(adminAccount.getDomainId(), account.getDomainId())) {
throw new InvalidParameterValueException("Invalid account " + accountName + " in domain " + domainId + " given, unable to update account."); throw new PermissionDeniedException("Invalid account " + accountName + " in domain " + domainId + " given, permission denied");
} }
if (account.getAccountName().equals(accountName)) { if (account.getAccountName().equals(accountName)) {
@ -1177,7 +1177,7 @@ public class ManagementServerImpl implements ManagementServer {
@Override @Override
public boolean enableAccount(EnableAccountCmd cmd) throws InvalidParameterValueException{ public boolean enableAccount(EnableAccountCmd cmd) throws InvalidParameterValueException, PermissionDeniedException{
String accountName = cmd.getAccountName(); String accountName = cmd.getAccountName();
Long domainId = cmd.getDomainId(); Long domainId = cmd.getDomainId();
boolean success = false; boolean success = false;
@ -1188,6 +1188,18 @@ public class ManagementServerImpl implements ManagementServer {
s_logger.error("Unable to find account " + accountName + " in domain " + domainId); s_logger.error("Unable to find account " + accountName + " in domain " + domainId);
throw new InvalidParameterValueException("Unable to find account " + accountName + " in domain " + domainId); throw new InvalidParameterValueException("Unable to find account " + accountName + " in domain " + domainId);
} }
//Don't allow to modify system account
if (account.getId().longValue() == Account.ACCOUNT_ID_SYSTEM) {
throw new InvalidParameterValueException ("Can not modify system account");
}
//Check if user performing the action is allowed to modify this account
Account adminAccount = (Account)UserContext.current().getAccountObject();
if ((adminAccount != null) && isChildDomain(adminAccount.getDomainId(), account.getDomainId())) {
throw new PermissionDeniedException("Invalid account " + accountName + " in domain " + domainId + " given, permission denied");
}
success = enableAccount(account.getId()); success = enableAccount(account.getId());
return success; return success;
} }