use of com.cloud.vm.VirtualMachine.State in project CloudStack-archive by CloudStack-extras.
the class AgentRoutingResource method initialize.
@Override
public StartupCommand[] initialize() {
synchronized (_vms) {
_vms.clear();
}
Map<String, State> changes = _simMgr.getVmStates(this.hostGuid);
Map<String, MockVMVO> vmsMaps = _simMgr.getVms(this.hostGuid);
totalCpu = agentHost.getCpuCount() * agentHost.getCpuSpeed();
totalMem = agentHost.getMemorySize();
for (Map.Entry<String, MockVMVO> entry : vmsMaps.entrySet()) {
MockVMVO vm = entry.getValue();
usedCpu += vm.getCpu();
usedMem += vm.getMemory();
_runningVms.put(entry.getKey(), new Pair<Long, Long>(Long.valueOf(vm.getCpu()), vm.getMemory()));
}
List<Object> info = getHostInfo();
StartupRoutingCommand cmd = new StartupRoutingCommand((Integer) info.get(0), (Long) info.get(1), (Long) info.get(2), (Long) info.get(4), (String) info.get(3), HypervisorType.Simulator, RouterPrivateIpStrategy.HostLocal);
cmd.setStateChanges(changes);
Map<String, String> hostDetails = new HashMap<String, String>();
hostDetails.put(RouterPrivateIpStrategy.class.getCanonicalName(), RouterPrivateIpStrategy.DcGlobal.toString());
cmd.setHostDetails(hostDetails);
cmd.setAgentTag("agent-simulator");
cmd.setPrivateIpAddress(agentHost.getPrivateIpAddress());
cmd.setPrivateNetmask(agentHost.getPrivateNetMask());
cmd.setPrivateMacAddress(agentHost.getPrivateMacAddress());
cmd.setStorageIpAddress(agentHost.getStorageIpAddress());
cmd.setStorageNetmask(agentHost.getStorageNetMask());
cmd.setStorageMacAddress(agentHost.getStorageMacAddress());
cmd.setStorageIpAddressDeux(agentHost.getStorageIpAddress());
cmd.setStorageNetmaskDeux(agentHost.getStorageNetMask());
cmd.setStorageMacAddressDeux(agentHost.getStorageIpAddress());
cmd.setName(agentHost.getName());
cmd.setGuid(agentHost.getGuid());
cmd.setVersion(agentHost.getVersion());
cmd.setAgentTag("agent-simulator");
cmd.setDataCenter(String.valueOf(agentHost.getDataCenterId()));
cmd.setPod(String.valueOf(agentHost.getPodId()));
cmd.setCluster(String.valueOf(agentHost.getClusterId()));
StartupStorageCommand ssCmd = initializeLocalSR();
return new StartupCommand[] { cmd, ssCmd };
}
use of com.cloud.vm.VirtualMachine.State in project CloudStack-archive by CloudStack-extras.
the class AgentRoutingResource method sync.
protected HashMap<String, State> sync() {
Map<String, State> newStates;
Map<String, State> oldStates = null;
HashMap<String, State> changes = new HashMap<String, State>();
synchronized (_vms) {
oldStates = new HashMap<String, State>(_vms.size());
oldStates.putAll(_vms);
newStates = new HashMap<String, State>(_vms.size());
newStates.putAll(_vms);
for (Map.Entry<String, State> entry : newStates.entrySet()) {
String vm = entry.getKey();
State newState = entry.getValue();
State oldState = oldStates.remove(vm);
if (s_logger.isTraceEnabled()) {
s_logger.trace("VM " + vm + ": has state " + newState + " and we have state " + (oldState != null ? oldState.toString() : "null"));
}
if (oldState == null) {
_vms.put(vm, newState);
changes.put(vm, newState);
} else if (oldState == State.Starting) {
if (newState == State.Running) {
_vms.put(vm, newState);
} else if (newState == State.Stopped) {
s_logger.debug("Ignoring vm " + vm + " because of a lag in starting the vm.");
}
} else if (oldState == State.Stopping) {
if (newState == State.Stopped) {
_vms.put(vm, newState);
} else if (newState == State.Running) {
s_logger.debug("Ignoring vm " + vm + " because of a lag in stopping the vm. ");
}
} else if (oldState != newState) {
_vms.put(vm, newState);
changes.put(vm, newState);
}
}
for (Map.Entry<String, State> entry : oldStates.entrySet()) {
String vm = entry.getKey();
State oldState = entry.getValue();
if (s_logger.isTraceEnabled()) {
s_logger.trace("VM " + vm + " is now missing from simulator agent so reporting stopped");
}
if (oldState == State.Stopping) {
s_logger.debug("Ignoring VM " + vm + " in transition state stopping.");
_vms.remove(vm);
} else if (oldState == State.Starting) {
s_logger.debug("Ignoring VM " + vm + " in transition state starting.");
} else if (oldState == State.Stopped) {
_vms.remove(vm);
} else {
changes.put(entry.getKey(), State.Stopped);
}
}
}
return changes;
}
use of com.cloud.vm.VirtualMachine.State in project CloudStack-archive by CloudStack-extras.
the class AgentRoutingResource method execute.
protected synchronized StopAnswer execute(StopCommand cmd) {
StopAnswer answer = null;
String vmName = cmd.getVmName();
State state = null;
synchronized (_vms) {
state = _vms.get(vmName);
_vms.put(vmName, State.Stopping);
}
try {
Answer result = _simMgr.simulate(cmd, hostGuid);
if (!result.getResult()) {
return new StopAnswer(cmd, result.getDetails());
}
answer = new StopAnswer(cmd, null, 0, new Long(100), new Long(200));
Pair<Long, Long> data = _runningVms.get(vmName);
if (data != null) {
this.usedCpu -= data.first();
this.usedMem -= data.second();
}
state = State.Stopped;
} finally {
synchronized (_vms) {
_vms.put(vmName, state);
}
}
return answer;
}
use of com.cloud.vm.VirtualMachine.State in project CloudStack-archive by CloudStack-extras.
the class AgentRoutingResource method execute.
protected CheckVirtualMachineAnswer execute(final CheckVirtualMachineCommand cmd) {
final String vmName = cmd.getVmName();
CheckVirtualMachineAnswer result = (CheckVirtualMachineAnswer) _simMgr.simulate(cmd, hostGuid);
State state = result.getState();
if (state == State.Running) {
synchronized (_vms) {
_vms.put(vmName, State.Running);
}
}
return result;
}
use of com.cloud.vm.VirtualMachine.State in project CloudStack-archive by CloudStack-extras.
the class MockVmManagerImpl method getVmStates.
@Override
public Map<String, State> getVmStates(String hostGuid) {
Map<String, State> states = new HashMap<String, State>();
List<MockVMVO> vms = _mockVmDao.findByHostGuid(hostGuid);
if (vms.isEmpty()) {
return states;
}
for (MockVm vm : vms) {
states.put(vm.getName(), vm.getState());
}
return states;
}
Aggregations