diff --git a/core/src/com/cloud/storage/resource/LocalNfsSecondaryStorageResource.java b/core/src/com/cloud/storage/resource/LocalNfsSecondaryStorageResource.java index 66551ef6fa4..97320ca589a 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 diff --git a/core/src/com/cloud/storage/resource/NfsSecondaryStorageResource.java b/core/src/com/cloud/storage/resource/NfsSecondaryStorageResource.java index 7fc253c6a44..b160315314b 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"); 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 be1983e10eb..8fb898e12e1 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; @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 future = new AsyncCallFuture(); - /* - CreateCacheObjectContext context = new CreateCacheObjectContext(null, future); - AsyncCallbackDispatcher caller = AsyncCallbackDispatcher.create(this); - caller.setContext(context); - caller.setCallback(future); - */ - CopyCommandResult result = null; try { objOnCacheStore.processEvent(Event.CreateOnlyRequested);