Search in sources :

Example 61 with ServiceOffering

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

the class VpcManagerImpl method configure.

@Override
@DB
public boolean configure(final String name, final Map<String, Object> params) throws ConfigurationException {
    // configure default vpc offering
    Transaction.execute(new TransactionCallbackNoReturn() {

        @Override
        public void doInTransactionWithoutResult(final TransactionStatus status) {
            if (_vpcOffDao.findByUniqueName(VpcOffering.defaultVPCOfferingName) == null) {
                s_logger.debug("Creating VPC offering " + VpcOffering.defaultVPCOfferingName);
                final Map<Service, Set<Provider>> svcProviderMap = getServiceSetMap(DEFAULT_SERVICES);
                createVpcOffering(VpcOffering.defaultVPCOfferingName, VpcOffering.defaultVPCOfferingName, svcProviderMap, true, State.Enabled, null, null, false);
            }
            if (_vpcOffDao.findByUniqueName(VpcOffering.defaultRemoteGatewayVPCOfferingName) == null) {
                s_logger.debug("Creating VPC offering " + VpcOffering.defaultRemoteGatewayVPCOfferingName);
                final Map<Service, Set<Provider>> svcProviderMap = getServiceSetMap(REMOTE_GATEWAY_SERVICES);
                createVpcOffering(VpcOffering.defaultRemoteGatewayVPCOfferingName, VpcOffering.defaultRemoteGatewayVPCOfferingName, svcProviderMap, true, State.Enabled, null, null, false);
            }
            if (_vpcOffDao.findByUniqueName(VpcOffering.defaultRemoteGatewayWithVPNVPCOfferingName) == null) {
                s_logger.debug("Creating VPC offering " + VpcOffering.defaultRemoteGatewayWithVPNVPCOfferingName);
                final Map<Service, Set<Provider>> svcProviderMap = getServiceSetMap(REMOTE_GATEWAY_WITH_VPN_SERVICES);
                createVpcOffering(VpcOffering.defaultRemoteGatewayWithVPNVPCOfferingName, VpcOffering.defaultRemoteGatewayWithVPNVPCOfferingName, svcProviderMap, true, State.Enabled, null, null, false);
            }
            if (_vpcOffDao.findByUniqueName(VpcOffering.defaultInternalVPCOfferingName) == null) {
                s_logger.debug("Creating VPC offering " + VpcOffering.defaultInternalVPCOfferingName);
                final Map<Service, Set<Provider>> svcProviderMap = getServiceSetMap(INTERNAL_VPC_SERVICES);
                createVpcOffering(VpcOffering.defaultInternalVPCOfferingName, VpcOffering.defaultInternalVPCOfferingName, svcProviderMap, true, State.Enabled, null, null, false);
            }
            if (_vpcOffDao.findByUniqueName(VpcOffering.redundantVPCOfferingName) == null) {
                s_logger.debug("Creating VPC offering " + VpcOffering.redundantVPCOfferingName);
                // Link the default Redundant VPC offering to the two default router offerings
                final ServiceOffering serviceOffering = _serviceOfferingDao.findByName(ServiceOffering.routerDefaultOffUniqueName);
                final ServiceOffering secondaryServiceOffering = _serviceOfferingDao.findByName(ServiceOffering.routerDefaultSecondaryOffUniqueName);
                Long serviceOfferingId = null;
                Long secondaryServiceOfferingId = null;
                if (serviceOffering != null) {
                    serviceOfferingId = serviceOffering.getId();
                }
                if (secondaryServiceOffering != null) {
                    secondaryServiceOfferingId = secondaryServiceOffering.getId();
                }
                final Map<Service, Set<Provider>> svcProviderMap = getServiceSetMap(DEFAULT_SERVICES);
                createVpcOffering(VpcOffering.redundantVPCOfferingName, VpcOffering.redundantVPCOfferingName, svcProviderMap, true, State.Enabled, serviceOfferingId, secondaryServiceOfferingId, true);
            }
        }
    });
    final Map<String, String> configs = _configDao.getConfiguration(params);
    final String value = configs.get(Config.VpcCleanupInterval.key());
    // 1 hour
    _cleanupInterval = NumbersUtil.parseInt(value, 60 * 60);
    final String maxNtwks = configs.get(Config.VpcMaxNetworks.key());
    // max=3 is default
    _maxNetworks = NumbersUtil.parseInt(maxNtwks, 3);
    IpAddressSearch = _ipAddressDao.createSearchBuilder();
    IpAddressSearch.and("accountId", IpAddressSearch.entity().getAllocatedToAccountId(), Op.EQ);
    IpAddressSearch.and("dataCenterId", IpAddressSearch.entity().getDataCenterId(), Op.EQ);
    IpAddressSearch.and("vpcId", IpAddressSearch.entity().getVpcId(), Op.EQ);
    IpAddressSearch.and("associatedWithNetworkId", IpAddressSearch.entity().getAssociatedWithNetworkId(), Op.EQ);
    final SearchBuilder<VlanVO> virtualNetworkVlanSB = _vlanDao.createSearchBuilder();
    virtualNetworkVlanSB.and("vlanType", virtualNetworkVlanSB.entity().getVlanType(), Op.EQ);
    IpAddressSearch.join("virtualNetworkVlanSB", virtualNetworkVlanSB, IpAddressSearch.entity().getVlanId(), virtualNetworkVlanSB.entity().getId(), JoinBuilder.JoinType.INNER);
    IpAddressSearch.done();
    return true;
}
Also used : ServiceOffering(com.cloud.offering.ServiceOffering) TransactionStatus(com.cloud.utils.db.TransactionStatus) TransactionCallbackNoReturn(com.cloud.utils.db.TransactionCallbackNoReturn) VlanVO(com.cloud.dc.VlanVO) Map(java.util.Map) HashMap(java.util.HashMap) VpcProvider(com.cloud.network.element.VpcProvider) Provider(com.cloud.network.Network.Provider) DB(com.cloud.utils.db.DB)

Example 62 with ServiceOffering

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

the class VirtualNetworkApplianceManagerImpl method upgradeRouter.

@Override
@DB
public VirtualRouter upgradeRouter(final UpgradeRouterCmd cmd) {
    final Long routerId = cmd.getId();
    final Long serviceOfferingId = cmd.getServiceOfferingId();
    final Account caller = CallContext.current().getCallingAccount();
    final DomainRouterVO router = _routerDao.findById(routerId);
    if (router == null) {
        throw new InvalidParameterValueException("Unable to find router with id " + routerId);
    }
    _accountMgr.checkAccess(caller, null, true, router);
    if (router.getServiceOfferingId() == serviceOfferingId) {
        s_logger.debug("Router: " + routerId + "already has service offering: " + serviceOfferingId);
        return _routerDao.findById(routerId);
    }
    final ServiceOffering newServiceOffering = _entityMgr.findById(ServiceOffering.class, serviceOfferingId);
    if (newServiceOffering == null) {
        throw new InvalidParameterValueException("Unable to find service offering with id " + serviceOfferingId);
    }
    // it cannot be used for user vms
    if (!newServiceOffering.getSystemUse()) {
        throw new InvalidParameterValueException("Cannot upgrade router vm to a non system service offering " + serviceOfferingId);
    }
    // Check that the router is stopped
    if (!router.getState().equals(VirtualMachine.State.Stopped)) {
        s_logger.warn("Unable to upgrade router " + router.toString() + " in state " + router.getState());
        throw new InvalidParameterValueException("Unable to upgrade router " + router.toString() + " in state " + router.getState() + "; make sure the router is stopped and not in an error state before upgrading.");
    }
    final ServiceOfferingVO currentServiceOffering = _serviceOfferingDao.findById(router.getServiceOfferingId());
    // offering
    if (currentServiceOffering.getUseLocalStorage() != newServiceOffering.getUseLocalStorage()) {
        throw new InvalidParameterValueException("Can't upgrade, due to new local storage status : " + newServiceOffering.getUseLocalStorage() + " is different from " + "curruent local storage status: " + currentServiceOffering.getUseLocalStorage());
    }
    router.setServiceOfferingId(serviceOfferingId);
    if (_routerDao.update(routerId, router)) {
        return _routerDao.findById(routerId);
    } else {
        throw new CloudRuntimeException("Unable to upgrade router " + routerId);
    }
}
Also used : Account(com.cloud.user.Account) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) ServiceOffering(com.cloud.offering.ServiceOffering) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ServiceOfferingVO(com.cloud.service.ServiceOfferingVO) DomainRouterVO(com.cloud.vm.DomainRouterVO) DB(com.cloud.utils.db.DB)

Example 63 with ServiceOffering

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

the class ConfigurationManagerImpl method getServiceOfferingNetworkRate.

