Search in sources :

Example 56 with CompositeData

use of javax.management.openmbean.CompositeData in project aries by apache.

the class BundleWiringStateMBeanTest method getJmxAttributes.

@SuppressWarnings("unchecked")
private Map<String, Object> getJmxAttributes(CompositeData jmxCapReq) {
    TabularData jmxAttributes = (TabularData) jmxCapReq.get(BundleWiringStateMBean.ATTRIBUTES);
    Map<String, Object> aMap = new HashMap<String, Object>();
    for (CompositeData jmxAttr : (Collection<CompositeData>) jmxAttributes.values()) {
        PropertyData<Object> pd = PropertyData.from(jmxAttr);
        Object val = pd.getValue();
        if (val instanceof Object[]) {
            val = Arrays.asList((Object[]) val);
        }
        aMap.put(pd.getKey(), val);
    }
    return aMap;
}
Also used : HashMap(java.util.HashMap) CompositeData(javax.management.openmbean.CompositeData) Collection(java.util.Collection) TabularData(javax.management.openmbean.TabularData)

Example 57 with CompositeData

use of javax.management.openmbean.CompositeData in project aries by apache.

the class BundleWiringStateMBeanTest method getJmxDirectives.

@SuppressWarnings("unchecked")
private Map<String, String> getJmxDirectives(CompositeData jmxCapReq) {
    TabularData jmxDirectives = (TabularData) jmxCapReq.get(BundleWiringStateMBean.DIRECTIVES);
    Map<String, String> dMap = new HashMap<String, String>();
    for (CompositeData jmxDir : (Collection<CompositeData>) jmxDirectives.values()) {
        dMap.put((String) jmxDir.get(BundleWiringStateMBean.KEY), (String) jmxDir.get(BundleWiringStateMBean.VALUE));
    }
    return dMap;
}
Also used : HashMap(java.util.HashMap) CompositeData(javax.management.openmbean.CompositeData) Collection(java.util.Collection) TabularData(javax.management.openmbean.TabularData)

Example 58 with CompositeData

use of javax.management.openmbean.CompositeData in project aries by apache.

the class BundleWiringStateMBeanTest method assertBundleWiring.

private void assertBundleWiring(BundleWiring bundleWiring, CompositeData jmxWiring) {
    CompositeData[] jmxCapabilities = (CompositeData[]) jmxWiring.get(BundleWiringStateMBean.CAPABILITIES);
    List<BundleCapability> capabilities = bundleWiring.getCapabilities(BundleRevision.PACKAGE_NAMESPACE);
    Assert.assertEquals(capabilities.size(), jmxCapabilities.length);
    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[]) jmxWiring.get(BundleWiringStateMBean.REQUIREMENTS);
    List<BundleRequirement> requirements = bundleWiring.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 = bundleWiring.getRequiredWires(BundleRevision.PACKAGE_NAMESPACE);
    CompositeData[] jmxRequiredWires = (CompositeData[]) jmxWiring.get(BundleWiringStateMBean.REQUIRED_WIRES);
    Assert.assertEquals(requiredWires.size(), jmxRequiredWires.length);
    Set<List<Object>> expectedRequiredWires = 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());
        expectedRequiredWires.add(data);
    }
    Set<List<Object>> actualRequiredWires = new HashSet<List<Object>>();
    for (CompositeData wire : jmxRequiredWires) {
        List<Object> data = new ArrayList<Object>();
        data.add(wire.get(BundleWiringStateMBean.PROVIDER_BUNDLE_ID));
        // TODO bundle revision id
        data.add(getJmxAttributes((CompositeData) wire.get(BundleWiringStateMBean.BUNDLE_CAPABILITY)));
        data.add(getJmxDirectives((CompositeData) wire.get(BundleWiringStateMBean.BUNDLE_CAPABILITY)));
        data.add(wire.get(BundleWiringStateMBean.REQUIRER_BUNDLE_ID));
        data.add(getJmxAttributes((CompositeData) wire.get(BundleWiringStateMBean.BUNDLE_REQUIREMENT)));
        data.add(getJmxDirectives((CompositeData) wire.get(BundleWiringStateMBean.BUNDLE_REQUIREMENT)));
        actualRequiredWires.add(data);
    }
    Assert.assertEquals(expectedRequiredWires, actualRequiredWires);
    List<BundleWire> providedWires = bundleWiring.getProvidedWires(BundleRevision.PACKAGE_NAMESPACE);
    CompositeData[] jmxProvidedWires = (CompositeData[]) jmxWiring.get(BundleWiringStateMBean.PROVIDED_WIRES);
    Assert.assertEquals(providedWires.size(), jmxProvidedWires.length);
    HashSet<List<Object>> expectedProvidedWires = new HashSet<List<Object>>();
    for (BundleWire wire : providedWires) {
        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());
        expectedProvidedWires.add(data);
    }
    Set<List<Object>> actualProvidedWires = new HashSet<List<Object>>();
    for (CompositeData wire : jmxProvidedWires) {
        List<Object> data = new ArrayList<Object>();
        data.add(wire.get(BundleWiringStateMBean.PROVIDER_BUNDLE_ID));
        data.add(getJmxAttributes((CompositeData) wire.get(BundleWiringStateMBean.BUNDLE_CAPABILITY)));
        data.add(getJmxDirectives((CompositeData) wire.get(BundleWiringStateMBean.BUNDLE_CAPABILITY)));
        data.add(wire.get(BundleWiringStateMBean.REQUIRER_BUNDLE_ID));
        data.add(getJmxAttributes((CompositeData) wire.get(BundleWiringStateMBean.BUNDLE_REQUIREMENT)));
        data.add(getJmxDirectives((CompositeData) wire.get(BundleWiringStateMBean.BUNDLE_REQUIREMENT)));
        actualProvidedWires.add(data);
    }
    Assert.assertEquals(expectedProvidedWires, actualProvidedWires);
}
Also used : CompositeData(javax.management.openmbean.CompositeData) ArrayList(java.util.ArrayList) BundleWire(org.osgi.framework.wiring.BundleWire) BundleRequirement(org.osgi.framework.wiring.BundleRequirement) ArrayList(java.util.ArrayList) List(java.util.List) BundleCapability(org.osgi.framework.wiring.BundleCapability) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 59 with CompositeData

