Api refactoring for following commands: updateAccount, updateTemplate/Iso, UpdateDomain, EnableUser/Account, DeletePod

This commit is contained in:
root 2010-08-15 21:01:24 -07:00
parent b4adabe4a9
commit 183eb4e4a3
17 changed files with 437 additions and 471 deletions

View File

@ -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";
/////////////////////////////////////////////////////

View File

@ -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";
/////////////////////////////////////////////////////

View File

@ -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<Pair<Enum, Boolean>> s_properties = new ArrayList<Pair<Enum, Boolean>>();
static {
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.ID, Boolean.TRUE));
s_properties.add(new Pair<Enum, Boolean>(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<Pair<Enum, Boolean>> getProperties() {
return s_properties;
}
@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 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;
// }
}

View File

@ -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<Pair<Enum, Boolean>> s_properties = new ArrayList<Pair<Enum, Boolean>>();
static {
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.ACCOUNT_OBJ, Boolean.FALSE));
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.ACCOUNT, Boolean.TRUE));
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.DOMAIN_ID, Boolean.TRUE));
}
/////////////////////////////////////////////////////
//////////////// API parameters /////////////////////
@ -79,36 +72,36 @@ public class DisableAccountCmd extends BaseCmd {
return s_properties;
}
@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 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<Pair<String, Object>> returnValues = new ArrayList<Pair<String, Object>>();
returnValues.add(new Pair<String, Object>(BaseCmd.Properties.JOB_ID.getName(), Long.valueOf(jobId)));
return returnValues;
}
// @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 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<Pair<String, Object>> returnValues = new ArrayList<Pair<String, Object>>();
// returnValues.add(new Pair<String, Object>(BaseCmd.Properties.JOB_ID.getName(), Long.valueOf(jobId)));
// return returnValues;
// }
}

View File

@ -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<Pair<Enum, Boolean>> s_properties = new ArrayList<Pair<Enum, Boolean>>();
/////////////////////////////////////////////////////
//////////////// API parameters /////////////////////

View File

@ -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<Pair<Enum, Boolean>> s_properties = new ArrayList<Pair<Enum, Boolean>>();
static {
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.ACCOUNT_OBJ, Boolean.FALSE));
s_properties.add(new Pair<Enum, Boolean>(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<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;
}
// @Override
// public List<Pair<String, Object>> execute(Map<String, Object> params) {
// Account adminAccount = (Account)params.get(BaseCmd.Properties.ACCOUNT_OBJ.getName());
// Long id = (Long)params.get(BaseCmd.Properties.ID.getName());
//
// // Check if user with id exists in the system
// User user = getManagementServer().findUserById(id);
// if (user == null) {
// throw new ServerApiException(BaseCmd.ACCOUNT_ERROR, "Unable to find user by id");
// } else if (user.getRemoved() != null) {
// throw new ServerApiException(BaseCmd.ACCOUNT_ERROR, "Unable to find user by id");
// }
//
// // If the user is a System user, return an error. We do not allow this
// Account account = getManagementServer().findAccountById(user.getAccountId());
// if ((account != null) && (account.getId() == Account.ACCOUNT_ID_SYSTEM)) {
// throw new ServerApiException(BaseCmd.ACCOUNT_ERROR, "user id : " + id + " is a system user, enabling is not allowed");
// }
//
// if ((adminAccount != null) && !getManagementServer().isChildDomain(adminAccount.getDomainId(), account.getDomainId())) {
// throw new ServerApiException(BaseCmd.ACCOUNT_ERROR, "Failed to enable user " + id + ", permission denied.");
// }
//
// boolean success = true;
// try {
// success = getManagementServer().enableUser(id.longValue());
// } catch (Exception ex) {
// s_logger.error("error enabling user with id: " + id, ex);
// success = false;
// }
//
// List<Pair<String, Object>> returnValues = new ArrayList<Pair<String, Object>>();
// returnValues.add(new Pair<String, Object>(BaseCmd.Properties.SUCCESS.getName(), Boolean.valueOf(success).toString()));
// return returnValues;
// }
}

View File

@ -18,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<Pair<Enum, Boolean>> s_properties = new ArrayList<Pair<Enum, Boolean>>();
static {
s_properties.add(new Pair<Enum, Boolean>(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<Pair<Enum, Boolean>> getProperties() {
return s_properties;
}
@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 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;
// }
}

View File

@ -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<Pair<Enum, Boolean>> s_properties = new ArrayList<Pair<Enum, Boolean>>();
/////////////////////////////////////////////////////
//////////////// API parameters /////////////////////
/////////////////////////////////////////////////////

View File

@ -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";
/////////////////////////////////////////////////////

View File

@ -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;

View File

@ -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<Pair<Enum, Boolean>> s_properties = new ArrayList<Pair<Enum, Boolean>>();
static {
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.ACCOUNT_OBJ, Boolean.FALSE));
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.ID, Boolean.TRUE));
s_properties.add(new Pair<Enum, Boolean>(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<Pair<Enum, Boolean>> getProperties() {
return s_properties;
}
@Override
public List<Pair<String, Object>> execute(Map<String, Object> params) {
Account account = (Account)params.get(BaseCmd.Properties.ACCOUNT_OBJ.getName());
Long domainId = (Long)params.get(BaseCmd.Properties.ID.getName());
String newName = (String)params.get(BaseCmd.Properties.NAME.getName());
Boolean editDomainResult = false;
//check if domain exists in the system
DomainVO domain = getManagementServer().findDomainIdById(domainId);
if (domain == null) {
throw new ServerApiException(BaseCmd.PARAM_ERROR, "unable to find domain " + domainId);
} else if (domain.getParent() == null) {
//check if domain is ROOT domain - and deny to edit it
throw new ServerApiException(BaseCmd.PARAM_ERROR, "ROOT domain can not be edited");
}
// check permissions
if ((account != null) && !getManagementServer().isChildDomain(account.getDomainId(), domain.getId())) {
throw new ServerApiException(BaseCmd.ACCOUNT_ERROR, "Unable to update domain " + domainId + ", permission denied");
}
if (newName == null) {
newName = domain.getName();
}
try {
getManagementServer().updateDomain(domainId, newName);
domain = getManagementServer().findDomainIdById(domainId);
if (domain.getName().equals(newName)) {
editDomainResult = true;
}
} catch (Exception ex) {
s_logger.error("Exception editing domain", ex);
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update domain " + domainId + ": internal error.");
}
List<Pair<String, Object>> returnValues = new ArrayList<Pair<String, Object>>();
if (editDomainResult == true) {
returnValues.add(new Pair<String, Object>(BaseCmd.Properties.SUCCESS.getName(), new Boolean(true)));
} else {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update domain " + domainId);
}
return returnValues;
}
// @Override
// public List<Pair<String, Object>> execute(Map<String, Object> params) {
// Account account = (Account)params.get(BaseCmd.Properties.ACCOUNT_OBJ.getName());
// Long domainId = (Long)params.get(BaseCmd.Properties.ID.getName());
// String newName = (String)params.get(BaseCmd.Properties.NAME.getName());
// Boolean editDomainResult = false;
//
// //check if domain exists in the system
// DomainVO domain = getManagementServer().findDomainIdById(domainId);
// if (domain == null) {
// throw new ServerApiException(BaseCmd.PARAM_ERROR, "unable to find domain " + domainId);
// } else if (domain.getParent() == null) {
// //check if domain is ROOT domain - and deny to edit it
// throw new ServerApiException(BaseCmd.PARAM_ERROR, "ROOT domain can not be edited");
// }
//
// // check permissions
// if ((account != null) && !getManagementServer().isChildDomain(account.getDomainId(), domain.getId())) {
// throw new ServerApiException(BaseCmd.ACCOUNT_ERROR, "Unable to update domain " + domainId + ", permission denied");
// }
//
// if (newName == null) {
// newName = domain.getName();
// }
//
// try {
// getManagementServer().updateDomain(domainId, newName);
// domain = getManagementServer().findDomainIdById(domainId);
// if (domain.getName().equals(newName)) {
// editDomainResult = true;
// }
// } catch (Exception ex) {
// s_logger.error("Exception editing domain", ex);
// throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update domain " + domainId + ": internal error.");
// }
//
// List<Pair<String, Object>> returnValues = new ArrayList<Pair<String, Object>>();
// if (editDomainResult == true) {
// returnValues.add(new Pair<String, Object>(BaseCmd.Properties.SUCCESS.getName(), new Boolean(true)));
// } else {
// throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update domain " + domainId);
// }
// return returnValues;
// }
}

View File

@ -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<Pair<Enum, Boolean>> s_properties = new ArrayList<Pair<Enum, Boolean>>();
static {
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.BOOTABLE, Boolean.FALSE));
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.DISPLAY_TEXT, Boolean.FALSE));
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.ID, Boolean.TRUE));
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.NAME, Boolean.FALSE));
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.OS_TYPE_ID, Boolean.FALSE));
s_properties.add(new Pair<Enum, Boolean>(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<Pair<Enum, Boolean>> getProperties() {
return s_properties;
}
@Override
public List<Pair<String, Object>> execute(Map<String, Object> params) {
Account account = (Account)params.get(BaseCmd.Properties.ACCOUNT_OBJ.getName());
String displayText = (String)params.get(BaseCmd.Properties.DISPLAY_TEXT.getName());
String name = (String)params.get(BaseCmd.Properties.NAME.getName());
Long isoId = (Long)params.get(BaseCmd.Properties.ID.getName());
Long guestOSId = (Long) params.get(BaseCmd.Properties.OS_TYPE_ID.getName());
Boolean bootable = (Boolean) params.get(BaseCmd.Properties.BOOTABLE.getName());
VMTemplateVO iso = getManagementServer().findTemplateById(isoId.longValue());
if ((iso == null) || iso.getFormat() != Storage.ImageFormat.ISO) {
throw new ServerApiException(BaseCmd.PARAM_ERROR, "Unable to find ISO with id " + isoId);
}
// do a permission check
if (account != null) {
Long isoOwner = iso.getAccountId();
if (!isAdmin(account.getType())) {
if ((isoOwner == null) || (account.getId().longValue() != isoOwner.longValue())) {
throw new ServerApiException(BaseCmd.ACCOUNT_ERROR, "Unable to modify ISO with id " + isoId);
}
} else if (account.getType() != Account.ACCOUNT_TYPE_ADMIN) {
Long isoOwnerDomainId = getManagementServer().findDomainIdByAccountId(isoOwner);
if (!getManagementServer().isChildDomain(account.getDomainId(), isoOwnerDomainId)) {
throw new ServerApiException(BaseCmd.ACCOUNT_ERROR, "Unable to modify ISO with id " + isoId);
}
}
}
// do the update
boolean success = false;
try {
success = getManagementServer().updateTemplate(isoId, name, displayText, null, guestOSId, null, bootable);
} catch (Exception ex) {
s_logger.error("Exception editing ISO", ex);
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update ISO " + isoId + ": " + ex.getMessage());
}
VMTemplateVO updatedIso = getManagementServer().findTemplateById(isoId);
if (success) {
List<Pair<String, Object>> isoData = new ArrayList<Pair<String, Object>>();
isoData.add(new Pair<String, Object>(BaseCmd.Properties.ID.getName(), updatedIso.getId().toString()));
isoData.add(new Pair<String, Object>(BaseCmd.Properties.NAME.getName(), updatedIso.getName()));
isoData.add(new Pair<String, Object>(BaseCmd.Properties.DISPLAY_TEXT.getName(), updatedIso.getDisplayText()));
isoData.add(new Pair<String, Object>(BaseCmd.Properties.IS_PUBLIC.getName(), Boolean.valueOf(updatedIso.isPublicTemplate()).toString()));
isoData.add(new Pair<String, Object>(BaseCmd.Properties.CREATED.getName(), getDateString(updatedIso.getCreated())));
isoData.add(new Pair<String, Object>(BaseCmd.Properties.FORMAT.getName(), updatedIso.getFormat()));
isoData.add(new Pair<String, Object>(BaseCmd.Properties.OS_TYPE_ID.getName(), updatedIso.getGuestOSId()));
isoData.add(new Pair<String, Object>(BaseCmd.Properties.BOOTABLE.getName(), updatedIso.isBootable()));
return isoData;
} else {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "internal error updating ISO");
}
}
// @Override
// public List<Pair<String, Object>> execute(Map<String, Object> params) {
// Account account = (Account)params.get(BaseCmd.Properties.ACCOUNT_OBJ.getName());
// String displayText = (String)params.get(BaseCmd.Properties.DISPLAY_TEXT.getName());
// String name = (String)params.get(BaseCmd.Properties.NAME.getName());
// Long isoId = (Long)params.get(BaseCmd.Properties.ID.getName());
// Long guestOSId = (Long) params.get(BaseCmd.Properties.OS_TYPE_ID.getName());
// Boolean bootable = (Boolean) params.get(BaseCmd.Properties.BOOTABLE.getName());
//
// VMTemplateVO iso = getManagementServer().findTemplateById(isoId.longValue());
// if ((iso == null) || iso.getFormat() != Storage.ImageFormat.ISO) {
// throw new ServerApiException(BaseCmd.PARAM_ERROR, "Unable to find ISO with id " + isoId);
// }
//
// // do a permission check
// if (account != null) {
// Long isoOwner = iso.getAccountId();
// if (!isAdmin(account.getType())) {
// if ((isoOwner == null) || (account.getId().longValue() != isoOwner.longValue())) {
// throw new ServerApiException(BaseCmd.ACCOUNT_ERROR, "Unable to modify ISO with id " + isoId);
// }
// } else if (account.getType() != Account.ACCOUNT_TYPE_ADMIN) {
// Long isoOwnerDomainId = getManagementServer().findDomainIdByAccountId(isoOwner);
// if (!getManagementServer().isChildDomain(account.getDomainId(), isoOwnerDomainId)) {
// throw new ServerApiException(BaseCmd.ACCOUNT_ERROR, "Unable to modify ISO with id " + isoId);
// }
// }
// }
//
// // do the update
// boolean success = false;
// try {
// success = getManagementServer().updateTemplate(isoId, name, displayText, null, guestOSId, null, bootable);
// } catch (Exception ex) {
// s_logger.error("Exception editing ISO", ex);
// throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update ISO " + isoId + ": " + ex.getMessage());
// }
//
// VMTemplateVO updatedIso = getManagementServer().findTemplateById(isoId);
// if (success) {
// List<Pair<String, Object>> isoData = new ArrayList<Pair<String, Object>>();
// isoData.add(new Pair<String, Object>(BaseCmd.Properties.ID.getName(), updatedIso.getId().toString()));
// isoData.add(new Pair<String, Object>(BaseCmd.Properties.NAME.getName(), updatedIso.getName()));
// isoData.add(new Pair<String, Object>(BaseCmd.Properties.DISPLAY_TEXT.getName(), updatedIso.getDisplayText()));
// isoData.add(new Pair<String, Object>(BaseCmd.Properties.IS_PUBLIC.getName(), Boolean.valueOf(updatedIso.isPublicTemplate()).toString()));
// isoData.add(new Pair<String, Object>(BaseCmd.Properties.CREATED.getName(), getDateString(updatedIso.getCreated())));
// isoData.add(new Pair<String, Object>(BaseCmd.Properties.FORMAT.getName(), updatedIso.getFormat()));
// isoData.add(new Pair<String, Object>(BaseCmd.Properties.OS_TYPE_ID.getName(), updatedIso.getGuestOSId()));
// isoData.add(new Pair<String, Object>(BaseCmd.Properties.BOOTABLE.getName(), updatedIso.isBootable()));
// return isoData;
// } else {
// throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "internal error updating ISO");
// }
// }
}

