Search in sources :

Example 76 with TabularDataSupport

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

the class BlueprintState method getLastEvents.

public synchronized TabularData getLastEvents() throws IOException {
    TabularDataSupport table = new TabularDataSupport(BlueprintStateMBean.OSGI_BLUEPRINT_EVENTS_TYPE);
    table.putAll(dataMap);
    return table;
}
Also used : TabularDataSupport(javax.management.openmbean.TabularDataSupport)

Example 77 with TabularDataSupport

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

the class ConfigurationAdminTest method testUpdateTabularData.

@SuppressWarnings("unchecked")
@Test
public void testUpdateTabularData() throws Exception {
    TabularData data = new TabularDataSupport(PROPERTIES_TYPE);
    PropertyData<String> p1 = PropertyData.newInstance("one", "first");
    data.put(p1.toCompositeData());
    PropertyData<Integer> p2 = PropertyData.newInstance("two", 3);
    data.put(p2.toCompositeData());
    org.osgi.service.cm.ConfigurationAdmin admin = mock(org.osgi.service.cm.ConfigurationAdmin.class);
    String pid = "org.apache.aries.jmx.mock";
    Configuration config = mock(Configuration.class);
    when(admin.getConfiguration(pid, null)).thenReturn(config);
    ConfigurationAdmin mbean = new ConfigurationAdmin(admin);
    mbean.updateForLocation(pid, null, data);
    ArgumentCaptor<Dictionary> props = ArgumentCaptor.forClass(Dictionary.class);
    verify(config).update(props.capture());
    Dictionary configProperties = props.getValue();
    assertEquals("first", configProperties.get("one"));
    assertEquals(3, configProperties.get("two"));
}
Also used : Dictionary(java.util.Dictionary) Configuration(org.osgi.service.cm.Configuration) Matchers.anyString(org.mockito.Matchers.anyString) TabularData(javax.management.openmbean.TabularData) TabularDataSupport(javax.management.openmbean.TabularDataSupport) Test(org.junit.Test)

Example 78 with TabularDataSupport

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

the class BundleDataTest method testToCompositeData.

