Search in sources :

Example 21 with DataCenterDeployment

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

the class ConsoleProxyManagerImpl method createProxyInstance.

protected Map<String, Object> createProxyInstance(long dataCenterId, VMTemplateVO template) throws ConcurrentOperationException {
    long id = consoleProxyDao.getNextInSequence(Long.class, "id");
    String name = VirtualMachineName.getConsoleProxyName(id, instance);
    DataCenterVO dc = dataCenterDao.findById(dataCenterId);
    Account systemAcct = accountManager.getSystemAccount();
    DataCenterDeployment plan = new DataCenterDeployment(dataCenterId);
    NetworkVO defaultNetwork = getDefaultNetworkForCreation(dc);
    List<? extends NetworkOffering> offerings = networkModel.getSystemAccountNetworkOfferings(NetworkOffering.SystemControlNetwork, NetworkOffering.SystemManagementNetwork);
    LinkedHashMap<Network, List<? extends NicProfile>> networks = new LinkedHashMap<>(offerings.size() + 1);
    NicProfile defaultNic = new NicProfile();
    defaultNic.setDefaultNic(true);
    defaultNic.setDeviceId(2);
    networks.put(networkOrchestrationService.setupNetwork(systemAcct, networkOfferingDao.findById(defaultNetwork.getNetworkOfferingId()), plan, null, null, false).get(0), new ArrayList<>(Arrays.asList(defaultNic)));
    for (NetworkOffering offering : offerings) {
        networks.put(networkOrchestrationService.setupNetwork(systemAcct, offering, plan, null, null, false).get(0), new ArrayList<>());
    }
    ServiceOfferingVO serviceOffering = serviceOfferingVO;
    if (serviceOffering == null) {
        serviceOffering = serviceOfferingDao.findDefaultSystemOffering(ServiceOffering.consoleProxyDefaultOffUniqueName, ConfigurationManagerImpl.SystemVMUseLocalStorage.valueIn(dataCenterId));
    }
    ConsoleProxyVO proxy = new ConsoleProxyVO(id, serviceOffering.getId(), name, template.getId(), template.getHypervisorType(), template.getGuestOSId(), dataCenterId, systemAcct.getDomainId(), systemAcct.getId(), accountManager.getSystemUser().getId(), 0, serviceOffering.isOfferHA());
    proxy.setDynamicallyScalable(template.isDynamicallyScalable());
    proxy = consoleProxyDao.persist(proxy);
    try {
        virtualMachineManager.allocate(name, template, serviceOffering, networks, plan, null);
    } catch (InsufficientCapacityException e) {
        String message = String.format("Unable to allocate proxy [%s] on zone [%s] due to [%s].", proxy.toString(), dataCenterId, e.getMessage());
        s_logger.warn(message, e);
        throw new CloudRuntimeException(message, e);
    }
    Map<String, Object> context = new HashMap<>();
    context.put("dc", dc);
    HostPodVO pod = hostPodDao.findById(proxy.getPodIdToDeployIn());
    context.put("pod", pod);
    context.put("proxyVmId", proxy.getId());
    return context;
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) Account(com.cloud.user.Account) NetworkVO(com.cloud.network.dao.NetworkVO) DataCenterDeployment(com.cloud.deploy.DataCenterDeployment) NetworkOffering(com.cloud.offering.NetworkOffering) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) NicProfile(com.cloud.vm.NicProfile) ServiceOfferingVO(com.cloud.service.ServiceOfferingVO) HostPodVO(com.cloud.dc.HostPodVO) LinkedHashMap(java.util.LinkedHashMap) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Network(com.cloud.network.Network) ArrayList(java.util.ArrayList) List(java.util.List) ConsoleProxyVO(com.cloud.vm.ConsoleProxyVO) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException)

Example 22 with DataCenterDeployment

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

the class ManagementServerImpl method findAllSuitableStoragePoolsForVm.

/**
 *  Looks for all suitable storage pools to allocate the given volume.
 *  We take into account the service offering of the VM and volume to find suitable storage pools. It is also excluded from the search the current storage pool used by the volume.
 *  We use {@link StoragePoolAllocator} to look for possible storage pools to allocate the given volume. We will look for possible local storage poosl even if the volume is using a shared storage disk offering.
 *
 *  Side note: the idea behind this method is to provide power for administrators of manually overriding deployments defined by CloudStack.
 */