@Override
public Integer getServiceOfferingNetworkRate(final long serviceOfferingId, final Long dataCenterId) {
    // validate network offering information
    final ServiceOffering offering = _serviceOfferingDao.findById(serviceOfferingId);
    if (offering == null) {
        throw new InvalidParameterValueException("Unable to find service offering by id=" + serviceOfferingId);
    }
    Integer networkRate;
    if (offering.getRateMbps() != null) {
        networkRate = offering.getRateMbps();
    } else {
        // for domain router service offering, get network rate from
        if (offering.getSystemVmType() != null && offering.getSystemVmType().equalsIgnoreCase(VirtualMachine.Type.DomainRouter.toString())) {
            networkRate = NetworkOrchestrationService.NetworkThrottlingRate.valueIn(dataCenterId);
        } else {
            networkRate = Integer.parseInt(_configDao.getValue(Config.VmNetworkThrottlingRate.key()));
        }
    }
    // all our other resources where -1 means unlimited
    if (networkRate == 0) {
        networkRate = -1;
    }
    return networkRate;
}
Also used : ServiceOffering(com.cloud.offering.ServiceOffering) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException)

Example 64 with ServiceOffering

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

the class ConfigurationManagerImpl method updateServiceOffering.

@Override
@ActionEvent(eventType = EventTypes.EVENT_SERVICE_OFFERING_EDIT, eventDescription = "updating service offering")
public ServiceOffering updateServiceOffering(final UpdateServiceOfferingCmd cmd) {
    final String displayText = cmd.getDisplayText();
    final Long id = cmd.getId();
    final String name = cmd.getServiceOfferingName();
    final Integer sortKey = cmd.getSortKey();
    Long userId = CallContext.current().getCallingUserId();
    if (userId == null) {
        userId = Long.valueOf(User.UID_SYSTEM);
    }
    // Verify input parameters
    final ServiceOffering offeringHandle = _entityMgr.findById(ServiceOffering.class, id);
    if (offeringHandle == null) {
        throw new InvalidParameterValueException("unable to find service offering " + id);
    }
    final User user = _userDao.findById(userId);
    if (user == null || user.getRemoved() != null) {
        throw new InvalidParameterValueException("Unable to find active user by id " + userId);
    }
    final Account account = _accountDao.findById(user.getAccountId());
    if (account.getType() == Account.ACCOUNT_TYPE_DOMAIN_ADMIN) {
        if (offeringHandle.getDomainId() == null) {
            throw new InvalidParameterValueException("Unable to update public service offering by id " + userId + " because it is domain-admin");
        }
        if (!_domainDao.isChildDomain(account.getDomainId(), offeringHandle.getDomainId())) {
            throw new InvalidParameterValueException("Unable to update service offering by another domain admin with id " + userId);
        }
    } else if (account.getType() != Account.ACCOUNT_TYPE_ADMIN) {
        throw new InvalidParameterValueException("Unable to update service offering by id " + userId + " because it is not root-admin or domain-admin");
    }
    final boolean updateNeeded = name != null || displayText != null || sortKey != null;
    if (!updateNeeded) {
        return _serviceOfferingDao.findById(id);
    }
    ServiceOfferingVO offering = _serviceOfferingDao.createForUpdate(id);
    if (name != null) {
        offering.setName(name);
    }
    if (displayText != null) {
        offering.setDisplayText(displayText);
    }
    if (sortKey != null) {
        offering.setSortKey(sortKey);
    }
    if (_serviceOfferingDao.update(id, offering)) {
        offering = _serviceOfferingDao.findById(id);
        CallContext.current().setEventDetails("Service offering id=" + offering.getId());
        return offering;
    } else {
        return null;
    }
}
Also used : Account(com.cloud.user.Account) User(com.cloud.user.User) ServiceOffering(com.cloud.offering.ServiceOffering) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) ServiceOfferingVO(com.cloud.service.ServiceOfferingVO) ActionEvent(com.cloud.event.ActionEvent)

Example 65 with ServiceOffering

use of com.cloud.offering.ServiceOffering 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, AffinityConflictException {
    // call affinitygroup chain
    final VirtualMachine vm = vmProfile.getVirtualMachine();
    final long vmGroupCount = _affinityGroupVMMapDao.countAffinityGroupsForVm(vm.getId());
    final Zone zone = zoneRepository.findOne(vm.getDataCenterId());
    if (vmGroupCount > 0) {
        for (final AffinityGroupProcessor processor : _affinityProcessors) {
            processor.process(vmProfile, plan, avoids);
        }
    }
    if (vm.getType() == VirtualMachine.Type.User || vm.getType() == VirtualMachine.Type.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.storage.StoragePool) Pod(com.cloud.dc.Pod) ServiceOffering(com.cloud.offering.ServiceOffering) Zone(com.cloud.db.model.Zone) Cluster(com.cloud.org.Cluster) StoragePoolHostVO(com.cloud.storage.StoragePoolHostVO) HostVO(com.cloud.host.HostVO) Volume(com.cloud.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.vm.VirtualMachine) Pair(com.cloud.utils.Pair)

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