| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -34,9 +34,9 @@ public class RestoreBackupCommand extends Command { | |||
| 34 | 34 | private List<String> backupVolumesUUIDs; | |
| 35 | 35 | private List<PrimaryDataStoreTO> restoreVolumePools; | |
| 36 | 36 | private List<String> restoreVolumePaths; | |
| 37 | + private List<String> backupFiles; | ||
| 37 | 38 | private String diskType; | |
| 38 | 39 | private Boolean vmExists; | |
| 39 | - private String restoreVolumeUUID; | ||
| 40 | 40 | private VirtualMachine.State vmState; | |
| 41 | 41 | private Integer mountTimeout; | |
| 42 | 42 | ||
@@ -92,6 +92,14 @@ public void setRestoreVolumePaths(List<String> restoreVolumePaths) { | |||
| 92 | 92 | this.restoreVolumePaths = restoreVolumePaths; | |
| 93 | 93 | } | |
| 94 | 94 | ||
| 95 | + public List<String> getBackupFiles() { | ||
| 96 | + return backupFiles; | ||
| 97 | + } | ||
| 98 | + | ||
| 99 | + public void setBackupFiles(List<String> backupFiles) { | ||
| 100 | + this.backupFiles = backupFiles; | ||
| 101 | + } | ||
| 102 | + | ||
| 95 | 103 | public Boolean isVmExists() { | |
| 96 | 104 | return vmExists; | |
| 97 | 105 | } | |
@@ -116,14 +124,6 @@ public void setMountOptions(String mountOptions) { | |||
| 116 | 124 | this.mountOptions = mountOptions; | |
| 117 | 125 | } | |
| 118 | 126 | ||
| 119 | - public String getRestoreVolumeUUID() { | ||
| 120 | - return restoreVolumeUUID; | ||
| 121 | - } | ||
| 122 | - | ||
| 123 | - public void setRestoreVolumeUUID(String restoreVolumeUUID) { | ||
| 124 | - this.restoreVolumeUUID = restoreVolumeUUID; | ||
| 125 | - } | ||
| 126 | - | ||
| 127 | 127 | public VirtualMachine.State getVmState() { | |
| 128 | 128 | return vmState; | |
| 129 | 129 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -167,6 +167,8 @@ public interface ResourceManager extends ResourceService, Configurable { | |||
| 167 | 167 | ||
| 168 | 168 | public HostVO findHostByGuid(String guid); | |
| 169 | 169 | ||
| 170 | + HostVO findHostByGuidPrefix(String guid); | ||
| 171 | + | ||
| 170 | 172 | public HostVO findHostByName(String name); | |
| 171 | 173 | ||
| 172 | 174 | HostStats getHostStatistics(Host host); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -171,7 +171,7 @@ public Scope getScope() { | |||
| 171 | 171 | @Override | |
| 172 | 172 | public String getConfigValue(long id, String key) { | |
| 173 | 173 | ClusterDetailsVO vo = findDetail(id, key); | |
| 174 | - return vo == null ? null : vo.getValue(); | ||
| 174 | + return vo == null ? null : getActualValue(vo); | ||
| 175 | 175 | } | |
| 176 | 176 | ||
| 177 | 177 | @Override | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -46,7 +46,7 @@ public Scope getScope() { | |||
| 46 | 46 | @Override | |
| 47 | 47 | public String getConfigValue(long id, String key) { | |
| 48 | 48 | ResourceDetail vo = findDetail(id, key); | |
| 49 | - return vo == null ? null : vo.getValue(); | ||
| 49 | + return vo == null ? null : getActualValue(vo); | ||
| 50 | 50 | } | |
| 51 | 51 | ||
| 52 | 52 | @Override | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1412,7 +1412,7 @@ public HostVO findAnyStateHypervisorHostInCluster(long clusterId) { | |||
| 1412 | 1412 | SearchCriteria<HostVO> sc = TypeStatusStateSearch.create(); | |
| 1413 | 1413 | sc.setParameters("type", Host.Type.Routing); | |
| 1414 | 1414 | sc.setParameters("cluster", clusterId); | |
| 1415 | - List<HostVO> list = listBy(sc, new Filter(1)); | ||
| 1415 | + List<HostVO> list = listBy(sc, new Filter(1, true)); | ||
| 1416 | 1416 | return list.isEmpty() ? null : list.get(0); | |
| 1417 | 1417 | } | |
| 1418 | 1418 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -202,7 +202,7 @@ public ImageStoreVO findOneByZoneAndProtocol(long dataCenterId, String protocol) | |||
| 202 | 202 | sc.setParameters("dataCenterId", dataCenterId); | |
| 203 | 203 | sc.setParameters("protocol", protocol); | |
| 204 | 204 | sc.setParameters("role", DataStoreRole.Image); | |
| 205 | - Filter filter = new Filter(1); | ||
| 205 | + Filter filter = new Filter(1, true); | ||
| 206 | 206 | List<ImageStoreVO> results = listBy(sc, filter); | |
| 207 | 207 | return results.size() == 0 ? null : results.get(0); | |
| 208 | 208 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -57,7 +57,18 @@ public Filter(Class<?> clazz, String field, boolean ascending) { | |||
| 57 | 57 | } | |
| 58 | 58 | ||
| 59 | 59 | public Filter(long limit) { | |
| 60 | - _orderBy = " ORDER BY RAND()"; | ||
| 60 | + this(limit, false); | ||
| 61 | + } | ||
| 62 | + | ||
| 63 | + /** | ||
| 64 | + * Constructor for creating a filter with random ordering | ||
| 65 | + * @param limit the maximum number of results to return | ||
| 66 | + * @param randomize if true, orders results randomly | ||
| 67 | + */ | ||
| 68 | + public Filter(long limit, boolean randomize) { | ||
| 69 | + if (randomize) { | ||
| 70 | + _orderBy = " ORDER BY RAND()" ; | ||
| 71 | + } | ||
| 61 | 72 | _limit = limit; | |
| 62 | 73 | } | |
| 63 | 74 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -347,7 +347,7 @@ public List<T> lockRows(final SearchCriteria<T> sc, final Filter filter, final b | |||
| 347 | 347 | @Override | |
| 348 | 348 | @DB() | |
| 349 | 349 | public T lockOneRandomRow(final SearchCriteria<T> sc, final boolean exclusive) { | |
| 350 | - final Filter filter = new Filter(1); | ||
| 350 | + final Filter filter = new Filter(1, true); | ||
| 351 | 351 | final List<T> beans = search(sc, filter, exclusive, true); | |
| 352 | 352 | return beans.isEmpty() ? null : beans.get(0); | |
| 353 | 353 | } | |
@@ -927,7 +927,7 @@ public Class<T> getEntityBeanType() { | |||
| 927 | 927 | ||
| 928 | 928 | @DB() | |
| 929 | 929 | protected T findOneIncludingRemovedBy(final SearchCriteria<T> sc) { | |
| 930 | - Filter filter = new Filter(1); | ||
| 930 | + Filter filter = new Filter(1, true); | ||
| 931 | 931 | List<T> results = searchIncludingRemoved(sc, filter, null, false); | |
| 932 | 932 | assert results.size() <= 1 : "Didn't the limiting worked?"; | |
| 933 | 933 | return results.size() == 0 ? null : results.get(0); | |
@@ -1335,7 +1335,7 @@ public int batchExpunge(final SearchCriteria<T> sc, final Long batchSize) { | |||
| 1335 | 1335 | Filter filter = null; | |
| 1336 | 1336 | final long batchSizeFinal = ObjectUtils.defaultIfNull(batchSize, 0L); | |
| 1337 | 1337 | if (batchSizeFinal > 0) { | |
| 1338 | - filter = new Filter(null, batchSizeFinal); | ||
| 1338 | + filter = new Filter(batchSizeFinal); | ||
| 1339 | 1339 | } | |
| 1340 | 1340 | int expunged = 0; | |
| 1341 | 1341 | int currentExpunged = 0; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -41,4 +41,62 @@ public void testAddOrderBy() { | |||
| 41 | 41 | Assert.assertTrue(filter.getOrderBy().split(",").length == 3); | |
| 42 | 42 | Assert.assertTrue(filter.getOrderBy().split(",")[2].trim().toLowerCase().equals("test.fld_int asc")); | |
| 43 | 43 | } | |
| 44 | + | ||
| 45 | + | ||
| 46 | + @Test | ||
| 47 | + public void testFilterWithLimitOnly() { | ||
| 48 | + Filter filter = new Filter(5); | ||
| 49 | + | ||
| 50 | + Assert.assertEquals(Long.valueOf(5), filter.getLimit()); | ||
| 51 | + Assert.assertNull(filter.getOrderBy()); | ||
| 52 | + Assert.assertNull(filter.getOffset()); | ||
| 53 | + } | ||
| 54 | + | ||
| 55 | + @Test | ||
| 56 | + public void testFilterWithLimitAndRandomizeFalse() { | ||
| 57 | + Filter filter = new Filter(10, false); | ||
| 58 | + | ||
| 59 | + Assert.assertEquals(Long.valueOf(10), filter.getLimit()); | ||
| 60 | + Assert.assertNull(filter.getOrderBy()); | ||
| 61 | + Assert.assertNull(filter.getOffset()); | ||
| 62 | + } | ||
| 63 | + | ||
| 64 | + @Test | ||
| 65 | + public void testFilterWithLimitAndRandomizeTrue() { | ||
| 66 | + Filter filter = new Filter(3, true); | ||
| 67 | + | ||
| 68 | + Assert.assertNull(filter.getLimit()); | ||
| 69 | + Assert.assertNotNull(filter.getOrderBy()); | ||
| 70 | + Assert.assertTrue(filter.getOrderBy().contains("ORDER BY RAND()")); | ||
| 71 | + Assert.assertTrue(filter.getOrderBy().contains("LIMIT 3")); | ||
| 72 | + Assert.assertEquals(" ORDER BY RAND() LIMIT 3", filter.getOrderBy()); | ||
| 73 | + } | ||
| 74 | + | ||
| 75 | + @Test | ||
| 76 | + public void testFilterRandomizeWithDifferentLimits() { | ||
| 77 | + Filter filter1 = new Filter(1, true); | ||
| 78 | + Filter filter10 = new Filter(10, true); | ||
| 79 | + Filter filter100 = new Filter(100, true); | ||
| 80 | + | ||
| 81 | + Assert.assertEquals(" ORDER BY RAND() LIMIT 1", filter1.getOrderBy()); | ||
| 82 | + Assert.assertEquals(" ORDER BY RAND() LIMIT 10", filter10.getOrderBy()); | ||
| 83 | + Assert.assertEquals(" ORDER BY RAND() LIMIT 100", filter100.getOrderBy()); | ||
| 84 | + } | ||
| 85 | + | ||
| 86 | + @Test | ||
| 87 | + public void testFilterConstructorBackwardsCompatibility() { | ||
| 88 | + // Test that Filter(long) behaves differently now (no ORDER BY RAND()) | ||
| 89 | + // compared to Filter(long, true) which preserves old behavior | ||
| 90 | + Filter simpleLimitFilter = new Filter(1); | ||
| 91 | + Filter randomFilter = new Filter(1, true); | ||
| 92 | + | ||
| 93 | + // Simple limit filter should just set limit | ||
| 94 | + Assert.assertEquals(Long.valueOf(1), simpleLimitFilter.getLimit()); | ||
| 95 | + Assert.assertNull(simpleLimitFilter.getOrderBy()); | ||
| 96 | + | ||
| 97 | + // Random filter should set orderBy with RAND() | ||
| 98 | + Assert.assertNull(randomFilter.getLimit()); | ||
| 99 | + Assert.assertNotNull(randomFilter.getOrderBy()); | ||
| 100 | + Assert.assertTrue(randomFilter.getOrderBy().contains("RAND()")); | ||
| 101 | + } | ||
| 44 | 102 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -20,6 +20,7 @@ | |||
| 20 | 20 | import java.sql.SQLException; | |
| 21 | 21 | import java.util.ArrayList; | |
| 22 | 22 | import java.util.Collection; | |
| 23 | + import java.util.List; | ||
| 23 | 24 | ||
| 24 | 25 | import org.junit.Assert; | |
| 25 | 26 | import org.junit.Before; | |
@@ -263,4 +264,71 @@ public void multiJoinSameTableTest() { | |||
| 263 | 264 | " INNER JOIN tableA tableA2Alias ON tableC.column3=tableA2Alias.column2 " + | |
| 264 | 265 | " INNER JOIN tableA tableA3Alias ON tableD.column4=tableA3Alias.column3 AND tableD.column5=? ", joinString.toString()); | |
| 265 | 266 | } | |
| 267 | + | ||
| 268 | + | ||
| 269 | + @Test | ||
| 270 | + public void testLockOneRandomRowUsesRandomFilter() { | ||
| 271 | + // Create a mock DAO to test lockOneRandomRow behavior | ||
| 272 | + GenericDaoBase<DbTestVO, Long> testDao = Mockito.mock(GenericDaoBase.class); | ||
| 273 | + | ||
| 274 | + // Capture the filter passed to the search method | ||
| 275 | + final Filter[] capturedFilter = new Filter[1]; | ||
| 276 | + | ||
| 277 | + Mockito.when(testDao.lockOneRandomRow(Mockito.any(SearchCriteria.class), Mockito.anyBoolean())) | ||
| 278 | + .thenCallRealMethod(); | ||
| 279 | + | ||
| 280 | + Mockito.when(testDao.search(Mockito.any(SearchCriteria.class), Mockito.any(Filter.class), | ||
| 281 | + Mockito.anyBoolean(), Mockito.anyBoolean())) | ||
| 282 | + .thenAnswer(invocation -> { | ||
| 283 | + capturedFilter[0] = invocation.getArgument(1); | ||
| 284 | + return new ArrayList<DbTestVO>(); | ||
| 285 | + }); | ||
| 286 | + | ||
| 287 | + SearchCriteria<DbTestVO> sc = Mockito.mock(SearchCriteria.class); | ||
| 288 | + testDao.lockOneRandomRow(sc, true); | ||
| 289 | + | ||
| 290 | + // Verify that the filter uses random ordering | ||
| 291 | + Assert.assertNotNull(capturedFilter[0]); | ||
| 292 | + Assert.assertNotNull(capturedFilter[0].getOrderBy()); | ||
| 293 | + Assert.assertTrue(capturedFilter[0].getOrderBy().contains("ORDER BY RAND()")); | ||
| 294 | + Assert.assertTrue(capturedFilter[0].getOrderBy().contains("LIMIT 1")); | ||
| 295 | + } | ||
| 296 | + | ||
| 297 | + @Test | ||
| 298 | + public void testLockOneRandomRowReturnsNullOnEmptyResult() { | ||
| 299 | + GenericDaoBase<DbTestVO, Long> testDao = Mockito.mock(GenericDaoBase.class); | ||
| 300 | + | ||
| 301 | + Mockito.when(testDao.lockOneRandomRow(Mockito.any(SearchCriteria.class), Mockito.anyBoolean())) | ||
| 302 | + .thenCallRealMethod(); | ||
| 303 | + | ||
| 304 | + Mockito.when(testDao.search(Mockito.any(SearchCriteria.class), Mockito.any(Filter.class), | ||
| 305 | + Mockito.anyBoolean(), Mockito.anyBoolean())) | ||
| 306 | + .thenReturn(new ArrayList<DbTestVO>()); | ||
| 307 | + | ||
| 308 | + SearchCriteria<DbTestVO> sc = Mockito.mock(SearchCriteria.class); | ||
| 309 | + DbTestVO result = testDao.lockOneRandomRow(sc, true); | ||
| 310 | + | ||
| 311 | + Assert.assertNull(result); | ||
| 312 | + } | ||
| 313 | + | ||
| 314 | + @Test | ||
| 315 | + public void testLockOneRandomRowReturnsFirstElement() { | ||
| 316 | + GenericDaoBase<DbTestVO, Long> testDao = Mockito.mock(GenericDaoBase.class); | ||
| 317 | + DbTestVO expectedResult = new DbTestVO(); | ||
| 318 | + List<DbTestVO> resultList = new ArrayList<>(); | ||
| 319 | + resultList.add(expectedResult); | ||
| 320 | + | ||
| 321 | + Mockito.when(testDao.lockOneRandomRow(Mockito.any(SearchCriteria.class), Mockito.anyBoolean())) | ||
| 322 | + .thenCallRealMethod(); | ||
| 323 | + | ||
| 324 | + Mockito.when(testDao.search(Mockito.any(SearchCriteria.class), Mockito.any(Filter.class), | ||
| 325 | + Mockito.anyBoolean(), Mockito.anyBoolean())) | ||
| 326 | + .thenReturn(resultList); | ||
| 327 | + | ||
| 328 | + SearchCriteria<DbTestVO> sc = Mockito.mock(SearchCriteria.class); | ||
| 329 | + DbTestVO result = testDao.lockOneRandomRow(sc, true); | ||
| 330 | + | ||
| 331 | + Assert.assertNotNull(result); | ||
| 332 | + Assert.assertEquals(expectedResult, result); | ||
| 333 | + } | ||
| 266 | 334 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments