cloudstack-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From miguelaferreira <...@git.apache.org>
Subject [GitHub] cloudstack pull request: Made following fixes in simulator
Date Wed, 26 Aug 2015 07:18:20 GMT
Github user miguelaferreira commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/741#discussion_r37952326
  
    --- Diff: plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockVmManagerImpl.java
---
    @@ -449,12 +450,34 @@ public Answer CleanupNetworkRules(final CleanupNetworkRulesCmd cmd,
final Simula
     
         @Override
         public Answer scaleVm(final ScaleVmCommand cmd) {
    -        return null;  //To change body of implemented methods use File | Settings | File
Templates.
    +        TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
    +        try {
    +            txn.start();
    +            final String vmName = cmd.getVmName();
    +            final MockVMVO vm = _mockVmDao.findByVmName(vmName);
    +            if (vm == null) {
    +                return new ScaleVmAnswer(cmd, false, "Can't find VM " + vmName);
    +            }
    +            vm.setCpu(cmd.getCpus() * cmd.getMaxSpeed());
    +            vm.setMemory(cmd.getMaxRam());
    +            _mockVmDao.update(vm.getId(), vm);
    +            s_logger.debug("Scaled up VM " + vmName);
    +            txn.commit();
    +            return new ScaleVmAnswer(cmd, true, null);
    +        } catch (final Exception ex) {
    +            txn.rollback();
    +            throw new CloudRuntimeException("Unable to scale up VM", ex);
    +        } finally {
    +            txn.close();
    +            txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
    --- End diff --
    
    Just out of curiosity: why do you open and immediately close a transaction in the `finally`
block of another transaction?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message