Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristopher Frost2011-10-18 09:17:03 -0400
committerChristopher Frost2011-10-18 09:17:03 -0400
commit57b80ed4f26e4b6ff174df2ee0362fe23d623e9c (patch)
tree2f313502526e4c9c893dd3f04bb0a7364ae2a913
parent2f69be0ce8fb9722c3b89961803b89abb77fae26 (diff)
downloadorg.eclipse.virgo.medic-57b80ed4f26e4b6ff174df2ee0362fe23d623e9c.tar.gz
org.eclipse.virgo.medic-57b80ed4f26e4b6ff174df2ee0362fe23d623e9c.tar.xz
org.eclipse.virgo.medic-57b80ed4f26e4b6ff174df2ee0362fe23d623e9c.zip
360646 Adding MBean for the mgmt of Medic Dumps
-rw-r--r--org.eclipse.virgo.medic.core/.classpath6
-rw-r--r--org.eclipse.virgo.medic.core/.springBeans13
-rw-r--r--org.eclipse.virgo.medic.core/ivy.xml1
-rw-r--r--org.eclipse.virgo.medic.core/src/main/java/org/eclipse/virgo/medic/impl/MedicActivator.java16
-rw-r--r--org.eclipse.virgo.medic.core/src/main/java/org/eclipse/virgo/medic/impl/config/ConfigurationAdminConfigurationProvider.java14
-rw-r--r--org.eclipse.virgo.medic.core/src/main/java/org/eclipse/virgo/medic/management/DumpInspector.java65
-rw-r--r--org.eclipse.virgo.medic.core/src/main/java/org/eclipse/virgo/medic/management/FileSystemDumpInspector.java123
-rw-r--r--org.eclipse.virgo.medic.core/src/main/java/org/eclipse/virgo/medic/management/MedicMBeanExporter.java72
-rw-r--r--org.eclipse.virgo.medic.core/src/test/java/org/eclipse/virgo/medic/impl/MedicActivatorTests.java39
-rw-r--r--org.eclipse.virgo.medic.core/src/test/java/org/eclipse/virgo/medic/management/FileSystemDumpInspectorTests.java82
-rw-r--r--org.eclipse.virgo.medic.core/template.mf2
-rw-r--r--org.eclipse.virgo.medic.integrationtest/.classpath4
12 files changed, 390 insertions, 47 deletions
diff --git a/org.eclipse.virgo.medic.core/.classpath b/org.eclipse.virgo.medic.core/.classpath
index 311966d..e72114b 100644
--- a/org.eclipse.virgo.medic.core/.classpath
+++ b/org.eclipse.virgo.medic.core/.classpath
@@ -28,11 +28,13 @@
<classpathentry kind="var" path="MEDIC_IVY_CACHE/org.eclipse.virgo.teststubs/org.eclipse.virgo.teststubs.osgi/3.1.0.D-20111011120826/org.eclipse.virgo.teststubs.osgi-3.1.0.D-20111011120826.jar" sourcepath="/MEDIC_IVY_CACHE/org.eclipse.virgo.teststubs/org.eclipse.virgo.teststubs.osgi/3.1.0.D-20111011120826/org.eclipse.virgo.teststubs.osgi-sources-3.1.0.D-20111011120826.jar"/>
<classpathentry kind="var" path="MEDIC_IVY_CACHE/org.aspectj/com.springsource.org.aspectj.runtime/1.6.6.RELEASE/com.springsource.org.aspectj.runtime-1.6.6.RELEASE.jar" sourcepath="/MEDIC_IVY_CACHE/org.aspectj/com.springsource.org.aspectj.runtime/1.6.6.RELEASE/com.springsource.org.aspectj.runtime-sources-1.6.6.RELEASE.jar"/>
<classpathentry kind="var" path="MEDIC_IVY_CACHE/org.slf4j/com.springsource.slf4j.api/1.6.1/com.springsource.slf4j.api-1.6.1.jar" sourcepath="/MEDIC_IVY_CACHE/org.slf4j/com.springsource.slf4j.api/1.6.1/com.springsource.slf4j.api-sources-1.6.1.jar"/>
- <classpathentry kind="var" path="MEDIC_IVY_CACHE/ch.qos.logback/com.springsource.ch.qos.logback.classic/0.9.24/com.springsource.ch.qos.logback.classic-0.9.24.jar" sourcepath="/MEDIC_IVY_CACHE/ch.qos.logback/com.springsource.ch.qos.logback.classic/0.9.24/com.springsource.ch.qos.logback.classic-sources-0.9.24.jar"/>
- <classpathentry kind="var" path="MEDIC_IVY_CACHE/ch.qos.logback/com.springsource.ch.qos.logback.core/0.9.24/com.springsource.ch.qos.logback.core-0.9.24.jar" sourcepath="/MEDIC_IVY_CACHE/ch.qos.logback/com.springsource.ch.qos.logback.core/0.9.24/com.springsource.ch.qos.logback.core-sources-0.9.24.jar"/>
+ <classpathentry kind="var" path="MEDIC_IVY_CACHE/ch.qos.logback/com.springsource.ch.qos.logback.classic/0.9.28/com.springsource.ch.qos.logback.classic-0.9.28.jar" sourcepath="/MEDIC_IVY_CACHE/ch.qos.logback/com.springsource.ch.qos.logback.classic/0.9.24/com.springsource.ch.qos.logback.classic-sources-0.9.24.jar"/>
+ <classpathentry kind="var" path="MEDIC_IVY_CACHE/ch.qos.logback/com.springsource.ch.qos.logback.core/0.9.28/com.springsource.ch.qos.logback.core-0.9.28.jar" sourcepath="/MEDIC_IVY_CACHE/ch.qos.logback/com.springsource.ch.qos.logback.core/0.9.24/com.springsource.ch.qos.logback.core-sources-0.9.24.jar"/>
<classpathentry kind="var" path="MEDIC_IVY_CACHE/org.eclipse.virgo.util/org.eclipse.virgo.util.osgi/3.1.0.D-20111011121247/org.eclipse.virgo.util.osgi-3.1.0.D-20111011121247.jar" sourcepath="/MEDIC_IVY_CACHE/org.eclipse.virgo.util/org.eclipse.virgo.util.osgi/3.1.0.D-20111011121247/org.eclipse.virgo.util.osgi-sources-3.1.0.D-20111011121247.jar"/>
<classpathentry kind="con" path="org.eclipse.ajdt.core.ASPECTJRT_CONTAINER"/>
<classpathentry kind="var" path="MEDIC_IVY_CACHE/org.eclipse.osgi/org.eclipse.equinox.cm/1.0.300.v20101204/org.eclipse.equinox.cm-1.0.300.v20101204.jar" sourcepath="/MEDIC_IVY_CACHE/org.eclipse.osgi/org.eclipse.equinox.cm/1.0.300.v20101204/org.eclipse.equinox.cm-sources-1.0.300.v20101204.jar"/>
<classpathentry kind="var" path="MEDIC_IVY_CACHE/org.eclipse.osgi/org.eclipse.osgi.services/3.3.0.v20110110/org.eclipse.osgi.services-3.3.0.v20110110.jar" sourcepath="/MEDIC_IVY_CACHE/org.eclipse.osgi/org.eclipse.osgi.services/3.3.0.v20110110/org.eclipse.osgi.services-sources-3.3.0.v20110110.jar"/>
+ <classpathentry kind="var" path="MEDIC_IVY_CACHE/org.eclipse.virgo.util/org.eclipse.virgo.util.io/3.1.0.D-20111011121247/org.eclipse.virgo.util.io-3.1.0.D-20111011121247.jar" sourcepath="/MEDIC_IVY_CACHE/org.eclipse.virgo.util/org.eclipse.virgo.util.io/3.1.0.D-20111011121247/org.eclipse.virgo.util.io-sources-3.1.0.D-20111011121247.jar"/>
+ <classpathentry kind="var" path="MEDIC_IVY_CACHE/org.slf4j/com.springsource.slf4j.bridge/1.6.1/com.springsource.slf4j.bridge-1.6.1.jar"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
diff --git a/org.eclipse.virgo.medic.core/.springBeans b/org.eclipse.virgo.medic.core/.springBeans
deleted file mode 100644
index 8ce1035..0000000
--- a/org.eclipse.virgo.medic.core/.springBeans
+++ /dev/null
@@ -1,13 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<beansProjectDescription>
- <version>1</version>
- <pluginVersion><![CDATA[2.2.5.200906231226-RC1]]></pluginVersion>
- <configSuffixes>
- <configSuffix><![CDATA[xml]]></configSuffix>
- </configSuffixes>
- <enableImports><![CDATA[false]]></enableImports>
- <configs>
- </configs>
- <configSets>
- </configSets>
-</beansProjectDescription>
diff --git a/org.eclipse.virgo.medic.core/ivy.xml b/org.eclipse.virgo.medic.core/ivy.xml
index 498d871..4480719 100644
--- a/org.eclipse.virgo.medic.core/ivy.xml
+++ b/org.eclipse.virgo.medic.core/ivy.xml
@@ -22,6 +22,7 @@
<dependency org="org.slf4j" name="com.springsource.slf4j.api" rev="${org.slf4j}" conf="compile->runtime"/>
<dependency org="org.slf4j" name="com.springsource.slf4j.bridge" rev="${org.slf4j}" conf="compile->runtime"/>
<dependency org="org.eclipse.virgo.util" name="org.eclipse.virgo.util.osgi" rev="${org.eclipse.virgo.util}" conf="compile->runtime"/>
+ <dependency org="org.eclipse.virgo.util" name="org.eclipse.virgo.util.io" rev="${org.eclipse.virgo.util}" conf="compile->runtime"/>
<dependency org="ch.qos.logback" name="com.springsource.ch.qos.logback.classic" rev="${ch.qos.logback}" conf="provided, additional->runtime"/>
<dependency org="ch.qos.logback" name="com.springsource.ch.qos.logback.core" rev="${ch.qos.logback}" conf="provided, additional->runtime"/>
<dependency org="org.eclipse.osgi" name="org.eclipse.osgi" rev="${org.eclipse.osgi}" conf="provided->runtime"/>
diff --git a/org.eclipse.virgo.medic.core/src/main/java/org/eclipse/virgo/medic/impl/MedicActivator.java b/org.eclipse.virgo.medic.core/src/main/java/org/eclipse/virgo/medic/impl/MedicActivator.java
index 0a05ac8..06865a3 100644
--- a/org.eclipse.virgo.medic.core/src/main/java/org/eclipse/virgo/medic/impl/MedicActivator.java
+++ b/org.eclipse.virgo.medic.core/src/main/java/org/eclipse/virgo/medic/impl/MedicActivator.java
@@ -19,7 +19,6 @@ import java.util.Hashtable;
import java.util.List;
import java.util.logging.ConsoleHandler;
import java.util.logging.Handler;
-import java.util.logging.LogManager;
import java.util.logging.Logger;
import org.osgi.framework.BundleActivator;
@@ -67,6 +66,7 @@ import org.eclipse.virgo.medic.log.impl.logback.JoranLoggerContextConfigurer;
import org.eclipse.virgo.medic.log.impl.logback.LoggerContextConfigurer;
import org.eclipse.virgo.medic.log.impl.logback.StandardContextSelectorDelegate;
import org.eclipse.virgo.medic.log.osgi.OSGiLogServiceListener;
+import org.eclipse.virgo.medic.management.MedicMBeanExporter;
import org.eclipse.virgo.util.osgi.ServiceRegistrationTracker;
public final class MedicActivator implements BundleActivator {
@@ -86,6 +86,8 @@ public final class MedicActivator implements BundleActivator {
private static final String PROPERTY_LOGBACK_CONTEXT_SELECTOR = "logback.ContextSelector";
private final ServiceRegistrationTracker registrationTracker = new ServiceRegistrationTracker();
+
+ private MedicMBeanExporter medicMBeanExporter;
private volatile StandardDumpGenerator dumpGenerator;
@@ -122,6 +124,7 @@ public final class MedicActivator implements BundleActivator {
public void stop(BundleContext context) throws Exception {
this.registrationTracker.unregisterAll();
+
ServiceReference<ExtendedLogReaderService> localLogReaderReference = this.logReaderReference;
if(localLogReaderReference != null){
context.ungetService(localLogReaderReference);
@@ -131,16 +134,20 @@ public final class MedicActivator implements BundleActivator {
}
private void dumpStart(BundleContext context, ConfigurationProvider configurationProvider) {
-
this.dumpGenerator = new StandardDumpGenerator(new StandardDumpContributorResolver(context), configurationProvider, this.eventLoggerFactory.createEventLogger(context.getBundle()));
this.registrationTracker.track(context.registerService(DumpGenerator.class.getName(), this.dumpGenerator, null));
this.dumpContributorPublisher = new DumpContributorPublisher(context);
- this.dumpContributorPublisher.publishDumpContributors();
+ this.dumpContributorPublisher.publishDumpContributors();
+
+ this.medicMBeanExporter = new MedicMBeanExporter(configurationProvider, this.dumpGenerator);
}
private void dumpStop() {
- if (this.dumpGenerator != null) {
+ if(this.medicMBeanExporter != null){
+ this.medicMBeanExporter.close();
+ }
+ if (this.dumpGenerator != null) {
this.dumpGenerator.close();
}
@@ -150,7 +157,6 @@ public final class MedicActivator implements BundleActivator {
}
private void logStart(BundleContext context, ConfigurationProvider configurationProvider) throws ConfigurationPublicationFailedException {
-
StandardContextSelectorDelegate delegate = createContextSelectorDelegate(context);
this.registrationTracker.track(context.registerService(BundleListener.class.getName(), delegate, null));
DelegatingContextSelector.setDelegate(delegate);
diff --git a/org.eclipse.virgo.medic.core/src/main/java/org/eclipse/virgo/medic/impl/config/ConfigurationAdminConfigurationProvider.java b/org.eclipse.virgo.medic.core/src/main/java/org/eclipse/virgo/medic/impl/config/ConfigurationAdminConfigurationProvider.java
index 9e3984b..12a0682 100644
--- a/org.eclipse.virgo.medic.core/src/main/java/org/eclipse/virgo/medic/impl/config/ConfigurationAdminConfigurationProvider.java
+++ b/org.eclipse.virgo.medic.core/src/main/java/org/eclipse/virgo/medic/impl/config/ConfigurationAdminConfigurationProvider.java
@@ -25,8 +25,6 @@ import org.osgi.service.cm.ConfigurationListener;
public final class ConfigurationAdminConfigurationProvider implements ConfigurationProvider, ConfigurationListener {
private static final String CONFIG_ADMIN_PID = "org.eclipse.virgo.medic";
-
- private static final String CONFIG_ADMIN_SERVICE_NAME = "org.osgi.service.cm.ConfigurationAdmin";
private static final Dictionary<String, String> DEFAULT_CONFIG = createDefaultConfiguration();
@@ -44,9 +42,8 @@ public final class ConfigurationAdminConfigurationProvider implements Configurat
}
- @SuppressWarnings("unchecked")
private void initialisePropertiesFromConfigurationAdmin() {
- ServiceReference<ConfigurationAdmin> configAdminReference = (ServiceReference<ConfigurationAdmin>)this.bundleContext.getServiceReference(CONFIG_ADMIN_SERVICE_NAME);
+ ServiceReference<ConfigurationAdmin> configAdminReference = this.bundleContext.getServiceReference(ConfigurationAdmin.class);
if (configAdminReference != null) {
this.bundleContext.registerService(ConfigurationListener.class.getName(), new MedicConfigurationListener(), null);
@@ -61,8 +58,8 @@ public final class ConfigurationAdminConfigurationProvider implements Configurat
try {
Configuration configuration = configurationAdmin.getConfiguration(CONFIG_ADMIN_PID, null);
- @SuppressWarnings("unchecked")
- Dictionary<String,String> properties = configuration.getProperties();
+ @SuppressWarnings("unchecked")
+ Dictionary<String,String> properties = configuration.getProperties();
if (properties == null) {
properties = DEFAULT_CONFIG;
@@ -87,8 +84,9 @@ public final class ConfigurationAdminConfigurationProvider implements Configurat
}
private final class MedicConfigurationListener implements ConfigurationListener {
- @SuppressWarnings("unchecked")
- public void configurationEvent(ConfigurationEvent configEvent) {
+
+ @SuppressWarnings("unchecked")
+ public void configurationEvent(ConfigurationEvent configEvent) {
if (CONFIG_ADMIN_PID.equals(configEvent.getPid()) && configEvent.getType() == ConfigurationEvent.CM_UPDATED) {
setPropertiesFromConfigurationAdmin((ServiceReference<ConfigurationAdmin>)configEvent.getReference());
}
diff --git a/org.eclipse.virgo.medic.core/src/main/java/org/eclipse/virgo/medic/management/DumpInspector.java b/org.eclipse.virgo.medic.core/src/main/java/org/eclipse/virgo/medic/management/DumpInspector.java
new file mode 100644
index 0000000..e16b610
--- /dev/null
+++ b/org.eclipse.virgo.medic.core/src/main/java/org/eclipse/virgo/medic/management/DumpInspector.java
@@ -0,0 +1,65 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2011 VMware Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VMware Inc. - initial contribution
+ *******************************************************************************/
+package org.eclipse.virgo.medic.management;
+
+import java.io.IOException;
+import java.text.ParseException;
+
+import javax.management.MXBean;
+
+/**
+ *
+ * Implementations should be thread safe
+ *
+ */
+@MXBean
+public interface DumpInspector {
+
+ /**
+ * A list of the available dump names
+ *
+ * @return array of dump ids
+ * @throws IOException
+ * @throws ParseException
+ */
+ String[] getDumps() throws IOException, ParseException;
+
+ /**
+ * A list of the available dump items for the given dump
+ *
+ * @param dumpId
+ * @return array of dump entries
+ * @throws IOException
+ */
+ String[] getDumpEntries(String dumpId) throws IOException;
+
+ /**
+ * Return the requested dump item as an array of Strings, one per line
+ *
+ * @param dumpId
+ * @param item
+ * @return array of lines from the dump file
+ */
+ String[] getDumpEntry(String dumpId, String item);
+
+ /**
+ * Create a new Dump
+ *
+ */
+ void createDump();
+
+ /**
+ * Delete the given dump from the file system
+ *
+ * @param dumpId
+ */
+ void delete(String dumpId);
+}
diff --git a/org.eclipse.virgo.medic.core/src/main/java/org/eclipse/virgo/medic/management/FileSystemDumpInspector.java b/org.eclipse.virgo.medic.core/src/main/java/org/eclipse/virgo/medic/management/FileSystemDumpInspector.java
new file mode 100644
index 0000000..4a933fb
--- /dev/null
+++ b/org.eclipse.virgo.medic.core/src/main/java/org/eclipse/virgo/medic/management/FileSystemDumpInspector.java
@@ -0,0 +1,123 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2011 VMware Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VMware Inc. - initial contribution
+ *******************************************************************************/
+package org.eclipse.virgo.medic.management;
+
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.LineNumberReader;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.eclipse.virgo.medic.dump.DumpGenerator;
+import org.eclipse.virgo.util.io.FileSystemUtils;;
+
+/**
+ *
+ * Utility class for the viewing of produced Dumps.
+ *
+ * This class is thread safe
+ */
+public class FileSystemDumpInspector implements DumpInspector {
+
+ private final Logger logger = LoggerFactory.getLogger(FileSystemDumpInspector.class);
+
+ private final File dumpDirectory;
+
+ private final DumpGenerator generator;
+
+ /**
+ *
+ *
+ */
+ public FileSystemDumpInspector(DumpGenerator generator, String dumpDir) {
+ this.generator = generator;
+ this.dumpDirectory = new File(dumpDir);
+ }
+
+ @Override
+ public String[] getDumps() throws IOException {
+ if(this.dumpDirectory.exists() && this.dumpDirectory.isDirectory()){
+ return FileSystemUtils.list(this.dumpDirectory, this.logger);
+ } else {
+ return new String[0];
+ }
+ }
+
+ @Override
+ public String[] getDumpEntries(String dumpId) throws IOException {
+ File dumpDir = new File(this.dumpDirectory, dumpId);
+ String[] items;
+ if(dumpDir.exists() && dumpDir.isDirectory()){
+ items = FileSystemUtils.list(dumpDir, this.logger);
+ } else {
+ items = new String[0];
+ }
+ return items;
+ }
+
+ @Override
+ public String[] getDumpEntry(String dumpId, String entryName) {
+ if(dumpId == null || entryName == null){
+ return new String[0];
+ }
+ List<String> lines = new ArrayList<String>();
+ File dumpEntry = new File(this.dumpDirectory, dumpId + File.separatorChar + entryName);
+ if(dumpEntry != null){
+ LineNumberReader reader = null;
+ try {
+ reader = new LineNumberReader(new FileReader(dumpEntry));
+ while (reader.ready()){
+ String rawLine = reader.readLine();
+ if(rawLine != null){
+ lines.add(this.escapeAngleBrackets(rawLine));
+ }
+ }
+ reader.close();
+ } catch (IOException e) {
+ logger.error("Error while reading dump file " + dumpEntry.getPath(), e);
+ try {
+ if(reader != null){
+ reader.close();
+ }
+ } catch (IOException e1) {
+ // no-op to close stream
+ }
+ // no-op just return the default null value and let the js deal with it
+ }
+ }
+ return lines.toArray(new String[lines.size()]);
+ }
+
+ @Override
+ public void createDump() {
+ generator.generateDump("Generated via JMX");
+ }
+
+ @Override
+ public void delete(String dumpId) {
+ File root = new File(this.dumpDirectory, dumpId);
+ if(root.exists() && root.isDirectory()){
+ FileSystemUtils.deleteRecursively(root);
+ }
+ }
+
+ private String escapeAngleBrackets(String unfriendlyMarkup) {
+ String processed = unfriendlyMarkup.replace("<", "&#60;");
+ processed = processed.replace(">", "&#62;");
+ processed = processed.replace("", "&#8734;");
+ return processed;
+ }
+
+}
diff --git a/org.eclipse.virgo.medic.core/src/main/java/org/eclipse/virgo/medic/management/MedicMBeanExporter.java b/org.eclipse.virgo.medic.core/src/main/java/org/eclipse/virgo/medic/management/MedicMBeanExporter.java
new file mode 100644
index 0000000..ab4531a
--- /dev/null
+++ b/org.eclipse.virgo.medic.core/src/main/java/org/eclipse/virgo/medic/management/MedicMBeanExporter.java
@@ -0,0 +1,72 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2011 VMware Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VMware Inc. - initial contribution
+ *******************************************************************************/
+package org.eclipse.virgo.medic.management;
+
+import java.lang.management.ManagementFactory;
+import java.util.Dictionary;
+
+import javax.management.MBeanServer;
+import javax.management.ObjectInstance;
+import javax.management.ObjectName;
+
+import org.eclipse.virgo.medic.dump.DumpGenerator;
+import org.eclipse.virgo.medic.impl.config.ConfigurationProvider;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ *
+ *
+ *
+ * This class is Thread Safe
+ *
+ */
+public class MedicMBeanExporter {
+
+ private final Logger logger = LoggerFactory.getLogger(MedicMBeanExporter.class);
+
+ private static final String DOMAIN = "org.eclipse.virgo.kernel";
+
+ private final MBeanServer server = ManagementFactory.getPlatformMBeanServer();
+
+ private ObjectInstance registeredMBean;
+
+ /**
+ *
+ * @param serverHome
+ */
+ public MedicMBeanExporter(ConfigurationProvider configurationProvider, DumpGenerator dumpGenerator) {
+ try {
+ ObjectName dumpMBeanName = new ObjectName(String.format("%s:type=Medic,name=DumpInspector", DOMAIN));
+ String dumpDirectory = configurationProvider.getConfiguration().get(ConfigurationProvider.KEY_DUMP_ROOT_DIRECTORY);
+ System.out.println("dump dir" + dumpDirectory);
+ registeredMBean = this.server.registerMBean(new FileSystemDumpInspector(dumpGenerator, dumpDirectory), dumpMBeanName);
+ } catch (Exception e) {
+ logger.error("Unable to register the DumpInspectorMBean", e);
+ }
+ }
+
+ /**
+ *
+ */
+ public void close(){
+ ObjectInstance localRegisteredMBean = this.registeredMBean;
+ if(localRegisteredMBean != null){
+ try {
+ this.server.unregisterMBean(localRegisteredMBean.getObjectName());
+ this.registeredMBean = null;
+ } catch (Exception e) {
+ logger.error("Unable to unregister MBean", e);
+ }
+ }
+ }
+
+}
diff --git a/org.eclipse.virgo.medic.core/src/test/java/org/eclipse/virgo/medic/impl/MedicActivatorTests.java b/org.eclipse.virgo.medic.core/src/test/java/org/eclipse/virgo/medic/impl/MedicActivatorTests.java
index c933c65..2d75076 100644
--- a/org.eclipse.virgo.medic.core/src/test/java/org/eclipse/virgo/medic/impl/MedicActivatorTests.java
+++ b/org.eclipse.virgo.medic.core/src/test/java/org/eclipse/virgo/medic/impl/MedicActivatorTests.java
@@ -11,48 +11,51 @@
package org.eclipse.virgo.medic.impl;
-import static org.eclipse.virgo.teststubs.osgi.framework.OSGiAssert.assertServiceListenerCount;
-import static org.eclipse.virgo.teststubs.osgi.framework.OSGiAssert.assertServiceRegistrationCount;
import static org.easymock.EasyMock.createNiceMock;
import static org.easymock.EasyMock.replay;
+import static org.eclipse.virgo.teststubs.osgi.framework.OSGiAssert.assertServiceListenerCount;
+import static org.eclipse.virgo.teststubs.osgi.framework.OSGiAssert.assertServiceRegistrationCount;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
import java.io.PrintStream;
+import java.lang.management.ManagementFactory;
-import org.junit.Test;
-import org.osgi.framework.BundleActivator;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.BundleListener;
-import org.osgi.service.cm.ConfigurationListener;
-import org.osgi.service.packageadmin.PackageAdmin;
-
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
import org.eclipse.equinox.log.ExtendedLogReaderService;
import org.eclipse.virgo.medic.dump.DumpContributor;
import org.eclipse.virgo.medic.dump.DumpGenerator;
import org.eclipse.virgo.medic.eventlog.EventLogger;
import org.eclipse.virgo.medic.eventlog.EventLoggerFactory;
-import org.eclipse.virgo.medic.impl.MedicActivator;
import org.eclipse.virgo.medic.log.DelegatingPrintStream;
import org.eclipse.virgo.medic.log.LoggingConfigurationPublisher;
import org.eclipse.virgo.teststubs.osgi.framework.StubBundle;
import org.eclipse.virgo.teststubs.osgi.framework.StubBundleContext;
import org.eclipse.virgo.teststubs.osgi.support.ObjectClassFilter;
+import org.junit.Test;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleListener;
+import org.osgi.service.cm.ConfigurationListener;
+
-@SuppressWarnings("deprecation")
public class MedicActivatorTests {
+
+ private final MBeanServer server = ManagementFactory.getPlatformMBeanServer();
@Test
public void startAndStop() throws Exception {
BundleActivator bundleActivator = new MedicActivator();
StubBundleContext bundleContext = new StubBundleContext().addFilter(new ObjectClassFilter(DumpContributor.class));
bundleContext.addProperty("org.eclipse.virgo.suppress.heap.dumps", "false");
+ bundleContext.addProperty("org.eclipse.virgo.kernel.home", "src/test/resources/testDumps");
- PackageAdmin packageAdmin = createNiceMock(PackageAdmin.class);
ExtendedLogReaderService logReaderService = createNiceMock(ExtendedLogReaderService.class);
- replay(packageAdmin, logReaderService);
+ replay(logReaderService);
- bundleContext.registerService(PackageAdmin.class, packageAdmin, null);
bundleContext.registerService(ExtendedLogReaderService.class, logReaderService, null);
bundleActivator.start(bundleContext);
@@ -67,9 +70,13 @@ public class MedicActivatorTests {
assertServiceRegistrationCount(bundleContext, ConfigurationListener.class, 1);
assertServiceRegistrationCount(bundleContext, BundleListener.class, 1);
- bundleActivator.stop(bundleContext);
+ assertTrue(this.server.isRegistered(new ObjectName("org.eclipse.virgo.kernel:type=Medic,name=DumpInspector")));
+
+ bundleActivator.stop(bundleContext);
+
+ assertFalse(this.server.isRegistered(new ObjectName("org.eclipse.virgo.kernel:type=Medic,name=DumpInspector")));
- assertEquals(2, bundleContext.getServiceRegistrations().size());
+ assertEquals(1, bundleContext.getServiceRegistrations().size());
}
@Test
diff --git a/org.eclipse.virgo.medic.core/src/test/java/org/eclipse/virgo/medic/management/FileSystemDumpInspectorTests.java b/org.eclipse.virgo.medic.core/src/test/java/org/eclipse/virgo/medic/management/FileSystemDumpInspectorTests.java
new file mode 100644
index 0000000..b17978e
--- /dev/null
+++ b/org.eclipse.virgo.medic.core/src/test/java/org/eclipse/virgo/medic/management/FileSystemDumpInspectorTests.java
@@ -0,0 +1,82 @@
+package org.eclipse.virgo.medic.management;
+
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expectLastCall;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.eclipse.virgo.medic.dump.DumpGenerator;
+import org.junit.Before;
+import org.junit.Test;
+
+public class FileSystemDumpInspectorTests {
+
+ private FileSystemDumpInspector fileSystemDumpInspector;
+
+ private DumpGenerator dumpGenerator;
+
+ @Before
+ public void setup() {
+ this.dumpGenerator = createMock(DumpGenerator.class);
+ this.fileSystemDumpInspector = new FileSystemDumpInspector(dumpGenerator, "src/test/resources/testDumps/serviceability/dump");
+ }
+
+ @Test
+ public void testGetDumps() throws IOException {
+ String[] dumps = fileSystemDumpInspector.getDumps();
+ assertTrue(dumps.length == 1);
+ assertEquals("Unexpected dump found" + dumps[0], "testDump", dumps[0]);
+ }
+
+ @Test
+ public void testGetDumpEntries() throws IOException {
+ String[] dumpEntries = fileSystemDumpInspector.getDumpEntries("testDump");
+ assertTrue(dumpEntries.length == 1);
+ assertEquals("Unexpected dump found" + dumpEntries[0], "testDumpItem.txt", dumpEntries[0]);
+ }
+
+ @Test
+ public void testGetDumpEntriesNotThere() throws IOException {
+ String[] dumpEntries = fileSystemDumpInspector.getDumpEntries("notHere");
+ assertTrue(dumpEntries.length == 0);
+ }
+
+ @Test
+ public void testGetDumpEntry() {
+ String[] dumpEntry = fileSystemDumpInspector.getDumpEntry("testDump", "testDumpItem.txt");
+ assertTrue(dumpEntry.length == 2);
+ assertEquals("Unexpected dump found" + dumpEntry[0], "foo", dumpEntry[0]);
+ assertEquals("Unexpected dump found" + dumpEntry[1], "bar", dumpEntry[1]);
+ }
+
+ @Test
+ public void testGetDumpEntryNotThere() {
+ String[] dumpEntry = fileSystemDumpInspector.getDumpEntry("testDump", "notHere");
+ assertTrue(dumpEntry.length == 0);
+ }
+
+ @Test
+ public void testCreateDump(){
+ this.dumpGenerator.generateDump("Generated via JMX");
+ expectLastCall().once();
+ replay(this.dumpGenerator);
+ fileSystemDumpInspector.createDump();
+ verify(this.dumpGenerator);
+ }
+
+ @Test
+ public void testDeleteDump() {
+ File deleteMe = new File("src/test/resources/testDumps/serviceability/dump/deleteMe");
+ deleteMe.mkdir();
+ assertTrue(deleteMe.exists() && deleteMe.isDirectory());
+ fileSystemDumpInspector.delete("deleteMe");
+ assertFalse(deleteMe.exists());
+ }
+
+}
diff --git a/org.eclipse.virgo.medic.core/template.mf b/org.eclipse.virgo.medic.core/template.mf
index e502374..fcd29f0 100644
--- a/org.eclipse.virgo.medic.core/template.mf
+++ b/org.eclipse.virgo.medic.core/template.mf
@@ -7,7 +7,7 @@ Bundle-Version: ${version}
Bundle-Activator: org.eclipse.virgo.medic.impl.MedicActivator
Import-Template:
org.eclipse.virgo.medic.*;version="${version:[=.=.=, =.+1)}",
- org.eclipse.virgo.util.osgi;version="${org.eclipse.virgo.util:[=.=.=, +1.0.0)}",
+ org.eclipse.virgo.util.*;version="${org.eclipse.virgo.util:[=.=.=, +1.0.0)}",
org.eclipse.equinox.log;version="${org.eclipse.equinox.log:[=.=.=, +1.=.=)}",
javax.jms;version="0";resolution:=optional,
javax.mail.*;version="0";resolution:=optional,
diff --git a/org.eclipse.virgo.medic.integrationtest/.classpath b/org.eclipse.virgo.medic.integrationtest/.classpath
index 47c648b..78061e9 100644
--- a/org.eclipse.virgo.medic.integrationtest/.classpath
+++ b/org.eclipse.virgo.medic.integrationtest/.classpath
@@ -24,8 +24,8 @@
<classpathentry kind="var" path="MEDIC_IVY_CACHE/org.eclipse.osgi/org.eclipse.osgi/3.7.0.v20110613/org.eclipse.osgi-3.7.0.v20110613.jar" sourcepath="/MEDIC_IVY_CACHE/org.eclipse.osgi/org.eclipse.osgi/3.7.0.v20110613/org.eclipse.osgi-sources-3.7.0.v20110613.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="var" path="MEDIC_IVY_CACHE/org.slf4j/com.springsource.slf4j.api/1.6.1/com.springsource.slf4j.api-1.6.1.jar" sourcepath="/MEDIC_IVY_CACHE/org.slf4j/com.springsource.slf4j.api/1.6.1/com.springsource.slf4j.api-sources-1.6.1.jar"/>
- <classpathentry kind="var" path="MEDIC_IVY_CACHE/ch.qos.logback/com.springsource.ch.qos.logback.classic/0.9.24/com.springsource.ch.qos.logback.classic-0.9.24.jar" sourcepath="/MEDIC_IVY_CACHE/ch.qos.logback/com.springsource.ch.qos.logback.classic/0.9.24/com.springsource.ch.qos.logback.classic-sources-0.9.24.jar"/>
- <classpathentry kind="var" path="MEDIC_IVY_CACHE/ch.qos.logback/com.springsource.ch.qos.logback.core/0.9.24/com.springsource.ch.qos.logback.core-0.9.24.jar" sourcepath="/MEDIC_IVY_CACHE/ch.qos.logback/com.springsource.ch.qos.logback.core/0.9.24/com.springsource.ch.qos.logback.core-sources-0.9.24.jar"/>
+ <classpathentry kind="var" path="MEDIC_IVY_CACHE/ch.qos.logback/com.springsource.ch.qos.logback.classic/0.9.28/com.springsource.ch.qos.logback.classic-0.9.28.jar" sourcepath="/MEDIC_IVY_CACHE/ch.qos.logback/com.springsource.ch.qos.logback.classic/0.9.24/com.springsource.ch.qos.logback.classic-sources-0.9.24.jar"/>
+ <classpathentry kind="var" path="MEDIC_IVY_CACHE/ch.qos.logback/com.springsource.ch.qos.logback.core/0.9.28/com.springsource.ch.qos.logback.core-0.9.28.jar" sourcepath="/MEDIC_IVY_CACHE/ch.qos.logback/com.springsource.ch.qos.logback.core/0.9.24/com.springsource.ch.qos.logback.core-sources-0.9.24.jar"/>
<classpathentry kind="var" path="MEDIC_IVY_CACHE/org.eclipse.virgo.test/org.eclipse.virgo.test.framework/3.1.0.D-20111011121620/org.eclipse.virgo.test.framework-3.1.0.D-20111011121620.jar" sourcepath="/MEDIC_IVY_CACHE/org.eclipse.virgo.test/org.eclipse.virgo.test.framework/3.1.0.D-20111011121620/org.eclipse.virgo.test.framework-sources-3.1.0.D-20111011121620.jar"/>
<classpathentry kind="con" path="org.eclipse.ajdt.core.ASPECTJRT_CONTAINER"/>
<classpathentry kind="src" path="/org.eclipse.virgo.medic">

Back to the top