diff --git a/org.jdrupes.vmoperator.runner.qemu/src/org/jdrupes/vmoperator/runner/qemu/CpuController.java b/org.jdrupes.vmoperator.runner.qemu/src/org/jdrupes/vmoperator/runner/qemu/CpuController.java index 512db1b..6d8ccc1 100644 --- a/org.jdrupes.vmoperator.runner.qemu/src/org/jdrupes/vmoperator/runner/qemu/CpuController.java +++ b/org.jdrupes.vmoperator.runner.qemu/src/org/jdrupes/vmoperator/runner/qemu/CpuController.java @@ -85,6 +85,11 @@ public class CpuController extends Component { */ @Handler public void onHotpluggableCpuStatus(HotpluggableCpuStatus result) { + if (!result.successful()) { + logger.warning(() -> "Failed to get hotpluggable CPU status " + + "(won't adjust number of CPUs.): " + result.errorMessage()); + } + // Sort List used = new ArrayList<>(); List unused = new ArrayList<>(); diff --git a/org.jdrupes.vmoperator.runner.qemu/src/org/jdrupes/vmoperator/runner/qemu/events/MonitorResult.java b/org.jdrupes.vmoperator.runner.qemu/src/org/jdrupes/vmoperator/runner/qemu/events/MonitorResult.java index ee8515f..83295dd 100644 --- a/org.jdrupes.vmoperator.runner.qemu/src/org/jdrupes/vmoperator/runner/qemu/events/MonitorResult.java +++ b/org.jdrupes.vmoperator.runner.qemu/src/org/jdrupes/vmoperator/runner/qemu/events/MonitorResult.java @@ -19,6 +19,7 @@ package org.jdrupes.vmoperator.runner.qemu.events; import com.fasterxml.jackson.databind.JsonNode; +import java.util.Optional; import org.jdrupes.vmoperator.runner.qemu.commands.QmpAddCpu; import org.jdrupes.vmoperator.runner.qemu.commands.QmpCommand; import org.jdrupes.vmoperator.runner.qemu.commands.QmpDelCpu; @@ -89,6 +90,7 @@ public class MonitorResult extends Event { * * @return the json node */ + @SuppressWarnings("PMD.AvoidDuplicateLiterals") public JsonNode values() { if (response.has("return")) { return response.get("return"); @@ -99,6 +101,43 @@ public class MonitorResult extends Event { return null; } + /** + * Returns the error class if this result is an error. + * + * @return the optional + */ + public Optional errorClass() { + if (!response.has("error")) { + return Optional.empty(); + } + return Optional.ofNullable(response.get("error").get("class").asText()); + } + + /** + * Returns the error description if this result is an error. + * + * @return the optional + */ + public Optional errorDescription() { + if (!response.has("error")) { + return Optional.empty(); + } + return Optional.ofNullable(response.get("error").get("desc").asText()); + } + + /** + * Combines error class and error description to a string + * "class: desc". Returns an empty string is this result is not an error. + * + * @return the string + */ + public String errorMessage() { + if (successful()) { + return ""; + } + return errorClass().get() + ": " + errorDescription().get(); + } + @Override public String toString() { StringBuilder builder = new StringBuilder();