mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-02 11:52:28 +01:00
during resource calculation directly return ids for service offering,
templates Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
This commit is contained in:
parent
3f6b7b930a
commit
a3ea8603a9
@ -56,5 +56,5 @@ public interface ServiceOfferingDao extends GenericDao<ServiceOfferingVO, Long>
|
||||
|
||||
ServiceOfferingVO findServiceOfferingByComputeOnlyDiskOffering(long diskOfferingId);
|
||||
|
||||
List<ServiceOfferingVO> listByHostTag(String tag);
|
||||
List<Long> listIdsByHostTag(String tag);
|
||||
}
|
||||
|
||||
@ -35,6 +35,7 @@ import com.cloud.service.ServiceOfferingVO;
|
||||
import com.cloud.storage.Storage.ProvisioningType;
|
||||
import com.cloud.utils.db.DB;
|
||||
import com.cloud.utils.db.GenericDaoBase;
|
||||
import com.cloud.utils.db.GenericSearchBuilder;
|
||||
import com.cloud.utils.db.SearchBuilder;
|
||||
import com.cloud.utils.db.SearchCriteria;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
@ -295,8 +296,9 @@ public class ServiceOfferingDaoImpl extends GenericDaoBase<ServiceOfferingVO, Lo
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ServiceOfferingVO> listByHostTag(String tag) {
|
||||
SearchBuilder<ServiceOfferingVO> sb = createSearchBuilder();
|
||||
public List<Long> listIdsByHostTag(String tag) {
|
||||
GenericSearchBuilder<ServiceOfferingVO, Long> sb = createSearchBuilder(Long.class);
|
||||
sb.selectFields(sb.entity().getId());
|
||||
sb.and("tagNotNull", sb.entity().getHostTag(), SearchCriteria.Op.NNULL);
|
||||
sb.and().op("tagEq", sb.entity().getHostTag(), SearchCriteria.Op.EQ);
|
||||
sb.or("tagStartLike", sb.entity().getHostTag(), SearchCriteria.Op.LIKE);
|
||||
@ -304,11 +306,12 @@ public class ServiceOfferingDaoImpl extends GenericDaoBase<ServiceOfferingVO, Lo
|
||||
sb.or("tagEndLike", sb.entity().getHostTag(), SearchCriteria.Op.LIKE);
|
||||
sb.cp();
|
||||
sb.done();
|
||||
SearchCriteria<ServiceOfferingVO> sc = sb.create();
|
||||
SearchCriteria<Long> sc = sb.create();
|
||||
|
||||
sc.setParameters("tagEq", tag);
|
||||
sc.setParameters("tagStartLike", tag + ",%");
|
||||
sc.setParameters("tagMidLike", "%," + tag + ",%");
|
||||
sc.setParameters("tagEndLike", "%," + tag);
|
||||
return listBy(sc);
|
||||
return customSearch(sc, null);
|
||||
}
|
||||
}
|
||||
|
||||
@ -91,5 +91,5 @@ public interface VMTemplateDao extends GenericDao<VMTemplateVO, Long>, StateDao<
|
||||
|
||||
List<VMTemplateVO> findTemplatesLinkedToUserdata(long userdataId);
|
||||
|
||||
List<VMTemplateVO> listByTemplateTag(String tag);
|
||||
List<Long> listIdsByTemplateTag(String tag);
|
||||
}
|
||||
|
||||
@ -672,13 +672,14 @@ public class VMTemplateDaoImpl extends GenericDaoBase<VMTemplateVO, Long> implem
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<VMTemplateVO> listByTemplateTag(String tag) {
|
||||
SearchBuilder<VMTemplateVO> sb = createSearchBuilder();
|
||||
public List<Long> listIdsByTemplateTag(String tag) {
|
||||
GenericSearchBuilder<VMTemplateVO, Long> sb = createSearchBuilder(Long.class);
|
||||
sb.selectFields(sb.entity().getId());
|
||||
sb.and("tag", sb.entity().getTemplateTag(), SearchCriteria.Op.EQ);
|
||||
sb.done();
|
||||
SearchCriteria<VMTemplateVO> sc = sb.create();
|
||||
SearchCriteria<Long> sc = sb.create();
|
||||
sc.setParameters("tag", tag);
|
||||
return listIncludingRemovedBy(sc);
|
||||
return customSearchIncludingRemoved(sc, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -94,7 +94,6 @@ import com.cloud.projects.Project;
|
||||
import com.cloud.projects.ProjectAccount.Role;
|
||||
import com.cloud.projects.dao.ProjectAccountDao;
|
||||
import com.cloud.projects.dao.ProjectDao;
|
||||
import com.cloud.service.ServiceOfferingVO;
|
||||
import com.cloud.service.dao.ServiceOfferingDao;
|
||||
import com.cloud.storage.DataStoreRole;
|
||||
import com.cloud.storage.DiskOfferingVO;
|
||||
@ -1294,16 +1293,14 @@ public class ResourceLimitManagerImpl extends ManagerBase implements ResourceLim
|
||||
if (StringUtils.isEmpty(tag)) {
|
||||
return _userVmJoinDao.listByAccountServiceOfferingTemplateAndNotInState(accountId, states, null, null);
|
||||
}
|
||||
List<ServiceOfferingVO> offerings = serviceOfferingDao.listByHostTag(tag);
|
||||
List<VMTemplateVO> templates = _vmTemplateDao.listByTemplateTag(tag);
|
||||
List<Long> offerings = serviceOfferingDao.listIdsByHostTag(tag);
|
||||
List<Long> templates = _vmTemplateDao.listIdsByTemplateTag(tag);
|
||||
if (CollectionUtils.isEmpty(offerings) && CollectionUtils.isEmpty(templates)) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
return _userVmJoinDao.listByAccountServiceOfferingTemplateAndNotInState(accountId, states,
|
||||
offerings.stream().map(ServiceOfferingVO::getId).collect(Collectors.toList()),
|
||||
templates.stream().map(VMTemplateVO::getId).collect(Collectors.toList())
|
||||
);
|
||||
offerings, templates);
|
||||
}
|
||||
|
||||
protected List<UserVmJoinVO> getVmsWithAccount(long accountId) {
|
||||
@ -1321,7 +1318,7 @@ public class ResourceLimitManagerImpl extends ManagerBase implements ResourceLim
|
||||
vrIds);
|
||||
}
|
||||
|
||||
private long calculateReservedResources(List<UserVmJoinVO> vms,long accountId, ResourceType type, String tag) {
|
||||
private long calculateReservedResources(List<UserVmJoinVO> vms, long accountId, ResourceType type, String tag) {
|
||||
Set<Long> vmIds = vms.stream().map(UserVmJoinVO::getId).collect(Collectors.toSet());
|
||||
List<ReservationVO> reservations = reservationDao.getReservationsForAccount(accountId, type, tag);
|
||||
long reserved = 0;
|
||||
|
||||
@ -58,10 +58,8 @@ import com.cloud.offering.DiskOffering;
|
||||
import com.cloud.offering.ServiceOffering;
|
||||
import com.cloud.projects.ProjectVO;
|
||||
import com.cloud.projects.dao.ProjectDao;
|
||||
import com.cloud.service.ServiceOfferingVO;
|
||||
import com.cloud.service.dao.ServiceOfferingDao;
|
||||
import com.cloud.storage.DiskOfferingVO;
|
||||
import com.cloud.storage.VMTemplateVO;
|
||||
import com.cloud.storage.VolumeVO;
|
||||
import com.cloud.storage.dao.DiskOfferingDao;
|
||||
import com.cloud.storage.dao.VMTemplateDao;
|
||||
@ -614,8 +612,8 @@ public class ResourceLimitManagerImplTest {
|
||||
@Test
|
||||
public void testGetVmsWithAccountAndTagNegative() {
|
||||
String tag = hostTags.get(0);
|
||||
Mockito.when(serviceOfferingDao.listByHostTag(tag)).thenReturn(null);
|
||||
Mockito.when(vmTemplateDao.listByTemplateTag(tag)).thenReturn(null);
|
||||
Mockito.when(serviceOfferingDao.listIdsByHostTag(tag)).thenReturn(null);
|
||||
Mockito.when(vmTemplateDao.listIdsByTemplateTag(tag)).thenReturn(null);
|
||||
List<UserVmJoinVO> result = resourceLimitManager.getVmsWithAccountAndTag(1L, hostTags.get(0));
|
||||
Assert.assertTrue(CollectionUtils.isEmpty(result));
|
||||
}
|
||||
@ -624,12 +622,8 @@ public class ResourceLimitManagerImplTest {
|
||||
public void testGetVmsWithAccountAndTag() throws NoSuchFieldException, IllegalAccessException {
|
||||
overrideDefaultConfigValue(VirtualMachineManager.ResourceCountRunningVMsonly, "_defaultValue", "true");
|
||||
String tag = hostTags.get(0);
|
||||
ServiceOfferingVO serviceOfferingVO = Mockito.mock(ServiceOfferingVO.class);
|
||||
Mockito.when(serviceOfferingVO.getId()).thenReturn(1L);
|
||||
VMTemplateVO templateVO = Mockito.mock(VMTemplateVO.class);
|
||||
Mockito.when(templateVO.getId()).thenReturn(1L);
|
||||
Mockito.when(serviceOfferingDao.listByHostTag(tag)).thenReturn(List.of(serviceOfferingVO));
|
||||
Mockito.when(vmTemplateDao.listByTemplateTag(tag)).thenReturn(List.of(templateVO));
|
||||
Mockito.when(serviceOfferingDao.listIdsByHostTag(tag)).thenReturn(List.of(1L));
|
||||
Mockito.when(vmTemplateDao.listIdsByTemplateTag(tag)).thenReturn(List.of(1L));
|
||||
List<UserVmJoinVO> vmList = List.of(Mockito.mock(UserVmJoinVO.class));
|
||||
Mockito.when(userVmJoinDao.listByAccountServiceOfferingTemplateAndNotInState(Mockito.anyLong(), Mockito.anyList(), Mockito.anyList(), Mockito.anyList())).thenReturn(vmList);
|
||||
List<UserVmJoinVO> result = resourceLimitManager.getVmsWithAccountAndTag(1L, tag);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user