cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From raj...@apache.org
Subject git commit: updated refs/heads/volume-upload to ad6b7b3
Date Mon, 19 Jan 2015 12:34:38 GMT
Repository: cloudstack
Updated Branches:
  refs/heads/volume-upload cd02ceb7a -> ad6b7b30c


Volume upload: sending the nfsstore url in the metadata

decoding the metadata and deserialising it on receiving it


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

Branch: refs/heads/volume-upload
Commit: ad6b7b30cbbb68fd1b72dd5a2fe92143931d0220
Parents: cd02ceb
Author: Rajani Karuturi <rajanikaruturi@gmail.com>
Authored: Mon Jan 19 18:03:00 2015 +0530
Committer: Rajani Karuturi <rajanikaruturi@gmail.com>
Committed: Mon Jan 19 18:04:14 2015 +0530

----------------------------------------------------------------------
 .../TemplateOrVolumePostUploadCommand.java      | 124 +++++++++++++++++++
 .../subsystem/api/storage/VolumeService.java    |   3 +-
 .../storage/volume/VolumeServiceImpl.java       |   5 +-
 .../com/cloud/storage/VolumeApiServiceImpl.java |  21 ++--
 .../resource/NfsSecondaryStorageResource.java   |  20 ++-
 5 files changed, 158 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/ad6b7b30/core/src/org/apache/cloudstack/storage/command/TemplateOrVolumePostUploadCommand.java
----------------------------------------------------------------------
diff --git a/core/src/org/apache/cloudstack/storage/command/TemplateOrVolumePostUploadCommand.java
b/core/src/org/apache/cloudstack/storage/command/TemplateOrVolumePostUploadCommand.java
index d2a9577..78cfccb 100644
--- a/core/src/org/apache/cloudstack/storage/command/TemplateOrVolumePostUploadCommand.java
+++ b/core/src/org/apache/cloudstack/storage/command/TemplateOrVolumePostUploadCommand.java
@@ -26,6 +26,130 @@ public class TemplateOrVolumePostUploadCommand {
     DataObject dataObject;
     EndPoint endPoint;
 
+    long entityId;
+    String entityUUID;
+    String absolutePath;
+    String checksum;
+    String type;
+    String name;
+//    String installPathPrefix;
+    String localPath;
+//    String isHvm;
+    String imageFormat;
+    String dataTo;
+    String dataToRole;
+
+    public TemplateOrVolumePostUploadCommand(long entityId, String entityUUID, String absolutePath,
String checksum, String type, String name,
+                                             String localPath, String imageFormat, String
dataTo, String dataToRole) {
+        this.entityId = entityId;
+        this.entityUUID = entityUUID;
+        this.absolutePath = absolutePath;
+        this.checksum = checksum;
+        this.type = type;
+        this.name = name;
+//        this.installPathPrefix = installPathPrefix;
+        this.localPath = localPath;
+//        this.isHvm = isHvm;
+        this.imageFormat = imageFormat;
+        this.dataTo = dataTo;
+        this.dataToRole = dataToRole;
+    }
+
+    public String getDataTo() {
+        return dataTo;
+    }
+
+    public void setDataTo(String dataTo) {
+        this.dataTo = dataTo;
+    }
+
+    public String getDataToRole() {
+        return dataToRole;
+    }
+
+    public void setDataToRole(String dataToRole) {
+        this.dataToRole = dataToRole;
+    }
+    //    public String getInstallPathPrefix() {
+//        return installPathPrefix;
+//    }
+//
+//    public void setInstallPathPrefix(String installPathPrefix) {
+//        this.installPathPrefix = installPathPrefix;
+//    }
+
+    public String getLocalPath() {
+        return localPath;
+    }
+
+    public void setLocalPath(String localPath) {
+        this.localPath = localPath;
+    }
+
+//    public String getIsHvm() {
+//        return isHvm;
+//    }
+
+//    public void setIsHvm(String isHvm) {
+//        this.isHvm = isHvm;
+//    }
+
+    public String getImageFormat() {
+        return imageFormat;
+    }
+
+    public void setImageFormat(String imageFormat) {
+        this.imageFormat = imageFormat;
+    }
+
+    public long getEntityId() {
+        return entityId;
+    }
+
+    public void setEntityId(long entityId) {
+        this.entityId = entityId;
+    }
+
+    public String getEntityUUID() {
+        return entityUUID;
+    }
+
+    public void setEntityUUID(String entityUUID) {
+        this.entityUUID = entityUUID;
+    }
+
+    public String getAbsolutePath() {
+        return absolutePath;
+    }
+
+    public void setAbsolutePath(String absolutePath) {
+        this.absolutePath = absolutePath;
+    }
+
+    public String getChecksum() {
+        return checksum;
+    }
+
+    public void setChecksum(String checksum) {
+        this.checksum = checksum;
+    }
+
+    public String getType() {
+        return type;
+    }
+
+    public void setType(String type) {
+        this.type = type;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
     public TemplateOrVolumePostUploadCommand(DataObject dataObject, EndPoint endPoint) {
         this.dataObject = dataObject;
         this.endPoint = endPoint;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/ad6b7b30/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/VolumeService.java
----------------------------------------------------------------------
diff --git a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/VolumeService.java
b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/VolumeService.java
index d9a75cc..21f269f 100644
--- a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/VolumeService.java
+++ b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/VolumeService.java
@@ -20,6 +20,7 @@ package org.apache.cloudstack.engine.subsystem.api.storage;
 
 import java.util.Map;
 
+import com.cloud.utils.Pair;
 import org.apache.cloudstack.engine.cloud.entity.api.VolumeEntity;
 import org.apache.cloudstack.framework.async.AsyncCallFuture;
 import org.apache.cloudstack.storage.command.CommandResult;
@@ -94,7 +95,7 @@ public interface VolumeService {
 
     AsyncCallFuture<VolumeApiResult> registerVolume(VolumeInfo volume, DataStore store);
 
-    public EndPoint registerVolumeForPostUpload(VolumeInfo volume, DataStore store);
+    public Pair<EndPoint,DataObject> registerVolumeForPostUpload(VolumeInfo volume,
DataStore store);
 
     AsyncCallFuture<VolumeApiResult> resize(VolumeInfo volume);
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/ad6b7b30/engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java
----------------------------------------------------------------------
diff --git a/engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java
b/engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java
index 5d23ffe..0d6aa56 100644
--- a/engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java
+++ b/engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java
@@ -27,6 +27,7 @@ import java.util.Map;
 import javax.inject.Inject;
 
 import com.cloud.storage.RegisterVolumePayload;
+import com.cloud.utils.Pair;
 import org.apache.cloudstack.engine.cloud.entity.api.VolumeEntity;
 import org.apache.cloudstack.engine.subsystem.api.storage.ChapInfo;
 import org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult;
@@ -1224,7 +1225,7 @@ public class VolumeServiceImpl implements VolumeService {
     }
 
     @Override
-    public EndPoint registerVolumeForPostUpload(VolumeInfo volume, DataStore store) {
+    public Pair<EndPoint,DataObject> registerVolumeForPostUpload(VolumeInfo volume,
DataStore store) {
         DataObject volumeOnStore = store.create(volume);
 
         volumeOnStore.processEvent(Event.CreateOnlyRequested);
@@ -1234,7 +1235,7 @@ public class VolumeServiceImpl implements VolumeService {
             s_logger.warn("There is no secondary storage VM for image store " + store.getName());
             return null;
         }
-        return ep;
+        return new Pair<>(ep,volumeOnStore);
     }
 
     protected Void registerVolumeCallback(AsyncCallbackDispatcher<VolumeServiceImpl, CreateCmdResult>
callback, CreateVolumeContext<VolumeApiResult> context) {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/ad6b7b30/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 29ac7f1..0512d4f 100644
--- a/server/src/com/cloud/storage/VolumeApiServiceImpl.java
+++ b/server/src/com/cloud/storage/VolumeApiServiceImpl.java
@@ -34,9 +34,9 @@ import com.google.gson.GsonBuilder;
 
 import org.apache.cloudstack.api.command.user.volume.GetUploadParamsForVolumeCmd;
 import org.apache.cloudstack.api.response.GetUploadParamsResponse;
+import org.apache.cloudstack.engine.subsystem.api.storage.DataObject;
 import org.apache.cloudstack.engine.subsystem.api.storage.EndPoint;
 import org.apache.cloudstack.storage.command.TemplateOrVolumePostUploadCommand;
-import org.apache.cloudstack.storage.command.TemplateOrVolumePostUploadCommandTypeAdapter;
 import org.apache.log4j.Logger;
 import org.apache.cloudstack.api.command.user.volume.AttachVolumeCmd;
 import org.apache.cloudstack.api.command.user.volume.CreateVolumeCmd;
@@ -297,21 +297,23 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic
         RegisterVolumePayload payload = new RegisterVolumePayload(null, cmd.getChecksum(),
cmd.getFormat());
         vol.addPayload(payload);
 
-        EndPoint ep = volService.registerVolumeForPostUpload(vol, store);
+        Pair<EndPoint, DataObject> pair = volService.registerVolumeForPostUpload(vol,
store);
+        EndPoint ep = pair.first();
+        DataObject dataObject = pair.second();
 
-        TemplateOrVolumePostUploadCommand command = new TemplateOrVolumePostUploadCommand(vol,
ep);
 
         GetUploadParamsResponse response = new GetUploadParamsResponse();
-        String url = "https://" + command.getEndPoint().getPublicAddr() + "/upload/" + command.getDataObject().getUuid();
+        String url = "https://" + ep.getPublicAddr() + "/upload/" + 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);
         }
 
-        response.setId(UUID.fromString(command.getDataObject().getUuid()));
+        response.setId(UUID.fromString(vol.getUuid()));
 
         /*
          * TODO: hardcoding the timeout to current + 60 min for now. This needs to goto the
database
@@ -323,10 +325,15 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic
 
         String key = _configDao.getValue(Config.SSVMPSK.key());
          /*
-          * encoded metadata using the post upload config ssh key
+          * encoded metadata using the post upload config key
           */
 
-        Gson gson = new GsonBuilder().registerTypeAdapter(TemplateOrVolumePostUploadCommand.class,
new TemplateOrVolumePostUploadCommandTypeAdapter()).create();
+
+        TemplateOrVolumePostUploadCommand command =
+            new TemplateOrVolumePostUploadCommand(vol.getId(), vol.getUuid(), volumeStore.getInstallPath(),
volumeStore.getChecksum(), vol.getType().toString(), vol.getName(),
+                                                  volumeStore.getLocalDownloadPath(), vol.getFormat().toString(),
dataObject.getDataStore().getUri(),
+                                                  dataObject.getDataStore().getRole().toString());
+        Gson gson = new GsonBuilder().create();
         String jsonPayload = gson.toJson(command);
         response.setMetadata(EncryptionUtil.encodeData(jsonPayload, key));
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/ad6b7b30/services/secondary-storage/server/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java
----------------------------------------------------------------------
diff --git a/services/secondary-storage/server/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java
b/services/secondary-storage/server/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java
index fd27678..348dac7 100755
--- a/services/secondary-storage/server/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java
+++ b/services/secondary-storage/server/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java
@@ -52,6 +52,10 @@ import java.util.UUID;
 
 import javax.naming.ConfigurationException;
 
+import com.cloud.utils.EncryptionUtil;
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import org.apache.cloudstack.storage.command.TemplateOrVolumePostUploadCommand;
 import org.apache.cloudstack.storage.template.UploadEntity;
 import org.apache.commons.codec.digest.DigestUtils;
 import org.apache.commons.httpclient.HttpStatus;
@@ -183,6 +187,7 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements
S
 
     private static final String TEMPLATE_ROOT_DIR = "template/tmpl";
     private static final String VOLUME_ROOT_DIR = "volumes";
+    private static final String POST_UPLOAD_KEY_LOCATION = "/etc/cloudstack/agent/ms-psk";
 
     int _timeout;
 
@@ -1401,7 +1406,7 @@ public class NfsSecondaryStorageResource extends ServerResourceBase
implements S
 
     private void savePostUploadPSK(String psk) {
         try {
-            FileUtils.writeStringToFile(new File("/etc/cloudstack/agent/ms-psk"),psk, "utf-8");
+            FileUtils.writeStringToFile(new File(POST_UPLOAD_KEY_LOCATION),psk, "utf-8");
         } catch (IOException ex) {
             s_logger.debug("Failed to copy PSK to the file.", ex);
         }
@@ -2725,13 +2730,18 @@ public class NfsSecondaryStorageResource extends ServerResourceBase
implements S
 
             InputStream inputStream = new ByteArrayInputStream(data);
             ByteArrayOutputStream output = new ByteArrayOutputStream();
-            HashMap<String, String> paramsMap = new HashMap<>();
+            HashMap<String, String> params = new HashMap<>();
 
-            parsePostBody(inputStream, output, paramsMap);
+            parsePostBody(inputStream, output, params);
+            String encodedMetadata = params.get("metadata");
+            String key = FileUtils.readFileToString(new File(POST_UPLOAD_KEY_LOCATION), "utf-8");
+            String metadata = EncryptionUtil.decodeData(encodedMetadata, key);
+
+            Gson gson = new GsonBuilder().create();
+            TemplateOrVolumePostUploadCommand cmd = gson.fromJson(metadata, TemplateOrVolumePostUploadCommand.class);
 
             //call handle upload method.
-            //TODO: get entityid, absolute path from metadata and filename from post data
-            handleuplod(1, null, "file", output.size(), output.toByteArray());
+            handleuplod(cmd.getEntityId(), cmd.getAbsolutePath(), cmd.getName(), output.size(),
output.toByteArray());
 
             s_logger.error(new String(data));
 


Mime
View raw message