Search in sources :

Example 6 with Pod

use of com.cloud.legacymodel.dc.Pod in project cosmic by MissionCriticalCloud.

the class UpdatePodCmd method execute.

// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() {
    final Pod result = _configService.editPod(this);
    if (result != null) {
        final PodResponse response = _responseGenerator.createPodResponse(result, false);
        response.setResponseName(getCommandName());
        this.setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update pod");
    }
}
Also used : Pod(com.cloud.legacymodel.dc.Pod) ServerApiException(com.cloud.api.ServerApiException) PodResponse(com.cloud.api.response.PodResponse)

Example 7 with Pod

use of com.cloud.legacymodel.dc.Pod in project cosmic by MissionCriticalCloud.

the class CreatePodCmd method execute.

// ///////////////////////////////////////////////////
// ///////////////// Accessors ///////////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() {
    final Pod result = _configService.createPod(getZoneId(), getPodName(), getStartIp(), getEndIp(), getGateway(), getNetmask(), getAllocationState());
    if (result != null) {
        final PodResponse response = _responseGenerator.createPodResponse(result, false);
        response.setResponseName(getCommandName());
        this.setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create pod");
    }
}
Also used : Pod(com.cloud.legacymodel.dc.Pod) ServerApiException(com.cloud.api.ServerApiException) PodResponse(com.cloud.api.response.PodResponse)

Example 8 with Pod

use of com.cloud.legacymodel.dc.Pod in project cosmic by MissionCriticalCloud.

the class ListPodsByCmd method execute.

// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() {
    final Pair<List<? extends Pod>, Integer> result = _mgr.searchForPods(this);
    final ListResponse<PodResponse> response = new ListResponse<>();
    final List<PodResponse> podResponses = new ArrayList<>();
    for (final Pod pod : result.first()) {
        final PodResponse podResponse = _responseGenerator.createPodResponse(pod, showCapacities);
        podResponse.setObjectName("pod");
        podResponses.add(podResponse);
    }
    response.setResponses(podResponses, result.second());
    response.setResponseName(getCommandName());
    this.setResponseObject(response);
}
Also used : Pod(com.cloud.legacymodel.dc.Pod) ListResponse(com.cloud.api.response.ListResponse) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) PodResponse(com.cloud.api.response.PodResponse)

Example 9 with Pod

use of com.cloud.legacymodel.dc.Pod in project cosmic by MissionCriticalCloud.

the class DeploymentPlanningManagerImpl method checkClustersforDestination.

