Improve error handling.
This commit is contained in:
parent
219d8aa91a
commit
c5818b6bf4
2 changed files with 44 additions and 0 deletions
|
|
@ -85,6 +85,11 @@ public class CpuController extends Component {
|
||||||
*/
|
*/
|
||||||
@Handler
|
@Handler
|
||||||
public void onHotpluggableCpuStatus(HotpluggableCpuStatus result) {
|
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
|
// Sort
|
||||||
List<ObjectNode> used = new ArrayList<>();
|
List<ObjectNode> used = new ArrayList<>();
|
||||||
List<ObjectNode> unused = new ArrayList<>();
|
List<ObjectNode> unused = new ArrayList<>();
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@
|
||||||
package org.jdrupes.vmoperator.runner.qemu.events;
|
package org.jdrupes.vmoperator.runner.qemu.events;
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.JsonNode;
|
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.QmpAddCpu;
|
||||||
import org.jdrupes.vmoperator.runner.qemu.commands.QmpCommand;
|
import org.jdrupes.vmoperator.runner.qemu.commands.QmpCommand;
|
||||||
import org.jdrupes.vmoperator.runner.qemu.commands.QmpDelCpu;
|
import org.jdrupes.vmoperator.runner.qemu.commands.QmpDelCpu;
|
||||||
|
|
@ -89,6 +90,7 @@ public class MonitorResult extends Event<Void> {
|
||||||
*
|
*
|
||||||
* @return the json node
|
* @return the json node
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("PMD.AvoidDuplicateLiterals")
|
||||||
public JsonNode values() {
|
public JsonNode values() {
|
||||||
if (response.has("return")) {
|
if (response.has("return")) {
|
||||||
return response.get("return");
|
return response.get("return");
|
||||||
|
|
@ -99,6 +101,43 @@ public class MonitorResult extends Event<Void> {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the error class if this result is an error.
|
||||||
|
*
|
||||||
|
* @return the optional
|
||||||
|
*/
|
||||||
|
public Optional<String> 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<String> 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
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue