Search in sources :

Example 31 with HostPodVO

use of com.cloud.dc.HostPodVO in project cloudstack by apache.

the class ConfigurationManagerTest method checkIfPodIsDeletableFailureOnClusterTest.

@Test(expected = CloudRuntimeException.class)
public void checkIfPodIsDeletableFailureOnClusterTest() {
    HostPodVO hostPodVO = Mockito.mock(HostPodVO.class);
    Mockito.when(hostPodVO.getDataCenterId()).thenReturn(new Random().nextLong());
    Mockito.when(_podDao.findById(anyLong())).thenReturn(hostPodVO);
    ClusterVO clusterVO = Mockito.mock(ClusterVO.class);
    ArrayList<ClusterVO> arrayList = new ArrayList<ClusterVO>();
    arrayList.add(clusterVO);
    Mockito.when(_privateIpAddressDao.countIPs(anyLong(), anyLong(), anyBoolean())).thenReturn(0);
    Mockito.when(_volumeDao.findByPod(anyLong())).thenReturn(new ArrayList<VolumeVO>());
    Mockito.when(_hostDao.findByPodId(anyLong())).thenReturn(new ArrayList<HostVO>());
    Mockito.when(_vmInstanceDao.listByPodId(anyLong())).thenReturn(new ArrayList<VMInstanceVO>());
    Mockito.when(_clusterDao.listByPodId(anyLong())).thenReturn(arrayList);
    configurationMgr.checkIfPodIsDeletable(new Random().nextLong());
}
Also used : ClusterVO(com.cloud.dc.ClusterVO) Random(java.util.Random) VolumeVO(com.cloud.storage.VolumeVO) ArrayList(java.util.ArrayList) VMInstanceVO(com.cloud.vm.VMInstanceVO) HostPodVO(com.cloud.dc.HostPodVO) HostVO(com.cloud.host.HostVO) Test(org.junit.Test)

Example 32 with HostPodVO

use of com.cloud.dc.HostPodVO in project cloudstack by apache.

the class ConfigurationManagerTest method checkIfPodIsDeletableFailureOnHostTest.

@Test(expected = CloudRuntimeException.class)
public void checkIfPodIsDeletableFailureOnHostTest() {
    HostPodVO hostPodVO = Mockito.mock(HostPodVO.class);
    Mockito.when(hostPodVO.getDataCenterId()).thenReturn(new Random().nextLong());
    Mockito.when(_podDao.findById(anyLong())).thenReturn(hostPodVO);
    HostVO hostVO = Mockito.mock(HostVO.class);
    ArrayList<HostVO> arrayList = new ArrayList<HostVO>();
    arrayList.add(hostVO);
    Mockito.when(_privateIpAddressDao.countIPs(anyLong(), anyLong(), anyBoolean())).thenReturn(0);
    Mockito.when(_volumeDao.findByPod(anyLong())).thenReturn(new ArrayList<VolumeVO>());
    Mockito.when(_hostDao.findByPodId(anyLong())).thenReturn(arrayList);
    Mockito.when(_vmInstanceDao.listByPodId(anyLong())).thenReturn(new ArrayList<VMInstanceVO>());
    Mockito.when(_clusterDao.listByPodId(anyLong())).thenReturn(new ArrayList<ClusterVO>());
    configurationMgr.checkIfPodIsDeletable(new Random().nextLong());
}
Also used : ClusterVO(com.cloud.dc.ClusterVO) Random(java.util.Random) VolumeVO(com.cloud.storage.VolumeVO) ArrayList(java.util.ArrayList) VMInstanceVO(com.cloud.vm.VMInstanceVO) HostPodVO(com.cloud.dc.HostPodVO) HostVO(com.cloud.host.HostVO) Test(org.junit.Test)

Example 33 with HostPodVO

use of com.cloud.dc.HostPodVO in project cloudstack by apache.

the class FirstFitPlanner method orderClusters.

