Search in sources :

Example 66 with ServiceOffering

use of com.cloud.offering.ServiceOffering in project cosmic by MissionCriticalCloud.

the class FirstFitPlanner method scanPodsForDestination.

private List<Long> scanPodsForDestination(final VirtualMachineProfile vmProfile, final DeploymentPlan plan, final ExcludeList avoid) {
    final ServiceOffering offering = vmProfile.getServiceOffering();
    final int requiredCpu = offering.getCpu();
    final long requiredRam = offering.getRamSize() * 1024L * 1024L;
    // list pods under this zone by cpu and ram capacity
    List<Long> prioritizedPodIds = new ArrayList<>();
    final Pair<List<Long>, Map<Long, Double>> podCapacityInfo = listPodsByCapacity(plan.getDataCenterId(), requiredCpu, requiredRam);
    final List<Long> podsWithCapacity = podCapacityInfo.first();
    if (!podsWithCapacity.isEmpty()) {
        if (avoid.getPodsToAvoid() != null) {
            if (s_logger.isDebugEnabled()) {
                s_logger.debug("Removing from the podId list these pods from avoid set: " + avoid.getPodsToAvoid());
            }
            podsWithCapacity.removeAll(avoid.getPodsToAvoid());
        }
        if (!isRootAdmin(vmProfile)) {
            final List<Long> disabledPods = listDisabledPods(plan.getDataCenterId());
            if (!disabledPods.isEmpty()) {
                if (s_logger.isDebugEnabled()) {
                    s_logger.debug("Removing from the podId list these pods that are disabled: " + disabledPods);
                }
                podsWithCapacity.removeAll(disabledPods);
            }
        }
    } else {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("No pods found having a host with enough capacity, returning.");
        }
        return null;
    }
    if (!podsWithCapacity.isEmpty()) {
        prioritizedPodIds = reorderPods(podCapacityInfo, vmProfile, plan);
        if (prioritizedPodIds == null || prioritizedPodIds.isEmpty()) {
            if (s_logger.isDebugEnabled()) {
                s_logger.debug("No Pods found for destination, returning.");
            }
            return null;
        }
        final List<Long> clusterList = new ArrayList<>();
        // loop over pods
        for (final Long podId : prioritizedPodIds) {
            s_logger.debug("Checking resources under Pod: " + podId);
            final List<Long> clustersUnderPod = scanClustersForDestinationInZoneOrPod(podId, false, vmProfile, plan, avoid);
            if (clustersUnderPod != null) {
                clusterList.addAll(clustersUnderPod);
            }
        }
        return clusterList;
    } else {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("No Pods found after removing disabled pods and pods in avoid list, returning.");
        }
        return null;
    }
}
Also used : ServiceOffering(com.cloud.offering.ServiceOffering) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Example 67 with ServiceOffering

use of com.cloud.offering.ServiceOffering in project cosmic by MissionCriticalCloud.

the class VirtualMachineManagerImpl method upgradeVmDb.

@Override
public boolean upgradeVmDb(final long vmId, final long serviceOfferingId) {
    final VMInstanceVO vmForUpdate = _vmDao.createForUpdate();
    vmForUpdate.setServiceOfferingId(serviceOfferingId);
    final ServiceOffering newSvcOff = _entityMgr.findById(ServiceOffering.class, serviceOfferingId);
    vmForUpdate.setHaEnabled(newSvcOff.getOfferHA());
    vmForUpdate.setLimitCpuUse(newSvcOff.getLimitCpuUse());
    vmForUpdate.setServiceOfferingId(newSvcOff.getId());
    return _vmDao.update(vmId, vmForUpdate);
}
Also used : ServiceOffering(com.cloud.offering.ServiceOffering)

Example 68 with ServiceOffering

use of com.cloud.offering.ServiceOffering in project cosmic by MissionCriticalCloud.

the class VirtualMachineManagerImpl method orchestrateReConfigureVm.

private VMInstanceVO orchestrateReConfigureVm(final String vmUuid, final ServiceOffering oldServiceOffering, final boolean reconfiguringOnExistingHost) throws ResourceUnavailableException, ConcurrentOperationException {
    final VMInstanceVO vm = _vmDao.findByUuid(vmUuid);
    final long newServiceofferingId = vm.getServiceOfferingId();
    final ServiceOffering newServiceOffering = _offeringDao.findById(vm.getId(), newServiceofferingId);
    final HostVO hostVo = _hostDao.findById(vm.getHostId());
    final Float memoryOvercommitRatio = CapacityManager.MemOverprovisioningFactor.valueIn(hostVo.getClusterId());
    final Float cpuOvercommitRatio = CapacityManager.CpuOverprovisioningFactor.valueIn(hostVo.getClusterId());
    final long minMemory = (long) (newServiceOffering.getRamSize() / memoryOvercommitRatio);
    final ScaleVmCommand reconfigureCmd = new ScaleVmCommand(vm.getInstanceName(), newServiceOffering.getCpu(), minMemory * 1024L * 1024L, newServiceOffering.getRamSize() * 1024L * 1024L, newServiceOffering.getLimitCpuUse());
    final Long dstHostId = vm.getHostId();
    final ItWorkVO work = new ItWorkVO(UUID.randomUUID().toString(), _nodeId, State.Running, vm.getType(), vm.getId());
    work.setStep(Step.Prepare);
    work.setResourceType(ItWorkVO.ResourceType.Host);
    work.setResourceId(vm.getHostId());
    _workDao.persist(work);
    boolean success = false;
    try {
        if (reconfiguringOnExistingHost) {
            vm.setServiceOfferingId(oldServiceOffering.getId());
            // release the old capacity
            _capacityMgr.releaseVmCapacity(vm, false, false, vm.getHostId());
            vm.setServiceOfferingId(newServiceofferingId);
            // lock the new capacity
            _capacityMgr.allocateVmCapacity(vm, false);
        }
        final Answer reconfigureAnswer = _agentMgr.send(vm.getHostId(), reconfigureCmd);
        if (reconfigureAnswer == null || !reconfigureAnswer.getResult()) {
            s_logger.error("Unable to scale vm due to " + (reconfigureAnswer == null ? "" : reconfigureAnswer.getDetails()));
            throw new CloudRuntimeException("Unable to scale vm due to " + (reconfigureAnswer == null ? "" : reconfigureAnswer.getDetails()));
        }
        success = true;
    } catch (final OperationTimedoutException e) {
        throw new AgentUnavailableException("Operation timed out on reconfiguring " + vm, dstHostId);
    } catch (final AgentUnavailableException e) {
        throw e;
    } finally {
        if (!success) {
            // release the new capacity
            _capacityMgr.releaseVmCapacity(vm, false, false, vm.getHostId());
            vm.setServiceOfferingId(oldServiceOffering.getId());
            // allocate the old capacity
            _capacityMgr.allocateVmCapacity(vm, false);
        }
    }
    return vm;
}
Also used : OperationTimedoutException(com.cloud.exception.OperationTimedoutException) ServiceOffering(com.cloud.offering.ServiceOffering) HostVO(com.cloud.host.HostVO) AgentControlAnswer(com.cloud.agent.api.AgentControlAnswer) RebootAnswer(com.cloud.agent.api.RebootAnswer) StartAnswer(com.cloud.agent.api.StartAnswer) RestoreVMSnapshotAnswer(com.cloud.agent.api.RestoreVMSnapshotAnswer) PlugNicAnswer(com.cloud.agent.api.PlugNicAnswer) StopAnswer(com.cloud.agent.api.StopAnswer) Answer(com.cloud.agent.api.Answer) UnPlugNicAnswer(com.cloud.agent.api.UnPlugNicAnswer) ClusterVMMetaDataSyncAnswer(com.cloud.agent.api.ClusterVMMetaDataSyncAnswer) CheckVirtualMachineAnswer(com.cloud.agent.api.CheckVirtualMachineAnswer) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) ScaleVmCommand(com.cloud.agent.api.ScaleVmCommand)

Example 69 with ServiceOffering

use of com.cloud.offering.ServiceOffering in project cosmic by MissionCriticalCloud.

the class ApiResponseHelper method createNetworkOfferingResponse.

@Override
public NetworkOfferingResponse createNetworkOfferingResponse(final NetworkOffering offering) {
    final NetworkOfferingResponse response = new NetworkOfferingResponse();
    response.setId(offering.getUuid());
    response.setName(offering.getName());
    response.setDisplayText(offering.getDisplayText());
    response.setTags(offering.getTags());
    response.setTrafficType(offering.getTrafficType().toString());
    response.setIsDefault(offering.isDefault());
    response.setSpecifyVlan(offering.getSpecifyVlan());
    response.setConserveMode(offering.isConserveMode());
    response.setSpecifyIpRanges(offering.getSpecifyIpRanges());
    response.setAvailability(offering.getAvailability().toString());
    response.setIsPersistent(offering.getIsPersistent());
    response.setNetworkRate(ApiDBUtils.getNetworkRate(offering.getId()));
    response.setEgressDefaultPolicy(offering.getEgressDefaultPolicy());
    response.setConcurrentConnections(offering.getConcurrentConnections());
    response.setSupportsStrechedL2Subnet(offering.getSupportsStrechedL2());
    final Long so;
    if (offering.getServiceOfferingId() != null) {
        so = offering.getServiceOfferingId();
    } else {
        so = ApiDBUtils.findDefaultRouterServiceOffering();
    }
    if (so != null) {
        final ServiceOffering serviceOffering = ApiDBUtils.findServiceOfferingById(so);
        if (serviceOffering != null) {
            response.setServiceOfferingId(serviceOffering.getUuid());
            response.setServiceOfferingName(serviceOffering.getName());
        }
    }
    final ServiceOffering secondaryServiceOffering = _serviceOfferingDao.findById(offering.getSecondaryServiceOfferingId());
    if (secondaryServiceOffering != null) {
        response.setSecondaryServiceOfferingId(secondaryServiceOffering.getUuid());
        response.setSecondaryServiceOfferingName(secondaryServiceOffering.getName());
    }
    if (offering.getGuestType() != null) {
        response.setGuestIpType(offering.getGuestType().toString());
    }
    response.setState(offering.getState().name());
    final Map<Service, Set<Provider>> serviceProviderMap = ApiDBUtils.listNetworkOfferingServices(offering.getId());
    final List<ServiceResponse> serviceResponses = new ArrayList<>();
    for (final Map.Entry<Service, Set<Provider>> entry : serviceProviderMap.entrySet()) {
        final Service service = entry.getKey();
        final Set<Provider> srvc_providers = entry.getValue();
        final ServiceResponse svcRsp = new ServiceResponse();
        // skip gateway service
        if (service == Service.Gateway) {
            continue;
        }
        svcRsp.setName(service.getName());
        final List<ProviderResponse> providers = getProviderResponses(srvc_providers);
        svcRsp.setProviders(providers);
        if (Service.Lb == service) {
            final List<CapabilityResponse> lbCapResponse = new ArrayList<>();
            final CapabilityResponse lbIsoaltion = new CapabilityResponse();
            lbIsoaltion.setName(Capability.SupportedLBIsolation.getName());
            lbIsoaltion.setValue(offering.getDedicatedLB() ? "dedicated" : "shared");
            lbCapResponse.add(lbIsoaltion);
            final CapabilityResponse eLb = new CapabilityResponse();
            eLb.setName(Capability.ElasticLb.getName());
            eLb.setValue(offering.getElasticLb() ? "true" : "false");
            lbCapResponse.add(eLb);
            final CapabilityResponse inline = new CapabilityResponse();
            inline.setName(Capability.InlineMode.getName());
            inline.setValue(offering.isInline() ? "true" : "false");
            lbCapResponse.add(inline);
            svcRsp.setCapabilities(lbCapResponse);
        } else if (Service.SourceNat == service) {
            final List<CapabilityResponse> capabilities = new ArrayList<>();
            final CapabilityResponse sharedSourceNat = new CapabilityResponse();
            sharedSourceNat.setName(Capability.SupportedSourceNatTypes.getName());
            sharedSourceNat.setValue(offering.getSharedSourceNat() ? "perzone" : "peraccount");
            capabilities.add(sharedSourceNat);
            final CapabilityResponse redundantRouter = new CapabilityResponse();
            redundantRouter.setName(Capability.RedundantRouter.getName());
            redundantRouter.setValue(offering.getRedundantRouter() ? "true" : "false");
            capabilities.add(redundantRouter);
            svcRsp.setCapabilities(capabilities);
        } else if (service == Service.StaticNat) {
            final List<CapabilityResponse> staticNatCapResponse = new ArrayList<>();
            final CapabilityResponse eIp = new CapabilityResponse();
            eIp.setName(Capability.ElasticIp.getName());
            eIp.setValue(offering.getElasticIp() ? "true" : "false");
            staticNatCapResponse.add(eIp);
            final CapabilityResponse associatePublicIp = new CapabilityResponse();
            associatePublicIp.setName(Capability.AssociatePublicIP.getName());
            associatePublicIp.setValue(offering.getAssociatePublicIP() ? "true" : "false");
            staticNatCapResponse.add(associatePublicIp);
            svcRsp.setCapabilities(staticNatCapResponse);
        }
        serviceResponses.add(svcRsp);
    }
    response.setForVpc(_configMgr.isOfferingForVpc(offering));
    response.setServices(serviceResponses);
    // set network offering details
    final Map<Detail, String> details = _ntwkModel.getNtwkOffDetails(offering.getId());
    if (details != null && !details.isEmpty()) {
        response.setDetails(details);
    }
    response.setObjectName("networkoffering");
    return response;
}
Also used : EnumSet(java.util.EnumSet) HashSet(java.util.HashSet) Set(java.util.Set) VirtualRouterProviderResponse(com.cloud.api.response.VirtualRouterProviderResponse) ProviderResponse(com.cloud.api.response.ProviderResponse) NetworkOfferingResponse(com.cloud.api.response.NetworkOfferingResponse) ServiceOffering(com.cloud.offering.ServiceOffering) ArrayList(java.util.ArrayList) Service(com.cloud.network.Network.Service) CapabilityResponse(com.cloud.api.response.CapabilityResponse) VirtualRouterProvider(com.cloud.network.VirtualRouterProvider) PhysicalNetworkServiceProvider(com.cloud.network.PhysicalNetworkServiceProvider) Provider(com.cloud.network.Network.Provider) ServiceResponse(com.cloud.api.response.ServiceResponse) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) HashMap(java.util.HashMap) Detail(com.cloud.offering.NetworkOffering.Detail)

