From 183eb4e4a33a09424d1b0bbcd64e19d474152f95 Mon Sep 17 00:00:00 2001 From: root Date: Sun, 15 Aug 2010 21:01:24 -0700 Subject: [PATCH] Api refactoring for following commands: updateAccount, updateTemplate/Iso, UpdateDomain, EnableUser/Account, DeletePod --- .../com/cloud/api/commands/AddConfigCmd.java | 5 +- .../api/commands/DeleteDiskOfferingCmd.java | 3 +- .../com/cloud/api/commands/DeletePodCmd.java | 75 ++++----- .../cloud/api/commands/DisableAccountCmd.java | 81 +++++----- .../cloud/api/commands/EnableAccountCmd.java | 11 +- .../com/cloud/api/commands/EnableUserCmd.java | 88 +++++------ .../api/commands/GetCloudIdentifierCmd.java | 46 +++--- .../cloud/api/commands/UpdateAccountCmd.java | 12 +- .../com/cloud/api/commands/UpdateCfgCmd.java | 10 +- .../api/commands/UpdateDiskOfferingCmd.java | 7 +- .../cloud/api/commands/UpdateDomainCmd.java | 112 ++++++------- .../com/cloud/api/commands/UpdateIsoCmd.java | 138 +++++++--------- .../cloud/api/commands/UpdateTemplateCmd.java | 149 ++++++++---------- .../configuration/ConfigurationManager.java | 3 +- .../ConfigurationManagerImpl.java | 11 +- .../com/cloud/server/ManagementServer.java | 34 ++-- .../cloud/server/ManagementServerImpl.java | 123 ++++++++++++--- 17 files changed, 437 insertions(+), 471 deletions(-) diff --git a/server/src/com/cloud/api/commands/AddConfigCmd.java b/server/src/com/cloud/api/commands/AddConfigCmd.java index be279e03025..3058f8f8e16 100644 --- a/server/src/com/cloud/api/commands/AddConfigCmd.java +++ b/server/src/com/cloud/api/commands/AddConfigCmd.java @@ -21,16 +21,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.Parameter; -import com.cloud.api.BaseCmd.Manager; -import com.cloud.configuration.ConfigurationVO; -import com.cloud.storage.DiskOfferingVO; @Implementation(method="addConfig", manager=Manager.ConfigManager) public class AddConfigCmd extends BaseCmd { public static final Logger s_logger = Logger.getLogger(AddConfigCmd.class.getName()); - private static final String s_name = "addconfigresponse"; ///////////////////////////////////////////////////// diff --git a/server/src/com/cloud/api/commands/DeleteDiskOfferingCmd.java b/server/src/com/cloud/api/commands/DeleteDiskOfferingCmd.java index c40ff24bc8e..72953d7d493 100644 --- a/server/src/com/cloud/api/commands/DeleteDiskOfferingCmd.java +++ b/server/src/com/cloud/api/commands/DeleteDiskOfferingCmd.java @@ -21,14 +21,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.Parameter; -import com.cloud.api.BaseCmd.Manager; @Implementation(method="deleteDiskOffering", manager=Manager.ConfigManager) public class DeleteDiskOfferingCmd extends BaseCmd { public static final Logger s_logger = Logger.getLogger(DeleteDiskOfferingCmd.class.getName()); - private static final String s_name = "deletediskofferingresponse"; ///////////////////////////////////////////////////// diff --git a/server/src/com/cloud/api/commands/DeletePodCmd.java b/server/src/com/cloud/api/commands/DeletePodCmd.java index 56c188eba2b..0de49a8b347 100644 --- a/server/src/com/cloud/api/commands/DeletePodCmd.java +++ b/server/src/com/cloud/api/commands/DeletePodCmd.java @@ -18,29 +18,18 @@ package com.cloud.api.commands; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - import org.apache.log4j.Logger; import com.cloud.api.BaseCmd; +import com.cloud.api.BaseCmd.Manager; +import com.cloud.api.Implementation; import com.cloud.api.Parameter; -import com.cloud.api.ServerApiException; -import com.cloud.dc.HostPodVO; -import com.cloud.user.User; -import com.cloud.utils.Pair; +@Implementation(method="deletePod", manager=Manager.ConfigManager) public class DeletePodCmd extends BaseCmd { public static final Logger s_logger = Logger.getLogger(DeletePodCmd.class.getName()); private static final String s_name = "deletepodresponse"; - private static final List> s_properties = new ArrayList>(); - - static { - s_properties.add(new Pair(BaseCmd.Properties.ID, Boolean.TRUE)); - s_properties.add(new Pair(BaseCmd.Properties.USER_ID, Boolean.FALSE)); - } ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// @@ -58,7 +47,6 @@ public class DeletePodCmd extends BaseCmd { return id; } - ///////////////////////////////////////////////////// /////////////// API Implementation/////////////////// ///////////////////////////////////////////////////// @@ -66,35 +54,32 @@ public class DeletePodCmd extends BaseCmd { public String getName() { return s_name; } - public List> getProperties() { - return s_properties; - } - @Override - public List> execute(Map 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> returnValues = new ArrayList>(); - returnValues.add(new Pair(BaseCmd.Properties.SUCCESS.getName(), "true")); - - return returnValues; - } +// @Override +// public List> execute(Map 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> returnValues = new ArrayList>(); +// returnValues.add(new Pair(BaseCmd.Properties.SUCCESS.getName(), "true")); +// +// return returnValues; +// } } diff --git a/server/src/com/cloud/api/commands/DisableAccountCmd.java b/server/src/com/cloud/api/commands/DisableAccountCmd.java index 0c9c5917e3d..10f4bbf45ae 100644 --- a/server/src/com/cloud/api/commands/DisableAccountCmd.java +++ b/server/src/com/cloud/api/commands/DisableAccountCmd.java @@ -18,28 +18,21 @@ package com.cloud.api.commands; -import java.util.ArrayList; import java.util.List; -import java.util.Map; import org.apache.log4j.Logger; import com.cloud.api.BaseCmd; +import com.cloud.api.BaseCmd.Manager; +import com.cloud.api.Implementation; import com.cloud.api.Parameter; -import com.cloud.api.ServerApiException; -import com.cloud.user.Account; import com.cloud.utils.Pair; - + + +@Implementation(method="disableAccount", manager=Manager.ManagementServer) public class DisableAccountCmd extends BaseCmd { public static final Logger s_logger = Logger.getLogger(DisableAccountCmd.class.getName()); private static final String s_name = "disableaccountresponse"; - private static final List> s_properties = new ArrayList>(); - - static { - s_properties.add(new Pair(BaseCmd.Properties.ACCOUNT_OBJ, Boolean.FALSE)); - s_properties.add(new Pair(BaseCmd.Properties.ACCOUNT, Boolean.TRUE)); - s_properties.add(new Pair(BaseCmd.Properties.DOMAIN_ID, Boolean.TRUE)); - } ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// @@ -79,36 +72,36 @@ public class DisableAccountCmd extends BaseCmd { return s_properties; } - @Override - public List> execute(Map 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 disable 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 disable system account"); - } - - long jobId = getManagementServer().disableAccountAsync(account.getId().longValue()); - if (jobId == 0) { - s_logger.warn("Unable to schedule async-job for DisableAccount comamnd"); - } else { - if (s_logger.isDebugEnabled()) - s_logger.debug("DisableAccount command has been accepted, job id: " + jobId); - } - - List> returnValues = new ArrayList>(); - returnValues.add(new Pair(BaseCmd.Properties.JOB_ID.getName(), Long.valueOf(jobId))); - return returnValues; - } +// @Override +// public List> execute(Map 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 disable 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 disable system account"); +// } +// +// long jobId = getManagementServer().disableAccountAsync(account.getId().longValue()); +// if (jobId == 0) { +// s_logger.warn("Unable to schedule async-job for DisableAccount comamnd"); +// } else { +// if (s_logger.isDebugEnabled()) +// s_logger.debug("DisableAccount command has been accepted, job id: " + jobId); +// } +// +// List> returnValues = new ArrayList>(); +// returnValues.add(new Pair(BaseCmd.Properties.JOB_ID.getName(), Long.valueOf(jobId))); +// return returnValues; +// } } diff --git a/server/src/com/cloud/api/commands/EnableAccountCmd.java b/server/src/com/cloud/api/commands/EnableAccountCmd.java index 19a77fe773f..f4951437d8e 100644 --- a/server/src/com/cloud/api/commands/EnableAccountCmd.java +++ b/server/src/com/cloud/api/commands/EnableAccountCmd.java @@ -18,26 +18,17 @@ package com.cloud.api.commands; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - import org.apache.log4j.Logger; import com.cloud.api.BaseCmd; +import com.cloud.api.BaseCmd.Manager; import com.cloud.api.Implementation; import com.cloud.api.Parameter; -import com.cloud.api.ServerApiException; -import com.cloud.api.BaseCmd.Manager; -import com.cloud.user.Account; -import com.cloud.utils.Pair; @Implementation(method="enableAccount", manager=Manager.ManagementServer) public class EnableAccountCmd extends BaseCmd { public static final Logger s_logger = Logger.getLogger(EnableAccountCmd.class.getName()); - private static final String s_name = "enableaccountresponse"; - private static final List> s_properties = new ArrayList>(); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/server/src/com/cloud/api/commands/EnableUserCmd.java b/server/src/com/cloud/api/commands/EnableUserCmd.java index 5ca6fe256e6..240702b3cfd 100644 --- a/server/src/com/cloud/api/commands/EnableUserCmd.java +++ b/server/src/com/cloud/api/commands/EnableUserCmd.java @@ -18,29 +18,20 @@ package com.cloud.api.commands; -import java.util.ArrayList; import java.util.List; -import java.util.Map; import org.apache.log4j.Logger; import com.cloud.api.BaseCmd; +import com.cloud.api.BaseCmd.Manager; +import com.cloud.api.Implementation; import com.cloud.api.Parameter; -import com.cloud.api.ServerApiException; -import com.cloud.user.Account; -import com.cloud.user.User; import com.cloud.utils.Pair; - + +@Implementation(method="enableUser", manager=Manager.ManagementServer) public class EnableUserCmd extends BaseCmd { public static final Logger s_logger = Logger.getLogger(EnableUserCmd.class.getName()); - private static final String s_name = "enableuserresponse"; - private static final List> s_properties = new ArrayList>(); - - static { - s_properties.add(new Pair(BaseCmd.Properties.ACCOUNT_OBJ, Boolean.FALSE)); - s_properties.add(new Pair(BaseCmd.Properties.ID, Boolean.TRUE)); - } ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// @@ -58,7 +49,6 @@ public class EnableUserCmd extends BaseCmd { return id; } - ///////////////////////////////////////////////////// /////////////// API Implementation/////////////////// ///////////////////////////////////////////////////// @@ -73,39 +63,39 @@ public class EnableUserCmd extends BaseCmd { return s_properties; } - @Override - public List> execute(Map 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> returnValues = new ArrayList>(); - returnValues.add(new Pair(BaseCmd.Properties.SUCCESS.getName(), Boolean.valueOf(success).toString())); - return returnValues; - } +// @Override +// public List> execute(Map 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> returnValues = new ArrayList>(); +// returnValues.add(new Pair(BaseCmd.Properties.SUCCESS.getName(), Boolean.valueOf(success).toString())); +// return returnValues; +// } } diff --git a/server/src/com/cloud/api/commands/GetCloudIdentifierCmd.java b/server/src/com/cloud/api/commands/GetCloudIdentifierCmd.java index 37f0be9275e..03fdf9138ae 100644 --- a/server/src/com/cloud/api/commands/GetCloudIdentifierCmd.java +++ b/server/src/com/cloud/api/commands/GetCloudIdentifierCmd.java @@ -18,37 +18,36 @@ package com.cloud.api.commands; -import java.util.ArrayList; import java.util.List; -import java.util.Map; import org.apache.log4j.Logger; import com.cloud.api.BaseCmd; +import com.cloud.api.BaseCmd.Manager; +import com.cloud.api.Implementation; +import com.cloud.api.Parameter; import com.cloud.utils.Pair; +@Implementation(method="getCloudIdentifierResponse", manager=Manager.ManagementServer) public class GetCloudIdentifierCmd extends BaseCmd { public static final Logger s_logger = Logger.getLogger(GetCloudIdentifierCmd.class.getName()); - private static final String s_name = "getcloudidentifierresponse"; - private static final List> s_properties = new ArrayList>(); - - static { - s_properties.add(new Pair(BaseCmd.Properties.USER_ID, Boolean.TRUE)); - } ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// ///////////////////////////////////////////////////// - // none -- a no argument API command + @Parameter(name="userid", type=CommandType.LONG, required=true) + private Long userid; ///////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// ///////////////////////////////////////////////////// - // none -- a no argument API command + public Long getUserId() { + return userid; + } ///////////////////////////////////////////////////// @@ -58,22 +57,19 @@ public class GetCloudIdentifierCmd extends BaseCmd { public String getName() { return s_name; } - public List> getProperties() { - return s_properties; - } - @Override - public List> execute(Map params) { - Long userId = (Long)params.get(BaseCmd.Properties.USER_ID.getName()); - - ArrayList signedResponse = getManagementServer().getCloudIdentifierResponse(userId); - - List> returnValues = new ArrayList>(); - - returnValues.add(new Pair(BaseCmd.Properties.CLOUD_IDENTIFIER.getName(),signedResponse.get(0))); - returnValues.add(new Pair(BaseCmd.Properties.SIGNATURE.getName(),signedResponse.get(1))); - return returnValues; - } +// @Override +// public List> execute(Map params) { +// Long userId = (Long)params.get(BaseCmd.Properties.USER_ID.getName()); +// +// ArrayList signedResponse = getManagementServer().getCloudIdentifierResponse(userId); +// +// List> returnValues = new ArrayList>(); +// +// returnValues.add(new Pair(BaseCmd.Properties.CLOUD_IDENTIFIER.getName(),signedResponse.get(0))); +// returnValues.add(new Pair(BaseCmd.Properties.SIGNATURE.getName(),signedResponse.get(1))); +// return returnValues; +// } } \ No newline at end of file diff --git a/server/src/com/cloud/api/commands/UpdateAccountCmd.java b/server/src/com/cloud/api/commands/UpdateAccountCmd.java index 3b2eaa3b438..c7ddf21778b 100644 --- a/server/src/com/cloud/api/commands/UpdateAccountCmd.java +++ b/server/src/com/cloud/api/commands/UpdateAccountCmd.java @@ -18,26 +18,18 @@ package com.cloud.api.commands; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - import org.apache.log4j.Logger; import com.cloud.api.BaseCmd; +import com.cloud.api.BaseCmd.Manager; import com.cloud.api.Implementation; import com.cloud.api.Parameter; -import com.cloud.api.ServerApiException; -import com.cloud.api.BaseCmd.Manager; -import com.cloud.user.Account; -import com.cloud.utils.Pair; @Implementation(method="updateAccount", manager=Manager.ManagementServer) public class UpdateAccountCmd extends BaseCmd{ public static final Logger s_logger = Logger.getLogger(UpdateAccountCmd.class.getName()); private static final String s_name = "updateaccountresponse"; - private static final List> s_properties = new ArrayList>(); - + ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// ///////////////////////////////////////////////////// diff --git a/server/src/com/cloud/api/commands/UpdateCfgCmd.java b/server/src/com/cloud/api/commands/UpdateCfgCmd.java index e32561dfc34..7d4987723e3 100644 --- a/server/src/com/cloud/api/commands/UpdateCfgCmd.java +++ b/server/src/com/cloud/api/commands/UpdateCfgCmd.java @@ -18,24 +18,16 @@ package com.cloud.api.commands; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - import org.apache.log4j.Logger; import com.cloud.api.BaseCmd; +import com.cloud.api.BaseCmd.Manager; import com.cloud.api.Implementation; import com.cloud.api.Parameter; -import com.cloud.api.ServerApiException; -import com.cloud.api.BaseCmd.Manager; -import com.cloud.user.User; -import com.cloud.utils.Pair; @Implementation(method="updateConfiguration", manager=Manager.ConfigManager) public class UpdateCfgCmd extends BaseCmd { public static final Logger s_logger = Logger.getLogger(UpdateCfgCmd.class.getName()); - private static final String s_name = "updateconfigurationresponse"; ///////////////////////////////////////////////////// diff --git a/server/src/com/cloud/api/commands/UpdateDiskOfferingCmd.java b/server/src/com/cloud/api/commands/UpdateDiskOfferingCmd.java index 416bf4da4f8..07f6a128c2f 100644 --- a/server/src/com/cloud/api/commands/UpdateDiskOfferingCmd.java +++ b/server/src/com/cloud/api/commands/UpdateDiskOfferingCmd.java @@ -17,16 +17,15 @@ */ package com.cloud.api.commands; -import org.apache.log4j.Logger; - - import java.util.Date; +import org.apache.log4j.Logger; + import com.cloud.api.BaseCmd; +import com.cloud.api.BaseCmd.Manager; import com.cloud.api.Implementation; import com.cloud.api.Parameter; import com.cloud.api.ServerApiException; -import com.cloud.api.BaseCmd.Manager; import com.cloud.serializer.Param; import com.cloud.serializer.SerializerHelper; import com.cloud.storage.DiskOfferingVO; diff --git a/server/src/com/cloud/api/commands/UpdateDomainCmd.java b/server/src/com/cloud/api/commands/UpdateDomainCmd.java index dc3ceba3f53..1fa00e23a88 100644 --- a/server/src/com/cloud/api/commands/UpdateDomainCmd.java +++ b/server/src/com/cloud/api/commands/UpdateDomainCmd.java @@ -18,29 +18,17 @@ package com.cloud.api.commands; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - import org.apache.log4j.Logger; import com.cloud.api.BaseCmd; +import com.cloud.api.BaseCmd.Manager; +import com.cloud.api.Implementation; import com.cloud.api.Parameter; -import com.cloud.api.ServerApiException; -import com.cloud.domain.DomainVO; -import com.cloud.user.Account; -import com.cloud.utils.Pair; - + +@Implementation(method="updateDomain", manager=Manager.ManagementServer) public class UpdateDomainCmd extends BaseCmd{ public static final Logger s_logger = Logger.getLogger(UpdateDomainCmd.class.getName()); private static final String s_name = "updatedomainresponse"; - private static final List> s_properties = new ArrayList>(); - - static { - s_properties.add(new Pair(BaseCmd.Properties.ACCOUNT_OBJ, Boolean.FALSE)); - s_properties.add(new Pair(BaseCmd.Properties.ID, Boolean.TRUE)); - s_properties.add(new Pair(BaseCmd.Properties.NAME, Boolean.FALSE)); - } ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// @@ -72,53 +60,49 @@ public class UpdateDomainCmd extends BaseCmd{ public String getName() { return s_name; } - @Override - public List> getProperties() { - return s_properties; - } - @Override - public List> execute(Map 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> returnValues = new ArrayList>(); - if (editDomainResult == true) { - returnValues.add(new Pair(BaseCmd.Properties.SUCCESS.getName(), new Boolean(true))); - } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update domain " + domainId); - } - return returnValues; - } +// @Override +// public List> execute(Map 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> returnValues = new ArrayList>(); +// if (editDomainResult == true) { +// returnValues.add(new Pair(BaseCmd.Properties.SUCCESS.getName(), new Boolean(true))); +// } else { +// throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update domain " + domainId); +// } +// return returnValues; +// } } diff --git a/server/src/com/cloud/api/commands/UpdateIsoCmd.java b/server/src/com/cloud/api/commands/UpdateIsoCmd.java index 098cc4e667e..879050aee90 100644 --- a/server/src/com/cloud/api/commands/UpdateIsoCmd.java +++ b/server/src/com/cloud/api/commands/UpdateIsoCmd.java @@ -18,35 +18,17 @@ package com.cloud.api.commands; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - import org.apache.log4j.Logger; import com.cloud.api.BaseCmd; +import com.cloud.api.BaseCmd.Manager; +import com.cloud.api.Implementation; import com.cloud.api.Parameter; -import com.cloud.api.ServerApiException; -import com.cloud.storage.Storage; -import com.cloud.storage.VMTemplateVO; -import com.cloud.user.Account; -import com.cloud.utils.Pair; - + +@Implementation(method="updateTemplate", manager=Manager.ManagementServer) public class UpdateIsoCmd extends BaseCmd { public static final Logger s_logger = Logger.getLogger(UpdateIsoCmd.class.getName()); - private static final String s_name = "updateisoresponse"; - private static final List> s_properties = new ArrayList>(); - - static { - s_properties.add(new Pair(BaseCmd.Properties.BOOTABLE, Boolean.FALSE)); - s_properties.add(new Pair(BaseCmd.Properties.DISPLAY_TEXT, Boolean.FALSE)); - s_properties.add(new Pair(BaseCmd.Properties.ID, Boolean.TRUE)); - s_properties.add(new Pair(BaseCmd.Properties.NAME, Boolean.FALSE)); - s_properties.add(new Pair(BaseCmd.Properties.OS_TYPE_ID, Boolean.FALSE)); - - s_properties.add(new Pair(BaseCmd.Properties.ACCOUNT_OBJ, Boolean.FALSE)); - } ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// @@ -99,63 +81,59 @@ public class UpdateIsoCmd extends BaseCmd { public String getName() { return s_name; } - @Override - public List> getProperties() { - return s_properties; - } - @Override - public List> execute(Map 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> isoData = new ArrayList>(); - isoData.add(new Pair(BaseCmd.Properties.ID.getName(), updatedIso.getId().toString())); - isoData.add(new Pair(BaseCmd.Properties.NAME.getName(), updatedIso.getName())); - isoData.add(new Pair(BaseCmd.Properties.DISPLAY_TEXT.getName(), updatedIso.getDisplayText())); - isoData.add(new Pair(BaseCmd.Properties.IS_PUBLIC.getName(), Boolean.valueOf(updatedIso.isPublicTemplate()).toString())); - isoData.add(new Pair(BaseCmd.Properties.CREATED.getName(), getDateString(updatedIso.getCreated()))); - isoData.add(new Pair(BaseCmd.Properties.FORMAT.getName(), updatedIso.getFormat())); - isoData.add(new Pair(BaseCmd.Properties.OS_TYPE_ID.getName(), updatedIso.getGuestOSId())); - isoData.add(new Pair(BaseCmd.Properties.BOOTABLE.getName(), updatedIso.isBootable())); - return isoData; - } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "internal error updating ISO"); - } - } +// @Override +// public List> execute(Map 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> isoData = new ArrayList>(); +// isoData.add(new Pair(BaseCmd.Properties.ID.getName(), updatedIso.getId().toString())); +// isoData.add(new Pair(BaseCmd.Properties.NAME.getName(), updatedIso.getName())); +// isoData.add(new Pair(BaseCmd.Properties.DISPLAY_TEXT.getName(), updatedIso.getDisplayText())); +// isoData.add(new Pair(BaseCmd.Properties.IS_PUBLIC.getName(), Boolean.valueOf(updatedIso.isPublicTemplate()).toString())); +// isoData.add(new Pair(BaseCmd.Properties.CREATED.getName(), getDateString(updatedIso.getCreated()))); +// isoData.add(new Pair(BaseCmd.Properties.FORMAT.getName(), updatedIso.getFormat())); +// isoData.add(new Pair(BaseCmd.Properties.OS_TYPE_ID.getName(), updatedIso.getGuestOSId())); +// isoData.add(new Pair(BaseCmd.Properties.BOOTABLE.getName(), updatedIso.isBootable())); +// return isoData; +// } else { +// throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "internal error updating ISO"); +// } +// } } diff --git a/server/src/com/cloud/api/commands/UpdateTemplateCmd.java b/server/src/com/cloud/api/commands/UpdateTemplateCmd.java index 46d5ee9b8f5..d17f9c509b5 100644 --- a/server/src/com/cloud/api/commands/UpdateTemplateCmd.java +++ b/server/src/com/cloud/api/commands/UpdateTemplateCmd.java @@ -18,34 +18,17 @@ package com.cloud.api.commands; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - import org.apache.log4j.Logger; import com.cloud.api.BaseCmd; +import com.cloud.api.BaseCmd.Manager; +import com.cloud.api.Implementation; import com.cloud.api.Parameter; -import com.cloud.api.ServerApiException; -import com.cloud.storage.VMTemplateVO; -import com.cloud.user.Account; -import com.cloud.utils.Pair; - + +@Implementation(method="updateTemplate", manager=Manager.ManagementServer) public class UpdateTemplateCmd extends BaseCmd { public static final Logger s_logger = Logger.getLogger(UpdateTemplateCmd.class.getName()); private static final String s_name = "updatetemplateresponse"; - private static final List> s_properties = new ArrayList>(); - - static { - s_properties.add(new Pair(BaseCmd.Properties.ACCOUNT_OBJ, Boolean.FALSE)); - - s_properties.add(new Pair(BaseCmd.Properties.DISPLAY_TEXT, Boolean.FALSE)); - s_properties.add(new Pair(BaseCmd.Properties.FORMAT, Boolean.FALSE)); - s_properties.add(new Pair(BaseCmd.Properties.ID, Boolean.TRUE)); - s_properties.add(new Pair(BaseCmd.Properties.NAME, Boolean.FALSE)); - s_properties.add(new Pair(BaseCmd.Properties.OS_TYPE_ID, Boolean.FALSE)); - s_properties.add(new Pair(BaseCmd.Properties.PASSWORD_ENABLED, Boolean.FALSE)); - } ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// @@ -96,6 +79,10 @@ public class UpdateTemplateCmd extends BaseCmd { public Boolean isPasswordEnabled() { return passwordEnabled; } + + public Boolean isBootable() { + return true; + } ///////////////////////////////////////////////////// /////////////// API Implementation/////////////////// @@ -105,67 +92,63 @@ public class UpdateTemplateCmd extends BaseCmd { public String getName() { return s_name; } - @Override - public List> getProperties() { - return s_properties; - } - @Override - public List> execute(Map 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> templateData = new ArrayList>(); - templateData.add(new Pair(BaseCmd.Properties.ID.getName(), updatedTemplate.getId().toString())); - templateData.add(new Pair(BaseCmd.Properties.NAME.getName(), updatedTemplate.getName())); - templateData.add(new Pair(BaseCmd.Properties.DISPLAY_TEXT.getName(), updatedTemplate.getDisplayText())); - templateData.add(new Pair(BaseCmd.Properties.IS_PUBLIC.getName(), Boolean.valueOf(updatedTemplate.isPublicTemplate()).toString())); - templateData.add(new Pair(BaseCmd.Properties.CREATED.getName(), getDateString(updatedTemplate.getCreated()))); - templateData.add(new Pair(BaseCmd.Properties.FORMAT.getName(), updatedTemplate.getFormat())); - templateData.add(new Pair(BaseCmd.Properties.OS_TYPE_ID.getName(), updatedTemplate.getGuestOSId())); - templateData.add(new Pair(BaseCmd.Properties.PASSWORD_ENABLED.getName(), updatedTemplate.getEnablePassword())); - templateData.add(new Pair(BaseCmd.Properties.CROSS_ZONES.getName(), Boolean.valueOf(updatedTemplate.isCrossZones()).toString())); - return templateData; - } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "internal error updating template"); - } - } +// @Override +// public List> execute(Map 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> templateData = new ArrayList>(); +// templateData.add(new Pair(BaseCmd.Properties.ID.getName(), updatedTemplate.getId().toString())); +// templateData.add(new Pair(BaseCmd.Properties.NAME.getName(), updatedTemplate.getName())); +// templateData.add(new Pair(BaseCmd.Properties.DISPLAY_TEXT.getName(), updatedTemplate.getDisplayText())); +// templateData.add(new Pair(BaseCmd.Properties.IS_PUBLIC.getName(), Boolean.valueOf(updatedTemplate.isPublicTemplate()).toString())); +// templateData.add(new Pair(BaseCmd.Properties.CREATED.getName(), getDateString(updatedTemplate.getCreated()))); +// templateData.add(new Pair(BaseCmd.Properties.FORMAT.getName(), updatedTemplate.getFormat())); +// templateData.add(new Pair(BaseCmd.Properties.OS_TYPE_ID.getName(), updatedTemplate.getGuestOSId())); +// templateData.add(new Pair(BaseCmd.Properties.PASSWORD_ENABLED.getName(), updatedTemplate.getEnablePassword())); +// templateData.add(new Pair(BaseCmd.Properties.CROSS_ZONES.getName(), Boolean.valueOf(updatedTemplate.isCrossZones()).toString())); +// return templateData; +// } else { +// throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "internal error updating template"); +// } +// } } diff --git a/server/src/com/cloud/configuration/ConfigurationManager.java b/server/src/com/cloud/configuration/ConfigurationManager.java index 156f38c8996..632a47ea6d0 100644 --- a/server/src/com/cloud/configuration/ConfigurationManager.java +++ b/server/src/com/cloud/configuration/ConfigurationManager.java @@ -22,6 +22,7 @@ import java.util.List; import com.cloud.api.commands.AddConfigCmd; import com.cloud.api.commands.CreateDiskOfferingCmd; import com.cloud.api.commands.DeleteDiskOfferingCmd; +import com.cloud.api.commands.DeletePodCmd; import com.cloud.api.commands.UpdateCfgCmd; import com.cloud.api.commands.UpdateDiskOfferingCmd; import com.cloud.api.commands.UpdateZoneCmd; @@ -154,7 +155,7 @@ public interface ConfigurationManager extends Manager { * @param userId * @param podId */ - void deletePod(long userId,long podId) throws InvalidParameterValueException, InternalErrorException; + void deletePod(DeletePodCmd cmd) throws InvalidParameterValueException, InternalErrorException; /** * Creates a new zone diff --git a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java index 28b5901301f..92fa5f10281 100644 --- a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java +++ b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java @@ -36,6 +36,7 @@ import com.cloud.api.ServerApiException; import com.cloud.api.commands.AddConfigCmd; import com.cloud.api.commands.CreateDiskOfferingCmd; import com.cloud.api.commands.DeleteDiskOfferingCmd; +import com.cloud.api.commands.DeletePodCmd; import com.cloud.api.commands.UpdateCfgCmd; import com.cloud.api.commands.UpdateDiskOfferingCmd; import com.cloud.api.commands.UpdateZoneCmd; @@ -161,7 +162,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager { } public void updateConfiguration(UpdateCfgCmd cmd) throws InvalidParameterValueException, InternalErrorException{ - long userId = UserContext.current().getUserId(); + Long userId = UserContext.current().getUserId(); String name = cmd.getName(); String value = cmd.getValue(); updateConfiguration (userId, name, value); @@ -365,7 +366,13 @@ public class ConfigurationManagerImpl implements ConfigurationManager { } @DB - public void deletePod(long userId, long podId) throws InvalidParameterValueException, InternalErrorException { + public void deletePod(DeletePodCmd cmd) throws InvalidParameterValueException, InternalErrorException { + Long podId = cmd.getId(); + Long userId = 1L; + + if (UserContext.current() != null) + userId = UserContext.current().getUserId(); + // Make sure the pod exists if (!validPod(podId)) { throw new InvalidParameterValueException("A pod with ID: " + podId + " does not exist."); diff --git a/server/src/com/cloud/server/ManagementServer.java b/server/src/com/cloud/server/ManagementServer.java index ebc89279714..6b865a4ecf8 100644 --- a/server/src/com/cloud/server/ManagementServer.java +++ b/server/src/com/cloud/server/ManagementServer.java @@ -26,7 +26,11 @@ import java.util.Map; import com.cloud.alert.AlertVO; import com.cloud.api.commands.EnableAccountCmd; +import com.cloud.api.commands.EnableUserCmd; +import com.cloud.api.commands.GetCloudIdentifierCmd; import com.cloud.api.commands.UpdateAccountCmd; +import com.cloud.api.commands.UpdateDomainCmd; +import com.cloud.api.commands.UpdateTemplateCmd; import com.cloud.async.AsyncJobResult; import com.cloud.async.AsyncJobVO; import com.cloud.capacity.CapacityVO; @@ -203,15 +207,7 @@ public interface ManagementServer { * @return true if disable was successful, false otherwise */ boolean disableAccount(long accountId); - long disableAccountAsync(long accountId); - - /** - * Enables an account by accountId - * @param accountId - * @return true if enable was successful, false otherwise - */ - boolean enableAccount(long accountId); - + long disableAccountAsync(long accountId); /** * Enables an account by accountId @@ -241,7 +237,7 @@ public interface ManagementServer { * @param userId * @return true if enable was successful, false otherwise */ - boolean enableUser(long userId); + boolean enableUser(EnableUserCmd cmd) throws InvalidParameterValueException; /** * Locks a user by userId. A locked user cannot access the API, but will still have running VMs/IP addresses allocated/etc. @@ -1020,12 +1016,12 @@ public interface ManagementServer { */ HostPodVO editPod(long userId, long podId, String newPodName, String gateway, String cidr, String startIp, String endIp) throws InvalidParameterValueException, InternalErrorException; - /** - * Deletes a pod from the database - * @param userId - * @param podId - */ - void deletePod(long userId, long podId) throws InvalidParameterValueException, InternalErrorException; +// /** +// * Deletes a pod from the database +// * @param userId +// * @param podId +// */ +// void deletePod(long userId, long podId) throws InvalidParameterValueException, InternalErrorException; /** * Adds a new zone to the database @@ -1171,7 +1167,7 @@ public interface ManagementServer { * @param Boolean bootable * @return success/failure */ - boolean updateTemplate(Long id, String name, String displayText, String format, Long guestOsId, Boolean passwordEnabled, Boolean bootable) throws InvalidParameterValueException; + boolean updateTemplate(UpdateTemplateCmd cmd) throws InvalidParameterValueException; /** * Creates a template by downloading to all zones @@ -1550,7 +1546,7 @@ public interface ManagementServer { * @param domainId the id of the domain to be updated * @param domainName the new name of the domain */ - void updateDomain(Long domainId, String domainName); + void updateDomain(UpdateDomainCmd cmd) throws InvalidParameterValueException; /** * find the domain Id associated with the given account @@ -2048,7 +2044,7 @@ public interface ManagementServer { * @param userId -- id for the user * @return -- ArrayList of */ - ArrayList getCloudIdentifierResponse(long userId); + ArrayList getCloudIdentifierResponse(GetCloudIdentifierCmd cmd) throws InvalidParameterValueException; /** * check if a network security group name in the given account/domain is in use diff --git a/server/src/com/cloud/server/ManagementServerImpl.java b/server/src/com/cloud/server/ManagementServerImpl.java index d6bba466c59..e940caa521d 100755 --- a/server/src/com/cloud/server/ManagementServerImpl.java +++ b/server/src/com/cloud/server/ManagementServerImpl.java @@ -58,6 +58,7 @@ import com.cloud.alert.AlertManager; import com.cloud.alert.AlertVO; import com.cloud.alert.dao.AlertDao; import com.cloud.api.BaseCmd; +import com.cloud.api.ServerApiException; import com.cloud.api.commands.AssociateIPAddrCmd; import com.cloud.api.commands.AuthorizeNetworkGroupIngressCmd; import com.cloud.api.commands.CancelMaintenanceCmd; @@ -71,6 +72,8 @@ import com.cloud.api.commands.DeleteTemplateCmd; import com.cloud.api.commands.DeleteUserCmd; import com.cloud.api.commands.DeployVMCmd; import com.cloud.api.commands.EnableAccountCmd; +import com.cloud.api.commands.EnableUserCmd; +import com.cloud.api.commands.GetCloudIdentifierCmd; import com.cloud.api.commands.PrepareForMaintenanceCmd; import com.cloud.api.commands.PreparePrimaryStorageForMaintenanceCmd; import com.cloud.api.commands.ReconnectHostCmd; @@ -78,6 +81,8 @@ import com.cloud.api.commands.StartRouterCmd; import com.cloud.api.commands.StartSystemVMCmd; import com.cloud.api.commands.StartVMCmd; import com.cloud.api.commands.UpdateAccountCmd; +import com.cloud.api.commands.UpdateDomainCmd; +import com.cloud.api.commands.UpdateTemplateCmd; import com.cloud.api.commands.UpgradeVMCmd; import com.cloud.async.AsyncInstanceCreateStatus; import com.cloud.async.AsyncJobExecutor; @@ -1044,17 +1049,31 @@ public class ManagementServerImpl implements ManagementServer { } @Override - public boolean enableUser(long userId) { + public boolean enableUser(EnableUserCmd cmd) throws InvalidParameterValueException{ + Long userId = cmd.getId(); + Account adminAccount = (Account)UserContext.current().getAccountObject(); boolean success = false; + + //Check if user exists in the system + User user = findUserById(userId); + if ((user == null) || (user.getRemoved() != null)) + throw new InvalidParameterValueException("Unable to find active user by id " + userId); + + // If the user is a System user, return an error + Account account = findAccountById(user.getAccountId()); + if ((account != null) && (account.getId() == Account.ACCOUNT_ID_SYSTEM)) { + throw new InvalidParameterValueException("User id : " + userId + " is a system user, enabling is not allowed"); + } + + if ((adminAccount != null) && !isChildDomain(adminAccount.getDomainId(), account.getDomainId())) { + throw new InvalidParameterValueException("Failed to enable user " + userId + ", permission denied."); + } + success = doSetUserStatus(userId, Account.ACCOUNT_STATE_ENABLED); // make sure the account is enabled too - UserVO user = _userDao.findById(userId); - if (user != null) { - success = (success && enableAccount(user.getAccountId())); - } else { - s_logger.warn("Unable to find user with id: " + userId); - } + success = (success && enableAccount(user.getAccountId())); + return success; } @@ -1198,7 +1217,6 @@ public class ManagementServerImpl implements ManagementServer { return success; } - @Override public boolean enableAccount(long accountId) { boolean success = false; AccountVO acctForUpdate = _accountDao.createForUpdate(); @@ -4270,10 +4288,10 @@ public class ManagementServerImpl implements ManagementServer { return _configMgr.editPod(userId, podId, newPodName, gateway, cidr, startIp, endIp); } - @Override - public void deletePod(long userId, long podId) throws InvalidParameterValueException, InternalErrorException { - _configMgr.deletePod(userId, podId); - } +// @Override +// public void deletePod(long userId, long podId) throws InvalidParameterValueException, InternalErrorException { +// _configMgr.deletePod(userId, podId); +// } @Override public DataCenterVO createZone(long userId, String zoneName, String dns1, String dns2, String internalDns1, String internalDns2, String vnetRange,String guestCidr) throws InvalidParameterValueException, InternalErrorException { @@ -4716,13 +4734,49 @@ public class ManagementServerImpl implements ManagementServer { } @Override - public boolean updateTemplate(Long id, String name, String displayText, String format, Long guestOSId, Boolean passwordEnabled, Boolean bootable) throws InvalidParameterValueException { + public boolean updateTemplate(UpdateTemplateCmd cmd) throws InvalidParameterValueException { + Long id = cmd.getId(); + String name = cmd.getName(); + String displayText = cmd.getDisplayText(); + String format = cmd.getFormat(); + Long guestOSId = cmd.getOsTypeId(); + Boolean passwordEnabled = cmd.isPasswordEnabled(); + Boolean bootable = cmd.isBootable(); + Account account= (Account)UserContext.current().getAccountObject(); + + //verify that template exists + VMTemplateVO template = findTemplateById(id); + if (template == null) { + throw new InvalidParameterValueException("unable to find template 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); + } + + //do a permission check + if (account != null) { + 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); + } + } 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); + } + } + } + + boolean updateNeeded = !(name == null && displayText == null && format == null && guestOSId == null && passwordEnabled == null && bootable == null); if (!updateNeeded) { return true; } - VMTemplateVO template = _templateDao.createForUpdate(id); + template = _templateDao.createForUpdate(id); if (name != null) { template.setName(name); @@ -6299,16 +6353,39 @@ public class ManagementServerImpl implements ManagementServer { return success && deleteDomainSuccess; } - public void updateDomain(Long domainId, String domainName) { + public void updateDomain(UpdateDomainCmd cmd) throws InvalidParameterValueException{ + Long domainId = cmd.getId(); + String domainName = cmd.getName(); + + //check if domain exists in the system + DomainVO domain = findDomainIdById(domainId); + if (domain == null) { + throw new InvalidParameterValueException("Unable to find domain " + domainId); + } else if (domain.getParent() == null) { + //check if domain is ROOT domain - and deny to edit it + throw new InvalidParameterValueException("ROOT domain can not be edited"); + } + + // 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"); + } + + if (domainName == null) { + domainName = domain.getName(); + } + + SearchCriteria sc = _domainDao.createSearchCriteria(); sc.addAnd("name", SearchCriteria.Op.EQ, domainName); List domains = _domainDao.search(sc, null); if ((domains == null) || domains.isEmpty()) { _domainDao.update(domainId, domainName); - DomainVO domain = _domainDao.findById(domainId); + domain = _domainDao.findById(domainId); EventUtils.saveEvent(new Long(1), domain.getOwner(), EventVO.LEVEL_INFO, EventTypes.EVENT_DOMAIN_UPDATE, "Domain, " + domainName + " was updated"); } else { - DomainVO domain = _domainDao.findById(domainId); + 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."); } } @@ -8020,8 +8097,14 @@ public class ManagementServerImpl implements ManagementServer { return null; } - public ArrayList getCloudIdentifierResponse(long userId) - { + public ArrayList getCloudIdentifierResponse(GetCloudIdentifierCmd cmd) throws InvalidParameterValueException{ + Long userId = cmd.getUserId(); + + //verify that user exists + User user = findUserById(userId); + if ((user == null) || (user.getRemoved() != null)) + throw new InvalidParameterValueException("Unable to find active user by id " + userId); + Criteria c = new Criteria (); c.addCriteria(Criteria.NAME, "cloud.identifier"); @@ -8037,7 +8120,7 @@ public class ManagementServerImpl implements ManagementServer { String signature = ""; try { //get the user obj to get his secret key - User user = getUser(userId); + user = getUser(userId); String secretKey = user.getSecretKey(); String input = cloudIdentifier; signature = signRequest(input, secretKey);