Search in sources :

Example 21 with InvalidParameterValueException

use of com.cloud.legacymodel.exceptions.InvalidParameterValueException in project cosmic by MissionCriticalCloud.

the class ConfigurationManagerImpl method createServiceOffering.

protected ServiceOfferingVO createServiceOffering(final long userId, final boolean isSystem, final VirtualMachineType vmType, final String name, final Integer cpu, final Integer ramSize, final String displayText, final String provisioningType, final boolean localStorageRequired, final boolean offerHA, final boolean limitResourceUse, final boolean volatileVm, String tags, final Long domainId, final String hostTag, final Integer networkRate, final String deploymentPlanner, final Map<String, String> details, final Boolean isCustomizedIops, Long minIops, Long maxIops, Long bytesReadRate, Long bytesWriteRate, Long iopsReadRate, Long iopsWriteRate, Long iopsTotalRate, final boolean iopsRatePerGb, final Integer hypervisorSnapshotReserve) {
    // Check if user exists in the system
    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 (domainId == null) {
            throw new InvalidParameterValueException("Unable to create public service offering by id " + userId + " because it is domain-admin");
        }
        if (tags != null || hostTag != null) {
            throw new InvalidParameterValueException("Unable to create service offering with storage tags or host tags by id " + userId + " because it is domain-admin");
        }
        if (!_domainDao.isChildDomain(account.getDomainId(), domainId)) {
            throw new InvalidParameterValueException("Unable to create service offering by another domain admin with id " + userId);
        }
    } else if (account.getType() != Account.ACCOUNT_TYPE_ADMIN) {
        throw new InvalidParameterValueException("Unable to create service offering by id " + userId + " because it is not root-admin or domain-admin");
    }
    final StorageProvisioningType typedProvisioningType = StorageProvisioningType.valueOf(provisioningType);
    tags = StringUtils.cleanupTags(tags);
    ServiceOfferingVO offering = new ServiceOfferingVO(name, cpu, ramSize, networkRate, null, offerHA, limitResourceUse, volatileVm, displayText, typedProvisioningType, localStorageRequired, false, tags, isSystem, vmType, domainId, hostTag, deploymentPlanner);
    if (isCustomizedIops != null) {
        bytesReadRate = null;
        bytesWriteRate = null;
        iopsReadRate = null;
        iopsWriteRate = null;
        if (isCustomizedIops) {
            minIops = null;
            maxIops = null;
        } else {
            if (minIops == null && maxIops == null) {
                minIops = 0L;
                maxIops = 0L;
            } else {
                if (minIops == null || minIops <= 0) {
                    throw new InvalidParameterValueException("The min IOPS must be greater than 0.");
                }
                if (maxIops == null) {
                    maxIops = 0L;
                }
                if (minIops > maxIops) {
                    throw new InvalidParameterValueException("The min IOPS must be less than or equal to the max IOPS.");
                }
            }
        }
    } else {
        minIops = null;
        maxIops = null;
    }
    offering.setCustomizedIops(isCustomizedIops);
    offering.setMinIops(minIops);
    offering.setMaxIops(maxIops);
    if (bytesReadRate != null && bytesReadRate > 0) {
        offering.setBytesReadRate(bytesReadRate);
    }
    if (bytesWriteRate != null && bytesWriteRate > 0) {
        offering.setBytesWriteRate(bytesWriteRate);
    }
    if (iopsReadRate != null && iopsReadRate > 0) {
        offering.setIopsReadRate(iopsReadRate);
    }
    if (iopsWriteRate != null && iopsWriteRate > 0) {
        offering.setIopsWriteRate(iopsWriteRate);
    }
    if (iopsTotalRate != null && iopsTotalRate > 0) {
        if (iopsWriteRate != null && iopsWriteRate > 0 || iopsReadRate != null && iopsReadRate > 0) {
            throw new InvalidParameterValueException("Total IOPS rate cannot be used together with IOPS read rate or IOPS write rate");
        }
        offering.setIopsTotalRate(iopsTotalRate);
    }
    if (iopsRatePerGb) {
        offering.setIopsRatePerGb(iopsRatePerGb);
    }
    if (hypervisorSnapshotReserve != null && hypervisorSnapshotReserve < 0) {
        throw new InvalidParameterValueException("If provided, Hypervisor Snapshot Reserve must be greater than or equal to 0.");
    }
    offering.setHypervisorSnapshotReserve(hypervisorSnapshotReserve);
    List<ServiceOfferingDetailsVO> detailsVO = null;
    if (details != null) {
        // To have correct input, either both gpu card name and VGPU type should be passed or nothing should be passed.
        // Use XOR condition to verify that.
        final boolean entry1 = details.containsKey(GPU.Keys.pciDevice.toString());
        final boolean entry2 = details.containsKey(GPU.Keys.vgpuType.toString());
        if ((entry1 || entry2) && !(entry1 && entry2)) {
            throw new InvalidParameterValueException("Please specify the pciDevice and vgpuType correctly.");
        }
        detailsVO = new ArrayList<>();
        for (final Entry<String, String> detailEntry : details.entrySet()) {
            if (detailEntry.getKey().equals(GPU.Keys.pciDevice.toString())) {
                if (detailEntry.getValue() == null) {
                    throw new InvalidParameterValueException("Please specify a GPU Card.");
                }
            }
            if (detailEntry.getKey().equals(GPU.Keys.vgpuType.toString())) {
                if (detailEntry.getValue() == null) {
                    throw new InvalidParameterValueException("vGPUType value cannot be null");
                }
            }
            detailsVO.add(new ServiceOfferingDetailsVO(offering.getId(), detailEntry.getKey(), detailEntry.getValue(), true));
        }
    }
    if ((offering = _serviceOfferingDao.persist(offering)) != null) {
        if (detailsVO != null && !detailsVO.isEmpty()) {
            for (int index = 0; index < detailsVO.size(); index++) {
                detailsVO.get(index).setResourceId(offering.getId());
            }
            _serviceOfferingDetailsDao.saveDetails(detailsVO);
        }
        CallContext.current().setEventDetails("Service offering id=" + offering.getId());
        return offering;
    } else {
        return null;
    }
}
Also used : Account(com.cloud.legacymodel.user.Account) User(com.cloud.legacymodel.user.User) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) ServiceOfferingDetailsVO(com.cloud.service.ServiceOfferingDetailsVO) ServiceOfferingVO(com.cloud.service.ServiceOfferingVO) StorageProvisioningType(com.cloud.model.enumeration.StorageProvisioningType)

