Search in sources :

Example 21 with ServiceOfferingVO

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

the class ServiceOfferingDaoImpl method remove.

@Override
public boolean remove(Long id) {
    ServiceOfferingVO offering = createForUpdate();
    offering.setRemoved(new Date());
    return update(id, offering);
}
Also used : ServiceOfferingVO(com.cloud.service.ServiceOfferingVO) Date(java.util.Date)

Example 22 with ServiceOfferingVO

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

the class ServiceOfferingDaoImpl method createSystemServiceOfferings.

@Override
public List<ServiceOfferingVO> createSystemServiceOfferings(String name, String uniqueName, int cpuCount, int ramSize, int cpuSpeed, Integer rateMbps, Integer multicastRateMbps, boolean offerHA, String displayText, ProvisioningType provisioningType, boolean recreatable, String tags, boolean systemUse, VirtualMachine.Type vmType, boolean defaultUse) {
    List<ServiceOfferingVO> list = new ArrayList<ServiceOfferingVO>();
    ServiceOfferingVO offering = new ServiceOfferingVO(name, cpuCount, ramSize, cpuSpeed, rateMbps, multicastRateMbps, offerHA, displayText, provisioningType, false, recreatable, tags, systemUse, vmType, defaultUse);
    offering.setUniqueName(uniqueName);
    offering = persistSystemServiceOffering(offering);
    if (offering != null) {
        list.add(offering);
    }
    boolean useLocal = true;
    if (offering.getUseLocalStorage()) {
        // if 1st one is already local then 2nd needs to be shared
        useLocal = false;
    }
    offering = new ServiceOfferingVO(name + (useLocal ? " - Local Storage" : ""), cpuCount, ramSize, cpuSpeed, rateMbps, multicastRateMbps, offerHA, displayText, provisioningType, useLocal, recreatable, tags, systemUse, vmType, defaultUse);
    offering.setUniqueName(uniqueName + (useLocal ? "-Local" : ""));
    offering = persistSystemServiceOffering(offering);
    if (offering != null) {
        list.add(offering);
    }
    return list;
}
Also used : ArrayList(java.util.ArrayList) ServiceOfferingVO(com.cloud.service.ServiceOfferingVO)

Example 23 with ServiceOfferingVO

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

the class ServiceOfferingDaoImpl method findById.

@Override
public ServiceOfferingVO findById(Long vmId, long serviceOfferingId) {
    ServiceOfferingVO offering = super.findById(serviceOfferingId);
    if (offering.isDynamic()) {
        offering.setDynamicFlag(true);
        if (vmId == null) {
            throw new CloudRuntimeException("missing argument vmId");
        }
        Map<String, String> dynamicOffering = userVmDetailsDao.listDetailsKeyPairs(vmId);
        return getcomputeOffering(offering, dynamicOffering);
    }
    return offering;
}
Also used : CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ServiceOfferingVO(com.cloud.service.ServiceOfferingVO)

Example 24 with ServiceOfferingVO

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

the class ServiceOfferingDaoImpl method persistSystemServiceOffering.

@Override
@DB
public ServiceOfferingVO persistSystemServiceOffering(ServiceOfferingVO offering) {
    assert offering.getUniqueName() != null : "how are you going to find this later if you don't set it?";
    ServiceOfferingVO vo = findByName(offering.getUniqueName());
    if (vo != null) {
        // check invalid CPU speed in system service offering, set it to default value of 500 Mhz if 0 CPU speed is found
        if (vo.getSpeed() <= 0) {
            vo.setSpeed(500);
            update(vo.getId(), vo);
        }
        if (!vo.getUniqueName().endsWith("-Local")) {
            if (vo.getUseLocalStorage()) {
                vo.setUniqueName(vo.getUniqueName() + "-Local");
                vo.setName(vo.getName() + " - Local Storage");
                update(vo.getId(), vo);
            }
        }
        return vo;
    }
    try {
        return persist(offering);
    } catch (EntityExistsException e) {
        // Assume it's conflict on unique name
        return findByName(offering.getUniqueName());
    }
}
Also used : ServiceOfferingVO(com.cloud.service.ServiceOfferingVO) EntityExistsException(javax.persistence.EntityExistsException) DB(com.cloud.utils.db.DB)

Example 25 with ServiceOfferingVO

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

the class VirtualMachineManagerImplTest method testCheckIfCanUpgrade.

@Test
public void testCheckIfCanUpgrade() throws Exception {
    when(_vmInstance.getState()).thenReturn(State.Stopped);
    when(_serviceOfferingMock.isDynamic()).thenReturn(true);
    when(_vmInstance.getServiceOfferingId()).thenReturn(1l);
    when(_serviceOfferingMock.getId()).thenReturn(2l);
    ServiceOfferingVO mockCurrentServiceOffering = mock(ServiceOfferingVO.class);
    when(_offeringDao.findByIdIncludingRemoved(anyLong(), anyLong())).thenReturn(mockCurrentServiceOffering);
    when(mockCurrentServiceOffering.getUseLocalStorage()).thenReturn(true);
    when(_serviceOfferingMock.getUseLocalStorage()).thenReturn(true);
    when(mockCurrentServiceOffering.getSystemUse()).thenReturn(true);
    when(_serviceOfferingMock.getSystemUse()).thenReturn(true);
    when(mockCurrentServiceOffering.getTags()).thenReturn("x,y");
    when(_serviceOfferingMock.getTags()).thenReturn("z,x,y");
    _vmMgr.checkIfCanUpgrade(_vmInstance, _serviceOfferingMock);
}
Also used : ServiceOfferingVO(com.cloud.service.ServiceOfferingVO) 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