mirror of https://github.com/apache/cloudstack.git
[VMware to KVM Migration] Fix unused convert env vars (#11947)
* Fix unused convert env vars * Address review comments * Small fix to invoke internal method
This commit is contained in:
parent
b74f21b967
commit
6419e1c825
|
|
@ -882,7 +882,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
|
|||
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;
|
||||
|
|
@ -947,7 +947,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
|
|||
return convertInstanceVerboseMode;
|
||||
}
|
||||
|
||||
public String[] getConvertInstanceEnv() {
|
||||
public Map<String, String> getConvertInstanceEnv() {
|
||||
return convertInstanceEnv;
|
||||
}
|
||||
|
||||
|
|
@ -1437,14 +1437,14 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
|
|||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -22,9 +22,11 @@ import java.net.URLEncoder;
|
|||
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;
|
||||
|
|
@ -244,7 +246,12 @@ public class LibvirtConvertInstanceCommandWrapper extends CommandWrapper<Convert
|
|||
|
||||
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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ import java.util.ArrayList;
|
|||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.Callable;
|
||||
|
|
@ -44,6 +45,7 @@ import java.util.concurrent.TimeoutException;
|
|||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.apache.commons.collections4.MapUtils;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
|
|
@ -243,6 +245,14 @@ public class Script implements Callable<String> {
|
|||
}
|
||||
|
||||
public String execute(OutputInterpreter interpreter) {
|
||||
return executeInternal(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() ) {
|
||||
|
|
@ -254,11 +264,19 @@ public class Script implements Callable<String> {
|
|||
|
||||
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];
|
||||
|
|
|
|||
Loading…
Reference in New Issue