Arik Hadas has uploaded a new change for review. Change subject: core: refactor SchedulingManager#schedule ......................................................................
core: refactor SchedulingManager#schedule SchedulingManager#schedule used have too many responsibilities - input validation, best host selection, update pending resources, and cluster locks handling. This patch extract the best host selection to separate method to remove one of the responsibilities mentioned above and simplify the code. Change-Id: I57b8e4751b4da329658f4b8e1ae2366b1147a137 Signed-off-by: Arik Hadas <aha...@redhat.com> --- M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/scheduling/SchedulingManager.java 1 file changed, 34 insertions(+), 21 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/72/24372/1 diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/scheduling/SchedulingManager.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/scheduling/SchedulingManager.java index aad2326..1aecb22 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/scheduling/SchedulingManager.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/scheduling/SchedulingManager.java @@ -263,28 +263,8 @@ return null; } - Guid bestHost = null; + Guid bestHost = selectBestHost(cluster, vm, destHostId, vdsList, policy, parameters); - // in case a default destination host was specified, and - // it passed filters return it - if (destHostId != null) { - for (VDS vds : vdsList) { - if (destHostId.equals(vds.getId())) { - bestHost = destHostId; - break; - } - } - } - if (bestHost == null && (policy.getFunctions() == null - || policy.getFunctions().isEmpty())) { - bestHost = vdsList.get(0).getId(); - } - if (bestHost == null && shouldWeighClusterHosts(cluster, vdsList)) { - bestHost = runFunctions(policy.getFunctions(), vdsList, vm, parameters); - } - if (bestHost == null && vdsList.size() > 0) { - bestHost = vdsList.get(0).getId(); - } if (bestHost != null) { getVdsDynamicDao().updatePartialVdsDynamicCalc( bestHost, @@ -294,6 +274,7 @@ 0, 0); } + return bestHost; } catch (InterruptedException e) { log.error("interrupted", e); @@ -308,6 +289,38 @@ } } + private Guid selectBestHost(VDSGroup cluster, + VM vm, + Guid destHostId, + List<VDS> vdsList, + ClusterPolicy policy, + Map<String, String> parameters) { + // in case a default destination host was specified, and + // it passed filters return it + if (destHostId != null) { + for (VDS vds : vdsList) { + if (destHostId.equals(vds.getId())) { + return destHostId; + } + } + } + + if (policy.getFunctions() == null + || policy.getFunctions().isEmpty()) { + return vdsList.get(0).getId(); + } + + if (shouldWeighClusterHosts(cluster, vdsList)) { + return runFunctions(policy.getFunctions(), vdsList, vm, parameters); + } + + if (!vdsList.isEmpty()) { + return vdsList.get(0).getId(); + } + + return null; + } + /** * Checks whether scheduler should schedule several requests in parallel: * Conditions: -- To view, visit http://gerrit.ovirt.org/24372 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I57b8e4751b4da329658f4b8e1ae2366b1147a137 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Arik Hadas <aha...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches