Search in sources :

Example 66 with ServiceOfferingVO

use of com.cloud.service.ServiceOfferingVO 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 67 with ServiceOfferingVO

use of com.cloud.service.ServiceOfferingVO in project cloudstack by apache.

the class ManagementServerImpl method upgradeStoppedSystemVm.

private VirtualMachine upgradeStoppedSystemVm(final Long systemVmId, final Long serviceOfferingId, final Map<String, String> customparameters) {
    final Account caller = getCaller();
    final VMInstanceVO systemVm = _vmInstanceDao.findByIdTypes(systemVmId, VirtualMachine.Type.ConsoleProxy, VirtualMachine.Type.SecondaryStorageVm);
    if (systemVm == null) {
        throw new InvalidParameterValueException("Unable to find SystemVm with id " + systemVmId);
    }
    _accountMgr.checkAccess(caller, null, true, systemVm);
    // Check that the specified service offering ID is valid
    ServiceOfferingVO newServiceOffering = _offeringDao.findById(serviceOfferingId);
    final ServiceOfferingVO currentServiceOffering = _offeringDao.findById(systemVmId, systemVm.getServiceOfferingId());
    if (newServiceOffering.isDynamic()) {
        newServiceOffering.setDynamicFlag(true);
        _userVmMgr.validateCustomParameters(newServiceOffering, customparameters);
        newServiceOffering = _offeringDao.getcomputeOffering(newServiceOffering, customparameters);
    }
    _itMgr.checkIfCanUpgrade(systemVm, newServiceOffering);
    final boolean result = _itMgr.upgradeVmDb(systemVmId, serviceOfferingId);
    if (newServiceOffering.isDynamic()) {
        //save the custom values to the database.
        _userVmMgr.saveCustomOfferingDetails(systemVmId, newServiceOffering);
    }
    if (currentServiceOffering.isDynamic() && !newServiceOffering.isDynamic()) {
        _userVmMgr.removeCustomOfferingDetails(systemVmId);
    }
    if (result) {
        return _vmInstanceDao.findById(systemVmId);
    } else {
        throw new CloudRuntimeException("Unable to upgrade system vm " + systemVm);
    }
}
Also used : Account(com.cloud.user.Account) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) VMInstanceVO(com.cloud.vm.VMInstanceVO) ServiceOfferingVO(com.cloud.service.ServiceOfferingVO)

Example 68 with ServiceOfferingVO

use of com.cloud.service.ServiceOfferingVO in project cloudstack by apache.

the class SecondaryStorageManagerImpl method createSecStorageVmInstance.

protected Map<String, Object> createSecStorageVmInstance(long dataCenterId, SecondaryStorageVm.Role role) {
    DataStore secStore = _dataStoreMgr.getImageStore(dataCenterId);
    if (secStore == null) {
        String msg = "No secondary storage available in zone " + dataCenterId + ", cannot create secondary storage vm";
        s_logger.warn(msg);
        throw new CloudRuntimeException(msg);
    }
    long id = _secStorageVmDao.getNextInSequence(Long.class, "id");
    String name = VirtualMachineName.getSystemVmName(id, _instance, "s").intern();
    Account systemAcct = _accountMgr.getSystemAccount();
    DataCenterDeployment plan = new DataCenterDeployment(dataCenterId);
    DataCenter dc = _dcDao.findById(plan.getDataCenterId());
    NetworkVO defaultNetwork = getDefaultNetworkForCreation(dc);
    List<? extends NetworkOffering> offerings = null;
    if (_sNwMgr.isStorageIpRangeAvailable(dataCenterId)) {
        offerings = _networkModel.getSystemAccountNetworkOfferings(NetworkOffering.SystemControlNetwork, NetworkOffering.SystemManagementNetwork, NetworkOffering.SystemStorageNetwork);
    } else {
        offerings = _networkModel.getSystemAccountNetworkOfferings(NetworkOffering.SystemControlNetwork, NetworkOffering.SystemManagementNetwork);
    }
    LinkedHashMap<Network, List<? extends NicProfile>> networks = new LinkedHashMap<Network, List<? extends NicProfile>>(offerings.size() + 1);
    NicProfile defaultNic = new NicProfile();
    defaultNic.setDefaultNic(true);
    defaultNic.setDeviceId(2);
    try {
        networks.put(_networkMgr.setupNetwork(systemAcct, _networkOfferingDao.findById(defaultNetwork.getNetworkOfferingId()), plan, null, null, false).get(0), new ArrayList<NicProfile>(Arrays.asList(defaultNic)));
        for (NetworkOffering offering : offerings) {
            networks.put(_networkMgr.setupNetwork(systemAcct, offering, plan, null, null, false).get(0), new ArrayList<NicProfile>());
        }
    } catch (ConcurrentOperationException e) {
        s_logger.info("Unable to setup due to concurrent operation. " + e);
        return new HashMap<String, Object>();
    }
    VMTemplateVO template = null;
    HypervisorType availableHypervisor = _resourceMgr.getAvailableHypervisor(dataCenterId);
    template = _templateDao.findSystemVMReadyTemplate(dataCenterId, availableHypervisor);
    if (template == null) {
        throw new CloudRuntimeException("Not able to find the System templates or not downloaded in zone " + dataCenterId);
    }
    ServiceOfferingVO serviceOffering = _serviceOffering;
    if (serviceOffering == null) {
        serviceOffering = _offeringDao.findDefaultSystemOffering(ServiceOffering.ssvmDefaultOffUniqueName, ConfigurationManagerImpl.SystemVMUseLocalStorage.valueIn(dataCenterId));
    }
    SecondaryStorageVmVO secStorageVm = new SecondaryStorageVmVO(id, serviceOffering.getId(), name, template.getId(), template.getHypervisorType(), template.getGuestOSId(), dataCenterId, systemAcct.getDomainId(), systemAcct.getId(), _accountMgr.getSystemUser().getId(), role, serviceOffering.getOfferHA());
    secStorageVm.setDynamicallyScalable(template.isDynamicallyScalable());
    secStorageVm = _secStorageVmDao.persist(secStorageVm);
    try {
        _itMgr.allocate(name, template, serviceOffering, networks, plan, null);
        secStorageVm = _secStorageVmDao.findById(secStorageVm.getId());
    } catch (InsufficientCapacityException e) {
        s_logger.warn("InsufficientCapacity", e);
        throw new CloudRuntimeException("Insufficient capacity exception", e);
    }
    Map<String, Object> context = new HashMap<String, Object>();
    context.put("secStorageVmId", secStorageVm.getId());
    return context;
}
Also used : Account(com.cloud.user.Account) SecondaryStorageVmVO(com.cloud.vm.SecondaryStorageVmVO) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) VMTemplateVO(com.cloud.storage.VMTemplateVO) ServiceOfferingVO(com.cloud.service.ServiceOfferingVO) LinkedHashMap(java.util.LinkedHashMap) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) Network(com.cloud.network.Network) ArrayList(java.util.ArrayList) List(java.util.List) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) NetworkVO(com.cloud.network.dao.NetworkVO) DataCenterDeployment(com.cloud.deploy.DataCenterDeployment) NetworkOffering(com.cloud.offering.NetworkOffering) NicProfile(com.cloud.vm.NicProfile) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) HypervisorType(com.cloud.hypervisor.Hypervisor.HypervisorType) DataCenter(com.cloud.dc.DataCenter)

