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); } }
/** * Sets the ManagementInfo for this implementation. * * @param managementInfo the ManagementInfo */ public void setManagementInfo(ManagementInfo managementInfo) { managementInfo.setParent(this); this.managementInfo = managementInfo; }
private <T> OptimizedMBean<T> createOptimizedMBean(ManagementInfo info, Supplier<T> supplier) throws IntrospectionException, ClassNotFoundException, NoSuchMethodException { String className = info.getManagementClass(); Set<AttributeDescription> attributes = new HashSet<>(); Map<String, MethodHolder> getters = new HashMap<>(); Map<String, MethodHolder> setters = new HashMap<>(); Map<OperationKey, MethodHolder> operations = new HashMap<>(); for (ManagementOperationInfo operationInfo : info.getOperations()) { Method method = operationInfo.getMethod(); 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<>(supplier, mbeanInfo, getters, setters, operations, authorization);
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; } String[] roleNames = annotation.rolesAllowed(); Set<Role> roles = new HashSet<>(); for (String name : roleNames) { roles.add(new Role(name)); } String path = annotation.path(); ManagementOperationInfo operationInfo = new ManagementOperationInfo(method, path, OperationType.UNDEFINED, description, roles); info.addOperation(operationInfo); } }
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, () -> instance);
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(); String name = Management.class.getSimpleName(); context.addError(new InvalidAnnotation("Implementation is missing @" + name, method, annotation, clazz)); return; } String description = annotation.description(); if (description.trim().length() == 0) { description = null; } Set<Role> roles = new HashSet<>(); 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(method, path, type, description, roles); info.addOperation(operationInfo); }