modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/admin/templates/TemplateSchedulesDataSource.java | 16 +- modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/admin/templates/TemplateSchedulesView.java | 16 ++ modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/admin/templates/UpdateExistingSchedulesWidget.java | 74 ++++++++++ modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/DashboardsView.java | 35 ++-- modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/gwt/MeasurementDataGWTService.java | 7 modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/server/gwt/MeasurementDataGWTServiceImpl.java | 16 +- modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/measurement/MeasurementScheduleManagerBean.java | 15 +- 7 files changed, 143 insertions(+), 36 deletions(-)
New commits: commit 0a0aa07d0e4cdf71b1dee4a7631bd70e50715072 Author: Ian Springer ian.springer@redhat.com Date: Fri Oct 29 19:43:38 2010 -0400
add support to metric template view for specifying whether existing schedules should be updated
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/admin/templates/TemplateSchedulesDataSource.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/admin/templates/TemplateSchedulesDataSource.java index bad1853..6747b39 100644 --- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/admin/templates/TemplateSchedulesDataSource.java +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/admin/templates/TemplateSchedulesDataSource.java @@ -39,7 +39,7 @@ import org.rhq.enterprise.gui.coregui.client.inventory.common.AbstractMeasuremen import org.rhq.enterprise.gui.coregui.client.util.message.Message;
/** - * A DataSource for reading and updating the default metric schedules for a particular ResourceType. + * A DataSource for reading and updating the default metric schedules ("metric templates") for a particular ResourceType. * * @author Ian Springer */ @@ -86,8 +86,10 @@ public class TemplateSchedulesDataSource extends AbstractMeasurementScheduleComp @Override protected void enableSchedules(final AbstractMeasurementScheduleListView measurementScheduleListView, final int[] measurementDefinitionIds, final List<String> measurementDefinitionDisplayNames) { + TemplateSchedulesView templateSchedulesView = (TemplateSchedulesView)measurementScheduleListView; + boolean updateExistingSchedules = templateSchedulesView.isUpdateExistingSchedules(); final String s = (measurementDefinitionIds.length > 1) ? "s" : ""; - this.measurementService.enableMeasurementTemplates(measurementDefinitionIds, + this.measurementService.enableSchedulesForResourceType(measurementDefinitionIds, updateExistingSchedules, new AsyncCallback<Void>() { @Override public void onFailure(Throwable throwable) { @@ -110,8 +112,10 @@ public class TemplateSchedulesDataSource extends AbstractMeasurementScheduleComp @Override protected void disableSchedules(final AbstractMeasurementScheduleListView measurementScheduleListView, int[] measurementDefinitionIds, final List<String> measurementDefinitionDisplayNames) { + TemplateSchedulesView templateSchedulesView = (TemplateSchedulesView)measurementScheduleListView; + boolean updateExistingSchedules = templateSchedulesView.isUpdateExistingSchedules(); final String s = (measurementDefinitionIds.length > 1) ? "s" : ""; - this.measurementService.disableSchedulesForCompatibleGroup(this.resourceTypeId, measurementDefinitionIds, + this.measurementService.disableSchedulesForResourceType(measurementDefinitionIds, updateExistingSchedules, new AsyncCallback<Void>() { @Override public void onFailure(Throwable throwable) { @@ -135,9 +139,11 @@ public class TemplateSchedulesDataSource extends AbstractMeasurementScheduleComp protected void updateSchedules(final AbstractMeasurementScheduleListView measurementScheduleListView, int[] measurementDefinitionIds, final List<String> measurementDefinitionDisplayNames, final long collectionInterval) { + TemplateSchedulesView templateSchedulesView = (TemplateSchedulesView)measurementScheduleListView; + boolean updateExistingSchedules = templateSchedulesView.isUpdateExistingSchedules(); final String s = (measurementDefinitionIds.length > 1) ? "s" : ""; - this.measurementService.updateMeasurementTemplates(measurementDefinitionIds, collectionInterval, - new AsyncCallback<Void>() { + this.measurementService.updateSchedulesForResourceType(measurementDefinitionIds, collectionInterval, + updateExistingSchedules, new AsyncCallback<Void>() { @Override public void onFailure(Throwable throwable) { CoreGUI.getErrorHandler().handleError( diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/admin/templates/TemplateSchedulesView.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/admin/templates/TemplateSchedulesView.java index 648ae40..71f2f49 100644 --- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/admin/templates/TemplateSchedulesView.java +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/admin/templates/TemplateSchedulesView.java @@ -33,6 +33,8 @@ public class TemplateSchedulesView extends AbstractMeasurementScheduleListView {
private static final String[] EXCLUDED_FIELD_NAMES = new String[] { MeasurementScheduleCriteria.FILTER_FIELD_RESOURCE_TYPE_ID };
+ private boolean updateExistingSchedules = true; + public TemplateSchedulesView(String locatorId, int resourceTypeId) { super(locatorId, TITLE, new TemplateSchedulesDataSource(resourceTypeId), createCriteria(resourceTypeId), EXCLUDED_FIELD_NAMES); @@ -43,4 +45,18 @@ public class TemplateSchedulesView extends AbstractMeasurementScheduleListView { criteria.addCriteria(MeasurementScheduleCriteria.FILTER_FIELD_RESOURCE_TYPE_ID, resourceTypeId); return criteria; } + + @Override + protected void configureTable() { + super.configureTable(); + addExtraWidget(new UpdateExistingSchedulesWidget(this)); + } + + public boolean isUpdateExistingSchedules() { + return updateExistingSchedules; + } + + public void setUpdateExistingSchedules(boolean updateExistingSchedules) { + this.updateExistingSchedules = updateExistingSchedules; + } } diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/admin/templates/UpdateExistingSchedulesWidget.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/admin/templates/UpdateExistingSchedulesWidget.java new file mode 100644 index 0000000..8ec63ae --- /dev/null +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/admin/templates/UpdateExistingSchedulesWidget.java @@ -0,0 +1,74 @@ +/* + * RHQ Management Platform + * Copyright 2010, Red Hat Middleware LLC, and individual contributors + * as indicated by the @author tags. See the copyright.txt file in the + * distribution for a full listing of individual contributors. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ +package org.rhq.enterprise.gui.coregui.client.admin.templates; + +import com.smartgwt.client.widgets.form.DynamicForm; +import com.smartgwt.client.widgets.form.fields.CheckboxItem; +import com.smartgwt.client.widgets.form.fields.events.ChangedEvent; +import com.smartgwt.client.widgets.form.fields.events.ChangedHandler; +import com.smartgwt.client.widgets.grid.ListGrid; +import com.smartgwt.client.widgets.layout.VLayout; + +import org.rhq.enterprise.gui.coregui.client.components.table.TableWidget; +import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableDynamicForm; +import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableHLayout; + +/** + * A table widget that provides a checkbox for selecting whether or not to update existing schedules when updating + * metric templates. + * + * @author Ian Springer + */ +public class UpdateExistingSchedulesWidget extends LocatableHLayout implements TableWidget { + private TemplateSchedulesView schedulesView; + + public UpdateExistingSchedulesWidget(TemplateSchedulesView schedulesView) { + super(schedulesView.extendLocatorId("UpdateExistingSchedulesWidget")); + this.schedulesView = schedulesView; + } + + @Override + protected void onDraw() { + super.onDraw(); + + VLayout spacer = new VLayout(); + spacer.setWidth(20); + addMember(spacer); + + DynamicForm form = new LocatableDynamicForm(this.getLocatorId()); + form.setNumCols(3); + CheckboxItem checkboxItem = new CheckboxItem("updateExistingSchedules", "Update Existing Schedules"); + checkboxItem.setDefaultValue(schedulesView.isUpdateExistingSchedules()); + + checkboxItem.addChangedHandler(new ChangedHandler() { + public void onChanged(ChangedEvent changedEvent) { + boolean newValue = (Boolean)changedEvent.getValue(); + schedulesView.setUpdateExistingSchedules(newValue); + } + }); + form.setFields(checkboxItem); + addMember(form); + } + + @Override + public void refresh(ListGrid listGrid) { + return; + } +} diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/DashboardsView.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/DashboardsView.java index 422c244..bf0f629 100644 --- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/DashboardsView.java +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/DashboardsView.java @@ -22,8 +22,11 @@ */ package org.rhq.enterprise.gui.coregui.client.dashboard;
+import java.util.HashMap; import java.util.List; +import java.util.Map;
+import com.allen_sauer.gwt.log.client.Log; import com.google.gwt.user.client.History; import com.google.gwt.user.client.rpc.AsyncCallback; import com.smartgwt.client.types.Overflow; @@ -75,6 +78,7 @@ public class DashboardsView extends LocatableVLayout implements BookmarkableView private boolean editMode = false;
private List<Dashboard> dashboards; + private Map<String, Dashboard> dashboardsByName;
private DashboardView selectedDashboardView; private Dashboard selectedDashboard; @@ -112,6 +116,10 @@ public class DashboardsView extends LocatableVLayout implements BookmarkableView private void updateDashboards(List<Dashboard> dashboards) { removeMembers(getMembers()); this.dashboards = dashboards; + this.dashboardsByName = new HashMap(dashboards.size()); + for (Dashboard dashboard: dashboards) { + this.dashboardsByName.put(dashboard.getName(), dashboard); + }
tabSet = new LocatableTabSet(getLocatorId());
@@ -189,7 +197,7 @@ public class DashboardsView extends LocatableVLayout implements BookmarkableView protected Dashboard getDefaultDashboard() {
Dashboard dashboard = new Dashboard(); - dashboard.setName("Default Dashboard"); + dashboard.setName("Default"); dashboard.setColumns(2); dashboard.setColumnWidths("32%", "68%"); dashboard.getConfiguration().put(new PropertySimple(Dashboard.CFG_BACKGROUND, "#F1F2F3")); @@ -251,22 +259,17 @@ public class DashboardsView extends LocatableVLayout implements BookmarkableView }
public void addNewDashboard() { - - Dashboard dashboard = new Dashboard(); - dashboard.setName("Dashboard"); - - int i = 1; - while (true) { - boolean exists = false; - for (Dashboard db : dashboards) { - if (("Dashboard " + i).equals(db.getName())) - exists = true; - } - if (!exists) { - break; + int i = 0; + String availableDashboardName = null; + while (availableDashboardName == null) { + String candidateDashboardName = "Custom" + i++; + if (!this.dashboardsByName.containsKey(candidateDashboardName)) { + availableDashboardName = candidateDashboardName; } } - dashboard.setName("Dashboard " + i); + + Dashboard dashboard = new Dashboard(); + dashboard.setName(availableDashboardName);
dashboard.setColumns(2); dashboard.setColumnWidths("30%", "70%"); @@ -314,7 +317,7 @@ public class DashboardsView extends LocatableVLayout implements BookmarkableView } } } else { - com.allen_sauer.gwt.log.client.Log.info("WARN: While rendering DashboardsView tabSet is null."); + Log.info("WARN: While rendering DashboardsView, tabSet is null."); } } } diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/gwt/MeasurementDataGWTService.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/gwt/MeasurementDataGWTService.java index ea64488..4c145b7 100644 --- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/gwt/MeasurementDataGWTService.java +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/gwt/MeasurementDataGWTService.java @@ -80,11 +80,12 @@ public interface MeasurementDataGWTService extends RemoteService {
void updateSchedulesForCompatibleGroup(int resourceGroupId, int[] measurementDefinitionIds, long collectionInterval);
- void enableMeasurementTemplates(int[] measurementDefinitionIds); + void enableSchedulesForResourceType(int[] measurementDefinitionIds, boolean updateExistingSchedules);
- void disableMeasurementTemplates(int[] measurementDefinitionIds); + void disableSchedulesForResourceType(int[] measurementDefinitionIds, boolean updateExistingSchedules);
- void updateMeasurementTemplates(int[] measurementDefinitionIds, long collectionInterval); + void updateSchedulesForResourceType(int[] measurementDefinitionIds, long collectionInterval, + boolean updateExistingSchedules);
PageList<MeasurementDataTrait> findTraitsByCriteria(MeasurementDataTraitCriteria criteria);
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/server/gwt/MeasurementDataGWTServiceImpl.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/server/gwt/MeasurementDataGWTServiceImpl.java index 9073af2..0a83095 100644 --- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/server/gwt/MeasurementDataGWTServiceImpl.java +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/server/gwt/MeasurementDataGWTServiceImpl.java @@ -199,25 +199,29 @@ public class MeasurementDataGWTServiceImpl extends AbstractGWTServiceImpl implem } }
- public void enableMeasurementTemplates(int[] measurementDefinitionIds) { + public void enableSchedulesForResourceType(int[] measurementDefinitionIds, boolean updateExistingSchedules) { try { - scheduleManager.enableMeasurementTemplates(getSessionSubject(), measurementDefinitionIds); + scheduleManager.updateDefaultCollectionIntervalForMeasurementDefinitions(getSessionSubject(), + measurementDefinitionIds, 0, updateExistingSchedules); } catch (RuntimeException e) { throw new RuntimeException(ThrowableUtil.getAllMessages(e)); } }
- public void disableMeasurementTemplates(int[] measurementDefinitionIds) { + public void disableSchedulesForResourceType(int[] measurementDefinitionIds, boolean updateExistingSchedules) { try { - scheduleManager.disableMeasurementTemplates(getSessionSubject(), measurementDefinitionIds); + scheduleManager.updateDefaultCollectionIntervalForMeasurementDefinitions(getSessionSubject(), + measurementDefinitionIds, -1, updateExistingSchedules); } catch (RuntimeException e) { throw new RuntimeException(ThrowableUtil.getAllMessages(e)); } }
- public void updateMeasurementTemplates(int[] measurementDefinitionIds, long collectionInterval) { + public void updateSchedulesForResourceType(int[] measurementDefinitionIds, long collectionInterval, + boolean updateExistingSchedules) { try { - scheduleManager.updateMeasurementTemplates(getSessionSubject(), measurementDefinitionIds, collectionInterval); + scheduleManager.updateDefaultCollectionIntervalForMeasurementDefinitions(getSessionSubject(), + measurementDefinitionIds, collectionInterval, updateExistingSchedules); } catch (RuntimeException e) { throw new RuntimeException(ThrowableUtil.getAllMessages(e)); } diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/measurement/MeasurementScheduleManagerBean.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/measurement/MeasurementScheduleManagerBean.java index ccd65bc..3dc8b05 100644 --- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/measurement/MeasurementScheduleManagerBean.java +++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/measurement/MeasurementScheduleManagerBean.java @@ -332,13 +332,16 @@ public class MeasurementScheduleManagerBean implements MeasurementScheduleManage }
/** - * (Re-)Enables all collection schedules in the given measurement definition IDs and sets their collection - * intervals. This only enables the "templates", it does not enable actual schedules unless updateExistingSchedules - * is set to true. + * Updates the default enablement and/or collection intervals (i.e. metric templates) for the given measurement + * definitions. If updateExistingSchedules is true, the schedules for the corresponding metrics or all inventoried + * Resources are also updated. Otherwise, the updated templates will only affect Resources that added to + * inventory in the future. * * @param subject a valid subject that has Permission.MANAGE_SETTINGS * @param measurementDefinitionIds The primary keys for the definitions - * @param collectionInterval the new interval in millisconds for collection + * @param collectionInterval if > 0, enable the metric with this value as the the new collection + * interval, in milliseconds; if == 0, enable the metric with its current + * collection interval; if < 0, disable the metric * @param updateExistingSchedules If true, then existing schedules for this definition will also be updated. */ @RequiredPermission(Permission.MANAGE_SETTINGS) @@ -358,13 +361,13 @@ public class MeasurementScheduleManagerBean implements MeasurementScheduleManage return; }
- boolean enableDisable = (collectionInterval > 0); + boolean enable = (collectionInterval >= 0);
// batch the modifications to prevent the ORA error about IN clauses containing more than 1000 items for (int batchIndex = 0; (batchIndex < measurementDefinitionIds.length); batchIndex += 1000) { int[] batchIdArray = ArrayUtils.copyOfRange(measurementDefinitionIds, batchIndex, batchIndex + 1000);
- modifyDefaultCollectionIntervalForMeasurementDefinitions(subject, batchIdArray, enableDisable, + modifyDefaultCollectionIntervalForMeasurementDefinitions(subject, batchIdArray, enable, collectionInterval, updateExistingSchedules); } }
rhq-commits@lists.fedorahosted.org