cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mc...@apache.org
Subject [3/6] git commit: updated refs/heads/object_store to 1bd216f
Date Sun, 12 May 2013 04:06:27 GMT
Invoke reatetmplt.sh script after copying template from S3 to cache
storage.

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

Branch: refs/heads/object_store
Commit: f8e51f70a14d1d7d263b07c8a99ca666fbc8a9a5
Parents: 3d91a4e
Author: Min Chen <min.chen@citrix.com>
Authored: Sat May 11 18:19:29 2013 -0700
Committer: Min Chen <min.chen@citrix.com>
Committed: Sat May 11 18:19:29 2013 -0700

----------------------------------------------------------------------
 .../resource/LocalNfsSecondaryStorageResource.java |    1 +
 .../resource/NfsSecondaryStorageResource.java      |   55 ++++++++++++++-
 .../cache/manager/StorageCacheManagerImpl.java     |   10 +--
 3 files changed, 56 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/f8e51f70/core/src/com/cloud/storage/resource/LocalNfsSecondaryStorageResource.java
----------------------------------------------------------------------
diff --git a/core/src/com/cloud/storage/resource/LocalNfsSecondaryStorageResource.java b/core/src/com/cloud/storage/resource/LocalNfsSecondaryStorageResource.java
index 66551ef..97320ca 100644
--- a/core/src/com/cloud/storage/resource/LocalNfsSecondaryStorageResource.java
+++ b/core/src/com/cloud/storage/resource/LocalNfsSecondaryStorageResource.java
@@ -46,6 +46,7 @@ public class LocalNfsSecondaryStorageResource extends
         ((DownloadManagerImpl)_dlMgr).setThreadPool(Executors.newFixedThreadPool(10));
         _storage = new JavaStorageLayer();
         this._inSystemVM = false;
+        System.setProperty("paths.script", "/Users/minc/dev/cloud-asf"); //This is just for
my testing, not for QA build
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/f8e51f70/core/src/com/cloud/storage/resource/NfsSecondaryStorageResource.java
----------------------------------------------------------------------
diff --git a/core/src/com/cloud/storage/resource/NfsSecondaryStorageResource.java b/core/src/com/cloud/storage/resource/NfsSecondaryStorageResource.java
index 7fc253c..b160315 100755
--- a/core/src/com/cloud/storage/resource/NfsSecondaryStorageResource.java
+++ b/core/src/com/cloud/storage/resource/NfsSecondaryStorageResource.java
@@ -55,6 +55,7 @@ import org.apache.cloudstack.storage.command.DownloadProgressCommand;
 import org.apache.cloudstack.storage.command.DownloadCommand.ResourceType;
 import org.apache.cloudstack.storage.to.SnapshotObjectTO;
 import org.apache.cloudstack.storage.to.TemplateObjectTO;
+import org.apache.cloudstack.storage.to.VolumeObjectTO;
 import org.apache.commons.lang.StringUtils;
 import org.apache.log4j.Logger;
 
