Skip to content
Open
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 @@ -882,7 +882,7 @@ protected enum HealthCheckResult {
protected StorageSubsystemCommandHandler storageHandler;

private boolean convertInstanceVerboseMode = false;
private String[] convertInstanceEnv = null;
private Map<String, String> convertInstanceEnv = null;
protected boolean dpdkSupport = false;
protected String dpdkOvsPath;
protected String directDownloadTemporaryDownloadPath;
Expand Down Expand Up @@ -947,7 +947,7 @@ public boolean isConvertInstanceVerboseModeEnabled() {
return convertInstanceVerboseMode;
}

public String[] getConvertInstanceEnv() {
public Map<String, String> getConvertInstanceEnv() {
return convertInstanceEnv;
}

Expand Down Expand Up @@ -1437,14 +1437,14 @@ private void setConvertInstanceEnv(String convertEnvTmpDir, String convertEnvVir
return;
}
if (StringUtils.isNotBlank(convertEnvTmpDir) && StringUtils.isNotBlank(convertEnvVirtv2vTmpDir)) {
convertInstanceEnv = new String[2];
convertInstanceEnv[0] = String.format("%s=%s", "TMPDIR", convertEnvTmpDir);
convertInstanceEnv[1] = String.format("%s=%s", "VIRT_V2V_TMPDIR", convertEnvVirtv2vTmpDir);
convertInstanceEnv = new HashMap<>(2);
convertInstanceEnv.put("TMPDIR", convertEnvTmpDir);
convertInstanceEnv.put("VIRT_V2V_TMPDIR", convertEnvVirtv2vTmpDir);
} else {
convertInstanceEnv = new String[1];
convertInstanceEnv = new HashMap<>(1);
String key = StringUtils.isNotBlank(convertEnvTmpDir) ? "TMPDIR" : "VIRT_V2V_TMPDIR";
String value = StringUtils.isNotBlank(convertEnvTmpDir) ? convertEnvTmpDir : convertEnvVirtv2vTmpDir;
convertInstanceEnv[0] = String.format("%s=%s", key, value);
convertInstanceEnv.put(key, value);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@
import java.nio.charset.Charset;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import org.apache.cloudstack.storage.to.PrimaryDataStoreTO;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.StringUtils;

import com.cloud.agent.api.Answer;
Expand Down Expand Up @@ -244,7 +246,12 @@ protected boolean performInstanceConversion(String originalVMName, String source

String logPrefix = String.format("(%s) virt-v2v ovf source: %s progress", originalVMName, sourceOVFDirPath);
OutputInterpreter.LineByLineOutputLogger outputLogger = new OutputInterpreter.LineByLineOutputLogger(logger, logPrefix);
script.execute(outputLogger);
Map<String, String> convertInstanceEnv = serverResource.getConvertInstanceEnv();
if (MapUtils.isEmpty(convertInstanceEnv)) {
script.execute(outputLogger);
} else {
script.execute(outputLogger, convertInstanceEnv);
}
int exitValue = script.getExitValue();
return exitValue == 0;
}
Expand Down
20 changes: 19 additions & 1 deletion utils/src/main/java/com/cloud/utils/script/Script.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
Expand All @@ -42,6 +43,7 @@
import java.util.stream.Collectors;

import org.apache.cloudstack.utils.security.KeyStoreUtils;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.io.IOUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand Down Expand Up @@ -236,6 +238,14 @@ static String stackTraceAsString(Throwable throwable) {
}

public String execute(OutputInterpreter interpreter) {
return execute(interpreter, null);
}

public String execute(OutputInterpreter interpreter, Map<String, String> environment) {
return executeInternal(interpreter, environment);
}

private String executeInternal(OutputInterpreter interpreter, Map<String, String> environment) {
String[] command = _command.toArray(new String[_command.size()]);
String commandLine = buildCommandLine(command);
if (_logger.isDebugEnabled() && !avoidLoggingCommand) {
Expand All @@ -247,11 +257,19 @@ public String execute(OutputInterpreter interpreter) {

ProcessBuilder pb = new ProcessBuilder(command);
pb.redirectErrorStream(true);
if (_workDir != null)

if (MapUtils.isNotEmpty(environment)) {
Map<String, String> processEnvironment = pb.environment();
processEnvironment.putAll(environment);
}

if (_workDir != null) {
pb.directory(new File(_workDir));
}

_logger.trace(String.format("Starting process for command [%s].", commandLine));
_process = pb.start();

if (_process == null) {
_logger.warn(String.format("Unable to execute command [%s] because no process was created.", commandLine));
return "Unable to execute the command: " + command[0];
Expand Down
Loading