// /refactoring planner methods
private DeployDestination checkClustersforDestination(final List<Long> clusterList, final VirtualMachineProfile vmProfile, final DeploymentPlan plan, final ExcludeList avoid, final Zone zone, final DeploymentPlanner.PlannerResourceUsage resourceUsageRequired, final ExcludeList plannerAvoidOutput) {
    if (s_logger.isTraceEnabled()) {
        s_logger.trace("ClusterId List to consider: " + clusterList);
    }
    for (final Long clusterId : clusterList) {
        final ClusterVO clusterVO = _clusterDao.findById(clusterId);
        if (clusterVO.getHypervisorType() != vmProfile.getHypervisorType()) {
            s_logger.debug("Cluster: " + clusterId + " has HyperVisorType that does not match the VM, skipping this cluster");
            avoid.addCluster(clusterVO.getId());
            continue;
        }
        s_logger.debug("Checking resources in Cluster: " + clusterId + " under Pod: " + clusterVO.getPodId());
        // search for resources(hosts and storage) under this zone, pod,
        // cluster.
        final DataCenterDeployment potentialPlan = new DataCenterDeployment(plan.getDataCenterId(), clusterVO.getPodId(), clusterVO.getId(), null, plan.getPoolId(), null, plan.getReservationContext());
        // find suitable hosts under this cluster, need as many hosts as we
        // get.
        final List<Host> suitableHosts = findSuitableHosts(vmProfile, potentialPlan, avoid, HostAllocator.RETURN_UPTO_ALL);
        // pools for each volume of the VM
        if (suitableHosts != null && !suitableHosts.isEmpty()) {
            final Pair<Map<Volume, List<StoragePool>>, List<Volume>> result = findSuitablePoolsForVolumes(vmProfile, potentialPlan, avoid, StoragePoolAllocator.RETURN_UPTO_ALL);
            final Map<Volume, List<StoragePool>> suitableVolumeStoragePools = result.first();
            final List<Volume> readyAndReusedVolumes = result.second();
            // choose the potential host and pool for the VM
            if (!suitableVolumeStoragePools.isEmpty()) {
                final Pair<Host, Map<Volume, StoragePool>> potentialResources = findPotentialDeploymentResources(suitableHosts, suitableVolumeStoragePools, avoid, resourceUsageRequired, readyAndReusedVolumes);
                if (potentialResources != null) {
                    final Pod pod = _podDao.findById(clusterVO.getPodId());
                    final Host host = _hostDao.findById(potentialResources.first().getId());
                    final Map<Volume, StoragePool> storageVolMap = potentialResources.second();
                    // we don't have to prepare this volume.
                    for (final Volume vol : readyAndReusedVolumes) {
                        storageVolMap.remove(vol);
                    }
                    final DeployDestination dest = new DeployDestination(zone, pod, clusterVO, host, storageVolMap);
                    s_logger.debug("Returning Deployment Destination: " + dest);
                    return dest;
                }
            } else {
                s_logger.debug("No suitable storagePools found under this Cluster: " + clusterId);
            }
        } else {
            s_logger.debug("No suitable hosts found under this Cluster: " + clusterId);
        }
        if (canAvoidCluster(clusterVO, avoid, plannerAvoidOutput, vmProfile)) {
            avoid.addCluster(clusterVO.getId());
        }
    }
    s_logger.debug("Could not find suitable Deployment Destination for this VM under any clusters, returning. ");
    return null;
}
Also used : ClusterVO(com.cloud.dc.ClusterVO) StoragePool(com.cloud.legacymodel.storage.StoragePool) Pod(com.cloud.legacymodel.dc.Pod) Host(com.cloud.legacymodel.dc.Host) Volume(com.cloud.legacymodel.storage.Volume) ArrayList(java.util.ArrayList) ExcludeList(com.cloud.deploy.DeploymentPlanner.ExcludeList) List(java.util.List) Map(java.util.Map) HashMap(java.util.HashMap)

Example 10 with Pod

use of com.cloud.legacymodel.dc.Pod in project cosmic by MissionCriticalCloud.

the class DeploymentPlanningManagerImpl method planDeployment.