Example 22 with InvalidParameterValueException

use of com.cloud.legacymodel.exceptions.InvalidParameterValueException in project cosmic by MissionCriticalCloud.

the class ConfigurationManagerImpl method commitVlan.

private Vlan commitVlan(final Long zoneId, final Long podId, final String startIP, final String endIP, final String newVlanGatewayFinal, final String newVlanNetmaskFinal, final String vlanId, final Boolean forVirtualNetwork, final Long networkId, final Long physicalNetworkId, final String startIPv6, final String endIPv6, final String ip6Gateway, final String ip6Cidr, final Domain domain, final Account vlanOwner, final Network network, final Pair<Boolean, Pair<String, String>> sameSubnet) {
    return Transaction.execute(new TransactionCallback<Vlan>() {

        @Override
        public Vlan doInTransaction(final TransactionStatus status) {
            String newVlanNetmask = newVlanNetmaskFinal;
            String newVlanGateway = newVlanGatewayFinal;
            if ((sameSubnet == null || sameSubnet.first() == false) && network.getTrafficType() == TrafficType.Guest && network.getGuestType() == GuestType.Shared && _vlanDao.listVlansByNetworkId(networkId) != null) {
                final Map<Capability, String> dhcpCapabilities = _networkSvc.getNetworkOfferingServiceCapabilities(_networkOfferingDao.findById(network.getNetworkOfferingId()), Service.Dhcp);
                final String supportsMultipleSubnets = dhcpCapabilities.get(Capability.DhcpAccrossMultipleSubnets);
                if (supportsMultipleSubnets == null || !Boolean.valueOf(supportsMultipleSubnets)) {
                    throw new InvalidParameterValueException("The Dhcp serivice provider for this network dose not support the dhcp  across multiple subnets");
                }
                s_logger.info("adding a new subnet to the network " + network.getId());
            } else if (sameSubnet != null) {
                // if it is same subnet the user might not send the vlan and the
                // netmask details. so we are
                // figuring out while validation and setting them here.
                newVlanGateway = sameSubnet.second().first();
                newVlanNetmask = sameSubnet.second().second();
            }
            final Vlan vlan = createVlanAndPublicIpRange(zoneId, networkId, physicalNetworkId, forVirtualNetwork, podId, startIP, endIP, newVlanGateway, newVlanNetmask, vlanId, domain, vlanOwner, startIPv6, endIPv6, ip6Gateway, ip6Cidr);
            // gateway that will be configured on the corresponding routervm.
            return vlan;
        }
    });
}
Also used : InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) TransactionStatus(com.cloud.utils.db.TransactionStatus) Vlan(com.cloud.legacymodel.dc.Vlan) Map(java.util.Map) HashMap(java.util.HashMap)