View File

@ -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<Pair<Enum, Boolean>> s_properties = new ArrayList<Pair<Enum, Boolean>>();
static {
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.ACCOUNT_OBJ, Boolean.FALSE));
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.DISPLAY_TEXT, Boolean.FALSE));
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.FORMAT, Boolean.FALSE));
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.ID, Boolean.TRUE));
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.NAME, Boolean.FALSE));
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.OS_TYPE_ID, Boolean.FALSE));
s_properties.add(new Pair<Enum, Boolean>(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<Pair<Enum, Boolean>> getProperties() {
return s_properties;
}
@Override
public List<Pair<String, Object>> execute(Map<String, Object> params) {
Long templateId = (Long)params.get(BaseCmd.Properties.ID.getName());
Account account = (Account)params.get(BaseCmd.Properties.ACCOUNT_OBJ.getName());
String name = (String)params.get(BaseCmd.Properties.NAME.getName());
String displayText = (String)params.get(BaseCmd.Properties.DISPLAY_TEXT.getName());
String format = (String)params.get(BaseCmd.Properties.FORMAT.getName());
Long guestOSId = (Long) params.get(BaseCmd.Properties.OS_TYPE_ID.getName());
Boolean passwordEnabled = (Boolean)params.get(BaseCmd.Properties.PASSWORD_ENABLED.getName());
VMTemplateVO template = getManagementServer().findTemplateById(templateId.longValue());
if (template == null) {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "unable to find template with id " + templateId);
}
if (account != null) {
if (!isAdmin(account.getType())) {
if (template.getAccountId() != account.getId()) {
throw new ServerApiException(BaseCmd.ACCOUNT_ERROR, "unable to edit template with id " + templateId);
}
} else if (account.getType() != Account.ACCOUNT_TYPE_ADMIN) {
Long templateOwnerDomainId = getManagementServer().findDomainIdByAccountId(template.getAccountId());
if (!getManagementServer().isChildDomain(account.getDomainId(), templateOwnerDomainId)) {
throw new ServerApiException(BaseCmd.ACCOUNT_ERROR, "Unable to modify template with id " + templateId);
}
}
}
if (templateId == Long.valueOf(1)) {
throw new ServerApiException(BaseCmd.PARAM_ERROR, "unable to update template with id " + templateId);
}
boolean success = false;
try {
success = getManagementServer().updateTemplate(templateId, name, displayText, format, guestOSId, passwordEnabled, null);
} catch (Exception ex) {
s_logger.error("Exception editing template", ex);
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update template " + templateId + ": " + ex.getMessage());
}
VMTemplateVO updatedTemplate = getManagementServer().findTemplateById(templateId);
if (success) {
List<Pair<String, Object>> templateData = new ArrayList<Pair<String, Object>>();
templateData.add(new Pair<String, Object>(BaseCmd.Properties.ID.getName(), updatedTemplate.getId().toString()));
templateData.add(new Pair<String, Object>(BaseCmd.Properties.NAME.getName(), updatedTemplate.getName()));
templateData.add(new Pair<String, Object>(BaseCmd.Properties.DISPLAY_TEXT.getName(), updatedTemplate.getDisplayText()));
templateData.add(new Pair<String, Object>(BaseCmd.Properties.IS_PUBLIC.getName(), Boolean.valueOf(updatedTemplate.isPublicTemplate()).toString()));
templateData.add(new Pair<String, Object>(BaseCmd.Properties.CREATED.getName(), getDateString(updatedTemplate.getCreated())));
templateData.add(new Pair<String, Object>(BaseCmd.Properties.FORMAT.getName(), updatedTemplate.getFormat()));
templateData.add(new Pair<String, Object>(BaseCmd.Properties.OS_TYPE_ID.getName(), updatedTemplate.getGuestOSId()));
templateData.add(new Pair<String, Object>(BaseCmd.Properties.PASSWORD_ENABLED.getName(), updatedTemplate.getEnablePassword()));
templateData.add(new Pair<String, Object>(BaseCmd.Properties.CROSS_ZONES.getName(), Boolean.valueOf(updatedTemplate.isCrossZones()).toString()));
return templateData;
} else {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "internal error updating template");
}
}
// @Override
// public List<Pair<String, Object>> execute(Map<String, Object> params) {
// Long templateId = (Long)params.get(BaseCmd.Properties.ID.getName());
// Account account = (Account)params.get(BaseCmd.Properties.ACCOUNT_OBJ.getName());
// String name = (String)params.get(BaseCmd.Properties.NAME.getName());
// String displayText = (String)params.get(BaseCmd.Properties.DISPLAY_TEXT.getName());
// String format = (String)params.get(BaseCmd.Properties.FORMAT.getName());
// Long guestOSId = (Long) params.get(BaseCmd.Properties.OS_TYPE_ID.getName());
// Boolean passwordEnabled = (Boolean)params.get(BaseCmd.Properties.PASSWORD_ENABLED.getName());
//
// VMTemplateVO template = getManagementServer().findTemplateById(templateId.longValue());
// if (template == null) {
// throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "unable to find template with id " + templateId);
// }
//
// if (account != null) {
// if (!isAdmin(account.getType())) {
// if (template.getAccountId() != account.getId()) {
// throw new ServerApiException(BaseCmd.ACCOUNT_ERROR, "unable to edit template with id " + templateId);
// }
// } else if (account.getType() != Account.ACCOUNT_TYPE_ADMIN) {
// Long templateOwnerDomainId = getManagementServer().findDomainIdByAccountId(template.getAccountId());
// if (!getManagementServer().isChildDomain(account.getDomainId(), templateOwnerDomainId)) {
// throw new ServerApiException(BaseCmd.ACCOUNT_ERROR, "Unable to modify template with id " + templateId);
// }
// }
// }
//
// if (templateId == Long.valueOf(1)) {
// throw new ServerApiException(BaseCmd.PARAM_ERROR, "unable to update template with id " + templateId);
// }
//
//
// boolean success = false;
// try {
// success = getManagementServer().updateTemplate(templateId, name, displayText, format, guestOSId, passwordEnabled, null);
// } catch (Exception ex) {
// s_logger.error("Exception editing template", ex);
// throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update template " + templateId + ": " + ex.getMessage());
// }
//
// VMTemplateVO updatedTemplate = getManagementServer().findTemplateById(templateId);
// if (success) {
// List<Pair<String, Object>> templateData = new ArrayList<Pair<String, Object>>();
// templateData.add(new Pair<String, Object>(BaseCmd.Properties.ID.getName(), updatedTemplate.getId().toString()));
// templateData.add(new Pair<String, Object>(BaseCmd.Properties.NAME.getName(), updatedTemplate.getName()));
// templateData.add(new Pair<String, Object>(BaseCmd.Properties.DISPLAY_TEXT.getName(), updatedTemplate.getDisplayText()));
// templateData.add(new Pair<String, Object>(BaseCmd.Properties.IS_PUBLIC.getName(), Boolean.valueOf(updatedTemplate.isPublicTemplate()).toString()));
// templateData.add(new Pair<String, Object>(BaseCmd.Properties.CREATED.getName(), getDateString(updatedTemplate.getCreated())));
// templateData.add(new Pair<String, Object>(BaseCmd.Properties.FORMAT.getName(), updatedTemplate.getFormat()));
// templateData.add(new Pair<String, Object>(BaseCmd.Properties.OS_TYPE_ID.getName(), updatedTemplate.getGuestOSId()));
// templateData.add(new Pair<String, Object>(BaseCmd.Properties.PASSWORD_ENABLED.getName(), updatedTemplate.getEnablePassword()));
// templateData.add(new Pair<String, Object>(BaseCmd.Properties.CROSS_ZONES.getName(), Boolean.valueOf(updatedTemplate.isCrossZones()).toString()));
// return templateData;
// } else {
// throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "internal error updating template");
// }
// }
}

View File

@ -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

View File

@ -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.");

View File

@ -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 <CloudId+Signature>
*/
ArrayList<String> getCloudIdentifierResponse(long userId);
ArrayList<String> getCloudIdentifierResponse(GetCloudIdentifierCmd cmd) throws InvalidParameterValueException;
/**
* check if a network security group name in the given account/domain is in use

View File

@ -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<DomainVO> sc = _domainDao.createSearchCriteria();
sc.addAnd("name", SearchCriteria.Op.EQ, domainName);
List<DomainVO> 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<String> getCloudIdentifierResponse(long userId)
{
public ArrayList<String> 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);