Search in sources :

Example 6 with HostPodVO

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

the class VolumeServiceTest method setUp.

@Test(priority = -1)
public void setUp() {
    ComponentContext.initComponentsLifeCycle();
    host = hostDao.findByGuid(this.getHostGuid());
    if (host != null) {
        dcId = host.getDataCenterId();
        clusterId = host.getClusterId();
        podId = host.getPodId();
        return;
    }
    // create data center
    DataCenterVO dc = new DataCenterVO(UUID.randomUUID().toString(), "test", "8.8.8.8", null, "10.0.0.1", null, "10.0.0.1/24", null, null, NetworkType.Basic, null, null, true, true, null, null);
    dc = dcDao.persist(dc);
    dcId = dc.getId();
    // create pod
    HostPodVO pod = new HostPodVO(UUID.randomUUID().toString(), dc.getId(), this.getHostGateway(), this.getHostCidr(), 8, "test");
    pod = podDao.persist(pod);
    podId = pod.getId();
    // create xenserver cluster
    ClusterVO cluster = new ClusterVO(dc.getId(), pod.getId(), "devcloud cluster");
    cluster.setHypervisorType(HypervisorType.XenServer.toString());
    cluster.setClusterType(ClusterType.CloudManaged);
    cluster.setManagedState(ManagedState.Managed);
    cluster = clusterDao.persist(cluster);
    clusterId = cluster.getId();
    // create xenserver host
    host = new HostVO(this.getHostGuid());
    host.setName("devcloud xenserver host");
    host.setType(Host.Type.Routing);
    host.setPrivateIpAddress(this.getHostIp());
    host.setDataCenterId(dc.getId());
    host.setVersion("6.0.1");
    host.setAvailable(true);
    host.setSetup(true);
    host.setPodId(podId);
    host.setLastPinged(0);
    host.setResourceState(ResourceState.Enabled);
    host.setHypervisorType(HypervisorType.XenServer);
    host.setClusterId(cluster.getId());
    host = hostDao.persist(host);
    imageStore = new ImageStoreVO();
    imageStore.setName("test");
    imageStore.setDataCenterId(dcId);
    imageStore.setProviderName("CloudStack ImageStore Provider");
    imageStore.setRole(DataStoreRole.Image);
    imageStore.setUrl(this.getSecondaryStorage());
    imageStore.setUuid(UUID.randomUUID().toString());
    imageStore = imageStoreDao.persist(imageStore);
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) ClusterVO(com.cloud.dc.ClusterVO) ImageStoreVO(org.apache.cloudstack.storage.datastore.db.ImageStoreVO) HostPodVO(com.cloud.dc.HostPodVO) HostVO(com.cloud.host.HostVO) Test(org.testng.annotations.Test)

Example 7 with HostPodVO

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

the class ExplicitDedicationProcessor method process.

/**
     * This method will process the affinity group of type 'Explicit Dedication' for a deployment of a VM that demands dedicated resources.
     * For ExplicitDedicationProcessor we need to add dedicated resources into the IncludeList based on the level we have dedicated resources available.
     * For eg. if admin dedicates a pod to a domain, then all the user in that domain can use the resources of that pod.
     * We need to take care of the situation when dedicated resources further have resources dedicated to sub-domain/account.
     * This IncludeList is then used to update the avoid list for a given data center.
     */