@Test
public void testToCompositeData() throws Exception {
    Bundle bundle = mock(Bundle.class);
    BundleContext context = mock(BundleContext.class);
    PackageAdmin packageAdmin = mock(PackageAdmin.class);
    StartLevel startLevel = mock(StartLevel.class);
    Bundle b1 = mock(Bundle.class);
    when(b1.getSymbolicName()).thenReturn("b1");
    when(b1.getBundleId()).thenReturn(new Long(44));
    Bundle b2 = mock(Bundle.class);
    when(b2.getSymbolicName()).thenReturn("b2");
    when(b2.getBundleId()).thenReturn(new Long(55));
    Bundle b3 = mock(Bundle.class);
    when(b3.getSymbolicName()).thenReturn("b3");
    when(b3.getBundleId()).thenReturn(new Long(66));
    when(context.getBundles()).thenReturn(new Bundle[] { bundle, b1, b2, b3 });
    when(bundle.getSymbolicName()).thenReturn("test");
    when(bundle.getVersion()).thenReturn(Version.emptyVersion);
    when(bundle.getBundleId()).thenReturn(new Long(1));
    when(bundle.getLastModified()).thenReturn(new Long(12345));
    when(bundle.getLocation()).thenReturn("location");
    //headers
    Dictionary<String, String> headers = new Hashtable<String, String>();
    headers.put(Constants.BUNDLE_SYMBOLICNAME, "test");
    headers.put(Constants.BUNDLE_VERSION, "0.0.0");
    when(bundle.getHeaders()).thenReturn(headers);
    //exported packages
    ExportedPackage exported = mock(ExportedPackage.class);
    when(exported.getName()).thenReturn("org.apache.aries.jmx");
    when(exported.getVersion()).thenReturn(new Version("1.0.0"));
    when(exported.getExportingBundle()).thenReturn(bundle);
    when(packageAdmin.getExportedPackages(bundle)).thenReturn(new ExportedPackage[] { exported });
    //imported packages
    ExportedPackage ep1 = mock(ExportedPackage.class);
    when(ep1.getImportingBundles()).thenReturn(new Bundle[] { bundle, b2, b3 });
    when(ep1.getName()).thenReturn("org.apache.aries.jmx.b1");
    when(ep1.getVersion()).thenReturn(Version.emptyVersion);
    when(ep1.getExportingBundle()).thenReturn(b1);
    ExportedPackage ep2 = mock(ExportedPackage.class);
    when(ep2.getImportingBundles()).thenReturn(new Bundle[] { bundle, b3 });
    when(ep2.getName()).thenReturn("org.apache.aries.jmx.b2");
    when(ep2.getVersion()).thenReturn(Version.parseVersion("2.0.1"));
    when(ep2.getExportingBundle()).thenReturn(b2);
    headers.put(Constants.DYNAMICIMPORT_PACKAGE, "*");
    when(packageAdmin.getExportedPackages(b1)).thenReturn(new ExportedPackage[] { ep1 });
    when(packageAdmin.getExportedPackages(b2)).thenReturn(new ExportedPackage[] { ep2 });
    when(packageAdmin.getExportedPackages(b3)).thenReturn(null);
    //required bundles
    RequiredBundle rb1 = mock(RequiredBundle.class);
    when(rb1.getBundle()).thenReturn(b1);
    when(rb1.getRequiringBundles()).thenReturn(new Bundle[] { bundle, b2 });
    RequiredBundle rb2 = mock(RequiredBundle.class);
    when(rb2.getBundle()).thenReturn(b2);
    when(rb2.getRequiringBundles()).thenReturn(new Bundle[] { b1 });
    RequiredBundle rb3 = mock(RequiredBundle.class);
    when(rb3.getBundle()).thenReturn(b3);
    when(rb3.getRequiringBundles()).thenReturn(new Bundle[] { bundle, b1, b2 });
    headers.put(Constants.REQUIRE_BUNDLE, "b1;bundle-version=\"1.0.0\",b3;bundle-version=\"2.0.0\"");
    when(packageAdmin.getRequiredBundles("b1")).thenReturn(new RequiredBundle[] { rb1 });
    when(packageAdmin.getRequiredBundles("b2")).thenReturn(new RequiredBundle[] { rb2 });
    when(packageAdmin.getRequiredBundles("b3")).thenReturn(new RequiredBundle[] { rb3 });
    //services in use
    ServiceReference s1 = mock(ServiceReference.class);
    when(s1.getProperty(Constants.SERVICE_ID)).thenReturn(new Long(15));
    ServiceReference s2 = mock(ServiceReference.class);
    when(s2.getProperty(Constants.SERVICE_ID)).thenReturn(new Long(16));
    ServiceReference s3 = mock(ServiceReference.class);
    when(s3.getProperty(Constants.SERVICE_ID)).thenReturn(new Long(17));
    when(bundle.getServicesInUse()).thenReturn(new ServiceReference[] { s1, s2, s3 });
    BundleData b = new BundleData(context, bundle, packageAdmin, startLevel);
    CompositeData compositeData = b.toCompositeData();
    assertEquals("test", compositeData.get(SYMBOLIC_NAME));
    assertEquals("0.0.0", compositeData.get(VERSION));
    TabularData headerTable = (TabularData) compositeData.get(HEADERS);
    assertEquals(4, headerTable.values().size());
    CompositeData header = headerTable.get(new Object[] { Constants.BUNDLE_SYMBOLICNAME });
    assertNotNull(header);
    String value = (String) header.get(VALUE);
    assertEquals("test", value);
    String key = (String) header.get(KEY);
    assertEquals(Constants.BUNDLE_SYMBOLICNAME, key);
    TabularData bundleTable = new TabularDataSupport(BUNDLES_TYPE);
    bundleTable.put(b.toCompositeData());
    CompositeData bundleData = bundleTable.get(new Object[] { Long.valueOf(1) });
    assertNotNull(bundleData);
    String location = (String) bundleData.get(LOCATION);
    assertEquals("location", location);
    assertArrayEquals(new String[] { "org.apache.aries.jmx;1.0.0" }, (String[]) compositeData.get(EXPORTED_PACKAGES));
    assertArrayEquals(new String[] { "org.apache.aries.jmx.b1;0.0.0", "org.apache.aries.jmx.b2;2.0.1" }, (String[]) compositeData.get(IMPORTED_PACKAGES));
    assertEquals(toSet(new long[] { 44, 55, 66 }), toSet((Long[]) compositeData.get(REQUIRED_BUNDLES)));
    assertArrayEquals(new Long[] { new Long(15), new Long(16), new Long(17) }, (Long[]) compositeData.get(SERVICES_IN_USE));
    //default no return stub
    assertEquals("UNKNOWN", compositeData.get(STATE));
    assertEquals(0, ((Long[]) compositeData.get(HOSTS)).length);
    assertEquals(0, ((Long[]) compositeData.get(FRAGMENTS)).length);
}
Also used : Bundle(org.osgi.framework.Bundle) RequiredBundle(org.osgi.service.packageadmin.RequiredBundle) Hashtable(java.util.Hashtable) CompositeData(javax.management.openmbean.CompositeData) RequiredBundle(org.osgi.service.packageadmin.RequiredBundle) ServiceReference(org.osgi.framework.ServiceReference) TabularData(javax.management.openmbean.TabularData) PackageAdmin(org.osgi.service.packageadmin.PackageAdmin) Version(org.osgi.framework.Version) ExportedPackage(org.osgi.service.packageadmin.ExportedPackage) TabularDataSupport(javax.management.openmbean.TabularDataSupport) StartLevel(org.osgi.service.startlevel.StartLevel) BundleContext(org.osgi.framework.BundleContext) Test(org.junit.Test)

