Add capability of getting memInfo.
Understands the { "memInfo": true } request returning the MemoryInfo
as understood by JHardware.
Change-Id: I4ba133123dd9fea0e7a4f3151b9fe926efe3bb2a
diff --git a/src/main/resources/Documentation/rest-api.md b/src/main/resources/Documentation/rest-api.md
index 8933f56..878787d 100644
--- a/src/main/resources/Documentation/rest-api.md
+++ b/src/main/resources/Documentation/rest-api.md
@@ -18,15 +18,15 @@
- gerritVersion - JSON String with the version of running Gerrit server
- cpuInfo - JSON Object with all the CPU information collected by [jHardware](https://github.com/profesorfalken/jHardware)
-
+- memInfo - JSON Object with all the Memory information collected by [jHardware](https://github.com/profesorfalken/jHardware)
EXAMPLES
--------
-Ask the server to prepare zip file for version and cpuinfo
+Ask the server to prepare zip file for version, cpuinfo and meminfo
> curl -v -H "Content-Type: application/json" \
-> -d '{"gerritVersion": true,"cpuInfo": true }' \
+> -d '{"gerritVersion": true,"cpuInfo": true, "memInfo": true }' \
> http://host:port/plugins/gerrit-support/collect
```
diff --git a/src/main/scala/com/googlesource/gerrit/plugins/support/GerritSupportCommands.scala b/src/main/scala/com/googlesource/gerrit/plugins/support/GerritSupportCommands.scala
index e8c9480..d589feb 100644
--- a/src/main/scala/com/googlesource/gerrit/plugins/support/GerritSupportCommands.scala
+++ b/src/main/scala/com/googlesource/gerrit/plugins/support/GerritSupportCommands.scala
@@ -19,7 +19,7 @@
import com.google.gerrit.common.Version
import com.google.gson.{Gson, JsonElement, JsonObject, JsonPrimitive}
import com.google.inject._
-import org.jutils.jhardware.HardwareInfo.getProcessorInfo
+import org.jutils.jhardware.HardwareInfo.{getMemoryInfo, getProcessorInfo}
import scala.util.Try
@@ -53,6 +53,18 @@
}))
}
+class MemInfoCommand extends GerritSupportCommand {
+ implicit val gson = new Gson
+
+ def execute = CommandResult("mem-info.json",
+ gson.toJsonTree(
+ Try {
+ getMemoryInfo
+ } getOrElse {
+ ErrorInfo("error" -> s"Memory info not available on ${System.getProperty("os.name")}")
+ }))
+}
+
object ErrorInfo {
def apply[T](attributes: (String, T)*)(implicit gson: Gson): JsonObject =
attributes.foldLeft(new JsonObject) {
diff --git a/src/test/scala/com/googlesource/gerrit/plugins/support/GerritSupportTest.scala b/src/test/scala/com/googlesource/gerrit/plugins/support/GerritSupportTest.scala
index 60adf74..953ac03 100644
--- a/src/test/scala/com/googlesource/gerrit/plugins/support/GerritSupportTest.scala
+++ b/src/test/scala/com/googlesource/gerrit/plugins/support/GerritSupportTest.scala
@@ -47,6 +47,13 @@
cpuInfo.getAsJsonObject should haveValidFields
}
+ "mem-info command" should "return a json object with some fields" in {
+ val memInfo = new MemInfoCommand().execute.content
+
+ memInfo should not be null
+ memInfo.getAsJsonObject should haveValidFields
+ }
+
"Bundle builder" should "create an output zip file" in {
val zipFile = new SupportBundleBuilder(tmpPath.toPath, new Gson).build