More work on reading and updating PCM preferences to enable energymonitoring.
This commit is contained in:
parent
bcd2b84e9f
commit
2d13bddde1
|
@ -32,7 +32,7 @@ import java.util.concurrent.Callable;
|
|||
defaultValueProvider = biz.nellemann.hmci.DefaultProvider.class)
|
||||
public class Application implements Callable<Integer> {
|
||||
|
||||
@Option(names = { "-c", "--conf" }, description = "Configuration file [default: ${DEFAULT-VALUE}].", paramLabel = "<file>", defaultValue = "/etc/hmci.toml")
|
||||
@Option(names = { "-c", "--conf" }, description = "Configuration file [default: ${DEFAULT-VALUE}].", paramLabel = "<file>")
|
||||
private File configurationFile;
|
||||
|
||||
@Option(names = { "-d", "--debug" }, description = "Enable debugging [default: false].")
|
||||
|
|
|
@ -17,6 +17,7 @@ package biz.nellemann.hmci;
|
|||
|
||||
import biz.nellemann.hmci.dto.xml.*;
|
||||
import com.fasterxml.jackson.core.JsonParseException;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
|
||||
import org.slf4j.Logger;
|
||||
|
@ -37,8 +38,6 @@ class ManagedSystem extends Resource {
|
|||
private List<String> excludePartitions = new ArrayList<>();
|
||||
private List<String> includePartitions = new ArrayList<>();
|
||||
|
||||
private Boolean doEnergy = true;
|
||||
|
||||
private final RestClient restClient;
|
||||
|
||||
protected ManagedSystemEntry entry;
|
||||
|
@ -46,6 +45,8 @@ class ManagedSystem extends Resource {
|
|||
protected ManagedSystemPcmPreference pcmPreference;
|
||||
protected SystemEnergy systemEnergy;
|
||||
|
||||
protected boolean enableEnergyMonitoring = false;
|
||||
|
||||
private String uriPath;
|
||||
public String name;
|
||||
public String id;
|
||||
|
@ -84,17 +85,17 @@ class ManagedSystem extends Resource {
|
|||
return;
|
||||
}
|
||||
|
||||
if(pcmPreference.energyMonitoringCapable && !pcmPreference.energyMonitorEnabled) {
|
||||
// TODO: Try to enable
|
||||
if(doEnergy && pcmPreference.energyMonitoringCapable && !pcmPreference.energyMonitorEnabled) {
|
||||
setPcmPreference();
|
||||
}
|
||||
|
||||
if(pcmPreference.energyMonitorEnabled) {
|
||||
this.doEnergy = doEnergy;
|
||||
systemEnergy = new SystemEnergy(restClient, this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void discover() {
|
||||
|
||||
try {
|
||||
|
@ -191,10 +192,31 @@ class ManagedSystem extends Resource {
|
|||
|
||||
}
|
||||
|
||||
public void setPcmPreference() {
|
||||
log.info("getPcmPreferences()");
|
||||
|
||||
try {
|
||||
String urlPath = String.format("/rest/api/pcm/ManagedSystem/%s/preferences", id);
|
||||
XmlMapper xmlMapper = new XmlMapper();
|
||||
|
||||
if(pcmPreference.energyMonitoringCapable && !pcmPreference.energyMonitorEnabled) {
|
||||
//log.warn("getPcmPreferences() - TODO: Enabling energyMonitor");
|
||||
pcmPreference.metadata.atom = null;
|
||||
pcmPreference.energyMonitorEnabled = true;
|
||||
//xmlMapper.enable(SerializationFeature.INDENT_OUTPUT);
|
||||
String updateXml = xmlMapper.writeValueAsString(pcmPreference);
|
||||
//log.warn(updateXml);
|
||||
restClient.postRequest(urlPath, updateXml);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
log.warn("setPcmPreferences() - Error: {}", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void getPcmPreferences() {
|
||||
|
||||
log.info("getPcmPreferences()");
|
||||
log.debug("getPcmPreferences()");
|
||||
|
||||
try {
|
||||
String urlPath = String.format("/rest/api/pcm/ManagedSystem/%s/preferences", id);
|
||||
|
@ -217,19 +239,13 @@ class ManagedSystem extends Resource {
|
|||
|
||||
if(xmlFeed.getEntry().getContent().isManagedSystemPcmPreference()) {
|
||||
pcmPreference = xmlFeed.getEntry().getContent().getManagedSystemPcmPreference();
|
||||
if(pcmPreference.energyMonitoringCapable && !pcmPreference.energyMonitorEnabled) {
|
||||
log.warn("getPcmPreferences() - TODO: Enable energyMonitor");
|
||||
//pcmPreference.energyMonitorEnabled = true;
|
||||
//xmlMapper.configure(SerializationFeature.WRITE_SINGLE_ELEM_ARRAYS_UNWRAPPED,true);
|
||||
//String updateXml = xmlMapper.writeValueAsString(pcmPreference);
|
||||
//restClient.postRequest(urlPath, updateXml);
|
||||
}
|
||||
enableEnergyMonitoring = pcmPreference.energyMonitorEnabled;
|
||||
} else {
|
||||
throw new UnsupportedOperationException("Failed to deserialize ManagedSystemPcmPreference");
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
log.debug("getPcmPreferences() - Error: {}", e.getMessage());
|
||||
log.warn("getPcmPreferences() - Error: {}", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -168,8 +168,10 @@ class ManagementConsole implements Runnable {
|
|||
// Only continue for powered-on operating systems
|
||||
if(managedSystem.entry != null && Objects.equals(managedSystem.entry.state, "operating")) {
|
||||
|
||||
if(doEnergy) {
|
||||
managedSystem.getPcmPreferences();
|
||||
managedSystem.setDoEnergy(doEnergy);
|
||||
}
|
||||
|
||||
// Check exclude / include
|
||||
if (!excludeSystems.contains(managedSystem.name) && includeSystems.isEmpty()) {
|
||||
|
|
|
@ -23,6 +23,7 @@ public class RestClient {
|
|||
|
||||
private final static Logger log = LoggerFactory.getLogger(RestClient.class);
|
||||
private final MediaType MEDIA_TYPE_IBM_XML_LOGIN = MediaType.parse("application/vnd.ibm.powervm.web+xml; type=LogonRequest");
|
||||
private final MediaType MEDIA_TYPE_IBM_XML_POST = MediaType.parse("application/xml, application/vnd.ibm.powervm.pcm.dita");
|
||||
|
||||
|
||||
protected OkHttpClient httpClient;
|
||||
|
@ -211,17 +212,16 @@ public class RestClient {
|
|||
*/
|
||||
public synchronized String postRequest(URL url, String payload) throws IOException {
|
||||
|
||||
log.info("sendPostRequest() - URL: {}", url.toString());
|
||||
log.debug("sendPostRequest() - URL: {}", url.toString());
|
||||
RequestBody requestBody;
|
||||
if(payload != null) {
|
||||
requestBody = RequestBody.create(payload, MediaType.get("application/xml"));
|
||||
requestBody = RequestBody.create(payload, MEDIA_TYPE_IBM_XML_POST);
|
||||
} else {
|
||||
requestBody = RequestBody.create("", null);
|
||||
}
|
||||
|
||||
Request request = new Request.Builder()
|
||||
.url(url)
|
||||
//.addHeader("Content-Type", "application/xml")
|
||||
.addHeader("content-type", "application/xml")
|
||||
.addHeader("X-API-Session", (authToken == null ? "" : authToken) )
|
||||
.post(requestBody).build();
|
||||
|
@ -232,7 +232,7 @@ public class RestClient {
|
|||
|
||||
if (!response.isSuccessful()) {
|
||||
response.close();
|
||||
log.warn(responseBody);
|
||||
//log.warn(responseBody);
|
||||
log.error("sendPostRequest() - Unexpected response: {}", response.code());
|
||||
throw new IOException("sendPostRequest() - Unexpected response: " + response.code());
|
||||
}
|
||||
|
|
|
@ -1,25 +1,31 @@
|
|||
package biz.nellemann.hmci.dto.xml;
|
||||
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class Link implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@JacksonXmlProperty(isAttribute = true)
|
||||
public String rel;
|
||||
|
||||
public String getRel() {
|
||||
return rel;
|
||||
}
|
||||
|
||||
|
||||
@JacksonXmlProperty(isAttribute = true)
|
||||
public String type;
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
@JacksonXmlProperty(isAttribute = true)
|
||||
public String href;
|
||||
|
||||
public String getHref() {
|
||||
|
|
|
@ -2,14 +2,18 @@ package biz.nellemann.hmci.dto.xml;
|
|||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@JsonIgnoreProperties({ "kb", "kxe", "schemaVersion", "Metadata" })
|
||||
@JsonIgnoreProperties({ "kb", "kxe", "Metadata" })
|
||||
public class MachineTypeModelAndSerialNumber implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@JacksonXmlProperty(isAttribute = true)
|
||||
private final String schemaVersion = "V1_0";
|
||||
|
||||
@JsonProperty("MachineType")
|
||||
public String machineType;
|
||||
|
||||
|
|
|
@ -12,34 +12,46 @@ public class ManagedSystemPcmPreference {
|
|||
@JacksonXmlProperty(isAttribute = true)
|
||||
private final String schemaVersion = "V1_0";
|
||||
|
||||
@JacksonXmlProperty(isAttribute = true, localName = "xmlns:ManagedSystemPcmPreference")
|
||||
@JacksonXmlProperty(isAttribute = true, localName = "xmlns")
|
||||
private final String xmlns = "http://www.ibm.com/xmlns/systems/power/firmware/pcm/mc/2012_10/";
|
||||
|
||||
@JacksonXmlProperty(isAttribute = true, localName = "xmlns:ManagedSystemPcmPreference")
|
||||
private final String ns1 = "http://www.ibm.com/xmlns/systems/power/firmware/pcm/mc/2012_10/";
|
||||
|
||||
@JacksonXmlProperty(isAttribute = true, localName = "xmlns:ns2")
|
||||
private final String ns2 = "http://www.w3.org/XML/1998/namespace/k2";
|
||||
|
||||
|
||||
@JsonProperty("Metadata")
|
||||
public Metadata metadata;
|
||||
|
||||
@JsonProperty("SystemName")
|
||||
public String systemName;
|
||||
|
||||
//public MachineTypeModelAndSerialNumber machineTypeModelSerialNumber;
|
||||
@JsonProperty("MachineTypeModelSerialNumber")
|
||||
public MachineTypeModelAndSerialNumber machineTypeModelSerialNumber;
|
||||
|
||||
@JsonProperty("EnergyMonitoringCapable")
|
||||
public Boolean energyMonitoringCapable = false;
|
||||
|
||||
@JsonProperty("LongTermMonitorEnabled")
|
||||
public Boolean longTermMonitorEnabled = false;
|
||||
public Boolean longTermMonitorEnabled;
|
||||
|
||||
@JsonProperty("AggregationEnabled")
|
||||
public Boolean aggregationEnabled = false;
|
||||
public Boolean aggregationEnabled;
|
||||
|
||||
@JsonProperty("ShortTermMonitorEnabled")
|
||||
public Boolean shortTermMonitorEnabled;
|
||||
|
||||
@JsonProperty("ComputeLTMEnabled")
|
||||
public Boolean computeLTMEnabled;
|
||||
// ksv ksv="V1_1_0"
|
||||
//@JacksonXmlProperty(isAttribute = true)
|
||||
//@JsonProperty("ComputeLTMEnabled")
|
||||
//public Boolean computeLTMEnabled;
|
||||
|
||||
@JsonProperty("EnergyMonitorEnabled")
|
||||
public Boolean energyMonitorEnabled;
|
||||
public Boolean energyMonitorEnabled = false;
|
||||
|
||||
@JsonProperty("AssociatedManagedSystem")
|
||||
public Link associatedManagedSystem;
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue