Search in sources :

Example 11 with ServiceOffering

use of com.cloud.offering.ServiceOffering in project cloudstack by apache.

the class UpgradeSystemVMCmd method execute.

@Override
public void execute() {
    CallContext.current().setEventDetails("Vm Id: " + getId());
    ServiceOffering serviceOffering = _entityMgr.findById(ServiceOffering.class, serviceOfferingId);
    if (serviceOffering == null) {
        throw new InvalidParameterValueException("Unable to find service offering: " + serviceOfferingId);
    }
    VirtualMachine result = _mgr.upgradeSystemVM(this);
    if (result != null) {
        SystemVmResponse response = _responseGenerator.createSystemVmResponse(result);
        response.setResponseName(getCommandName());
        setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Fail to reboot system vm");
    }
}
Also used : SystemVmResponse(org.apache.cloudstack.api.response.SystemVmResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException) ServiceOffering(com.cloud.offering.ServiceOffering) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) VirtualMachine(com.cloud.vm.VirtualMachine)

Example 12 with ServiceOffering

use of com.cloud.offering.ServiceOffering in project cloudstack by apache.

the class ApiResponseHelper method createNetworkOfferingResponse.

@Override
public NetworkOfferingResponse createNetworkOfferingResponse(NetworkOffering offering) {
    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());
    response.setSupportsPublicAccess(offering.getSupportsPublicAccess());
    Long so = null;
    if (offering.getServiceOfferingId() != null) {
        so = offering.getServiceOfferingId();
    } else {
        so = ApiDBUtils.findDefaultRouterServiceOffering();
    }
    if (so != null) {
        ServiceOffering soffering = ApiDBUtils.findServiceOfferingById(so);
        if (soffering != null) {
            response.setServiceOfferingId(soffering.getUuid());
        }
    }
    if (offering.getGuestType() != null) {
        response.setGuestIpType(offering.getGuestType().toString());
    }
    response.setState(offering.getState().name());
    Map<Service, Set<Provider>> serviceProviderMap = ApiDBUtils.listNetworkOfferingServices(offering.getId());
    List<ServiceResponse> serviceResponses = new ArrayList<ServiceResponse>();
    for (Map.Entry<Service, Set<Provider>> entry : serviceProviderMap.entrySet()) {
        Service service = entry.getKey();
        Set<Provider> srvc_providers = entry.getValue();
        ServiceResponse svcRsp = new ServiceResponse();
        // skip gateway service
        if (service == Service.Gateway) {
            continue;
        }
        svcRsp.setName(service.getName());
        List<ProviderResponse> providers = new ArrayList<ProviderResponse>();
        for (Provider provider : srvc_providers) {
            if (provider != null) {
                ProviderResponse providerRsp = new ProviderResponse();
                providerRsp.setName(provider.getName());
                providers.add(providerRsp);
            }
        }
        svcRsp.setProviders(providers);
        if (Service.Lb == service) {
            List<CapabilityResponse> lbCapResponse = new ArrayList<CapabilityResponse>();
            CapabilityResponse lbIsoaltion = new CapabilityResponse();
            lbIsoaltion.setName(Capability.SupportedLBIsolation.getName());
            lbIsoaltion.setValue(offering.getDedicatedLB() ? "dedicated" : "shared");
            lbCapResponse.add(lbIsoaltion);
            CapabilityResponse eLb = new CapabilityResponse();
            eLb.setName(Capability.ElasticLb.getName());
            eLb.setValue(offering.getElasticLb() ? "true" : "false");
            lbCapResponse.add(eLb);
            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) {
            List<CapabilityResponse> capabilities = new ArrayList<CapabilityResponse>();
            CapabilityResponse sharedSourceNat = new CapabilityResponse();
            sharedSourceNat.setName(Capability.SupportedSourceNatTypes.getName());
            sharedSourceNat.setValue(offering.getSharedSourceNat() ? "perzone" : "peraccount");
            capabilities.add(sharedSourceNat);
            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) {
            List<CapabilityResponse> staticNatCapResponse = new ArrayList<CapabilityResponse>();
            CapabilityResponse eIp = new CapabilityResponse();
            eIp.setName(Capability.ElasticIp.getName());
            eIp.setValue(offering.getElasticIp() ? "true" : "false");
            staticNatCapResponse.add(eIp);
            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
    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) ProviderResponse(org.apache.cloudstack.api.response.ProviderResponse) VirtualRouterProviderResponse(org.apache.cloudstack.api.response.VirtualRouterProviderResponse) OvsProviderResponse(org.apache.cloudstack.api.response.OvsProviderResponse) NetworkOfferingResponse(org.apache.cloudstack.api.response.NetworkOfferingResponse) ServiceOffering(com.cloud.offering.ServiceOffering) ArrayList(java.util.ArrayList) Service(com.cloud.network.Network.Service) UsageService(org.apache.cloudstack.usage.UsageService) CapabilityResponse(org.apache.cloudstack.api.response.CapabilityResponse) OvsProvider(com.cloud.network.OvsProvider) VirtualRouterProvider(com.cloud.network.VirtualRouterProvider) PhysicalNetworkServiceProvider(com.cloud.network.PhysicalNetworkServiceProvider) Provider(com.cloud.network.Network.Provider) ServiceResponse(org.apache.cloudstack.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 13 with ServiceOffering

use of com.cloud.offering.ServiceOffering in project cloudstack by apache.

the class AutoScaleManagerImpl method createNewVM.

private long createNewVM(AutoScaleVmGroupVO asGroup) {
    AutoScaleVmProfileVO profileVo = _autoScaleVmProfileDao.findById(asGroup.getProfileId());
    long templateId = profileVo.getTemplateId();
    long serviceOfferingId = profileVo.getServiceOfferingId();
    if (templateId == -1) {
        return -1;
    }
    // create new VM into DB
    try {
        //Verify that all objects exist before passing them to the service
        Account owner = _accountService.getActiveAccountById(profileVo.getAccountId());
        DataCenter zone = _entityMgr.findById(DataCenter.class, profileVo.getZoneId());
        if (zone == null) {
            throw new InvalidParameterValueException("Unable to find zone by id=" + profileVo.getZoneId());
        }
        ServiceOffering serviceOffering = _entityMgr.findById(ServiceOffering.class, serviceOfferingId);
        if (serviceOffering == null) {
            throw new InvalidParameterValueException("Unable to find service offering: " + serviceOfferingId);
        }
        VirtualMachineTemplate template = _entityMgr.findById(VirtualMachineTemplate.class, templateId);
        // Make sure a valid template ID was specified
        if (template == null) {
            throw new InvalidParameterValueException("Unable to use template " + templateId);
        }
        if (!zone.isLocalStorageEnabled()) {
            if (serviceOffering.getUseLocalStorage()) {
                throw new InvalidParameterValueException("Zone is not configured to use local storage but service offering " + serviceOffering.getName() + " uses it");
            }
        }
        UserVm vm = null;
        IpAddresses addrs = new IpAddresses(null, null);
        if (zone.getNetworkType() == NetworkType.Basic) {
            vm = _userVmService.createBasicSecurityGroupVirtualMachine(zone, serviceOffering, template, null, owner, "autoScaleVm-" + asGroup.getId() + "-" + getCurrentTimeStampString(), "autoScaleVm-" + asGroup.getId() + "-" + getCurrentTimeStampString(), null, null, null, HypervisorType.XenServer, HTTPMethod.GET, null, null, null, null, true, null, null, null, null);
        } else {
            if (zone.isSecurityGroupEnabled()) {
                vm = _userVmService.createAdvancedSecurityGroupVirtualMachine(zone, serviceOffering, template, null, null, owner, "autoScaleVm-" + asGroup.getId() + "-" + getCurrentTimeStampString(), "autoScaleVm-" + asGroup.getId() + "-" + getCurrentTimeStampString(), null, null, null, HypervisorType.XenServer, HTTPMethod.GET, null, null, null, null, true, null, null, null, null);
            } else {
                vm = _userVmService.createAdvancedVirtualMachine(zone, serviceOffering, template, null, owner, "autoScaleVm-" + asGroup.getId() + "-" + getCurrentTimeStampString(), "autoScaleVm-" + asGroup.getId() + "-" + getCurrentTimeStampString(), null, null, null, HypervisorType.XenServer, HTTPMethod.GET, null, null, null, addrs, true, null, null, null, null);
            }
        }
        if (vm != null) {
            return vm.getId();
        } else {
            return -1;
        }
    } catch (InsufficientCapacityException ex) {
        s_logger.info(ex);
        s_logger.trace(ex.getMessage(), ex);
        throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR, ex.getMessage());
    } catch (ResourceUnavailableException ex) {
        s_logger.warn("Exception: ", ex);
        throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage());
    } catch (ConcurrentOperationException ex) {
        s_logger.warn("Exception: ", ex);
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
    } catch (ResourceAllocationException ex) {
        s_logger.warn("Exception: ", ex);
        throw new ServerApiException(ApiErrorCode.RESOURCE_ALLOCATION_ERROR, ex.getMessage());
    }
}
Also used : Account(com.cloud.user.Account) VirtualMachineTemplate(com.cloud.template.VirtualMachineTemplate) ServiceOffering(com.cloud.offering.ServiceOffering) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) IpAddresses(com.cloud.network.Network.IpAddresses) UserVm(com.cloud.uservm.UserVm) DataCenter(com.cloud.dc.DataCenter) ServerApiException(org.apache.cloudstack.api.ServerApiException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) ResourceAllocationException(com.cloud.exception.ResourceAllocationException)

