mirror of https://github.com/apache/cloudstack.git
CLOUDSTACK-3419: [Object_Store_Refactor] Uploaded volume is being
deleted while attaching it to guest VM.
This commit is contained in:
parent
f604e3d9cc
commit
08e722ddae
|
|
@ -653,7 +653,7 @@ public class VolumeServiceImpl implements VolumeService {
|
|||
|
||||
srcVolume.processEvent(Event.OperationSuccessed);
|
||||
destVolume.processEvent(Event.OperationSuccessed, result.getAnswer());
|
||||
srcVolume.getDataStore().delete(srcVolume);
|
||||
// srcVolume.getDataStore().delete(srcVolume);
|
||||
future.complete(res);
|
||||
} catch (Exception e) {
|
||||
res.setResult(e.toString());
|
||||
|
|
|
|||
|
|
@ -284,7 +284,11 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S
|
|||
newTemplTO.setSize(size);
|
||||
newDestTO = newTemplTO;
|
||||
} else {
|
||||
return new CopyCmdAnswer("not implemented yet");
|
||||
VolumeObjectTO newVolTO = new VolumeObjectTO();
|
||||
newVolTO.setPath(finalDownloadPath);
|
||||
newVolTO.setName(finalFileName);
|
||||
newVolTO.setSize(size);
|
||||
newDestTO = newVolTO;
|
||||
}
|
||||
|
||||
return new CopyCmdAnswer(newDestTO);
|
||||
|
|
@ -324,11 +328,11 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S
|
|||
|
||||
File destFile = S3Utils.getFile(s3, s3.getBucketName(), srcData.getPath(), downloadDirectory,
|
||||
new FileNamingStrategy() {
|
||||
@Override
|
||||
public String determineFileName(final String key) {
|
||||
return substringAfterLast(key, S3Utils.SEPARATOR);
|
||||
}
|
||||
});
|
||||
@Override
|
||||
public String determineFileName(final String key) {
|
||||
return substringAfterLast(key, S3Utils.SEPARATOR);
|
||||
}
|
||||
});
|
||||
|
||||
if (destFile == null) {
|
||||
return new CopyCmdAnswer("Can't find template");
|
||||
|
|
@ -684,10 +688,10 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S
|
|||
|
||||
DownloadAnswer answer = new DownloadAnswer(null, 100, null, VMTemplateStorageResourceAssoc.Status.DOWNLOADED,
|
||||
swiftPath, swiftPath, file.length(), file.length(), md5sum
|
||||
);
|
||||
);
|
||||
return answer;
|
||||
} catch (Exception e) {
|
||||
s_logger.debug("Failed to register template into swift", e);
|
||||
s_logger.debug("Failed to register template into swift", e);
|
||||
return new DownloadAnswer(e.toString(), VMTemplateStorageResourceAssoc.Status.DOWNLOAD_ERROR);
|
||||
} finally {
|
||||
if (file != null) {
|
||||
|
|
@ -745,16 +749,17 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S
|
|||
ext = filePath.substring(i + 1);
|
||||
}
|
||||
if (ext != null) {
|
||||
if (ext.equalsIgnoreCase("vhd"))
|
||||
if (ext.equalsIgnoreCase("vhd")) {
|
||||
return ImageFormat.VHD;
|
||||
else if (ext.equalsIgnoreCase("qcow2"))
|
||||
} else if (ext.equalsIgnoreCase("qcow2")) {
|
||||
return ImageFormat.QCOW2;
|
||||
else if (ext.equalsIgnoreCase("ova"))
|
||||
} else if (ext.equalsIgnoreCase("ova")) {
|
||||
return ImageFormat.OVA;
|
||||
else if (ext.equalsIgnoreCase("tar"))
|
||||
} else if (ext.equalsIgnoreCase("tar")) {
|
||||
return ImageFormat.TAR;
|
||||
else if (ext.equalsIgnoreCase("img"))
|
||||
} else if (ext.equalsIgnoreCase("img")) {
|
||||
return ImageFormat.RAW;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
|
|
@ -1016,16 +1021,16 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S
|
|||
} else if (dstore instanceof SwiftTO) {
|
||||
String path = cmd.getDirectory();
|
||||
String volumeId = StringUtils.substringAfterLast(path, "/"); // assuming
|
||||
// that
|
||||
// the
|
||||
// filename
|
||||
// is
|
||||
// the
|
||||
// last
|
||||
// section
|
||||
// in
|
||||
// the
|
||||
// path
|
||||
// that
|
||||
// the
|
||||
// filename
|
||||
// is
|
||||
// the
|
||||
// last
|
||||
// section
|
||||
// in
|
||||
// the
|
||||
// path
|
||||
String result = swiftDelete((SwiftTO) dstore, "V-" + volumeId.toString(), "");
|
||||
if (result != null) {
|
||||
String errMsg = "failed to delete snapshot for volume " + volumeId + " , err=" + result;
|
||||
|
|
@ -1066,12 +1071,12 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S
|
|||
final File targetFile = S3Utils.getFile(s3, s3.getBucketName(), key,
|
||||
_storage.getFile(directoryName), new FileNamingStrategy() {
|
||||
|
||||
@Override
|
||||
public String determineFileName(String key) {
|
||||
return snapshotFileName;
|
||||
}
|
||||
@Override
|
||||
public String determineFileName(String key) {
|
||||
return snapshotFileName;
|
||||
}
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
if (cmd.getParent() != null) {
|
||||
|
||||
|
|
@ -1220,8 +1225,9 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S
|
|||
return new Answer(cmd, false, checksum);
|
||||
} finally {
|
||||
try {
|
||||
if (is != null)
|
||||
if (is != null) {
|
||||
is.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Could not close the file " + absoluteTemplatePath);
|
||||
|
|
@ -1334,24 +1340,24 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S
|
|||
final String result = executeWithNoWaitLock(determineSnapshotLockId(accountId, volumeId),
|
||||
new Callable<String>() {
|
||||
|
||||
@Override
|
||||
public String call() throws Exception {
|
||||
@Override
|
||||
public String call() throws Exception {
|
||||
|
||||
if (deleteAllFlag) {
|
||||
S3Utils.deleteDirectory(s3, bucket, determineSnapshotS3Directory(accountId, volumeId));
|
||||
} else {
|
||||
S3Utils.deleteObject(
|
||||
s3,
|
||||
bucket,
|
||||
determineSnapshotS3Key(accountId, volumeId,
|
||||
determineSnapshotBackupFilename(name)));
|
||||
}
|
||||
if (deleteAllFlag) {
|
||||
S3Utils.deleteDirectory(s3, bucket, determineSnapshotS3Directory(accountId, volumeId));
|
||||
} else {
|
||||
S3Utils.deleteObject(
|
||||
s3,
|
||||
bucket,
|
||||
determineSnapshotS3Key(accountId, volumeId,
|
||||
determineSnapshotBackupFilename(name)));
|
||||
}
|
||||
|
||||
return null;
|
||||
return null;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
return result;
|
||||
|
||||
|
|
@ -1425,16 +1431,16 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S
|
|||
} else if (dstore instanceof SwiftTO) {
|
||||
String path = obj.getPath();
|
||||
String filename = StringUtils.substringAfterLast(path, "/"); // assuming
|
||||
// that
|
||||
// the
|
||||
// filename
|
||||
// is
|
||||
// the
|
||||
// last
|
||||
// section
|
||||
// in
|
||||
// the
|
||||
// path
|
||||
// that
|
||||
// the
|
||||
// filename
|
||||
// is
|
||||
// the
|
||||
// last
|
||||
// section
|
||||
// in
|
||||
// the
|
||||
// path
|
||||
String volumeId = StringUtils.substringAfterLast(StringUtils.substringBeforeLast(path, "/"), "/");
|
||||
String result = swiftDelete((SwiftTO) dstore, "V-" + volumeId, filename);
|
||||
if (result != null) {
|
||||
|
|
@ -1506,8 +1512,9 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S
|
|||
String bucket = s3.getBucketName();
|
||||
// List the objects in the source directory on S3
|
||||
final List<S3ObjectSummary> objectSummaries = S3Utils.getDirectory(s3, bucket, this.TEMPLATE_ROOT_DIR);
|
||||
if (objectSummaries == null)
|
||||
if (objectSummaries == null) {
|
||||
return null;
|
||||
}
|
||||
Map<String, TemplateProp> tmpltInfos = new HashMap<String, TemplateProp>();
|
||||
for (S3ObjectSummary objectSummary : objectSummaries) {
|
||||
String key = objectSummary.getKey();
|
||||
|
|
@ -1527,8 +1534,9 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S
|
|||
String bucket = s3.getBucketName();
|
||||
// List the objects in the source directory on S3
|
||||
final List<S3ObjectSummary> objectSummaries = S3Utils.getDirectory(s3, bucket, this.VOLUME_ROOT_DIR);
|
||||
if (objectSummaries == null)
|
||||
if (objectSummaries == null) {
|
||||
return null;
|
||||
}
|
||||
Map<Long, TemplateProp> tmpltInfos = new HashMap<Long, TemplateProp>();
|
||||
for (S3ObjectSummary objectSummary : objectSummaries) {
|
||||
String key = objectSummary.getKey();
|
||||
|
|
@ -1711,8 +1719,9 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S
|
|||
boolean success = true;
|
||||
String result;
|
||||
result = configureIpFirewall(ipList, cmd.getIsAppendAIp());
|
||||
if (result != null)
|
||||
if (result != null) {
|
||||
success = false;
|
||||
}
|
||||
|
||||
return new Answer(cmd, success, result);
|
||||
}
|
||||
|
|
@ -1928,16 +1937,16 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S
|
|||
Long volumeId = obj.getId();
|
||||
String path = obj.getPath();
|
||||
String filename = StringUtils.substringAfterLast(path, "/"); // assuming
|
||||
// that
|
||||
// the
|
||||
// filename
|
||||
// is
|
||||
// the
|
||||
// last
|
||||
// section
|
||||
// in
|
||||
// the
|
||||
// path
|
||||
// that
|
||||
// the
|
||||
// filename
|
||||
// is
|
||||
// the
|
||||
// last
|
||||
// section
|
||||
// in
|
||||
// the
|
||||
// path
|
||||
String result = swiftDelete((SwiftTO) dstore, "V-" + volumeId.toString(), filename);
|
||||
if (result != null) {
|
||||
String errMsg = "failed to delete volume " + filename + " , err=" + result;
|
||||
|
|
@ -2003,8 +2012,9 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S
|
|||
|
||||
@Override
|
||||
public Type getType() {
|
||||
if (SecondaryStorageVm.Role.templateProcessor.toString().equals(_role))
|
||||
if (SecondaryStorageVm.Role.templateProcessor.toString().equals(_role)) {
|
||||
return Host.Type.SecondaryStorage;
|
||||
}
|
||||
|
||||
return Host.Type.SecondaryStorageCmdExecutor;
|
||||
}
|
||||
|
|
@ -2067,8 +2077,9 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S
|
|||
}
|
||||
}
|
||||
|
||||
if (_inSystemVM)
|
||||
if (_inSystemVM) {
|
||||
_storage.mkdirs(_parent);
|
||||
}
|
||||
|
||||
_configSslScr = Script.findScript(getDefaultScriptsDir(), "config_ssl.sh");
|
||||
if (_configSslScr != null) {
|
||||
|
|
@ -2093,8 +2104,9 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S
|
|||
}
|
||||
|
||||
_role = (String) params.get("role");
|
||||
if (_role == null)
|
||||
if (_role == null) {
|
||||
_role = SecondaryStorageVm.Role.templateProcessor.toString();
|
||||
}
|
||||
s_logger.info("Secondary storage runs in role " + _role);
|
||||
|
||||
_guid = (String) params.get("guid");
|
||||
|
|
@ -2310,8 +2322,9 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S
|
|||
if (result != null) {
|
||||
s_logger.warn("Unable to mount " + nfsPath + " due to " + result);
|
||||
file = new File(root);
|
||||
if (file.exists())
|
||||
if (file.exists()) {
|
||||
file.delete();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
@ -2344,8 +2357,9 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S
|
|||
|
||||
final StartupSecondaryStorageCommand cmd = new StartupSecondaryStorageCommand();
|
||||
fillNetworkInformation(cmd);
|
||||
if (_publicIp != null)
|
||||
if (_publicIp != null) {
|
||||
cmd.setPublicIpAddress(_publicIp);
|
||||
}
|
||||
|
||||
if (_inSystemVM) {
|
||||
Script command = new Script("/bin/bash", s_logger);
|
||||
|
|
|
|||
Loading…
Reference in New Issue