add more checks in alloctor

This commit is contained in:
edison 2010-12-01 13:17:24 -08:00
parent f3c7012508
commit e99cc740e6
3 changed files with 38 additions and 12 deletions

View File

@ -56,21 +56,31 @@ public class FirstFitPlanner extends PlannerBase implements DeploymentPlanner {
/*Go through all the pods/clusters under zone*/
List<HostPodVO> pods = _podDao.listByDataCenterId(plan.getDataCenterId());
Collections.shuffle(pods);
//Collections.shuffle(pods);
for (HostPodVO hostPod : pods) {
List<ClusterVO> clusters = _clusterDao.listByPodId(hostPod.getId());
Collections.shuffle(clusters);
//Collections.shuffle(clusters);
for (ClusterVO clusterVO : clusters) {
if (clusterVO.getHypervisorType() != vmProfile.getHypervisorType()) {
continue;
}
List<HostVO> 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,

View File

@ -114,8 +114,9 @@ public class VMStateListener implements StateListener<State, VirtualMachine.Even
_capacityDao.update(capacityCpu.getId(), capacityCpu);
_capacityDao.update(capacityMemory.getId(), capacityMemory);
} finally {
txn.commit();
} catch (Exception e) {
txn.rollback();
}
}
}

View File

@ -24,6 +24,9 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import com.cloud.utils.db.DB;
import com.cloud.utils.db.Transaction;
/**
* StateMachine is a partial implementation of a finite state machine.
* Specifically, it implements the Moore machine.
@ -94,6 +97,7 @@ public class StateMachine2<S, E, V extends StateObject<S>> {
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<S, E, V extends StateObject<S>> {
if (nextState == null) {
transitionStatus = false;
}
Transaction txn = Transaction.currentTxn();
txn.start();
transitionStatus = _instanceDao.updateState(currentState, e, nextState, vo);
try {
for (StateListener<S,E, V> listener : _listeners) {
listener.processStateTransitionEvent(currentState, e, nextState, vo, transitionStatus);
transitionStatus = _instanceDao.updateState(currentState, e, nextState, vo);
for (StateListener<S,E, V> listener : _listeners) {
listener.processStateTransitionEvent(currentState, e, nextState, vo, transitionStatus);
}
txn.commit();
} catch (Exception ex) {
txn.rollback();
}
return transitionStatus;
}