@Override
public List<Long> orderClusters(VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoid) throws InsufficientServerCapacityException {
    VirtualMachine vm = vmProfile.getVirtualMachine();
    DataCenter dc = dcDao.findById(vm.getDataCenterId());
    //check if datacenter is in avoid set
    if (avoid.shouldAvoid(dc)) {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("DataCenter id = '" + dc.getId() + "' provided is in avoid set, DeploymentPlanner cannot allocate the VM, returning.");
        }
        return null;
    }
    List<Long> clusterList = new ArrayList<Long>();
    if (plan.getClusterId() != null) {
        Long clusterIdSpecified = plan.getClusterId();
        s_logger.debug("Searching resources only under specified Cluster: " + clusterIdSpecified);
        ClusterVO cluster = clusterDao.findById(plan.getClusterId());
        if (cluster != null) {
            if (avoid.shouldAvoid(cluster)) {
                s_logger.debug("The specified cluster is in avoid set, returning.");
            } else {
                clusterList.add(clusterIdSpecified);
                removeClustersCrossingThreshold(clusterList, avoid, vmProfile, plan);
            }
        } else {
            s_logger.debug("The specified cluster cannot be found, returning.");
            avoid.addCluster(plan.getClusterId());
            return null;
        }
    } else if (plan.getPodId() != null) {
        //consider clusters under this pod only
        Long podIdSpecified = plan.getPodId();
        s_logger.debug("Searching resources only under specified Pod: " + podIdSpecified);
        HostPodVO pod = podDao.findById(podIdSpecified);
        if (pod != null) {
            if (avoid.shouldAvoid(pod)) {
                s_logger.debug("The specified pod is in avoid set, returning.");
            } else {
                clusterList = scanClustersForDestinationInZoneOrPod(podIdSpecified, false, vmProfile, plan, avoid);
                if (clusterList == null) {
                    avoid.addPod(plan.getPodId());
                }
            }
        } else {
            s_logger.debug("The specified Pod cannot be found, returning.");
            avoid.addPod(plan.getPodId());
            return null;
        }
    } else {
        s_logger.debug("Searching all possible resources under this Zone: " + plan.getDataCenterId());
        boolean applyAllocationAtPods = Boolean.parseBoolean(configDao.getValue(Config.ApplyAllocationAlgorithmToPods.key()));
        if (applyAllocationAtPods) {
            //start scan at all pods under this zone.
            clusterList = scanPodsForDestination(vmProfile, plan, avoid);
        } else {
            //start scan at clusters under this zone.
            clusterList = scanClustersForDestinationInZoneOrPod(plan.getDataCenterId(), true, vmProfile, plan, avoid);
        }
    }
    if (clusterList != null && !clusterList.isEmpty()) {
        ServiceOffering offering = vmProfile.getServiceOffering();
        // In case of non-GPU VMs, protect GPU enabled Hosts and prefer VM deployment on non-GPU Hosts.
        if ((serviceOfferingDetailsDao.findDetail(offering.getId(), GPU.Keys.vgpuType.toString()) == null) && !(hostGpuGroupsDao.listHostIds().isEmpty())) {
            int requiredCpu = offering.getCpu() * offering.getSpeed();
            long requiredRam = offering.getRamSize() * 1024L * 1024L;
            reorderClustersBasedOnImplicitTags(clusterList, requiredCpu, requiredRam);
        }
    }
    return clusterList;
}
Also used : DataCenter(com.cloud.dc.DataCenter) ClusterVO(com.cloud.dc.ClusterVO) ServiceOffering(com.cloud.offering.ServiceOffering) ArrayList(java.util.ArrayList) HostPodVO(com.cloud.dc.HostPodVO) VirtualMachine(com.cloud.vm.VirtualMachine)

Example 34 with HostPodVO

use of com.cloud.dc.HostPodVO in project cloudstack by apache.

the class CloudZonesStartupProcessor method updateSecondaryHost.

protected void updateSecondaryHost(final HostVO host, final StartupStorageCommand startup, final Host.Type type) throws AgentAuthnException {
    String zoneToken = startup.getDataCenter();
    if (zoneToken == null) {
        s_logger.warn("No Zone Token passed in, cannot not find zone for the agent");
        throw new AgentAuthnException("No Zone Token passed in, cannot not find zone for agent");
    }
    DataCenterVO zone = _zoneDao.findByToken(zoneToken);
    if (zone == null) {
        zone = _zoneDao.findByName(zoneToken);
        if (zone == null) {
            try {
                long zoneId = Long.parseLong(zoneToken);
                zone = _zoneDao.findById(zoneId);
                if (zone == null) {
                    throw new AgentAuthnException("Could not find zone for agent with token " + zoneToken);
                }
            } catch (NumberFormatException nfe) {
                throw new AgentAuthnException("Could not find zone for agent with token " + zoneToken);
            }
        }
    }
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Successfully loaded the DataCenter from the zone token passed in ");
    }
    //yes, routing
    HostPodVO pod = findPod(startup, zone.getId(), Host.Type.Routing);
    Long podId = null;
    if (pod != null) {
        s_logger.debug("Found pod " + pod.getName() + " for the secondary storage host " + startup.getName());
        podId = pod.getId();
    }
    host.setDataCenterId(zone.getId());
    host.setPodId(podId);
    host.setClusterId(null);
    host.setPrivateIpAddress(startup.getPrivateIpAddress());
    host.setPrivateNetmask(startup.getPrivateNetmask());
    host.setPrivateMacAddress(startup.getPrivateMacAddress());
    host.setPublicIpAddress(startup.getPublicIpAddress());
    host.setPublicMacAddress(startup.getPublicMacAddress());
    host.setPublicNetmask(startup.getPublicNetmask());
    host.setStorageIpAddress(startup.getStorageIpAddress());
    host.setStorageMacAddress(startup.getStorageMacAddress());
    host.setStorageNetmask(startup.getStorageNetmask());
    host.setVersion(startup.getVersion());
    host.setName(startup.getName());
    host.setType(type);
    host.setStorageUrl(startup.getIqn());
    host.setLastPinged(System.currentTimeMillis() >> 10);
    host.setCaps(null);
    host.setCpus(null);
    host.setTotalMemory(0);
    host.setSpeed(null);
    host.setParent(startup.getParent());
    host.setTotalSize(startup.getTotalSize());
    host.setHypervisorType(HypervisorType.None);
    if (startup.getNfsShare() != null) {
        host.setStorageUrl(startup.getNfsShare());
    }
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) AgentAuthnException(com.cloud.agent.manager.authn.AgentAuthnException) HostPodVO(com.cloud.dc.HostPodVO)

Example 35 with HostPodVO

use of com.cloud.dc.HostPodVO in project cloudstack by apache.

the class CloudZonesStartupProcessor method findPod.

private HostPodVO findPod(StartupCommand startup, long zoneId, Host.Type type) {
    HostPodVO pod = null;
    List<HostPodVO> podsInZone = _podDao.listByDataCenterId(zoneId);
    for (HostPodVO hostPod : podsInZone) {
        if (checkCIDR(type, hostPod, startup.getPrivateIpAddress(), startup.getPrivateNetmask())) {
            pod = hostPod;
            //found the default POD having the same subnet.
            updatePodNetmaskIfNeeded(pod, startup.getPrivateNetmask());
            break;
        }
    }
    return pod;
}
Also used : HostPodVO(com.cloud.dc.HostPodVO)

Aggregations

HostPodVO (com.cloud.dc.HostPodVO)68 DataCenterVO (com.cloud.dc.DataCenterVO)32 HostVO (com.cloud.host.HostVO)32 ClusterVO (com.cloud.dc.ClusterVO)31 ArrayList (java.util.ArrayList)29 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)23 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)16 VolumeVO (com.cloud.storage.VolumeVO)14 VMInstanceVO (com.cloud.vm.VMInstanceVO)14 Account (com.cloud.user.Account)13 DB (com.cloud.utils.db.DB)12 Test (org.junit.Test)12 Random (java.util.Random)11 TransactionStatus (com.cloud.utils.db.TransactionStatus)10 ConfigurationException (javax.naming.ConfigurationException)10 HashMap (java.util.HashMap)8 List (java.util.List)8 DataCenter (com.cloud.dc.DataCenter)7 DedicatedResourceVO (com.cloud.dc.DedicatedResourceVO)7 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)6