From e99cc740e64a2e230fda87ca5d04b059d3c6bed3 Mon Sep 17 00:00:00 2001 From: edison Date: Wed, 1 Dec 2010 13:17:24 -0800 Subject: [PATCH] add more checks in alloctor --- .../src/com/cloud/deploy/FirstFitPlanner.java | 25 +++++++++++++------ server/src/com/cloud/vm/VMStateListener.java | 3 ++- .../com/cloud/utils/fsm/StateMachine2.java | 22 +++++++++++++--- 3 files changed, 38 insertions(+), 12 deletions(-) diff --git a/server/src/com/cloud/deploy/FirstFitPlanner.java b/server/src/com/cloud/deploy/FirstFitPlanner.java index e5bd1621290..85c4dd9f4ea 100644 --- a/server/src/com/cloud/deploy/FirstFitPlanner.java +++ b/server/src/com/cloud/deploy/FirstFitPlanner.java @@ -56,21 +56,31 @@ public class FirstFitPlanner extends PlannerBase implements DeploymentPlanner { /*Go through all the pods/clusters under zone*/ List pods = _podDao.listByDataCenterId(plan.getDataCenterId()); - Collections.shuffle(pods); + //Collections.shuffle(pods); for (HostPodVO hostPod : pods) { List clusters = _clusterDao.listByPodId(hostPod.getId()); - Collections.shuffle(clusters); + //Collections.shuffle(clusters); for (ClusterVO clusterVO : clusters) { + + if (clusterVO.getHypervisorType() != vmProfile.getHypervisorType()) { + continue; + } + List hosts = _hostDao.listByCluster(clusterVO.getId()); - Collections.shuffle(hosts); + //Collections.shuffle(hosts); + for (HostVO hostVO : hosts) { if (hostVO.getStatus() != Status.Up) { continue; } + if (avoid.shouldAvoid(hostVO)) { + continue; + } + boolean canDeployToHost = deployToHost(hostVO.getId(), cpu_requested, ram_requested, false); if (canDeployToHost) { Pod pod = _podDao.findById(hostPod.getId()); @@ -126,11 +136,12 @@ public class FirstFitPlanner extends PlannerBase implements DeploymentPlanner { _capacityDao.update(capacityMem.getId(), capacityMem); } - return success; - } finally { txn.commit(); - } - + return success; + } catch (Exception e) { + txn.rollback(); + return false; + } } @Override public boolean check(VirtualMachineProfile vm, DeploymentPlan plan, diff --git a/server/src/com/cloud/vm/VMStateListener.java b/server/src/com/cloud/vm/VMStateListener.java index 66aa718362f..3fdefd61b99 100644 --- a/server/src/com/cloud/vm/VMStateListener.java +++ b/server/src/com/cloud/vm/VMStateListener.java @@ -114,8 +114,9 @@ public class VMStateListener implements StateListener> { return entry.prevStates.get(e); } + @DB public boolean transitTO(V vo, E e) { S currentState = vo.getState(); S nextState = getNextState(currentState, e); @@ -102,13 +106,23 @@ public class StateMachine2> { if (nextState == null) { transitionStatus = false; } + + Transaction txn = Transaction.currentTxn(); + txn.start(); - transitionStatus = _instanceDao.updateState(currentState, e, nextState, vo); + try { - for (StateListener listener : _listeners) { - listener.processStateTransitionEvent(currentState, e, nextState, vo, transitionStatus); + transitionStatus = _instanceDao.updateState(currentState, e, nextState, vo); + + for (StateListener listener : _listeners) { + listener.processStateTransitionEvent(currentState, e, nextState, vo, transitionStatus); + } + txn.commit(); + + } catch (Exception ex) { + txn.rollback(); } - + return transitionStatus; }