Skip to content

Commit 86684cd

Browse files
committed
Made following fixes in simulator
- Support for ScaleVmCommand/NetworkRulesVmSecondaryIpCommand in resource layer - Added support for scaling up a running VM in simulator - Fixed some method names not following convention
1 parent 2772e4d commit 86684cd

4 files changed

Lines changed: 47 additions & 24 deletions

File tree

plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockVmManager.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,23 +81,23 @@ public interface MockVmManager extends Manager {
8181

8282
Answer setVmData(VmDataCommand cmd);
8383

84-
Answer CheckConsoleProxyLoad(CheckConsoleProxyLoadCommand cmd);
84+
Answer checkConsoleProxyLoad(CheckConsoleProxyLoadCommand cmd);
8585

86-
Answer WatchConsoleProxyLoad(WatchConsoleProxyLoadCommand cmd);
86+
Answer watchConsoleProxyLoad(WatchConsoleProxyLoadCommand cmd);
8787

88-
Answer SavePassword(SavePasswordCommand cmd);
88+
Answer savePassword(SavePasswordCommand cmd);
8989

90-
MigrateAnswer Migrate(MigrateCommand cmd, SimulatorInfo info);
90+
MigrateAnswer migrate(MigrateCommand cmd, SimulatorInfo info);
9191

9292
PrepareForMigrationAnswer prepareForMigrate(PrepareForMigrationCommand cmd);
9393

94-
SecurityGroupRuleAnswer AddSecurityGroupRules(SecurityGroupRulesCmd cmd, SimulatorInfo info);
94+
SecurityGroupRuleAnswer addSecurityGroupRules(SecurityGroupRulesCmd cmd, SimulatorInfo info);
9595

9696
GetDomRVersionAnswer getDomRVersion(GetDomRVersionCmd cmd);
9797

9898
CheckRouterAnswer checkRouter(CheckRouterCommand cmd);
9999

100-
Answer CleanupNetworkRules(CleanupNetworkRulesCmd cmd, SimulatorInfo info);
100+
Answer cleanupNetworkRules(CleanupNetworkRulesCmd cmd, SimulatorInfo info);
101101

102102
Answer scaleVm(ScaleVmCommand cmd);
103103

plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockVmManagerImpl.java

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
import com.cloud.agent.api.RebootCommand;
5858
import com.cloud.agent.api.RevertToVMSnapshotAnswer;
5959
import com.cloud.agent.api.RevertToVMSnapshotCommand;
60+
import com.cloud.agent.api.ScaleVmAnswer;
6061
import com.cloud.agent.api.ScaleVmCommand;
6162
import com.cloud.agent.api.SecurityGroupRuleAnswer;
6263
import com.cloud.agent.api.SecurityGroupRulesCmd;
@@ -248,7 +249,7 @@ public Map<String, MockVMVO> getVms(final String hostGuid) {
248249
return vmMap;
249250
} catch (final Exception ex) {
250251
txn.rollback();
251-
throw new CloudRuntimeException("unable to fetch vms from host " + hostGuid, ex);
252+
throw new CloudRuntimeException("unable to fetch vms from host " + hostGuid, ex);
252253
} finally {
253254
txn.close();
254255
txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
@@ -292,7 +293,7 @@ public Map<String, PowerState> getVmStates(final String hostGuid) {
292293
return states;
293294
} catch (final Exception ex) {
294295
txn.rollback();
295-
throw new CloudRuntimeException("unable to fetch vms from host " + hostGuid, ex);
296+
throw new CloudRuntimeException("unable to fetch vms from host " + hostGuid, ex);
296297
} finally {
297298
txn.close();
298299
txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
@@ -369,7 +370,7 @@ public CheckSshAnswer checkSshCommand(final CheckSshCommand cmd) {
369370
}
370371

371372
@Override
372-
public MigrateAnswer Migrate(final MigrateCommand cmd, final SimulatorInfo info) {
373+
public MigrateAnswer migrate(final MigrateCommand cmd, final SimulatorInfo info) {
373374
TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
374375
try {
375376
txn.start();
@@ -382,7 +383,7 @@ public MigrateAnswer Migrate(final MigrateCommand cmd, final SimulatorInfo info)
382383

383384
final MockHost destHost = _mockHostDao.findByGuid(destGuid);
384385
if (destHost == null) {
385-
return new MigrateAnswer(cmd, false, "can;t find host:" + info.getHostUuid(), null);
386+
return new MigrateAnswer(cmd, false, "can't find destination host:" + destGuid, null);
386387
}
387388
vm.setHostId(destHost.getId());
388389
_mockVmDao.update(vm.getId(), vm);
@@ -424,7 +425,7 @@ public Answer setVmData(final VmDataCommand cmd) {
424425
}
425426

426427
@Override
427-
public Answer CleanupNetworkRules(final CleanupNetworkRulesCmd cmd, final SimulatorInfo info) {
428+
public Answer cleanupNetworkRules(final CleanupNetworkRulesCmd cmd, final SimulatorInfo info) {
428429
TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
429430
try {
430431
txn.start();
@@ -449,12 +450,34 @@ public Answer CleanupNetworkRules(final CleanupNetworkRulesCmd cmd, final Simula
449450

450451
@Override
451452
public Answer scaleVm(final ScaleVmCommand cmd) {
452-
return null; //To change body of implemented methods use File | Settings | File Templates.
453+
TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
454+
try {
455+
txn.start();
456+
final String vmName = cmd.getVmName();
457+
final MockVMVO vm = _mockVmDao.findByVmName(vmName);
458+
if (vm == null) {
459+
return new ScaleVmAnswer(cmd, false, "Can't find VM " + vmName);
460+
}
461+
vm.setCpu(cmd.getCpus() * cmd.getMaxSpeed());
462+
vm.setMemory(cmd.getMaxRam());
463+
_mockVmDao.update(vm.getId(), vm);
464+
s_logger.debug("Scaled up VM " + vmName);
465+
txn.commit();
466+
return new ScaleVmAnswer(cmd, true, null);
467+
} catch (final Exception ex) {
468+
txn.rollback();
469+
throw new CloudRuntimeException("Unable to scale up VM", ex);
470+
} finally {
471+
txn.close();
472+
txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
473+
txn.close();
474+
}
453475
}
454476

455477
@Override
456478
public Answer plugSecondaryIp(final NetworkRulesVmSecondaryIpCommand cmd) {
457-
return null; //To change body of implemented methods use File | Settings | File Templates.
479+
s_logger.debug("Plugged secondary IP to VM " + cmd.getVmName());
480+
return new Answer(cmd, true, null);
458481
}
459482

460483
@Override
@@ -527,12 +550,12 @@ public Answer getVncPort(final GetVncPortCommand cmd) {
527550
}
528551

529552
@Override
530-
public Answer CheckConsoleProxyLoad(final CheckConsoleProxyLoadCommand cmd) {
553+
public Answer checkConsoleProxyLoad(final CheckConsoleProxyLoadCommand cmd) {
531554
return Answer.createUnsupportedCommandAnswer(cmd);
532555
}
533556

534557
@Override
535-
public Answer WatchConsoleProxyLoad(final WatchConsoleProxyLoadCommand cmd) {
558+
public Answer watchConsoleProxyLoad(final WatchConsoleProxyLoadCommand cmd) {
536559
return Answer.createUnsupportedCommandAnswer(cmd);
537560
}
538561

@@ -543,7 +566,7 @@ public GetDomRVersionAnswer getDomRVersion(final GetDomRVersionCmd cmd) {
543566
}
544567

545568
@Override
546-
public SecurityGroupRuleAnswer AddSecurityGroupRules(final SecurityGroupRulesCmd cmd, final SimulatorInfo info) {
569+
public SecurityGroupRuleAnswer addSecurityGroupRules(final SecurityGroupRulesCmd cmd, final SimulatorInfo info) {
547570
if (!info.isEnabled()) {
548571
return new SecurityGroupRuleAnswer(cmd, false, "Disabled", SecurityGroupRuleAnswer.FailureReason.CANNOT_BRIDGE_FIREWALL);
549572
}
@@ -611,7 +634,7 @@ private boolean logSecurityGroupAction(final SecurityGroupRulesCmd cmd, final Te
611634
}
612635

613636
@Override
614-
public Answer SavePassword(final SavePasswordCommand cmd) {
637+
public Answer savePassword(final SavePasswordCommand cmd) {
615638
return new Answer(cmd);
616639
}
617640

plugins/hypervisors/simulator/src/com/cloud/agent/manager/SimulatorManagerImpl.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ public Answer simulate(final Command cmd, final String hostGuid) {
286286
} else if (cmd instanceof PrepareForMigrationCommand) {
287287
answer = _mockVmMgr.prepareForMigrate((PrepareForMigrationCommand)cmd);
288288
} else if (cmd instanceof MigrateCommand) {
289-
answer = _mockVmMgr.Migrate((MigrateCommand)cmd, info);
289+
answer = _mockVmMgr.migrate((MigrateCommand)cmd, info);
290290
} else if (cmd instanceof StartCommand) {
291291
answer = _mockVmMgr.startVM((StartCommand)cmd, info);
292292
} else if (cmd instanceof CheckSshCommand) {
@@ -310,7 +310,7 @@ public Answer simulate(final Command cmd, final String hostGuid) {
310310
} else if (cmd instanceof VmDataCommand) {
311311
answer = _mockVmMgr.setVmData((VmDataCommand)cmd);
312312
} else if (cmd instanceof CleanupNetworkRulesCmd) {
313-
answer = _mockVmMgr.CleanupNetworkRules((CleanupNetworkRulesCmd)cmd, info);
313+
answer = _mockVmMgr.cleanupNetworkRules((CleanupNetworkRulesCmd)cmd, info);
314314
} else if (cmd instanceof CheckNetworkCommand) {
315315
answer = _mockAgentMgr.checkNetworkCommand((CheckNetworkCommand)cmd);
316316
} else if (cmd instanceof StopCommand) {
@@ -320,13 +320,13 @@ public Answer simulate(final Command cmd, final String hostGuid) {
320320
} else if (cmd instanceof GetVncPortCommand) {
321321
answer = _mockVmMgr.getVncPort((GetVncPortCommand)cmd);
322322
} else if (cmd instanceof CheckConsoleProxyLoadCommand) {
323-
answer = _mockVmMgr.CheckConsoleProxyLoad((CheckConsoleProxyLoadCommand)cmd);
323+
answer = _mockVmMgr.checkConsoleProxyLoad((CheckConsoleProxyLoadCommand)cmd);
324324
} else if (cmd instanceof WatchConsoleProxyLoadCommand) {
325-
answer = _mockVmMgr.WatchConsoleProxyLoad((WatchConsoleProxyLoadCommand)cmd);
325+
answer = _mockVmMgr.watchConsoleProxyLoad((WatchConsoleProxyLoadCommand)cmd);
326326
} else if (cmd instanceof SecurityGroupRulesCmd) {
327-
answer = _mockVmMgr.AddSecurityGroupRules((SecurityGroupRulesCmd)cmd, info);
327+
answer = _mockVmMgr.addSecurityGroupRules((SecurityGroupRulesCmd)cmd, info);
328328
} else if (cmd instanceof SavePasswordCommand) {
329-
answer = _mockVmMgr.SavePassword((SavePasswordCommand)cmd);
329+
answer = _mockVmMgr.savePassword((SavePasswordCommand)cmd);
330330
} else if (cmd instanceof PrimaryStorageDownloadCommand) {
331331
answer = _mockStorageMgr.primaryStorageDownload((PrimaryStorageDownloadCommand)cmd);
332332
} else if (cmd instanceof CreateCommand) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1500,7 +1500,7 @@ private boolean upgradeRunningVirtualMachine(Long vmId, Long newServiceOfferingI
15001500

15011501
Account caller = CallContext.current().getCallingAccount();
15021502
VMInstanceVO vmInstance = _vmInstanceDao.findById(vmId);
1503-
if (vmInstance.getHypervisorType() != HypervisorType.XenServer && vmInstance.getHypervisorType() != HypervisorType.VMware) {
1503+
if (vmInstance.getHypervisorType() != HypervisorType.XenServer && vmInstance.getHypervisorType() != HypervisorType.VMware && vmInstance.getHypervisorType() != HypervisorType.Simulator) {
15041504
s_logger.info("Scaling the VM dynamically is not supported for VMs running on Hypervisor "+vmInstance.getHypervisorType());
15051505
throw new InvalidParameterValueException("Scaling the VM dynamically is not supported for VMs running on Hypervisor "+vmInstance.getHypervisorType());
15061506
}

0 commit comments

Comments
 (0)