private OpenMBeanOperationInfo getOperation(String name, OpenMBeanParameterInfo addWildcardChildName, OperationEntry entry) { ModelNode opNode = entry.getDescriptionProvider().getModelDescription(null); OpenMBeanParameterInfo[] params = getParameterInfos(opNode); if (addWildcardChildName != null) { OpenMBeanParameterInfo[] newParams = new OpenMBeanParameterInfo[params.length + 1]; newParams[0] = addWildcardChildName; System.arraycopy(params, 0, newParams, 1, params.length); params = newParams; } return new OpenMBeanOperationInfoSupport( name, getDescription(opNode), params, getReturnType(opNode), entry.getFlags().contains(Flag.READ_ONLY) ? MBeanOperationInfo.INFO : MBeanOperationInfo.UNKNOWN, createOperationDescriptor()); }
private static MBeanOperationInfo customize(MBeanOperationInfo oi, String description, MBeanParameterInfo[] signature, int impact) { if (equal(description, oi.getDescription()) && identicalArrays(signature, oi.getSignature()) && impact == oi.getImpact()) return oi; if (oi instanceof OpenMBeanOperationInfo) { OpenMBeanOperationInfo ooi = (OpenMBeanOperationInfo) oi; OpenMBeanParameterInfo[] oparams = paramsToOpenParams(signature); return new OpenMBeanOperationInfoSupport(oi.getName(), description, oparams, ooi.getReturnOpenType(), impact, oi.getDescriptor()); } else { return new MBeanOperationInfo(oi.getName(), description, signature, oi.getReturnType(), impact, oi.getDescriptor()); } }
private OpenMBeanOperationInfo[] getOperations() { final boolean root = pathAddress.size() == 0; //TODO include inherited/global operations? List<OpenMBeanOperationInfo> ops = new ArrayList<OpenMBeanOperationInfo>(); for (Map.Entry<String, OperationEntry> entry : resourceRegistration.getOperationDescriptions(PathAddress.EMPTY_ADDRESS, false).entrySet()) { final String opName = entry.getKey(); if (opName.equals(ADD) || opName.equals(DESCRIBE)) { continue; } if (root) { if (opName.equals(READ_RESOURCE_OPERATION) || opName.equals(READ_ATTRIBUTE_OPERATION) || opName.equals(READ_RESOURCE_DESCRIPTION_OPERATION) || opName.equals(READ_CHILDREN_NAMES_OPERATION) || opName.equals(READ_CHILDREN_TYPES_OPERATION) || opName.equals(READ_CHILDREN_RESOURCES_OPERATION) || opName.equals(READ_OPERATION_NAMES_OPERATION) || opName.equals(READ_OPERATION_DESCRIPTION_OPERATION) || opName.equals(READ_RESOURCE_OPERATION) || opName.equals(READ_RESOURCE_OPERATION) || opName.equals(WRITE_ATTRIBUTE_OPERATION) || opName.equals(ValidateAddressOperationHandler.OPERATION_NAME) || opName.equals(CompositeOperationHandler.NAME) || opName.equals(DeploymentUploadStreamAttachmentHandler.OPERATION_NAME)) { //Ignore some of the global operations which probably don't make much sense here continue; } } final OperationEntry opEntry = entry.getValue(); if (mutabilityChecker.mutable(pathAddress) || opEntry.getFlags().contains(Flag.READ_ONLY) || opEntry.getFlags().contains(Flag.RUNTIME_ONLY)) { ops.add(getOperation(NameConverter.convertToCamelCase(entry.getKey()), null, opEntry)); } } addChildAddOperations(ops, resourceRegistration); return ops.toArray(new OpenMBeanOperationInfo[ops.size()]); }
private OpenMBeanOperationInfo findOperation(MBeanOperationInfo[] ops, String name) { for (MBeanOperationInfo op : ops) { Assert.assertNotNull(op.getName()); if (op.getName().equals(name)) { return assertCast(OpenMBeanOperationInfo.class, op); } } Assert.fail("No op called " + name); return null; }
public MBeanInfo getMBeanInfo() { OpenMBeanParameterInfoSupport parameterInfoSupport = new OpenMBeanParameterInfoSupport( "par name", "descripttiosdf", SimpleType.STRING); OpenMBeanOperationInfo infoSupport = new OpenMBeanOperationInfoSupport( operationName, "desciption", new OpenMBeanParameterInfo[] { parameterInfoSupport }, SimpleType.STRING, MBeanOperationInfo.ACTION); OpenMBeanAttributeInfoSupport attributeInfo = new OpenMBeanAttributeInfoSupport( attrName, "description", SimpleType.STRING, true, true, false); OpenMBeanInfoSupport beanInfoSupport = new OpenMBeanInfoSupport(this .getClass().getName(), "descriptor", new OpenMBeanAttributeInfo[] { attributeInfo }, null, new OpenMBeanOperationInfo[] { infoSupport }, null); return beanInfoSupport; }
public MBeanInfo getMBeanInfo() { try { OpenMBeanOperationInfo infoSupport = new OpenMBeanOperationInfoSupport( operationName, "desciption", null, getCompositeType(), MBeanOperationInfo.ACTION); OpenMBeanInfoSupport beanInfoSupport = new OpenMBeanInfoSupport( this.getClass().getName(), "descriptor", null, null, new OpenMBeanOperationInfo[] { infoSupport }, null); return beanInfoSupport; } catch (OpenDataException e) { e.printStackTrace(); assertTrue(false); } return null; }
public MBeanInfo getMBeanInfo() { try { OpenMBeanOperationInfo infoSupport = new OpenMBeanOperationInfoSupport( operationName, "desciption", null, getTabularType(), MBeanOperationInfo.ACTION); OpenMBeanInfoSupport beanInfoSupport = new OpenMBeanInfoSupport( this.getClass().getName(), "descriptor", null, null, new OpenMBeanOperationInfo[] { infoSupport }, null); return beanInfoSupport; } catch (Exception e) { e.printStackTrace(); assertTrue(false); } return null; }
private static void test(Object child, String name, boolean mxbean) throws Exception { final ObjectName childName = new ObjectName("test:type=Child,name="+name); final MBeanServer server = ManagementFactory.getPlatformMBeanServer(); server.registerMBean(child,childName); try { final MBeanInfo info = server.getMBeanInfo(childName); System.out.println(name+": " + info.getDescriptor()); final int len = info.getOperations().length; if (len == OPCOUNT) { System.out.println(name+": OK, only "+OPCOUNT+ " operations here..."); } else { final String qual = (len>OPCOUNT)?"many":"few"; System.err.println(name+": Too "+qual+" foos! Found "+ len+", expected "+OPCOUNT); for (MBeanOperationInfo op : info.getOperations()) { System.err.println("public "+op.getReturnType()+" "+ op.getName()+"();"); } throw new RuntimeException("Too " + qual + " foos for "+name); } final Descriptor d = info.getDescriptor(); final String mxstr = String.valueOf(d.getFieldValue("mxbean")); final boolean mxb = (mxstr==null)?false:Boolean.valueOf(mxstr).booleanValue(); System.out.println(name+": mxbean="+mxb); if (mxbean && !mxb) throw new AssertionError("MXBean is not OpenMBean?"); for (MBeanOperationInfo mboi : info.getOperations()) { // Sanity check if (mxbean && !mboi.getName().equals("foo")) { // The spec doesn't guarantee that the MBeanOperationInfo // of an MXBean will be an OpenMBeanOperationInfo, and in // some circumstances in our implementation it will not. // However, in thsi tests, for all methods but foo(), // it should. // if (!(mboi instanceof OpenMBeanOperationInfo)) throw new AssertionError("Operation "+mboi.getName()+ "() is not Open?"); } final String exp = EXPECTED_TYPES.get(mboi.getName()); // For MXBeans, we need to compare 'exp' with the original // type - because mboi.getReturnType() returns the OpenType // String type = (String)mboi.getDescriptor(). getFieldValue("originalType"); if (type == null) type = mboi.getReturnType(); if (type.equals(exp)) continue; System.err.println("Bad return type for "+ mboi.getName()+"! Found "+type+ ", expected "+exp); throw new RuntimeException("Bad return type for "+ mboi.getName()); } } finally { server.unregisterMBean(childName); } }
protected void cacheMBeanInfo(MBeanInfo info) { if (info == null) return; try { MBeanAttributeInfo[] oldA = info.getAttributes(); OpenMBeanAttributeInfo[] attribs = new OpenMBeanAttributeInfoSupport[oldA.length]; for (int a = 0; a < oldA.length; ++a) { OpenMBeanParameterInfo param = Translator.translate(oldA[a].getType()); if (param.getMinValue() == null) { Object[] lv; if (param.getLegalValues() == null) lv = null; else lv = param.getLegalValues().toArray(); attribs[a] = new OpenMBeanAttributeInfoSupport(oldA[a].getName(), oldA[a].getDescription(), ((OpenType<Object>) param.getOpenType()), oldA[a].isReadable(), oldA[a].isWritable(), oldA[a].isIs(), param.getDefaultValue(), lv); } else attribs[a] = new OpenMBeanAttributeInfoSupport(oldA[a].getName(), oldA[a].getDescription(), ((OpenType<Object>) param.getOpenType()), oldA[a].isReadable(), oldA[a].isWritable(), oldA[a].isIs(), param.getDefaultValue(), ((Comparable<Object>) param.getMinValue()), ((Comparable<Object>) param.getMaxValue())); } MBeanConstructorInfo[] oldC = info.getConstructors(); OpenMBeanConstructorInfo[] cons = new OpenMBeanConstructorInfoSupport[oldC.length]; for (int a = 0; a < oldC.length; ++a) cons[a] = new OpenMBeanConstructorInfoSupport(oldC[a].getName(), oldC[a].getDescription(), translateSignature(oldC[a].getSignature())); MBeanOperationInfo[] oldO = info.getOperations(); OpenMBeanOperationInfo[] ops = new OpenMBeanOperationInfoSupport[oldO.length]; for (int a = 0; a < oldO.length; ++a) ops[a] = new OpenMBeanOperationInfoSupport(oldO[a].getName(), oldO[a].getDescription(), translateSignature(oldO[a].getSignature()), Translator.translate(oldO[a].getReturnType()).getOpenType(), oldO[a].getImpact()); openInfo = new OpenMBeanInfoSupport(info.getClassName(), info.getDescription(), attribs, cons, ops, info.getNotifications()); } catch (OpenDataException e) { throw (InternalError) (new InternalError("A problem occurred creating the open type " + "descriptors.").initCause(e)); } }
/** * The operations are pulled from the core cache and the member regions. * @param cache * */ private OpenMBeanOperationInfo[] createMBeanOperationInfo() { List<OpenMBeanOperationInfo> operations = new ArrayList<OpenMBeanOperationInfo>(); for(Cache cache : getKnownCaches()) { if(cache != null && !cache.isInitialized()) operations.add( new OpenMBeanOperationInfoSupport(initializePrefix + cache.getName(), "Initialize the cache (root directory must be set first) \n" + "This action is ignored if the cache is initialized.\n" + "If the cache has been started with a valid configuration state available \n" + "it will start in an initialized state. Changes to configuration will then require a restart of the server.", new OpenMBeanParameterInfo[]{}, SimpleType.VOID, MBeanOperationInfo.ACTION) ); if(cache != null && cache.isInitialized() && !cache.isEnabled() ) operations.add( new OpenMBeanOperationInfoSupport(enablePrefix + cache.getName(), "Enable the cache (cache must be initialized)", new OpenMBeanParameterInfo[]{}, SimpleType.VOID, MBeanOperationInfo.ACTION) ); else if(cache != null && cache.isEnabled()) operations.add( new OpenMBeanOperationInfoSupport(disablePrefix + cache.getName(), "Disable the cache (cache must be initialized and enabled)", new OpenMBeanParameterInfo[]{}, SimpleType.VOID, MBeanOperationInfo.ACTION) ); } operations.add( new OpenMBeanOperationInfoSupport(storeOperation, "Store the named cache configuration to persistent storage", new OpenMBeanParameterInfo[]{new OpenMBeanParameterInfoSupport("name", "the bname of the cache to save configuration of", SimpleType.STRING)}, SimpleType.VOID, MBeanOperationInfo.ACTION) ); operations.add( new OpenMBeanOperationInfoSupport(storeAllOperation, "Store all current cache configuration to persistent storage", new OpenMBeanParameterInfo[]{}, SimpleType.VOID, MBeanOperationInfo.ACTION) ); operations.add( new OpenMBeanOperationInfoSupport(createOperation, "Create a new cache at the specified location.", new OpenMBeanParameterInfo[] { new OpenMBeanParameterInfoSupport("cacheName", "The name of the cache (and the root of the configuration file name)", SimpleType.STRING), new OpenMBeanParameterInfoSupport("cacheLocation", "The URI of the cache location (e.g. 'file:///vix/cache' or 'smb://server/cacheroot')", SimpleType.STRING), new OpenMBeanParameterInfoSupport("prototypeName", "The name of the prototype or blank(e.g. 'VixPrototype', 'TestWithEvictionPrototype')", SimpleType.STRING) }, SimpleType.STRING, MBeanOperationInfo.ACTION) ); return operations.toArray(new OpenMBeanOperationInfoSupport[operations.size()]); }
@Test public void testAddMethodSingleFixedChild() throws Exception { final ObjectName testObjectName = createObjectName(LEGACY_DOMAIN + ":subsystem=test"); final ObjectName childObjectName = createObjectName(LEGACY_DOMAIN + ":subsystem=test,single=only"); MBeanServerConnection connection = setupAndGetConnection(new MBeanInfoAdditionalInitialization(ProcessType.STANDALONE_SERVER, new SubystemWithSingleFixedChildExtension())); Set<ObjectName> names = connection.queryNames(createObjectName(LEGACY_DOMAIN + ":subsystem=test,*"), null); Assert.assertEquals(1, names.size()); Assert.assertTrue(names.contains(testObjectName)); MBeanInfo subsystemInfo = connection.getMBeanInfo(testObjectName); Assert.assertEquals(0, subsystemInfo.getAttributes().length); Assert.assertEquals(1, subsystemInfo.getOperations().length); OpenMBeanOperationInfo op = findOperation(subsystemInfo.getOperations(), "addSingleOnly"); Assert.assertEquals("add", op.getDescription()); Assert.assertEquals(1, op.getSignature().length); Assert.assertEquals(Integer.class.getName(), op.getSignature()[0].getType()); connection.invoke(testObjectName, "addSingleOnly", new Object[]{123}, new String[]{String.class.getName()}); names = connection.queryNames(createObjectName(LEGACY_DOMAIN + ":subsystem=test,*"), null); Assert.assertEquals(2, names.size()); Assert.assertTrue(names.contains(testObjectName)); Assert.assertTrue(names.contains(childObjectName)); subsystemInfo = connection.getMBeanInfo(testObjectName); Assert.assertEquals(0, subsystemInfo.getAttributes().length); Assert.assertEquals(1, subsystemInfo.getOperations().length); op = findOperation(subsystemInfo.getOperations(), "addSingleOnly"); Assert.assertEquals("add", op.getDescription()); Assert.assertEquals(1, op.getSignature().length); Assert.assertEquals(Integer.class.getName(), op.getSignature()[0].getType()); MBeanInfo childInfo = connection.getMBeanInfo(childObjectName); Assert.assertEquals(1, childInfo.getAttributes().length); Assert.assertEquals(Integer.class.getName(), childInfo.getAttributes()[0].getType()); Assert.assertEquals(1, childInfo.getOperations().length); op = findOperation(childInfo.getOperations(), REMOVE); Assert.assertEquals("remove", op.getDescription()); Assert.assertEquals(0, op.getSignature().length); Assert.assertEquals(123, connection.getAttribute(childObjectName, "attr")); try { connection.invoke(testObjectName, "addSingleOnly", new Object[]{123}, new String[]{String.class.getName()}); Assert.fail("Should not have been able to register a duplicate resource"); } catch (Exception expected) { //expected } connection.invoke(childObjectName, REMOVE, new Object[]{}, new String[]{}); names = connection.queryNames(createObjectName(LEGACY_DOMAIN + ":subsystem=test,*"), null); Assert.assertEquals(1, names.size()); Assert.assertTrue(names.contains(testObjectName)); }