use of javax.management.openmbean.CompositeType in project karaf by apache.
the class InstanceToTableMapper method createRowType.
private static CompositeType createRowType() throws OpenDataException {
String desc = "This type describes Karaf instance";
OpenType<?>[] itemTypes = new OpenType[] { SimpleType.INTEGER, SimpleType.STRING, SimpleType.BOOLEAN, SimpleType.INTEGER, SimpleType.STRING, SimpleType.INTEGER, SimpleType.STRING, SimpleType.INTEGER, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING };
String[] descriptions = new String[] { "The Process ID of the instance or 0 if not running", "The name of the instance", "Whether the instance is root", "The SSH port that can be used to connect to the instance", "The host address where the SSH server is listening", "The RMI registry port that can be used to manage the instance", "The host address where the RMI registry is listening", "The RMI server port that can be used to manage the instance", "The host address where the RMI server is listening", "The state of the instance", "The location of the instance", "The Java options of the instance" };
CompositeType comp = new CompositeType("Instances", desc, InstancesMBean.INSTANCE, descriptions, itemTypes);
return comp;
}
use of javax.management.openmbean.CompositeType in project karaf by apache.
the class JMXSecurityTest method testOSGiConfigAdminMBean.
private void testOSGiConfigAdminMBean(MBeanServerConnection connection, ObjectName mbean, String pidPrefix, boolean shouldSucceed, boolean isAdmin) throws Exception {
String infix = "." + System.currentTimeMillis();
String suffix = infix + "_" + counter.incrementAndGet();
String pid = pidPrefix + suffix;
CompositeType ct = new CompositeType("PROPERTY", "X", new String[] { "Key", "Value", "Type" }, new String[] { "X", "X", "X" }, new OpenType<?>[] { SimpleType.STRING, SimpleType.STRING, SimpleType.STRING });
TabularType tt = new TabularType("PROPERTIES", "X", ct, new String[] { "Key" });
TabularDataSupport tds = new TabularDataSupport(tt);
Map<String, Object> data = new HashMap<>();
data.put("Key", "foo");
data.put("Value", "bar");
data.put("Type", "String");
CompositeDataSupport cds = new CompositeDataSupport(ct, data);
tds.put(cds);
assertJmxInvoke(shouldSucceed, connection, mbean, "update", new Object[] { pid, tds }, new String[] { String.class.getName(), TabularData.class.getName() });
TabularData td = (TabularData) connection.invoke(mbean, "getProperties", new Object[] { pid }, new String[] { String.class.getName() });
if (shouldSucceed) {
assertEquals("bar", td.get(new Object[] { "foo" }).get("Value"));
}
String[][] configs = (String[][]) connection.invoke(mbean, "getConfigurations", new Object[] { "(service.pid=" + pid + ")" }, new String[] { String.class.getName() });
if (shouldSucceed) {
assertEquals(1, configs.length);
assertEquals(pid, configs[0][0]);
}
assertJmxInvoke(shouldSucceed, connection, mbean, "delete", new Object[] { pid }, new String[] { String.class.getName() });
TabularDataSupport tds2 = new TabularDataSupport(tt);
Map<String, Object> data2 = new HashMap<>();
data2.put("Key", "a.b.c");
data2.put("Value", "d.e.f");
data2.put("Type", "String");
CompositeDataSupport cds2 = new CompositeDataSupport(ct, data2);
tds2.put(cds2);
String suffix2 = infix + "_" + counter.incrementAndGet();
String pid2 = pidPrefix + suffix2;
String location2 = "mylocation" + System.currentTimeMillis();
assertJmxInvoke(shouldSucceed, connection, mbean, "updateForLocation", new Object[] { pid2, location2, tds2 }, new String[] { String.class.getName(), String.class.getName(), TabularData.class.getName() });
TabularData td2 = (TabularData) connection.invoke(mbean, "getPropertiesForLocation", new Object[] { pid2, location2 }, new String[] { String.class.getName(), String.class.getName() });
if (shouldSucceed) {
assertEquals("d.e.f", td2.get(new Object[] { "a.b.c" }).get("Value"));
}
assertJmxInvoke(shouldSucceed, connection, mbean, "deleteForLocation", new Object[] { pid2, location2 }, new String[] { String.class.getName(), String.class.getName() });
if (isAdmin) {
String suffix3 = infix + "_" + counter.incrementAndGet();
String pid3 = pidPrefix + suffix3;
TabularDataSupport tds3 = new TabularDataSupport(tt);
assertJmxInvoke(shouldSucceed, connection, mbean, "update", new Object[] { pid3, tds3 }, new String[] { String.class.getName(), TabularData.class.getName() });
String[][] configs2 = (String[][]) connection.invoke(mbean, "getConfigurations", new Object[] { "(service.pid=" + pidPrefix + infix + "*)" }, new String[] { String.class.getName() });
assertEquals(1, configs2.length);
assertEquals(pid3, configs2[0][0]);
String location3 = "my.other.location." + System.currentTimeMillis();
assertJmxInvoke(shouldSucceed, connection, mbean, "setBundleLocation", new Object[] { pid3, location3 }, new String[] { String.class.getName(), String.class.getName() });
String[][] configs3 = (String[][]) connection.invoke(mbean, "getConfigurations", new Object[] { "(service.pid=" + pidPrefix + infix + "*)" }, new String[] { String.class.getName() });
assertEquals(1, configs3.length);
assertEquals(pid3, configs3[0][0]);
connection.invoke(mbean, "deleteConfigurations", new Object[] { "(service.pid=" + pid3 + ")" }, new String[] { String.class.getName() });
assertEquals(0, ((String[][]) connection.invoke(mbean, "getConfigurations", new Object[] { "(service.pid=" + pidPrefix + infix + "*)" }, new String[] { String.class.getName() })).length);
}
}
use of javax.management.openmbean.CompositeType in project karaf by apache.
the class ServicesMBeanImpl method getServices.
public TabularData getServices(long bundleId, boolean inUse) throws MBeanException {
try {
CompositeType serviceType = new CompositeType("Service", "OSGi Service", new String[] { "Interfaces", "Properties" }, new String[] { "Interfaces class name of the service", "Properties of the service" }, new OpenType[] { new ArrayType(1, SimpleType.STRING), new ArrayType(1, SimpleType.STRING) });
TabularType tableType = new TabularType("Services", "Table of OSGi Services", serviceType, new String[] { "Interfaces", "Properties" });
TabularData table = new TabularDataSupport(tableType);
Bundle[] bundles;
if (bundleId >= 0) {
bundles = new Bundle[] { bundleContext.getBundle(bundleId) };
} else {
bundles = bundleContext.getBundles();
}
for (Bundle bundle : bundles) {
try {
ServiceReference[] serviceReferences;
if (inUse) {
serviceReferences = bundle.getServicesInUse();
} else {
serviceReferences = bundle.getRegisteredServices();
}
if (serviceReferences != null) {
for (ServiceReference reference : serviceReferences) {
String[] interfaces = (String[]) reference.getProperty("objectClass");
List<String> properties = new ArrayList<>();
for (String key : reference.getPropertyKeys()) {
properties.add(key + " = " + reference.getProperty(key));
}
CompositeData data = new CompositeDataSupport(serviceType, new String[] { "Interfaces", "Properties" }, new Object[] { interfaces, properties.toArray(new String[0]) });
table.put(data);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
return table;
} catch (Exception e) {
throw new MBeanException(null, e.toString());
}
}
use of javax.management.openmbean.CompositeType in project karaf by apache.
the class JmxReference method createReferenceType.
private static CompositeType createReferenceType() {
try {
String description = "This type encapsulates Scr references";
String[] itemNames = ScrServiceMBean.REFERENCE;
OpenType[] itemTypes = new OpenType[itemNames.length];
String[] itemDescriptions = new String[itemNames.length];
itemTypes[0] = SimpleType.STRING;
itemTypes[1] = SimpleType.BOOLEAN;
itemTypes[2] = SimpleType.STRING;
itemTypes[3] = SimpleType.STRING;
itemTypes[4] = SimpleType.STRING;
itemTypes[5] = new ArrayType(1, SimpleType.STRING);
itemDescriptions[0] = "The name of the reference";
itemDescriptions[1] = "The state of the reference";
itemDescriptions[2] = "The cardinality of the reference";
itemDescriptions[3] = "The availability of the reference";
itemDescriptions[4] = "The policy of the reference";
itemDescriptions[5] = "The bound services";
return new CompositeType("Reference", description, itemNames, itemDescriptions, itemTypes);
} catch (OpenDataException e) {
throw new IllegalStateException("Unable to build reference type", e);
}
}
use of javax.management.openmbean.CompositeType in project jdk8u_jdk by JetBrains.
the class DefaultMXBeanMappingFactory method makeTabularMapping.
private MXBeanMapping makeTabularMapping(Type objType, boolean sortedMap, Type keyType, Type valueType, MXBeanMappingFactory factory) throws OpenDataException {
final String objTypeName = typeName(objType);
final MXBeanMapping keyMapping = factory.mappingForType(keyType, factory);
final MXBeanMapping valueMapping = factory.mappingForType(valueType, factory);
final OpenType<?> keyOpenType = keyMapping.getOpenType();
final OpenType<?> valueOpenType = valueMapping.getOpenType();
final CompositeType rowType = new CompositeType(objTypeName, objTypeName, keyValueArray, keyValueArray, new OpenType<?>[] { keyOpenType, valueOpenType });
final TabularType tabularType = new TabularType(objTypeName, objTypeName, rowType, keyArray);
return new TabularMapping(objType, sortedMap, tabularType, keyMapping, valueMapping);
}
Aggregations