Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -163,16 +163,16 @@ private void deleteMountPath(String localRootPath) {

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<String> paths = new ArrayList<>();

public ZfsPathParser(String parent) {
public PathParser(String parent) {
_parent = parent;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
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;
Expand Down Expand Up @@ -2905,7 +2905,7 @@ protected boolean mountExists(String localRootPath, URI uri) {
script = new Script(!_inSystemVM, "mount", _timeout, s_logger);

List<String> res = new ArrayList<String>();
ZfsPathParser parser = new ZfsPathParser(localRootPath);
PathParser parser = new PathParser(localRootPath);
script.execute(parser);
res.addAll(parser.getPaths());
for (String s : res) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -60,6 +59,7 @@
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;
Expand All @@ -82,7 +82,6 @@
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;
Expand Down Expand Up @@ -850,8 +849,12 @@ private List<String> listVolumes(String rootdir) {

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;
Expand All @@ -862,8 +865,12 @@ private List<String> listTemplates(String rootdir) {

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;
Expand Down Expand Up @@ -961,33 +968,6 @@ public Map<Long, TemplateProp> gatherVolumeInfo(String rootDir) {
return result;
}

public static class ZfsPathParser extends OutputInterpreter {
String _parent;
List<String> paths = new ArrayList<String>();

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<String> getPaths() {
return paths;
}

@Override
public boolean drain() {
return true;
}
}

public DownloadManagerImpl() {
}

Expand Down