use of javax.management.openmbean.CompositeData in project aries by apache.

the class BundleWiringStateMBeanTest method testRevisionsWiring.

@Test
public void testRevisionsWiring() throws Exception {
    TabularData jmxWiringTable = brsMBean.getRevisionsWiring(bundleA.getBundleId(), BundleRevision.PACKAGE_NAMESPACE);
    Assert.assertEquals(1, jmxWiringTable.size());
    CompositeData jmxWiring = (CompositeData) jmxWiringTable.values().iterator().next();
    Assert.assertEquals(BundleWiringStateMBean.BUNDLE_WIRING_TYPE, jmxWiring.getCompositeType());
    Assert.assertEquals(bundleA.getBundleId(), jmxWiring.get(BundleWiringStateMBean.BUNDLE_ID));
    BundleWiring bw = (BundleWiring) bundleA.adapt(BundleWiring.class);
    assertBundleWiring(bw, jmxWiring);
}
Also used : CompositeData(javax.management.openmbean.CompositeData) BundleWiring(org.osgi.framework.wiring.BundleWiring) TabularData(javax.management.openmbean.TabularData) Test(org.junit.Test) AbstractIntegrationTest(org.apache.aries.jmx.AbstractIntegrationTest)

Example 60 with CompositeData

use of javax.management.openmbean.CompositeData in project aries by apache.

the class BundleWiringStateMBeanTest method testGetCurrentRevisionDeclaredRequirements.

@Test
public void testGetCurrentRevisionDeclaredRequirements() throws Exception {
    Bundle a = getBundleByName("org.apache.aries.jmx.test.bundlea");
    BundleRevision br = (BundleRevision) a.adapt(BundleRevision.class);
    List<BundleRequirement> requirements = br.getDeclaredRequirements(BundleRevision.PACKAGE_NAMESPACE);
    CompositeData[] jmxRequirements = brsMBean.getCurrentRevisionDeclaredRequirements(a.getBundleId(), 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);
}
Also used : Bundle(org.osgi.framework.Bundle) CompositeData(javax.management.openmbean.CompositeData) BundleRevision(org.osgi.framework.wiring.BundleRevision) HashMap(java.util.HashMap) Map(java.util.Map) BundleRequirement(org.osgi.framework.wiring.BundleRequirement) Test(org.junit.Test) AbstractIntegrationTest(org.apache.aries.jmx.AbstractIntegrationTest)

Aggregations

CompositeData (javax.management.openmbean.CompositeData)229 TabularData (javax.management.openmbean.TabularData)91 Test (org.junit.Test)73 CompositeDataSupport (javax.management.openmbean.CompositeDataSupport)68 TabularDataSupport (javax.management.openmbean.TabularDataSupport)51 CompositeType (javax.management.openmbean.CompositeType)50 HashMap (java.util.HashMap)31 ArrayList (java.util.ArrayList)27 Map (java.util.Map)27 Bundle (org.osgi.framework.Bundle)24 ObjectName (javax.management.ObjectName)21 OpenDataException (javax.management.openmbean.OpenDataException)18 IOException (java.io.IOException)17 Collection (java.util.Collection)16 AbstractIntegrationTest (org.apache.aries.jmx.AbstractIntegrationTest)16 AuditEvent (org.nhindirect.common.audit.AuditEvent)15 TabularType (javax.management.openmbean.TabularType)13 MBeanServer (javax.management.MBeanServer)12 DefaultAuditContext (org.nhindirect.common.audit.DefaultAuditContext)11 MBeanException (javax.management.MBeanException)8