ManagementInfo info = new ManagementInfo(name, group, path, description, type.getName(), readRoles, writeRoles); ManagementInfo overriden = componentType.getManagementInfo(); if (overriden != null) { info.getOperations().addAll(overriden.getOperations());
private void introspect(Object instance, ManagementInfo info) { for (Method method : instance.getClass().getMethods()) { ManagementOperation annotation = method.getAnnotation(ManagementOperation.class); if (annotation == null) { continue; } String description = annotation.description(); if (description.trim().length() == 0) { description = null; } Signature signature = new Signature(method); String[] roleNames = annotation.rolesAllowed(); Set<Role> roles = new HashSet<Role>(); for (String name : roleNames) { roles.add(new Role(name)); } String path = annotation.path(); ManagementOperationInfo operationInfo = new ManagementOperationInfo(signature, path, OperationType.UNDEFINED, description, roles); info.addOperation(operationInfo); } }
private ObjectName getObjectName(URI uri, ManagementInfo info) throws MalformedObjectNameException { String component; String subDomain; if (uri.toString().startsWith(Names.RUNTIME_NAME)) { subDomain = "runtime"; if (info.getName() == null) { component = UriHelper.getDefragmentedNameAsString(uri).substring(Names.RUNTIME_NAME.length() + 1); } else { component = info.getName(); } } else { subDomain = applicationDomain.getAuthority(); if (info.getName() == null) { component = UriHelper.getDefragmentedNameAsString(uri).substring(applicationDomain.toString().length() + 1); } else { component = info.getName(); } } String group = info.getGroup(); if (group != null) { return new ObjectName(DOMAIN + ":SubDomain=" + subDomain + ", type=component, group=" + group + ", name=" + component); } else { return new ObjectName(DOMAIN + ":SubDomain=" + subDomain + ", type=component, name=" + component); } }
private <T> OptimizedMBean<T> createOptimizedMBean(ManagementInfo info, ObjectFactory<T> objectFactory, ClassLoader loader) throws IntrospectionException, ClassNotFoundException, NoSuchMethodException { String className = info.getManagementClass(); Class<?> clazz = loader.loadClass(className); Set<AttributeDescription> attributes = new HashSet<AttributeDescription>(); Map<String, MethodHolder> setters = new HashMap<String, MethodHolder>(); Map<OperationKey, MethodHolder> operations = new HashMap<OperationKey, MethodHolder>(); for (ManagementOperationInfo operationInfo : info.getOperations()) { Method method = operationInfo.getSignature().getMethod(clazz); String description = operationInfo.getDescription(); if (roles.isEmpty()) { roles = info.getReadRoles(); if (roles.isEmpty()) { roles = info.getWriteRoles(); if (roles.isEmpty()) { roles = info.getWriteRoles(); String description = info.getDescription(); MBeanInfo mbeanInfo = new MBeanInfo(className, description, mBeanAttributes, null, mBeanOperations, null); return new OptimizedMBean<T>(objectFactory, mbeanInfo, getters, setters, operations, authorization);
writeRoles.add(new Role(Management.FABRIC3_ADMIN_ROLE)); ManagementInfo info = new ManagementInfo(name, group, path, description, clazz.getName(), readRoles, writeRoles); introspect(instance, info); managementBean = createOptimizedMBean(info, factory, loader);
public void visitMethod(ManagementOperation annotation, Method method, Class<?> implClass, InjectingComponentType componentType, IntrospectionContext context) { ManagementInfo info = componentType.getManagementInfo(); if (info == null) { // there was no management annotation on the type - record an error Class<?> clazz = method.getDeclaringClass(); context.addError(new InvalidAnnotation("Implementation is missing @" + Management.class.getSimpleName(), clazz)); return; } String description = annotation.description(); if (description.trim().length() == 0) { description = null; } Signature signature = new Signature(method); Set<Role> roles = new HashSet<Role>(); for (String roleName : annotation.rolesAllowed()) { roles.add(new Role(roleName)); } String path = annotation.path(); org.fabric3.api.annotation.management.OperationType operationType = annotation.type(); OperationType type = OperationType.valueOf(operationType.toString()); ManagementOperationInfo operationInfo = new ManagementOperationInfo(signature, path, type, description, roles); info.addOperation(operationInfo); }