@Override
public void process(VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoid) throws AffinityConflictException {
    VirtualMachine vm = vmProfile.getVirtualMachine();
    List<AffinityGroupVMMapVO> vmGroupMappings = _affinityGroupVMMapDao.findByVmIdType(vm.getId(), getType());
    DataCenter dc = _dcDao.findById(vm.getDataCenterId());
    List<DedicatedResourceVO> resourceList = new ArrayList<DedicatedResourceVO>();
    if (vmGroupMappings != null && !vmGroupMappings.isEmpty()) {
        for (AffinityGroupVMMapVO vmGroupMapping : vmGroupMappings) {
            if (vmGroupMapping != null) {
                if (s_logger.isDebugEnabled()) {
                    s_logger.debug("Processing affinity group " + vmGroupMapping.getAffinityGroupId() + "of type 'ExplicitDedication' for VM Id: " + vm.getId());
                }
                long affinityGroupId = vmGroupMapping.getAffinityGroupId();
                List<DedicatedResourceVO> dr = _dedicatedDao.listByAffinityGroupId(affinityGroupId);
                resourceList.addAll(dr);
            }
        }
        boolean canUse = false;
        if (plan.getHostId() != null) {
            HostVO host = _hostDao.findById(plan.getHostId());
            ClusterVO clusterofHost = _clusterDao.findById(host.getClusterId());
            HostPodVO podOfHost = _podDao.findById(host.getPodId());
            DataCenterVO zoneOfHost = _dcDao.findById(host.getDataCenterId());
            if (resourceList != null && resourceList.size() != 0) {
                for (DedicatedResourceVO resource : resourceList) {
                    if ((resource.getHostId() != null && resource.getHostId().longValue() == plan.getHostId().longValue()) || (resource.getClusterId() != null && resource.getClusterId().longValue() == clusterofHost.getId()) || (resource.getPodId() != null && resource.getPodId().longValue() == podOfHost.getId()) || (resource.getDataCenterId() != null && resource.getDataCenterId().longValue() == zoneOfHost.getId())) {
                        canUse = true;
                    }
                }
            }
            if (!canUse) {
                throw new CloudRuntimeException("Cannot use this host " + host.getName() + " for explicit dedication");
            }
        } else if (plan.getClusterId() != null) {
            ClusterVO cluster = _clusterDao.findById(plan.getClusterId());
            HostPodVO podOfCluster = _podDao.findById(cluster.getPodId());
            DataCenterVO zoneOfCluster = _dcDao.findById(cluster.getDataCenterId());
            List<HostVO> hostToUse = new ArrayList<HostVO>();
            // check whether this cluster or its pod is dedicated
            if (resourceList != null && resourceList.size() != 0) {
                for (DedicatedResourceVO resource : resourceList) {
                    if ((resource.getClusterId() != null && resource.getClusterId() == cluster.getId()) || (resource.getPodId() != null && resource.getPodId() == podOfCluster.getId()) || (resource.getDataCenterId() != null && resource.getDataCenterId() == zoneOfCluster.getId())) {
                        canUse = true;
                    }
                    // cluster
                    if (!canUse) {
                        if (resource.getHostId() != null) {
                            HostVO dHost = _hostDao.findById(resource.getHostId());
                            if (dHost.getClusterId() == cluster.getId()) {
                                hostToUse.add(dHost);
                            }
                        }
                    }
                }
            }
            if (hostToUse.isEmpty() && !canUse) {
                throw new CloudRuntimeException("Cannot use this cluster " + cluster.getName() + " for explicit dedication");
            }
            if (hostToUse != null && hostToUse.size() != 0) {
                // add other non-dedicated hosts to avoid list
                List<HostVO> hostList = _hostDao.findByClusterId(cluster.getId());
                for (HostVO host : hostList) {
                    if (!hostToUse.contains(host)) {
                        avoid.addHost(host.getId());
                    }
                }
            }
        } else if (plan.getPodId() != null) {
            HostPodVO pod = _podDao.findById(plan.getPodId());
            DataCenterVO zoneOfPod = _dcDao.findById(pod.getDataCenterId());
            List<ClusterVO> clustersToUse = new ArrayList<ClusterVO>();
            List<HostVO> hostsToUse = new ArrayList<HostVO>();
            // check whether this cluster or its pod is dedicated
            if (resourceList != null && resourceList.size() != 0) {
                for (DedicatedResourceVO resource : resourceList) {
                    if ((resource.getPodId() != null && resource.getPodId() == pod.getId()) || (resource.getDataCenterId() != null && resource.getDataCenterId() == zoneOfPod.getId())) {
                        canUse = true;
                    }
                    // this pod
                    if (!canUse) {
                        if (resource.getClusterId() != null) {
                            ClusterVO dCluster = _clusterDao.findById(resource.getClusterId());
                            if (dCluster.getPodId() == pod.getId()) {
                                clustersToUse.add(dCluster);
                            }
                        }
                        if (resource.getHostId() != null) {
                            HostVO dHost = _hostDao.findById(resource.getHostId());
                            if (dHost.getPodId() == pod.getId()) {
                                hostsToUse.add(dHost);
                            }
                        }
                    }
                }
            }
            if (hostsToUse.isEmpty() && clustersToUse.isEmpty() && !canUse) {
                throw new CloudRuntimeException("Cannot use this pod " + pod.getName() + " for explicit dedication");
            }
            if (clustersToUse != null && clustersToUse.size() != 0) {
                // add other non-dedicated clusters to avoid list
                List<ClusterVO> clusterList = _clusterDao.listByPodId(pod.getId());
                for (ClusterVO cluster : clusterList) {
                    if (!clustersToUse.contains(cluster)) {
                        avoid.addCluster(cluster.getId());
                    }
                }
            }
            if (hostsToUse != null && hostsToUse.size() != 0) {
                // add other non-dedicated hosts to avoid list
                List<HostVO> hostList = _hostDao.findByPodId(pod.getId());
                for (HostVO host : hostList) {
                    if (!hostsToUse.contains(host)) {
                        avoid.addHost(host.getId());
                    }
                }
            }
        } else {
            // check all resources under this zone
            if (resourceList != null && resourceList.size() != 0) {
                avoid = updateAvoidList(resourceList, avoid, dc);
            } else {
                avoid.addDataCenter(dc.getId());
                if (s_logger.isDebugEnabled()) {
                    s_logger.debug("No dedicated resources available for this domain or account under this group");
                }
            }
            if (s_logger.isDebugEnabled()) {
                s_logger.debug("ExplicitDedicationProcessor returns Avoid List as: Deploy avoids pods: " + avoid.getPodsToAvoid() + ", clusters: " + avoid.getClustersToAvoid() + ", hosts: " + avoid.getHostsToAvoid());
            }
        }
    }
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) ClusterVO(com.cloud.dc.ClusterVO) ArrayList(java.util.ArrayList) HostPodVO(com.cloud.dc.HostPodVO) HostVO(com.cloud.host.HostVO) DataCenter(com.cloud.dc.DataCenter) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ArrayList(java.util.ArrayList) List(java.util.List) ExcludeList(com.cloud.deploy.DeploymentPlanner.ExcludeList) DedicatedResourceVO(com.cloud.dc.DedicatedResourceVO) VirtualMachine(com.cloud.vm.VirtualMachine)

