You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ed...@apache.org on 2012/08/21 03:16:43 UTC
[1/3] git commit: refactor attach/detach iso
Updated Branches:
refs/heads/storagerefactor 63c3634b7 -> 7d6938ba2
refactor attach/detach iso
Project: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/commit/7d6938ba
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/7d6938ba
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/7d6938ba
Branch: refs/heads/storagerefactor
Commit: 7d6938ba2fe0c66d6f3232e0430603026f2d3c24
Parents: 63c3634
Author: Edison Su <su...@gmail.com>
Authored: Mon Aug 20 18:16:04 2012 -0700
Committer: Edison Su <su...@gmail.com>
Committed: Mon Aug 20 18:16:04 2012 -0700
----------------------------------------------------------------------
api/src/com/cloud/api/BaseCmd.java | 5 +-
api/src/com/cloud/api/commands/AttachIsoCmd.java | 2 +-
.../storage/orchestra/StorageOrchestraEngine.java | 2 +
.../orchestra/StorageOrchestraEngineImpl.java | 56 +-
.../cloud/storage/pool/StoragePoolManagerImpl.java | 13 +-
.../com/cloud/storage/volume/VolumeManager.java | 28 +-
.../cloud/storage/volume/VolumeManagerImpl.java | 2603 +++++++--------
server/src/com/cloud/template/TemplateManager.java | 5 +
.../com/cloud/template/TemplateManagerImpl.java | 163 +-
9 files changed, 1418 insertions(+), 1459 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7d6938ba/api/src/com/cloud/api/BaseCmd.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/BaseCmd.java b/api/src/com/cloud/api/BaseCmd.java
index 52cbbdd..a3ad4a6 100755
--- a/api/src/com/cloud/api/BaseCmd.java
+++ b/api/src/com/cloud/api/BaseCmd.java
@@ -55,6 +55,7 @@ import com.cloud.projects.ProjectService;
import com.cloud.resource.ResourceService;
import com.cloud.server.ManagementService;
import com.cloud.server.TaggedResourceService;
+import com.cloud.storage.orchestra.StorageOrchestraEngine;
import com.cloud.storage.pool.StoragePoolService;
import com.cloud.storage.snapshot.SnapshotService;
import com.cloud.template.TemplateService;
@@ -117,7 +118,6 @@ public abstract class BaseCmd {
public static StoragePoolService _storageService;
public static ResourceService _resourceService;
public static NetworkService _networkService;
- public static TemplateService _templateService;
public static SecurityGroupService _securityGroupService;
public static SnapshotService _snapshotService;
public static ConsoleProxyService _consoleProxyService;
@@ -138,6 +138,7 @@ public abstract class BaseCmd {
public static VpcService _vpcService;
public static NetworkACLService _networkACLService;
public static Site2SiteVpnService _s2sVpnService;
+ public static StorageOrchestraEngine _storageEngine;
static void setComponents(ResponseGenerator generator) {
ComponentLocator locator = ComponentLocator.getLocator(ManagementService.Name);
@@ -148,7 +149,6 @@ public abstract class BaseCmd {
_storageService = locator.getManager(StoragePoolService.class);
_resourceService = locator.getManager(ResourceService.class);
_networkService = locator.getManager(NetworkService.class);
- _templateService = locator.getManager(TemplateService.class);
_securityGroupService = locator.getManager(SecurityGroupService.class);
_snapshotService = locator.getManager(SnapshotService.class);
_consoleProxyService = locator.getManager(ConsoleProxyService.class);
@@ -169,6 +169,7 @@ public abstract class BaseCmd {
_vpcService = locator.getManager(VpcService.class);
_networkACLService = locator.getManager(NetworkACLService.class);
_s2sVpnService = locator.getManager(Site2SiteVpnService.class);
+ _storageEngine = locator.getManager(StorageOrchestraEngine.class);
}
public abstract void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException;
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7d6938ba/api/src/com/cloud/api/commands/AttachIsoCmd.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/commands/AttachIsoCmd.java b/api/src/com/cloud/api/commands/AttachIsoCmd.java
index 75f2ac7..ea8a526 100755
--- a/api/src/com/cloud/api/commands/AttachIsoCmd.java
+++ b/api/src/com/cloud/api/commands/AttachIsoCmd.java
@@ -95,7 +95,7 @@ public class AttachIsoCmd extends BaseAsyncCmd {
@Override
public void execute(){
UserContext.current().setEventDetails("Vm Id: " +getVirtualMachineId()+ " ISO Id: "+getId());
- boolean result = _templateService.attachIso(id, virtualMachineId);
+ boolean result = _storageEngine.attachIsoToVm(id, virtualMachineId);
if (result) {
UserVm userVm = _responseGenerator.findUserVmById(virtualMachineId);
if (userVm != null) {
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7d6938ba/server/src/com/cloud/storage/orchestra/StorageOrchestraEngine.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/storage/orchestra/StorageOrchestraEngine.java b/server/src/com/cloud/storage/orchestra/StorageOrchestraEngine.java
index 001d1d1..31b0ad9 100644
--- a/server/src/com/cloud/storage/orchestra/StorageOrchestraEngine.java
+++ b/server/src/com/cloud/storage/orchestra/StorageOrchestraEngine.java
@@ -35,4 +35,6 @@ public interface StorageOrchestraEngine {
VolumeVO allocVolume(CreateVolumeCmd cmd)
throws ResourceAllocationException;
Volume attachVolumeToVM(AttachVolumeCmd command);
+ boolean attachIsoToVm(long isoId, long vmId);
+ boolean detachIsoToVm(long vmId);
}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7d6938ba/server/src/com/cloud/storage/orchestra/StorageOrchestraEngineImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/storage/orchestra/StorageOrchestraEngineImpl.java b/server/src/com/cloud/storage/orchestra/StorageOrchestraEngineImpl.java
index 78b2fcf..d759228 100644
--- a/server/src/com/cloud/storage/orchestra/StorageOrchestraEngineImpl.java
+++ b/server/src/com/cloud/storage/orchestra/StorageOrchestraEngineImpl.java
@@ -12,6 +12,7 @@ import javax.naming.ConfigurationException;
import org.apache.log4j.Logger;
import com.cloud.agent.api.Answer;
+import com.cloud.agent.api.AttachIsoCommand;
import com.cloud.agent.api.AttachVolumeAnswer;
import com.cloud.agent.api.AttachVolumeCommand;
import com.cloud.agent.api.CreateVolumeFromSnapshotAnswer;
@@ -48,6 +49,7 @@ import com.cloud.exception.PermissionDeniedException;
import com.cloud.exception.ResourceAllocationException;
import com.cloud.exception.StorageUnavailableException;
import com.cloud.host.HostVO;
+import com.cloud.hypervisor.Hypervisor;
import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.org.Grouping;
import com.cloud.resource.ResourceManager;
@@ -63,11 +65,13 @@ import com.cloud.storage.VMTemplateStorageResourceAssoc.Status;
import com.cloud.storage.dao.DiskOfferingDao;
import com.cloud.storage.dao.SnapshotDao;
import com.cloud.storage.dao.StoragePoolDao;
+import com.cloud.storage.dao.VMTemplateDao;
import com.cloud.storage.dao.VolumeDao;
import com.cloud.storage.pool.Storage;
import com.cloud.storage.pool.StoragePool;
import com.cloud.storage.pool.Storage.ImageFormat;
import com.cloud.storage.pool.Storage.StoragePoolType;
+import com.cloud.storage.pool.Storage.TemplateType;
import com.cloud.storage.pool.StoragePoolManager;
import com.cloud.storage.snapshot.Snapshot;
import com.cloud.storage.snapshot.SnapshotManager;
@@ -83,6 +87,7 @@ import com.cloud.user.AccountManager;
import com.cloud.user.ResourceLimitService;
import com.cloud.user.UserContext;
import com.cloud.user.dao.AccountDao;
+import com.cloud.uservm.UserVm;
import com.cloud.utils.NumbersUtil;
import com.cloud.utils.Pair;
import com.cloud.utils.component.Inject;
@@ -127,6 +132,8 @@ public class StorageOrchestraEngineImpl implements StorageOrchestraEngine, Manag
protected UsageEventDao _usageEventDao;
@Inject
protected UserVmDao _userVmDao;
+ @Inject
+ protected VMTemplateDao _templateDao;
@@ -530,5 +537,52 @@ public class StorageOrchestraEngineImpl implements StorageOrchestraEngine, Manag
return _volumeMgr.attachVolumeToVM(volume, vm, deviceId);
}
-
+
+ @Override
+ @ActionEvent(eventType = EventTypes.EVENT_ISO_ATTACH, eventDescription = "attaching ISO", async = true)
+ public boolean attachIsoToVm(long isoId, long vmId) {
+ Account caller = UserContext.current().getCaller();
+ Long userId = UserContext.current().getCallerUserId();
+
+ UserVmVO vm = _userVmDao.findById(vmId);
+ if (vm == null) {
+ throw new InvalidParameterValueException("Unable to find a virtual machine with id " + vmId);
+ }
+
+ VMTemplateVO iso = _templateDao.findById(isoId);
+ if (iso == null || iso.getRemoved() != null) {
+ throw new InvalidParameterValueException("Unable to find an ISO with id " + isoId);
+ }
+
+ _accountMgr.checkAccess(caller, null, false, iso, vm);
+
+ Account vmOwner = _accountDao.findById(vm.getAccountId());
+ _accountMgr.checkAccess(vmOwner, null, false, iso, vm);
+
+ _volumeMgr.attachISOToVm(vm, iso);
+ return true;
+ }
+
+ @Override
+ @ActionEvent(eventType = EventTypes.EVENT_ISO_DETACH, eventDescription = "detaching ISO", async = true)
+ public boolean detachIsoToVm(long vmId) {
+ Account caller = UserContext.current().getCaller();
+ Long userId = UserContext.current().getCallerUserId();
+
+ UserVmVO vm = _userVmDao.findById(vmId);
+ if (vm == null) {
+ throw new InvalidParameterValueException ("Unable to find a virtual machine with id " + vmId);
+ }
+
+ Long isoId = vm.getIsoId();
+ if (isoId == null) {
+ throw new InvalidParameterValueException("The specified VM has no ISO attached to it.");
+ }
+
+ _accountMgr.checkAccess(caller, null, true, vm);
+ UserContext.current().setEventDetails("Vm Id: " + vmId + " ISO Id: " + isoId);
+
+ _volumeMgr.detachISOToVM(vm);
+ return true;
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7d6938ba/server/src/com/cloud/storage/pool/StoragePoolManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/storage/pool/StoragePoolManagerImpl.java b/server/src/com/cloud/storage/pool/StoragePoolManagerImpl.java
index 40e68e4..be9989d 100755
--- a/server/src/com/cloud/storage/pool/StoragePoolManagerImpl.java
+++ b/server/src/com/cloud/storage/pool/StoragePoolManagerImpl.java
@@ -1933,10 +1933,7 @@ public class StoragePoolManagerImpl implements StoragePoolManager, Manager, Clus
}
}
- protected DiskProfile toDiskProfile(VolumeVO vol, DiskOfferingVO offering) {
- return new DiskProfile(vol.getId(), vol.getVolumeType(), vol.getName(), offering.getId(), vol.getSize(), offering.getTagsArray(), offering.getUseLocalStorage(), offering.isRecreatable(),
- vol.getTemplateId());
- }
+
@Override
@@ -2288,12 +2285,4 @@ public class StoragePoolManagerImpl implements StoragePoolManager, Manager, Clus
StoragePool pool = _storagePoolDao.findById(id);
return pool;
}
-
- @Override
- public boolean PrepareTemplateOnPool(VMTemplateVO template, StoragePool pool) {
-
- }
-
- @O
-
}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7d6938ba/server/src/com/cloud/storage/volume/VolumeManager.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/storage/volume/VolumeManager.java b/server/src/com/cloud/storage/volume/VolumeManager.java
index 64ced09..432e389 100644
--- a/server/src/com/cloud/storage/volume/VolumeManager.java
+++ b/server/src/com/cloud/storage/volume/VolumeManager.java
@@ -8,8 +8,10 @@ import com.cloud.api.commands.ListVolumesCmd;
import com.cloud.dc.DataCenterVO;
import com.cloud.dc.HostPodVO;
import com.cloud.deploy.DeployDestination;
+import com.cloud.exception.AgentUnavailableException;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InsufficientStorageCapacityException;
+import com.cloud.exception.OperationTimedoutException;
import com.cloud.exception.ResourceAllocationException;
import com.cloud.exception.StorageUnavailableException;
import com.cloud.hypervisor.Hypervisor.HypervisorType;
@@ -31,13 +33,6 @@ import com.cloud.vm.VirtualMachine;
import com.cloud.vm.VirtualMachineProfile;
public interface VolumeManager {
- /** Returns the absolute path of the specified ISO
- * @param templateId - the ID of the template that represents the ISO
- * @param datacenterId
- * @return absolute ISO path
- */
- public Pair<String, String> getAbsoluteIsoPath(long templateId, long dataCenterId);
-
/**
* Moves a volume from its current storage pool to a storage pool with enough capacity in the specified zone, pod, or cluster
* @param volume
@@ -102,9 +97,6 @@ public interface VolumeManager {
List<Pair<DiskOfferingVO, Long>> dataDiskOfferings, Long templateId, Account owner);
void cleanupVolumes(long vmId) throws ConcurrentOperationException;
- boolean StorageMigration(
- VirtualMachineProfile<? extends VirtualMachine> vm,
- StoragePool destPool) throws ConcurrentOperationException;
boolean processEvent(Volume vol, Event event)
throws NoTransitionException;
@@ -123,14 +115,6 @@ public interface VolumeManager {
String getVmNameOnVolume(VolumeVO volume);
void expungeVolume(VolumeVO vol, boolean force);
- Volume migrateVolume(Long volumeId, Long storagePoolId)
- throws ConcurrentOperationException;
-
- void prepare(VirtualMachineProfile<? extends VirtualMachine> vm,
- DeployDestination dest, boolean recreate)
- throws StorageUnavailableException,
- InsufficientStorageCapacityException;
-
Volume copyVolume(Long volumeId, Long destStoragePoolId);
List<VolumeVO> searchForVolumes(ListVolumesCmd cmd);
@@ -138,5 +122,11 @@ public interface VolumeManager {
VolumeVO allocateDiskVolume(String volumeName, long zoneId, long ownerId,
long domainId, long diskOfferingId, long size);
- Volume attachVolumeToVM(VolumeVO volume, UserVmVO vm, Long deviceId);
+ Volume attachVolumeToVM(VolumeVO volume, UserVmVO vm, Long deviceId) throws StorageUnavailableException, ConcurrentOperationException, AgentUnavailableException, OperationTimedoutException;
+
+ boolean deleteVolume(long volumeId) throws ConcurrentOperationException;
+
+ void attachISOToVm(UserVmVO vm, VMTemplateVO iso);
+
+ void detachISOToVM(UserVmVO vm);
}