diff --git a/server/src/main/java/org/apache/cloudstack/storage/NfsMountManagerImpl.java b/server/src/main/java/org/apache/cloudstack/storage/NfsMountManagerImpl.java index 50ef1365451..479ee12a5fa 100644 --- a/server/src/main/java/org/apache/cloudstack/storage/NfsMountManagerImpl.java +++ b/server/src/main/java/org/apache/cloudstack/storage/NfsMountManagerImpl.java @@ -163,16 +163,16 @@ public class NfsMountManagerImpl implements NfsMountManager { private boolean mountExists(String localRootPath) { Script script = new Script(true, "mount", timeout, s_logger); - ZfsPathParser parser = new ZfsPathParser(localRootPath); + PathParser parser = new PathParser(localRootPath); script.execute(parser); return parser.getPaths().stream().filter(s -> s.contains(localRootPath)).findAny().map(s -> true).orElse(false); } - public static class ZfsPathParser extends OutputInterpreter { + public static class PathParser extends OutputInterpreter { String _parent; List paths = new ArrayList<>(); - public ZfsPathParser(String parent) { + public PathParser(String parent) { _parent = parent; } diff --git a/services/secondary-storage/server/src/main/java/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java b/services/secondary-storage/server/src/main/java/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java index 7f9e0a67409..ab98a812580 100644 --- a/services/secondary-storage/server/src/main/java/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java +++ b/services/secondary-storage/server/src/main/java/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java @@ -67,7 +67,7 @@ import org.apache.cloudstack.storage.configdrive.ConfigDrive; import org.apache.cloudstack.storage.configdrive.ConfigDriveBuilder; import org.apache.cloudstack.storage.template.DownloadManager; import org.apache.cloudstack.storage.template.DownloadManagerImpl; -import org.apache.cloudstack.storage.template.DownloadManagerImpl.ZfsPathParser; +import org.apache.cloudstack.storage.NfsMountManagerImpl.PathParser; import org.apache.cloudstack.storage.template.UploadEntity; import org.apache.cloudstack.storage.template.UploadManager; import org.apache.cloudstack.storage.template.UploadManagerImpl; @@ -2905,7 +2905,7 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S script = new Script(!_inSystemVM, "mount", _timeout, s_logger); List res = new ArrayList(); - ZfsPathParser parser = new ZfsPathParser(localRootPath); + PathParser parser = new PathParser(localRootPath); script.execute(parser); res.addAll(parser.getPaths()); for (String s : res) { diff --git a/services/secondary-storage/server/src/main/java/org/apache/cloudstack/storage/template/DownloadManagerImpl.java b/services/secondary-storage/server/src/main/java/org/apache/cloudstack/storage/template/DownloadManagerImpl.java index f6de4c3d0e8..4149cd174d1 100644 --- a/services/secondary-storage/server/src/main/java/org/apache/cloudstack/storage/template/DownloadManagerImpl.java +++ b/services/secondary-storage/server/src/main/java/org/apache/cloudstack/storage/template/DownloadManagerImpl.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.storage.template; -import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.IOException; @@ -60,6 +59,7 @@ import org.apache.cloudstack.storage.command.DownloadCommand; import org.apache.cloudstack.storage.command.DownloadCommand.ResourceType; import org.apache.cloudstack.storage.command.DownloadProgressCommand; import org.apache.cloudstack.storage.command.DownloadProgressCommand.RequestType; +import org.apache.cloudstack.storage.NfsMountManagerImpl.PathParser; import org.apache.cloudstack.storage.resource.NfsSecondaryStorageResource; import org.apache.cloudstack.storage.resource.SecondaryStorageResource; import org.apache.commons.collections.CollectionUtils; @@ -82,7 +82,6 @@ import com.cloud.utils.NumbersUtil; import com.cloud.utils.StringUtils; import com.cloud.utils.component.ManagerBase; import com.cloud.utils.exception.CloudRuntimeException; -import com.cloud.utils.script.OutputInterpreter; import com.cloud.utils.script.Script; import com.cloud.utils.storage.QCOW2Utils; import org.apache.cloudstack.utils.security.ChecksumValue; @@ -850,8 +849,12 @@ public class DownloadManagerImpl extends ManagerBase implements DownloadManager Script script = new Script(listVolScr, LOGGER); script.add("-r", rootdir); - ZfsPathParser zpp = new ZfsPathParser(rootdir); + PathParser zpp = new PathParser(rootdir); script.execute(zpp); + if (script.getExitValue() != 0) { + LOGGER.error("Error while executing script " + script.toString()); + throw new CloudRuntimeException("Error while executing script " + script.toString()); + } result.addAll(zpp.getPaths()); LOGGER.info("found " + zpp.getPaths().size() + " volumes" + zpp.getPaths()); return result; @@ -862,8 +865,12 @@ public class DownloadManagerImpl extends ManagerBase implements DownloadManager Script script = new Script(listTmpltScr, LOGGER); script.add("-r", rootdir); - ZfsPathParser zpp = new ZfsPathParser(rootdir); + PathParser zpp = new PathParser(rootdir); script.execute(zpp); + if (script.getExitValue() != 0) { + LOGGER.error("Error while executing script " + script.toString()); + throw new CloudRuntimeException("Error while executing script " + script.toString()); + } result.addAll(zpp.getPaths()); LOGGER.info("found " + zpp.getPaths().size() + " templates" + zpp.getPaths()); return result; @@ -961,33 +968,6 @@ public class DownloadManagerImpl extends ManagerBase implements DownloadManager return result; } - public static class ZfsPathParser extends OutputInterpreter { - String _parent; - List paths = new ArrayList(); - - public ZfsPathParser(String parent) { - _parent = parent; - } - - @Override - public String interpret(BufferedReader reader) throws IOException { - String line = null; - while ((line = reader.readLine()) != null) { - paths.add(line); - } - return null; - } - - public List getPaths() { - return paths; - } - - @Override - public boolean drain() { - return true; - } - } - public DownloadManagerImpl() { }