Alon Bar-Lev has uploaded a new change for review. Change subject: bll: remove usage of RandomUtils ......................................................................
bll: remove usage of RandomUtils RandomUtils is a wrapper to non secure random of java that is not used nor required within runtime. implementation of random utils is way too complex than required and provided as a wrapper instead of utility. had we had unit test utilities jar it should have moved there as tests use this class. for now, we remove the usage of this class at runtime, depreciating the class for future notice. Change-Id: Id20da6d8eb93ebbd237d20705440c5e583fc486e Signed-off-by: Alon Bar-Lev <[email protected]> --- M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/StorageHandlingCommandBase.java M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/utils/ClusterUtils.java M backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/RandomUtils.java 3 files changed, 16 insertions(+), 4 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/17/35217/1 diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/StorageHandlingCommandBase.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/StorageHandlingCommandBase.java index fa48f02..f975b6e 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/StorageHandlingCommandBase.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/StorageHandlingCommandBase.java @@ -1,5 +1,7 @@ package org.ovirt.engine.core.bll.storage; +import java.security.NoSuchAlgorithmException; +import java.security.SecureRandom; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -49,7 +51,6 @@ import org.ovirt.engine.core.dao.StorageDomainDynamicDAO; import org.ovirt.engine.core.dao.StoragePoolIsoMapDAO; import org.ovirt.engine.core.dao.UnregisteredOVFDataDAO; -import org.ovirt.engine.core.utils.RandomUtils; import org.ovirt.engine.core.utils.SyncronizeNumberOfAsyncOperations; import org.ovirt.engine.core.utils.linq.LinqUtils; import org.ovirt.engine.core.utils.linq.Predicate; @@ -146,7 +147,11 @@ List<VDS> hosts = getVdsDAO().getAllForStoragePoolAndStatus(getStoragePool().getId(), VDSStatus.Up); if (!hosts.isEmpty()) { - return RandomUtils.instance().pickRandom(hosts); + try { + return hosts.get(SecureRandom.getInstance("SHA1PRNG").nextInt() % hosts.size()); + } catch (NoSuchAlgorithmException e) { + throw new RuntimeException(e); + } } addCanDoActionMessage(VdcBllMessages.ACTION_TYPE_FAILED_NO_VDS_IN_POOL); return null; diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/utils/ClusterUtils.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/utils/ClusterUtils.java index d5dfe8c..25c522b 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/utils/ClusterUtils.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/utils/ClusterUtils.java @@ -1,5 +1,7 @@ package org.ovirt.engine.core.bll.utils; +import java.security.NoSuchAlgorithmException; +import java.security.SecureRandom; import java.util.List; import org.ovirt.engine.core.common.businessentities.VDS; @@ -11,7 +13,6 @@ import org.ovirt.engine.core.dal.dbbroker.DbFacade; import org.ovirt.engine.core.dao.VdsDAO; import org.ovirt.engine.core.dao.VdsGroupDAO; -import org.ovirt.engine.core.utils.RandomUtils; public class ClusterUtils { @@ -33,7 +34,11 @@ if (servers == null || servers.isEmpty()) { return null; } - return RandomUtils.instance().pickRandom(servers); + try { + return servers.get(SecureRandom.getInstance("SHA1PRNG").nextInt() % servers.size()); + } catch (NoSuchAlgorithmException e) { + throw new RuntimeException(e); + } } /** diff --git a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/RandomUtils.java b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/RandomUtils.java index 9d9742d..401ec17 100644 --- a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/RandomUtils.java +++ b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/RandomUtils.java @@ -19,9 +19,11 @@ * <LI><code>nextXXX(min, max)</code> for all types. * <LI><code>pickRandom()</code> - picks a random element from a given <code>List</code> or <code>Set</code>. * </UL> + * NOTICE: this class should only used for unit tests. * * @see java.util.Random */ +@Deprecated @SuppressWarnings("serial") public final class RandomUtils extends Random { -- To view, visit http://gerrit.ovirt.org/35217 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Id20da6d8eb93ebbd237d20705440c5e583fc486e Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Alon Bar-Lev <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
