merge changes

This commit is contained in:
Alex Huang 2011-01-14 10:47:20 -08:00
parent 19edfdfcdb
commit d43717eef8
10 changed files with 118 additions and 124 deletions

View File

@ -32,7 +32,6 @@ import com.cloud.utils.fsm.StateMachine;
*/ */
public interface VirtualMachine extends RunningOn, ControlledEntity { public interface VirtualMachine extends RunningOn, ControlledEntity {
public enum State implements FiniteState<State, Event> { public enum State implements FiniteState<State, Event> {
Creating(true, "VM is being created"),
Starting(true, "VM is being started. At this state, you should find host id filled which means it's being started on that host."), Starting(true, "VM is being started. At this state, you should find host id filled which means it's being started on that host."),
Running(false, "VM is running. host id has the host that it is running on."), Running(false, "VM is running. host id has the host that it is running on."),
Stopping(true, "VM is being stopped. host id has the host that it is being stopped on."), Stopping(true, "VM is being stopped. host id has the host that it is being stopped on."),
@ -85,9 +84,9 @@ public interface VirtualMachine extends RunningOn, ControlledEntity {
protected static final StateMachine<State, VirtualMachine.Event> s_fsm = new StateMachine<State, VirtualMachine.Event>(); protected static final StateMachine<State, VirtualMachine.Event> s_fsm = new StateMachine<State, VirtualMachine.Event>();
static { static {
s_fsm.addTransition(null, VirtualMachine.Event.CreateRequested, State.Creating); // s_fsm.addTransition(null, VirtualMachine.Event.CreateRequested, State.Creating);
s_fsm.addTransition(State.Creating, VirtualMachine.Event.OperationSucceeded, State.Stopped); // s_fsm.addTransition(State.Creating, VirtualMachine.Event.OperationSucceeded, State.Stopped);
s_fsm.addTransition(State.Creating, VirtualMachine.Event.OperationFailed, State.Error); // s_fsm.addTransition(State.Creating, VirtualMachine.Event.OperationFailed, State.Error);
s_fsm.addTransition(State.Stopped, VirtualMachine.Event.StartRequested, State.Starting); s_fsm.addTransition(State.Stopped, VirtualMachine.Event.StartRequested, State.Starting);
s_fsm.addTransition(State.Stopped, VirtualMachine.Event.DestroyRequested, State.Destroyed); s_fsm.addTransition(State.Stopped, VirtualMachine.Event.DestroyRequested, State.Destroyed);
s_fsm.addTransition(State.Error, VirtualMachine.Event.DestroyRequested, State.Destroyed); s_fsm.addTransition(State.Error, VirtualMachine.Event.DestroyRequested, State.Destroyed);
@ -102,7 +101,7 @@ public interface VirtualMachine extends RunningOn, ControlledEntity {
s_fsm.addTransition(State.Starting, VirtualMachine.Event.AgentReportShutdowned, State.Stopped); s_fsm.addTransition(State.Starting, VirtualMachine.Event.AgentReportShutdowned, State.Stopped);
s_fsm.addTransition(State.Destroyed, VirtualMachine.Event.RecoveryRequested, State.Stopped); s_fsm.addTransition(State.Destroyed, VirtualMachine.Event.RecoveryRequested, State.Stopped);
s_fsm.addTransition(State.Destroyed, VirtualMachine.Event.ExpungeOperation, State.Expunging); s_fsm.addTransition(State.Destroyed, VirtualMachine.Event.ExpungeOperation, State.Expunging);
s_fsm.addTransition(State.Creating, VirtualMachine.Event.MigrationRequested, State.Destroyed); // s_fsm.addTransition(State.Creating, VirtualMachine.Event.MigrationRequested, State.Destroyed);
s_fsm.addTransition(State.Running, VirtualMachine.Event.MigrationRequested, State.Migrating); s_fsm.addTransition(State.Running, VirtualMachine.Event.MigrationRequested, State.Migrating);
s_fsm.addTransition(State.Running, VirtualMachine.Event.AgentReportRunning, State.Running); s_fsm.addTransition(State.Running, VirtualMachine.Event.AgentReportRunning, State.Running);
s_fsm.addTransition(State.Running, VirtualMachine.Event.AgentReportStopped, State.Stopped); s_fsm.addTransition(State.Running, VirtualMachine.Event.AgentReportStopped, State.Stopped);

View File

@ -156,6 +156,7 @@
<lib dir="${jar.dir}"> <lib dir="${jar.dir}">
<include name="cloud-*.jar" /> <include name="cloud-*.jar" />
<include name="vmware-*.jar" /> <include name="vmware-*.jar" />
<exclude name="cloud-servlet-api.jar"/>
</lib> </lib>
<zipfileset dir="${scripts.target.dir}" prefix="WEB-INF/lib/scripts" filemode="555"> <zipfileset dir="${scripts.target.dir}" prefix="WEB-INF/lib/scripts" filemode="555">
<include name="**/*" /> <include name="**/*" />

View File

@ -166,7 +166,7 @@ public class VMInstanceVO implements VirtualMachine, FiniteStateObject<State, Vi
this.haEnabled = haEnabled; this.haEnabled = haEnabled;
this.mirroredVols = false; this.mirroredVols = false;
this.vncPassword = Long.toHexString(new Random().nextLong()); this.vncPassword = Long.toHexString(new Random().nextLong());
this.state = State.Creating; this.state = State.Stopped;
this.accountId = accountId; this.accountId = accountId;
this.domainId = domainId; this.domainId = domainId;
this.serviceOfferingId = serviceOfferingId; this.serviceOfferingId = serviceOfferingId;

View File

@ -481,7 +481,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx
private static boolean isInAssignableState(ConsoleProxyVO proxy) { private static boolean isInAssignableState(ConsoleProxyVO proxy) {
// console proxies that are in states of being able to serve user VM // console proxies that are in states of being able to serve user VM
State state = proxy.getState(); State state = proxy.getState();
if (state == State.Running || state == State.Starting || state == State.Creating || state == State.Migrating) { if (state == State.Running || state == State.Starting || state == State.Migrating) {
return true; return true;
} }
@ -599,7 +599,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx
} }
public ConsoleProxyVO assignProxyFromStoppedPool(long dataCenterId) { public ConsoleProxyVO assignProxyFromStoppedPool(long dataCenterId) {
List<ConsoleProxyVO> l = _consoleProxyDao.getProxyListInStates(dataCenterId, State.Creating, State.Starting, State.Stopped, State.Migrating); List<ConsoleProxyVO> l = _consoleProxyDao.getProxyListInStates(dataCenterId, State.Starting, State.Stopped, State.Migrating);
if (l != null && l.size() > 0) { if (l != null && l.size() > 0) {
return l.get(0); return l.get(0);
} }
@ -1047,56 +1047,56 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx
} }
} }
private void checkPendingProxyVMs() { // private void checkPendingProxyVMs() {
// drive state to change away from transient states // // drive state to change away from transient states
List<ConsoleProxyVO> l = _consoleProxyDao.getProxyListInStates(State.Creating); // List<ConsoleProxyVO> l = _consoleProxyDao.getProxyListInStates(State.Creating);
if (l != null && l.size() > 0) { // if (l != null && l.size() > 0) {
for (ConsoleProxyVO proxy : l) { // for (ConsoleProxyVO proxy : l) {
if (proxy.getLastUpdateTime() == null // if (proxy.getLastUpdateTime() == null
|| (proxy.getLastUpdateTime() != null && System.currentTimeMillis() - proxy.getLastUpdateTime().getTime() > 60000)) { // || (proxy.getLastUpdateTime() != null && System.currentTimeMillis() - proxy.getLastUpdateTime().getTime() > 60000)) {
try { // try {
ConsoleProxyVO readyProxy = null; // ConsoleProxyVO readyProxy = null;
if (_allocProxyLock.lock(ACQUIRE_GLOBAL_LOCK_TIMEOUT_FOR_SYNC)) { // if (_allocProxyLock.lock(ACQUIRE_GLOBAL_LOCK_TIMEOUT_FOR_SYNC)) {
try { // try {
readyProxy = allocProxyStorage(proxy.getDataCenterId(), proxy.getId()); // readyProxy = allocProxyStorage(proxy.getDataCenterId(), proxy.getId());
} finally { // } finally {
_allocProxyLock.unlock(); // _allocProxyLock.unlock();
} // }
//
if (readyProxy != null) { // if (readyProxy != null) {
GlobalLock proxyLock = GlobalLock.getInternLock(getProxyLockName(readyProxy.getId())); // GlobalLock proxyLock = GlobalLock.getInternLock(getProxyLockName(readyProxy.getId()));
try { // try {
if (proxyLock.lock(ACQUIRE_GLOBAL_LOCK_TIMEOUT_FOR_SYNC)) { // if (proxyLock.lock(ACQUIRE_GLOBAL_LOCK_TIMEOUT_FOR_SYNC)) {
try { // try {
readyProxy = start(readyProxy.getId()); // readyProxy = start(readyProxy.getId());
} finally { // } finally {
proxyLock.unlock(); // proxyLock.unlock();
} // }
} else { // } else {
if (s_logger.isInfoEnabled()) { // if (s_logger.isInfoEnabled()) {
s_logger.info("Unable to acquire synchronization lock to start console proxy : " + readyProxy.getName()); // s_logger.info("Unable to acquire synchronization lock to start console proxy : " + readyProxy.getName());
} // }
} // }
} finally { // } finally {
proxyLock.releaseRef(); // proxyLock.releaseRef();
} // }
} // }
} else { // } else {
if (s_logger.isInfoEnabled()) { // if (s_logger.isInfoEnabled()) {
s_logger.info("Unable to acquire synchronization lock to allocate proxy storage, wait for next turn"); // s_logger.info("Unable to acquire synchronization lock to allocate proxy storage, wait for next turn");
} // }
} // }
} catch (StorageUnavailableException e) { // } catch (StorageUnavailableException e) {
s_logger.warn("Storage unavailable", e); // s_logger.warn("Storage unavailable", e);
} catch (InsufficientCapacityException e) { // } catch (InsufficientCapacityException e) {
s_logger.warn("insuffiient capacity", e); // s_logger.warn("insuffiient capacity", e);
} catch (ResourceUnavailableException e) { // } catch (ResourceUnavailableException e) {
s_logger.debug("Concurrent operation: " + e.getMessage()); // s_logger.debug("Concurrent operation: " + e.getMessage());
} // }
} // }
} // }
} // }
} // }
private Runnable getCapacityScanTask() { private Runnable getCapacityScanTask() {
return new Runnable() { return new Runnable() {
@ -1144,7 +1144,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx
} }
try { try {
checkPendingProxyVMs(); // checkPendingProxyVMs();
// scan default data center first // scan default data center first
long defaultId = 0; long defaultId = 0;

View File

@ -12,7 +12,6 @@ import java.util.concurrent.TimeUnit;
import javax.ejb.Local; import javax.ejb.Local;
import javax.naming.ConfigurationException; import javax.naming.ConfigurationException;
import javax.persistence.EntityExistsException;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
@ -617,7 +616,6 @@ public class OvsNetworkManagerImpl implements OvsNetworkManager {
} }
switch (vmState) { switch (vmState) {
case Creating:
case Destroyed: case Destroyed:
case Error: case Error:
case Migrating: case Migrating:

View File

@ -248,7 +248,6 @@ public class SecurityGroupManagerImpl implements SecurityGroupManager, SecurityG
return; return;
} }
switch (vmState) { switch (vmState) {
case Creating:
case Destroyed: case Destroyed:
case Error: case Error:
case Migrating: case Migrating:

View File

@ -89,7 +89,6 @@ import com.cloud.dc.dao.HostPodDao;
import com.cloud.deploy.DeployDestination; import com.cloud.deploy.DeployDestination;
import com.cloud.domain.Domain; import com.cloud.domain.Domain;
import com.cloud.domain.dao.DomainDao; import com.cloud.domain.dao.DomainDao;
import com.cloud.event.ActionEvent;
import com.cloud.event.Event; import com.cloud.event.Event;
import com.cloud.event.EventTypes; import com.cloud.event.EventTypes;
import com.cloud.event.EventUtils; import com.cloud.event.EventUtils;
@ -438,7 +437,7 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
SearchCriteria<VolumeVO> volumeSC = volumeSB.create(); SearchCriteria<VolumeVO> volumeSC = volumeSB.create();
volumeSC.setParameters("poolId", storagePool.getId()); volumeSC.setParameters("poolId", storagePool.getId());
volumeSC.setJoinParameters("activeVmSB", "state", new Object[] {State.Creating, State.Starting, State.Running, State.Stopping, State.Migrating}); volumeSC.setJoinParameters("activeVmSB", "state", State.Starting, State.Running, State.Stopping, State.Migrating);
List<VolumeVO> volumes = _volsDao.search(volumeSC, null); List<VolumeVO> volumes = _volsDao.search(volumeSC, null);
if (volumes.size() > 0) { if (volumes.size() > 0) {

View File

@ -337,7 +337,7 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V
s_logger.warn("No storage hosts found in zone " + zoneId + " , skip programming firewall rules"); s_logger.warn("No storage hosts found in zone " + zoneId + " , skip programming firewall rules");
return true; return true;
} }
List<SecondaryStorageVmVO> alreadyRunning = _secStorageVmDao.getSecStorageVmListInStates( State.Running, State.Migrating, State.Creating, State.Starting); List<SecondaryStorageVmVO> alreadyRunning = _secStorageVmDao.getSecStorageVmListInStates( State.Running, State.Migrating, State.Starting);
String copyPort = Integer.toString(TemplateConstants.DEFAULT_TMPLT_COPY_PORT); String copyPort = Integer.toString(TemplateConstants.DEFAULT_TMPLT_COPY_PORT);
SecStorageFirewallCfgCommand cpc = new SecStorageFirewallCfgCommand(); SecStorageFirewallCfgCommand cpc = new SecStorageFirewallCfgCommand();
@ -525,58 +525,58 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V
private void checkPendingSecStorageVMs() { // private void checkPendingSecStorageVMs() {
// drive state to change away from transient states // // drive state to change away from transient states
List<SecondaryStorageVmVO> l = _secStorageVmDao.getSecStorageVmListInStates(State.Creating); // List<SecondaryStorageVmVO> l = _secStorageVmDao.getSecStorageVmListInStates(State.Creating);
if (l != null && l.size() > 0) { // if (l != null && l.size() > 0) {
for (SecondaryStorageVmVO secStorageVm : l) { // for (SecondaryStorageVmVO secStorageVm : l) {
if (secStorageVm.getLastUpdateTime() == null || // if (secStorageVm.getLastUpdateTime() == null ||
(secStorageVm.getLastUpdateTime() != null && System.currentTimeMillis() - secStorageVm.getLastUpdateTime().getTime() > 60000)) { // (secStorageVm.getLastUpdateTime() != null && System.currentTimeMillis() - secStorageVm.getLastUpdateTime().getTime() > 60000)) {
try { // try {
SecondaryStorageVmVO readysecStorageVm = null; // SecondaryStorageVmVO readysecStorageVm = null;
if (_allocLock.lock(ACQUIRE_GLOBAL_LOCK_TIMEOUT_FOR_SYNC)) { // if (_allocLock.lock(ACQUIRE_GLOBAL_LOCK_TIMEOUT_FOR_SYNC)) {
try { // try {
readysecStorageVm = allocSecStorageVmStorage(secStorageVm.getDataCenterId(), secStorageVm.getId()); // readysecStorageVm = allocSecStorageVmStorage(secStorageVm.getDataCenterId(), secStorageVm.getId());
} finally { // } finally {
_allocLock.unlock(); // _allocLock.unlock();
} // }
//
if (readysecStorageVm != null) { // if (readysecStorageVm != null) {
GlobalLock secStorageVmLock = GlobalLock.getInternLock(getSecStorageVmLockName(readysecStorageVm.getId())); // GlobalLock secStorageVmLock = GlobalLock.getInternLock(getSecStorageVmLockName(readysecStorageVm.getId()));
try { // try {
if (secStorageVmLock.lock(ACQUIRE_GLOBAL_LOCK_TIMEOUT_FOR_SYNC)) { // if (secStorageVmLock.lock(ACQUIRE_GLOBAL_LOCK_TIMEOUT_FOR_SYNC)) {
try { // try {
readysecStorageVm = start(readysecStorageVm.getId()); // readysecStorageVm = start(readysecStorageVm.getId());
} finally { // } finally {
secStorageVmLock.unlock(); // secStorageVmLock.unlock();
} // }
} else { // } else {
if (s_logger.isInfoEnabled()) { // if (s_logger.isInfoEnabled()) {
s_logger.info("Unable to acquire synchronization lock to start secondary storage vm : " + readysecStorageVm.getName()); // s_logger.info("Unable to acquire synchronization lock to start secondary storage vm : " + readysecStorageVm.getName());
} // }
} // }
} finally { // } finally {
secStorageVmLock.releaseRef(); // secStorageVmLock.releaseRef();
} // }
} // }
} else { // } else {
if (s_logger.isInfoEnabled()) { // if (s_logger.isInfoEnabled()) {
s_logger.info("Unable to acquire synchronization lock to allocate secondary storage vm storage, wait for next turn"); // s_logger.info("Unable to acquire synchronization lock to allocate secondary storage vm storage, wait for next turn");
} // }
} // }
} catch (StorageUnavailableException e) { // } catch (StorageUnavailableException e) {
s_logger.warn("Storage unavailable", e); // s_logger.warn("Storage unavailable", e);
} catch (InsufficientCapacityException e) { // } catch (InsufficientCapacityException e) {
s_logger.warn("insuffiient capacity", e); // s_logger.warn("insuffiient capacity", e);
} catch (ConcurrentOperationException e) { // } catch (ConcurrentOperationException e) {
s_logger.debug("Concurrent operation: " + e.getMessage()); // s_logger.debug("Concurrent operation: " + e.getMessage());
} catch (ResourceUnavailableException e) { // } catch (ResourceUnavailableException e) {
s_logger.debug("Concurrent operation: " + e.getMessage()); // s_logger.debug("Concurrent operation: " + e.getMessage());
} // }
} // }
} // }
} // }
} // }
private Runnable getCapacityScanTask() { private Runnable getCapacityScanTask() {
return new Runnable() { return new Runnable() {
@ -616,14 +616,14 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V
} }
try { try {
checkPendingSecStorageVMs(); //checkPendingSecStorageVMs();
List<DataCenterVO> datacenters = _dcDao.listAllIncludingRemoved(); List<DataCenterVO> datacenters = _dcDao.listAllIncludingRemoved();
for (DataCenterVO dc: datacenters){ for (DataCenterVO dc: datacenters){
if(isZoneReady(zoneHostInfoMap, dc.getId())) { if(isZoneReady(zoneHostInfoMap, dc.getId())) {
List<SecondaryStorageVmVO> alreadyRunning = _secStorageVmDao.getSecStorageVmListInStates(dc.getId(), State.Running, State.Migrating, State.Creating, State.Starting); List<SecondaryStorageVmVO> alreadyRunning = _secStorageVmDao.getSecStorageVmListInStates(dc.getId(), State.Running, State.Migrating, State.Starting);
List<SecondaryStorageVmVO> stopped = _secStorageVmDao.getSecStorageVmListInStates(dc.getId(), State.Stopped, State.Stopping); List<SecondaryStorageVmVO> stopped = _secStorageVmDao.getSecStorageVmListInStates(dc.getId(), State.Stopped, State.Stopping);
if (alreadyRunning.size() == 0) { if (alreadyRunning.size() == 0) {
if (stopped.size() == 0) { if (stopped.size() == 0) {
@ -693,7 +693,7 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V
public SecondaryStorageVmVO assignSecStorageVmFromStoppedPool(long dataCenterId) { public SecondaryStorageVmVO assignSecStorageVmFromStoppedPool(long dataCenterId) {
List<SecondaryStorageVmVO> l = _secStorageVmDao.getSecStorageVmListInStates( List<SecondaryStorageVmVO> l = _secStorageVmDao.getSecStorageVmListInStates(
dataCenterId, State.Creating, State.Starting, State.Stopped, dataCenterId, State.Starting, State.Stopped,
State.Migrating); State.Migrating);
if (l != null && l.size() > 0) { if (l != null && l.size() > 0) {
return l.get(0); return l.get(0);

View File

@ -31,7 +31,6 @@ import java.util.concurrent.TimeUnit;
import javax.ejb.Local; import javax.ejb.Local;
import javax.naming.ConfigurationException; import javax.naming.ConfigurationException;
import javax.naming.InsufficientResourcesException;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
@ -1207,7 +1206,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
return true; return true;
} }
if (state == State.Creating || state == State.Destroyed || state == State.Expunging || state == State.Error) { if (state == State.Destroyed || state == State.Expunging || state == State.Error) {
s_logger.warn("Stopped called on " + vm.toString() + " but the state is " + state.toString()); s_logger.warn("Stopped called on " + vm.toString() + " but the state is " + state.toString());
return true; return true;
} }

View File

@ -223,7 +223,6 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager {
_storageMgr.allocateRawVolume(VolumeType.DATADISK, "DATA-" + vm.getId(), offering.first(), offering.second(), vm, owner); _storageMgr.allocateRawVolume(VolumeType.DATADISK, "DATA-" + vm.getId(), offering.first(), offering.second(), vm, owner);
} }
stateTransitTo(vm, Event.OperationSucceeded, null);
txn.commit(); txn.commit();
if (s_logger.isDebugEnabled()) { if (s_logger.isDebugEnabled()) {
s_logger.debug("Allocation completed for VM: " + vm); s_logger.debug("Allocation completed for VM: " + vm);
@ -676,7 +675,7 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager {
return true; return true;
} }
if (state == State.Creating || state == State.Destroyed || state == State.Expunging || state == State.Error) { if (state == State.Destroyed || state == State.Expunging || state == State.Error) {
s_logger.debug("Stopped called on " + vm + " but the state is " + state); s_logger.debug("Stopped called on " + vm + " but the state is " + state);
return true; return true;
} }