diff --git a/server/src/com/cloud/api/commands/EnableAccountCmd.java b/server/src/com/cloud/api/commands/EnableAccountCmd.java index fa35b18f47f..19a77fe773f 100644 --- a/server/src/com/cloud/api/commands/EnableAccountCmd.java +++ b/server/src/com/cloud/api/commands/EnableAccountCmd.java @@ -25,23 +25,20 @@ import java.util.Map; import org.apache.log4j.Logger; import com.cloud.api.BaseCmd; +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>(); - 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 ///////////////////// ///////////////////////////////////////////////////// @@ -75,41 +72,36 @@ public class EnableAccountCmd extends BaseCmd { return s_name; } - @Override - public List> getProperties() { - 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 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> 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 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> returnValues = new ArrayList>(); +// returnValues.add(new Pair(BaseCmd.Properties.SUCCESS.getName(), Boolean.valueOf(success).toString())); +// return returnValues; +// } } diff --git a/server/src/com/cloud/server/ManagementServer.java b/server/src/com/cloud/server/ManagementServer.java index 7006d6d6778..ebc89279714 100644 --- a/server/src/com/cloud/server/ManagementServer.java +++ b/server/src/com/cloud/server/ManagementServer.java @@ -25,6 +25,7 @@ import java.util.List; import java.util.Map; import com.cloud.alert.AlertVO; +import com.cloud.api.commands.EnableAccountCmd; import com.cloud.api.commands.UpdateAccountCmd; import com.cloud.async.AsyncJobResult; import com.cloud.async.AsyncJobVO; @@ -210,6 +211,14 @@ public interface ManagementServer { * @return true if enable was successful, false otherwise */ boolean enableAccount(long accountId); + + + /** + * Enables an account by accountId + * @param accountId + * @return true if enable was successful, false otherwise + */ + boolean enableAccount(EnableAccountCmd cmd) throws InvalidParameterValueException; /** * Locks an account by accountId. A locked account cannot access the API, but will still have running VMs/IP addresses allocated/etc. diff --git a/server/src/com/cloud/server/ManagementServerImpl.java b/server/src/com/cloud/server/ManagementServerImpl.java index dc8da78174c..d6bba466c59 100755 --- a/server/src/com/cloud/server/ManagementServerImpl.java +++ b/server/src/com/cloud/server/ManagementServerImpl.java @@ -70,6 +70,7 @@ import com.cloud.api.commands.DeleteIsoCmd; 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.PrepareForMaintenanceCmd; import com.cloud.api.commands.PreparePrimaryStorageForMaintenanceCmd; import com.cloud.api.commands.ReconnectHostCmd; @@ -1205,6 +1206,23 @@ public class ManagementServerImpl implements ManagementServer { success = _accountDao.update(Long.valueOf(accountId), acctForUpdate); return success; } + + + @Override + public boolean enableAccount(EnableAccountCmd cmd) throws InvalidParameterValueException{ + String accountName = cmd.getAccountName(); + Long domainId = cmd.getDomainId(); + boolean success = false; + Account account = _accountDao.findActiveAccount(accountName, domainId); + + //Check if account exists + if (account == null) { + s_logger.error("Unable to find account " + accountName + " in domain " + domainId); + throw new InvalidParameterValueException("Unable to find account " + accountName + " in domain " + domainId); + } + success = enableAccount(account.getId()); + return success; + } @Override public boolean lockAccount(long accountId) {