Search in sources :

Example 1 with ProvisioningType

use of com.cloud.storage.Storage.ProvisioningType in project cloudstack by apache.

the class ConfigurationManagerImpl method createServiceOffering.

protected ServiceOfferingVO createServiceOffering(final long userId, final boolean isSystem, final VirtualMachine.Type vmType, final String name, final Integer cpu, final Integer ramSize, final Integer speed, 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, 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 ProvisioningType typedProvisioningType = ProvisioningType.getProvisioningType(provisioningType);
    tags = StringUtils.cleanupTags(tags);
    ServiceOfferingVO offering = new ServiceOfferingVO(name, cpu, ramSize, speed, 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 (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<ServiceOfferingDetailsVO>();
        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.user.Account) ProvisioningType(com.cloud.storage.Storage.ProvisioningType) User(com.cloud.user.User) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ServiceOfferingDetailsVO(com.cloud.service.ServiceOfferingDetailsVO) ServiceOfferingVO(com.cloud.service.ServiceOfferingVO)

Example 2 with ProvisioningType

use of com.cloud.storage.Storage.ProvisioningType in project cloudstack by apache.

the class DatabaseConfig method saveDiskOffering.

@DB
protected void saveDiskOffering() {
    long id = Long.parseLong(_currentObjectParams.get("id"));
    long domainId = Long.parseLong(_currentObjectParams.get("domainId"));
    String name = _currentObjectParams.get("name");
    String displayText = _currentObjectParams.get("displayText");
    ProvisioningType provisioningType = ProvisioningType.valueOf(_currentObjectParams.get("provisioningtype"));
    long diskSpace = Long.parseLong(_currentObjectParams.get("diskSpace"));
    diskSpace = diskSpace * 1024 * 1024;
    //        boolean mirroring = Boolean.parseBoolean(_currentObjectParams.get("mirrored"));
    String tags = _currentObjectParams.get("tags");
    String useLocal = _currentObjectParams.get("useLocal");
    boolean local = false;
    if (useLocal != null) {
        local = Boolean.parseBoolean(useLocal);
    }
    if (tags != null && tags.length() > 0) {
        String[] tokens = tags.split(",");
        StringBuilder newTags = new StringBuilder();
        for (String token : tokens) {
            newTags.append(token.trim()).append(",");
        }
        newTags.delete(newTags.length() - 1, newTags.length());
        tags = newTags.toString();
    }
    DiskOfferingVO diskOffering = new DiskOfferingVO(domainId, name, displayText, provisioningType, diskSpace, tags, false, null, null, null);
    diskOffering.setUseLocalStorage(local);
    Long bytesReadRate = Long.parseLong(_currentObjectParams.get("bytesReadRate"));
    if (bytesReadRate != null && (bytesReadRate > 0))
        diskOffering.setBytesReadRate(bytesReadRate);
    Long bytesWriteRate = Long.parseLong(_currentObjectParams.get("bytesWriteRate"));
    if (bytesWriteRate != null && (bytesWriteRate > 0))
        diskOffering.setBytesWriteRate(bytesWriteRate);
    Long iopsReadRate = Long.parseLong(_currentObjectParams.get("iopsReadRate"));
    if (iopsReadRate != null && (iopsReadRate > 0))
        diskOffering.setIopsReadRate(iopsReadRate);
    Long iopsWriteRate = Long.parseLong(_currentObjectParams.get("iopsWriteRate"));
    if (iopsWriteRate != null && (iopsWriteRate > 0))
        diskOffering.setIopsWriteRate(iopsWriteRate);
    DiskOfferingDaoImpl offering = ComponentContext.inject(DiskOfferingDaoImpl.class);
    try {
        offering.persist(diskOffering);
    } catch (Exception e) {
        s_logger.error("error creating disk offering", e);
    }
/*
        String insertSql = "INSERT INTO `cloud`.`disk_offering` (id, domain_id, name, display_text, disk_size, mirrored, tags) " +
                "VALUES (" + id + "," + domainId + ",'" + name + "','" + displayText + "'," + diskSpace + "," + mirroring + ", ? )";

        Transaction txn = Transaction.currentTxn();
        try {
            PreparedStatement stmt = txn.prepareAutoCloseStatement(insertSql);
            stmt.setString(1, tags);
            stmt.executeUpdate();
        } catch (SQLException ex) {
            s_logger.error("error creating disk offering", ex);
            return;
        }
         */
}
Also used : ProvisioningType(com.cloud.storage.Storage.ProvisioningType) DiskOfferingVO(com.cloud.storage.DiskOfferingVO) DiskOfferingDaoImpl(com.cloud.storage.dao.DiskOfferingDaoImpl) URISyntaxException(java.net.URISyntaxException) SQLException(java.sql.SQLException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) SAXException(org.xml.sax.SAXException) DB(com.cloud.utils.db.DB)

Example 3 with ProvisioningType

use of com.cloud.storage.Storage.ProvisioningType in project cloudstack by apache.

the class DatabaseConfig method saveServiceOffering.

@DB
protected void saveServiceOffering() {
    long id = Long.parseLong(_currentObjectParams.get("id"));
    String name = _currentObjectParams.get("name");
    String displayText = _currentObjectParams.get("displayText");
    ProvisioningType provisioningType = ProvisioningType.valueOf(_currentObjectParams.get("provisioningType"));
    int cpu = Integer.parseInt(_currentObjectParams.get("cpu"));
    int ramSize = Integer.parseInt(_currentObjectParams.get("ramSize"));
    int speed = Integer.parseInt(_currentObjectParams.get("speed"));
    String useLocalStorageValue = _currentObjectParams.get("useLocalStorage");
    //        int nwRate = Integer.parseInt(_currentObjectParams.get("nwRate"));
    //        int mcRate = Integer.parseInt(_currentObjectParams.get("mcRate"));
    boolean ha = Boolean.parseBoolean(_currentObjectParams.get("enableHA"));
    boolean mirroring = Boolean.parseBoolean(_currentObjectParams.get("mirrored"));
    boolean useLocalStorage;
    if (useLocalStorageValue != null) {
        if (Boolean.parseBoolean(useLocalStorageValue)) {
            useLocalStorage = true;
        } else {
            useLocalStorage = false;
        }
    } else {
        useLocalStorage = false;
    }
    ServiceOfferingVO serviceOffering = new ServiceOfferingVO(name, cpu, ramSize, speed, null, null, ha, displayText, provisioningType, useLocalStorage, false, null, false, null, false);
    Long bytesReadRate = Long.parseLong(_currentObjectParams.get("bytesReadRate"));
    if ((bytesReadRate != null) && (bytesReadRate > 0))
        serviceOffering.setBytesReadRate(bytesReadRate);
    Long bytesWriteRate = Long.parseLong(_currentObjectParams.get("bytesWriteRate"));
    if ((bytesWriteRate != null) && (bytesWriteRate > 0))
        serviceOffering.setBytesWriteRate(bytesWriteRate);
    Long iopsReadRate = Long.parseLong(_currentObjectParams.get("iopsReadRate"));
    if ((iopsReadRate != null) && (iopsReadRate > 0))
        serviceOffering.setIopsReadRate(iopsReadRate);
    Long iopsWriteRate = Long.parseLong(_currentObjectParams.get("iopsWriteRate"));
    if ((iopsWriteRate != null) && (iopsWriteRate > 0))
        serviceOffering.setIopsWriteRate(iopsWriteRate);
    ServiceOfferingDaoImpl dao = ComponentContext.inject(ServiceOfferingDaoImpl.class);
    try {
        dao.persist(serviceOffering);
    } catch (Exception e) {
        s_logger.error("error creating service offering", e);
    }
/*
        String insertSql = "INSERT INTO `cloud`.`service_offering` (id, name, cpu, ram_size, speed, nw_rate, mc_rate, created, ha_enabled, mirrored, display_text, guest_ip_type, use_local_storage) " +
                "VALUES (" + id + ",'" + name + "'," + cpu + "," + ramSize + "," + speed + "," + nwRate + "," + mcRate + ",now()," + ha + "," + mirroring + ",'" + displayText + "','" + guestIpType + "','" + useLocalStorage + "')";

        Transaction txn = Transaction.currentTxn();
        try {
            PreparedStatement stmt = txn.prepareAutoCloseStatement(insertSql);
            stmt.executeUpdate();
        } catch (SQLException ex) {
            s_logger.error("error creating service offering", ex);
            return;
        }
         */
}
Also used : ProvisioningType(com.cloud.storage.Storage.ProvisioningType) ServiceOfferingDaoImpl(com.cloud.service.dao.ServiceOfferingDaoImpl) ServiceOfferingVO(com.cloud.service.ServiceOfferingVO) URISyntaxException(java.net.URISyntaxException) SQLException(java.sql.SQLException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) SAXException(org.xml.sax.SAXException) DB(com.cloud.utils.db.DB)

Example 4 with ProvisioningType

use of com.cloud.storage.Storage.ProvisioningType in project cloudstack by apache.

the class ConfigurationManagerImpl method createDiskOffering.

protected DiskOfferingVO createDiskOffering(final Long userId, final Long domainId, final String name, final String description, final String provisioningType, final Long numGibibytes, String tags, boolean isCustomized, final boolean localStorageRequired, final boolean isDisplayOfferingEnabled, final Boolean isCustomizedIops, Long minIops, Long maxIops, Long bytesReadRate, Long bytesWriteRate, Long iopsReadRate, Long iopsWriteRate, final Integer hypervisorSnapshotReserve) {
    // special case for custom disk offerings
    long diskSize = 0;
    if (numGibibytes != null && numGibibytes <= 0) {
        throw new InvalidParameterValueException("Please specify a disk size of at least 1 Gb.");
    } else if (numGibibytes != null && numGibibytes > _maxVolumeSizeInGb) {
        throw new InvalidParameterValueException("The maximum size for a disk is " + _maxVolumeSizeInGb + " Gb.");
    }
    final ProvisioningType typedProvisioningType = ProvisioningType.getProvisioningType(provisioningType);
    if (numGibibytes != null) {
        diskSize = numGibibytes * 1024 * 1024 * 1024;
    }
    if (diskSize == 0) {
        isCustomized = true;
    }
    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;
    }
    // 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 disk offering by id " + userId + " because it is domain-admin");
        }
        if (tags != null) {
            throw new InvalidParameterValueException("Unable to create disk offering with storage tags by id " + userId + " because it is domain-admin");
        }
        if (!_domainDao.isChildDomain(account.getDomainId(), domainId)) {
            throw new InvalidParameterValueException("Unable to create disk offering by another domain admin with id " + userId);
        }
    } else if (account.getType() != Account.ACCOUNT_TYPE_ADMIN) {
        throw new InvalidParameterValueException("Unable to create disk offering by id " + userId + " because it is not root-admin or domain-admin");
    }
    tags = StringUtils.cleanupTags(tags);
    final DiskOfferingVO newDiskOffering = new DiskOfferingVO(domainId, name, description, typedProvisioningType, diskSize, tags, isCustomized, isCustomizedIops, minIops, maxIops);
    newDiskOffering.setUseLocalStorage(localStorageRequired);
    newDiskOffering.setDisplayOffering(isDisplayOfferingEnabled);
    if (bytesReadRate != null && bytesReadRate > 0) {
        newDiskOffering.setBytesReadRate(bytesReadRate);
    }
    if (bytesWriteRate != null && bytesWriteRate > 0) {
        newDiskOffering.setBytesWriteRate(bytesWriteRate);
    }
    if (iopsReadRate != null && iopsReadRate > 0) {
        newDiskOffering.setIopsReadRate(iopsReadRate);
    }
    if (iopsWriteRate != null && iopsWriteRate > 0) {
        newDiskOffering.setIopsWriteRate(iopsWriteRate);
    }
    if (hypervisorSnapshotReserve != null && hypervisorSnapshotReserve < 0) {
        throw new InvalidParameterValueException("If provided, Hypervisor Snapshot Reserve must be greater than or equal to 0.");
    }
    newDiskOffering.setHypervisorSnapshotReserve(hypervisorSnapshotReserve);
    CallContext.current().setEventDetails("Disk offering id=" + newDiskOffering.getId());
    final DiskOfferingVO offering = _diskOfferingDao.persist(newDiskOffering);
    if (offering != null) {
        CallContext.current().setEventDetails("Disk offering id=" + newDiskOffering.getId());
        return offering;
    } else {
        return null;
    }
}
Also used : ProvisioningType(com.cloud.storage.Storage.ProvisioningType) Account(com.cloud.user.Account) User(com.cloud.user.User) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) DiskOfferingVO(com.cloud.storage.DiskOfferingVO)

Aggregations

ProvisioningType (com.cloud.storage.Storage.ProvisioningType)4 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)2 ServiceOfferingVO (com.cloud.service.ServiceOfferingVO)2 DiskOfferingVO (com.cloud.storage.DiskOfferingVO)2 Account (com.cloud.user.Account)2 User (com.cloud.user.User)2 DB (com.cloud.utils.db.DB)2 IOException (java.io.IOException)2 URISyntaxException (java.net.URISyntaxException)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 SQLException (java.sql.SQLException)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 SAXException (org.xml.sax.SAXException)2 ServiceOfferingDetailsVO (com.cloud.service.ServiceOfferingDetailsVO)1 ServiceOfferingDaoImpl (com.cloud.service.dao.ServiceOfferingDaoImpl)1 DiskOfferingDaoImpl (com.cloud.storage.dao.DiskOfferingDaoImpl)1