summaryrefslogtreecommitdiff
path: root/java/broker-plugins/experimental/info/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'java/broker-plugins/experimental/info/src/main')
-rw-r--r--java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/AppInfo.java97
-rw-r--r--java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/InfoService.java30
-rw-r--r--java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/InfoServiceImpl.java66
-rw-r--r--java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/SystemInfo.java90
-rw-r--r--java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/util/IniFileReader.java142
-rw-r--r--java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/util/SoapClient.java162
6 files changed, 587 insertions, 0 deletions
diff --git a/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/AppInfo.java b/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/AppInfo.java
new file mode 100644
index 0000000000..15d9f6f55f
--- /dev/null
+++ b/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/AppInfo.java
@@ -0,0 +1,97 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.qpid.info;
+
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.TreeMap;
+import java.util.Map.Entry;
+
+import org.apache.qpid.common.QpidProperties;
+import org.apache.qpid.server.configuration.ServerConfiguration;
+import org.apache.qpid.server.registry.ApplicationRegistry;
+
+/**
+ * AppInfo class is gathering application specific informations
+ *
+ */
+public class AppInfo
+{
+
+ private static final List<String> appProps = Arrays.asList("QPID_HOME",
+ "QPID_WORK");
+
+ private static Map<String, String> appInfoMap = new TreeMap<String, String>();
+
+ /**
+ * getInfo method retrieves a key-value map for specific application properties
+ * @return Map<String,String>
+ */
+ public static Map<String, String> getInfo()
+ {
+
+ // Gather the selected app props
+ Properties sysprops = System.getProperties();
+ String propName;
+ for (Iterator<Entry<Object, Object>> it = sysprops.entrySet()
+ .iterator(); it.hasNext();)
+ {
+ Entry<Object, Object> en = it.next();
+ propName = en.getKey().toString();
+ if (appProps.indexOf(propName) >= 0)
+ {
+ appInfoMap.put(propName, en.getValue().toString());
+ }
+ }
+
+ ServerConfiguration sc;
+ try
+ {
+ sc = ApplicationRegistry.getInstance().getConfiguration();
+ if (null != sc)
+ {
+ appInfoMap.put("jmxport", sc.getJMXManagementPort() + "");
+ appInfoMap.put("port", sc.getPorts().toString());
+ appInfoMap.put("version", QpidProperties.getReleaseVersion());
+ appInfoMap.put("vhosts", "standalone");
+ // brokerInfoMap.put("DefaultVirtualHost",
+ // sc.getDefaultVirtualHost());
+ appInfoMap.put("JMXPrincipalDatabase", sc
+ .getJMXPrincipalDatabase());
+ appInfoMap.put("KeystorePath", sc.getKeystorePath());
+ appInfoMap.put("PluginDirectory", sc.getPluginDirectory());
+ appInfoMap.put("CertType", sc.getCertType());
+ appInfoMap.put("QpidWork", sc.getQpidWork());
+ appInfoMap.put("Bind", sc.getBind());
+ }
+ } catch (Exception e)
+ {
+ //
+ }
+ return appInfoMap;
+
+ }
+
+}
diff --git a/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/InfoService.java b/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/InfoService.java
new file mode 100644
index 0000000000..2804dfb1b4
--- /dev/null
+++ b/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/InfoService.java
@@ -0,0 +1,30 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+ /**
+ * Interface exposing the service methods
+ */
+ package org.apache.qpid.info;
+
+ public interface InfoService
+ {
+ public Info<?> invoke(String action);
+ }
diff --git a/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/InfoServiceImpl.java b/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/InfoServiceImpl.java
new file mode 100644
index 0000000000..a2ffaea3bb
--- /dev/null
+++ b/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/InfoServiceImpl.java
@@ -0,0 +1,66 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+/**
+ *
+ * @author sorin
+ *
+ * Implementation for Info service
+ */
+
+package org.apache.qpid.info;
+
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.Map;
+import java.util.SortedMap;
+import java.util.TreeMap;
+
+
+public class InfoServiceImpl implements InfoService
+{
+
+ SortedMap<String, String> infoMap = new TreeMap<String, String>();
+
+ /**
+ * invoke method collects all the informations from System and Application
+ * and encapsulates them in an Info object
+ * @return An instance of an Info object
+ */
+ public Info<? extends Map<String,?>> invoke(String action)
+ {
+ // Record the action (STARTUP/SHUTDOWN)
+ infoMap.put("action",action);
+
+ // Record the current time stamp
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSSZ");
+ infoMap.put("time", sdf.format(Calendar.getInstance().getTime()));
+
+ // Add the system specific properties
+ infoMap.putAll(SystemInfo.getInfo());
+
+ // Add the application specific properties
+ infoMap.putAll(AppInfo.getInfo());
+
+ return new Info<SortedMap<String, String>>(infoMap);
+ }
+
+}
diff --git a/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/SystemInfo.java b/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/SystemInfo.java
new file mode 100644
index 0000000000..25095b62dc
--- /dev/null
+++ b/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/SystemInfo.java
@@ -0,0 +1,90 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.qpid.info;
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.TreeMap;
+import java.util.Map.Entry;
+
+/**
+ * Collector for system specific information
+ */
+public class SystemInfo
+{
+
+ private static Map<String, String> sysInfoMap = new TreeMap<String, String>();
+
+ private static final List<String> sysProps = Arrays.asList(
+ "java.class.path", "java.home", "java.vm.name", "java.vm.vendor",
+ "java.vm.version", "java.class.version", "java.runtime.version",
+ "os.arch", "os.name", "os.version", "sun.arch.data.model",
+ "user.home", "user.dir", "user.name", "user.timezone");
+
+ /**
+ * getInfo collects all the properties specified in sysprops list
+ * @return A Map<String,String>
+ */
+ public static Map<String, String> getInfo()
+ {
+
+ // Get the hostname
+ try
+ {
+ InetAddress addr = InetAddress.getLocalHost();
+ String hostname = addr.getHostName();
+ sysInfoMap.put("hostname", hostname);
+ sysInfoMap.put("ip", addr.getHostAddress());
+ } catch (UnknownHostException e)
+ {
+ //
+ }
+ // Get the runtime info
+ sysInfoMap.put("CPUCores", Runtime.getRuntime().availableProcessors()
+ + "");
+ sysInfoMap.put("Maximum_Memory", Runtime.getRuntime().maxMemory() + "");
+ sysInfoMap.put("Free_Memory", Runtime.getRuntime().freeMemory() + "");
+
+ // Gather the selected system props
+ Properties sysprops = System.getProperties();
+ String propName;
+ for (Iterator<Entry<Object, Object>> it = sysprops.entrySet()
+ .iterator(); it.hasNext();)
+ {
+ Entry<Object, Object> en = it.next();
+ propName = en.getKey().toString();
+ if (sysProps.indexOf(propName) >= 0)
+ {
+ sysInfoMap.put(propName, en.getValue().toString());
+ }
+ }
+
+ return sysInfoMap;
+
+ }
+
+}
diff --git a/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/util/IniFileReader.java b/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/util/IniFileReader.java
new file mode 100644
index 0000000000..f5e8396cbe
--- /dev/null
+++ b/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/util/IniFileReader.java
@@ -0,0 +1,142 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.qpid.info.util;
+
+import java.util.*;
+import java.io.*;
+
+public class IniFileReader
+{
+ private final Map<String, Properties> sections;
+
+ private final String COMMENT_SEMICOLON = ";";
+
+ private final String COMMENT_HASH = "#";
+
+ enum State
+ {
+ IN_SECTION, OFF_SECTION, GLOBAL
+ }
+
+ /*
+ * IniFileReader constructor
+ */
+ public IniFileReader()
+ {
+ sections = new HashMap<String, Properties>();
+ }
+
+ /**
+ * Cleans up the after comments or the empty spaces/tabs surrounding the given string
+ * @param str The String to be cleaned
+ * @return String Cleanup Version
+ */
+ private String cleanUp(String str)
+ {
+ if (str.contains(COMMENT_SEMICOLON))
+ str = str.substring(0, str.indexOf(COMMENT_SEMICOLON));
+ if (str.contains(COMMENT_HASH))
+ str = str.substring(0, str.indexOf(COMMENT_HASH));
+ return str.trim();
+ }
+
+ /**
+ * Loads and parses the ini file with the full path specified in the argument
+ * @param fileName Full path to the ini file
+ * @throws IllegalArgumentException If the file cannot be processed
+ */
+ public void load(String fileName) throws IllegalArgumentException
+ {
+ if (! new File(fileName).isFile()) throw new IllegalArgumentException("File: "+fileName+ " does not exist or cannot be read.");
+ State state = State.GLOBAL;
+ String line;
+ Properties sectionProps = new Properties();
+ String sectionName = "";
+ try
+ {
+ BufferedReader in = new BufferedReader(new FileReader(fileName));
+ while ((line = in.readLine()) != null)
+ {
+ String str = cleanUp(line);
+
+ // Did we get a section header?
+ if (str.startsWith("[") && str.endsWith("]"))
+ {
+ // We encountered a new section header
+ if (state != State.IN_SECTION)
+ {
+ sections.put(sectionName, sectionProps);
+ sectionProps = new Properties();
+ sectionName = str.replace("[", "").replace("]", "")
+ .trim();
+ state = State.IN_SECTION;
+ }
+ }
+
+ // Any other line tested separately, ignore if out of a section
+ // and add if in section
+ if (str.length() == 0)
+ {
+ // We encountered a commented or an empty line, both cases
+ // mean we are off the section
+ if (state == State.IN_SECTION)
+ {
+ sections.put(sectionName, sectionProps);
+ state = State.OFF_SECTION;
+ }
+ } else
+ {
+ // proper line, add it to the props
+ if (state != State.OFF_SECTION)
+ {
+ if (str.contains("="))
+ {
+ int ix = str.indexOf("=");
+ sectionProps.put(str.substring(0, ix).trim(), str
+ .substring(ix + 1).trim());
+ }
+ }
+ }
+ }
+ in.close();
+ } catch (IOException e)
+ {
+ sections.clear();
+ return;
+ }
+ if (state != State.OFF_SECTION)
+ {
+ sections.put(sectionName, sectionProps);
+ }
+ }
+
+ /**
+ * Getter for the Sections Map
+ * @return Map<String,Properties> The parsed content of the ini file in this structure
+ */
+ public Map<String, Properties> getSections()
+ {
+ return sections;
+ }
+
+
+}
diff --git a/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/util/SoapClient.java b/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/util/SoapClient.java
new file mode 100644
index 0000000000..703a710568
--- /dev/null
+++ b/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/util/SoapClient.java
@@ -0,0 +1,162 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+/**
+ *
+ * @author sorin
+ *
+ * An simple SOAP client for qpid info service
+ */
+package org.apache.qpid.info.util;
+
+import java.io.BufferedWriter;
+
+import java.io.OutputStreamWriter;
+
+import java.net.InetAddress;
+
+import java.net.Socket;
+import java.util.HashMap;
+import java.util.Properties;
+
+public class SoapClient
+{
+
+ private final StringBuffer xmlData;
+
+ private final Properties _destprops;
+
+ private final String hostname;
+
+ private final String port;
+
+ private final String urlpath;
+
+ private final String soapenvelope;
+
+ private final String soapaction;
+
+ private final StringBuffer soapMessage = new StringBuffer();
+
+ public SoapClient(HashMap<String, String> map, Properties destprops)
+ {
+ if (null == destprops)
+ {
+ _destprops = new Properties();
+ } else
+ {
+ _destprops = destprops;
+ }
+ hostname = _destprops.getProperty("soap.hostname", "null");
+ port = _destprops.getProperty("soap.port", "null");
+ urlpath = _destprops.getProperty("soap.path", "null");
+ soapenvelope = _destprops.getProperty("soap.envelope", "null");
+ soapaction = _destprops.getProperty("soap.action", "null");
+ xmlData = new StringBuffer(soapenvelope);
+ replaceVariables(map);
+ }
+
+ public StringBuffer getXMLData()
+ {
+ return xmlData;
+ }
+
+ public StringBuffer getSoapMessage()
+ {
+ return soapMessage;
+ }
+
+ public String getSoapEnvelope()
+ {
+ return soapenvelope;
+ }
+
+ public void setXMLData(StringBuilder sb)
+ {
+ xmlData.delete(0, xmlData.length() - 1);
+ xmlData.append(sb);
+ }
+
+ public void replaceVariables(HashMap<String, String> vars)
+ {
+ if (vars == null)
+ return;
+ int ix = 0;
+ for (String var : vars.keySet())
+ {
+ while ((ix = xmlData.indexOf("@" + var.toUpperCase())) >= 0)
+ {
+ xmlData.replace(ix, ix + 1 + var.length(), vars.get(var));
+ }
+ }
+ }
+
+ public void replaceVariables(Properties varProps)
+ {
+ if (varProps == null)
+ return;
+ int ix = 0;
+ for (Object var : varProps.keySet())
+ {
+ while ((ix = xmlData.indexOf("@" + var)) >= 0)
+ {
+ xmlData.replace(ix, ix + 1 + var.toString().length(), varProps
+ .get(var).toString());
+ }
+ }
+ }
+
+ public String sendSOAPMessage()
+ {
+
+ try
+ {
+ InetAddress addr = InetAddress.getByName(hostname);
+ Socket sock = new Socket(addr, Integer.parseInt(port));
+ StringBuffer sb = new StringBuffer();
+ sb.append("POST " + urlpath + " HTTP/1.1\r\n");
+ sb.append("Host: " + hostname + ":" + port + "\r\n");
+ sb.append("Content-Length: " + xmlData.length() + "\r\n");
+ sb.append("Content-Type: text/xml; charset=\"utf-8\"\r\n");
+ sb.append("SOAPAction: \"urn:" + soapaction + "\"\r\n");
+ sb.append("User-Agent: Axis2\r\n");
+ sb.append("\r\n");
+ // Send header
+ BufferedWriter wr = new BufferedWriter(new OutputStreamWriter(sock
+ .getOutputStream(), "UTF-8"));
+ synchronized (soapMessage)
+ {
+ soapMessage.setLength(0);
+ soapMessage.append(sb);
+ soapMessage.append(xmlData);
+ }
+ String msg = soapMessage.toString();
+ // Send data
+ wr.write(msg);
+ wr.flush();
+ wr.close();
+ return msg;
+ } catch (Exception ex)
+ {
+ // Drop any exception
+ return null;
+ }
+ }
+}