Example 70 with ServiceOffering

use of com.cloud.offering.ServiceOffering in project cosmic by MissionCriticalCloud.

the class FirstFitAllocator method allocateTo.

@Override
public List<Host> allocateTo(final VirtualMachineProfile vmProfile, final DeploymentPlan plan, final Type type, final ExcludeList avoid, final List<? extends Host> hosts, final int returnUpTo, final boolean considerReservedCapacity) {
    final long dcId = plan.getDataCenterId();
    final Long podId = plan.getPodId();
    final Long clusterId = plan.getClusterId();
    final ServiceOffering offering = vmProfile.getServiceOffering();
    final VMTemplateVO template = (VMTemplateVO) vmProfile.getTemplate();
    final Account account = vmProfile.getOwner();
    List<Host> suitableHosts = new ArrayList<>();
    final List<Host> hostsCopy = new ArrayList<>(hosts);
    if (type == Host.Type.Storage) {
        // routing or not.
        return suitableHosts;
    }
    final String hostTagOnOffering = offering.getHostTag();
    final String hostTagOnTemplate = template.getTemplateTag();
    final boolean hasSvcOfferingTag = hostTagOnOffering != null ? true : false;
    final boolean hasTemplateTag = hostTagOnTemplate != null ? true : false;
    final String haVmTag = (String) vmProfile.getParameter(VirtualMachineProfile.Param.HaTag);
    if (haVmTag != null) {
        hostsCopy.retainAll(_hostDao.listByHostTag(type, clusterId, podId, dcId, haVmTag));
    } else {
        if (hostTagOnOffering == null && hostTagOnTemplate == null) {
            hostsCopy.retainAll(_resourceMgr.listAllUpAndEnabledNonHAHosts(type, clusterId, podId, dcId));
        } else {
            if (hasSvcOfferingTag) {
                if (s_logger.isDebugEnabled()) {
                    s_logger.debug("Looking for hosts having tag specified on SvcOffering:" + hostTagOnOffering);
                }
                hostsCopy.retainAll(_hostDao.listByHostTag(type, clusterId, podId, dcId, hostTagOnOffering));
                if (s_logger.isDebugEnabled()) {
                    s_logger.debug("Hosts with tag '" + hostTagOnOffering + "' are:" + hostsCopy);
                }
            }
            if (hasTemplateTag) {
                if (s_logger.isDebugEnabled()) {
                    s_logger.debug("Looking for hosts having tag specified on Template:" + hostTagOnTemplate);
                }
                hostsCopy.retainAll(_hostDao.listByHostTag(type, clusterId, podId, dcId, hostTagOnTemplate));
                if (s_logger.isDebugEnabled()) {
                    s_logger.debug("Hosts with tag '" + hostTagOnTemplate + "' are:" + hostsCopy);
                }
            }
        }
    }
    if (!hostsCopy.isEmpty()) {
        suitableHosts = allocateTo(plan, offering, template, avoid, hostsCopy, returnUpTo, considerReservedCapacity, account);
    }
    return suitableHosts;
}
Also used : Account(com.cloud.user.Account) ServiceOffering(com.cloud.offering.ServiceOffering) VMTemplateVO(com.cloud.storage.VMTemplateVO) ArrayList(java.util.ArrayList) Host(com.cloud.host.Host)

Aggregations

ServiceOffering (com.cloud.offering.ServiceOffering)103 ArrayList (java.util.ArrayList)34 Account (com.cloud.user.Account)30 DataCenter (com.cloud.dc.DataCenter)23 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)20 HashMap (java.util.HashMap)18 VirtualMachine (com.cloud.vm.VirtualMachine)17 VMTemplateVO (com.cloud.storage.VMTemplateVO)14 UserVm (com.cloud.uservm.UserVm)14 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)14 Map (java.util.Map)14 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)13 ServerApiException (com.cloud.api.ServerApiException)12 HostVO (com.cloud.host.HostVO)12 DiskOffering (com.cloud.offering.DiskOffering)11 ServiceOfferingVO (com.cloud.service.ServiceOfferingVO)11 Host (com.cloud.host.Host)10 Network (com.cloud.network.Network)10 List (java.util.List)10 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)9