diff --git a/server/src/com/cloud/api/doc/Alert.java b/server/src/com/cloud/api/doc/Alert.java new file mode 100644 index 00000000000..56d82cafbec --- /dev/null +++ b/server/src/com/cloud/api/doc/Alert.java @@ -0,0 +1,20 @@ +package com.cloud.api.doc; + +public class Alert { + private String type; + private int value; + + public Alert(String type, int value) { + this.type = type; + this.value = value; + } + + public String getType() { + return type; + } + + public int getValue() { + return value; + } + +} diff --git a/server/src/com/cloud/api/doc/ApiXmlDocWriter.java b/server/src/com/cloud/api/doc/ApiXmlDocWriter.java index 11d46b7f913..be3f156164f 100644 --- a/server/src/com/cloud/api/doc/ApiXmlDocWriter.java +++ b/server/src/com/cloud/api/doc/ApiXmlDocWriter.java @@ -41,6 +41,7 @@ import java.util.zip.ZipOutputStream; import org.apache.log4j.Logger; +import com.cloud.alert.AlertManager; import com.cloud.api.BaseAsyncCmd; import com.cloud.api.BaseAsyncCreateCmd; import com.cloud.api.BaseCmd; @@ -200,6 +201,9 @@ public class ApiXmlDocWriter { regularUser.close(); regularUserSorted.close(); + //write alerttypes to xml + writeAlertTypes(xmlDocDir); + //gzip directory with xml doc //zipDir(dirName + "xmldoc.zip", xmlDocDir); @@ -401,6 +405,25 @@ public class ApiXmlDocWriter { } + private static void writeAlertTypes(String dirName) { + XStream xs = new XStream(); + xs.alias("alert", Alert.class); + try { + ObjectOutputStream out = xs.createObjectOutputStream(new FileWriter(dirName + "/alert_types.xml"), "alerts"); + for(Field f : AlertManager.class.getFields()){ + String name = f.getName().substring(11); + Alert alert = new Alert(name, f.getInt(null)); + out.writeObject(alert); + } + out.close(); + } catch (IOException e) { + s_logger.error("Failed to create output stream to write an alert types ", e); + } catch (IllegalAccessException e) { + s_logger.error("Failed to read alert fields ", e); + } + } + + private static class LinkedProperties extends Properties { private final LinkedList keys = new LinkedList();