Example 23 with InvalidParameterValueException

use of com.cloud.legacymodel.exceptions.InvalidParameterValueException in project cosmic by MissionCriticalCloud.

the class ConfigurationManagerImpl method releasePublicIpRange.

@Override
@ActionEvent(eventType = EventTypes.EVENT_VLAN_IP_RANGE_RELEASE, eventDescription = "releasing a public ip range", async = false)
public boolean releasePublicIpRange(final ReleasePublicIpRangeCmd cmd) {
    final Long vlanDbId = cmd.getId();
    final VlanVO vlan = _vlanDao.findById(vlanDbId);
    if (vlan == null) {
        throw new InvalidParameterValueException("Please specify a valid IP range id.");
    }
    return releasePublicIpRange(vlanDbId, CallContext.current().getCallingUserId(), CallContext.current().getCallingAccount());
}
Also used : InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) VlanVO(com.cloud.dc.VlanVO) ActionEvent(com.cloud.event.ActionEvent)

Example 24 with InvalidParameterValueException

use of com.cloud.legacymodel.exceptions.InvalidParameterValueException in project cosmic by MissionCriticalCloud.

the class ConfigurationManagerImpl method deleteServiceOffering.

@Override
@ActionEvent(eventType = EventTypes.EVENT_SERVICE_OFFERING_DELETE, eventDescription = "deleting service offering")
public boolean deleteServiceOffering(final DeleteServiceOfferingCmd cmd) {
    final Long offeringId = cmd.getId();
    Long userId = CallContext.current().getCallingUserId();
    if (userId == null) {
        userId = Long.valueOf(User.UID_SYSTEM);
    }
    // Verify service offering id
    final ServiceOfferingVO offering = _serviceOfferingDao.findById(offeringId);
    if (offering == null) {
        throw new InvalidParameterValueException("unable to find service offering " + offeringId);
    }
    if (offering.getDefaultUse()) {
        throw new InvalidParameterValueException("Default service offerings cannot be deleted");
    }
    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 (offering.getDomainId() == null) {
            throw new InvalidParameterValueException("Unable to delete public service offering by id " + userId + " because it is domain-admin");
        }
        if (!_domainDao.isChildDomain(account.getDomainId(), offering.getDomainId())) {
            throw new InvalidParameterValueException("Unable to delete service offering by another domain admin with id " + userId);
        }
    } else if (account.getType() != Account.ACCOUNT_TYPE_ADMIN) {
        throw new InvalidParameterValueException("Unable to delete service offering by id " + userId + " because it is not root-admin or domain-admin");
    }
    offering.setState(DiskOffering.State.Inactive);
    if (_serviceOfferingDao.update(offeringId, offering)) {
        CallContext.current().setEventDetails("Service offering id=" + offeringId);
        return true;
    } else {
        return false;
    }
}
Also used : Account(com.cloud.legacymodel.user.Account) User(com.cloud.legacymodel.user.User) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) ServiceOfferingVO(com.cloud.service.ServiceOfferingVO) ActionEvent(com.cloud.event.ActionEvent)

Example 25 with InvalidParameterValueException

use of com.cloud.legacymodel.exceptions.InvalidParameterValueException in project cosmic by MissionCriticalCloud.

the class ConfigurationManagerImpl method editPod.

@Override
@DB
public Pod editPod(final long id, String name, String startIp, String endIp, String gateway, String netmask, String allocationStateStr) {
    // verify parameters
    final HostPodVO pod = _podDao.findById(id);
    if (pod == null) {
        throw new InvalidParameterValueException("Unable to find pod by id " + id);
    }
    final String[] existingPodIpRange = pod.getDescription().split("-");
    String[] leftRangeToAdd = null;
    String[] rightRangeToAdd = null;
    boolean allowToDownsize = false;
    // pod has allocated private IP addresses
    if (podHasAllocatedPrivateIPs(id)) {
        if (netmask != null) {
            final long newCidr = NetUtils.getCidrSize(netmask);
            final long oldCidr = pod.getCidrSize();
            if (newCidr > oldCidr) {
                throw new CloudRuntimeException("The specified pod has allocated private IP addresses, so its IP address range can be extended only");
            }
        }
        if (startIp != null && !startIp.equals(existingPodIpRange[0])) {
            if (NetUtils.ipRangesOverlap(startIp, null, existingPodIpRange[0], existingPodIpRange[1])) {
                throw new CloudRuntimeException("The specified pod has allocated private IP addresses, so its IP address range can be extended only");
            } else {
                leftRangeToAdd = new String[2];
                final long endIpForUpdate = NetUtils.ip2Long(existingPodIpRange[0]) - 1;
                leftRangeToAdd[0] = startIp;
                leftRangeToAdd[1] = NetUtils.long2Ip(endIpForUpdate);
            }
        }
        if (endIp != null && !endIp.equals(existingPodIpRange[1])) {
            if (NetUtils.ipRangesOverlap(endIp, endIp, existingPodIpRange[0], existingPodIpRange[1])) {
                throw new CloudRuntimeException("The specified pod has allocated private IP addresses, so its IP address range can be extended only");
            } else {
                rightRangeToAdd = new String[2];
                final long startIpForUpdate = NetUtils.ip2Long(existingPodIpRange[1]) + 1;
                rightRangeToAdd[0] = NetUtils.long2Ip(startIpForUpdate);
                rightRangeToAdd[1] = endIp;
            }
        }
    } else {
        allowToDownsize = true;
    }
    if (gateway == null) {
        gateway = pod.getGateway();
    }
    if (netmask == null) {
        netmask = NetUtils.getCidrNetmask(pod.getCidrSize());
    }
    final String oldPodName = pod.getName();
    if (name == null) {
        name = oldPodName;
    }
    if (gateway == null) {
        gateway = pod.getGateway();
    }
    if (startIp == null) {
        startIp = existingPodIpRange[0];
    }
    if (endIp == null) {
        endIp = existingPodIpRange[1];
    }
    if (allocationStateStr == null) {
        allocationStateStr = pod.getAllocationState().toString();
    }
    // Verify pod's attributes
    final String cidr = NetUtils.ipAndNetMaskToCidr(gateway, netmask);
    final boolean checkForDuplicates = !oldPodName.equals(name);
    checkPodAttributes(id, name, pod.getDataCenterId(), gateway, cidr, startIp, endIp, allocationStateStr, checkForDuplicates, false);
    try {
        final String[] existingPodIpRangeFinal = existingPodIpRange;
        final String[] leftRangeToAddFinal = leftRangeToAdd;
        final String[] rightRangeToAddFinal = rightRangeToAdd;
        final boolean allowToDownsizeFinal = allowToDownsize;
        final String allocationStateStrFinal = allocationStateStr;
        final String startIpFinal = startIp;
        final String endIpFinal = endIp;
        final String nameFinal = name;
        final String gatewayFinal = gateway;
        Transaction.execute(new TransactionCallbackNoReturn() {

            @Override
            public void doInTransactionWithoutResult(final TransactionStatus status) {
                final long zoneId = pod.getDataCenterId();
                String startIp = startIpFinal;
                String endIp = endIpFinal;
                if (!allowToDownsizeFinal) {
                    if (leftRangeToAddFinal != null) {
                        _zoneDao.addPrivateIpAddress(zoneId, pod.getId(), leftRangeToAddFinal[0], leftRangeToAddFinal[1]);
                    }
                    if (rightRangeToAddFinal != null) {
                        _zoneDao.addPrivateIpAddress(zoneId, pod.getId(), rightRangeToAddFinal[0], rightRangeToAddFinal[1]);
                    }
                } else {
                    // delete the old range
                    _zoneDao.deletePrivateIpAddressByPod(pod.getId());
                    // add the new one
                    if (startIp == null) {
                        startIp = existingPodIpRangeFinal[0];
                    }
                    if (endIp == null) {
                        endIp = existingPodIpRangeFinal[1];
                    }
                    _zoneDao.addPrivateIpAddress(zoneId, pod.getId(), startIp, endIp);
                }
                pod.setName(nameFinal);
                pod.setDataCenterId(zoneId);
                pod.setGateway(gatewayFinal);
                pod.setCidrAddress(getCidrAddress(cidr));
                pod.setCidrSize(getCidrSize(cidr));
                final String ipRange = startIp + "-" + endIp;
                pod.setDescription(ipRange);
                final AllocationState allocationState;
                if (allocationStateStrFinal != null && !allocationStateStrFinal.isEmpty()) {
                    allocationState = AllocationState.valueOf(allocationStateStrFinal);
                    pod.setAllocationState(allocationState);
                }
                _podDao.update(id, pod);
            }
        });
    } catch (final Exception e) {
        s_logger.error("Unable to edit pod due to " + e.getMessage(), e);
        throw new CloudRuntimeException("Failed to edit pod. Please contact Cloud Support.");
    }
    return pod;
}
Also used : InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) AllocationState(com.cloud.model.enumeration.AllocationState) TransactionStatus(com.cloud.utils.db.TransactionStatus) TransactionCallbackNoReturn(com.cloud.utils.db.TransactionCallbackNoReturn) HostPodVO(com.cloud.dc.HostPodVO) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) PermissionDeniedException(com.cloud.legacymodel.exceptions.PermissionDeniedException) ResourceAllocationException(com.cloud.legacymodel.exceptions.ResourceAllocationException) SQLException(java.sql.SQLException) ConcurrentOperationException(com.cloud.legacymodel.exceptions.ConcurrentOperationException) InsufficientCapacityException(com.cloud.legacymodel.exceptions.InsufficientCapacityException) ConfigurationException(javax.naming.ConfigurationException) ResourceUnavailableException(com.cloud.legacymodel.exceptions.ResourceUnavailableException) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) DB(com.cloud.utils.db.DB)

