Skip to content

Commit 08e722d

Browse files
committed
CLOUDSTACK-3419: [Object_Store_Refactor] Uploaded volume is being
deleted while attaching it to guest VM.
1 parent f604e3d commit 08e722d

2 files changed

Lines changed: 87 additions & 73 deletions

File tree

‎engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,7 @@ protected Void copyVolumeFromImageToPrimaryCallback(
653653

654654
srcVolume.processEvent(Event.OperationSuccessed);
655655
destVolume.processEvent(Event.OperationSuccessed, result.getAnswer());
656-
srcVolume.getDataStore().delete(srcVolume);
656+
// srcVolume.getDataStore().delete(srcVolume);
657657
future.complete(res);
658658
} catch (Exception e) {
659659
res.setResult(e.toString());

‎services/secondary-storage/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java‎

Lines changed: 86 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,11 @@ protected CopyCmdAnswer postProcessing(File destFile, String downloadPath, Strin
284284
newTemplTO.setSize(size);
285285
newDestTO = newTemplTO;
286286
} else {
287-
return new CopyCmdAnswer("not implemented yet");
287+
VolumeObjectTO newVolTO = new VolumeObjectTO();
288+
newVolTO.setPath(finalDownloadPath);
289+
newVolTO.setName(finalFileName);
290+
newVolTO.setSize(size);
291+
newDestTO = newVolTO;
288292
}
289293

290294
return new CopyCmdAnswer(newDestTO);
@@ -324,11 +328,11 @@ protected Answer copyFromS3ToNfs(CopyCommand cmd, DataTO srcData, S3TO s3, DataT
324328

325329
File destFile = S3Utils.getFile(s3, s3.getBucketName(), srcData.getPath(), downloadDirectory,
326330
new FileNamingStrategy() {
327-
@Override
328-
public String determineFileName(final String key) {
329-
return substringAfterLast(key, S3Utils.SEPARATOR);
330-
}
331-
});
331+
@Override
332+
public String determineFileName(final String key) {
333+
return substringAfterLast(key, S3Utils.SEPARATOR);
334+
}
335+
});
332336

333337
if (destFile == null) {
334338
return new CopyCmdAnswer("Can't find template");
@@ -684,10 +688,10 @@ protected Answer registerTemplateOnSwift(DownloadCommand cmd) {
684688

685689
DownloadAnswer answer = new DownloadAnswer(null, 100, null, VMTemplateStorageResourceAssoc.Status.DOWNLOADED,
686690
swiftPath, swiftPath, file.length(), file.length(), md5sum
687-
);
691+
);
688692
return answer;
689693
} catch (Exception e) {
690-
s_logger.debug("Failed to register template into swift", e);
694+
s_logger.debug("Failed to register template into swift", e);
691695
return new DownloadAnswer(e.toString(), VMTemplateStorageResourceAssoc.Status.DOWNLOAD_ERROR);
692696
} finally {
693697
if (file != null) {
@@ -745,16 +749,17 @@ private ImageFormat getTemplateFormat(String filePath) {
745749
ext = filePath.substring(i + 1);
746750
}
747751
if (ext != null) {
748-
if (ext.equalsIgnoreCase("vhd"))
752+
if (ext.equalsIgnoreCase("vhd")) {
749753
return ImageFormat.VHD;
750-
else if (ext.equalsIgnoreCase("qcow2"))
754+
} else if (ext.equalsIgnoreCase("qcow2")) {
751755
return ImageFormat.QCOW2;
752-
else if (ext.equalsIgnoreCase("ova"))
756+
} else if (ext.equalsIgnoreCase("ova")) {
753757
return ImageFormat.OVA;
754-
else if (ext.equalsIgnoreCase("tar"))
758+
} else if (ext.equalsIgnoreCase("tar")) {
755759
return ImageFormat.TAR;
756-
else if (ext.equalsIgnoreCase("img"))
760+
} else if (ext.equalsIgnoreCase("img")) {
757761
return ImageFormat.RAW;
762+
}
758763
}
759764

760765
return null;
@@ -1016,16 +1021,16 @@ public Answer execute(DeleteSnapshotsDirCommand cmd) {
10161021
} else if (dstore instanceof SwiftTO) {
10171022
String path = cmd.getDirectory();
10181023
String volumeId = StringUtils.substringAfterLast(path, "/"); // assuming
1019-
// that
1020-
// the
1021-
// filename
1022-
// is
1023-
// the
1024-
// last
1025-
// section
1026-
// in
1027-
// the
1028-
// path
1024+
// that
1025+
// the
1026+
// filename
1027+
// is
1028+
// the
1029+
// last
1030+
// section
1031+
// in
1032+
// the
1033+
// path
10291034
String result = swiftDelete((SwiftTO) dstore, "V-" + volumeId.toString(), "");
10301035
if (result != null) {
10311036
String errMsg = "failed to delete snapshot for volume " + volumeId + " , err=" + result;
@@ -1066,12 +1071,12 @@ public Void call() throws Exception {
10661071
final File targetFile = S3Utils.getFile(s3, s3.getBucketName(), key,
10671072
_storage.getFile(directoryName), new FileNamingStrategy() {
10681073

1069-
@Override
1070-
public String determineFileName(String key) {
1071-
return snapshotFileName;
1072-
}
1074+
@Override
1075+
public String determineFileName(String key) {
1076+
return snapshotFileName;
1077+
}
10731078

1074-
});
1079+
});
10751080

10761081
if (cmd.getParent() != null) {
10771082

@@ -1220,8 +1225,9 @@ private Answer execute(ComputeChecksumCommand cmd) {
12201225
return new Answer(cmd, false, checksum);
12211226
} finally {
12221227
try {
1223-
if (is != null)
1228+
if (is != null) {
12241229
is.close();
1230+
}
12251231
} catch (IOException e) {
12261232
if (s_logger.isDebugEnabled()) {
12271233
s_logger.debug("Could not close the file " + absoluteTemplatePath);
@@ -1334,24 +1340,24 @@ private String deleteSnapshotBackupfromS3(final S3TO s3, final Long accountId, f
13341340
final String result = executeWithNoWaitLock(determineSnapshotLockId(accountId, volumeId),
13351341
new Callable<String>() {
13361342

1337-
@Override
1338-
public String call() throws Exception {
1339-
1340-
if (deleteAllFlag) {
1341-
S3Utils.deleteDirectory(s3, bucket, determineSnapshotS3Directory(accountId, volumeId));
1342-
} else {
1343-
S3Utils.deleteObject(
1344-
s3,
1345-
bucket,
1346-
determineSnapshotS3Key(accountId, volumeId,
1347-
determineSnapshotBackupFilename(name)));
1348-
}
1343+
@Override
1344+
public String call() throws Exception {
1345+
1346+
if (deleteAllFlag) {
1347+
S3Utils.deleteDirectory(s3, bucket, determineSnapshotS3Directory(accountId, volumeId));
1348+
} else {
1349+
S3Utils.deleteObject(
1350+
s3,
1351+
bucket,
1352+
determineSnapshotS3Key(accountId, volumeId,
1353+
determineSnapshotBackupFilename(name)));
1354+
}
13491355

1350-
return null;
1356+
return null;
13511357

1352-
}
1358+
}
13531359

1354-
});
1360+
});
13551361

13561362
return result;
13571363

@@ -1425,16 +1431,16 @@ protected Answer deleteSnapshot(final DeleteCommand cmd) {
14251431
} else if (dstore instanceof SwiftTO) {
14261432
String path = obj.getPath();
14271433
String filename = StringUtils.substringAfterLast(path, "/"); // assuming
1428-
// that
1429-
// the
1430-
// filename
1431-
// is
1432-
// the
1433-
// last
1434-
// section
1435-
// in
1436-
// the
1437-
// path
1434+
// that
1435+
// the
1436+
// filename
1437+
// is
1438+
// the
1439+
// last
1440+
// section
1441+
// in
1442+
// the
1443+
// path
14381444
String volumeId = StringUtils.substringAfterLast(StringUtils.substringBeforeLast(path, "/"), "/");
14391445
String result = swiftDelete((SwiftTO) dstore, "V-" + volumeId, filename);
14401446
if (result != null) {
@@ -1506,8 +1512,9 @@ Map<String, TemplateProp> s3ListTemplate(S3TO s3) {
15061512
String bucket = s3.getBucketName();
15071513
// List the objects in the source directory on S3
15081514
final List<S3ObjectSummary> objectSummaries = S3Utils.getDirectory(s3, bucket, this.TEMPLATE_ROOT_DIR);
1509-
if (objectSummaries == null)
1515+
if (objectSummaries == null) {
15101516
return null;
1517+
}
15111518
Map<String, TemplateProp> tmpltInfos = new HashMap<String, TemplateProp>();
15121519
for (S3ObjectSummary objectSummary : objectSummaries) {
15131520
String key = objectSummary.getKey();
@@ -1527,8 +1534,9 @@ Map<Long, TemplateProp> s3ListVolume(S3TO s3) {
15271534
String bucket = s3.getBucketName();
15281535
// List the objects in the source directory on S3
15291536
final List<S3ObjectSummary> objectSummaries = S3Utils.getDirectory(s3, bucket, this.VOLUME_ROOT_DIR);
1530-
if (objectSummaries == null)
1537+
if (objectSummaries == null) {
15311538
return null;
1539+
}
15321540
Map<Long, TemplateProp> tmpltInfos = new HashMap<Long, TemplateProp>();
15331541
for (S3ObjectSummary objectSummary : objectSummaries) {
15341542
String key = objectSummary.getKey();
@@ -1711,8 +1719,9 @@ private Answer execute(SecStorageFirewallCfgCommand cmd) {
17111719
boolean success = true;
17121720
String result;
17131721
result = configureIpFirewall(ipList, cmd.getIsAppendAIp());
1714-
if (result != null)
1722+
if (result != null) {
17151723
success = false;
1724+
}
17161725

17171726
return new Answer(cmd, success, result);
17181727
}
@@ -1928,16 +1937,16 @@ protected Answer deleteVolume(final DeleteCommand cmd) {
19281937
Long volumeId = obj.getId();
19291938
String path = obj.getPath();
19301939
String filename = StringUtils.substringAfterLast(path, "/"); // assuming
1931-
// that
1932-
// the
1933-
// filename
1934-
// is
1935-
// the
1936-
// last
1937-
// section
1938-
// in
1939-
// the
1940-
// path
1940+
// that
1941+
// the
1942+
// filename
1943+
// is
1944+
// the
1945+
// last
1946+
// section
1947+
// in
1948+
// the
1949+
// path
19411950
String result = swiftDelete((SwiftTO) dstore, "V-" + volumeId.toString(), filename);
19421951
if (result != null) {
19431952
String errMsg = "failed to delete volume " + filename + " , err=" + result;
@@ -2003,8 +2012,9 @@ protected long convertFilesystemSize(final String size) {
20032012

20042013
@Override
20052014
public Type getType() {
2006-
if (SecondaryStorageVm.Role.templateProcessor.toString().equals(_role))
2015+
if (SecondaryStorageVm.Role.templateProcessor.toString().equals(_role)) {
20072016
return Host.Type.SecondaryStorage;
2017+
}
20082018

20092019
return Host.Type.SecondaryStorageCmdExecutor;
20102020
}
@@ -2067,8 +2077,9 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
20672077
}
20682078
}
20692079

2070-
if (_inSystemVM)
2080+
if (_inSystemVM) {
20712081
_storage.mkdirs(_parent);
2082+
}
20722083

20732084
_configSslScr = Script.findScript(getDefaultScriptsDir(), "config_ssl.sh");
20742085
if (_configSslScr != null) {
@@ -2093,8 +2104,9 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
20932104
}
20942105

20952106
_role = (String) params.get("role");
2096-
if (_role == null)
2107+
if (_role == null) {
20972108
_role = SecondaryStorageVm.Role.templateProcessor.toString();
2109+
}
20982110
s_logger.info("Secondary storage runs in role " + _role);
20992111

21002112
_guid = (String) params.get("guid");
@@ -2310,8 +2322,9 @@ protected String mount(String root, String nfsPath) {
23102322
if (result != null) {
23112323
s_logger.warn("Unable to mount " + nfsPath + " due to " + result);
23122324
file = new File(root);
2313-
if (file.exists())
2325+
if (file.exists()) {
23142326
file.delete();
2327+
}
23152328
return null;
23162329
}
23172330

@@ -2344,8 +2357,9 @@ public StartupCommand[] initialize() {
23442357

23452358
final StartupSecondaryStorageCommand cmd = new StartupSecondaryStorageCommand();
23462359
fillNetworkInformation(cmd);
2347-
if (_publicIp != null)
2360+
if (_publicIp != null) {
23482361
cmd.setPublicIpAddress(_publicIp);
2362+
}
23492363

23502364
if (_inSystemVM) {
23512365
Script command = new Script("/bin/bash", s_logger);

0 commit comments

Comments
 (0)