Fix size issue in copying template from S3 to cache storage to make

system vm up.
This commit is contained in:
Min Chen 2013-05-15 18:54:55 -07:00
parent d5050d3157
commit b66c484905
5 changed files with 12 additions and 5 deletions

View File

@ -263,7 +263,7 @@ public class TemplateDataStoreVO implements StateObject<ObjectInDataStoreStateMa
return tid.hashCode()+hid.hashCode();
}
public void setSize(long size) {
public void setSize(Long size) {
this.size = size;
}

View File

@ -349,7 +349,7 @@ public class TemplateServiceImpl implements TemplateService {
tmpltStore.setPhysicalSize(tmpltInfo.getPhysicalSize());
tmpltStore.setDataStoreRole(store.getRole());
_vmTemplateStoreDao.persist(tmpltStore);
// update size in vm_template table
VMTemplateVO tmlpt = _templateDao.findById(tmplt.getId());
tmlpt.setSize(tmpltInfo.getSize());
@ -613,7 +613,7 @@ public class TemplateServiceImpl implements TemplateService {
TemplateDataStoreVO tmpltStore = _vmTemplateStoreDao.findByStoreTemplate(storeId, tmplt.getId());
if ( tmpltStore == null ) {
tmpltStore = new TemplateDataStoreVO(storeId, tmplt.getId(), new Date(), 100, Status.DOWNLOADED, null, null, null, TemplateConstants.DEFAULT_SYSTEM_VM_TEMPLATE_PATH + tmplt.getId() + File.separator, tmplt.getUrl());
tmpltStore.setSize(0);
tmpltStore.setSize(0L);
tmpltStore.setPhysicalSize(0); // no size information for pre-seeded system vm templates
tmpltStore.setDataStoreRole(store.getRole());
_vmTemplateStoreDao.persist(tmpltStore);

View File

@ -359,6 +359,7 @@ public class VolumeServiceImpl implements VolumeService {
try {
templateOnPrimaryStoreObj.processEvent(Event.CreateOnlyRequested);
} catch (Exception e) {
s_logger.info("Got exception in case of multi-thread");
try {
templateOnPrimaryStoreObj = waitForTemplateDownloaded(dataStore, template);
} catch(Exception e1) {

View File

@ -50,6 +50,7 @@ import com.cloud.agent.api.StartupSecondaryStorageCommand;
import com.cloud.agent.api.StopAnswer;
import com.cloud.agent.api.check.CheckSshAnswer;
import com.cloud.agent.api.check.CheckSshCommand;
import com.cloud.agent.api.to.NfsTO;
import com.cloud.agent.api.to.NicTO;
import com.cloud.agent.api.to.VirtualMachineTO;
import com.cloud.agent.manager.Commands;
@ -293,6 +294,8 @@ public class SecondaryStorageManagerImpl extends ManagerBase implements Secondar
List<DataStore> ssStores = this._dataStoreMgr.getImageStoresByScope(new ZoneScope(zoneId));
for( DataStore ssStore : ssStores ) {
if (!(ssStore.getTO() instanceof NfsTO ))
continue; // only do this for Nfs
String secUrl = ssStore.getUri();
SecStorageSetupCommand setupCmd = null;
if (!_useSSlCopy) {

View File

@ -224,7 +224,7 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S
return Answer.createUnsupportedCommandAnswer(cmd);
}
}
protected Answer copyFromS3ToNfs(CopyCommand cmd, DataTO srcData, S3TO s3, DataTO destData, NfsTO destImageStore) {
final String storagePath = destImageStore.getUrl();
final String destPath = destData.getPath();
@ -308,6 +308,8 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S
String finalFileName = templateFilename;
String finalDownloadPath = destPath + File.separator + templateFilename;
// compute the size of
long size = this._storage.getSize(downloadPath + File.separator + templateFilename);
DataTO newDestTO = null;
@ -315,6 +317,7 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S
TemplateObjectTO newTemplTO = new TemplateObjectTO();
newTemplTO.setPath(finalDownloadPath);
newTemplTO.setName(finalFileName);
newTemplTO.setSize(size);
newDestTO = newTemplTO;
} else {
return new CopyCmdAnswer("not implemented yet");
@ -355,7 +358,7 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S
command.add("-n", templateName);
command.add("-t", destPath);
String result = command.execute();
if (result != null && !result.equalsIgnoreCase("")) {
return new CopyCmdAnswer(result);
}