You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sirona.apache.org by ol...@apache.org on 2014/09/05 11:25:19 UTC
svn commit: r1622658 - in /incubator/sirona/trunk/server/reporting:
reporting-api/src/main/java/org/apache/sirona/reporting/web/jmx/
reporting-ui/src/main/webapp/partials/
reporting-webapp/src/main/java/org/apache/sirona/reporting/web/plugin/jmx/
Author: olamy
Date: Fri Sep 5 09:25:19 2014
New Revision: 1622658
URL: http://svn.apache.org/r1622658
Log:
refactor to not return jvm beans
Added:
incubator/sirona/trunk/server/reporting/reporting-api/src/main/java/org/apache/sirona/reporting/web/jmx/MBeanAttribute.java (with props)
incubator/sirona/trunk/server/reporting/reporting-api/src/main/java/org/apache/sirona/reporting/web/jmx/MBeanInformations.java (with props)
incubator/sirona/trunk/server/reporting/reporting-api/src/main/java/org/apache/sirona/reporting/web/jmx/MBeanOperation.java (with props)
incubator/sirona/trunk/server/reporting/reporting-api/src/main/java/org/apache/sirona/reporting/web/jmx/MBeanParameter.java (with props)
Modified:
incubator/sirona/trunk/server/reporting/reporting-api/src/main/java/org/apache/sirona/reporting/web/jmx/JMXServices.java
incubator/sirona/trunk/server/reporting/reporting-ui/src/main/webapp/partials/jmx.html
incubator/sirona/trunk/server/reporting/reporting-webapp/src/main/java/org/apache/sirona/reporting/web/plugin/jmx/JMXEndpoints.java
Modified: incubator/sirona/trunk/server/reporting/reporting-api/src/main/java/org/apache/sirona/reporting/web/jmx/JMXServices.java
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/server/reporting/reporting-api/src/main/java/org/apache/sirona/reporting/web/jmx/JMXServices.java?rev=1622658&r1=1622657&r2=1622658&view=diff
==============================================================================
--- incubator/sirona/trunk/server/reporting/reporting-api/src/main/java/org/apache/sirona/reporting/web/jmx/JMXServices.java (original)
+++ incubator/sirona/trunk/server/reporting/reporting-api/src/main/java/org/apache/sirona/reporting/web/jmx/JMXServices.java Fri Sep 5 09:25:19 2014
@@ -17,15 +17,21 @@
package org.apache.sirona.reporting.web.jmx;
import org.apache.commons.codec.binary.Base64;
+import org.apache.sirona.SironaException;
import javax.management.InstanceNotFoundException;
import javax.management.IntrospectionException;
+import javax.management.MBeanAttributeInfo;
import javax.management.MBeanInfo;
+import javax.management.MBeanOperationInfo;
+import javax.management.MBeanParameterInfo;
import javax.management.MBeanServerConnection;
import javax.management.MalformedObjectNameException;
import javax.management.ObjectInstance;
import javax.management.ObjectName;
import javax.management.ReflectionException;
+import javax.management.openmbean.CompositeData;
+import javax.management.openmbean.TabularData;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
@@ -33,6 +39,13 @@ import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import java.io.IOException;
import java.lang.management.ManagementFactory;
+import java.lang.reflect.Array;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
/**
* @since 0.3
@@ -40,7 +53,9 @@ import java.lang.management.ManagementFa
@Path( "/jmx" )
public class JMXServices
{
- protected final MBeanServerConnection server = ManagementFactory.getPlatformMBeanServer();
+ private final MBeanServerConnection server = ManagementFactory.getPlatformMBeanServer();
+
+ private static final String EMPTY_STRING = "";
@GET
@Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
@@ -54,13 +69,35 @@ public class JMXServices
@GET
@Path( "/{encodedName}" )
@Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
- public MBeanInfo find(@PathParam( "encodedName" ) String encodedName )
+ public MBeanInformations find( @PathParam( "encodedName" ) String encodedName )
throws IOException, MalformedObjectNameException, InstanceNotFoundException, IntrospectionException,
ReflectionException
{
final ObjectName name = new ObjectName( new String( Base64.decodeBase64( encodedName ) ) );
+
+/*
+ .set("objectname", name.toString())
+ .set("objectnameHash", Base64.encodeBase64URLSafeString(name.toString().getBytes()))
+ .set("classname", info.getClassName())
+ .set("description", value(info.getDescription()))
+ .set("attributes", attributes(name, info))
+ .set("operations", operations(info))
+ */
+
final MBeanInfo info = server.getMBeanInfo( name );
- return info;
+
+ MBeanInformations mBeanInformations = new MBeanInformations( name.toString(), //
+ Base64.encodeBase64URLSafeString(
+ name.toString().getBytes() ), //
+ info.getClassName(), //
+ info.getDescription(), //
+ new ArrayList<MBeanAttribute>(
+ attributes( name, info ) ), //
+ new ArrayList<MBeanOperation>(
+ operations( info ) ) );
+
+ return mBeanInformations;
+
}
@@ -78,4 +115,150 @@ public class JMXServices
return root;
}
+ private Collection<MBeanOperation> operations( final MBeanInfo info )
+ {
+ final Collection<MBeanOperation> operations = new LinkedList<MBeanOperation>();
+ for ( final MBeanOperationInfo operationInfo : info.getOperations() )
+ {
+ final MBeanOperation mBeanOperation =
+ new MBeanOperation( operationInfo.getName(), operationInfo.getReturnType() );
+ for ( final MBeanParameterInfo param : operationInfo.getSignature() )
+ {
+ mBeanOperation.getParameters().add( new MBeanParameter( param.getName(), param.getType() ) );
+ }
+ operations.add( mBeanOperation );
+ }
+ return operations;
+ }
+
+ // FIXME this html stuff here is just weird!!!
+ private Collection<MBeanAttribute> attributes( final ObjectName name, final MBeanInfo info )
+ {
+ final Collection<MBeanAttribute> list = new LinkedList<MBeanAttribute>();
+ for ( final MBeanAttributeInfo attribute : info.getAttributes() )
+ {
+ Object value;
+ try
+ {
+ value = server.getAttribute( name, attribute.getName() );
+ }
+ catch ( final Exception e )
+ {
+ value = "<div class=\"alert-error\">" + e.getMessage() + "</div>";
+ }
+ list.add( new MBeanAttribute( attribute.getName(), nullProtection( attribute.getType() ),
+ nullProtection( attribute.getDescription() ), value( value ) ) );
+ }
+ return list;
+ }
+
+ public static String nullProtection( final String value )
+ {
+ if ( value == null )
+ {
+ return EMPTY_STRING;
+ }
+ return value;
+ }
+
+ // FIXME this html stuff here is just weird!!!
+ private static String value( final Object value )
+ {
+ try
+ {
+ if ( value == null )
+ {
+ return nullProtection( null );
+ }
+
+ if ( value.getClass().isArray() )
+ {
+ final int length = Array.getLength( value );
+ if ( length == 0 )
+ {
+ return "";
+ }
+
+ final StringBuilder builder = new StringBuilder().append( "<ul>" );
+ for ( int i = 0; i < length; i++ )
+ {
+ builder.append( "<li>" ).append( value( Array.get( value, i ) ) ).append( "</li>" );
+ }
+ builder.append( "</ul>" );
+ return builder.toString();
+ }
+
+ if ( Collection.class.isInstance( value ) )
+ {
+ final StringBuilder builder = new StringBuilder().append( "<ul>" );
+ for ( final Object o : Collection.class.cast( value ) )
+ {
+ builder.append( "<li>" ).append( value( o ) ).append( "</li>" );
+ }
+ builder.append( "</ul>" );
+ return builder.toString();
+ }
+
+ if ( TabularData.class.isInstance( value ) )
+ {
+ final TabularData td = TabularData.class.cast( value );
+ final StringBuilder builder = new StringBuilder().append( "<table class=\"table table-condensed\">" );
+ for ( final Object type : td.keySet() )
+ {
+ final List<?> values = (List<?>) type;
+ final CompositeData data = td.get( values.toArray( new Object[values.size()] ) );
+ builder.append( "<tr>" );
+ final Set<String> dataKeys = data.getCompositeType().keySet();
+ for ( final String k : data.getCompositeType().keySet() )
+ {
+ builder.append( "<td>" ).append( value( data.get( k ) ) ).append( "</td>" );
+ }
+ builder.append( "</tr>" );
+ }
+ builder.append( "</table>" );
+
+ return builder.toString();
+ }
+
+ if ( CompositeData.class.isInstance( value ) )
+ {
+ final CompositeData cd = CompositeData.class.cast( value );
+ final Set<String> keys = cd.getCompositeType().keySet();
+
+ final StringBuilder builder = new StringBuilder().append( "<table class=\"table table-condensed\">" );
+ for ( final String type : keys )
+ {
+ builder.append( "<tr><td>" ).append( type ).append( "</td><td>" ).append(
+ value( cd.get( type ) ) ).append( "</td></tr>" );
+ }
+ builder.append( "</table>" );
+
+ return builder.toString();
+
+ }
+
+ if ( Map.class.isInstance( value ) )
+ {
+ final Map<?, ?> map = Map.class.cast( value );
+
+ final StringBuilder builder = new StringBuilder().append( "<table class=\"table table-condensed\">" );
+ for ( final Map.Entry<?, ?> entry : map.entrySet() )
+ {
+ builder.append( "<tr><tr>" ).append( value( entry.getKey() ) ).append( "</td><td>" ).append(
+ value( entry.getValue() ) ).append( "</td></tr>" );
+ }
+ builder.append( "</table>" );
+
+ return builder.toString();
+
+ }
+
+ return value.toString();
+ }
+ catch ( final Exception e )
+ {
+ throw new SironaException( e );
+ }
+ }
+
}
Added: incubator/sirona/trunk/server/reporting/reporting-api/src/main/java/org/apache/sirona/reporting/web/jmx/MBeanAttribute.java
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/server/reporting/reporting-api/src/main/java/org/apache/sirona/reporting/web/jmx/MBeanAttribute.java?rev=1622658&view=auto
==============================================================================
--- incubator/sirona/trunk/server/reporting/reporting-api/src/main/java/org/apache/sirona/reporting/web/jmx/MBeanAttribute.java (added)
+++ incubator/sirona/trunk/server/reporting/reporting-api/src/main/java/org/apache/sirona/reporting/web/jmx/MBeanAttribute.java Fri Sep 5 09:25:19 2014
@@ -0,0 +1,53 @@
+package org.apache.sirona.reporting.web.jmx;
+
+import java.io.Serializable;
+
+/**
+ * @since 0.3
+ */
+public class MBeanAttribute
+ implements Serializable
+{
+ private final String name;
+
+ private final String type;
+
+ private final String description;
+
+ private final String value;
+
+ public MBeanAttribute( final String name, final String type, final String description, final String value )
+ {
+ this.name = name;
+ this.type = type;
+ this.value = value;
+ if ( description != null )
+ {
+ this.description = description;
+ }
+ else
+ {
+ this.description = "No description";
+ }
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public String getType()
+ {
+ return type;
+ }
+
+ public String getDescription()
+ {
+ return description;
+ }
+
+ public String getValue()
+ {
+ return value;
+ }
+}
Propchange: incubator/sirona/trunk/server/reporting/reporting-api/src/main/java/org/apache/sirona/reporting/web/jmx/MBeanAttribute.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/sirona/trunk/server/reporting/reporting-api/src/main/java/org/apache/sirona/reporting/web/jmx/MBeanAttribute.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: incubator/sirona/trunk/server/reporting/reporting-api/src/main/java/org/apache/sirona/reporting/web/jmx/MBeanInformations.java
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/server/reporting/reporting-api/src/main/java/org/apache/sirona/reporting/web/jmx/MBeanInformations.java?rev=1622658&view=auto
==============================================================================
--- incubator/sirona/trunk/server/reporting/reporting-api/src/main/java/org/apache/sirona/reporting/web/jmx/MBeanInformations.java (added)
+++ incubator/sirona/trunk/server/reporting/reporting-api/src/main/java/org/apache/sirona/reporting/web/jmx/MBeanInformations.java Fri Sep 5 09:25:19 2014
@@ -0,0 +1,83 @@
+/*
+ * 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.sirona.reporting.web.jmx;
+
+import java.util.List;
+
+/**
+ * @since 0.3
+ */
+public class MBeanInformations
+{
+
+ private final String objectName;
+
+ private final String objectNameHash;
+
+ private final String classname;
+
+ private final String description;
+
+ private final List<MBeanAttribute> attributes;
+
+ private final List<MBeanOperation> operations;
+
+ public MBeanInformations( final String objectName, //
+ final String objectNameHash, //
+ final String classname, //
+ final String description, //
+ final List<MBeanAttribute> attributes, //
+ final List<MBeanOperation> operations )
+ {
+ this.objectName = objectName;
+ this.objectNameHash = objectNameHash;
+ this.classname = classname;
+ this.description = description;
+ this.attributes = attributes;
+ this.operations = operations;
+ }
+
+ public String getObjectName()
+ {
+ return objectName;
+ }
+
+ public String getObjectNameHash()
+ {
+ return objectNameHash;
+ }
+
+ public String getClassname()
+ {
+ return classname;
+ }
+
+ public String getDescription()
+ {
+ return description;
+ }
+
+ public List<MBeanAttribute> getAttributes()
+ {
+ return attributes;
+ }
+
+ public List<MBeanOperation> getOperations()
+ {
+ return operations;
+ }
+}
Propchange: incubator/sirona/trunk/server/reporting/reporting-api/src/main/java/org/apache/sirona/reporting/web/jmx/MBeanInformations.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/sirona/trunk/server/reporting/reporting-api/src/main/java/org/apache/sirona/reporting/web/jmx/MBeanInformations.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: incubator/sirona/trunk/server/reporting/reporting-api/src/main/java/org/apache/sirona/reporting/web/jmx/MBeanOperation.java
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/server/reporting/reporting-api/src/main/java/org/apache/sirona/reporting/web/jmx/MBeanOperation.java?rev=1622658&view=auto
==============================================================================
--- incubator/sirona/trunk/server/reporting/reporting-api/src/main/java/org/apache/sirona/reporting/web/jmx/MBeanOperation.java (added)
+++ incubator/sirona/trunk/server/reporting/reporting-api/src/main/java/org/apache/sirona/reporting/web/jmx/MBeanOperation.java Fri Sep 5 09:25:19 2014
@@ -0,0 +1,55 @@
+/*
+ * 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.sirona.reporting.web.jmx;
+
+import java.io.Serializable;
+import java.util.Collection;
+import java.util.LinkedList;
+
+/**
+ * @since 0.3
+ */
+public class MBeanOperation
+ implements Serializable
+{
+ private final String name;
+
+ private final String returnType;
+
+ private final Collection<MBeanParameter> parameters = new LinkedList<MBeanParameter>();
+
+ public MBeanOperation( final String name, final String returnType )
+ {
+ this.name = name;
+ this.returnType = returnType;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public String getReturnType()
+ {
+ return returnType;
+ }
+
+ public Collection<MBeanParameter> getParameters()
+ {
+ return parameters;
+ }
+}
Propchange: incubator/sirona/trunk/server/reporting/reporting-api/src/main/java/org/apache/sirona/reporting/web/jmx/MBeanOperation.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/sirona/trunk/server/reporting/reporting-api/src/main/java/org/apache/sirona/reporting/web/jmx/MBeanOperation.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: incubator/sirona/trunk/server/reporting/reporting-api/src/main/java/org/apache/sirona/reporting/web/jmx/MBeanParameter.java
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/server/reporting/reporting-api/src/main/java/org/apache/sirona/reporting/web/jmx/MBeanParameter.java?rev=1622658&view=auto
==============================================================================
--- incubator/sirona/trunk/server/reporting/reporting-api/src/main/java/org/apache/sirona/reporting/web/jmx/MBeanParameter.java (added)
+++ incubator/sirona/trunk/server/reporting/reporting-api/src/main/java/org/apache/sirona/reporting/web/jmx/MBeanParameter.java Fri Sep 5 09:25:19 2014
@@ -0,0 +1,47 @@
+/*
+ * 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.sirona.reporting.web.jmx;
+
+import java.io.Serializable;
+
+/**
+ * @since 0.3
+ */
+public class MBeanParameter
+ implements Serializable
+{
+ private final String name;
+
+ private final String type;
+
+ public MBeanParameter( final String name, final String type )
+ {
+ this.name = name;
+ this.type = type.replace( "java.lang.", "" );
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public String getType()
+ {
+ return type;
+ }
+}
Propchange: incubator/sirona/trunk/server/reporting/reporting-api/src/main/java/org/apache/sirona/reporting/web/jmx/MBeanParameter.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/sirona/trunk/server/reporting/reporting-api/src/main/java/org/apache/sirona/reporting/web/jmx/MBeanParameter.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Modified: incubator/sirona/trunk/server/reporting/reporting-ui/src/main/webapp/partials/jmx.html
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/server/reporting/reporting-ui/src/main/webapp/partials/jmx.html?rev=1622658&r1=1622657&r2=1622658&view=diff
==============================================================================
--- incubator/sirona/trunk/server/reporting/reporting-ui/src/main/webapp/partials/jmx.html (original)
+++ incubator/sirona/trunk/server/reporting/reporting-ui/src/main/webapp/partials/jmx.html Fri Sep 5 09:25:19 2014
@@ -20,7 +20,8 @@
<abn-tree tree-data="treeData" on-select="selectionHandler(branch)"></abn-tree>
</div>
<div class="col-lg-9">
- jmx detail: {{::mbean.description}}
+ <h1>{{::mbean.objectName}}</h1>
+ <h2>{{::mbean.classname}}</h2>
<ul class="nav nav-tabs" role="tablist">
<li class="active"><a href="#attributes" role="tab" data-toggle="tab">Attributes</a></li>
Modified: incubator/sirona/trunk/server/reporting/reporting-webapp/src/main/java/org/apache/sirona/reporting/web/plugin/jmx/JMXEndpoints.java
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/server/reporting/reporting-webapp/src/main/java/org/apache/sirona/reporting/web/plugin/jmx/JMXEndpoints.java?rev=1622658&r1=1622657&r2=1622658&view=diff
==============================================================================
--- incubator/sirona/trunk/server/reporting/reporting-webapp/src/main/java/org/apache/sirona/reporting/web/plugin/jmx/JMXEndpoints.java (original)
+++ incubator/sirona/trunk/server/reporting/reporting-webapp/src/main/java/org/apache/sirona/reporting/web/plugin/jmx/JMXEndpoints.java Fri Sep 5 09:25:19 2014
@@ -20,6 +20,9 @@ import org.apache.commons.codec.binary.B
import org.apache.sirona.SironaException;
import org.apache.sirona.configuration.Configuration;
import org.apache.sirona.reporting.web.jmx.JMXNode;
+import org.apache.sirona.reporting.web.jmx.MBeanAttribute;
+import org.apache.sirona.reporting.web.jmx.MBeanOperation;
+import org.apache.sirona.reporting.web.jmx.MBeanParameter;
import org.apache.sirona.reporting.web.plugin.api.MapBuilder;
import org.apache.sirona.reporting.web.plugin.api.Regex;
import org.apache.sirona.reporting.web.plugin.api.Template;
@@ -313,78 +316,4 @@ public class JMXEndpoints {
}
}
- public static class MBeanAttribute {
- private final String name;
- private final String type;
- private final String description;
- private final String value;
-
- public MBeanAttribute(final String name, final String type, final String description, final String value) {
- this.name = name;
- this.type = type;
- this.value = value;
- if (description != null) {
- this.description = description;
- } else {
- this.description = "No description";
- }
- }
-
- public String getName() {
- return name;
- }
-
- public String getType() {
- return type;
- }
-
- public String getDescription() {
- return description;
- }
-
- public String getValue() {
- return value;
- }
- }
-
- public static class MBeanOperation {
- private final String name;
- private final String returnType;
- private final Collection<MBeanParameter> parameters = new LinkedList<MBeanParameter>();
-
- public MBeanOperation(final String name, final String returnType) {
- this.name = name;
- this.returnType = returnType;
- }
-
- public String getName() {
- return name;
- }
-
- public String getReturnType() {
- return returnType;
- }
-
- public Collection<MBeanParameter> getParameters() {
- return parameters;
- }
- }
-
- public static class MBeanParameter {
- private final String name;
- private final String type;
-
- public MBeanParameter(final String name, final String type) {
- this.name = name;
- this.type = type.replace("java.lang.", "");
- }
-
- public String getName() {
- return name;
- }
-
- public String getType() {
- return type;
- }
- }
}