mirror of https://github.com/apache/cloudstack.git
new vmsync for simulator
This commit is contained in:
parent
680d4202de
commit
521b2840b2
|
|
@ -100,7 +100,6 @@ import com.cloud.utils.component.ManagerBase;
|
|||
import com.cloud.utils.db.TransactionLegacy;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
import com.cloud.vm.DiskProfile;
|
||||
import com.cloud.vm.VirtualMachine.State;
|
||||
|
||||
@Component
|
||||
@Local(value = {MockStorageManager.class})
|
||||
|
|
@ -511,13 +510,10 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
|
|||
if (volume != null) {
|
||||
_mockVolumeDao.remove(volume.getId());
|
||||
}
|
||||
|
||||
if (cmd.getVmName() != null) {
|
||||
MockVm vm = _mockVMDao.findByVmName(cmd.getVmName());
|
||||
if (vm != null) {
|
||||
vm.setState(State.Expunging);
|
||||
MockVMVO vmVo = _mockVMDao.createForUpdate(vm.getId());
|
||||
_mockVMDao.update(vm.getId(), vmVo);
|
||||
_mockVMDao.remove(vm.getId());
|
||||
}
|
||||
}
|
||||
txn.commit();
|
||||
|
|
|
|||
|
|
@ -56,11 +56,11 @@ import com.cloud.agent.api.routing.VmDataCommand;
|
|||
import com.cloud.simulator.MockVMVO;
|
||||
import com.cloud.utils.Pair;
|
||||
import com.cloud.utils.component.Manager;
|
||||
import com.cloud.vm.VirtualMachine.State;
|
||||
import com.cloud.vm.VirtualMachine.PowerState;
|
||||
|
||||
public interface MockVmManager extends Manager {
|
||||
|
||||
Map<String, State> getVmStates(String hostGuid);
|
||||
Map<String, PowerState> getVmStates(String hostGuid);
|
||||
|
||||
Map<String, MockVMVO> getVms(String hostGuid);
|
||||
|
||||
|
|
|
|||
|
|
@ -90,7 +90,6 @@ import com.cloud.utils.Ternary;
|
|||
import com.cloud.utils.component.ManagerBase;
|
||||
import com.cloud.utils.db.TransactionLegacy;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
import com.cloud.vm.VirtualMachine.State;
|
||||
import com.cloud.vm.VirtualMachine.PowerState;
|
||||
|
||||
@Component
|
||||
|
|
@ -147,7 +146,7 @@ public class MockVmManagerImpl extends ManagerBase implements MockVmManager {
|
|||
vm = new MockVMVO();
|
||||
vm.setCpu(cpuHz);
|
||||
vm.setMemory(ramSize);
|
||||
vm.setState(State.Running);
|
||||
vm.setPowerState(PowerState.PowerOn);
|
||||
vm.setName(vmName);
|
||||
vm.setVncPort(vncPort);
|
||||
vm.setHostId(host.getId());
|
||||
|
|
@ -175,8 +174,8 @@ public class MockVmManagerImpl extends ManagerBase implements MockVmManager {
|
|||
txn.close();
|
||||
}
|
||||
} else {
|
||||
if (vm.getState() == State.Stopped) {
|
||||
vm.setState(State.Running);
|
||||
if (vm.getPowerState() == PowerState.PowerOff) {
|
||||
vm.setPowerState(PowerState.PowerOn);
|
||||
txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
|
||||
try {
|
||||
txn.start();
|
||||
|
|
@ -193,7 +192,7 @@ public class MockVmManagerImpl extends ManagerBase implements MockVmManager {
|
|||
}
|
||||
}
|
||||
|
||||
if (vm.getState() == State.Running && vmName.startsWith("s-")) {
|
||||
if (vm.getPowerState() == PowerState.PowerOn && vmName.startsWith("s-")) {
|
||||
String prvIp = null;
|
||||
String prvMac = null;
|
||||
String prvNetMask = null;
|
||||
|
|
@ -289,18 +288,18 @@ public class MockVmManagerImpl extends ManagerBase implements MockVmManager {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Map<String, State> getVmStates(String hostGuid) {
|
||||
public Map<String, PowerState> getVmStates(String hostGuid) {
|
||||
TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
|
||||
try {
|
||||
txn.start();
|
||||
Map<String, State> states = new HashMap<String, State>();
|
||||
Map<String, PowerState> states = new HashMap<String, PowerState>();
|
||||
List<MockVMVO> vms = _mockVmDao.findByHostGuid(hostGuid);
|
||||
if (vms.isEmpty()) {
|
||||
txn.commit();
|
||||
return states;
|
||||
}
|
||||
for (MockVm vm : vms) {
|
||||
states.put(vm.getName(), vm.getState());
|
||||
states.put(vm.getName(), vm.getPowerState());
|
||||
}
|
||||
txn.commit();
|
||||
return states;
|
||||
|
|
@ -355,7 +354,7 @@ public class MockVmManagerImpl extends ManagerBase implements MockVmManager {
|
|||
}
|
||||
|
||||
txn.commit();
|
||||
return new CheckVirtualMachineAnswer(cmd, vm.getState()==State.Running? PowerState.PowerOn: PowerState.PowerOff, vm.getVncPort());
|
||||
return new CheckVirtualMachineAnswer(cmd, vm.getPowerState(), vm.getVncPort());
|
||||
} catch (Exception ex) {
|
||||
txn.rollback();
|
||||
throw new CloudRuntimeException("unable to fetch vm state " + cmd.getVmName(), ex);
|
||||
|
|
@ -392,10 +391,6 @@ public class MockVmManagerImpl extends ManagerBase implements MockVmManager {
|
|||
MockVMVO vm = _mockVmDao.findByVmNameAndHost(vmName, info.getHostUuid());
|
||||
if (vm == null) {
|
||||
return new MigrateAnswer(cmd, false, "can't find vm:" + vmName + " on host:" + info.getHostUuid(), null);
|
||||
} else {
|
||||
if (vm.getState() == State.Migrating) {
|
||||
vm.setState(State.Running);
|
||||
}
|
||||
}
|
||||
|
||||
MockHost destHost = _mockHostDao.findByGuid(destGuid);
|
||||
|
|
@ -423,7 +418,6 @@ public class MockVmManagerImpl extends ManagerBase implements MockVmManager {
|
|||
try {
|
||||
txn.start();
|
||||
MockVMVO vm = _mockVmDao.findById(vmTo.getId());
|
||||
vm.setState(State.Migrating);
|
||||
_mockVmDao.update(vm.getId(), vm);
|
||||
txn.commit();
|
||||
} catch (Exception ex) {
|
||||
|
|
@ -505,7 +499,7 @@ public class MockVmManagerImpl extends ManagerBase implements MockVmManager {
|
|||
return new RevertToVMSnapshotAnswer(cmd, false, "No VM by name " + cmd.getVmName());
|
||||
}
|
||||
s_logger.debug("Reverted to snapshot " + snapshot + " of VM " + vm);
|
||||
return new RevertToVMSnapshotAnswer(cmd, cmd.getVolumeTOs(), vmVo.getState()== State.Running? PowerState.PowerOn: PowerState.PowerOff);
|
||||
return new RevertToVMSnapshotAnswer(cmd, cmd.getVolumeTOs(), vmVo.getPowerState());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -516,7 +510,7 @@ public class MockVmManagerImpl extends ManagerBase implements MockVmManager {
|
|||
String vmName = cmd.getVmName();
|
||||
MockVm vm = _mockVmDao.findByVmName(vmName);
|
||||
if (vm != null) {
|
||||
vm.setState(State.Stopped);
|
||||
vm.setPowerState(PowerState.PowerOff);
|
||||
_mockVmDao.update(vm.getId(), (MockVMVO)vm);
|
||||
}
|
||||
|
||||
|
|
@ -537,24 +531,7 @@ public class MockVmManagerImpl extends ManagerBase implements MockVmManager {
|
|||
|
||||
@Override
|
||||
public RebootAnswer rebootVM(RebootCommand cmd) {
|
||||
TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
|
||||
try {
|
||||
txn.start();
|
||||
MockVm vm = _mockVmDao.findByVmName(cmd.getVmName());
|
||||
if (vm != null) {
|
||||
vm.setState(State.Running);
|
||||
_mockVmDao.update(vm.getId(), (MockVMVO)vm);
|
||||
}
|
||||
txn.commit();
|
||||
return new RebootAnswer(cmd, "Rebooted " + cmd.getVmName(), true);
|
||||
} catch (Exception ex) {
|
||||
txn.rollback();
|
||||
throw new CloudRuntimeException("unable to stop vm " + cmd.getVmName(), ex);
|
||||
} finally {
|
||||
txn.close();
|
||||
txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
|
||||
txn.close();
|
||||
}
|
||||
return new RebootAnswer(cmd, "Rebooted " + cmd.getVmName(), true);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ import com.cloud.simulator.MockVMVO;
|
|||
import com.cloud.simulator.dao.MockConfigurationDao;
|
||||
import com.cloud.utils.Pair;
|
||||
import com.cloud.utils.component.Manager;
|
||||
import com.cloud.vm.VirtualMachine.State;
|
||||
import com.cloud.vm.VirtualMachine.PowerState;
|
||||
|
||||
public interface SimulatorManager extends Manager {
|
||||
public static final String Name = "simulator manager";
|
||||
|
|
@ -62,7 +62,7 @@ public interface SimulatorManager extends Manager {
|
|||
|
||||
public HashMap<String, Pair<Long, Long>> syncNetworkGroups(String hostGuid);
|
||||
|
||||
Map<String, State> getVmStates(String hostGuid);
|
||||
Map<String, PowerState> getVmStates(String hostGuid);
|
||||
|
||||
Map<String, MockVMVO> getVms(String hostGuid);
|
||||
|
||||
|
|
@ -71,4 +71,4 @@ public interface SimulatorManager extends Manager {
|
|||
boolean clearSimulatorMock(Long id);
|
||||
|
||||
MockConfigurationDao getMockConfigurationDao();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -128,7 +128,7 @@ import com.cloud.utils.component.PluggableService;
|
|||
import com.cloud.utils.db.DB;
|
||||
import com.cloud.utils.db.TransactionLegacy;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
import com.cloud.vm.VirtualMachine.State;
|
||||
import com.cloud.vm.VirtualMachine.PowerState;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.stream.JsonReader;
|
||||
|
||||
|
|
@ -453,7 +453,7 @@ public class SimulatorManagerImpl extends ManagerBase implements SimulatorManage
|
|||
}
|
||||
|
||||
@Override
|
||||
public Map<String, State> getVmStates(String hostGuid) {
|
||||
public Map<String, PowerState> getVmStates(String hostGuid) {
|
||||
return _mockVmMgr.getVmStates(hostGuid);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -59,7 +59,6 @@ import com.cloud.storage.template.TemplateProp;
|
|||
import com.cloud.utils.Pair;
|
||||
import com.cloud.utils.db.TransactionLegacy;
|
||||
import com.cloud.vm.VirtualMachine.PowerState;
|
||||
import com.cloud.vm.VirtualMachine.State;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.stream.JsonReader;
|
||||
|
||||
|
|
@ -288,18 +287,7 @@ public class AgentRoutingResource extends AgentStorageResource {
|
|||
protected HashMap<String, HostVmStateReportEntry> getHostVmStateReport() {
|
||||
HashMap<String, HostVmStateReportEntry> report = new HashMap<String, HostVmStateReportEntry>();
|
||||
|
||||
Map<String, State> states = _simMgr.getVmStates(this.hostGuid);
|
||||
for (String vmName : states.keySet()) {
|
||||
State state = states.get(vmName);
|
||||
if (state == State.Running) {
|
||||
report.put(vmName, new HostVmStateReportEntry(PowerState.PowerOn, agentHost.getName()));
|
||||
} else if (state == State.Stopped) {
|
||||
report.put(vmName, new HostVmStateReportEntry(PowerState.PowerOff, agentHost.getName()));
|
||||
} else {
|
||||
report.put(vmName, new HostVmStateReportEntry(PowerState.PowerUnknown, agentHost.getName()));
|
||||
}
|
||||
}
|
||||
|
||||
Map<String, PowerState> states = _simMgr.getVmStates(this.hostGuid);
|
||||
return report;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ import javax.persistence.Table;
|
|||
|
||||
import org.apache.cloudstack.api.InternalIdentity;
|
||||
|
||||
import com.cloud.vm.VirtualMachine.State;
|
||||
import com.cloud.vm.VirtualMachine.PowerState;
|
||||
|
||||
@Entity
|
||||
@Table(name = "mockvm")
|
||||
|
|
@ -44,8 +44,8 @@ public class MockVMVO implements MockVm, InternalIdentity {
|
|||
@Column(name = "type")
|
||||
private String vmType;
|
||||
|
||||
@Column(name = "state")
|
||||
private State state;
|
||||
@Column(name = "power_state")
|
||||
protected PowerState powerState;
|
||||
|
||||
@Column(name = "vnc_port")
|
||||
private int vncPort;
|
||||
|
|
@ -96,20 +96,21 @@ public class MockVMVO implements MockVm, InternalIdentity {
|
|||
}
|
||||
|
||||
@Override
|
||||
public State getState() {
|
||||
return this.state;
|
||||
public PowerState getPowerState() {
|
||||
return powerState;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPowerState(PowerState powerState) {
|
||||
this.powerState = powerState;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return this.vmType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setState(State state) {
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getVncPort() {
|
||||
return this.vncPort;
|
||||
|
|
|
|||
|
|
@ -16,16 +16,16 @@
|
|||
// under the License.
|
||||
package com.cloud.simulator;
|
||||
|
||||
import com.cloud.vm.VirtualMachine.State;
|
||||
import com.cloud.vm.VirtualMachine.PowerState;
|
||||
|
||||
// As storage is mapped from storage device, can virtually treat that VM here does
|
||||
public interface MockVm {
|
||||
|
||||
public String getName();
|
||||
|
||||
public State getState();
|
||||
public PowerState getPowerState();
|
||||
|
||||
public void setState(State state);
|
||||
public void setPowerState(PowerState state);
|
||||
|
||||
public void setHostId(long hostId);
|
||||
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ public class MockVMDaoImpl extends GenericDaoBase<MockVMVO, Long> implements Moc
|
|||
public List<MockVMVO> findByHostGuid(String guid) {
|
||||
SearchCriteria<MockVMVO> sc = GuidSearch.create();
|
||||
sc.setJoinParameters("host", "guid", guid);
|
||||
sc.setParameters("state", VirtualMachine.State.Running);
|
||||
sc.setParameters("power_state", VirtualMachine.PowerState.PowerOn);
|
||||
return listBy(sc);
|
||||
}
|
||||
|
||||
|
|
@ -78,7 +78,7 @@ public class MockVMDaoImpl extends GenericDaoBase<MockVMVO, Long> implements Moc
|
|||
|
||||
GuidSearch = createSearchBuilder();
|
||||
GuidSearch.join("host", host, host.entity().getId(), GuidSearch.entity().getHostId(), JoinBuilder.JoinType.INNER);
|
||||
GuidSearch.and("state", GuidSearch.entity().getState(), SearchCriteria.Op.EQ);
|
||||
GuidSearch.and("power_state", GuidSearch.entity().getPowerState(), SearchCriteria.Op.EQ);
|
||||
GuidSearch.done();
|
||||
|
||||
vmNameSearch = createSearchBuilder();
|
||||
|
|
|
|||
|
|
@ -73,14 +73,14 @@ CREATE TABLE `simulator`.`mockvm` (
|
|||
`name` varchar(255),
|
||||
`host_id` bigint unsigned,
|
||||
`type` varchar(40),
|
||||
`state` varchar(40),
|
||||
`power_state` varchar(40),
|
||||
`vnc_port` bigint unsigned,
|
||||
`memory` bigint unsigned,
|
||||
`cpu` bigint unsigned,
|
||||
`bootargs` varchar(255),
|
||||
PRIMARY KEY (`id`),
|
||||
INDEX `i_mockvm__host_id`(`host_id`),
|
||||
INDEX `i_mockvm__state`(`state`),
|
||||
INDEX `i_mockvm__power_state`(`power_state`),
|
||||
INDEX `i_mockvm__type`(`type`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue