Skip to content

Commit 41703c2

Browse files
committed
pass json file instead
Signed-off-by: Abhishek Kumar <[email protected]>
1 parent 070051c commit 41703c2

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

plugins/hypervisors/external/src/main/java/org/apache/cloudstack/hypervisor/external/provisioner/simpleprovisioner/SimpleExternalProvisioner.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import java.nio.file.Path;
2727
import java.nio.file.Paths;
2828
import java.nio.file.StandardCopyOption;
29+
import java.nio.file.StandardOpenOption;
2930
import java.util.ArrayList;
3031
import java.util.HashMap;
3132
import java.util.List;
@@ -79,7 +80,6 @@
7980
import com.cloud.vm.VmDetailConstants;
8081
import com.cloud.vm.dao.UserVmDao;
8182
import com.cloud.vm.dao.VMInstanceDao;
82-
import com.fasterxml.jackson.core.JsonProcessingException;
8383

8484
public class SimpleExternalProvisioner extends ManagerBase implements ExternalProvisioner, PluggableService, Configurable {
8585

@@ -523,16 +523,16 @@ public Pair<Boolean, String> executeExternalCommand(String file, String action,
523523
List<String> command = new ArrayList<>();
524524
command.add(executablePath.toString());
525525
command.add(action);
526-
String parameters = prepareParameters(accessDetails);
527-
command.add(parameters);
526+
String dataFile = prepareActionData(accessDetails);
527+
command.add(dataFile);
528528
command.add(Integer.toString(wait));
529529
ProcessBuilder builder = new ProcessBuilder(command);
530530
builder.redirectErrorStream(true);
531531

532532
if (IS_DEBUG) {
533533
logger.info("Executable: {}",executablePath);
534534
logger.info("Action: {} with wait: {}", action, wait);
535-
logger.info("Parameters: {}", parameters);
535+
logger.info("Data file: {}", dataFile);
536536
return new Pair<>(true, "Operation successful!");
537537
}
538538
logger.debug("Executing command: {}", command);
@@ -573,8 +573,16 @@ public Answer checkHealth(String hostGuid, String extensionName, String extensio
573573
return new Answer(cmd);
574574
}
575575

576-
private String prepareParameters(Map<String, Object> details) throws JsonProcessingException {
577-
return GsonHelper.getGson().toJson(details);
576+
private String prepareActionData(Map<String, Object> details) throws IOException {
577+
// ToDo: some mechanism to clean up these data files
578+
String json = GsonHelper.getGson().toJson(details);
579+
logger.debug("Data: {}", json);
580+
long epochMillis = System.currentTimeMillis();
581+
String fileName = epochMillis + ".json";
582+
Path tempDir = Files.createTempDirectory("orchestrator");
583+
Path tempFile = tempDir.resolve(fileName);
584+
Files.writeString(tempFile, json, StandardOpenOption.CREATE_NEW);
585+
return tempFile.toAbsolutePath().toString();
578586
}
579587

580588
@Override

0 commit comments

Comments
 (0)