mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
Invoke reatetmplt.sh script after copying template from S3 to cache
storage.
This commit is contained in:
parent
3d91a4e012
commit
f8e51f70a1
@ -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
|
||||
|
||||
@ -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");
|
||||
|
||||
@ -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);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user