001/* 002 * VM-Operator 003 * Copyright (C) 2023 Michael N. Lipp 004 * 005 * This program is free software: you can redistribute it and/or modify 006 * it under the terms of the GNU Affero General Public License as 007 * published by the Free Software Foundation, either version 3 of the 008 * License, or (at your option) any later version. 009 * 010 * This program is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 013 * GNU Affero General Public License for more details. 014 * 015 * You should have received a copy of the GNU Affero General Public License 016 * along with this program. If not, see <https://www.gnu.org/licenses/>. 017 */ 018 019package org.jdrupes.vmoperator.runner.qemu.events; 020 021import com.fasterxml.jackson.databind.JsonNode; 022import com.fasterxml.jackson.databind.node.ObjectNode; 023import java.util.ArrayList; 024import java.util.Collections; 025import java.util.List; 026import org.jdrupes.vmoperator.runner.qemu.commands.QmpCommand; 027 028/** 029 * A {@link MonitorResult} that reports the hot pluggable CPU status. 030 */ 031public class HotpluggableCpuStatus extends MonitorResult { 032 033 @SuppressWarnings("PMD.ImmutableField") 034 private List<ObjectNode> usedCpus = new ArrayList<>(); 035 @SuppressWarnings("PMD.ImmutableField") 036 private List<ObjectNode> unusedCpus = new ArrayList<>(); 037 038 /** 039 * Instantiates a new hotpluggable cpu result. 040 * 041 * @param command the command 042 * @param response the response 043 */ 044 @SuppressWarnings({ "PMD.ConstructorCallsOverridableMethod", 045 "PMD.ForLoopCanBeForeach" }) 046 public HotpluggableCpuStatus(QmpCommand command, JsonNode response) { 047 super(command, response); 048 if (!successful()) { 049 return; 050 } 051 052 // Sort 053 for (var itr = values().iterator(); itr.hasNext();) { 054 ObjectNode cpu = (ObjectNode) itr.next(); 055 if (cpu.has("qom-path")) { 056 usedCpus.add(cpu); 057 } else { 058 unusedCpus.add(cpu); 059 } 060 } 061 usedCpus = Collections.unmodifiableList(usedCpus); 062 unusedCpus = Collections.unmodifiableList(unusedCpus); 063 } 064 065 /** 066 * Gets the used cpus. 067 * 068 * @return the usedCpus 069 */ 070 public List<ObjectNode> usedCpus() { 071 return usedCpus; 072 } 073 074 /** 075 * Gets the unused cpus. 076 * 077 * @return the unusedCpus 078 */ 079 public List<ObjectNode> unusedCpus() { 080 return unusedCpus; 081 } 082 083}