}
return null;
}
public void checkHostsDedication (VMInstanceVO vm, long srcHostId, long destHostId) {
HostVO srcHost = _hostDao.findById(srcHostId);
HostVO destHost = _hostDao.findById(destHostId);
boolean srcExplDedicated = checkIfHostIsDedicated(srcHost);
boolean destExplDedicated = checkIfHostIsDedicated(destHost);
//if srcHost is explicitly dedicated and destination Host is not
if (srcExplDedicated && !destExplDedicated) {
//raise an alert
String msg = "VM is being migrated from a explicitly dedicated host " + srcHost.getName() +" to non-dedicated host " + destHost.getName();
_alertMgr.sendAlert(AlertManager.ALERT_TYPE_USERVM, vm.getDataCenterId(), vm.getPodIdToDeployIn(), msg, msg);
s_logger.warn(msg);
}
//if srcHost is non dedicated but destination Host is explicitly dedicated
if (!srcExplDedicated && destExplDedicated) {
//raise an alert
String msg = "VM is being migrated from a non dedicated host " + srcHost.getName() + " to a explicitly dedicated host "+ destHost.getName();
_alertMgr.sendAlert(AlertManager.ALERT_TYPE_USERVM, vm.getDataCenterId(), vm.getPodIdToDeployIn(), msg, msg);
s_logger.warn(msg);
}
//if hosts are dedicated to different account/domains, raise an alert
if (srcExplDedicated && destExplDedicated) {
if((accountOfDedicatedHost(srcHost) != null) && (accountOfDedicatedHost(srcHost)!= accountOfDedicatedHost(destHost))) {
String msg = "VM is being migrated from host " + srcHost.getName() + " explicitly dedicated to account " + accountOfDedicatedHost(srcHost) +
" to host " + destHost.getName() + " explicitly dedicated to account " + accountOfDedicatedHost(destHost);
_alertMgr.sendAlert(AlertManager.ALERT_TYPE_USERVM, vm.getDataCenterId(), vm.getPodIdToDeployIn(), msg, msg);
s_logger.warn(msg);
}
if((domainOfDedicatedHost(srcHost) != null) && (domainOfDedicatedHost(srcHost)!= domainOfDedicatedHost(destHost))) {
String msg = "VM is being migrated from host " + srcHost.getName() + " explicitly dedicated to domain " + domainOfDedicatedHost(srcHost) +
" to host " + destHost.getName() + " explicitly dedicated to domain " + domainOfDedicatedHost(destHost);
_alertMgr.sendAlert(AlertManager.ALERT_TYPE_USERVM, vm.getDataCenterId(), vm.getPodIdToDeployIn(), msg, msg);
s_logger.warn(msg);
}
}
// Checks for implicitly dedicated hosts
ServiceOfferingVO deployPlanner = _offeringDao.findById(vm.getServiceOfferingId());
if(deployPlanner.getDeploymentPlanner() != null && deployPlanner.getDeploymentPlanner().equals("ImplicitDedicationPlanner")) {
//VM is deployed using implicit planner
long accountOfVm = vm.getAccountId();
String msg = "VM of account " + accountOfVm + " with implicit deployment planner being migrated to host " + destHost.getName();
//Get all vms on destination host
boolean emptyDestination = false;
List<VMInstanceVO> vmsOnDest= getVmsOnHost(destHostId);
if (vmsOnDest == null || vmsOnDest.isEmpty()) {
emptyDestination = true;
}
if (!emptyDestination) {
//Check if vm is deployed using strict implicit planner
if(!isServiceOfferingUsingPlannerInPreferredMode(vm.getServiceOfferingId())) {
//Check if all vms on destination host are created using strict implicit mode
if(!checkIfAllVmsCreatedInStrictMode(accountOfVm, vmsOnDest)) {
msg = "VM of account " + accountOfVm + " with strict implicit deployment planner being migrated to host " + destHost.getName() +
" not having all vms strict implicitly dedicated to account " + accountOfVm;
}
} else {
//If vm is deployed using preferred implicit planner, check if all vms on destination host must be
//using implicit planner and must belong to same account
for (VMInstanceVO vmsDest : vmsOnDest) {
ServiceOfferingVO destPlanner = _offeringDao.findById(vmsDest.getServiceOfferingId());
if (!((destPlanner.getDeploymentPlanner() != null && destPlanner.getDeploymentPlanner().equals("ImplicitDedicationPlanner")) &&
vmsDest.getAccountId()==accountOfVm)) {
msg = "VM of account " + accountOfVm + " with preffered implicit deployment planner being migrated to host " + destHost.getName() +
" not having all vms implicitly dedicated to account " + accountOfVm;
}
}
}
}
_alertMgr.sendAlert(AlertManager.ALERT_TYPE_USERVM, vm.getDataCenterId(), vm.getPodIdToDeployIn(), msg, msg);
s_logger.warn(msg);
} else {
//VM is not deployed using implicit planner, check if it migrated between dedicated hosts
List<PlannerHostReservationVO> reservedHosts = _plannerHostReservationDao.listAllDedicatedHosts();
boolean srcImplDedicated = false;
boolean destImplDedicated = false;
String msg = null;
for (PlannerHostReservationVO reservedHost : reservedHosts) {
if(reservedHost.getHostId() == srcHostId) {
srcImplDedicated = true;
}
if(reservedHost.getHostId() == destHostId) {
destImplDedicated = true;
}
}
if(srcImplDedicated) {
if(destImplDedicated){
msg = "VM is being migrated from implicitly dedicated host " + srcHost.getName() + " to another implicitly dedicated host " + destHost.getName();
} else {
msg = "VM is being migrated from implicitly dedicated host " + srcHost.getName() + " to shared host " + destHost.getName();
}
_alertMgr.sendAlert(AlertManager.ALERT_TYPE_USERVM, vm.getDataCenterId(), vm.getPodIdToDeployIn(), msg, msg);
s_logger.warn(msg);
} else {
if (destImplDedicated) {
msg = "VM is being migrated from shared host " + srcHost.getName() + " to implicitly dedicated host " + destHost.getName();
_alertMgr.sendAlert(AlertManager.ALERT_TYPE_USERVM, vm.getDataCenterId(), vm.getPodIdToDeployIn(), msg, msg);
s_logger.warn(msg);
}
}
}