Repository: cloudstack Updated Branches: refs/heads/hotfix/broken-simulator [created] 972ff0ce2
Commit 05d056bb broke the simulator run, fixed by excluding the simulator from the new check Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/972ff0ce Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/972ff0ce Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/972ff0ce Branch: refs/heads/hotfix/broken-simulator Commit: 972ff0ce20ce7d68dcf03d1922c14a00d76dbfd4 Parents: e4d6cd8 Author: Hugo Trippaers <htrippa...@schubergphilis.com> Authored: Tue Aug 5 09:14:16 2014 +0200 Committer: Hugo Trippaers <htrippa...@schubergphilis.com> Committed: Tue Aug 5 09:14:16 2014 +0200 ---------------------------------------------------------------------- server/src/com/cloud/vm/UserVmManagerImpl.java | 254 ++++++++++---------- 1 file changed, 128 insertions(+), 126 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/972ff0ce/server/src/com/cloud/vm/UserVmManagerImpl.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java b/server/src/com/cloud/vm/UserVmManagerImpl.java index 05cc183..b51e8ac 100755 --- a/server/src/com/cloud/vm/UserVmManagerImpl.java +++ b/server/src/com/cloud/vm/UserVmManagerImpl.java @@ -35,6 +35,9 @@ import javax.ejb.Local; import javax.inject.Inject; import javax.naming.ConfigurationException; +import org.apache.commons.codec.binary.Base64; +import org.apache.log4j.Logger; + import org.apache.cloudstack.acl.ControlledEntity.ACLType; import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.affinity.AffinityGroupService; @@ -84,8 +87,6 @@ import org.apache.cloudstack.storage.command.DeleteCommand; import org.apache.cloudstack.storage.command.DettachCommand; import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao; import org.apache.cloudstack.storage.datastore.db.StoragePoolVO; -import org.apache.commons.codec.binary.Base64; -import org.apache.log4j.Logger; import com.cloud.agent.AgentManager; import com.cloud.agent.api.Answer; @@ -1013,10 +1014,10 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir } if (caller.getType() != Account.ACCOUNT_TYPE_ADMIN) { - if (!(network.getGuestType() == Network.GuestType.Shared && network.getAclType() == ACLType.Domain) - && !(network.getAclType() == ACLType.Account && network.getAccountId() == vmInstance.getAccountId())) { - throw new InvalidParameterValueException("only shared network or isolated network with the same account_id can be added to vmId: " + vmId); - } + if (!(network.getGuestType() == Network.GuestType.Shared && network.getAclType() == ACLType.Domain) + && !(network.getAclType() == ACLType.Account && network.getAccountId() == vmInstance.getAccountId())) { + throw new InvalidParameterValueException("only shared network or isolated network with the same account_id can be added to vmId: " + vmId); + } } List<NicVO> allNics = _nicDao.listByVmId(vmInstance.getId()); @@ -1255,7 +1256,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir @Override @ActionEvent(eventType = EventTypes.EVENT_VM_UPGRADE, eventDescription = "Upgrading VM", async = true) public UserVm upgradeVirtualMachine(ScaleVMCmd cmd) throws ResourceUnavailableException, ConcurrentOperationException, ManagementServerException, - VirtualMachineMigrationException { + VirtualMachineMigrationException { Long vmId = cmd.getId(); Long newServiceOfferingId = cmd.getServiceOfferingId(); @@ -1315,7 +1316,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir @Override public boolean upgradeVirtualMachine(Long vmId, Long newServiceOfferingId, Map<String, String> customParameters) throws ResourceUnavailableException, - ConcurrentOperationException, ManagementServerException, VirtualMachineMigrationException { + ConcurrentOperationException, ManagementServerException, VirtualMachineMigrationException { // Verify input parameters VMInstanceVO vmInstance = _vmInstanceDao.findById(vmId); @@ -1331,7 +1332,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir } private boolean upgradeRunningVirtualMachine(Long vmId, Long newServiceOfferingId, Map<String, String> customParameters) throws ResourceUnavailableException, - ConcurrentOperationException, ManagementServerException, VirtualMachineMigrationException { + ConcurrentOperationException, ManagementServerException, VirtualMachineMigrationException { Account caller = CallContext.current().getCallingAccount(); VMInstanceVO vmInstance = _vmInstanceDao.findById(vmId); @@ -1386,7 +1387,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir // Check zone wide flag boolean enableDynamicallyScaleVm = EnableDynamicallyScaleVm.valueIn(vmInstance.getDataCenterId()); if (!enableDynamicallyScaleVm) { - throw new PermissionDeniedException("Dynamically scaling virtual machines is disabled for this zone, please contact your admin"); + throw new PermissionDeniedException("Dynamically scaling virtual machines is disabled for this zone, please contact your admin"); } // Check vm flag @@ -1574,49 +1575,49 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir Account account = _accountDao.lockRow(vm.getAccountId(), true); - // if the account is deleted, throw error - if (account.getRemoved() != null) { + // if the account is deleted, throw error + if (account.getRemoved() != null) { throw new CloudRuntimeException("Unable to recover VM as the account is deleted"); - } + } - // Get serviceOffering for Virtual Machine + // Get serviceOffering for Virtual Machine ServiceOfferingVO serviceOffering = _serviceOfferingDao.findById(vm.getId(), vm.getServiceOfferingId()); - // First check that the maximum number of UserVMs, CPU and Memory limit for the given - // accountId will not be exceeded + // First check that the maximum number of UserVMs, CPU and Memory limit for the given + // accountId will not be exceeded resourceLimitCheck(account, vm.isDisplayVm(), new Long(serviceOffering.getCpu()), new Long(serviceOffering.getRamSize())); - _haMgr.cancelDestroy(vm, vm.getHostId()); + _haMgr.cancelDestroy(vm, vm.getHostId()); - try { + try { if (!_itMgr.stateTransitTo(vm, VirtualMachine.Event.RecoveryRequested, null)) { s_logger.debug("Unable to recover the vm because it is not in the correct state: " + vmId); throw new InvalidParameterValueException("Unable to recover the vm because it is not in the correct state: " + vmId); - } - } catch (NoTransitionException e) { + } + } catch (NoTransitionException e) { throw new InvalidParameterValueException("Unable to recover the vm because it is not in the correct state: " + vmId); - } + } - // Recover the VM's disks - List<VolumeVO> volumes = _volsDao.findByInstance(vmId); - for (VolumeVO volume : volumes) { - if (volume.getVolumeType().equals(Volume.Type.ROOT)) { - // Create an event - Long templateId = volume.getTemplateId(); - Long diskOfferingId = volume.getDiskOfferingId(); - Long offeringId = null; - if (diskOfferingId != null) { + // Recover the VM's disks + List<VolumeVO> volumes = _volsDao.findByInstance(vmId); + for (VolumeVO volume : volumes) { + if (volume.getVolumeType().equals(Volume.Type.ROOT)) { + // Create an event + Long templateId = volume.getTemplateId(); + Long diskOfferingId = volume.getDiskOfferingId(); + Long offeringId = null; + if (diskOfferingId != null) { DiskOfferingVO offering = _diskOfferingDao.findById(diskOfferingId); if (offering != null && (offering.getType() == DiskOfferingVO.Type.Disk)) { - offeringId = offering.getId(); + offeringId = offering.getId(); + } + } + UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VOLUME_CREATE, volume.getAccountId(), volume.getDataCenterId(), volume.getId(), volume.getName(), + offeringId, templateId, volume.getSize(), Volume.class.getName(), volume.getUuid(), volume.isDisplayVolume()); } } - UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VOLUME_CREATE, volume.getAccountId(), volume.getDataCenterId(), volume.getId(), volume.getName(), - offeringId, templateId, volume.getSize(), Volume.class.getName(), volume.getUuid(), volume.isDisplayVolume()); - } - } - //Update Resource Count for the given account + //Update Resource Count for the given account resourceCountIncrement(account.getId(), vm.isDisplayVm(), new Long(serviceOffering.getCpu()), new Long(serviceOffering.getRamSize())); } }); @@ -1669,7 +1670,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir String value = _configDao.getValue(Config.SetVmInternalNameUsingDisplayName.key()); _instanceNameFlag = (value == null) ? false : Boolean.parseBoolean(value); - _scaleRetry = NumbersUtil.parseInt(configs.get(Config.ScaleRetry.key()), 2); + _scaleRetry = NumbersUtil.parseInt(configs.get(Config.ScaleRetry.key()), 2); s_logger.info("User VM Manager is configured."); @@ -2072,25 +2073,25 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir List<? extends Nic> nics = _nicDao.listByVmId(vm.getId()); if (nics == null || nics.isEmpty()) { - s_logger.error("unable to find any nics for vm " + vm.getUuid()); - return false; + s_logger.error("unable to find any nics for vm " + vm.getUuid()); + return false; } for (Nic nic : nics) { - Network network = _networkDao.findById(nic.getNetworkId()); + Network network = _networkDao.findById(nic.getNetworkId()); NicProfile nicProfile = new NicProfile(nic, network, null, null, null, _networkModel.isSecurityGroupSupportedInNetwork(network), _networkModel.getNetworkTag( template.getHypervisorType(), network)); - VirtualMachineProfile vmProfile = new VirtualMachineProfileImpl(vm); + VirtualMachineProfile vmProfile = new VirtualMachineProfileImpl(vm); - UserDataServiceProvider element = _networkModel.getUserDataUpdateProvider(network); - if (element == null) { - throw new CloudRuntimeException("Can't find network element for " + Service.UserData.getName() + " provider needed for UserData update"); - } - boolean result = element.saveUserData(network, nicProfile, vmProfile); - if (!result) { - s_logger.error("Failed to update userdata for vm " + vm + " and nic " + nic); - } + UserDataServiceProvider element = _networkModel.getUserDataUpdateProvider(network); + if (element == null) { + throw new CloudRuntimeException("Can't find network element for " + Service.UserData.getName() + " provider needed for UserData update"); + } + boolean result = element.saveUserData(network, nicProfile, vmProfile); + if (!result) { + s_logger.error("Failed to update userdata for vm " + vm + " and nic " + nic); + } } return true; @@ -2255,26 +2256,26 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir Transaction.execute(new TransactionCallbackNoReturn() { @Override public void doInTransactionWithoutResult(TransactionStatus status) { - // don't let the group be deleted when we are assigning vm to - // it. + // don't let the group be deleted when we are assigning vm to + // it. InstanceGroupVO ngrpLock = _vmGroupDao.lockRow(groupFinal.getId(), false); - if (ngrpLock == null) { + if (ngrpLock == null) { s_logger.warn("Failed to acquire lock on vm group id=" + groupFinal.getId() + " name=" + groupFinal.getName()); throw new CloudRuntimeException("Failed to acquire lock on vm group id=" + groupFinal.getId() + " name=" + groupFinal.getName()); - } + } - // Currently don't allow to assign a vm to more than one group - if (_groupVMMapDao.listByInstanceId(userVmId) != null) { - // Delete all mappings from group_vm_map table + // Currently don't allow to assign a vm to more than one group + if (_groupVMMapDao.listByInstanceId(userVmId) != null) { + // Delete all mappings from group_vm_map table List<InstanceGroupVMMapVO> groupVmMaps = _groupVMMapDao.listByInstanceId(userVmId); - for (InstanceGroupVMMapVO groupMap : groupVmMaps) { + for (InstanceGroupVMMapVO groupMap : groupVmMaps) { SearchCriteria<InstanceGroupVMMapVO> sc = _groupVMMapDao.createSearchCriteria(); sc.addAnd("instanceId", SearchCriteria.Op.EQ, groupMap.getInstanceId()); - _groupVMMapDao.expunge(sc); - } - } + _groupVMMapDao.expunge(sc); + } + } InstanceGroupVMMapVO groupVmMapVO = new InstanceGroupVMMapVO(groupFinal.getId(), userVmId); - _groupVMMapDao.persist(groupVmMapVO); + _groupVMMapDao.persist(groupVmMapVO); } }); @@ -2522,7 +2523,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir List<NetworkOfferingVO> requiredOfferings = _networkOfferingDao.listByAvailability(Availability.Required, false); if (requiredOfferings.size() < 1) { throw new InvalidParameterValueException("Unable to find network offering with availability=" + Availability.Required - + " to automatically create the network as a part of vm creation"); + + " to automatically create the network as a part of vm creation"); } if (requiredOfferings.get(0).getState() == NetworkOffering.State.Enabled) { @@ -2716,8 +2717,9 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir } } + // Special case for simulator as we need to be able to simulator other types of hypervisors HypervisorType hypervisorType = null; - if (template.getHypervisorType() == null || template.getHypervisorType() == HypervisorType.None) { + if (template.getHypervisorType() == null || template.getHypervisorType() == HypervisorType.None || hypervisor == HypervisorType.Simulator) { hypervisorType = hypervisor; } else { if (hypervisor != null && hypervisor != HypervisorType.None && hypervisor != template.getHypervisorType()) { @@ -2802,10 +2804,10 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir //relax the check if the caller is admin account if (caller.getType() != Account.ACCOUNT_TYPE_ADMIN) { - if (!(network.getGuestType() == Network.GuestType.Shared && network.getAclType() == ACLType.Domain) - && !(network.getAclType() == ACLType.Account && network.getAccountId() == accountId)) { - throw new InvalidParameterValueException("only shared network or isolated network with the same account_id can be added to vm"); - } + if (!(network.getGuestType() == Network.GuestType.Shared && network.getAclType() == ACLType.Domain) + && !(network.getAclType() == ACLType.Account && network.getAccountId() == accountId)) { + throw new InvalidParameterValueException("only shared network or isolated network with the same account_id can be added to vm"); + } } IpAddresses requestedIpPair = null; @@ -3150,7 +3152,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir } protected UserVm startVirtualMachine(DeployVMCmd cmd, Map<VirtualMachineProfile.Param, Object> additonalParams, String deploymentPlannerToUse) throws ResourceUnavailableException, - InsufficientCapacityException, ConcurrentOperationException { + InsufficientCapacityException, ConcurrentOperationException { long vmId = cmd.getEntityId(); Long hostId = cmd.getHostId(); @@ -3235,7 +3237,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir diskstats = _vmDiskStatsDao.findBy(userVm.getAccountId(), userVm.getDataCenterId(), userVm.getId(), volume.getId()); if (diskstats == null) { diskstats = new VmDiskStatisticsVO(userVm.getAccountId(), userVm.getDataCenterId(), userVm.getId(), volume.getId()); - _vmDiskStatsDao.persist(diskstats); + _vmDiskStatsDao.persist(diskstats); } } @@ -3292,7 +3294,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir } } } - } + } } boolean ipChanged = false; if (originalIp != null && !originalIp.equalsIgnoreCase(returnedIp)) { @@ -3358,9 +3360,9 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir VirtualMachineEntity vmEntity = _orchSrvc.getVirtualMachine(vm.getUuid()); status = vmEntity.stop(Long.toString(userId)); if (status) { - return _vmDao.findById(vmId); + return _vmDao.findById(vmId); } else { - return null; + return null; } } catch (ResourceUnavailableException e) { throw new CloudRuntimeException("Unable to contact the agent to stop the virtual machine " + vm, e); @@ -3475,9 +3477,9 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir if (template.getEnablePassword()) { if (vm.getDetail("password") != null) { password = DBEncryptionUtil.decrypt(vm.getDetail("password")); - } else { + } else { password = _mgr.generateRandomPassword(); - } + } } if (!validPassword(password)) { @@ -3641,8 +3643,8 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir if (previousVmDiskStats != null && ((previousVmDiskStats.getCurrentIORead() != vmDiskStat_lock.getCurrentIORead()) || ((previousVmDiskStats.getCurrentIOWrite() != vmDiskStat_lock - .getCurrentIOWrite()) - || (previousVmDiskStats.getCurrentBytesRead() != vmDiskStat_lock.getCurrentBytesRead()) || (previousVmDiskStats + .getCurrentIOWrite()) + || (previousVmDiskStats.getCurrentBytesRead() != vmDiskStat_lock.getCurrentBytesRead()) || (previousVmDiskStats .getCurrentBytesWrite() != vmDiskStat_lock.getCurrentBytesWrite())))) { s_logger.debug("vm disk stats changed from the time GetVmDiskStatsCommand was sent. " + "Ignoring current answer. Host: " + host.getName() + " . VM: " + vmDiskStat.getVmName() + " IO Read: " + vmDiskStat.getIORead() + " IO Write: " + vmDiskStat.getIOWrite() + " Bytes Read: " @@ -3756,7 +3758,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir @Override public UserVm createVirtualMachine(DeployVMCmd cmd) throws InsufficientCapacityException, ResourceUnavailableException, ConcurrentOperationException, - StorageUnavailableException, ResourceAllocationException { + StorageUnavailableException, ResourceAllocationException { // TODO Auto-generated method stub return null; } @@ -3800,7 +3802,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir HypervisorType destHypervisorType = destPool.getHypervisor(); if (destHypervisorType == null) { destHypervisorType = _clusterDao.findById( - destPool.getClusterId()).getHypervisorType(); + destPool.getClusterId()).getHypervisorType(); } if (vm.getHypervisorType() != destHypervisorType) { @@ -3832,7 +3834,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir @Override @ActionEvent(eventType = EventTypes.EVENT_VM_MIGRATE, eventDescription = "migrating VM", async = true) public VirtualMachine migrateVirtualMachine(Long vmId, Host destinationHost) throws ResourceUnavailableException, ConcurrentOperationException, ManagementServerException, - VirtualMachineMigrationException { + VirtualMachineMigrationException { // access check - only root admin can migrate VM Account caller = CallContext.current().getCallingAccount(); if (!_accountMgr.isRootAdmin(caller.getId())) { @@ -3885,7 +3887,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir // check if host is UP if (destinationHost.getState() != com.cloud.host.Status.Up || destinationHost.getResourceState() != ResourceState.Enabled) { throw new InvalidParameterValueException("Cannot migrate VM, destination host is not in correct state, has status: " + destinationHost.getState() + ", state: " - + destinationHost.getResourceState()); + + destinationHost.getResourceState()); } if (vm.getType() != VirtualMachine.Type.User) { @@ -3901,7 +3903,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir checkHostsDedication(vm, srcHostId, destinationHost.getId()); - // call to core process + // call to core process DataCenterVO dcVO = _dcDao.findById(destinationHost.getDataCenterId()); HostPodVO pod = _podDao.findById(destinationHost.getPodId()); Cluster cluster = _clusterDao.findById(destinationHost.getClusterId()); @@ -3915,7 +3917,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir + " already has max Running VMs(count includes system VMs), cannot migrate to this host"); } throw new VirtualMachineMigrationException("Destination host, hostId: " + destinationHost.getId() - + " already has max Running VMs(count includes system VMs), cannot migrate to this host"); + + " already has max Running VMs(count includes system VMs), cannot migrate to this host"); } UserVmVO uservm = _vmDao.findById(vmId); @@ -3925,7 +3927,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir _itMgr.migrate(vm.getUuid(), srcHostId, dest); VMInstanceVO vmInstance = _vmInstanceDao.findById(vmId); if (vmInstance.getType().equals(VirtualMachine.Type.User)) { - return _vmDao.findById(vmId); + return _vmDao.findById(vmId); } else { return vmInstance; } @@ -4147,7 +4149,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir @Override @ActionEvent(eventType = EventTypes.EVENT_VM_MIGRATE, eventDescription = "migrating VM", async = true) public VirtualMachine migrateVirtualMachineWithVolume(Long vmId, Host destinationHost, Map<String, String> volumeToPool) throws ResourceUnavailableException, - ConcurrentOperationException, ManagementServerException, VirtualMachineMigrationException { + ConcurrentOperationException, ManagementServerException, VirtualMachineMigrationException { // Access check - only root administrator can migrate VM. Account caller = CallContext.current().getCallingAccount(); if (!_accountMgr.isRootAdmin(caller.getId())) { @@ -4377,42 +4379,42 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir Transaction.execute(new TransactionCallbackNoReturn() { @Override public void doInTransactionWithoutResult(TransactionStatus status) { - //generate destroy vm event for usage + //generate destroy vm event for usage UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VM_DESTROY, vm.getAccountId(), vm.getDataCenterId(), vm.getId(), vm.getHostName(), vm.getServiceOfferingId(), vm.getTemplateId(), vm.getHypervisorType().toString(), VirtualMachine.class.getName(), vm.getUuid(), vm.isDisplayVm()); - // update resource counts for old account + // update resource counts for old account resourceCountDecrement(oldAccount.getAccountId(), vm.isDisplayVm(), new Long(offering.getCpu()), new Long(offering.getRamSize())); - // OWNERSHIP STEP 1: update the vm owner - vm.setAccountId(newAccount.getAccountId()); - vm.setDomainId(cmd.getDomainId()); - _vmDao.persist(vm); + // OWNERSHIP STEP 1: update the vm owner + vm.setAccountId(newAccount.getAccountId()); + vm.setDomainId(cmd.getDomainId()); + _vmDao.persist(vm); + + // OS 2: update volume + for (VolumeVO volume : volumes) { + UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VOLUME_DELETE, volume.getAccountId(), volume.getDataCenterId(), volume.getId(), volume.getName(), + Volume.class.getName(), volume.getUuid(), volume.isDisplayVolume()); + _resourceLimitMgr.decrementResourceCount(oldAccount.getAccountId(), ResourceType.volume); + _resourceLimitMgr.decrementResourceCount(oldAccount.getAccountId(), ResourceType.primary_storage, new Long(volume.getSize())); + volume.setAccountId(newAccount.getAccountId()); + volume.setDomainId(newAccount.getDomainId()); + _volsDao.persist(volume); + _resourceLimitMgr.incrementResourceCount(newAccount.getAccountId(), ResourceType.volume); + _resourceLimitMgr.incrementResourceCount(newAccount.getAccountId(), ResourceType.primary_storage, new Long(volume.getSize())); + UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VOLUME_CREATE, volume.getAccountId(), volume.getDataCenterId(), volume.getId(), volume.getName(), + volume.getDiskOfferingId(), volume.getTemplateId(), volume.getSize(), Volume.class.getName(), volume.getUuid(), volume.isDisplayVolume()); + //snapshots: mark these removed in db + List<SnapshotVO> snapshots = _snapshotDao.listByVolumeIdIncludingRemoved(volume.getId()); + for (SnapshotVO snapshot : snapshots) { + _snapshotDao.remove(snapshot.getId()); + } + } - // OS 2: update volume - for (VolumeVO volume : volumes) { - UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VOLUME_DELETE, volume.getAccountId(), volume.getDataCenterId(), volume.getId(), volume.getName(), - Volume.class.getName(), volume.getUuid(), volume.isDisplayVolume()); - _resourceLimitMgr.decrementResourceCount(oldAccount.getAccountId(), ResourceType.volume); - _resourceLimitMgr.decrementResourceCount(oldAccount.getAccountId(), ResourceType.primary_storage, new Long(volume.getSize())); - volume.setAccountId(newAccount.getAccountId()); - volume.setDomainId(newAccount.getDomainId()); - _volsDao.persist(volume); - _resourceLimitMgr.incrementResourceCount(newAccount.getAccountId(), ResourceType.volume); - _resourceLimitMgr.incrementResourceCount(newAccount.getAccountId(), ResourceType.primary_storage, new Long(volume.getSize())); - UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VOLUME_CREATE, volume.getAccountId(), volume.getDataCenterId(), volume.getId(), volume.getName(), - volume.getDiskOfferingId(), volume.getTemplateId(), volume.getSize(), Volume.class.getName(), volume.getUuid(), volume.isDisplayVolume()); - //snapshots: mark these removed in db - List<SnapshotVO> snapshots = _snapshotDao.listByVolumeIdIncludingRemoved(volume.getId()); - for (SnapshotVO snapshot : snapshots) { - _snapshotDao.remove(snapshot.getId()); - } - } - - //update resource count of new account + //update resource count of new account resourceCountIncrement(newAccount.getAccountId(), vm.isDisplayVm(), new Long(offering.getCpu()), new Long(offering.getRamSize())); - //generate usage events to account for this change + //generate usage events to account for this change UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VM_CREATE, vm.getAccountId(), vm.getDataCenterId(), vm.getId(), vm.getHostName(), vm.getServiceOfferingId(), vm.getTemplateId(), vm.getHypervisorType().toString(), VirtualMachine.class.getName(), vm.getUuid(), vm.isDisplayVm()); } @@ -4533,7 +4535,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir List<NetworkOfferingVO> requiredOfferings = _networkOfferingDao.listByAvailability(Availability.Required, false); if (requiredOfferings.size() < 1) { throw new InvalidParameterValueException("Unable to find network offering with availability=" + Availability.Required - + " to automatically create the network as a part of vm creation"); + + " to automatically create the network as a part of vm creation"); } if (requiredOfferings.get(0).getState() == NetworkOffering.State.Enabled) { // get Virtual networks @@ -4577,7 +4579,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir defaultNetwork = _networkDao.findById(newNetwork.getId()); } else if (virtualNetworks.size() > 1) { throw new InvalidParameterValueException("More than 1 default Isolated networks are found " + "for account " + newAccount - + "; please specify networkIds"); + + "; please specify networkIds"); } else { defaultNetwork = _networkDao.findById(virtualNetworks.get(0).getId()); } @@ -4665,7 +4667,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir Long templateId = root.getTemplateId(); boolean isISO = false; if (templateId == null) { - // Assuming that for a vm deployed using ISO, template ID is set to NULL + // Assuming that for a vm deployed using ISO, template ID is set to NULL isISO = true; templateId = vm.getIsoId(); } @@ -4724,10 +4726,10 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir vm.setTemplateId(newTemplateId); _vmDao.update(vmId, vm); } else { - newVol = volumeMgr.allocateDuplicateVolume(root, newTemplateId); - vm.setGuestOSId(template.getGuestOSId()); - vm.setTemplateId(newTemplateId); - _vmDao.update(vmId, vm); + newVol = volumeMgr.allocateDuplicateVolume(root, newTemplateId); + vm.setGuestOSId(template.getGuestOSId()); + vm.setTemplateId(newTemplateId); + _vmDao.update(vmId, vm); } } else { newVol = volumeMgr.allocateDuplicateVolume(root, null); @@ -4751,15 +4753,15 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir if (vm.getHypervisorType() == HypervisorType.VMware) { VolumeInfo volumeInStorage = volFactory.getVolume(root.getId()); if (volumeInStorage != null) { - s_logger.info("Expunging volume " + root.getId() + " from primary data store"); - AsyncCallFuture<VolumeApiResult> future = _volService.expungeVolumeAsync(volFactory.getVolume(root.getId())); - try { - future.get(); - } catch (Exception e) { - s_logger.debug("Failed to expunge volume:" + root.getId(), e); + s_logger.info("Expunging volume " + root.getId() + " from primary data store"); + AsyncCallFuture<VolumeApiResult> future = _volService.expungeVolumeAsync(volFactory.getVolume(root.getId())); + try { + future.get(); + } catch (Exception e) { + s_logger.debug("Failed to expunge volume:" + root.getId(), e); + } } } - } Map<VirtualMachineProfile.Param, Object> params = null; String password = null;