private List<StoragePool> findAllSuitableStoragePoolsForVm(final VolumeVO volume, Long diskOfferingId, Long newSize, Long newMinIops, Long newMaxIops, VMInstanceVO vm, Host vmHost, ExcludeList avoid, Cluster srcCluster, HypervisorType hypervisorType) {
    List<StoragePool> suitablePools = new ArrayList<>();
    Long clusterId = null;
    Long podId = null;
    if (srcCluster != null) {
        clusterId = srcCluster.getId();
        podId = srcCluster.getPodId();
    }
    DataCenterDeployment plan = new DataCenterDeployment(volume.getDataCenterId(), podId, clusterId, null, null, null, null);
    VirtualMachineProfile profile = new VirtualMachineProfileImpl(vm);
    // OfflineVmwareMigration: vm might be null here; deal!
    DiskOfferingVO diskOffering = _diskOfferingDao.findById(diskOfferingId);
    DiskProfile diskProfile = new DiskProfile(volume, diskOffering, hypervisorType);
    if (!Objects.equals(volume.getDiskOfferingId(), diskOfferingId)) {
        diskProfile.setSize(newSize);
        diskProfile.setMinIops(newMinIops);
        diskProfile.setMaxIops(newMaxIops);
    }
    for (StoragePoolAllocator allocator : _storagePoolAllocators) {
        List<StoragePool> pools = allocator.allocateToPool(diskProfile, profile, plan, avoid, StoragePoolAllocator.RETURN_UPTO_ALL, true);
        if (CollectionUtils.isEmpty(pools)) {
            continue;
        }
        for (StoragePool pool : pools) {
            boolean isLocalPoolSameHostAsVmHost = pool.isLocal() && (vmHost == null || StringUtils.equals(vmHost.getPrivateIpAddress(), pool.getHostAddress()));
            if (isLocalPoolSameHostAsVmHost || pool.isShared()) {
                suitablePools.add(pool);
            }
        }
    }
    return suitablePools;
}
Also used : StoragePool(com.cloud.storage.StoragePool) DataCenterDeployment(com.cloud.deploy.DataCenterDeployment) VirtualMachineProfileImpl(com.cloud.vm.VirtualMachineProfileImpl) DiskOfferingVO(com.cloud.storage.DiskOfferingVO) ArrayList(java.util.ArrayList) VirtualMachineProfile(com.cloud.vm.VirtualMachineProfile) DiskProfile(com.cloud.vm.DiskProfile) StoragePoolAllocator(org.apache.cloudstack.engine.subsystem.api.storage.StoragePoolAllocator)

Example 23 with DataCenterDeployment

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

the class ManagementServerImpl method hasSuitablePoolsForVolume.

private boolean hasSuitablePoolsForVolume(final VolumeVO volume, final Host host, final VirtualMachineProfile vmProfile) {
    final DiskOfferingVO diskOffering = _diskOfferingDao.findById(volume.getDiskOfferingId());
    final DiskProfile diskProfile = new DiskProfile(volume, diskOffering, vmProfile.getHypervisorType());
    final DataCenterDeployment plan = new DataCenterDeployment(host.getDataCenterId(), host.getPodId(), host.getClusterId(), host.getId(), null, null);
    final ExcludeList avoid = new ExcludeList();
    for (final StoragePoolAllocator allocator : _storagePoolAllocators) {
        final List<StoragePool> poolList = allocator.allocateToPool(diskProfile, vmProfile, plan, avoid, 1);
        if (poolList != null && !poolList.isEmpty()) {
            return true;
        }
    }
    return false;
}
Also used : ExcludeList(com.cloud.deploy.DeploymentPlanner.ExcludeList) DataCenterDeployment(com.cloud.deploy.DataCenterDeployment) StoragePool(com.cloud.storage.StoragePool) DiskOfferingVO(com.cloud.storage.DiskOfferingVO) DiskProfile(com.cloud.vm.DiskProfile) StoragePoolAllocator(org.apache.cloudstack.engine.subsystem.api.storage.StoragePoolAllocator)

Example 24 with DataCenterDeployment

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

the class FirstFitPlannerTest method checkClusterReorderingForStartVMWithThresholdCheckDisabled.

@Test
public void checkClusterReorderingForStartVMWithThresholdCheckDisabled() throws InsufficientServerCapacityException {
    VirtualMachineProfileImpl vmProfile = mock(VirtualMachineProfileImpl.class);
    DataCenterDeployment plan = mock(DataCenterDeployment.class);
    ExcludeList avoids = mock(ExcludeList.class);
    initializeForTest(vmProfile, plan, avoids);
    List<Long> clustersCrossingThreshold = initializeForClusterThresholdDisabled();
    List<Long> clusterList = planner.orderClusters(vmProfile, plan, avoids);
    assertTrue("Reordered cluster list does not have clusters exceeding threshold", (clusterList.containsAll(clustersCrossingThreshold)));
}
Also used : ExcludeList(com.cloud.deploy.DeploymentPlanner.ExcludeList) DataCenterDeployment(com.cloud.deploy.DataCenterDeployment) Test(org.junit.Test)

Example 25 with DataCenterDeployment

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

the class ResourceManagerImpl method migrateAwayVmWithVolumes.

/**
 * Looks for Hosts able to allocate the VM and migrates the VM with its volume.
 */
private void migrateAwayVmWithVolumes(HostVO host, VMInstanceVO vm) {
    final DataCenterDeployment plan = new DataCenterDeployment(host.getDataCenterId(), host.getPodId(), host.getClusterId(), null, null, null);
    ServiceOfferingVO offeringVO = serviceOfferingDao.findById(vm.getServiceOfferingId());
    final VirtualMachineProfile profile = new VirtualMachineProfileImpl(vm, null, offeringVO, null, null);
    plan.setMigrationPlan(true);
    DeployDestination dest = null;
    try {
        dest = deploymentManager.planDeployment(profile, plan, new DeploymentPlanner.ExcludeList(), null);
    } catch (InsufficientServerCapacityException e) {
        throw new CloudRuntimeException(String.format("Maintenance failed, could not find deployment destination for VM [id=%s, name=%s].", vm.getId(), vm.getInstanceName()), e);
    }
    Host destHost = dest.getHost();
    try {
        _vmMgr.migrateWithStorage(vm.getUuid(), host.getId(), destHost.getId(), null);
    } catch (ResourceUnavailableException e) {
        throw new CloudRuntimeException(String.format("Maintenance failed, could not migrate VM [id=%s, name=%s] with local storage from host [id=%s, name=%s] to host [id=%s, name=%s].", vm.getId(), vm.getInstanceName(), host.getId(), host.getName(), destHost.getId(), destHost.getName()), e);
    }
}
Also used : DataCenterDeployment(com.cloud.deploy.DataCenterDeployment) VirtualMachineProfileImpl(com.cloud.vm.VirtualMachineProfileImpl) DeployDestination(com.cloud.deploy.DeployDestination) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) InsufficientServerCapacityException(com.cloud.exception.InsufficientServerCapacityException) Host(com.cloud.host.Host) VirtualMachineProfile(com.cloud.vm.VirtualMachineProfile) ServiceOfferingVO(com.cloud.service.ServiceOfferingVO)

Aggregations

DataCenterDeployment (com.cloud.deploy.DataCenterDeployment)87 ExcludeList (com.cloud.deploy.DeploymentPlanner.ExcludeList)45 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)34 Test (org.junit.Test)28 ArrayList (java.util.ArrayList)26 StoragePool (com.cloud.storage.StoragePool)25 VirtualMachineProfileImpl (com.cloud.vm.VirtualMachineProfileImpl)24 VirtualMachineProfile (com.cloud.vm.VirtualMachineProfile)18 HashMap (java.util.HashMap)18 DeployDestination (com.cloud.deploy.DeployDestination)16 ServiceOfferingVO (com.cloud.service.ServiceOfferingVO)16 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)15 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)15 InsufficientServerCapacityException (com.cloud.exception.InsufficientServerCapacityException)15 Host (com.cloud.host.Host)15 VolumeVO (com.cloud.storage.VolumeVO)15 Account (com.cloud.user.Account)15 DiskProfile (com.cloud.vm.DiskProfile)15 LinkedHashMap (java.util.LinkedHashMap)15 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)14