Example 79 with TabularDataSupport

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

the class BundleDataTest method testFromCompositeData.

@Test
public void testFromCompositeData() throws Exception {
    Map<String, Object> items = new HashMap<String, Object>();
    items.put(EXPORTED_PACKAGES, new String[] { "org.apache.aries.jmx;1.0.0" });
    items.put(FRAGMENT, false);
    items.put(FRAGMENTS, new Long[0]);
    items.put(HOSTS, new Long[0]);
    items.put(IDENTIFIER, new Long(3));
    items.put(IMPORTED_PACKAGES, new String[] { "org.apache.aries.jmx.b1;0.0.0", "org.apache.aries.jmx.b2;2.0.1" });
    items.put(LAST_MODIFIED, new Long(8797));
    items.put(LOCATION, "");
    items.put(ACTIVATION_POLICY_USED, true);
    items.put(PERSISTENTLY_STARTED, false);
    items.put(REGISTERED_SERVICES, new Long[0]);
    items.put(REMOVAL_PENDING, false);
    items.put(REQUIRED, true);
    items.put(REQUIRED_BUNDLES, new Long[] { new Long(44), new Long(66) });
    items.put(REQUIRING_BUNDLES, new Long[0]);
    items.put(SERVICES_IN_USE, new Long[] { new Long(15), new Long(16), new Long(17) });
    items.put(START_LEVEL, 1);
    items.put(STATE, "ACTIVE");
    items.put(SYMBOLIC_NAME, "test");
    items.put(VERSION, "0.0.0");
    TabularData headerTable = new TabularDataSupport(HEADERS_TYPE);
    headerTable.put(new Header("a", "a").toCompositeData());
    headerTable.put(new Header("b", "b").toCompositeData());
    items.put(HEADERS, headerTable);
    CompositeData compositeData = new CompositeDataSupport(BUNDLE_TYPE, items);
    BundleData b = BundleData.from(compositeData);
    assertEquals("test", b.getSymbolicName());
    assertEquals("0.0.0", b.getVersion());
    assertEquals(2, b.getHeaders().size());
    assertArrayEquals(new String[] { "org.apache.aries.jmx;1.0.0" }, b.getExportedPackages());
    assertArrayEquals(new String[] { "org.apache.aries.jmx.b1;0.0.0", "org.apache.aries.jmx.b2;2.0.1" }, b.getImportedPackages());
    assertArrayEquals(new long[] { 44, 66 }, b.getRequiredBundles());
    assertArrayEquals(new long[] { 15, 16, 17 }, b.getServicesInUse());
    //default no return stub
    assertEquals("ACTIVE", b.getState());
    assertEquals(0, b.getHosts().length);
    assertEquals(0, b.getFragments().length);
}
Also used : Header(org.apache.aries.jmx.codec.BundleData.Header) HashMap(java.util.HashMap) TabularDataSupport(javax.management.openmbean.TabularDataSupport) CompositeData(javax.management.openmbean.CompositeData) CompositeDataSupport(javax.management.openmbean.CompositeDataSupport) TabularData(javax.management.openmbean.TabularData) Test(org.junit.Test)

