mirror of
https://github.com/apache/cloudstack.git
synced 2025-12-16 10:32:34 +01:00
CLOUDSTACK-7204:
fixed build for simulator
This commit is contained in:
parent
89017a7d7b
commit
680d4202de
@ -91,6 +91,7 @@ import com.cloud.utils.component.ManagerBase;
|
|||||||
import com.cloud.utils.db.TransactionLegacy;
|
import com.cloud.utils.db.TransactionLegacy;
|
||||||
import com.cloud.utils.exception.CloudRuntimeException;
|
import com.cloud.utils.exception.CloudRuntimeException;
|
||||||
import com.cloud.vm.VirtualMachine.State;
|
import com.cloud.vm.VirtualMachine.State;
|
||||||
|
import com.cloud.vm.VirtualMachine.PowerState;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
@Local(value = {MockVmManager.class})
|
@Local(value = {MockVmManager.class})
|
||||||
@ -354,7 +355,7 @@ public class MockVmManagerImpl extends ManagerBase implements MockVmManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
txn.commit();
|
txn.commit();
|
||||||
return new CheckVirtualMachineAnswer(cmd, vm.getState(), vm.getVncPort());
|
return new CheckVirtualMachineAnswer(cmd, vm.getState()==State.Running? PowerState.PowerOn: PowerState.PowerOff, vm.getVncPort());
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
txn.rollback();
|
txn.rollback();
|
||||||
throw new CloudRuntimeException("unable to fetch vm state " + cmd.getVmName(), ex);
|
throw new CloudRuntimeException("unable to fetch vm state " + cmd.getVmName(), ex);
|
||||||
@ -504,7 +505,7 @@ public class MockVmManagerImpl extends ManagerBase implements MockVmManager {
|
|||||||
return new RevertToVMSnapshotAnswer(cmd, false, "No VM by name " + cmd.getVmName());
|
return new RevertToVMSnapshotAnswer(cmd, false, "No VM by name " + cmd.getVmName());
|
||||||
}
|
}
|
||||||
s_logger.debug("Reverted to snapshot " + snapshot + " of VM " + vm);
|
s_logger.debug("Reverted to snapshot " + snapshot + " of VM " + vm);
|
||||||
return new RevertToVMSnapshotAnswer(cmd, cmd.getVolumeTOs(), vmVo.getState());
|
return new RevertToVMSnapshotAnswer(cmd, cmd.getVolumeTOs(), vmVo.getState()== State.Running? PowerState.PowerOn: PowerState.PowerOff);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -39,7 +39,7 @@ import com.cloud.resource.ResourceManager;
|
|||||||
import com.cloud.simulator.dao.MockConfigurationDao;
|
import com.cloud.simulator.dao.MockConfigurationDao;
|
||||||
import com.cloud.utils.component.AdapterBase;
|
import com.cloud.utils.component.AdapterBase;
|
||||||
import com.cloud.vm.VirtualMachine;
|
import com.cloud.vm.VirtualMachine;
|
||||||
import com.cloud.vm.VirtualMachine.State;
|
import com.cloud.vm.VirtualMachine.PowerState;
|
||||||
|
|
||||||
@Local(value=Investigator.class)
|
@Local(value=Investigator.class)
|
||||||
public class SimulatorInvestigator extends AdapterBase implements Investigator {
|
public class SimulatorInvestigator extends AdapterBase implements Investigator {
|
||||||
@ -90,7 +90,7 @@ public class SimulatorInvestigator extends AdapterBase implements Investigator {
|
|||||||
}
|
}
|
||||||
CheckVirtualMachineAnswer cvmAnswer = (CheckVirtualMachineAnswer)answer;
|
CheckVirtualMachineAnswer cvmAnswer = (CheckVirtualMachineAnswer)answer;
|
||||||
s_logger.debug("Agent responded with state " + cvmAnswer.getState().toString());
|
s_logger.debug("Agent responded with state " + cvmAnswer.getState().toString());
|
||||||
return cvmAnswer.getState() == State.Running;
|
return cvmAnswer.getState() == PowerState.PowerOn;
|
||||||
} catch (AgentUnavailableException e) {
|
} catch (AgentUnavailableException e) {
|
||||||
s_logger.debug("Unable to reach the agent for " + vm.toString() + ": " + e.getMessage());
|
s_logger.debug("Unable to reach the agent for " + vm.toString() + ": " + e.getMessage());
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@ -227,18 +227,16 @@ public class AgentRoutingResource extends AgentStorageResource {
|
|||||||
if (this.totalCpu < (vmSpec.getCpus() * vmSpec.getMaxSpeed() + this.usedCpu) || this.totalMem < (vmSpec.getMaxRam() + this.usedMem)) {
|
if (this.totalCpu < (vmSpec.getCpus() * vmSpec.getMaxSpeed() + this.usedCpu) || this.totalMem < (vmSpec.getMaxRam() + this.usedMem)) {
|
||||||
return new StartAnswer(cmd, "Not enough resource to start the vm");
|
return new StartAnswer(cmd, "Not enough resource to start the vm");
|
||||||
}
|
}
|
||||||
try {
|
Answer result = _simMgr.simulate(cmd, hostGuid);
|
||||||
Answer result = _simMgr.simulate(cmd, hostGuid);
|
if (!result.getResult()) {
|
||||||
if (!result.getResult()) {
|
return new StartAnswer(cmd, result.getDetails());
|
||||||
return new StartAnswer(cmd, result.getDetails());
|
|
||||||
}
|
|
||||||
|
|
||||||
this.usedCpu += vmSpec.getCpus() * vmSpec.getMaxSpeed();
|
|
||||||
this.usedMem += vmSpec.getMaxRam();
|
|
||||||
_runningVms.put(vmName, new Pair<Long, Long>(Long.valueOf(vmSpec.getCpus() * vmSpec.getMaxSpeed()), vmSpec.getMaxRam()));
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.usedCpu += vmSpec.getCpus() * vmSpec.getMaxSpeed();
|
||||||
|
this.usedMem += vmSpec.getMaxRam();
|
||||||
|
_runningVms.put(vmName, new Pair<Long, Long>(Long.valueOf(vmSpec.getCpus() * vmSpec.getMaxSpeed()), vmSpec.getMaxRam()));
|
||||||
|
|
||||||
|
|
||||||
return new StartAnswer(cmd);
|
return new StartAnswer(cmd);
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -248,22 +246,20 @@ public class AgentRoutingResource extends AgentStorageResource {
|
|||||||
StopAnswer answer = null;
|
StopAnswer answer = null;
|
||||||
String vmName = cmd.getVmName();
|
String vmName = cmd.getVmName();
|
||||||
|
|
||||||
try {
|
Answer result = _simMgr.simulate(cmd, hostGuid);
|
||||||
Answer result = _simMgr.simulate(cmd, hostGuid);
|
|
||||||
|
|
||||||
if (!result.getResult()) {
|
|
||||||
return new StopAnswer(cmd, result.getDetails(), false);
|
|
||||||
}
|
|
||||||
|
|
||||||
answer = new StopAnswer(cmd, null, true);
|
|
||||||
Pair<Long, Long> data = _runningVms.get(vmName);
|
|
||||||
if (data != null) {
|
|
||||||
this.usedCpu -= data.first();
|
|
||||||
this.usedMem -= data.second();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (!result.getResult()) {
|
||||||
|
return new StopAnswer(cmd, result.getDetails(), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
answer = new StopAnswer(cmd, null, true);
|
||||||
|
Pair<Long, Long> data = _runningVms.get(vmName);
|
||||||
|
if (data != null) {
|
||||||
|
this.usedCpu -= data.first();
|
||||||
|
this.usedMem -= data.second();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
return answer;
|
return answer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user