@Override
public DeployDestination planDeployment(final VirtualMachineProfile vmProfile, final DeploymentPlan plan, final ExcludeList avoids, DeploymentPlanner planner) throws InsufficientServerCapacityException {
    // call affinitygroup chain
    final VirtualMachine vm = vmProfile.getVirtualMachine();
    final long vmGroupCount = _affinityGroupVMMapDao.countAffinityGroupsForVm(vm.getId());
    final Zone zone = zoneRepository.findById(vm.getDataCenterId()).orElse(null);
    if (vmGroupCount > 0) {
        for (final AffinityGroupProcessor processor : _affinityProcessors) {
            processor.process(vmProfile, plan, avoids);
        }
    }
    if (vm.getType() == VirtualMachineType.User || vm.getType() == VirtualMachineType.DomainRouter) {
        checkForNonDedicatedResources(vmProfile, zone, avoids);
    }
    s_logger.debug("Deployment will {}", avoids.toString());
    // check if datacenter is in avoid set
    if (avoids.shouldAvoid(zone)) {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("DataCenter id = '" + zone.getId() + "' provided is in avoid set, DeploymentPlanner cannot allocate the VM, returning.");
        }
        return null;
    }
    final ServiceOffering offering = vmProfile.getServiceOffering();
    if (planner == null) {
        String plannerName = offering.getDeploymentPlanner();
        if (plannerName == null) {
            plannerName = _configDao.getValue(Config.VmDeploymentPlanner.key());
        }
        planner = getDeploymentPlannerByName(plannerName);
    }
    final int cpu_requested = offering.getCpu();
    final long ram_requested = offering.getRamSize() * 1024L * 1024L;
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("DeploymentPlanner allocation algorithm: " + planner);
        s_logger.debug("Trying to allocate a host and storage pools from zone:" + plan.getDataCenterId() + ", pod:" + plan.getPodId() + ",cluster:" + plan.getClusterId() + ", requested cpu: " + cpu_requested + ", requested ram: " + ram_requested);
        s_logger.debug("Is ROOT volume READY (pool already allocated)?: " + (plan.getPoolId() != null ? "Yes" : "No"));
    }
    final String haVmTag = (String) vmProfile.getParameter(VirtualMachineProfile.Param.HaTag);
    if (plan.getHostId() != null && haVmTag == null) {
        final Long hostIdSpecified = plan.getHostId();
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("DeploymentPlan has host_id specified, choosing this host and making no checks on this host: " + hostIdSpecified);
        }
        final HostVO host = _hostDao.findById(hostIdSpecified);
        if (host == null) {
            s_logger.debug("The specified host cannot be found");
        } else if (avoids.shouldAvoid(host)) {
            s_logger.debug("The specified host is in avoid set");
        } else {
            if (s_logger.isDebugEnabled()) {
                s_logger.debug("Looking for suitable pools for this host under zone: " + host.getDataCenterId() + ", pod: " + host.getPodId() + ", cluster: " + host.getClusterId());
            }
            Pod pod = _podDao.findById(host.getPodId());
            Cluster cluster = _clusterDao.findById(host.getClusterId());
            // search for storage under the zone, pod, cluster of the host.
            final DataCenterDeployment lastPlan = new DataCenterDeployment(host.getDataCenterId(), host.getPodId(), host.getClusterId(), hostIdSpecified, plan.getPoolId(), null, plan.getReservationContext());
            final Pair<Map<Volume, List<StoragePool>>, List<Volume>> result = findSuitablePoolsForVolumes(vmProfile, lastPlan, avoids, HostAllocator.RETURN_UPTO_ALL);
            final Map<Volume, List<StoragePool>> suitableVolumeStoragePools = result.first();
            final List<Volume> readyAndReusedVolumes = result.second();
            // choose the potential pool for this VM for this host
            if (!suitableVolumeStoragePools.isEmpty()) {
                final List<Host> suitableHosts = new ArrayList<>();
                suitableHosts.add(host);
                final Pair<Host, Map<Volume, StoragePool>> potentialResources = findPotentialDeploymentResources(suitableHosts, suitableVolumeStoragePools, avoids, getPlannerUsage(planner, vmProfile, plan, avoids), readyAndReusedVolumes);
                if (potentialResources != null) {
                    pod = _podDao.findById(host.getPodId());
                    cluster = _clusterDao.findById(host.getClusterId());
                    final Map<Volume, StoragePool> storageVolMap = potentialResources.second();
                    // we don't have to prepare this volume.
                    for (final Volume vol : readyAndReusedVolumes) {
                        storageVolMap.remove(vol);
                    }
                    final DeployDestination dest = new DeployDestination(zone, pod, cluster, host, storageVolMap);
                    s_logger.debug("Returning Deployment Destination: " + dest);
                    return dest;
                }
            }
        }
        s_logger.debug("Cannot deploy to specified host, returning.");
        return null;
    }
    DeployDestination dest = null;
    List<Long> clusterList = null;
    if (planner != null && planner.canHandle(vmProfile, plan, avoids)) {
        while (true) {
            if (planner instanceof DeploymentClusterPlanner) {
                final ExcludeList plannerAvoidInput = new ExcludeList(avoids.getZonesToAvoid(), avoids.getPodsToAvoid(), avoids.getClustersToAvoid(), avoids.getHostsToAvoid(), avoids.getPoolsToAvoid());
                clusterList = ((DeploymentClusterPlanner) planner).orderClusters(vmProfile, plan, avoids);
                if (clusterList != null && !clusterList.isEmpty()) {
                    // planner refactoring. call allocators to list hosts
                    final ExcludeList plannerAvoidOutput = new ExcludeList(avoids.getZonesToAvoid(), avoids.getPodsToAvoid(), avoids.getClustersToAvoid(), avoids.getHostsToAvoid(), avoids.getPoolsToAvoid());
                    resetAvoidSet(plannerAvoidOutput, plannerAvoidInput);
                    dest = checkClustersforDestination(clusterList, vmProfile, plan, avoids, zone, getPlannerUsage(planner, vmProfile, plan, avoids), plannerAvoidOutput);
                    if (dest != null) {
                        return dest;
                    }
                    // reset the avoid input to the planners
                    resetAvoidSet(avoids, plannerAvoidOutput);
                } else {
                    return null;
                }
            } else {
                dest = planner.plan(vmProfile, plan, avoids);
                if (dest != null) {
                    final long hostId = dest.getHost().getId();
                    avoids.addHost(dest.getHost().getId());
                    if (checkIfHostFitsPlannerUsage(hostId, DeploymentPlanner.PlannerResourceUsage.Shared)) {
                        // found destination
                        return dest;
                    } else {
                        // deployment picked it up for dedicated access
                        continue;
                    }
                } else {
                    return null;
                }
            }
        }
    }
    return dest;
}
Also used : ExcludeList(com.cloud.deploy.DeploymentPlanner.ExcludeList) StoragePool(com.cloud.legacymodel.storage.StoragePool) Pod(com.cloud.legacymodel.dc.Pod) ServiceOffering(com.cloud.offering.ServiceOffering) Zone(com.cloud.db.model.Zone) Cluster(com.cloud.legacymodel.dc.Cluster) StoragePoolHostVO(com.cloud.storage.StoragePoolHostVO) HostVO(com.cloud.host.HostVO) Volume(com.cloud.legacymodel.storage.Volume) ArrayList(java.util.ArrayList) ExcludeList(com.cloud.deploy.DeploymentPlanner.ExcludeList) List(java.util.List) AffinityGroupProcessor(com.cloud.affinity.AffinityGroupProcessor) Map(java.util.Map) HashMap(java.util.HashMap) VirtualMachine(com.cloud.legacymodel.vm.VirtualMachine) Pair(com.cloud.legacymodel.utils.Pair)

Aggregations

Pod (com.cloud.legacymodel.dc.Pod)15 Zone (com.cloud.db.model.Zone)5 StoragePool (com.cloud.legacymodel.storage.StoragePool)5 Cluster (com.cloud.legacymodel.dc.Cluster)4 DataCenter (com.cloud.legacymodel.dc.DataCenter)4 Host (com.cloud.legacymodel.dc.Host)4 CloudRuntimeException (com.cloud.legacymodel.exceptions.CloudRuntimeException)4 Volume (com.cloud.legacymodel.storage.Volume)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 PodResponse (com.cloud.api.response.PodResponse)3 InsufficientAddressCapacityException (com.cloud.legacymodel.exceptions.InsufficientAddressCapacityException)3 DiskOffering (com.cloud.legacymodel.storage.DiskOffering)3 DB (com.cloud.utils.db.DB)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 ServerApiException (com.cloud.api.ServerApiException)2 VlanVO (com.cloud.dc.VlanVO)2 DeployDestination (com.cloud.deploy.DeployDestination)2 ExcludeList (com.cloud.deploy.DeploymentPlanner.ExcludeList)2