Aggregations

InvalidParameterValueException (com.cloud.legacymodel.exceptions.InvalidParameterValueException)483 Account (com.cloud.legacymodel.user.Account)219 ActionEvent (com.cloud.event.ActionEvent)159 CloudRuntimeException (com.cloud.legacymodel.exceptions.CloudRuntimeException)153 ArrayList (java.util.ArrayList)105 DB (com.cloud.utils.db.DB)97 PermissionDeniedException (com.cloud.legacymodel.exceptions.PermissionDeniedException)76 List (java.util.List)62 TransactionStatus (com.cloud.utils.db.TransactionStatus)58 ResourceUnavailableException (com.cloud.legacymodel.exceptions.ResourceUnavailableException)53 Network (com.cloud.legacymodel.network.Network)51 ServerApiException (com.cloud.api.ServerApiException)47 ConcurrentOperationException (com.cloud.legacymodel.exceptions.ConcurrentOperationException)43 Pair (com.cloud.legacymodel.utils.Pair)36 HashMap (java.util.HashMap)36 ConfigurationException (javax.naming.ConfigurationException)36 ResourceAllocationException (com.cloud.legacymodel.exceptions.ResourceAllocationException)33 NetworkVO (com.cloud.network.dao.NetworkVO)31 TransactionCallbackNoReturn (com.cloud.utils.db.TransactionCallbackNoReturn)30 HostVO (com.cloud.host.HostVO)29