Example 80 with TabularDataSupport

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

the class ServiceDataTest method testFromCompositeData.

@Test
public void testFromCompositeData() throws Exception {
    Map<String, Object> items = new HashMap<String, Object>();
    items.put(IDENTIFIER, new Long(99));
    items.put(BUNDLE_IDENTIFIER, new Long(5));
    items.put(USING_BUNDLES, new Long[] { new Long(10), new Long(11) });
    items.put(OBJECT_CLASS, new String[] { "org.apache.aries.jmx.Test", "org.apache.aries.jmx.Mock" });
    TabularData propertyTable = new TabularDataSupport(JmxConstants.PROPERTIES_TYPE);
    propertyTable.put(PropertyData.newInstance("a", true).toCompositeData());
    propertyTable.put(PropertyData.newInstance("b", "value").toCompositeData());
    propertyTable.put(PropertyData.newInstance("c", new int[] { 1, 2 }).toCompositeData());
    propertyTable.put(PropertyData.newInstance("d", new Long[] { new Long(3), new Long(4) }).toCompositeData());
    items.put(ServiceStateMBean.PROPERTIES, propertyTable);
    CompositeData compositeData = new CompositeDataSupport(SERVICE_TYPE, items);
    ServiceData data = ServiceData.from(compositeData);
    assertEquals(99, data.getServiceId());
    assertEquals(5, data.getBundleId());
    assertArrayEquals(new long[] { 10, 11 }, data.getUsingBundles());
    assertArrayEquals(new String[] { "org.apache.aries.jmx.Test", "org.apache.aries.jmx.Mock" }, data.getServiceInterfaces());
    List<PropertyData<? extends Object>> properties = data.getProperties();
    assertEquals(4, properties.size());
    for (PropertyData<? extends Object> property : properties) {
        if (property.getKey().equals("a")) {
            assertTrue((Boolean) property.getValue());
            assertEquals(P_BOOLEAN, property.getEncodedType());
        } else if (property.getKey().equals("b")) {
            assertEquals("value", property.getValue());
            assertEquals(STRING, property.getEncodedType());
        } else if (property.getKey().equals("c")) {
            assertArrayEquals(new int[] { 1, 2 }, (int[]) property.getValue());
            assertEquals("Array of int", property.getEncodedType());
            assertEquals("1,2", property.getEncodedValue());
        } else if (property.getKey().equals("d")) {
            assertArrayEquals(new Long[] { new Long(3), new Long(4) }, (Long[]) property.getValue());
            assertEquals("Array of Long", property.getEncodedType());
            assertEquals("3,4", property.getEncodedValue());
        } else {
            fail("unknown key parsed from properties");
        }
    }
}
Also used : HashMap(java.util.HashMap) CompositeData(javax.management.openmbean.CompositeData) CompositeDataSupport(javax.management.openmbean.CompositeDataSupport) TabularData(javax.management.openmbean.TabularData) TabularDataSupport(javax.management.openmbean.TabularDataSupport) Test(org.junit.Test)

Aggregations

TabularDataSupport (javax.management.openmbean.TabularDataSupport)103 TabularData (javax.management.openmbean.TabularData)67 CompositeDataSupport (javax.management.openmbean.CompositeDataSupport)60 CompositeData (javax.management.openmbean.CompositeData)51 CompositeType (javax.management.openmbean.CompositeType)50 TabularType (javax.management.openmbean.TabularType)36 Map (java.util.Map)27 OpenDataException (javax.management.openmbean.OpenDataException)24 HashMap (java.util.HashMap)11 Bundle (org.osgi.framework.Bundle)10 IOException (java.io.IOException)7 ObjectName (javax.management.ObjectName)7 OpenType (javax.management.openmbean.OpenType)7 EndpointUtilizationStatistics (org.apache.camel.spi.EndpointUtilizationStatistics)7 Test (org.junit.Test)6 ConcurrentMap (java.util.concurrent.ConcurrentMap)5 MBeanException (javax.management.MBeanException)5 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)5 ArrayList (java.util.ArrayList)4 Dictionary (java.util.Dictionary)4