@@ -237,7 +238,8 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements
S
 
         try {
 
-            final File downloadDirectory = _storage.getFile(determineStorageTemplatePath(storagePath,
destPath));
+            String downloadPath = determineStorageTemplatePath(storagePath, destPath);
+            final File downloadDirectory = _storage.getFile(downloadPath);
             downloadDirectory.mkdirs();
 
             if (!downloadDirectory.exists()) {
@@ -267,12 +269,59 @@ public class NfsSecondaryStorageResource extends ServerResourceBase
implements S
                 return new CopyCmdAnswer("Can't find template");
             }
 
+            // do post processing to unzip the file if it is compressed
+            String scriptsDir = "scripts/storage/secondary";
+            String createTmpltScr = Script.findScript(scriptsDir, "createtmplt.sh");
+            if (createTmpltScr == null) {
+                throw new ConfigurationException("Unable to find createtmplt.sh");
+            }
+            s_logger.info("createtmplt.sh found in " + createTmpltScr);
+            String createVolScr = Script.findScript(scriptsDir, "createvolume.sh");
+            if (createVolScr == null) {
+                throw new ConfigurationException("Unable to find createvolume.sh");
+            }
+            s_logger.info("createvolume.sh found in " + createVolScr);
+            String script = srcData.getObjectType() == DataObjectType.TEMPLATE ? createTmpltScr
: createVolScr;
+
+            int installTimeoutPerGig = 180 * 60 * 1000;
+            int imgSizeGigs = (int) Math.ceil(destFile.length() * 1.0d / (1024 * 1024 * 1024));
+            imgSizeGigs++; // add one just in case
+            long timeout = imgSizeGigs * installTimeoutPerGig;
+
+            String origPath = destFile.getAbsolutePath();
+            String extension = null;
+            if ( srcData.getObjectType() == DataObjectType.TEMPLATE){
+                extension = ((TemplateObjectTO)srcData).getFormat().getFileExtension();
+            } else{
+                extension = ((VolumeObjectTO)srcData).getDiskType().toString().toLowerCase();
+            }
+
+            String templateName = UUID.randomUUID().toString();
+            String templateFilename = templateName + "." + extension;
+            Script scr = new Script(script, timeout, s_logger);
+            scr.add("-s", Integer.toString(imgSizeGigs)); // not used for now
+            scr.add("-n", templateFilename);
+
+            scr.add("-t", downloadPath);
+            scr.add("-f", origPath); // this is the temporary
+                                                      // template file downloaded
+            String result;
+            result = scr.execute();
+
+            if (result != null) {
+                // script execution failure
+                throw new CloudRuntimeException("Failed to run script " + script);
+            }
+
+            String finalFileName = templateFilename;
+            String finalDownloadPath = destPath + File.separator + templateFilename;
+
             DataTO newDestTO = null;
 
             if (destData.getObjectType() == DataObjectType.TEMPLATE) {
                 TemplateObjectTO newTemplTO = new TemplateObjectTO();
-                newTemplTO.setPath(destPath + File.separator + destFile.getName());
-                newTemplTO.setName(destFile.getName());
+                newTemplTO.setPath(finalDownloadPath);
+                newTemplTO.setName(finalFileName);
                 newDestTO = newTemplTO;
             } else {
                 return new CopyCmdAnswer("not implemented yet");

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/f8e51f70/engine/storage/cache/src/org/apache/cloudstack/storage/cache/manager/StorageCacheManagerImpl.java
----------------------------------------------------------------------
diff --git a/engine/storage/cache/src/org/apache/cloudstack/storage/cache/manager/StorageCacheManagerImpl.java
b/engine/storage/cache/src/org/apache/cloudstack/storage/cache/manager/StorageCacheManagerImpl.java
index be1983e..8fb898e 100644
--- a/engine/storage/cache/src/org/apache/cloudstack/storage/cache/manager/StorageCacheManagerImpl.java
+++ b/engine/storage/cache/src/org/apache/cloudstack/storage/cache/manager/StorageCacheManagerImpl.java
@@ -39,6 +39,7 @@ import org.apache.cloudstack.framework.async.AsyncRpcConext;
 import org.apache.cloudstack.storage.cache.allocator.StorageCacheAllocator;
 import org.apache.cloudstack.storage.command.CommandResult;
 import org.apache.cloudstack.storage.command.CopyCmdAnswer;
+import org.apache.cloudstack.storage.datastore.ObjectInDataStoreManager;
 import org.apache.log4j.Logger;
 
 import com.cloud.utils.component.Manager;
@@ -50,6 +51,7 @@ public class StorageCacheManagerImpl implements StorageCacheManager, Manager
{
     List<StorageCacheAllocator> storageCacheAllocator;
     @Inject
     DataMotionService dataMotionSvr;
+
     @Override
     public DataStore getCacheStorage(Scope scope) {
         for (StorageCacheAllocator allocator : storageCacheAllocator) {
@@ -131,16 +133,10 @@ public class StorageCacheManagerImpl implements StorageCacheManager,
Manager {
 	@Override
 	public DataObject createCacheObject(DataObject data, Scope scope) {
 		DataStore cacheStore = this.getCacheStorage(scope);
+		//TODO: consider multiple thread to create
 		DataObject objOnCacheStore = cacheStore.create(data);
 
 		AsyncCallFuture<CopyCommandResult> future = new AsyncCallFuture<CopyCommandResult>();
-		/*
-		CreateCacheObjectContext<CopyCommandResult> context = new CreateCacheObjectContext<CopyCommandResult>(null,
future);
-		AsyncCallbackDispatcher<StorageCacheManagerImpl, CopyCommandResult> caller = AsyncCallbackDispatcher.create(this);
-		caller.setContext(context);
-		caller.setCallback(future);
-		*/
-
 		CopyCommandResult result = null;
 		try {
 		    objOnCacheStore.processEvent(Event.CreateOnlyRequested);


Mime
View raw message