Example 8 with HostPodVO

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

the class ExplicitDedicationProcessor method updateAvoidList.

private ExcludeList updateAvoidList(List<DedicatedResourceVO> dedicatedResources, ExcludeList avoidList, DataCenter dc) {
    ExcludeList includeList = new ExcludeList();
    for (DedicatedResourceVO dr : dedicatedResources) {
        if (dr.getHostId() != null) {
            includeList.addHost(dr.getHostId());
            HostVO dedicatedHost = _hostDao.findById(dr.getHostId());
            includeList.addCluster(dedicatedHost.getClusterId());
            includeList.addPod(dedicatedHost.getPodId());
        }
        if (dr.getClusterId() != null) {
            includeList.addCluster(dr.getClusterId());
            //add all hosts inside this in includeList
            List<HostVO> hostList = _hostDao.findByClusterId(dr.getClusterId());
            for (HostVO host : hostList) {
                DedicatedResourceVO dHost = _dedicatedDao.findByHostId(host.getId());
                if (dHost != null && !dedicatedResources.contains(dHost)) {
                    avoidList.addHost(host.getId());
                } else {
                    includeList.addHost(host.getId());
                }
            }
            ClusterVO dedicatedCluster = _clusterDao.findById(dr.getClusterId());
            includeList.addPod(dedicatedCluster.getPodId());
        }
        if (dr.getPodId() != null) {
            includeList.addPod(dr.getPodId());
            //add all cluster under this pod in includeList
            List<ClusterVO> clusterList = _clusterDao.listByPodId(dr.getPodId());
            for (ClusterVO cluster : clusterList) {
                DedicatedResourceVO dCluster = _dedicatedDao.findByClusterId(cluster.getId());
                if (dCluster != null && !dedicatedResources.contains(dCluster)) {
                    avoidList.addCluster(cluster.getId());
                } else {
                    includeList.addCluster(cluster.getId());
                }
            }
            //add all hosts inside this pod in includeList
            List<HostVO> hostList = _hostDao.findByPodId(dr.getPodId());
            for (HostVO host : hostList) {
                DedicatedResourceVO dHost = _dedicatedDao.findByHostId(host.getId());
                if (dHost != null && !dedicatedResources.contains(dHost)) {
                    avoidList.addHost(host.getId());
                } else {
                    includeList.addHost(host.getId());
                }
            }
        }
        if (dr.getDataCenterId() != null) {
            includeList.addDataCenter(dr.getDataCenterId());
            //add all Pod under this data center in includeList
            List<HostPodVO> podList = _podDao.listByDataCenterId(dr.getDataCenterId());
            for (HostPodVO pod : podList) {
                DedicatedResourceVO dPod = _dedicatedDao.findByPodId(pod.getId());
                if (dPod != null && !dedicatedResources.contains(dPod)) {
                    avoidList.addPod(pod.getId());
                } else {
                    includeList.addPod(pod.getId());
                }
            }
            List<ClusterVO> clusterList = _clusterDao.listClustersByDcId(dr.getDataCenterId());
            for (ClusterVO cluster : clusterList) {
                DedicatedResourceVO dCluster = _dedicatedDao.findByClusterId(cluster.getId());
                if (dCluster != null && !dedicatedResources.contains(dCluster)) {
                    avoidList.addCluster(cluster.getId());
                } else {
                    includeList.addCluster(cluster.getId());
                }
            }
            //add all hosts inside this in includeList
            List<HostVO> hostList = _hostDao.listByDataCenterId(dr.getDataCenterId());
            for (HostVO host : hostList) {
                DedicatedResourceVO dHost = _dedicatedDao.findByHostId(host.getId());
                if (dHost != null && !dedicatedResources.contains(dHost)) {
                    avoidList.addHost(host.getId());
                } else {
                    includeList.addHost(host.getId());
                }
            }
        }
    }
    //Update avoid list using includeList.
    //add resources in avoid list which are not in include list.
    List<HostPodVO> pods = _podDao.listByDataCenterId(dc.getId());
    List<ClusterVO> clusters = _clusterDao.listClustersByDcId(dc.getId());
    List<HostVO> hosts = _hostDao.listByDataCenterId(dc.getId());
    Set<Long> podsInIncludeList = includeList.getPodsToAvoid();
    Set<Long> clustersInIncludeList = includeList.getClustersToAvoid();
    Set<Long> hostsInIncludeList = includeList.getHostsToAvoid();
    for (HostPodVO pod : pods) {
        if (podsInIncludeList != null && !podsInIncludeList.contains(pod.getId())) {
            avoidList.addPod(pod.getId());
        }
    }
    for (ClusterVO cluster : clusters) {
        if (clustersInIncludeList != null && !clustersInIncludeList.contains(cluster.getId())) {
            avoidList.addCluster(cluster.getId());
        }
    }
    for (HostVO host : hosts) {
        if (hostsInIncludeList != null && !hostsInIncludeList.contains(host.getId())) {
            avoidList.addHost(host.getId());
        }
    }
    return avoidList;
}
Also used : ExcludeList(com.cloud.deploy.DeploymentPlanner.ExcludeList) ClusterVO(com.cloud.dc.ClusterVO) DedicatedResourceVO(com.cloud.dc.DedicatedResourceVO) HostPodVO(com.cloud.dc.HostPodVO) HostVO(com.cloud.host.HostVO)

Example 9 with HostPodVO

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

the class HighAvailabilityManagerImpl method scheduleRestartForVmsOnHost.

@Override
public void scheduleRestartForVmsOnHost(final HostVO host, boolean investigate) {
    if (host.getType() != Host.Type.Routing) {
        return;
    }
    if (host.getHypervisorType() == HypervisorType.VMware || host.getHypervisorType() == HypervisorType.Hyperv) {
        s_logger.info("Don't restart VMs on host " + host.getId() + " as it is a " + host.getHypervisorType().toString() + " host");
        return;
    }
    s_logger.warn("Scheduling restart for VMs on host " + host.getId() + "-" + host.getName());
    final List<VMInstanceVO> vms = _instanceDao.listByHostId(host.getId());
    final DataCenterVO dcVO = _dcDao.findById(host.getDataCenterId());
    // send an email alert that the host is down
    StringBuilder sb = null;
    List<VMInstanceVO> reorderedVMList = new ArrayList<VMInstanceVO>();
    if ((vms != null) && !vms.isEmpty()) {
        sb = new StringBuilder();
        sb.append("  Starting HA on the following VMs:");
        // collect list of vm names for the alert email
        for (int i = 0; i < vms.size(); i++) {
            VMInstanceVO vm = vms.get(i);
            if (vm.getType() == VirtualMachine.Type.User) {
                reorderedVMList.add(vm);
            } else {
                reorderedVMList.add(0, vm);
            }
            if (vm.isHaEnabled()) {
                sb.append(" " + vm.getHostName());
            }
        }
    }
    // send an email alert that the host is down, include VMs
    HostPodVO podVO = _podDao.findById(host.getPodId());
    String hostDesc = "name: " + host.getName() + " (id:" + host.getId() + "), availability zone: " + dcVO.getName() + ", pod: " + podVO.getName();
    _alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_HOST, host.getDataCenterId(), host.getPodId(), "Host is down, " + hostDesc, "Host [" + hostDesc + "] is down." + ((sb != null) ? sb.toString() : ""));
    for (VMInstanceVO vm : reorderedVMList) {
        ServiceOfferingVO vmOffering = _serviceOfferingDao.findById(vm.getServiceOfferingId());
        if (vmOffering.getUseLocalStorage()) {
            if (s_logger.isDebugEnabled()) {
                s_logger.debug("Skipping HA on vm " + vm + ", because it uses local storage. Its fate is tied to the host.");
            }
            continue;
        }
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("Notifying HA Mgr of to restart vm " + vm.getId() + "-" + vm.getInstanceName());
        }
        vm = _instanceDao.findByUuid(vm.getUuid());
        Long hostId = vm.getHostId();
        if (hostId != null && !hostId.equals(host.getId())) {
            s_logger.debug("VM " + vm.getInstanceName() + " is not on down host " + host.getId() + " it is on other host " + hostId + " VM HA is done");
            continue;
        }
        scheduleRestart(vm, investigate);
    }
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) ArrayList(java.util.ArrayList) VMInstanceVO(com.cloud.vm.VMInstanceVO) HostPodVO(com.cloud.dc.HostPodVO) ServiceOfferingVO(com.cloud.service.ServiceOfferingVO)

Example 10 with HostPodVO

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

the class EndpointSelectorTest method setUp.

@Before
public void setUp() {
    // create data center
    DataCenterVO dc = new DataCenterVO(UUID.randomUUID().toString(), "test", "8.8.8.8", null, "10.0.0.1", null, "10.0.0.1/24", null, null, DataCenter.NetworkType.Basic, null, null, true, true, null, null);
    dc = dcDao.persist(dc);
    dcId = dc.getId();
    // create pod
    HostPodVO pod = new HostPodVO(UUID.randomUUID().toString(), dc.getId(), "10.223.0.1", "10.233.2.2/25", 8, "test");
    pod = podDao.persist(pod);
    podId = pod.getId();
    // create xenserver cluster
    ClusterVO cluster = new ClusterVO(dc.getId(), pod.getId(), "devcloud cluster");
    cluster.setHypervisorType(Hypervisor.HypervisorType.XenServer.toString());
    cluster.setClusterType(Cluster.ClusterType.CloudManaged);
    cluster.setManagedState(Managed.ManagedState.Managed);
    cluster = clusterDao.persist(cluster);
    clusterId = cluster.getId();
    imageStore = new ImageStoreVO();
    imageStore.setName(UUID.randomUUID().toString());
    imageStore.setDataCenterId(dcId);
    imageStore.setProviderName(DataStoreProvider.NFS_IMAGE);
    imageStore.setRole(DataStoreRole.Image);
    imageStore.setUrl(UUID.randomUUID().toString());
    imageStore.setUuid(UUID.randomUUID().toString());
    imageStore.setProtocol("nfs");
    imageStore = imageStoreDao.persist(imageStore);
    when(primaryDataStoreProvider.configure(Matchers.anyMap())).thenReturn(true);
    Set<DataStoreProvider.DataStoreProviderType> types = new HashSet<DataStoreProvider.DataStoreProviderType>();
    types.add(DataStoreProvider.DataStoreProviderType.PRIMARY);
    when(primaryDataStoreProvider.getTypes()).thenReturn(types);
    when(primaryDataStoreProvider.getName()).thenReturn(DataStoreProvider.DEFAULT_PRIMARY);
    when(primaryDataStoreProvider.getDataStoreDriver()).thenReturn(driver);
    User user = mock(User.class);
    when(user.getId()).thenReturn(1L);
    Account account = mock(Account.class);
    when(account.getId()).thenReturn(1L);
    when(accountManager.getSystemAccount()).thenReturn(account);
    when(accountManager.getSystemUser()).thenReturn(user);
    if (Merovingian2.getLockMaster() == null) {
        _lockMaster = Merovingian2.createLockMaster(1234);
    } else {
        _lockMaster = Merovingian2.getLockMaster();
    }
    _lockMaster.cleanupThisServer();
    ComponentContext.initComponentsLifeCycle();
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) Account(com.cloud.user.Account) ClusterVO(com.cloud.dc.ClusterVO) User(com.cloud.user.User) PrimaryDataStoreProvider(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreProvider) DataStoreProvider(org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProvider) ImageStoreVO(org.apache.cloudstack.storage.datastore.db.ImageStoreVO) HostPodVO(com.cloud.dc.HostPodVO) HashSet(java.util.HashSet) Before(org.junit.Before)

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