Example 69 with ServiceOfferingVO

use of com.cloud.service.ServiceOfferingVO in project cloudstack by apache.

the class ServiceOfferingDaoImpl method findDefaultSystemOffering.

@Override
public ServiceOfferingVO findDefaultSystemOffering(String offeringName, Boolean useLocalStorage) {
    String name = offeringName;
    if (useLocalStorage != null && useLocalStorage.booleanValue()) {
        name += "-Local";
    }
    ServiceOfferingVO serviceOffering = findByName(name);
    if (serviceOffering == null) {
        String message = "System service offering " + name + " not found";
        s_logger.error(message);
        throw new CloudRuntimeException(message);
    }
    return serviceOffering;
}
Also used : CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ServiceOfferingVO(com.cloud.service.ServiceOfferingVO)

Example 70 with ServiceOfferingVO

use of com.cloud.service.ServiceOfferingVO in project cloudstack by apache.

the class VirtualMachineManagerImplTest method testScaleVM2.

@Test(expected = CloudRuntimeException.class)
public void testScaleVM2() throws Exception {
    new DeployDestination(null, null, null, _host);
    doReturn(3L).when(_vmInstance).getId();
    when(_vmInstanceDao.findById(anyLong())).thenReturn(_vmInstance);
    ServiceOfferingVO newServiceOffering = getSvcoffering(512);
    doReturn(1L).when(_vmInstance).getHostId();
    doReturn(hostVO).when(_hostDao).findById(1L);
    doReturn(1L).when(_vmInstance).getDataCenterId();
    doReturn(1L).when(hostVO).getClusterId();
    when(CapacityManager.CpuOverprovisioningFactor.valueIn(1L)).thenReturn(1.0f);
    ScaleVmCommand reconfigureCmd = new ScaleVmCommand("myVmName", newServiceOffering.getCpu(), newServiceOffering.getSpeed(), newServiceOffering.getSpeed(), newServiceOffering.getRamSize(), newServiceOffering.getRamSize(), newServiceOffering.getLimitCpuUse());
    new ScaleVmAnswer(reconfigureCmd, true, "details");
    when(_agentMgr.send(2l, reconfigureCmd)).thenReturn(null);
    _vmMgr.reConfigureVm(_vmInstance.getUuid(), getSvcoffering(256), false);
}
Also used : ScaleVmAnswer(com.cloud.agent.api.ScaleVmAnswer) DeployDestination(com.cloud.deploy.DeployDestination) ServiceOfferingVO(com.cloud.service.ServiceOfferingVO) ScaleVmCommand(com.cloud.agent.api.ScaleVmCommand) Test(org.junit.Test)

Aggregations

ServiceOfferingVO (com.cloud.service.ServiceOfferingVO)72 ArrayList (java.util.ArrayList)24 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)18 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)18 Account (com.cloud.user.Account)17 List (java.util.List)14 Network (com.cloud.network.Network)10 DB (com.cloud.utils.db.DB)10 VolumeVO (com.cloud.storage.VolumeVO)9 NicProfile (com.cloud.vm.NicProfile)9 VMInstanceVO (com.cloud.vm.VMInstanceVO)9 HashMap (java.util.HashMap)9 LinkedHashMap (java.util.LinkedHashMap)9 ConfigurationException (javax.naming.ConfigurationException)9 DataCenterDeployment (com.cloud.deploy.DataCenterDeployment)8 ExcludeList (com.cloud.deploy.DeploymentPlanner.ExcludeList)8 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)8 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)8 HypervisorType (com.cloud.hypervisor.Hypervisor.HypervisorType)8 DomainRouterVO (com.cloud.vm.DomainRouterVO)8