Skip to content

Commit 2b35a02

Browse files
SadiJrSadiJr
andauthored
Improve logs in NfsSecondaryStorageResource class, (#7211)
Co-authored-by: SadiJr <sadi@scclouds.com.br>
1 parent 14ca172 commit 2b35a02

1 file changed

Lines changed: 45 additions & 19 deletions

File tree

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

Lines changed: 45 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@
159159
import com.cloud.storage.template.VhdProcessor;
160160
import com.cloud.storage.template.VmdkProcessor;
161161
import com.cloud.utils.EncryptionUtil;
162+
import com.cloud.utils.LogUtils;
162163
import com.cloud.utils.NumbersUtil;
163164
import com.cloud.utils.Pair;
164165
import com.cloud.utils.SwiftUtil;
@@ -272,6 +273,7 @@ public static String retrieveNfsVersionFromParams(Map<String, Object> params) {
272273

273274
@Override
274275
public Answer executeRequest(Command cmd) {
276+
s_logger.debug(LogUtils.logGsonWithoutException("Executing command %s [%s].", cmd.getClass().getSimpleName(), cmd));
275277
if (cmd instanceof DownloadProgressCommand) {
276278
return _dlMgr.handleDownloadCommand(this, (DownloadProgressCommand)cmd);
277279
} else if (cmd instanceof DownloadCommand) {
@@ -406,13 +408,17 @@ public Answer execute(GetDatadisksCommand cmd) {
406408
NfsTO nfsImageStore = (NfsTO)srcStore;
407409
String secondaryStorageUrl = nfsImageStore.getUrl();
408410
assert (secondaryStorageUrl != null);
411+
409412
String templateUrl = secondaryStorageUrl + File.separator + srcData.getPath();
413+
String templateDetails = ReflectionToStringBuilderUtils.reflectOnlySelectedFields(template, "uuid", "path", "name");
414+
s_logger.debug(String.format("Trying to get disks of template [%s], using path [%s].", templateDetails, templateUrl));
415+
410416
Pair<String, String> templateInfo = decodeTemplateRelativePathAndNameFromUrl(secondaryStorageUrl, templateUrl, template.getName());
411417
String templateRelativeFolderPath = templateInfo.first();
412418

413419
try {
414420
String secondaryMountPoint = getRootDir(secondaryStorageUrl, _nfsVersion);
415-
s_logger.info("MDOVE Secondary storage mount point: " + secondaryMountPoint);
421+
s_logger.info(String.format("Trying to find template [%s] in secondary storage root mount point [%s].", templateDetails, secondaryMountPoint));
416422

417423
String srcOVAFileName = getTemplateOnSecStorageFilePath(secondaryMountPoint, templateRelativeFolderPath, templateInfo.second(), ImageFormat.OVA.getFileExtension());
418424

@@ -423,39 +429,46 @@ public Answer execute(GetDatadisksCommand cmd) {
423429
command.add("--no-same-permissions");
424430
command.add("-xf", srcOVAFileName);
425431
command.setWorkDir(secondaryMountPoint + File.separator + templateRelativeFolderPath);
426-
s_logger.info("Executing command: " + command.toString());
432+
433+
s_logger.info(String.format("Trying to decompress OVA file [%s] using command [%s].", srcOVAFileName, command.toString()));
427434
String result = command.execute();
428435
if (result != null) {
429-
String msg = "Unable to unpack snapshot OVA file at: " + srcOVAFileName;
436+
String msg = String.format("Unable to unpack snapshot OVA file [%s] due to [%s].", srcOVAFileName, result);
430437
s_logger.error(msg);
431438
throw new Exception(msg);
432439
}
433440

441+
String directory = secondaryMountPoint + File.separator + templateRelativeFolderPath;
434442
command = new Script("chmod", 0, s_logger);
435443
command.add("-R");
436-
command.add("666", secondaryMountPoint + File.separator + templateRelativeFolderPath);
444+
command.add("666", directory);
445+
446+
s_logger.debug(String.format("Trying to add, recursivelly, permission 666 to directory [%s] using command [%s].", directory, command.toString()));
437447
result = command.execute();
438448
if (result != null) {
439-
s_logger.warn("Unable to set permissions for " + secondaryMountPoint + File.separator + templateRelativeFolderPath + " due to " + result);
449+
s_logger.warn(String.format("Unable to set permissions 666 for directory [%s] due to [%s].", directory, result));
440450
}
441451
}
442452

443453
Script command = new Script("cp", _timeout, s_logger);
444454
command.add(ovfFilePath);
445455
command.add(ovfFilePath + ORIGINAL_FILE_EXTENSION);
456+
s_logger.debug(String.format("Trying to copy file from [%s] to [%s] using command [%s].", ovfFilePath, ovfFilePath + ORIGINAL_FILE_EXTENSION, command.toString()));
446457
String result = command.execute();
447458
if (result != null) {
448-
String msg = "Unable to rename original OVF, error msg: " + result;
459+
String msg = String.format("Unable to copy original OVF file [%s] to [%s] due to [%s].", ovfFilePath, ovfFilePath + ORIGINAL_FILE_EXTENSION, result);
449460
s_logger.error(msg);
450461
}
451462

452-
s_logger.debug("Reading OVF " + ovfFilePath + " to retrive the number of disks present in OVA");
463+
s_logger.debug(String.format("Reading OVF file [%s] to retrive the number of disks present in OVA file.", ovfFilePath));
453464
OVFHelper ovfHelper = new OVFHelper();
454465

455466
List<DatadiskTO> disks = ovfHelper.getOVFVolumeInfoFromFile(ovfFilePath, configurationId);
467+
s_logger.debug(LogUtils.logGsonWithoutException("Found %s disks reading OVF file [%s] and using configuration id [%s]. The disks specifications are [%s].",
468+
disks.size(), ovfFilePath, configurationId, disks));
456469
return new GetDatadisksAnswer(disks);
457470
} catch (Exception e) {
458-
String msg = "Get Datadisk Template Count failed due to " + e.getMessage();
471+
String msg = String.format("Failed to get disks from template [%s] due to [%s].", templateDetails, e.getMessage());
459472
s_logger.error(msg, e);
460473
return new GetDatadisksAnswer(msg);
461474
}
@@ -584,7 +597,7 @@ public Answer execute(MoveVolumeCommand cmd) {
584597
* Template url may or may not end with .ova extension
585598
*/
586599
public static Pair<String, String> decodeTemplateRelativePathAndNameFromUrl(String storeUrl, String templateUrl, String defaultName) {
587-
600+
s_logger.debug(String.format("Trying to get template relative path and name from URL [%s].", templateUrl));
588601
String templateName = null;
589602
String mountPoint = null;
590603
if (templateUrl.endsWith(".ova")) {
@@ -598,6 +611,7 @@ public static Pair<String, String> decodeTemplateRelativePathAndNameFromUrl(Stri
598611
templateName = templateUrl.substring(index + 1).replace(".ova", "");
599612

600613
if (templateName == null || templateName.isEmpty()) {
614+
s_logger.debug(String.format("Cannot find template name from URL [%s]. Using default name [%s].", templateUrl, defaultName));
601615
templateName = defaultName;
602616
}
603617
} else {
@@ -608,11 +622,13 @@ public static Pair<String, String> decodeTemplateRelativePathAndNameFromUrl(Stri
608622
templateName = defaultName;
609623
}
610624

625+
s_logger.debug(String.format("Template relative path [%s] and name [%s] found from URL [%s].", mountPoint, templateName, templateUrl));
611626
return new Pair<String, String>(mountPoint, templateName);
612627
}
613628

614629
public static String getTemplateOnSecStorageFilePath(String secStorageMountPoint, String templateRelativeFolderPath, String templateName, String fileExtension) {
615-
630+
s_logger.debug(String.format("Trying to find template [%s] with file extension [%s] in secondary storage mount point [%s] using relative folder path [%s].",
631+
templateName, fileExtension, secStorageMountPoint, templateRelativeFolderPath));
616632
StringBuffer sb = new StringBuffer();
617633
sb.append(secStorageMountPoint);
618634
if (!secStorageMountPoint.endsWith("/")) {
@@ -699,17 +715,27 @@ private void writeMetaOvaForTemplate(final String installFullPath, final String
699715
}
700716

701717
private String getOVFFilePath(String srcOVAFileName) {
718+
s_logger.debug(String.format("Trying to get OVF file from OVA path [%s].", srcOVAFileName));
719+
702720
File file = new File(srcOVAFileName);
703721
assert (_storage != null);
704722
String[] files = _storage.listFiles(file.getParent());
705-
if (files != null) {
706-
for (String fileName : files) {
707-
if (fileName.toLowerCase().endsWith(".ovf")) {
708-
File ovfFile = new File(fileName);
709-
return file.getParent() + File.separator + ovfFile.getName();
710-
}
723+
724+
if (files == null) {
725+
s_logger.warn(String.format("Cannot find any files in parent directory [%s] of OVA file [%s].", file.getParent(), srcOVAFileName));
726+
return null;
727+
}
728+
729+
s_logger.debug(String.format("Found [%s] files in parent directory of OVA file [%s]. Files found are [%s].", files.length + 1, file.getParent(), StringUtils.join(files, ", ")));
730+
for (String fileName : files) {
731+
if (fileName.toLowerCase().endsWith(".ovf")) {
732+
File ovfFile = new File(fileName);
733+
String ovfFilePath = file.getParent() + File.separator + ovfFile.getName();
734+
s_logger.debug(String.format("Found OVF file [%s] from OVA file [%s].", ovfFilePath, srcOVAFileName));
735+
return ovfFilePath;
711736
}
712737
}
738+
s_logger.warn(String.format("Cannot find any OVF file in parent directory [%s] of OVA file [%s].", file.getParent(), srcOVAFileName));
713739
return null;
714740
}
715741

@@ -2616,13 +2642,13 @@ synchronized public String getRootDir(String secUrl, String nfsVersion) {
26162642
return _parent;
26172643
}
26182644
try {
2645+
s_logger.debug(String.format("Trying to get root directory from secondary storage URL [%s] using NFS version [%s].", secUrl, nfsVersion));
26192646
URI uri = new URI(secUrl);
26202647
String dir = mountUri(uri, nfsVersion);
26212648
return _parent + "/" + dir;
26222649
} catch (Exception e) {
2623-
String msg = "GetRootDir for " + secUrl + " failed due to " + e.toString();
2624-
s_logger.error(msg, e);
2625-
throw new CloudRuntimeException(msg);
2650+
String msg = String.format("Failed to get root directory from secondary storage URL [%s], using NFS version [%s], due to [%s].", secUrl, nfsVersion, e.getMessage());
2651+
throw new CloudRuntimeException(msg, e);
26262652
}
26272653
}
26282654

0 commit comments

Comments
 (0)