cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From raj...@apache.org
Subject [2/2] git commit: updated refs/heads/volume-upload to dd1a8da
Date Fri, 27 Feb 2015 12:14:47 GMT
volume upload: Volume entry created in DB even though GetUpload* API fails with "No ssvm present"
error

Signed-off-by: Rajani Karuturi <rajanikaruturi@gmail.com>


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/dd1a8da9
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/dd1a8da9
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/dd1a8da9

Branch: refs/heads/volume-upload
Commit: dd1a8da9775f3348bc664550270d7a0e99199e5b
Parents: da1d8f9
Author: Rajani Karuturi <rajanikaruturi@gmail.com>
Authored: Thu Feb 26 15:13:52 2015 +0530
Committer: Rajani Karuturi <rajanikaruturi@gmail.com>
Committed: Fri Feb 27 17:42:32 2015 +0530

----------------------------------------------------------------------
 .../com/cloud/storage/VolumeApiServiceImpl.java | 100 ++++++++++---------
 1 file changed, 54 insertions(+), 46 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/dd1a8da9/server/src/com/cloud/storage/VolumeApiServiceImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/storage/VolumeApiServiceImpl.java b/server/src/com/cloud/storage/VolumeApiServiceImpl.java
index 62f7710..9840096 100644
--- a/server/src/com/cloud/storage/VolumeApiServiceImpl.java
+++ b/server/src/com/cloud/storage/VolumeApiServiceImpl.java
@@ -30,6 +30,7 @@ import javax.inject.Inject;
 
 import com.cloud.utils.EncryptionUtil;
 import com.cloud.utils.ImageStoreUtil;
+import com.cloud.utils.db.TransactionCallbackWithException;
 import com.google.gson.Gson;
 import com.google.gson.GsonBuilder;
 
@@ -276,70 +277,77 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic
     }
 
     @Override
