Search in sources :

Example 1 with PlannerHostReservationVO

use of com.cloud.deploy.PlannerHostReservationVO in project cloudstack by apache.

the class DeploymentPlanningManagerImplTest method testSetUp.

@Before
public void testSetUp() {
    MockitoAnnotations.initMocks(this);
    ComponentContext.initComponentsLifeCycle();
    PlannerHostReservationVO reservationVO = new PlannerHostReservationVO(200L, 1L, 2L, 3L, PlannerResourceUsage.Shared);
    Mockito.when(_plannerHostReserveDao.persist(Matchers.any(PlannerHostReservationVO.class))).thenReturn(reservationVO);
    Mockito.when(_plannerHostReserveDao.findById(Matchers.anyLong())).thenReturn(reservationVO);
    Mockito.when(_affinityGroupVMMapDao.countAffinityGroupsForVm(Matchers.anyLong())).thenReturn(0L);
    VMInstanceVO vm = new VMInstanceVO();
    Mockito.when(vmProfile.getVirtualMachine()).thenReturn(vm);
    Mockito.when(vmDetailsDao.listDetailsKeyPairs(Matchers.anyLong())).thenReturn(null);
    Mockito.when(_dcDao.findById(Matchers.anyLong())).thenReturn(dc);
    Mockito.when(dc.getId()).thenReturn(dataCenterId);
    ClusterVO clusterVO = new ClusterVO();
    clusterVO.setHypervisorType(HypervisorType.XenServer.toString());
    Mockito.when(_clusterDao.findById(Matchers.anyLong())).thenReturn(clusterVO);
    Mockito.when(_planner.getName()).thenReturn("FirstFitPlanner");
    List<DeploymentPlanner> planners = new ArrayList<DeploymentPlanner>();
    planners.add(_planner);
    _dpm.setPlanners(planners);
}
Also used : ClusterVO(com.cloud.dc.ClusterVO) ArrayList(java.util.ArrayList) DeploymentPlanner(com.cloud.deploy.DeploymentPlanner) PlannerHostReservationVO(com.cloud.deploy.PlannerHostReservationVO) Before(org.junit.Before)

Example 2 with PlannerHostReservationVO

use of com.cloud.deploy.PlannerHostReservationVO in project cloudstack by apache.

the class UserVmManagerImpl method checkHostsDedication.

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.AlertType.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.AlertType.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).equals(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.AlertType.ALERT_TYPE_USERVM, vm.getDataCenterId(), vm.getPodIdToDeployIn(), msg, msg);
            s_logger.warn(msg);
        }
        if (!((domainOfDedicatedHost(srcHost) == null) || (domainOfDedicatedHost(srcHost).equals(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.AlertType.ALERT_TYPE_USERVM, vm.getDataCenterId(), vm.getPodIdToDeployIn(), msg, msg);
            s_logger.warn(msg);
        }
    }
    // Checks for implicitly dedicated hosts
    ServiceOfferingVO deployPlanner = _offeringDao.findById(vm.getId(), 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 {
                //using implicit planner and must belong to same account
                for (VMInstanceVO vmsDest : vmsOnDest) {
                    ServiceOfferingVO destPlanner = _offeringDao.findById(vm.getId(), 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.AlertType.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.AlertType.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.AlertType.ALERT_TYPE_USERVM, vm.getDataCenterId(), vm.getPodIdToDeployIn(), msg, msg);
                s_logger.warn(msg);
            }
        }
    }
}
Also used : PlannerHostReservationVO(com.cloud.deploy.PlannerHostReservationVO) ServiceOfferingVO(com.cloud.service.ServiceOfferingVO) HostVO(com.cloud.host.HostVO)

Aggregations

PlannerHostReservationVO (com.cloud.deploy.PlannerHostReservationVO)2 ClusterVO (com.cloud.dc.ClusterVO)1 DeploymentPlanner (com.cloud.deploy.DeploymentPlanner)1 HostVO (com.cloud.host.HostVO)1 ServiceOfferingVO (com.cloud.service.ServiceOfferingVO)1 ArrayList (java.util.ArrayList)1 Before (org.junit.Before)1