Skip to content

Commit e99cc74

Browse files
committed
add more checks in alloctor
1 parent f3c7012 commit e99cc74

3 files changed

Lines changed: 38 additions & 12 deletions

File tree

server/src/com/cloud/deploy/FirstFitPlanner.java

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,21 +56,31 @@ public DeployDestination plan(VirtualMachineProfile vmProfile,
5656

5757
/*Go through all the pods/clusters under zone*/
5858
List<HostPodVO> pods = _podDao.listByDataCenterId(plan.getDataCenterId());
59-
Collections.shuffle(pods);
59+
//Collections.shuffle(pods);
6060

6161
for (HostPodVO hostPod : pods) {
6262
List<ClusterVO> clusters = _clusterDao.listByPodId(hostPod.getId());
63-
Collections.shuffle(clusters);
63+
//Collections.shuffle(clusters);
6464

6565
for (ClusterVO clusterVO : clusters) {
66+
67+
if (clusterVO.getHypervisorType() != vmProfile.getHypervisorType()) {
68+
continue;
69+
}
70+
6671
List<HostVO> hosts = _hostDao.listByCluster(clusterVO.getId());
67-
Collections.shuffle(hosts);
72+
//Collections.shuffle(hosts);
73+
6874

6975
for (HostVO hostVO : hosts) {
7076
if (hostVO.getStatus() != Status.Up) {
7177
continue;
7278
}
7379

80+
if (avoid.shouldAvoid(hostVO)) {
81+
continue;
82+
}
83+
7484
boolean canDeployToHost = deployToHost(hostVO.getId(), cpu_requested, ram_requested, false);
7585
if (canDeployToHost) {
7686
Pod pod = _podDao.findById(hostPod.getId());
@@ -126,11 +136,12 @@ private boolean deployToHost(Long hostId, Integer cpu, long ram, boolean fromLas
126136
_capacityDao.update(capacityMem.getId(), capacityMem);
127137
}
128138

129-
return success;
130-
} finally {
131139
txn.commit();
132-
}
133-
140+
return success;
141+
} catch (Exception e) {
142+
txn.rollback();
143+
return false;
144+
}
134145
}
135146
@Override
136147
public boolean check(VirtualMachineProfile vm, DeploymentPlan plan,

server/src/com/cloud/vm/VMStateListener.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,9 @@ private void releaseResource(VMInstanceVO vm, boolean moveFromReserved, boolean
114114

115115
_capacityDao.update(capacityCpu.getId(), capacityCpu);
116116
_capacityDao.update(capacityMemory.getId(), capacityMemory);
117-
} finally {
118117
txn.commit();
118+
} catch (Exception e) {
119+
txn.rollback();
119120
}
120121
}
121122
}

utils/src/com/cloud/utils/fsm/StateMachine2.java

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
import java.util.Map;
2525
import java.util.Set;
2626

27+
import com.cloud.utils.db.DB;
28+
import com.cloud.utils.db.Transaction;
29+
2730
/**
2831
* StateMachine is a partial implementation of a finite state machine.
2932
* Specifically, it implements the Moore machine.
@@ -94,6 +97,7 @@ public List<S> getFromStates(S s, E e) {
9497
return entry.prevStates.get(e);
9598
}
9699

100+
@DB
97101
public boolean transitTO(V vo, E e) {
98102
S currentState = vo.getState();
99103
S nextState = getNextState(currentState, e);
@@ -102,13 +106,23 @@ public boolean transitTO(V vo, E e) {
102106
if (nextState == null) {
103107
transitionStatus = false;
104108
}
109+
110+
Transaction txn = Transaction.currentTxn();
111+
txn.start();
105112

106-
transitionStatus = _instanceDao.updateState(currentState, e, nextState, vo);
113+
try {
107114

108-
for (StateListener<S,E, V> listener : _listeners) {
109-
listener.processStateTransitionEvent(currentState, e, nextState, vo, transitionStatus);
110-
}
115+
transitionStatus = _instanceDao.updateState(currentState, e, nextState, vo);
116+
117+
for (StateListener<S,E, V> listener : _listeners) {
118+
listener.processStateTransitionEvent(currentState, e, nextState, vo, transitionStatus);
119+
}
120+
txn.commit();
111121

122+
} catch (Exception ex) {
123+
txn.rollback();
124+
}
125+
112126
return transitionStatus;
113127
}
114128

0 commit comments

Comments
 (0)