mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
CLOUDSTACK-2584: set Format value in CopyCommand.
This commit is contained in:
parent
eb0a7489b4
commit
039098469a
@ -256,6 +256,10 @@ public class TemplateObject implements TemplateInfo {
|
||||
} catch (NoTransitionException e) {
|
||||
s_logger.debug("failed to update state", e);
|
||||
throw new CloudRuntimeException("Failed to update state" + e.toString());
|
||||
} catch (Exception ex){
|
||||
s_logger.debug("failed to process event and answer", ex);
|
||||
objectInStoreMgr.delete(this);
|
||||
throw new CloudRuntimeException("Failed to process event", ex);
|
||||
} finally{
|
||||
// in case of OperationFailed, expunge the entry
|
||||
if ( event == ObjectInDataStoreStateMachine.Event.OperationFailed){
|
||||
|
||||
@ -25,6 +25,7 @@ import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.TemplateEvent;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.TemplateState;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine.Event;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine.State;
|
||||
@ -43,6 +44,7 @@ import org.apache.log4j.Logger;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.cloud.agent.api.to.DataObjectType;
|
||||
import com.cloud.agent.api.to.S3TO;
|
||||
import com.cloud.storage.DataStoreRole;
|
||||
import com.cloud.storage.VMTemplateStoragePoolVO;
|
||||
import com.cloud.storage.dao.SnapshotDao;
|
||||
@ -136,7 +138,12 @@ public class ObjectInDataStoreManagerImpl implements ObjectInDataStoreManager {
|
||||
ts.setTemplateId(obj.getId());
|
||||
ts.setDataStoreId(dataStore.getId());
|
||||
ts.setDataStoreRole(dataStore.getRole());
|
||||
ts.setInstallPath(TemplateConstants.DEFAULT_TMPLT_ROOT_DIR + "/" + TemplateConstants.DEFAULT_TMPLT_FIRST_LEVEL_DIR + templateDao.findById(obj.getId()).getAccountId() + "/" + obj.getId());
|
||||
String installPath = TemplateConstants.DEFAULT_TMPLT_ROOT_DIR + "/" + TemplateConstants.DEFAULT_TMPLT_FIRST_LEVEL_DIR + templateDao.findById(obj.getId()).getAccountId() + "/" + obj.getId();
|
||||
if ( dataStore.getTO() instanceof S3TO ){
|
||||
TemplateInfo tmpl = (TemplateInfo)obj;
|
||||
installPath += "/" + tmpl.getUniqueName(); // for S3, we append template name in the path for template sync since we don't have template.properties there
|
||||
}
|
||||
ts.setInstallPath(installPath);
|
||||
ts.setState(ObjectInDataStoreStateMachine.State.Allocated);
|
||||
ts = templateDataStoreDao.persist(ts);
|
||||
break;
|
||||
|
||||
@ -1456,7 +1456,9 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
|
||||
if (privateTemplate == null) {
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
txn.start();
|
||||
// template_store_ref entries should have been removed using our DataObject.processEvent command in case of failure.
|
||||
// template_store_ref entries should have been removed using our DataObject.processEvent command in case of failure, but clean it up here to avoid
|
||||
// some leftovers which will cause removing template from vm_template table fail.
|
||||
this._tmplStoreDao.deletePrimaryRecordsForTemplate(templateId);
|
||||
// Remove the template_zone_ref record
|
||||
this._tmpltZoneDao.deletePrimaryRecordsForTemplate(templateId);
|
||||
// Remove the template record
|
||||
|
||||
@ -625,6 +625,31 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S
|
||||
}
|
||||
}
|
||||
|
||||
private ImageFormat getTemplateFormat(String filePath){
|
||||
String ext = null;
|
||||
int extensionPos = filePath.lastIndexOf('.');
|
||||
int lastSeparator = Math.max(filePath.lastIndexOf('/'), filePath.lastIndexOf('\\'));
|
||||
int i = lastSeparator > extensionPos ? -1 : extensionPos;
|
||||
if (i > 0 ) {
|
||||
ext = filePath.substring(i+1);
|
||||
}
|
||||
if ( ext != null){
|
||||
if ( ext.equalsIgnoreCase("vhd"))
|
||||
return ImageFormat.VHD;
|
||||
else if (ext.equalsIgnoreCase("qcow2"))
|
||||
return ImageFormat.QCOW2;
|
||||
else if (ext.equalsIgnoreCase("ova"))
|
||||
return ImageFormat.OVA;
|
||||
else if (ext.equalsIgnoreCase("tar"))
|
||||
return ImageFormat.TAR;
|
||||
else if (ext.equalsIgnoreCase("img"))
|
||||
return ImageFormat.RAW;
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
protected Answer copyFromNfsToS3(CopyCommand cmd) {
|
||||
final DataTO srcData = cmd.getSrcTO();
|
||||
final DataTO destData = cmd.getDestTO();
|
||||
@ -645,6 +670,7 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S
|
||||
|
||||
final String bucket = s3.getBucketName();
|
||||
final File srcFile = _storage.getFile(templatePath);
|
||||
ImageFormat format = this.getTemplateFormat(templatePath);
|
||||
String key = destData.getPath() + S3Utils.SEPARATOR + srcFile.getName();
|
||||
putFile(s3, srcFile, bucket, key);
|
||||
|
||||
@ -653,6 +679,7 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S
|
||||
TemplateObjectTO newTemplate = new TemplateObjectTO();
|
||||
newTemplate.setPath(key);
|
||||
newTemplate.setSize(srcFile.length());
|
||||
newTemplate.setFormat(format);
|
||||
retObj = newTemplate;
|
||||
} else if (destData.getObjectType() == DataObjectType.VOLUME) {
|
||||
VolumeObjectTO newVol = new VolumeObjectTO();
|
||||
|
||||
@ -697,9 +697,6 @@ public class DownloadManagerImpl extends ManagerBase implements DownloadManager
|
||||
} else {
|
||||
installPathPrefix = resource.getRootDir(cmd) + File.separator + installPathPrefix;
|
||||
}
|
||||
} else if (dstore instanceof S3TO) {
|
||||
// S3 key has template name inside to help template sync
|
||||
installPathPrefix = installPathPrefix + File.separator + cmd.getName();
|
||||
}
|
||||
String user = null;
|
||||
String password = null;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user