You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by da...@apache.org on 2011/10/31 16:02:19 UTC
svn commit: r1195503 - in /aries/trunk/sandbox/jmx-next:
jmx-api/src/main/java/org/osgi/jmx/
jmx-core/src/main/java/org/apache/aries/jmx/codec/
jmx-core/src/main/java/org/apache/aries/jmx/util/
jmx-itests/src/test/java/org/apache/aries/jmx/framework/
Author: davidb
Date: Mon Oct 31 15:02:18 2011
New Revision: 1195503
URL: http://svn.apache.org/viewvc?rev=1195503&view=rev
Log:
FInish getCurrentWiring itest.
Modified:
aries/trunk/sandbox/jmx-next/jmx-api/src/main/java/org/osgi/jmx/JmxConstants.java
aries/trunk/sandbox/jmx-next/jmx-core/src/main/java/org/apache/aries/jmx/codec/BundleWiringData.java
aries/trunk/sandbox/jmx-next/jmx-core/src/main/java/org/apache/aries/jmx/util/TypeUtils.java
aries/trunk/sandbox/jmx-next/jmx-itests/src/test/java/org/apache/aries/jmx/framework/BundleRevisionsStateMBeanTest.java
Modified: aries/trunk/sandbox/jmx-next/jmx-api/src/main/java/org/osgi/jmx/JmxConstants.java
URL: http://svn.apache.org/viewvc/aries/trunk/sandbox/jmx-next/jmx-api/src/main/java/org/osgi/jmx/JmxConstants.java?rev=1195503&r1=1195502&r2=1195503&view=diff
==============================================================================
--- aries/trunk/sandbox/jmx-next/jmx-api/src/main/java/org/osgi/jmx/JmxConstants.java (original)
+++ aries/trunk/sandbox/jmx-next/jmx-api/src/main/java/org/osgi/jmx/JmxConstants.java Mon Oct 31 15:02:18 2011
@@ -1,6 +1,6 @@
/*
* Copyright (c) OSGi Alliance (2009). All Rights Reserved.
- *
+ *
* Licensed 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
@@ -27,11 +27,11 @@ import javax.management.openmbean.Tabula
/**
* Constants for OSGi JMX Specification.
- *
+ *
* Additionally, this class contains a number of utility types that are used in
* different places in the specification. These are {@link #LONG_ARRAY_TYPE},
* {@link #STRING_ARRAY_TYPE}, and {@link #PROPERTIES_TYPE}.
- *
+ *
* @version $Rev$
* @Immutable
*/
@@ -62,7 +62,7 @@ public class JmxConstants {
/**
* For an encoded array we need to start with ARRAY_OF. This must be
* followed by one of the names in {@link #SCALAR}.
- *
+ *
*/
public final static String ARRAY_OF = "Array of ";
@@ -72,6 +72,11 @@ public class JmxConstants {
*/
public final static String VECTOR_OF = "Vector of ";
+ /**
+ * Value for {@link #PROPERTY_TYPE} <code>Type</code> value in the case of
+ * {@link org.osgi.framework.Version}
+ */
+ public static final String VERSION = "Version";
/**
* Value for {@link #PROPERTY_TYPE} <code>Type</code> value in the case of
* {@link java.lang.String}
@@ -242,7 +247,7 @@ public class JmxConstants {
/**
* The key PROPERTY_TYPE.
- *
+ *
* ### can we call this value PropertyType and service type ServiceType?
*/
public static final String TYPE = "Type";
@@ -250,11 +255,11 @@ public class JmxConstants {
/**
* The type of the property. The key is {@link #TYPE} and the type is
* {@link SimpleType#STRING}. This string must follow the following syntax:
- *
+ *
* TYPE ::= ( 'Array of ' | 'Vector of ' )? {@link #SCALAR}
- *
+ *
* ### why can't we just use the class name?
- *
+ *
* ### why do we have to distinguish between primitives and wrappers?
*/
public static final Item TYPE_ITEM = new Item(
Modified: aries/trunk/sandbox/jmx-next/jmx-core/src/main/java/org/apache/aries/jmx/codec/BundleWiringData.java
URL: http://svn.apache.org/viewvc/aries/trunk/sandbox/jmx-next/jmx-core/src/main/java/org/apache/aries/jmx/codec/BundleWiringData.java?rev=1195503&r1=1195502&r2=1195503&view=diff
==============================================================================
--- aries/trunk/sandbox/jmx-next/jmx-core/src/main/java/org/apache/aries/jmx/codec/BundleWiringData.java (original)
+++ aries/trunk/sandbox/jmx-next/jmx-core/src/main/java/org/apache/aries/jmx/codec/BundleWiringData.java Mon Oct 31 15:02:18 2011
@@ -31,7 +31,6 @@ import javax.management.openmbean.Tabula
import org.osgi.framework.wiring.BundleCapability;
import org.osgi.framework.wiring.BundleRequirement;
import org.osgi.framework.wiring.BundleWire;
-import org.osgi.framework.wiring.BundleWiring;
import org.osgi.jmx.framework.BundleRevisionsStateMBean;
public class BundleWiringData {
@@ -55,31 +54,7 @@ public class BundleWiringData {
items.put(BundleRevisionsStateMBean.REQUIREMENTS, getRequirements());
items.put(BundleRevisionsStateMBean.CAPABILITIES, getCapabilities());
-
- CompositeData[] reqWiresData = new CompositeData[requiredWires.size()];
- for (int i=0; i < requiredWires.size(); i++) {
- BundleWire requiredWire = requiredWires.get(i);
- Map<String, Object> wireItems = new HashMap<String, Object>();
- BundleWiring providerWiring = requiredWire.getProviderWiring();
- wireItems.put(BundleRevisionsStateMBean.PROVIDER_BUNDLE_ID, providerWiring.getBundle().getBundleId());
- wireItems.put(BundleRevisionsStateMBean.PROVIDER_BUNDLE_REVISION_ID, null); // TODO
- BundleWiring requirerWiring = requiredWire.getRequirerWiring();
- wireItems.put(BundleRevisionsStateMBean.REQUIRER_BUNDLE_ID, requirerWiring.getBundle().getBundleId());
- wireItems.put(BundleRevisionsStateMBean.REQUIRER_BUNDLE_REVISION_ID, null); // TODO
- BundleCapability capability = requiredWire.getCapability();
- wireItems.put(BundleRevisionsStateMBean.BUNDLE_CAPABILITY,
- getCapReqCompositeData(BundleRevisionsStateMBean.BUNDLE_CAPABILITY_TYPE,
- capability.getNamespace(), capability.getAttributes().entrySet(), capability.getDirectives().entrySet()));
- BundleRequirement requirement = requiredWire.getRequirement();
- wireItems.put(BundleRevisionsStateMBean.BUNDLE_REQUIREMENT,
- getCapReqCompositeData(BundleRevisionsStateMBean.BUNDLE_REQUIREMENT_TYPE,
- requirement.getNamespace(), requirement.getAttributes().entrySet(), requirement.getDirectives().entrySet()));
-
- CompositeData wireData = new CompositeDataSupport(BundleRevisionsStateMBean.BUNDLE_WIRE_TYPE, wireItems);
- reqWiresData[i] = wireData;
- }
-
- items.put(BundleRevisionsStateMBean.BUNDLE_WIRES_TYPE, reqWiresData);
+ items.put(BundleRevisionsStateMBean.BUNDLE_WIRES_TYPE, getRequiredWires());
return new CompositeDataSupport(BundleRevisionsStateMBean.BUNDLE_WIRING_TYPE, items);
} catch (OpenDataException e) {
@@ -130,4 +105,31 @@ public class BundleWiringData {
CompositeData req = new CompositeDataSupport(type, reqItems);
return req;
}
+
+ private CompositeData[] getRequiredWires() throws OpenDataException {
+ CompositeData[] reqWiresData = new CompositeData[requiredWires.size()];
+ for (int i=0; i < requiredWires.size(); i++) {
+ BundleWire requiredWire = requiredWires.get(i);
+ Map<String, Object> wireItems = new HashMap<String, Object>();
+
+ BundleCapability capability = requiredWire.getCapability();
+ wireItems.put(BundleRevisionsStateMBean.PROVIDER_BUNDLE_ID, capability.getRevision().getBundle().getBundleId());
+ wireItems.put(BundleRevisionsStateMBean.PROVIDER_BUNDLE_REVISION_ID, null); // TODO
+ wireItems.put(BundleRevisionsStateMBean.BUNDLE_CAPABILITY,
+ getCapReqCompositeData(BundleRevisionsStateMBean.BUNDLE_CAPABILITY_TYPE,
+ capability.getNamespace(), capability.getAttributes().entrySet(), capability.getDirectives().entrySet()));
+
+ BundleRequirement requirement = requiredWire.getRequirement();
+ wireItems.put(BundleRevisionsStateMBean.REQUIRER_BUNDLE_ID, requirement.getRevision().getBundle().getBundleId());
+ wireItems.put(BundleRevisionsStateMBean.REQUIRER_BUNDLE_REVISION_ID, null); // TODO
+
+ wireItems.put(BundleRevisionsStateMBean.BUNDLE_REQUIREMENT,
+ getCapReqCompositeData(BundleRevisionsStateMBean.BUNDLE_REQUIREMENT_TYPE,
+ requirement.getNamespace(), requirement.getAttributes().entrySet(), requirement.getDirectives().entrySet()));
+
+ CompositeData wireData = new CompositeDataSupport(BundleRevisionsStateMBean.BUNDLE_WIRE_TYPE, wireItems);
+ reqWiresData[i] = wireData;
+ }
+ return reqWiresData;
+ }
}
Modified: aries/trunk/sandbox/jmx-next/jmx-core/src/main/java/org/apache/aries/jmx/util/TypeUtils.java
URL: http://svn.apache.org/viewvc/aries/trunk/sandbox/jmx-next/jmx-core/src/main/java/org/apache/aries/jmx/util/TypeUtils.java?rev=1195503&r1=1195502&r2=1195503&view=diff
==============================================================================
--- aries/trunk/sandbox/jmx-next/jmx-core/src/main/java/org/apache/aries/jmx/util/TypeUtils.java (original)
+++ aries/trunk/sandbox/jmx-next/jmx-core/src/main/java/org/apache/aries/jmx/util/TypeUtils.java Mon Oct 31 15:02:18 2011
@@ -35,6 +35,7 @@ import static org.osgi.jmx.JmxConstants.
import static org.osgi.jmx.JmxConstants.P_SHORT;
import static org.osgi.jmx.JmxConstants.SHORT;
import static org.osgi.jmx.JmxConstants.STRING;
+import static org.osgi.jmx.JmxConstants.VERSION;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
@@ -46,9 +47,11 @@ import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
+import org.osgi.framework.Version;
+
/**
* This class provides common utilities related to type conversions for the MBean implementations
- *
+ *
* @version $Rev$ $Date$
*/
public class TypeUtils {
@@ -87,6 +90,7 @@ public class TypeUtils {
wrapperTypes.put(SHORT, Short.class);
wrapperTypes.put(BOOLEAN, Boolean.class);
wrapperTypes.put(CHARACTER, Character.class);
+ wrapperTypes.put(VERSION, Version.class);
mathTypes.put(BIGDECIMAL, BigDecimal.class);
mathTypes.put(BIGINTEGER, BigInteger.class);
types.put(STRING, String.class);
@@ -97,7 +101,7 @@ public class TypeUtils {
/**
* Converts a <code>Dictionary</code> object to a <code>Map</code>
- *
+ *
* @param dictionary
* @return
*/
@@ -113,7 +117,7 @@ public class TypeUtils {
/**
* Converts primitive long[] array to Long[]
- *
+ *
* @param array
* @return
*/
@@ -127,7 +131,7 @@ public class TypeUtils {
/**
* Converts Long[] array to primitive
- *
+ *
* @param array
* @return
*/
@@ -141,7 +145,7 @@ public class TypeUtils {
/**
* Converts a String value to an Object of the specified type
- *
+ *
* @param type
* one of types listed in {@link #types}
* @param value
@@ -175,7 +179,7 @@ public class TypeUtils {
String parseMethodName = "parse" + new String(simpleTypeName);
Method parseMethod = promotedType.getDeclaredMethod(parseMethodName, String.class);
result = (T) parseMethod.invoke(null, value);
- }
+ }
} catch (SecurityException e) {
throw new IllegalArgumentException("Cannot convert value [" + value + "] to type [" + type + "]", e);
} catch (NoSuchMethodException e) {
Modified: aries/trunk/sandbox/jmx-next/jmx-itests/src/test/java/org/apache/aries/jmx/framework/BundleRevisionsStateMBeanTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/sandbox/jmx-next/jmx-itests/src/test/java/org/apache/aries/jmx/framework/BundleRevisionsStateMBeanTest.java?rev=1195503&r1=1195502&r2=1195503&view=diff
==============================================================================
--- aries/trunk/sandbox/jmx-next/jmx-itests/src/test/java/org/apache/aries/jmx/framework/BundleRevisionsStateMBeanTest.java (original)
+++ aries/trunk/sandbox/jmx-next/jmx-itests/src/test/java/org/apache/aries/jmx/framework/BundleRevisionsStateMBeanTest.java Mon Oct 31 15:02:18 2011
@@ -24,22 +24,26 @@ import static org.ops4j.pax.swissbox.tin
import static org.ops4j.pax.swissbox.tinybundles.core.TinyBundles.withBnd;
import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import javax.management.ObjectName;
import javax.management.openmbean.CompositeData;
+import javax.management.openmbean.TabularData;
import org.apache.aries.jmx.AbstractIntegrationTest;
+import org.apache.aries.jmx.codec.PropertyData;
import org.junit.Assert;
import org.junit.Test;
import org.ops4j.pax.exam.CoreOptions;
import org.ops4j.pax.exam.Option;
import org.ops4j.pax.exam.container.def.PaxRunnerOptions;
-import org.ops4j.pax.exam.container.def.options.VMOption;
import org.ops4j.pax.exam.junit.Configuration;
-import org.ops4j.pax.exam.options.TimeoutOption;
import org.osgi.framework.Bundle;
import org.osgi.framework.Constants;
import org.osgi.framework.wiring.BundleCapability;
@@ -50,18 +54,12 @@ import org.osgi.framework.wiring.BundleW
import org.osgi.jmx.framework.BundleRevisionsStateMBean;
import org.osgi.jmx.framework.PackageStateMBean;
-/**
- *
- *
- * @version $Rev: 1190259 $ $Date: 2011-10-28 12:46:48 +0100 (Fri, 28 Oct 2011) $
- */
public class BundleRevisionsStateMBeanTest extends AbstractIntegrationTest {
-
@Configuration
public static Option[] configuration() {
return testOptions(
- new VMOption( "-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000" ),
- new TimeoutOption( 0 ),
+ // new VMOption( "-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000" ),
+ // new TimeoutOption( 0 ),
PaxRunnerOptions.rawPaxRunnerOption("config", "classpath:ss-runner.properties"),
CoreOptions.equinox().version("3.7.0.v20110613"),
@@ -120,34 +118,111 @@ public class BundleRevisionsStateMBeanTe
}
@Test
- public void testMBeanInterface() throws IOException {
+ public void testGetCurrentWiring() throws IOException {
BundleRevisionsStateMBean brsMBean = getMBean(BundleRevisionsStateMBean.OBJECTNAME, BundleRevisionsStateMBean.class);
Bundle a = context().getBundleByName("org.apache.aries.jmx.test.bundlea");
+ CompositeData jmxWiring = brsMBean.getCurrentWiring(a.getBundleId(), BundleRevisionsStateMBean.PACKAGE_NAMESPACE);
- CompositeData wiring = brsMBean.getCurrentWiring(a.getBundleId(), BundleRevisionsStateMBean.PACKAGE_NAMESPACE);
-
- Assert.assertEquals(BundleRevisionsStateMBean.BUNDLE_WIRING_TYPE, wiring.getCompositeType());
- Assert.assertEquals(a.getBundleId(), wiring.get(BundleRevisionsStateMBean.BUNDLE_ID));
+ Assert.assertEquals(BundleRevisionsStateMBean.BUNDLE_WIRING_TYPE, jmxWiring.getCompositeType());
+ Assert.assertEquals(a.getBundleId(), jmxWiring.get(BundleRevisionsStateMBean.BUNDLE_ID));
BundleWiring bw = a.adapt(BundleWiring.class);
- CompositeData[] jmxCapabilities = (CompositeData[]) wiring.get(BundleRevisionsStateMBean.CAPABILITIES);
+ CompositeData[] jmxCapabilities = (CompositeData[]) jmxWiring.get(BundleRevisionsStateMBean.CAPABILITIES);
List<BundleCapability> capabilities = bw.getCapabilities(BundleRevision.PACKAGE_NAMESPACE);
Assert.assertEquals(capabilities.size(), jmxCapabilities.length);
- Map<Map<String, Object>, Map<String, String>> m = new HashMap<Map<String,Object>, Map<String,String>>();
- for (BundleCapability cap : capabilities) {
- m.put(cap.getAttributes(), cap.getDirectives());
- }
+ Map<Map<String, Object>, Map<String, String>> expectedCapabilities = capabilitiesToMap(capabilities);
+ Map<Map<String, Object>, Map<String, String>> actualCapabilities = jmxCapReqToMap(jmxCapabilities);
+ Assert.assertEquals(expectedCapabilities, actualCapabilities);
- CompositeData[] jmxRequirements = (CompositeData[]) wiring.get(BundleRevisionsStateMBean.REQUIREMENTS);
+ CompositeData[] jmxRequirements = (CompositeData[]) jmxWiring.get(BundleRevisionsStateMBean.REQUIREMENTS);
List<BundleRequirement> requirements = bw.getRequirements(BundleRevision.PACKAGE_NAMESPACE);
Assert.assertEquals(requirements.size(), jmxRequirements.length);
+ Map<Map<String, Object>, Map<String, String>> expectedRequirements = requirementsToMap(requirements);
+ Map<Map<String, Object>, Map<String, String>> actualRequirements = jmxCapReqToMap(jmxRequirements);
+ Assert.assertEquals(expectedRequirements, actualRequirements);
+
List<BundleWire> requiredWires = bw.getRequiredWires(BundleRevision.PACKAGE_NAMESPACE);
- CompositeData[] jmxRequiredWires = (CompositeData[]) wiring.get(BundleRevisionsStateMBean.BUNDLE_WIRES_TYPE);
- // currently the wires only contains the required wires.
+ CompositeData[] jmxRequiredWires = (CompositeData[]) jmxWiring.get(BundleRevisionsStateMBean.BUNDLE_WIRES_TYPE);
+ // currently the wires only contains the required wires
+ // should we have separate JMX slots for provided and required wires instead?
Assert.assertEquals(requiredWires.size(), jmxRequiredWires.length);
+ Set<List<Object>> expectedWires = new HashSet<List<Object>>();
+ for (BundleWire wire : requiredWires) {
+ List<Object> data = new ArrayList<Object>();
+
+ data.add(wire.getCapability().getRevision().getBundle().getBundleId());
+ data.add(wire.getCapability().getAttributes());
+ data.add(wire.getCapability().getDirectives());
+ data.add(wire.getRequirement().getRevision().getBundle().getBundleId());
+ data.add(wire.getRequirement().getAttributes());
+ data.add(wire.getRequirement().getDirectives());
+ expectedWires.add(data);
+ }
+
+ Set<List<Object>> actualWires = new HashSet<List<Object>>();
+ for (CompositeData wire : jmxRequiredWires) {
+ List<Object> data = new ArrayList<Object>();
+ data.add(wire.get(BundleRevisionsStateMBean.PROVIDER_BUNDLE_ID));
+ // TODO bundle revision id
+ data.add(getJmxAttributes((CompositeData) wire.get(BundleRevisionsStateMBean.BUNDLE_CAPABILITY)));
+ data.add(getJmxDirectives((CompositeData) wire.get(BundleRevisionsStateMBean.BUNDLE_CAPABILITY)));
+ data.add(wire.get(BundleRevisionsStateMBean.REQUIRER_BUNDLE_ID));
+ data.add(getJmxAttributes((CompositeData) wire.get(BundleRevisionsStateMBean.BUNDLE_REQUIREMENT)));
+ data.add(getJmxDirectives((CompositeData) wire.get(BundleRevisionsStateMBean.BUNDLE_REQUIREMENT)));
+ actualWires.add(data);
+ }
+
+ Assert.assertEquals(expectedWires, actualWires);
+ }
+
+ private Map<Map<String, Object>, Map<String, String>> capabilitiesToMap(List<BundleCapability> capabilities) {
+ Map<Map<String, Object>, Map<String, String>> map = new HashMap<Map<String,Object>, Map<String,String>>();
+ for (BundleCapability cap : capabilities) {
+ map.put(cap.getAttributes(), cap.getDirectives());
+ }
+ return map;
+ }
+
+ private Map<Map<String, Object>, Map<String, String>> requirementsToMap(List<BundleRequirement> requirements) {
+ Map<Map<String, Object>, Map<String, String>> map = new HashMap<Map<String,Object>, Map<String,String>>();
+ for (BundleRequirement req : requirements) {
+ map.put(req.getAttributes(), req.getDirectives());
+ }
+ return map;
+ }
+
+ private Map<Map<String, Object>, Map<String, String>> jmxCapReqToMap(CompositeData[] jmxCapabilitiesOrRequirements) {
+ Map<Map<String, Object>, Map<String, String>> actualCapabilities = new HashMap<Map<String,Object>, Map<String,String>>();
+ for (CompositeData jmxCapReq : jmxCapabilitiesOrRequirements) {
+ Map<String, Object> aMap = getJmxAttributes(jmxCapReq);
+ Map<String, String> dMap = getJmxDirectives(jmxCapReq);
+ actualCapabilities.put(aMap, dMap);
+ }
+ return actualCapabilities;
+ }
+
+ @SuppressWarnings("unchecked")
+ private Map<String, Object> getJmxAttributes(CompositeData jmxCapReq) {
+ TabularData jmxAttributes = (TabularData) jmxCapReq.get(BundleRevisionsStateMBean.ATTRIBUTES);
+ Map<String, Object> aMap = new HashMap<String, Object>();
+ for (CompositeData jmxAttr : (Collection<CompositeData>) jmxAttributes.values()) {
+ PropertyData<Object> pd = PropertyData.from(jmxAttr);
+ aMap.put(pd.getKey(), pd.getValue());
+ }
+ return aMap;
+ }
+
+ @SuppressWarnings("unchecked")
+ private Map<String, String> getJmxDirectives(CompositeData jmxCapReq) {
+ TabularData jmxDirectives = (TabularData) jmxCapReq.get(BundleRevisionsStateMBean.DIRECTIVES);
+ Map<String, String> dMap = new HashMap<String, String>();
+ for (CompositeData jmxDir : (Collection<CompositeData>) jmxDirectives.values()) {
+ dMap.put((String) jmxDir.get(BundleRevisionsStateMBean.KEY), (String) jmxDir.get(BundleRevisionsStateMBean.VALUE));
+ }
+ return dMap;
}
}