Example 14 with ServiceOffering

use of com.cloud.offering.ServiceOffering in project cloudstack by apache.

the class FirstFitPlanner method scanClustersForDestinationInZoneOrPod.

private List<Long> scanClustersForDestinationInZoneOrPod(long id, boolean isZone, VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoid) {
    VirtualMachine vm = vmProfile.getVirtualMachine();
    ServiceOffering offering = vmProfile.getServiceOffering();
    DataCenter dc = dcDao.findById(vm.getDataCenterId());
    int requiredCpu = offering.getCpu() * offering.getSpeed();
    long requiredRam = offering.getRamSize() * 1024L * 1024L;
    //list clusters under this zone by cpu and ram capacity
    Pair<List<Long>, Map<Long, Double>> clusterCapacityInfo = listClustersByCapacity(id, requiredCpu, requiredRam, avoid, isZone);
    List<Long> prioritizedClusterIds = clusterCapacityInfo.first();
    if (!prioritizedClusterIds.isEmpty()) {
        if (avoid.getClustersToAvoid() != null) {
            if (s_logger.isDebugEnabled()) {
                s_logger.debug("Removing from the clusterId list these clusters from avoid set: " + avoid.getClustersToAvoid());
            }
            prioritizedClusterIds.removeAll(avoid.getClustersToAvoid());
        }
        if (!isRootAdmin(vmProfile)) {
            List<Long> disabledClusters = new ArrayList<Long>();
            if (isZone) {
                disabledClusters = listDisabledClusters(plan.getDataCenterId(), null);
            } else {
                disabledClusters = listDisabledClusters(plan.getDataCenterId(), id);
            }
            if (!disabledClusters.isEmpty()) {
                if (s_logger.isDebugEnabled()) {
                    s_logger.debug("Removing from the clusterId list these clusters that are disabled/clusters under disabled pods: " + disabledClusters);
                }
                prioritizedClusterIds.removeAll(disabledClusters);
            }
        }
        removeClustersCrossingThreshold(prioritizedClusterIds, avoid, vmProfile, plan);
        String hostTagOnOffering = offering.getHostTag();
        if (hostTagOnOffering != null) {
            removeClustersWithoutMatchingTag(prioritizedClusterIds, hostTagOnOffering);
        }
    } else {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("No clusters found having a host with enough capacity, returning.");
        }
        return null;
    }
    if (!prioritizedClusterIds.isEmpty()) {
        List<Long> clusterList = reorderClusters(id, isZone, clusterCapacityInfo, vmProfile, plan);
        //return checkClustersforDestination(clusterList, vmProfile, plan, avoid, dc);
        return clusterList;
    } else {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("No clusters found after removing disabled clusters and clusters in avoid list, returning.");
        }
        return null;
    }
}
Also used : DataCenter(com.cloud.dc.DataCenter) ServiceOffering(com.cloud.offering.ServiceOffering) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) VirtualMachine(com.cloud.vm.VirtualMachine)

