throws Exception {
makeResponseNotCacheable(response);
final ObjectName objectName = context.getObjectName();
final ApplicationConfig config = context.getApplicationConfig();
AccessController.checkAccess(context.getServiceContext(),
ACL_VIEW_APPLICATIONS);
AccessController.checkAccess(context.getServiceContext(),
ACL_VIEW_MBEANS);
List<ApplicationConfig> applications = null;
if(config.isCluster()){
applications = config.getApplications();
}else{
applications = new ArrayList<ApplicationConfig>(1);
applications.add(config);
}
/* the ObjectInfo for the mbean that is being viewed */
ObjectInfo objInfo = null;
/* array that will be initialized with all attribute names for this
mbean */
String[] attributeNames = null;
/* a Map which constains list of attribute values for each application
in the cluster.
ApplicationConfig is the key and attribute List is the value*/
final Map<ApplicationConfig, List> appConfigToAttrListMap =
new HashMap<ApplicationConfig, List>(applications.size());
for(Iterator it=applications.iterator(); it.hasNext(); ){
ApplicationConfig childAppConfig = (ApplicationConfig)it.next();
ServerConnection serverConnection = null;
try {
serverConnection =
ServerConnector.getServerConnection(childAppConfig);
/* assuming that all servers in this cluster have exact same
object info, we will get the ObjectInfo from the first
server in the list (could be further down in the list,
if the first server(s) is down */
if(objInfo == null){
objInfo = serverConnection.getObjectInfo(objectName);
assert objInfo != null;
ObjectAttributeInfo[] attributes = objInfo.getAttributes();
attributeNames = new String[attributes.length];
for (int i = 0; i < attributes.length; i++) {
// TODO: we should only add the readable attributes here
attributeNames[i] = attributes[i].getName();
}
}
/* add attribute values of this application to the map*/
appConfigToAttrListMap.put(childAppConfig,
serverConnection.getAttributes(objectName, attributeNames));
} catch (ConnectionFailedException e){
logger.log(Level.FINE, "Error retrieving attributes for:" +
childAppConfig.getName(), e);
/* add null, indicating that the server is down */
appConfigToAttrListMap.put(childAppConfig, null);
} finally{
ServiceUtils.close(serverConnection);
}
}
/* if objInfo is null, that means that we couldn't get connection to
any server */
if(objInfo == null){
throw new ConnectionFailedException(null);
}
request.setAttribute("objInfo", objInfo);
request.setAttribute("appConfigToAttrListMap", appConfigToAttrListMap);
/* setup the form to be used in the html form */
MBeanConfigForm mbeanConfigForm = (MBeanConfigForm)actionForm;
mbeanConfigForm.setObjectName(objectName.getCanonicalName());
ApplicationConfig appConfig = context.getApplicationConfig();
MBeanConfig mbeanConfig =
appConfig.findMBeanByObjectName(objectName.getCanonicalName());
if(mbeanConfig != null){
if(appConfig.isCluster()){
request.setAttribute("mbeanIncludedIn", "cluster");
}else{
request.setAttribute("mbeanIncludedIn", "application");
}
request.setAttribute("mbeanConfig", mbeanConfig);
}else{
ApplicationConfig clusterConfig = appConfig.getClusterConfig();
if(clusterConfig != null){
mbeanConfig =
clusterConfig.findMBeanByObjectName(objectName.getCanonicalName());
}
if(mbeanConfig != null){
request.setAttribute("mbeanIncludedIn", "cluster");
request.setAttribute("mbeanConfig", mbeanConfig);
}