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/09 07:21:18 UTC
svn commit: r1623640 - in /incubator/sirona/trunk/server/reporting:
reporting-api/src/main/java/org/apache/sirona/reporting/web/jmx/
reporting-ui/src/main/webapp/js/app/controllers/
reporting-ui/src/main/webapp/partials/
Author: olamy
Date: Tue Sep 9 05:21:17 2014
New Revision: 1623640
URL: http://svn.apache.org/r1623640
Log:
better display for result
Added:
incubator/sirona/trunk/server/reporting/reporting-api/src/main/java/org/apache/sirona/reporting/web/jmx/JMXInvocationResult.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/js/app/controllers/controllers-jmx.js
incubator/sirona/trunk/server/reporting/reporting-ui/src/main/webapp/partials/jmx.html
Added: incubator/sirona/trunk/server/reporting/reporting-api/src/main/java/org/apache/sirona/reporting/web/jmx/JMXInvocationResult.java
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/server/reporting/reporting-api/src/main/java/org/apache/sirona/reporting/web/jmx/JMXInvocationResult.java?rev=1623640&view=auto
==============================================================================
--- incubator/sirona/trunk/server/reporting/reporting-api/src/main/java/org/apache/sirona/reporting/web/jmx/JMXInvocationResult.java (added)
+++ incubator/sirona/trunk/server/reporting/reporting-api/src/main/java/org/apache/sirona/reporting/web/jmx/JMXInvocationResult.java Tue Sep 9 05:21:17 2014
@@ -0,0 +1,106 @@
+/*
+ * 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.List;
+import java.util.Map;
+
+/**
+ * @since 0.3
+ */
+public class JMXInvocationResult
+ implements Serializable
+{
+
+ private String errorMessage;
+
+ private List<String> results;
+
+ private Map<String, String> mapResult;
+
+ public JMXInvocationResult()
+ {
+ // no op
+ }
+
+ public JMXInvocationResult( String errorMessage, List<String> results, Map<String, String> mapResult )
+ {
+ this.errorMessage = errorMessage;
+ this.results = results;
+ this.mapResult = mapResult;
+ }
+
+ public String getErrorMessage()
+ {
+ return errorMessage;
+ }
+
+ public void setErrorMessage( String errorMessage )
+ {
+ this.errorMessage = errorMessage;
+ }
+
+ public JMXInvocationResult errorMessage( String errorMessage )
+ {
+ this.errorMessage = errorMessage;
+ return this;
+ }
+
+ public List<String> getResults()
+ {
+ return results;
+ }
+
+ public void setResults( List<String> results )
+ {
+ this.results = results;
+ }
+
+ public JMXInvocationResult results( List<String> results )
+ {
+ this.results = results;
+ return this;
+ }
+
+ public Map<String, String> getMapResult()
+ {
+ return mapResult;
+ }
+
+ public void setMapResult( Map<String, String> mapResult )
+ {
+ this.mapResult = mapResult;
+ }
+
+ public JMXInvocationResult mapResult( Map<String, String> mapResult )
+ {
+ this.mapResult = mapResult;
+ return this;
+ }
+
+ @Override
+ public String toString()
+ {
+ return "JMXInvocationResult{" +
+ "errorMessage='" + errorMessage + '\'' +
+ ", results=" + results +
+ ", mapResult=" + mapResult +
+ '}';
+ }
+}
Propchange: incubator/sirona/trunk/server/reporting/reporting-api/src/main/java/org/apache/sirona/reporting/web/jmx/JMXInvocationResult.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/sirona/trunk/server/reporting/reporting-api/src/main/java/org/apache/sirona/reporting/web/jmx/JMXInvocationResult.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
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=1623640&r1=1623639&r2=1623640&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 Tue Sep 9 05:21:17 2014
@@ -19,6 +19,7 @@ package org.apache.sirona.reporting.web.
import org.apache.commons.codec.binary.Base64;
import org.apache.sirona.SironaException;
import org.apache.sirona.configuration.Configuration;
+import org.apache.sirona.util.ClassLoaders;
import javax.management.InstanceNotFoundException;
import javax.management.IntrospectionException;
@@ -47,12 +48,12 @@ import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
+import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
-import org.apache.sirona.util.ClassLoaders;
/**
* @since 0.3
@@ -130,7 +131,8 @@ public class JMXServices
@POST
@Consumes( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
- public String invoke( JMXInvocationRequest request )
+ @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
+ public JMXInvocationResult invoke( JMXInvocationRequest request )
{
if ( !METHOD_INVOCATION_ALLOWED )
@@ -155,20 +157,16 @@ public class JMXServices
}
final Object result = server.invoke( name, request.getOperationName(),
convertParams( signature, request.getParameters() ), sign );
- return "<div>Method was invoked and returned:</div>" + value( result );
+ return value( result );
}
}
}
catch ( final Exception e )
{
- return "<div class=\"alert alert-error\">\n" +
- "\n" + e.getMessage() + "\n" +
- "</div>";
+ return new JMXInvocationResult().errorMessage( e.getMessage() );
}
- return "<div class=\"alert alert-error\">Operation" + request.getOperationName() + " not found.</div>";
-
-
+ return new JMXInvocationResult().errorMessage( request.getOperationName() + " not found" );
}
private Object[] convertParams( final MBeanParameterInfo[] signature, final List<String> params )
@@ -314,31 +312,30 @@ public class JMXServices
}
catch ( final Exception e )
{
- value = "<div class=\"alert-error\">" + e.getMessage() + "</div>";
+ value = e.getMessage();
}
- list.add( new MBeanAttribute( attribute.getName(), nullProtection( attribute.getType() ),
- nullProtection( attribute.getDescription() ), value( value ) ) );
+ list.add( new MBeanAttribute( attribute.getName(), //
+ nullProtection( attribute.getType() ), //
+ nullProtection( attribute.getDescription() ), //
+ value == null ? "" : value.toString() ) );
}
return list;
}
public static String nullProtection( final String value )
{
- if ( value == null )
- {
- return EMPTY_STRING;
- }
- return value;
+ return ( value == null ) ? EMPTY_STRING : value;
}
+
// FIXME this html stuff here is just weird!!!
- private static String value( final Object value )
+ private static JMXInvocationResult value( final Object value )
{
try
{
if ( value == null )
{
- return nullProtection( null );
+ return new JMXInvocationResult();
}
if ( value.getClass().isArray() )
@@ -346,48 +343,53 @@ public class JMXServices
final int length = Array.getLength( value );
if ( length == 0 )
{
- return "";
+ return new JMXInvocationResult();
}
- final StringBuilder builder = new StringBuilder().append( "<ul>" );
+ List<String> results = new ArrayList<String>( length );
for ( int i = 0; i < length; i++ )
{
- builder.append( "<li>" ).append( value( Array.get( value, i ) ) ).append( "</li>" );
+ Object o = Array.get( value, i );
+ if ( o != null )
+ {
+ results.add( o.toString() );
+ }
}
- builder.append( "</ul>" );
- return builder.toString();
+ return new JMXInvocationResult().results( results );
}
if ( Collection.class.isInstance( value ) )
{
- final StringBuilder builder = new StringBuilder().append( "<ul>" );
+ List<String> results = new ArrayList<String>();
for ( final Object o : Collection.class.cast( value ) )
{
- builder.append( "<li>" ).append( value( o ) ).append( "</li>" );
+ if ( o != null )
+ {
+ results.add( o.toString() );
+ }
}
- builder.append( "</ul>" );
- return builder.toString();
+ return new JMXInvocationResult().results( results );
}
if ( TabularData.class.isInstance( value ) )
{
final TabularData td = TabularData.class.cast( value );
- final StringBuilder builder = new StringBuilder().append( "<table class=\"table table-condensed\">" );
+ List<String> results = new ArrayList<String>();
+ //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>" );
+ Object o = data.get( k );
+ if ( o != null )
+ {
+ results.add( o.toString() );
+ }
}
- builder.append( "</tr>" );
}
- builder.append( "</table>" );
-
- return builder.toString();
+ return new JMXInvocationResult().results( results );
}
if ( CompositeData.class.isInstance( value ) )
@@ -395,39 +397,35 @@ public class JMXServices
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\">" );
+ Map<String, String> results = new HashMap<String, String>();
+
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();
+ Object o = cd.get( type );
+ results.put( type, o != null ? o.toString() : "" );
+ }
+ return new JMXInvocationResult().mapResult( results );
}
if ( Map.class.isInstance( value ) )
{
final Map<?, ?> map = Map.class.cast( value );
- final StringBuilder builder = new StringBuilder().append( "<table class=\"table table-condensed\">" );
+ Map<String, String> results = new HashMap<String, String>();
+
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>" );
+ results.put( entry.getKey().toString(), entry.getValue().toString() );
}
- builder.append( "</table>" );
-
- return builder.toString();
-
+ return new JMXInvocationResult().mapResult( results );
}
- return value.toString();
+ return new JMXInvocationResult().results( Collections.singletonList( value.toString() ) );
}
catch ( final Exception e )
{
- throw new SironaException( e );
+ throw new SironaException( e.getMessage(), e );
}
}
Modified: incubator/sirona/trunk/server/reporting/reporting-ui/src/main/webapp/js/app/controllers/controllers-jmx.js
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/server/reporting/reporting-ui/src/main/webapp/js/app/controllers/controllers-jmx.js?rev=1623640&r1=1623639&r2=1623640&view=diff
==============================================================================
--- incubator/sirona/trunk/server/reporting/reporting-ui/src/main/webapp/js/app/controllers/controllers-jmx.js (original)
+++ incubator/sirona/trunk/server/reporting/reporting-ui/src/main/webapp/js/app/controllers/controllers-jmx.js Tue Sep 9 05:21:17 2014
@@ -56,7 +56,11 @@ define(['jquery','angular','bootstrap','
var request={ mbeanEncodedName: base64, operationName: name, parameters: parameters };
- jmx.invoke({ mbeanEncodedName: base64, operationName: name, parameters: parameters });
+ jmx.invoke({ mbeanEncodedName: base64, operationName: name, parameters: parameters })
+ .$promise.then(function(result){
+ $scope.invokeResult=result;
+ });
+
};
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=1623640&r1=1623639&r2=1623640&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 Tue Sep 9 05:21:17 2014
@@ -23,6 +23,8 @@
<h1>{{mbean.objectName}}</h1>
<h2>{{mbean.classname}}</h2>
+ <div id="invoke-result">{{invokeResult}}</div>
+
<ul class="nav nav-tabs" role="tablist">
<li class="active"><a href="#attributes" role="tab" data-toggle="tab">Attributes</a></li>
<li><a href="#operations" role="tab" data-toggle="tab">Operations</a></li>