-    @DB
     @ActionEvent(eventType = EventTypes.EVENT_VOLUME_UPLOAD, eventDescription = "uploading
volume for post upload", async = true)
-    public GetUploadParamsResponse uploadVolume(GetUploadParamsForVolumeCmd cmd) throws ResourceAllocationException,
MalformedURLException {
+    public GetUploadParamsResponse uploadVolume(final GetUploadParamsForVolumeCmd cmd) throws
ResourceAllocationException, MalformedURLException {
         Account caller = CallContext.current().getCallingAccount();
         long ownerId = cmd.getEntityOwnerId();
-        Account owner = _entityMgr.findById(Account.class, ownerId);
-        Long zoneId = cmd.getZoneId();
-        String volumeName = cmd.getName();
+        final Account owner = _entityMgr.findById(Account.class, ownerId);
+        final Long zoneId = cmd.getZoneId();
+        final String volumeName = cmd.getName();
         String format = cmd.getFormat();
-        Long diskOfferingId = cmd.getDiskOfferingId();
+        final Long diskOfferingId = cmd.getDiskOfferingId();
         String imageStoreUuid = cmd.getImageStoreUuid();
-        DataStore store = _tmpltMgr.getImageStore(imageStoreUuid, zoneId);
+        final DataStore store = _tmpltMgr.getImageStore(imageStoreUuid, zoneId);
 
         validateVolume(caller, ownerId, zoneId, volumeName, null, format, diskOfferingId);
 
-        VolumeVO volume = persistVolume(owner, zoneId, volumeName, null, cmd.getFormat(),
diskOfferingId, Volume.State.NotUploaded);
-
-        VolumeInfo vol = volFactory.getVolume(volume.getId());
-
-        RegisterVolumePayload payload = new RegisterVolumePayload(null, cmd.getChecksum(),
cmd.getFormat());
-        vol.addPayload(payload);
+        return Transaction.execute(new TransactionCallbackWithException<GetUploadParamsResponse,
MalformedURLException>() {
+            @Override
+            public GetUploadParamsResponse doInTransaction(TransactionStatus status) throws
MalformedURLException {
 
-        Pair<EndPoint, DataObject> pair = volService.registerVolumeForPostUpload(vol,
store);
-        EndPoint ep = pair.first();
-        DataObject dataObject = pair.second();
+                VolumeVO volume = persistVolume(owner, zoneId, volumeName, null, cmd.getFormat(),
diskOfferingId, Volume.State.NotUploaded);
 
+                VolumeInfo vol = volFactory.getVolume(volume.getId());
 
-        GetUploadParamsResponse response = new GetUploadParamsResponse();
+                RegisterVolumePayload payload = new RegisterVolumePayload(null, cmd.getChecksum(),
cmd.getFormat());
+                vol.addPayload(payload);
 
-        String ssvmUrlDomain = _configDao.getValue(Config.SecStorageSecureCopyCert.key());
+                Pair<EndPoint, DataObject> pair = volService.registerVolumeForPostUpload(vol,
store);
+                EndPoint ep = pair.first();
+                DataObject dataObject = pair.second();
 
-        String url = ImageStoreUtil.generatePostUploadUrl(ssvmUrlDomain, ep.getPublicAddr(),
vol.getUuid());
-        response.setPostURL(new URL(url));
 
-        // set the post url, this is used in the monitoring thread to determine the SSVM
-        VolumeDataStoreVO volumeStore = _volumeStoreDao.findByVolume(volume.getId());
-        if (volumeStore != null) {
-            volumeStore.setExtractUrl(url);
-            _volumeStoreDao.persist(volumeStore);
-        }
+                GetUploadParamsResponse response = new GetUploadParamsResponse();
 
-        response.setId(UUID.fromString(vol.getUuid()));
+                String ssvmUrlDomain = _configDao.getValue(Config.SecStorageSecureCopyCert.key());
 
-        int timeout = ImageStoreUploadMonitorImpl.getUploadOperationTimeout();
-        DateTime currentDateTime = new DateTime(DateTimeZone.UTC);
-        String expires = currentDateTime.plusMinutes(timeout).toString();
-        response.setTimeout(expires);
+                String url = ImageStoreUtil.generatePostUploadUrl(ssvmUrlDomain, ep.getPublicAddr(),
vol.getUuid());
+                response.setPostURL(new URL(url));
 
-        String key = _configDao.getValue(Config.SSVMPSK.key());
-         /*
-          * encoded metadata using the post upload config key
-          */
-        TemplateOrVolumePostUploadCommand command = new TemplateOrVolumePostUploadCommand(vol.getId(),
vol.getUuid(), volumeStore.getInstallPath(), volumeStore.getChecksum(), vol
-                .getType().toString(), vol.getName(), vol.getFormat().toString(), dataObject.getDataStore().getUri(),
dataObject.getDataStore().getRole().toString());
-        command.setLocalPath(volumeStore.getLocalDownloadPath());
-        Gson gson = new GsonBuilder().create();
-        String metadata = EncryptionUtil.encodeData(gson.toJson(command), key);
-        response.setMetadata(metadata);
+                // set the post url, this is used in the monitoring thread to determine the
SSVM
+                VolumeDataStoreVO volumeStore = _volumeStoreDao.findByVolume(vol.getId());
+                if (volumeStore != null) {
+                    volumeStore.setExtractUrl(url);
+                    _volumeStoreDao.persist(volumeStore);
+                }
 
-        /*
-         * signature calculated on the url, expiry, metadata.
-         */
-        response.setSignature(EncryptionUtil.generateSignature(metadata + url + expires,
key));
-        return response;
+                response.setId(UUID.fromString(vol.getUuid()));
+
+                int timeout = ImageStoreUploadMonitorImpl.getUploadOperationTimeout();
+                DateTime currentDateTime = new DateTime(DateTimeZone.UTC);
+                String expires = currentDateTime.plusMinutes(timeout).toString();
+                response.setTimeout(expires);
+
+                String key = _configDao.getValue(Config.SSVMPSK.key());
+                 /*
+                  * encoded metadata using the post upload config key
+                  */
+                TemplateOrVolumePostUploadCommand command =
+                    new TemplateOrVolumePostUploadCommand(vol.getId(), vol.getUuid(), volumeStore.getInstallPath(),
volumeStore.getChecksum(), vol.getType().toString(),
+                                                          vol.getName(), vol.getFormat().toString(),
dataObject.getDataStore().getUri(),
+                                                          dataObject.getDataStore().getRole().toString());
+                command.setLocalPath(volumeStore.getLocalDownloadPath());
+                Gson gson = new GsonBuilder().create();
+                String metadata = EncryptionUtil.encodeData(gson.toJson(command), key);
+                response.setMetadata(metadata);
+
+                /*
+                 * signature calculated on the url, expiry, metadata.
+                 */
+                response.setSignature(EncryptionUtil.generateSignature(metadata + url + expires,
key));
+                return response;
+            }
+        });
     }
 
     private boolean validateVolume(Account caller, long ownerId, Long zoneId, String volumeName,
String url,


Mime
View raw message