mirror of https://github.com/apache/cloudstack.git
bug 9564: 1) For all list commands set pageSize() to default.page.size if not specified 2) When pageSize is specified in the request, and it's more than default.page.size - throw an exception
status 9564: resolved fixed
This commit is contained in:
parent
666055239a
commit
b7e4ec1749
|
|
@ -21,28 +21,27 @@ package com.cloud.api;
|
|||
import com.cloud.async.AsyncJob;
|
||||
import com.cloud.exception.InvalidParameterValueException;
|
||||
|
||||
|
||||
public abstract class BaseListCmd extends BaseCmd {
|
||||
|
||||
private static Long MAX_PAGESIZE = 500L;
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////// BaseList API parameters /////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
// ///////////////////////////////////////////////////
|
||||
// ///////// BaseList API parameters /////////////////
|
||||
// ///////////////////////////////////////////////////
|
||||
|
||||
@Parameter(name="keyword", type=CommandType.STRING, description="List by keyword")
|
||||
@Parameter(name = "keyword", type = CommandType.STRING, description = "List by keyword")
|
||||
private String keyword;
|
||||
|
||||
// FIXME: Need to be able to specify next/prev/first/last, so Integer might not be right
|
||||
@Parameter(name=ApiConstants.PAGE, type=CommandType.INTEGER)
|
||||
// FIXME: Need to be able to specify next/prev/first/last, so Integer might not be right
|
||||
@Parameter(name = ApiConstants.PAGE, type = CommandType.INTEGER)
|
||||
private Integer page;
|
||||
|
||||
@Parameter(name=ApiConstants.PAGE_SIZE, type=CommandType.INTEGER)
|
||||
@Parameter(name = ApiConstants.PAGE_SIZE, type = CommandType.INTEGER)
|
||||
private Integer pageSize;
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////////// Accessors ///////////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
// ///////////////////////////////////////////////////
|
||||
// ///////////////// Accessors ///////////////////////
|
||||
// ///////////////////////////////////////////////////
|
||||
|
||||
public String getKeyword() {
|
||||
return keyword;
|
||||
|
|
@ -53,51 +52,46 @@ public abstract class BaseListCmd extends BaseCmd {
|
|||
}
|
||||
|
||||
public Integer getPageSize() {
|
||||
if (pageSize != null && pageSize.longValue() > MAX_PAGESIZE.longValue()) {
|
||||
throw new InvalidParameterValueException("Page size can't exceed max allowed page size value: " + MAX_PAGESIZE.longValue());
|
||||
}
|
||||
|
||||
return pageSize;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void configure() {
|
||||
MAX_PAGESIZE = _configService.getDefaultPageSize();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public long getEntityOwnerId() {
|
||||
//no owner is needed for list command
|
||||
// no owner is needed for list command
|
||||
return 0;
|
||||
}
|
||||
|
||||
public Long getPageSizeVal() {
|
||||
Long pageSize = null;
|
||||
Long pageSize = MAX_PAGESIZE;
|
||||
Integer pageSizeInt = getPageSize();
|
||||
if (pageSizeInt != null) {
|
||||
pageSize = pageSizeInt.longValue();
|
||||
if (pageSize == -1) {
|
||||
pageSize = null;
|
||||
} else if (pageSize > MAX_PAGESIZE){//FIX ME - have a validator and do this.
|
||||
throw new InvalidParameterValueException("The parameter " + ApiConstants.PAGE_SIZE + " exceeded its max value - " + MAX_PAGESIZE);
|
||||
}
|
||||
}
|
||||
if (pageSizeInt != null && pageSizeInt.intValue() != -1) {
|
||||
pageSize = pageSizeInt.longValue();
|
||||
}
|
||||
return pageSize;
|
||||
}
|
||||
|
||||
public Long getStartIndex() {
|
||||
Long startIndex = Long.valueOf(0);
|
||||
Long pageSizeVal = getPageSizeVal();
|
||||
if (pageSizeVal == null) {
|
||||
return null; // there's no limit, so start index is irrelevant
|
||||
}
|
||||
|
||||
if (page != null) {
|
||||
int pageNum = page.intValue();
|
||||
if (pageNum > 0) {
|
||||
startIndex = Long.valueOf(pageSizeVal * (pageNum-1));
|
||||
startIndex = Long.valueOf(pageSizeVal * (pageNum - 1));
|
||||
}
|
||||
}
|
||||
return startIndex;
|
||||
}
|
||||
|
||||
|
||||
public AsyncJob.Type getInstanceType() {
|
||||
return AsyncJob.Type.None;
|
||||
return AsyncJob.Type.None;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,8 +15,8 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package com.cloud.api.commands;
|
||||
|
||||
package com.cloud.api.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
|
@ -27,50 +27,49 @@ import com.cloud.api.ApiConstants;
|
|||
import com.cloud.api.BaseListCmd;
|
||||
import com.cloud.api.Implementation;
|
||||
import com.cloud.api.Parameter;
|
||||
import com.cloud.api.BaseCmd.CommandType;
|
||||
import com.cloud.api.response.AlertResponse;
|
||||
import com.cloud.api.response.ListResponse;
|
||||
|
||||
@Implementation(description="Lists all alerts.", responseObject=AlertResponse.class)
|
||||
@Implementation(description = "Lists all alerts.", responseObject = AlertResponse.class)
|
||||
public class ListAlertsCmd extends BaseListCmd {
|
||||
|
||||
public static final Logger s_logger = Logger.getLogger(ListAlertsCmd.class.getName());
|
||||
|
||||
private static final String s_name = "listalertsresponse";
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
//////////////// API parameters /////////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
// ///////////////////////////////////////////////////
|
||||
// ////////////// API parameters /////////////////////
|
||||
// ///////////////////////////////////////////////////
|
||||
|
||||
@Parameter(name=ApiConstants.ID, type=CommandType.LONG, description="the ID of the alert")
|
||||
@Parameter(name = ApiConstants.ID, type = CommandType.LONG, description = "the ID of the alert")
|
||||
private Long id;
|
||||
|
||||
@Parameter(name=ApiConstants.TYPE, type=CommandType.STRING, description="list by alert type")
|
||||
|
||||
@Parameter(name = ApiConstants.TYPE, type = CommandType.STRING, description = "list by alert type")
|
||||
private String type;
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////////// Accessors ///////////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
// ///////////////////////////////////////////////////
|
||||
// ///////////////// Accessors ///////////////////////
|
||||
// ///////////////////////////////////////////////////
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////// API Implementation///////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
// ///////////////////////////////////////////////////
|
||||
// ///////////// API Implementation///////////////////
|
||||
// ///////////////////////////////////////////////////
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return s_name;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void execute(){
|
||||
public void execute() {
|
||||
List<? extends Alert> result = _mgr.searchForAlerts(this);
|
||||
ListResponse<AlertResponse> response = new ListResponse<AlertResponse>();
|
||||
List<AlertResponse> alertResponseList = new ArrayList<AlertResponse>();
|
||||
|
|
|
|||
|
|
@ -93,9 +93,7 @@ public class ListCapacityCmd extends BaseListCmd {
|
|||
pageSizeVal = pageSize.longValue();
|
||||
}
|
||||
return pageSizeVal;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(){
|
||||
|
|
|
|||
|
|
@ -94,7 +94,6 @@ import com.cloud.storage.dao.UploadDao;
|
|||
import com.cloud.storage.dao.VMTemplateDao;
|
||||
import com.cloud.storage.dao.VMTemplateHostDao;
|
||||
import com.cloud.storage.dao.VolumeDao;
|
||||
import com.cloud.storage.snapshot.SnapshotManager;
|
||||
import com.cloud.user.Account;
|
||||
import com.cloud.user.AccountManager;
|
||||
import com.cloud.user.AccountVO;
|
||||
|
|
@ -107,6 +106,7 @@ import com.cloud.user.dao.UserStatisticsDao;
|
|||
import com.cloud.uservm.UserVm;
|
||||
import com.cloud.utils.NumbersUtil;
|
||||
import com.cloud.utils.component.ComponentLocator;
|
||||
import com.cloud.vm.ConsoleProxyVO;
|
||||
import com.cloud.vm.DomainRouterVO;
|
||||
import com.cloud.vm.InstanceGroupVO;
|
||||
import com.cloud.vm.NicProfile;
|
||||
|
|
@ -115,6 +115,7 @@ import com.cloud.vm.UserVmVO;
|
|||
import com.cloud.vm.VMInstanceVO;
|
||||
import com.cloud.vm.VirtualMachine;
|
||||
import com.cloud.vm.VmStats;
|
||||
import com.cloud.vm.dao.ConsoleProxyDao;
|
||||
import com.cloud.vm.dao.DomainRouterDao;
|
||||
import com.cloud.vm.dao.UserVmDao;
|
||||
|
||||
|
|
@ -124,7 +125,6 @@ public class ApiDBUtils {
|
|||
private static AgentManager _agentMgr;
|
||||
public static AsyncJobManager _asyncMgr;
|
||||
private static SecurityGroupManager _securityGroupMgr;
|
||||
private static SnapshotManager _snapMgr;
|
||||
private static StorageManager _storageMgr;
|
||||
private static UserVmManager _userVmMgr;
|
||||
private static NetworkManager _networkMgr;
|
||||
|
|
@ -160,6 +160,7 @@ public class ApiDBUtils {
|
|||
private static NetworkDao _networkDao;
|
||||
private static ConfigurationService _configMgr;
|
||||
private static ConfigurationDao _configDao;
|
||||
private static ConsoleProxyDao _consoleProxyDao;
|
||||
|
||||
static {
|
||||
_ms = (ManagementServer) ComponentLocator.getComponent(ManagementServer.Name);
|
||||
|
|
@ -169,7 +170,6 @@ public class ApiDBUtils {
|
|||
_agentMgr = locator.getManager(AgentManager.class);
|
||||
_asyncMgr = locator.getManager(AsyncJobManager.class);
|
||||
_securityGroupMgr = locator.getManager(SecurityGroupManager.class);
|
||||
_snapMgr = locator.getManager(SnapshotManager.class);
|
||||
_storageMgr = locator.getManager(StorageManager.class);
|
||||
_userVmMgr = locator.getManager(UserVmManager.class);
|
||||
_networkMgr = locator.getManager(NetworkManager.class);
|
||||
|
|
@ -204,6 +204,7 @@ public class ApiDBUtils {
|
|||
_networkOfferingDao = locator.getDao(NetworkOfferingDao.class);
|
||||
_networkDao = locator.getDao(NetworkDao.class);
|
||||
_configDao = locator.getDao(ConfigurationDao.class);
|
||||
_consoleProxyDao = locator.getDao(ConsoleProxyDao.class);
|
||||
|
||||
// Note: stats collector should already have been initialized by this time, otherwise a null instance is returned
|
||||
_statsCollector = StatsCollector.getInstance();
|
||||
|
|
@ -574,11 +575,15 @@ public class ApiDBUtils {
|
|||
public static Long getDedicatedNetworkDomain(long networkId) {
|
||||
return _networkMgr.getDedicatedNetworkDomain(networkId);
|
||||
}
|
||||
|
||||
public static float getCpuOverprovisioningFactor(){
|
||||
|
||||
public static float getCpuOverprovisioningFactor() {
|
||||
String opFactor = _configDao.getValue(Config.CPUOverprovisioningFactor.key());
|
||||
float cpuOverprovisioningFactor = NumbersUtil.parseFloat(opFactor, 1);
|
||||
return cpuOverprovisioningFactor;
|
||||
}
|
||||
|
||||
public static ConsoleProxyVO findConsoleProxy(long id) {
|
||||
return _consoleProxyDao.findById(id);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -152,12 +152,11 @@ import com.cloud.vm.ConsoleProxyVO;
|
|||
import com.cloud.vm.InstanceGroup;
|
||||
import com.cloud.vm.InstanceGroupVO;
|
||||
import com.cloud.vm.NicProfile;
|
||||
import com.cloud.vm.SecondaryStorageVmVO;
|
||||
import com.cloud.vm.SystemVm;
|
||||
import com.cloud.vm.UserVmVO;
|
||||
import com.cloud.vm.VMInstanceVO;
|
||||
import com.cloud.vm.VirtualMachine;
|
||||
import com.cloud.vm.VirtualMachine.State;
|
||||
import com.cloud.vm.VirtualMachine.Type;
|
||||
import com.cloud.vm.VmStats;
|
||||
|
||||
public class ApiResponseHelper implements ResponseGenerator {
|
||||
|
|
@ -522,7 +521,7 @@ public class ApiResponseHelper implements ResponseGenerator {
|
|||
}
|
||||
cpuAlloc = decimalFormat.format(((float) cpu / (float) (host.getCpus() * host.getSpeed())) * 100f) + "%";
|
||||
hostResponse.setCpuAllocated(cpuAlloc);
|
||||
|
||||
|
||||
String cpuWithOverprovisioning = new Float(host.getCpus() * host.getSpeed() * ApiDBUtils.getCpuOverprovisioningFactor()).toString();
|
||||
hostResponse.setCpuWithOverprovisioning(cpuWithOverprovisioning);
|
||||
}
|
||||
|
|
@ -768,7 +767,7 @@ public class ApiResponseHelper implements ResponseGenerator {
|
|||
zoneResponse.setType(dataCenter.getNetworkType().toString());
|
||||
zoneResponse.setAllocationState(dataCenter.getAllocationState().toString());
|
||||
zoneResponse.setZoneToken(dataCenter.getZoneToken());
|
||||
zoneResponse.setDhcpProvider(dataCenter.getDhcpProvider());
|
||||
zoneResponse.setDhcpProvider(dataCenter.getDhcpProvider());
|
||||
zoneResponse.setObjectName("zone");
|
||||
return zoneResponse;
|
||||
}
|
||||
|
|
@ -1275,10 +1274,10 @@ public class ApiResponseHelper implements ResponseGenerator {
|
|||
}
|
||||
|
||||
@Override
|
||||
public SystemVmResponse createSystemVmResponse(VirtualMachine systemVM) {
|
||||
public SystemVmResponse createSystemVmResponse(VirtualMachine vm) {
|
||||
SystemVmResponse vmResponse = new SystemVmResponse();
|
||||
if (systemVM instanceof SystemVm) {
|
||||
SystemVm vm = (SystemVm) systemVM;
|
||||
if (vm.getType() == Type.SecondaryStorageVm || vm.getType() == Type.ConsoleProxy) {
|
||||
// SystemVm vm = (SystemVm) systemVM;
|
||||
|
||||
vmResponse.setId(vm.getId());
|
||||
vmResponse.setSystemVmType(vm.getType().toString().toLowerCase());
|
||||
|
|
@ -1298,20 +1297,9 @@ public class ApiResponseHelper implements ResponseGenerator {
|
|||
vmResponse.setState(vm.getState().toString());
|
||||
}
|
||||
|
||||
String instanceType = "console_proxy";
|
||||
if (systemVM instanceof SecondaryStorageVmVO) {
|
||||
instanceType = "sec_storage_vm"; // FIXME: this should be a
|
||||
// constant so that the async
|
||||
// jobs get updated with the
|
||||
// correct instance type, they
|
||||
// are using
|
||||
// different instance types at
|
||||
// the moment
|
||||
}
|
||||
|
||||
// for console proxies, add the active sessions
|
||||
if (systemVM instanceof ConsoleProxyVO) {
|
||||
ConsoleProxyVO proxy = (ConsoleProxyVO) systemVM;
|
||||
if (vm.getType() == Type.ConsoleProxy) {
|
||||
ConsoleProxyVO proxy = ApiDBUtils.findConsoleProxy(vm.getId());
|
||||
vmResponse.setActiveViewerSessions(proxy.getActiveSession());
|
||||
}
|
||||
|
||||
|
|
@ -1322,7 +1310,7 @@ public class ApiResponseHelper implements ResponseGenerator {
|
|||
vmResponse.setDns2(zone.getDns2());
|
||||
}
|
||||
|
||||
List<NicProfile> nicProfiles = ApiDBUtils.getNics(systemVM);
|
||||
List<NicProfile> nicProfiles = ApiDBUtils.getNics(vm);
|
||||
for (NicProfile singleNicProfile : nicProfiles) {
|
||||
Network network = ApiDBUtils.findNetworkById(singleNicProfile.getNetworkId());
|
||||
if (network != null) {
|
||||
|
|
@ -2105,7 +2093,7 @@ public class ApiResponseHelper implements ResponseGenerator {
|
|||
}
|
||||
|
||||
float cpuOverprovisioningFactor = ApiDBUtils.getCpuOverprovisioningFactor();
|
||||
|
||||
|
||||
// collect all the capacity types, sum allocated/used and sum total...get one capacity number for each
|
||||
for (Capacity capacity : hostCapacities) {
|
||||
if (poolIdsToIgnore.contains(capacity.getHostOrPoolId())) {
|
||||
|
|
@ -2123,17 +2111,17 @@ public class ApiResponseHelper implements ResponseGenerator {
|
|||
|
||||
Long totalCapacity = totalCapacityMap.get(key);
|
||||
Long usedCapacity = usedCapacityMap.get(key);
|
||||
|
||||
//reset overprovisioning factor to 1
|
||||
|
||||
// reset overprovisioning factor to 1
|
||||
float overprovisioningFactor = 1;
|
||||
if (capacityType == Capacity.CAPACITY_TYPE_CPU){
|
||||
overprovisioningFactor = cpuOverprovisioningFactor;
|
||||
if (capacityType == Capacity.CAPACITY_TYPE_CPU) {
|
||||
overprovisioningFactor = cpuOverprovisioningFactor;
|
||||
}
|
||||
|
||||
if (totalCapacity == null) {
|
||||
totalCapacity = new Long((long)(capacity.getTotalCapacity() * overprovisioningFactor));
|
||||
totalCapacity = new Long((long) (capacity.getTotalCapacity() * overprovisioningFactor));
|
||||
} else {
|
||||
totalCapacity = new Long((long)(capacity.getTotalCapacity() * overprovisioningFactor)) + totalCapacity;
|
||||
totalCapacity = new Long((long) (capacity.getTotalCapacity() * overprovisioningFactor)) + totalCapacity;
|
||||
}
|
||||
|
||||
if (usedCapacity == null) {
|
||||
|
|
@ -2160,14 +2148,14 @@ public class ApiResponseHelper implements ResponseGenerator {
|
|||
usedCapacity = usedCapacityMap.get(keyForPodTotal);
|
||||
|
||||
overprovisioningFactor = 1;
|
||||
if (capacityType == Capacity.CAPACITY_TYPE_CPU){
|
||||
overprovisioningFactor = cpuOverprovisioningFactor;
|
||||
if (capacityType == Capacity.CAPACITY_TYPE_CPU) {
|
||||
overprovisioningFactor = cpuOverprovisioningFactor;
|
||||
}
|
||||
|
||||
if (totalCapacity == null) {
|
||||
totalCapacity = new Long((long)(capacity.getTotalCapacity() * overprovisioningFactor));
|
||||
totalCapacity = new Long((long) (capacity.getTotalCapacity() * overprovisioningFactor));
|
||||
} else {
|
||||
totalCapacity = new Long((long)(capacity.getTotalCapacity() * overprovisioningFactor)) + totalCapacity;
|
||||
totalCapacity = new Long((long) (capacity.getTotalCapacity() * overprovisioningFactor)) + totalCapacity;
|
||||
}
|
||||
|
||||
if (usedCapacity == null) {
|
||||
|
|
@ -2236,7 +2224,6 @@ public class ApiResponseHelper implements ResponseGenerator {
|
|||
capacityResponse.setZoneId(summedCapacity.getDataCenterId());
|
||||
capacityResponse.setZoneName(ApiDBUtils.findZoneById(summedCapacity.getDataCenterId()).getName());
|
||||
if (summedCapacity.getTotalCapacity() != 0) {
|
||||
// float computed = ((float)summedCapacity.getUsedCapacity() / (float)summedCapacity.getTotalCapacity() * 100f);
|
||||
capacityResponse.setPercentUsed(format.format((float) summedCapacity.getUsedCapacity() / (float) summedCapacity.getTotalCapacity() * 100f));
|
||||
} else {
|
||||
capacityResponse.setPercentUsed(format.format(0L));
|
||||
|
|
|
|||
|
|
@ -437,23 +437,12 @@ public class ApiServer implements HttpRequestHandler {
|
|||
// if the command is of the listXXXCommand, we will need to also return the
|
||||
// the job id and status if possible
|
||||
if (cmdObj instanceof BaseListCmd) {
|
||||
// validate page size
|
||||
validatePageSize((BaseListCmd) cmdObj);
|
||||
buildAsyncListResponse((BaseListCmd) cmdObj, account);
|
||||
}
|
||||
return ApiResponseSerializer.toSerializedString((ResponseObject) cmdObj.getResponseObject(), cmdObj.getResponseType());
|
||||
}
|
||||
}
|
||||
|
||||
private void validatePageSize(BaseListCmd command) {
|
||||
List<ResponseObject> responses = ((ListResponse<ResponseObject>) command.getResponseObject()).getResponses();
|
||||
int defaultPageLimit = BaseCmd._configService.getDefaultPageSize().intValue();
|
||||
if (responses != null && responses.size() > defaultPageLimit && command.getPage() == null && command.getPageSize() == null) {
|
||||
throw new ServerApiException(BaseCmd.PAGE_LIMIT_EXCEED, "Number of returned objects per page exceed default page limit " + defaultPageLimit
|
||||
+ "; please specify \"page\"/\"pagesize\" parameters");
|
||||
}
|
||||
}
|
||||
|
||||
private void buildAsyncListResponse(BaseListCmd command, Account account) {
|
||||
List<ResponseObject> responses = ((ListResponse) command.getResponseObject()).getResponses();
|
||||
if (responses != null && responses.size() > 0) {
|
||||
|
|
|
|||
|
|
@ -52,7 +52,6 @@ import com.cloud.utils.Pair;
|
|||
import com.cloud.vm.ConsoleProxyVO;
|
||||
import com.cloud.vm.DomainRouterVO;
|
||||
import com.cloud.vm.InstanceGroupVO;
|
||||
import com.cloud.vm.SecondaryStorageVmVO;
|
||||
import com.cloud.vm.UserVmVO;
|
||||
import com.cloud.vm.VMInstanceVO;
|
||||
import com.cloud.vm.VirtualMachine;
|
||||
|
|
@ -341,8 +340,6 @@ public interface ManagementServer extends ManagementService {
|
|||
*/
|
||||
List<DomainRouterVO> listAllActiveRouters();
|
||||
|
||||
List<ConsoleProxyVO> searchForConsoleProxy(Criteria c);
|
||||
|
||||
/**
|
||||
* Finds a pod by the specified ID.
|
||||
*
|
||||
|
|
@ -550,8 +547,6 @@ public interface ManagementServer extends ManagementService {
|
|||
*/
|
||||
boolean isChildDomain(Long parentId, Long childId);
|
||||
|
||||
List<SecondaryStorageVmVO> searchForSecondaryStorageVm(Criteria c);
|
||||
|
||||
SecurityGroupVO findNetworkGroupByName(Long accountId, String groupName);
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -58,7 +58,6 @@ import com.cloud.agent.api.GetVncPortCommand;
|
|||
import com.cloud.agent.api.storage.CopyVolumeAnswer;
|
||||
import com.cloud.agent.api.storage.CopyVolumeCommand;
|
||||
import com.cloud.alert.Alert;
|
||||
import com.cloud.alert.AlertManager;
|
||||
import com.cloud.alert.AlertVO;
|
||||
import com.cloud.alert.dao.AlertDao;
|
||||
import com.cloud.api.ApiConstants;
|
||||
|
|
@ -125,7 +124,6 @@ import com.cloud.async.dao.AsyncJobDao;
|
|||
import com.cloud.capacity.Capacity;
|
||||
import com.cloud.capacity.CapacityVO;
|
||||
import com.cloud.capacity.dao.CapacityDao;
|
||||
import com.cloud.certificate.dao.CertificateDao;
|
||||
import com.cloud.configuration.Config;
|
||||
import com.cloud.configuration.ConfigurationManager;
|
||||
import com.cloud.configuration.ConfigurationVO;
|
||||
|
|
@ -153,7 +151,6 @@ import com.cloud.domain.Domain;
|
|||
import com.cloud.domain.DomainVO;
|
||||
import com.cloud.domain.dao.DomainDao;
|
||||
import com.cloud.event.ActionEvent;
|
||||
import com.cloud.event.Event;
|
||||
import com.cloud.event.EventTypes;
|
||||
import com.cloud.event.EventUtils;
|
||||
import com.cloud.event.EventVO;
|
||||
|
|
@ -165,9 +162,9 @@ import com.cloud.exception.OperationTimedoutException;
|
|||
import com.cloud.exception.PermissionDeniedException;
|
||||
import com.cloud.exception.ResourceUnavailableException;
|
||||
import com.cloud.exception.StorageUnavailableException;
|
||||
import com.cloud.host.DetailVO;
|
||||
import com.cloud.host.Host;
|
||||
import com.cloud.host.Host.Type;
|
||||
import com.cloud.host.DetailVO;
|
||||
import com.cloud.host.HostVO;
|
||||
import com.cloud.host.Status;
|
||||
import com.cloud.host.dao.DetailsDao;
|
||||
|
|
@ -176,11 +173,9 @@ import com.cloud.hypervisor.Hypervisor.HypervisorType;
|
|||
import com.cloud.info.ConsoleProxyInfo;
|
||||
import com.cloud.keystore.KeystoreManager;
|
||||
import com.cloud.network.IPAddressVO;
|
||||
import com.cloud.network.NetworkManager;
|
||||
import com.cloud.network.NetworkVO;
|
||||
import com.cloud.network.dao.IPAddressDao;
|
||||
import com.cloud.network.dao.NetworkDao;
|
||||
import com.cloud.network.router.VirtualNetworkApplianceManager;
|
||||
import com.cloud.network.security.SecurityGroupVO;
|
||||
import com.cloud.network.security.dao.SecurityGroupDao;
|
||||
import com.cloud.server.auth.UserAuthenticator;
|
||||
|
|
@ -214,7 +209,6 @@ import com.cloud.storage.dao.VMTemplateDao;
|
|||
import com.cloud.storage.dao.VolumeDao;
|
||||
import com.cloud.storage.secondary.SecondaryStorageVmManager;
|
||||
import com.cloud.storage.upload.UploadMonitor;
|
||||
import com.cloud.template.TemplateManager;
|
||||
import com.cloud.template.VirtualMachineTemplate.TemplateFilter;
|
||||
import com.cloud.user.Account;
|
||||
import com.cloud.user.AccountManager;
|
||||
|
|
@ -289,7 +283,7 @@ public class ManagementServerImpl implements ManagementServer {
|
|||
private final VlanDao _vlanDao;
|
||||
private final AccountVlanMapDao _accountVlanMapDao;
|
||||
private final PodVlanMapDao _podVlanMapDao;
|
||||
private final HostDao _hostDao;
|
||||
private final HostDao _hostDao;
|
||||
private final DetailsDao _detailsDao;
|
||||
private final UserDao _userDao;
|
||||
private final UserVmDao _userVmDao;
|
||||
|
|
@ -315,21 +309,17 @@ public class ManagementServerImpl implements ManagementServer {
|
|||
private final NetworkDao _networkDao;
|
||||
private final StorageManager _storageMgr;
|
||||
private final VirtualMachineManager _itMgr;
|
||||
private final NetworkManager _networkMgr;
|
||||
|
||||
private final Adapters<UserAuthenticator> _userAuthenticators;
|
||||
private final HostPodDao _hostPodDao;
|
||||
private final VMInstanceDao _vmInstanceDao;
|
||||
private final VolumeDao _volumeDao;
|
||||
private final AlertManager _alertMgr;
|
||||
private final AsyncJobDao _jobDao;
|
||||
private final AsyncJobManager _asyncMgr;
|
||||
private final TemplateManager _tmpltMgr;
|
||||
private final int _purgeDelay;
|
||||
private final InstanceGroupDao _vmGroupDao;
|
||||
private final UploadMonitor _uploadMonitor;
|
||||
private final UploadDao _uploadDao;
|
||||
private final CertificateDao _certDao;
|
||||
private final SSHKeyPairDao _sshKeyPairDao;
|
||||
|
||||
private final KeystoreManager _ksMgr;
|
||||
|
|
@ -340,10 +330,6 @@ public class ManagementServerImpl implements ManagementServer {
|
|||
|
||||
private final Map<String, String> _configs;
|
||||
|
||||
private final int _routerRamSize;
|
||||
private final int _proxyRamSize;
|
||||
private final int _ssRamSize;
|
||||
|
||||
private final Map<String, Boolean> _availableIdsMap;
|
||||
|
||||
private String _hashKey = null;
|
||||
|
|
@ -357,7 +343,7 @@ public class ManagementServerImpl implements ManagementServer {
|
|||
_vlanDao = locator.getDao(VlanDao.class);
|
||||
_accountVlanMapDao = locator.getDao(AccountVlanMapDao.class);
|
||||
_podVlanMapDao = locator.getDao(PodVlanMapDao.class);
|
||||
_hostDao = locator.getDao(HostDao.class);
|
||||
_hostDao = locator.getDao(HostDao.class);
|
||||
_detailsDao = locator.getDao(DetailsDao.class);
|
||||
_hostPodDao = locator.getDao(HostPodDao.class);
|
||||
_jobDao = locator.getDao(AsyncJobDao.class);
|
||||
|
|
@ -395,17 +381,13 @@ public class ManagementServerImpl implements ManagementServer {
|
|||
_poolHostDao = locator.getDao(StoragePoolHostDao.class);
|
||||
_vmGroupDao = locator.getDao(InstanceGroupDao.class);
|
||||
_uploadDao = locator.getDao(UploadDao.class);
|
||||
_certDao = locator.getDao(CertificateDao.class);
|
||||
_configs = _configDao.getConfiguration();
|
||||
_vmInstanceDao = locator.getDao(VMInstanceDao.class);
|
||||
_volumeDao = locator.getDao(VolumeDao.class);
|
||||
_alertMgr = locator.getManager(AlertManager.class);
|
||||
_asyncMgr = locator.getManager(AsyncJobManager.class);
|
||||
_tmpltMgr = locator.getManager(TemplateManager.class);
|
||||
_uploadMonitor = locator.getManager(UploadMonitor.class);
|
||||
_sshKeyPairDao = locator.getDao(SSHKeyPairDao.class);
|
||||
_itMgr = locator.getManager(VirtualMachineManager.class);
|
||||
_networkMgr = locator.getManager(NetworkManager.class);
|
||||
_ksMgr = locator.getManager(KeystoreManager.class);
|
||||
_userAuthenticators = locator.getAdapters(UserAuthenticator.class);
|
||||
if (_userAuthenticators == null || !_userAuthenticators.isSet()) {
|
||||
|
|
@ -415,12 +397,6 @@ public class ManagementServerImpl implements ManagementServer {
|
|||
String value = _configs.get("account.cleanup.interval");
|
||||
int cleanup = NumbersUtil.parseInt(value, 60 * 60 * 24); // 1 day.
|
||||
|
||||
// Parse the max number of UserVMs and public IPs from server-setup.xml,
|
||||
// and set them in the right places
|
||||
_routerRamSize = NumbersUtil.parseInt(_configs.get("router.ram.size"), VirtualNetworkApplianceManager.DEFAULT_ROUTER_VM_RAMSIZE);
|
||||
_proxyRamSize = NumbersUtil.parseInt(_configs.get("consoleproxy.ram.size"), ConsoleProxyManager.DEFAULT_PROXY_VM_RAMSIZE);
|
||||
_ssRamSize = NumbersUtil.parseInt(_configs.get("secstorage.ram.size"), SecondaryStorageVmManager.DEFAULT_SS_VM_RAMSIZE);
|
||||
|
||||
_statsCollector = StatsCollector.getInstance(_configs);
|
||||
|
||||
_purgeDelay = NumbersUtil.parseInt(_configs.get("event.purge.delay"), 0);
|
||||
|
|
@ -2262,50 +2238,6 @@ public class ManagementServerImpl implements ManagementServer {
|
|||
return _routerDao.search(sc, searchFilter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ConsoleProxyVO> searchForConsoleProxy(Criteria c) {
|
||||
Filter searchFilter = new Filter(ConsoleProxyVO.class, c.getOrderBy(), c.getAscending(), c.getOffset(), c.getLimit());
|
||||
SearchCriteria<ConsoleProxyVO> sc = _consoleProxyDao.createSearchCriteria();
|
||||
|
||||
Object id = c.getCriteria(Criteria.ID);
|
||||
Object name = c.getCriteria(Criteria.NAME);
|
||||
Object state = c.getCriteria(Criteria.STATE);
|
||||
Object zone = c.getCriteria(Criteria.DATACENTERID);
|
||||
Object pod = c.getCriteria(Criteria.PODID);
|
||||
Object hostId = c.getCriteria(Criteria.HOSTID);
|
||||
Object keyword = c.getCriteria(Criteria.KEYWORD);
|
||||
|
||||
if (keyword != null) {
|
||||
SearchCriteria<ConsoleProxyVO> ssc = _consoleProxyDao.createSearchCriteria();
|
||||
ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%");
|
||||
ssc.addOr("state", SearchCriteria.Op.LIKE, "%" + keyword + "%");
|
||||
|
||||
sc.addAnd("name", SearchCriteria.Op.SC, ssc);
|
||||
}
|
||||
|
||||
if (id != null) {
|
||||
sc.addAnd("id", SearchCriteria.Op.EQ, id);
|
||||
}
|
||||
|
||||
if (name != null) {
|
||||
sc.addAnd("name", SearchCriteria.Op.LIKE, "%" + name + "%");
|
||||
}
|
||||
if (state != null) {
|
||||
sc.addAnd("state", SearchCriteria.Op.EQ, state);
|
||||
}
|
||||
if (zone != null) {
|
||||
sc.addAnd("dataCenterId", SearchCriteria.Op.EQ, zone);
|
||||
}
|
||||
if (pod != null) {
|
||||
sc.addAnd("podId", SearchCriteria.Op.EQ, pod);
|
||||
}
|
||||
if (hostId != null) {
|
||||
sc.addAnd("hostId", SearchCriteria.Op.EQ, hostId);
|
||||
}
|
||||
|
||||
return _consoleProxyDao.search(sc, searchFilter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<VolumeVO> searchForVolumes(ListVolumesCmd cmd) {
|
||||
Account account = UserContext.current().getCaller();
|
||||
|
|
@ -3419,25 +3351,24 @@ public class ManagementServerImpl implements ManagementServer {
|
|||
Long domainId = cmd.getDomainId();
|
||||
String acctName = cmd.getAccountName();
|
||||
Long id = cmd.getId();
|
||||
Long accountId = null;
|
||||
|
||||
if (caller.getType() == Account.ACCOUNT_TYPE_DOMAIN_ADMIN) {
|
||||
// validate domainId before proceeding
|
||||
if (domainId != null) {
|
||||
if ((caller != null) && !_domainDao.isChildDomain(caller.getDomainId(), domainId)) {
|
||||
throw new PermissionDeniedException("Invalid domain id (" + domainId + ") given, unable to list " + cmd.getMediaType() + " permissions.");
|
||||
DomainVO domain = _domainDao.findById(domainId);
|
||||
if (domain == null) {
|
||||
throw new InvalidParameterValueException("Unable to find domain by id " + domainId);
|
||||
}
|
||||
|
||||
_accountMgr.checkAccess(caller, domain);
|
||||
|
||||
if (acctName != null) {
|
||||
Account userAccount = _accountDao.findActiveAccount(acctName, domainId);
|
||||
if (userAccount != null) {
|
||||
accountId = userAccount.getId();
|
||||
} else {
|
||||
if (userAccount == null) {
|
||||
throw new PermissionDeniedException("Unable to find account " + acctName + " in domain " + domainId);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (caller.getType() == Account.ACCOUNT_TYPE_NORMAL) {
|
||||
accountId = caller.getId();
|
||||
}
|
||||
|
||||
if (id == Long.valueOf(1)) {
|
||||
|
|
@ -3921,20 +3852,31 @@ public class ManagementServerImpl implements ManagementServer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public List<SecondaryStorageVmVO> searchForSecondaryStorageVm(Criteria c) {
|
||||
Filter searchFilter = new Filter(SecondaryStorageVmVO.class, c.getOrderBy(), c.getAscending(), c.getOffset(), c.getLimit());
|
||||
SearchCriteria<SecondaryStorageVmVO> sc = _secStorageVmDao.createSearchCriteria();
|
||||
public List<? extends VMInstanceVO> searchForSystemVm(ListSystemVMsCmd cmd) {
|
||||
String type = cmd.getSystemVmType();
|
||||
Long zoneId = _accountMgr.checkAccessAndSpecifyAuthority(UserContext.current().getCaller(), cmd.getZoneId());
|
||||
Long id = cmd.getId();
|
||||
String name = cmd.getSystemVmName();
|
||||
String state = cmd.getState();
|
||||
String keyword = cmd.getKeyword();
|
||||
Long podId = cmd.getPodId();
|
||||
Long hostId = cmd.getHostId();
|
||||
|
||||
Object id = c.getCriteria(Criteria.ID);
|
||||
Object name = c.getCriteria(Criteria.NAME);
|
||||
Object state = c.getCriteria(Criteria.STATE);
|
||||
Object zone = c.getCriteria(Criteria.DATACENTERID);
|
||||
Object pod = c.getCriteria(Criteria.PODID);
|
||||
Object hostId = c.getCriteria(Criteria.HOSTID);
|
||||
Object keyword = c.getCriteria(Criteria.KEYWORD);
|
||||
Filter searchFilter = new Filter(VMInstanceVO.class, "id", true, cmd.getStartIndex(), cmd.getPageSizeVal());
|
||||
SearchBuilder<VMInstanceVO> sb = _vmInstanceDao.createSearchBuilder();
|
||||
|
||||
sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ);
|
||||
sb.and("name", sb.entity().getHostName(), SearchCriteria.Op.LIKE);
|
||||
sb.and("state", sb.entity().getState(), SearchCriteria.Op.EQ);
|
||||
sb.and("dataCenterId", sb.entity().getDataCenterId(), SearchCriteria.Op.EQ);
|
||||
sb.and("podId", sb.entity().getPodId(), SearchCriteria.Op.EQ);
|
||||
sb.and("hostId", sb.entity().getHostId(), SearchCriteria.Op.EQ);
|
||||
sb.and("type", sb.entity().getType(), SearchCriteria.Op.EQ);
|
||||
|
||||
SearchCriteria<VMInstanceVO> sc = sb.create();
|
||||
|
||||
if (keyword != null) {
|
||||
SearchCriteria<SecondaryStorageVmVO> ssc = _secStorageVmDao.createSearchCriteria();
|
||||
SearchCriteria<VMInstanceVO> ssc = _vmInstanceDao.createSearchCriteria();
|
||||
ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%");
|
||||
ssc.addOr("state", SearchCriteria.Op.LIKE, "%" + keyword + "%");
|
||||
|
||||
|
|
@ -3942,55 +3884,30 @@ public class ManagementServerImpl implements ManagementServer {
|
|||
}
|
||||
|
||||
if (id != null) {
|
||||
sc.addAnd("id", SearchCriteria.Op.EQ, id);
|
||||
sc.setParameters("id", id);
|
||||
}
|
||||
|
||||
if (name != null) {
|
||||
sc.addAnd("name", SearchCriteria.Op.LIKE, "%" + name + "%");
|
||||
sc.setParameters("name", name);
|
||||
}
|
||||
if (state != null) {
|
||||
sc.addAnd("state", SearchCriteria.Op.EQ, state);
|
||||
sc.setParameters("state", state);
|
||||
}
|
||||
if (zone != null) {
|
||||
sc.addAnd("dataCenterId", SearchCriteria.Op.EQ, zone);
|
||||
if (zoneId != null) {
|
||||
sc.setParameters("dataCenterId", zoneId);
|
||||
}
|
||||
if (pod != null) {
|
||||
sc.addAnd("podId", SearchCriteria.Op.EQ, pod);
|
||||
if (podId != null) {
|
||||
sc.setParameters("podId", podId);
|
||||
}
|
||||
if (hostId != null) {
|
||||
sc.addAnd("hostId", SearchCriteria.Op.EQ, hostId);
|
||||
sc.setParameters("hostId", hostId);
|
||||
}
|
||||
|
||||
return _secStorageVmDao.search(sc, searchFilter);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
public List<? extends VMInstanceVO> searchForSystemVm(ListSystemVMsCmd cmd) {
|
||||
Criteria c = new Criteria("id", Boolean.TRUE, cmd.getStartIndex(), cmd.getPageSizeVal());
|
||||
Long zoneId = _accountMgr.checkAccessAndSpecifyAuthority(UserContext.current().getCaller(), cmd.getZoneId());
|
||||
|
||||
c.addCriteria(Criteria.KEYWORD, cmd.getKeyword());
|
||||
c.addCriteria(Criteria.ID, cmd.getId());
|
||||
c.addCriteria(Criteria.DATACENTERID, zoneId);
|
||||
c.addCriteria(Criteria.PODID, cmd.getPodId());
|
||||
c.addCriteria(Criteria.HOSTID, cmd.getHostId());
|
||||
c.addCriteria(Criteria.NAME, cmd.getSystemVmName());
|
||||
c.addCriteria(Criteria.STATE, cmd.getState());
|
||||
|
||||
String type = cmd.getSystemVmType();
|
||||
List systemVMs = new ArrayList();
|
||||
|
||||
if (type == null) { // search for all vm types
|
||||
systemVMs.addAll(searchForConsoleProxy(c));
|
||||
systemVMs.addAll(searchForSecondaryStorageVm(c));
|
||||
} else if ((type != null) && (type.equalsIgnoreCase("secondarystoragevm"))) { // search for ssvm
|
||||
systemVMs.addAll(searchForSecondaryStorageVm(c));
|
||||
} else if ((type != null) && (type.equalsIgnoreCase("consoleproxy"))) { // search for consoleproxy
|
||||
systemVMs.addAll(searchForConsoleProxy(c));
|
||||
if (type != null) {
|
||||
sc.setParameters("type", type);
|
||||
}
|
||||
|
||||
return systemVMs;
|
||||
return _vmInstanceDao.search(sc, searchFilter);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -4337,7 +4254,6 @@ public class ManagementServerImpl implements ManagementServer {
|
|||
}
|
||||
}
|
||||
|
||||
long userId = UserContext.current().getCallerUserId();
|
||||
long accountId = volume.getAccountId();
|
||||
|
||||
String secondaryStorageURL = _storageMgr.getSecondaryStorageURL(zoneId);
|
||||
|
|
@ -4538,17 +4454,6 @@ public class ManagementServerImpl implements ManagementServer {
|
|||
return "unknown";
|
||||
}
|
||||
|
||||
private Long saveScheduledEvent(Long userId, Long accountId, String type, String description) {
|
||||
EventVO event = new EventVO();
|
||||
event.setUserId(userId);
|
||||
event.setAccountId(accountId);
|
||||
event.setType(type);
|
||||
event.setState(Event.State.Scheduled);
|
||||
event.setDescription("Scheduled async job for " + description);
|
||||
event = _eventDao.persist(event);
|
||||
return event.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long saveStartedEvent(Long userId, Long accountId, String type, String description, long startEventId) {
|
||||
return EventUtils.saveStartedEvent(userId, accountId, type, description, startEventId);
|
||||
|
|
@ -4644,8 +4549,7 @@ public class ManagementServerImpl implements ManagementServer {
|
|||
Account caller = UserContext.current().getCaller();
|
||||
String accountName = cmd.getAccountName();
|
||||
Long domainId = cmd.getDomainId();
|
||||
Account owner = null;
|
||||
_accountMgr.finalizeOwner(caller, accountName, domainId);
|
||||
Account owner = _accountMgr.finalizeOwner(caller, accountName, domainId);
|
||||
|
||||
SSHKeyPairVO s = _sshKeyPairDao.findByName(owner.getAccountId(), owner.getDomainId(), cmd.getName());
|
||||
if (s == null) {
|
||||
|
|
@ -4762,54 +4666,50 @@ public class ManagementServerImpl implements ManagementServer {
|
|||
|
||||
return password;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@DB
|
||||
public boolean updateHostPassword(UpdateHostPasswordCmd cmd) {
|
||||
if (cmd.getClusterId()==null && cmd.getHostId() == null){
|
||||
throw new InvalidParameterValueException("You should provide one of cluster id or a host id.");
|
||||
}
|
||||
else if (cmd.getClusterId()==null){
|
||||
HostVO h = _hostDao.findById(cmd.getHostId());
|
||||
if (h.getHypervisorType() == HypervisorType.XenServer){
|
||||
throw new InvalidParameterValueException("You should provide cluster id for Xenserver cluster.");
|
||||
}
|
||||
DetailVO nv= _detailsDao.findDetail(h.getId(), ApiConstants.USERNAME);
|
||||
if (nv.getValue().equals(cmd.getUsername())){
|
||||
DetailVO nvp= _detailsDao.findDetail(h.getId(), ApiConstants.PASSWORD);
|
||||
nvp.setValue(cmd.getPassword());
|
||||
_detailsDao.persist(nvp);
|
||||
}
|
||||
else {
|
||||
throw new InvalidParameterValueException("The username is not under use by management server.");
|
||||
}
|
||||
}
|
||||
else {
|
||||
//get all the hosts in this cluster
|
||||
List<HostVO> hosts = _hostDao.listByCluster(cmd.getClusterId());
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
txn.start();
|
||||
for (HostVO h : hosts) {
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Changing password for host name = " + h.getName());
|
||||
}
|
||||
//update password for this host
|
||||
DetailVO nv= _detailsDao.findDetail(h.getId(), ApiConstants.USERNAME);
|
||||
if (nv.getValue().equals(cmd.getUsername())){
|
||||
DetailVO nvp= _detailsDao.findDetail(h.getId(), ApiConstants.PASSWORD);
|
||||
nvp.setValue(cmd.getPassword());
|
||||
_detailsDao.persist(nvp);
|
||||
}
|
||||
else {
|
||||
//if one host in the cluster has diff username then rollback to maintain consistency
|
||||
txn.rollback();
|
||||
throw new InvalidParameterValueException("The username is not same for all hosts, please modify passwords for individual hosts.");
|
||||
}
|
||||
}
|
||||
txn.commit();
|
||||
// if hypervisor is xenserver then we update it in CitrixResourceBase
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (cmd.getClusterId() == null && cmd.getHostId() == null) {
|
||||
throw new InvalidParameterValueException("You should provide one of cluster id or a host id.");
|
||||
} else if (cmd.getClusterId() == null) {
|
||||
HostVO h = _hostDao.findById(cmd.getHostId());
|
||||
if (h.getHypervisorType() == HypervisorType.XenServer) {
|
||||
throw new InvalidParameterValueException("You should provide cluster id for Xenserver cluster.");
|
||||
}
|
||||
DetailVO nv = _detailsDao.findDetail(h.getId(), ApiConstants.USERNAME);
|
||||
if (nv.getValue().equals(cmd.getUsername())) {
|
||||
DetailVO nvp = _detailsDao.findDetail(h.getId(), ApiConstants.PASSWORD);
|
||||
nvp.setValue(cmd.getPassword());
|
||||
_detailsDao.persist(nvp);
|
||||
} else {
|
||||
throw new InvalidParameterValueException("The username is not under use by management server.");
|
||||
}
|
||||
} else {
|
||||
// get all the hosts in this cluster
|
||||
List<HostVO> hosts = _hostDao.listByCluster(cmd.getClusterId());
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
txn.start();
|
||||
for (HostVO h : hosts) {
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Changing password for host name = " + h.getName());
|
||||
}
|
||||
// update password for this host
|
||||
DetailVO nv = _detailsDao.findDetail(h.getId(), ApiConstants.USERNAME);
|
||||
if (nv.getValue().equals(cmd.getUsername())) {
|
||||
DetailVO nvp = _detailsDao.findDetail(h.getId(), ApiConstants.PASSWORD);
|
||||
nvp.setValue(cmd.getPassword());
|
||||
_detailsDao.persist(nvp);
|
||||
} else {
|
||||
// if one host in the cluster has diff username then rollback to maintain consistency
|
||||
txn.rollback();
|
||||
throw new InvalidParameterValueException("The username is not same for all hosts, please modify passwords for individual hosts.");
|
||||
}
|
||||
}
|
||||
txn.commit();
|
||||
// if hypervisor is xenserver then we update it in CitrixResourceBase
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue