public ActionForward execute(ComponentContext context, ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception {
log.trace("Executing ConfigMetricsFormPrepareAction...");
Subject subject = WebUtility.getSubject(request);
MeasurementScheduleManagerLocal scheduleManager = LookupUtil.getMeasurementScheduleManager();
MeasurementDefinitionManagerLocal definitionManager = LookupUtil.getMeasurementDefinitionManager();
ResourceTypeManagerLocal rtManager = LookupUtil.getResourceTypeManager();
// NOTE: This action will be passed either a resourceTypeId OR a resourceId or a groupID or type+parent
boolean configuringDefaultSchedules = false;
int type = WebUtility.getOptionalIntRequestParameter(request, "type", -1);
int parent = WebUtility.getOptionalIntRequestParameter(request, "parent", -1);
// If only a type is present, we want the defaults
if ((type > 0) && (parent == -1)) {
configuringDefaultSchedules = true;
}
PageList<MeasurementScheduleComposite> measurementSchedules = null;
PageControl pageControl = WebUtility.getPageControl(request);
int groupId = WebUtility.getOptionalIntRequestParameter(request, "groupId", -1);
if (configuringDefaultSchedules || (groupId > 0) || ((type > 0) && (parent > 0))) {
pageControl.initDefaultOrderingField("md.name"); // underlying query runs over the MeasurementDefinition
} else {
pageControl.initDefaultOrderingField("ms.definition.name");
}
// We never want pagination for the schedules table, so don't allow user to change ps to anything other than -1.
pageControl.setPageSize(PageControl.SIZE_UNLIMITED);
if (configuringDefaultSchedules) {
int resourceTypeId = type;
log.debug("Obtaining default metric schedules for resource type " + resourceTypeId + "...");
List<MeasurementDefinition> definitions = definitionManager.findMeasurementDefinitionsByResourceType(
subject, resourceTypeId, null, null);
List<MeasurementScheduleComposite> composites = new ArrayList<MeasurementScheduleComposite>();
for (MeasurementDefinition definition : definitions) {
composites.add(new MeasurementScheduleComposite(definition, definition.isDefaultOn(), definition
.getDefaultInterval()));
}
measurementSchedules = new PageList<MeasurementScheduleComposite>(composites, definitions.size(),
pageControl);
//request.setAttribute(AttrConstants.MONITOR_ENABLED_ATTR, Boolean.FALSE);
ResourceType rType = rtManager.getResourceTypeById(subject, resourceTypeId);
request.setAttribute(AttrConstants.RESOURCE_TYPE_ATTR, rType);
//request.setAttribute("section", resourceCategoryName);
} else {
int resourceId = WebUtility.getOptionalIntRequestParameter(request, "id", -1);
if ((parent > 0) && (type > 0)) {
//request.setAttribute(AttrConstants.MONITOR_ENABLED_ATTR, true);
measurementSchedules = scheduleManager.getMeasurementScheduleCompositesByContext(subject, EntityContext
.forAutoGroup(parent, type), pageControl);
request.setAttribute("type", type);
request.setAttribute("parent", parent);
ResourceManagerLocal resMgr = LookupUtil.getResourceManager();
Resource parentRes = resMgr.getResourceById(subject, parent);
request.setAttribute("parentName", parentRes.getName());
} else if (resourceId > 0) {
boolean monitoringConfigured = isMonitoringConfigured(resourceId);
//request.setAttribute(AttrConstants.MONITOR_ENABLED_ATTR, monitoringConfigured);
if (monitoringConfigured) {
log.debug("Obtaining metric schedules for resource " + resourceId + "...");
measurementSchedules = scheduleManager.getMeasurementScheduleCompositesByContext(subject,
EntityContext.forResource(resourceId), pageControl);
}
} else if (groupId > 0) {
boolean monitoringConfigured = true; // isMonitoringConfiguredForGroup(groupId); // TODO implement the method, see below
//request.setAttribute(AttrConstants.MONITOR_ENABLED_ATTR, true); // TODO change true -> monitoringConfigured
if (monitoringConfigured) {
log.debug("Obtaining metric schedules for comp group " + groupId + "...");
measurementSchedules = scheduleManager.getMeasurementScheduleCompositesByContext(subject,
EntityContext.forGroup(groupId), pageControl);
request.setAttribute(AttrConstants.GROUP_ID, groupId);
}
//adding the groupName into the request to display on config page.