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);
}
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;
}
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;
}
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());
}
}
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);
}
Aggregations