Example 15 with ServiceOffering

use of com.cloud.offering.ServiceOffering in project cloudstack by apache.

the class FirstFitPlanner method removeClustersCrossingThreshold.

/**
     * This method should remove the clusters crossing capacity threshold to avoid further vm allocation on it.
     * @param clusterListForVmAllocation
     * @param avoid
     * @param vmProfile
     * @param plan
     */
protected void removeClustersCrossingThreshold(List<Long> clusterListForVmAllocation, ExcludeList avoid, VirtualMachineProfile vmProfile, DeploymentPlan plan) {
    // Check if cluster threshold for cpu/memory has to be checked or not. By default we
    // always check cluster threshold isn't crossed. However, the check may be skipped for
    // starting (not deploying) an instance.
    VirtualMachine vm = vmProfile.getVirtualMachine();
    Map<String, String> details = vmDetailsDao.listDetailsKeyPairs(vm.getId());
    Boolean isThresholdEnabled = ClusterThresholdEnabled.value();
    if (!(isThresholdEnabled || (details != null && details.containsKey("deployvm")))) {
        return;
    }
    List<Short> capacityList = getCapacitiesForCheckingThreshold();
    List<Long> clustersCrossingThreshold = new ArrayList<Long>();
    ServiceOffering offering = vmProfile.getServiceOffering();
    int cpu_requested = offering.getCpu() * offering.getSpeed();
    long ram_requested = offering.getRamSize() * 1024L * 1024L;
    // remove it from the clusterList that will be used for vm allocation.
    for (short capacity : capacityList) {
        if (clusterListForVmAllocation == null || clusterListForVmAllocation.size() == 0) {
            return;
        }
        if (capacity == Capacity.CAPACITY_TYPE_CPU) {
            clustersCrossingThreshold = capacityDao.listClustersCrossingThreshold(capacity, plan.getDataCenterId(), ClusterCPUCapacityDisableThreshold.key(), cpu_requested);
        } else if (capacity == Capacity.CAPACITY_TYPE_MEMORY) {
            clustersCrossingThreshold = capacityDao.listClustersCrossingThreshold(capacity, plan.getDataCenterId(), ClusterMemoryCapacityDisableThreshold.key(), ram_requested);
        }
        if (clustersCrossingThreshold != null && clustersCrossingThreshold.size() != 0) {
            // addToAvoid Set
            avoid.addClusterList(clustersCrossingThreshold);
            // Remove clusters crossing disabled threshold
            clusterListForVmAllocation.removeAll(clustersCrossingThreshold);
            s_logger.debug("Cannot allocate cluster list " + clustersCrossingThreshold.toString() + " for vm creation since their allocated percentage" + " crosses the disable capacity threshold defined at each cluster/ at global value for capacity Type : " + capacity + ", skipping these clusters");
        }
    }
}
Also used : ServiceOffering(com.cloud.offering.ServiceOffering) ArrayList(java.util.ArrayList) VirtualMachine(com.cloud.vm.VirtualMachine)

Aggregations

ServiceOffering (com.cloud.offering.ServiceOffering)46 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)18 Account (com.cloud.user.Account)14 ArrayList (java.util.ArrayList)13 DataCenter (com.cloud.dc.DataCenter)11 VirtualMachine (com.cloud.vm.VirtualMachine)9 ServerApiException (org.apache.cloudstack.api.ServerApiException)8 ServerApiException (com.cloud.api.ServerApiException)5 VirtualMachineTemplate (com.cloud.template.VirtualMachineTemplate)5 UserVm (com.cloud.uservm.UserVm)5 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)5 HashMap (java.util.HashMap)5 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)4 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)4 Host (com.cloud.host.Host)4 HostVO (com.cloud.host.HostVO)4 DiskOffering (com.cloud.offering.DiskOffering)4 ServiceOfferingVO (com.cloud.service.ServiceOfferingVO)4 VMTemplateVO (com.cloud.storage.VMTemplateVO)4 ServiceOfferingResponse (com.cloud.api.response.ServiceOfferingResponse)3