mirror of
https://github.com/apache/cloudstack.git
synced 2025-12-16 02:22:52 +01:00
Refactoring addConfig/deleteDiskOffering/deletePod/getCloudIdentifier/enableAccount/enableUser/enableAccount/updateUser/updateDiskOffering/updateConfig commands to new API framework
This commit is contained in:
parent
dc6e07ad75
commit
b49f63c28e
@ -25,6 +25,10 @@ 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.ConfigurationResponse;
|
||||
import com.cloud.configuration.ConfigurationVO;
|
||||
import com.cloud.serializer.SerializerHelper;
|
||||
|
||||
@Implementation(method="addConfig", manager=Manager.ConfigManager)
|
||||
public class AddConfigCmd extends BaseCmd {
|
||||
@ -92,35 +96,19 @@ public class AddConfigCmd extends BaseCmd {
|
||||
public String getName() {
|
||||
return s_name;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@Override
|
||||
public List<Pair<String, Object>> execute(Map<String, Object> params) {
|
||||
String instance = (String) params.get(BaseCmd.Properties.INSTANCE.getName());
|
||||
String component = (String) params.get(BaseCmd.Properties.COMPONENT.getName());
|
||||
String category = (String) params.get(BaseCmd.Properties.CATEGORY.getName());
|
||||
String name = (String) params.get(BaseCmd.Properties.NAME.getName());
|
||||
String value = (String) params.get(BaseCmd.Properties.VALUE.getName());
|
||||
String description = (String) params.get(BaseCmd.Properties.DESCRIPTION.getName());
|
||||
|
||||
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());
|
||||
}
|
||||
public String getResponse() {
|
||||
ConfigurationResponse response = new ConfigurationResponse();
|
||||
ConfigurationVO responseObject = (ConfigurationVO)getResponseObject();
|
||||
if (responseObject != null) {
|
||||
response.setName(responseObject.getName());
|
||||
response.setValue(responseObject.getValue());
|
||||
//TODO - return description and category if needed (didn't return in 2.1 release)
|
||||
|
||||
} else {
|
||||
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to add config");
|
||||
}
|
||||
return SerializerHelper.toSerializedString(responseObject);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
@ -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="deleteDiskOffering", manager=Manager.ConfigManager)
|
||||
public class DeleteDiskOfferingCmd extends BaseCmd {
|
||||
@ -58,8 +61,14 @@ public class DeleteDiskOfferingCmd extends BaseCmd {
|
||||
|
||||
@Override
|
||||
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.
|
||||
// Seems like we should return success/true as the response though, so this will probably have to change.
|
||||
return null;
|
||||
SuccessResponse response = new SuccessResponse();
|
||||
Boolean responseObject = (Boolean)getResponseObject();
|
||||
|
||||
if (responseObject != null) {
|
||||
response.setSuccess(responseObject);
|
||||
} else {
|
||||
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete disk offering");
|
||||
}
|
||||
return SerializerHelper.toSerializedString(responseObject);
|
||||
}
|
||||
}
|
||||
|
||||
@ -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="deletePod", manager=Manager.ConfigManager)
|
||||
public class DeletePodCmd extends BaseCmd {
|
||||
@ -54,32 +57,17 @@ public class DeletePodCmd extends BaseCmd {
|
||||
public String getName() {
|
||||
return s_name;
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public List<Pair<String, Object>> execute(Map<String, Object> params) {
|
||||
// Long podId = (Long) params.get(BaseCmd.Properties.ID.getName());
|
||||
// Long userId = (Long)params.get(BaseCmd.Properties.USER_ID.getName());
|
||||
//
|
||||
// if (userId == null) {
|
||||
// userId = Long.valueOf(User.UID_SYSTEM);
|
||||
// }
|
||||
//
|
||||
// //verify parameters
|
||||
// HostPodVO pod = getManagementServer().findHostPodById(podId);
|
||||
// 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;
|
||||
// }
|
||||
|
||||
@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 pod");
|
||||
}
|
||||
return SerializerHelper.toSerializedString(responseObject);
|
||||
}
|
||||
}
|
||||
|
||||
@ -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="enableAccount", manager=Manager.ManagementServer)
|
||||
public class EnableAccountCmd extends BaseCmd {
|
||||
@ -63,36 +66,16 @@ public class EnableAccountCmd extends BaseCmd {
|
||||
return s_name;
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public List<Pair<String, Object>> execute(Map<String, Object> params) {
|
||||
// Account adminAccount = (Account)params.get(BaseCmd.Properties.ACCOUNT_OBJ.getName());
|
||||
// Long domainId = (Long)params.get(BaseCmd.Properties.DOMAIN_ID.getName());
|
||||
// String accountName = (String)params.get(BaseCmd.Properties.ACCOUNT.getName());
|
||||
//
|
||||
// if ((adminAccount != null) && !getManagementServer().isChildDomain(adminAccount.getDomainId(), domainId)) {
|
||||
// throw new ServerApiException(BaseCmd.ACCOUNT_ERROR, "Failed to enable account " + accountName + " in domain " + domainId + ", permission denied.");
|
||||
// }
|
||||
//
|
||||
// Account account = getManagementServer().findActiveAccount(accountName, domainId);
|
||||
// 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;
|
||||
// }
|
||||
@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 account");
|
||||
}
|
||||
return SerializerHelper.toSerializedString(responseObject);
|
||||
}
|
||||
}
|
||||
|
||||
@ -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="enableUser", manager=Manager.ManagementServer)
|
||||
public class EnableUserCmd extends BaseCmd {
|
||||
@ -53,42 +56,18 @@ public class EnableUserCmd 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 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;
|
||||
// }
|
||||
}
|
||||
|
||||
@ -18,12 +18,17 @@
|
||||
|
||||
package com.cloud.api.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
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.api.response.CloudIdentifierResponse;
|
||||
import com.cloud.serializer.SerializerHelper;
|
||||
|
||||
@Implementation(method="getCloudIdentifierResponse", manager=Manager.ManagementServer)
|
||||
public class GetCloudIdentifierCmd extends BaseCmd {
|
||||
@ -54,19 +59,18 @@ public class GetCloudIdentifierCmd extends BaseCmd {
|
||||
public String getName() {
|
||||
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);
|
||||
}
|
||||
}
|
||||
@ -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="updateAccount", manager=Manager.ManagementServer)
|
||||
public class UpdateAccountCmd extends BaseCmd{
|
||||
@ -67,48 +70,17 @@ public class UpdateAccountCmd extends BaseCmd{
|
||||
public String getName() {
|
||||
return s_name;
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public List<Pair<String, Object>> execute(Map<String, Object> params) {
|
||||
// Long domainId = (Long)params.get(BaseCmd.Properties.DOMAIN_ID.getName());
|
||||
// String accountName = (String)params.get(BaseCmd.Properties.ACCOUNT.getName());
|
||||
// String newAccountName = (String)params.get(BaseCmd.Properties.NEW_NAME.getName());
|
||||
// Account adminAccount = (Account)params.get(BaseCmd.Properties.ACCOUNT_OBJ.getName());;
|
||||
// Boolean updateAccountResult = false;
|
||||
// Account account = null;
|
||||
//
|
||||
// // check if account exists in the system
|
||||
// account = getManagementServer().findAccountByName(accountName, domainId);
|
||||
// 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;
|
||||
// }
|
||||
|
||||
@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 account");
|
||||
}
|
||||
return SerializerHelper.toSerializedString(responseObject);
|
||||
}
|
||||
}
|
||||
|
||||
@ -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="updateConfiguration", manager=Manager.ConfigManager)
|
||||
public class UpdateCfgCmd extends BaseCmd {
|
||||
@ -59,27 +62,17 @@ public class UpdateCfgCmd extends BaseCmd {
|
||||
public String getName() {
|
||||
return s_name;
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public List<Pair<String, Object>> execute(Map<String, Object> params) {
|
||||
// String name = (String) params.get(BaseCmd.Properties.NAME.getName());
|
||||
// String value = (String) params.get(BaseCmd.Properties.VALUE.getName());
|
||||
// Long userId = (Long)params.get(BaseCmd.Properties.USER_ID.getName());
|
||||
//
|
||||
// if (userId == null) {
|
||||
// userId = Long.valueOf(User.UID_SYSTEM);
|
||||
// }
|
||||
//
|
||||
// try {
|
||||
// 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;
|
||||
// }
|
||||
|
||||
@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 config");
|
||||
}
|
||||
return SerializerHelper.toSerializedString(responseObject);
|
||||
}
|
||||
}
|
||||
|
||||
@ -17,8 +17,6 @@
|
||||
*/
|
||||
|
||||
package com.cloud.api.commands;
|
||||
import java.util.Date;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.api.BaseCmd;
|
||||
@ -26,7 +24,7 @@ import com.cloud.api.BaseCmd.Manager;
|
||||
import com.cloud.api.Implementation;
|
||||
import com.cloud.api.Parameter;
|
||||
import com.cloud.api.ServerApiException;
|
||||
import com.cloud.serializer.Param;
|
||||
import com.cloud.api.response.DiskOfferingResponse;
|
||||
import com.cloud.serializer.SerializerHelper;
|
||||
import com.cloud.storage.DiskOfferingVO;
|
||||
|
||||
@ -91,109 +89,14 @@ public class UpdateDiskOfferingCmd extends BaseCmd{
|
||||
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());
|
||||
// FIXME: domain name in the response
|
||||
// response.setDomain(responseObject.getDomain());
|
||||
} else {
|
||||
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update disk offering");
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
18
server/src/com/cloud/api/response/SuccessResponse.java
Normal file
18
server/src/com/cloud/api/response/SuccessResponse.java
Normal 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;
|
||||
}
|
||||
|
||||
}
|
||||
@ -63,11 +63,11 @@ public interface ConfigurationManager extends Manager {
|
||||
|
||||
/**
|
||||
* Updates a configuration entry with a new value
|
||||
* @param userId
|
||||
* @param name
|
||||
* @param value
|
||||
* @param cmd - the command wrapping name and value parameters
|
||||
* @return true or false
|
||||
* @throws InvalidParameterValueException, InternalErrorException
|
||||
*/
|
||||
void updateConfiguration(UpdateCfgCmd cmd) throws InvalidParameterValueException, InternalErrorException;
|
||||
boolean updateConfiguration(UpdateCfgCmd cmd) throws InvalidParameterValueException, InternalErrorException;
|
||||
|
||||
/**
|
||||
* Creates a new service offering
|
||||
@ -107,19 +107,17 @@ public interface ConfigurationManager extends Manager {
|
||||
|
||||
/**
|
||||
* Updates a disk offering
|
||||
* @param userId
|
||||
* @param diskOfferingId
|
||||
* @param name
|
||||
* @param description
|
||||
* @param tags
|
||||
* @param cmd - the command specifying diskOfferingId, name, description, tags
|
||||
* @return updated disk offering
|
||||
* @throws InvalidParameterValueException
|
||||
*/
|
||||
DiskOfferingVO updateDiskOffering(UpdateDiskOfferingCmd cmd) throws InvalidParameterValueException;
|
||||
|
||||
/**
|
||||
* Deletes a disk offering
|
||||
* @param userId
|
||||
* @param diskOfferingId
|
||||
* @param cmd - the command specifying disk offering id
|
||||
* @return true or false
|
||||
* @throws InvalidParameterValueException
|
||||
*/
|
||||
boolean deleteDiskOffering(DeleteDiskOfferingCmd cmd) throws InvalidParameterValueException;
|
||||
|
||||
@ -187,14 +185,15 @@ public interface ConfigurationManager extends Manager {
|
||||
* @throws InternalErrorException
|
||||
* @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;
|
||||
|
||||
/**
|
||||
* Deletes a pod from the database. Will not allow you to delete pods that are being used anywhere in the system.
|
||||
* @param userId
|
||||
* @param podId
|
||||
* @param cmd - the command containing 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
|
||||
@ -308,13 +307,9 @@ public interface ConfigurationManager extends Manager {
|
||||
|
||||
/**
|
||||
* Persists a config value via the API call
|
||||
* @param instance
|
||||
* @param component
|
||||
* @param category
|
||||
* @param name
|
||||
* @param value
|
||||
* @param description
|
||||
* @return
|
||||
* @param cmd - the command that wraps instance, component, category, name, value, description parameters
|
||||
* @throws InvalidParameterValueException, InternalErrorException
|
||||
* @return true or false
|
||||
*/
|
||||
public boolean addConfig(AddConfigCmd cmd);
|
||||
boolean addConfig(AddConfigCmd cmd);
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
public void updateConfiguration(UpdateCfgCmd cmd) throws InvalidParameterValueException, InternalErrorException{
|
||||
public boolean updateConfiguration(UpdateCfgCmd cmd) throws InvalidParameterValueException, InternalErrorException{
|
||||
Long userId = UserContext.current().getUserId();
|
||||
String name = cmd.getName();
|
||||
String value = cmd.getValue();
|
||||
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
|
||||
public void deletePod(DeletePodCmd cmd) throws InvalidParameterValueException, InternalErrorException {
|
||||
public boolean deletePod(DeletePodCmd cmd) throws InvalidParameterValueException, InternalErrorException {
|
||||
Long podId = cmd.getId();
|
||||
Long userId = 1L;
|
||||
|
||||
@ -403,13 +407,15 @@ public class ConfigurationManagerImpl implements ConfigurationManager {
|
||||
|
||||
HostPodVO pod = _podDao.findById(podId);
|
||||
DataCenterVO zone = _zoneDao.findById(pod.getDataCenterId());
|
||||
|
||||
_podDao.delete(podId);
|
||||
|
||||
// Delete private IP addresses in the pod
|
||||
_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());
|
||||
//Delete the pod and private IP addresses in the pod
|
||||
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());
|
||||
return true;
|
||||
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@DB
|
||||
|
||||
@ -223,8 +223,9 @@ public interface ManagementServer {
|
||||
* Enables an account by accountId
|
||||
* @param cmd - the enableAccount command defining the accountId to be deleted.
|
||||
* @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.
|
||||
@ -235,18 +236,20 @@ public interface ManagementServer {
|
||||
|
||||
/**
|
||||
* Updates an account name
|
||||
* @param cmd
|
||||
* @param cmd - the parameter containing accountId
|
||||
* @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
|
||||
* @param cmd
|
||||
* @param cmd - the command containing userId
|
||||
* @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.
|
||||
|
||||
@ -983,7 +983,7 @@ public class ManagementServerImpl implements ManagementServer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean enableUser(EnableUserCmd cmd) throws InvalidParameterValueException{
|
||||
public boolean enableUser(EnableUserCmd cmd) throws InvalidParameterValueException, PermissionDeniedException{
|
||||
Long userId = cmd.getId();
|
||||
Account adminAccount = (Account)UserContext.current().getAccountObject();
|
||||
boolean success = false;
|
||||
@ -1000,7 +1000,7 @@ public class ManagementServerImpl implements ManagementServer {
|
||||
}
|
||||
|
||||
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);
|
||||
@ -1108,7 +1108,7 @@ public class ManagementServerImpl implements ManagementServer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateAccount(UpdateAccountCmd cmd) throws InvalidParameterValueException{
|
||||
public boolean updateAccount(UpdateAccountCmd cmd) throws InvalidParameterValueException, PermissionDeniedException{
|
||||
Long domainId = cmd.getDomainId();
|
||||
String accountName = cmd.getAccountName();
|
||||
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
|
||||
Account adminAccount = (Account)UserContext.current().getAccountObject();
|
||||
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)) {
|
||||
@ -1177,7 +1177,7 @@ public class ManagementServerImpl implements ManagementServer {
|
||||
|
||||
|
||||
@Override
|
||||
public boolean enableAccount(EnableAccountCmd cmd) throws InvalidParameterValueException{
|
||||
public boolean enableAccount(EnableAccountCmd cmd) throws InvalidParameterValueException, PermissionDeniedException{
|
||||
String accountName = cmd.getAccountName();
|
||||
Long domainId = cmd.getDomainId();
|
||||
boolean success = false;
|
||||
@ -1188,6 +1188,18 @@ public class ManagementServerImpl implements ManagementServer {
|
||||
s_logger.error("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());
|
||||
return success;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user