modules/enterprise/gui/coregui/src/main/java/org/rhq/coregui/client/dashboard/portlets/groups/GroupMetricsPortlet.java
| 360 ++++------
modules/enterprise/gui/coregui/src/main/java/org/rhq/coregui/client/dashboard/portlets/resource/ResourceMetricsPortlet.java
| 318 +++-----
2 files changed, 316 insertions(+), 362 deletions(-)
New commits:
commit a0452e14bb4958093d8ece81e29caec017e45bf2
Author: Mike Thompson <mithomps(a)redhat.com>
Date: Tue Nov 26 14:46:14 2013 -0800
[BZ 1034852] time range change in summary->activity doesn't change time range
in monitoring->metrics
(cherry picked from commit 6b6f1894258cb4dcbcd2cdcf82908a1d266f3f59)
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/coregui/client/dashboard/portlets/groups/GroupMetricsPortlet.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/coregui/client/dashboard/portlets/groups/GroupMetricsPortlet.java
index b3b734a..c1d7269 100644
---
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/coregui/client/dashboard/portlets/groups/GroupMetricsPortlet.java
+++
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/coregui/client/dashboard/portlets/groups/GroupMetricsPortlet.java
@@ -33,6 +33,9 @@ import com.smartgwt.client.types.Overflow;
import com.smartgwt.client.types.VerticalAlignment;
import com.smartgwt.client.widgets.Canvas;
import com.smartgwt.client.widgets.HTMLFlow;
+import com.smartgwt.client.widgets.Window;
+import com.smartgwt.client.widgets.events.CloseClickEvent;
+import com.smartgwt.client.widgets.events.CloseClickHandler;
import com.smartgwt.client.widgets.form.DynamicForm;
import com.smartgwt.client.widgets.form.events.SubmitValuesEvent;
import com.smartgwt.client.widgets.form.events.SubmitValuesHandler;
@@ -67,7 +70,6 @@ import
org.rhq.coregui.client.dashboard.portlets.PortletConfigurationEditorCompo
import
org.rhq.coregui.client.dashboard.portlets.PortletConfigurationEditorComponent.Constant;
import org.rhq.coregui.client.gwt.GWTServiceLookup;
import org.rhq.coregui.client.inventory.common.detail.summary.AbstractActivityView;
-import
org.rhq.coregui.client.inventory.common.detail.summary.AbstractActivityView.ChartViewWindow;
import org.rhq.coregui.client.inventory.common.graph.CustomDateRangeState;
import
org.rhq.coregui.client.inventory.groups.detail.monitoring.table.CompositeGroupD3GraphListView;
import
org.rhq.coregui.client.inventory.groups.detail.monitoring.table.CompositeGroupD3MultiLineGraph;
@@ -83,6 +85,7 @@ import org.rhq.coregui.client.util.enhanced.EnhancedVLayout;
*/
public class GroupMetricsPortlet extends EnhancedVLayout implements
CustomSettingsPortlet, AutoRefreshPortlet {
+ public static final String CHART_TITLE = MSG.common_title_metric_chart();
private int groupId = -1;
private EntityContext context;
protected Canvas recentMeasurementsContent = new Canvas();
@@ -99,6 +102,10 @@ public class GroupMetricsPortlet extends EnhancedVLayout implements
CustomSettin
protected Timer refreshTimer;
+ // final version needed to pass to anon classes
+ // so we can call refresh in anon callback handler
+ final protected GroupMetricsPortlet refreshablePortlet;
+
//defines the list of configuration elements to load/persist for this portlet
protected static List<String> CONFIG_INCLUDE = new ArrayList<String>();
static {
@@ -113,6 +120,7 @@ public class GroupMetricsPortlet extends EnhancedVLayout implements
CustomSettin
super();
this.groupId = context.getGroupId();
this.context = context;
+ this.refreshablePortlet = this;
}
@Override
@@ -372,7 +380,7 @@ public class GroupMetricsPortlet extends EnhancedVLayout implements
CustomSettin
@Override
public void
onClick(ClickEvent event) {
ChartViewWindow
window = new ChartViewWindow(
- title);
+ title,
"", refreshablePortlet);
CompositeGroupD3GraphListView graph = new CompositeGroupD3MultiLineGraph(
groupId,
md.getId(), isAutoGroup);
window.addItem(graph);
@@ -489,4 +497,40 @@ public class GroupMetricsPortlet extends EnhancedVLayout implements
CustomSettin
protected void setRefreshing(boolean currentlyRefreshing) {
this.currentlyLoading = currentlyRefreshing;
}
+ public static class ChartViewWindow extends Window {
+
+
+ public ChartViewWindow(String title, String windowTitle,final GroupMetricsPortlet
portlet) {
+ super();
+ if ((windowTitle != null) && (!windowTitle.trim().isEmpty())) {
+ setTitle(windowTitle + ": " + title);
+ } else {
+ setTitle(CHART_TITLE + ": " + title);
+ }
+ setShowMinimizeButton(false);
+ setShowMaximizeButton(false);
+ setShowCloseButton(true);
+ setIsModal(true);
+ setShowModalMask(true);
+ setWidth(950);
+ setHeight(420);
+ setShowResizer(true);
+ setCanDragResize(true);
+ centerInPage();
+
+ addCloseClickHandler(new CloseClickHandler() {
+ @Override
+ public void onCloseClick(CloseClickEvent event) {
+ try {
+ ChartViewWindow.this.destroy();
+ portlet.refresh();
+
+ } catch (Throwable e) {
+ Log.warn("Cannot destroy chart display window.", e);
+ }
+ }
+ });
+
+ }
+ }
}
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/coregui/client/dashboard/portlets/resource/ResourceMetricsPortlet.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/coregui/client/dashboard/portlets/resource/ResourceMetricsPortlet.java
index 862749d..ddd70a3 100644
---
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/coregui/client/dashboard/portlets/resource/ResourceMetricsPortlet.java
+++
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/coregui/client/dashboard/portlets/resource/ResourceMetricsPortlet.java
@@ -55,7 +55,6 @@ import org.rhq.coregui.client.dashboard.PortletViewFactory;
import org.rhq.coregui.client.dashboard.portlets.groups.GroupMetricsPortlet;
import org.rhq.coregui.client.gwt.GWTServiceLookup;
import org.rhq.coregui.client.inventory.common.detail.summary.AbstractActivityView;
-import
org.rhq.coregui.client.inventory.common.detail.summary.AbstractActivityView.ChartViewWindow;
import org.rhq.coregui.client.inventory.common.graph.CustomDateRangeState;
import org.rhq.coregui.client.inventory.resource.detail.monitoring.D3GraphListView;
import org.rhq.coregui.client.inventory.resource.type.ResourceTypeRepository;
@@ -240,7 +239,7 @@ public class ResourceMetricsPortlet extends GroupMetricsPortlet {
link.addClickHandler(new
ClickHandler() {
@Override
public void
onClick(ClickEvent event) {
- window = new
ChartViewWindow(title);
+ window = new
ChartViewWindow(title,"", refreshablePortlet);
graphView =
D3GraphListView.createSingleGraph(
resourceComposite.getResource(), md.getId(),
commit 393d350149f01f0c30b3b897c1f68acd9f6453ef
Author: Mike Thompson <mithomps(a)redhat.com>
Date: Tue Nov 26 12:20:40 2013 -0800
[BZ 1035443] Summary Last Metrics values are different values than Chart Last Metric
values.
(cherry picked from commit a532e90dd41ce1fcfb3f3d9fbdf126448ac80c1c)
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/coregui/client/dashboard/portlets/groups/GroupMetricsPortlet.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/coregui/client/dashboard/portlets/groups/GroupMetricsPortlet.java
index 9fe962c..b3b734a 100644
---
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/coregui/client/dashboard/portlets/groups/GroupMetricsPortlet.java
+++
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/coregui/client/dashboard/portlets/groups/GroupMetricsPortlet.java
@@ -68,15 +68,16 @@ import
org.rhq.coregui.client.dashboard.portlets.PortletConfigurationEditorCompo
import org.rhq.coregui.client.gwt.GWTServiceLookup;
import org.rhq.coregui.client.inventory.common.detail.summary.AbstractActivityView;
import
org.rhq.coregui.client.inventory.common.detail.summary.AbstractActivityView.ChartViewWindow;
+import org.rhq.coregui.client.inventory.common.graph.CustomDateRangeState;
import
org.rhq.coregui.client.inventory.groups.detail.monitoring.table.CompositeGroupD3GraphListView;
import
org.rhq.coregui.client.inventory.groups.detail.monitoring.table.CompositeGroupD3MultiLineGraph;
import org.rhq.coregui.client.inventory.resource.type.ResourceTypeRepository;
import org.rhq.coregui.client.util.BrowserUtility;
import org.rhq.coregui.client.util.Log;
-import org.rhq.coregui.client.util.MeasurementUtility;
import org.rhq.coregui.client.util.enhanced.EnhancedVLayout;
-/**This portlet allows the end user to customize the metric display
+/**
+ * This portlet allows the end user to customize the metric display
*
* @author Simeon Pinder
*/
@@ -86,11 +87,6 @@ public class GroupMetricsPortlet extends EnhancedVLayout implements
CustomSettin
private EntityContext context;
protected Canvas recentMeasurementsContent = new Canvas();
protected boolean currentlyLoading = false;
- protected long start = -1;
- protected long end = -1;
- protected int lastN = -1;
- protected int units = -1;
-
// A non-displayed, persisted identifier for the portlet
public static final String KEY = "GroupMetrics";
// A default displayed, persisted name for the portlet
@@ -216,46 +212,11 @@ public class GroupMetricsPortlet extends EnhancedVLayout implements
CustomSettin
* digits.
*/
protected void getRecentMetrics() {
- final DashboardPortlet storedPortlet = this.portletWindow.getStoredPortlet();
- final Configuration portletConfig = storedPortlet.getConfiguration();
//display container
final VLayout column = new VLayout();
column.setHeight(10);//pack
- //initialize to defaults
- end = -1;
- start = -1;
- lastN = -1;
- units = -1;
-
- //result timeframe if enabled
- PropertySimple property = portletConfig.getSimple(Constant.METRIC_RANGE_ENABLE);
- if (null != property && Boolean.valueOf(property.getBooleanValue()))
{//then proceed setting
-
- boolean isAdvanced =
Boolean.valueOf(portletConfig.getSimpleValue(Constant.METRIC_RANGE_BEGIN_END_FLAG,
- Constant.METRIC_RANGE_BEGIN_END_FLAG_DEFAULT));
- if (isAdvanced) {
- //Advanced time settings
- String currentSetting =
portletConfig.getSimpleValue(Constant.METRIC_RANGE,
- Constant.METRIC_RANGE_DEFAULT);
- String[] range = currentSetting.split(",");
- if (range.length == 2) {
- start = Long.valueOf(range[0]);
- end = Long.valueOf(range[1]);
- }
- } else {
- //Simple time settings
- property = portletConfig.getSimple(Constant.METRIC_RANGE_LASTN);
- if (property != null) {
- lastN =
Integer.valueOf(portletConfig.getSimpleValue(Constant.METRIC_RANGE_LASTN,
- Constant.METRIC_RANGE_LASTN_DEFAULT));
- units =
Integer.valueOf(portletConfig.getSimpleValue(Constant.METRIC_RANGE_UNIT,
- Constant.METRIC_RANGE_UNIT_DEFAULT));
- }
- }
- }
-
//locate resourceGroupRef
ResourceGroupCriteria criteria = new ResourceGroupCriteria();
criteria.addFilterId(this.groupId);
@@ -324,158 +285,151 @@ public class GroupMetricsPortlet extends EnhancedVLayout
implements CustomSettin
.getId();
}
-
AsyncCallback<List<List<MeasurementDataNumericHighLowComposite>>>
callback = new
AsyncCallback<List<List<MeasurementDataNumericHighLowComposite>>>() {
- @Override
- public void onFailure(Throwable caught) {
- Log.debug("Error retrieving recent
metrics charting data for group ["
- + groupId + "]:" +
caught.getMessage());
- setRefreshing(false);
- }
+
GWTServiceLookup.getMeasurementDataService().findDataForCompatibleGroup(
+ groupId, definitionArrayIds,
+
CustomDateRangeState.getInstance().getStartTime(),
+
CustomDateRangeState.getInstance().getEndTime(), 60,
+ new
AsyncCallback<List<List<MeasurementDataNumericHighLowComposite>>>() {
+ @Override
+ public void onFailure(Throwable caught)
{
+ Log.debug("Error retrieving
recent metrics charting data for group ["
+ + groupId + "]:" +
caught.getMessage());
+ setRefreshing(false);
+ }
- @Override
- public void onSuccess(
-
List<List<MeasurementDataNumericHighLowComposite>> results) {
- if (!results.isEmpty()) {
- boolean someChartedData = false;
- //iterate over the retrieved charting
data
- for (int index = 0; index <
displayOrder.length; index++) {
- //retrieve the correct
measurement definition
- final MeasurementDefinition md =
measurementDefMap
- .get(displayOrder[index]);
-
- //load the data results for the
given metric definition
-
List<MeasurementDataNumericHighLowComposite> data = results
- .get(index);
-
- //locate last and minimum
values.
- double lastValue = -1;
- double minValue =
Double.MAX_VALUE;//
- for
(MeasurementDataNumericHighLowComposite d : data) {
- if
((!Double.isNaN(d.getValue()))
- &&
(String.valueOf(d.getValue()).indexOf("NaN") == -1)) {
- if (d.getValue() <
minValue) {
- minValue =
d.getValue();
+ @Override
+ public void onSuccess(
+
List<List<MeasurementDataNumericHighLowComposite>> results) {
+ if (!results.isEmpty()) {
+ boolean someChartedData = false;
+ //iterate over the retrieved
charting data
+ for (int index = 0; index <
displayOrder.length; index++) {
+ //retrieve the correct
measurement definition
+ final MeasurementDefinition
md = measurementDefMap
+
.get(displayOrder[index]);
+
+ //load the data results for
the given metric definition
+
List<MeasurementDataNumericHighLowComposite> data = results
+ .get(index);
+
+ //locate last and minimum
values.
+ double lastValue = -1;
+ double minValue =
Double.MAX_VALUE;//
+ for
(MeasurementDataNumericHighLowComposite d : data) {
+ if
((!Double.isNaN(d.getValue()))
+ &&
(!String.valueOf(d.getValue()).contains("NaN"))) {
+ if (d.getValue() <
minValue) {
+ minValue =
d.getValue();
+ }
+ lastValue =
d.getValue();
}
- lastValue =
d.getValue();
}
- }
- //collapse the data into comma
delimited list for consumption by third party javascript library(jquery.sparkline)
- String commaDelimitedList =
"";
+ //collapse the data into
comma delimited list for consumption by third party javascript library(jquery.sparkline)
+ String commaDelimitedList =
"";
- for
(MeasurementDataNumericHighLowComposite d : data) {
- if
((!Double.isNaN(d.getValue()))
- &&
(String.valueOf(d.getValue()).indexOf("NaN") == -1)) {
- commaDelimitedList +=
d.getValue() + ",";
+ for
(MeasurementDataNumericHighLowComposite d : data) {
+ if
((!Double.isNaN(d.getValue()))
+ &&
(!String.valueOf(d.getValue()).contains("NaN"))) {
+ commaDelimitedList +=
d.getValue() + ",";
+ }
}
- }
- DynamicForm row = new
DynamicForm();
- row.setNumCols(3);
- row.setColWidths(65,
"*", 100);
- row.setWidth100();
- row.setAutoHeight();
-
row.setOverflow(Overflow.VISIBLE);
- HTMLFlow graph = new HTMLFlow();
- // String
contents = "<span id='sparkline_" + index + "'
class='dynamicsparkline' width='0'>"
- // +
commaDelimitedList + "</span>";
- String contents = "<span
id='sparkline_" + index
- + "'
class='dynamicsparkline' width='0' " + "values='"
- + commaDelimitedList +
"'>...</span>";
- graph.setContents(contents);
-
graph.setContentsType(ContentsType.PAGE);
- //disable scrollbars on span
- graph.setScrollbarSize(0);
-
- CanvasItem graphContainer = new
CanvasItem();
-
graphContainer.setShowTitle(false);
- graphContainer.setHeight(16);
- graphContainer.setWidth(60);
- graphContainer.setCanvas(graph);
-
- final String title =
md.getDisplayName();
- LinkItem link =
AbstractActivityView.newLinkItem(title, null);
- link.setTooltip(title);
-
link.setTitleVAlign(VerticalAlignment.TOP);
- link.setAlign(Alignment.LEFT);
- link.setClipValue(true);
- link.setWrap(true);
- link.setHeight(26);
-
if(!BrowserUtility.isBrowserPreIE9()){
-
- link.addClickHandler(new
ClickHandler() {
- @Override
- public void
onClick(ClickEvent event) {
- ChartViewWindow window =
new ChartViewWindow(title);
-
CompositeGroupD3GraphListView graph = new CompositeGroupD3MultiLineGraph(
- groupId, md.getId(),
isAutoGroup);
- window.addItem(graph);
- graph.populateData();
- window.show();
+ DynamicForm row = new
DynamicForm();
+ row.setNumCols(3);
+ row.setColWidths(65,
"*", 100);
+ row.setWidth100();
+ row.setAutoHeight();
+
row.setOverflow(Overflow.VISIBLE);
+ HTMLFlow graph = new
HTMLFlow();
+ //
String contents = "<span id='sparkline_" + index + "'
class='dynamicsparkline' width='0'>"
+ //
+ commaDelimitedList + "</span>";
+ String contents =
"<span id='sparkline_" + index
+ + "'
class='dynamicsparkline' width='0' " + "values='"
+ + commaDelimitedList +
"'>...</span>";
+ graph.setContents(contents);
+
graph.setContentsType(ContentsType.PAGE);
+ //disable scrollbars on span
+ graph.setScrollbarSize(0);
+
+ CanvasItem graphContainer =
new CanvasItem();
+
graphContainer.setShowTitle(false);
+
graphContainer.setHeight(16);
+ graphContainer.setWidth(60);
+
graphContainer.setCanvas(graph);
+
+ final String title =
md.getDisplayName();
+ LinkItem link =
AbstractActivityView.newLinkItem(title,
+ null);
+ link.setTooltip(title);
+
link.setTitleVAlign(VerticalAlignment.TOP);
+
link.setAlign(Alignment.LEFT);
+ link.setClipValue(true);
+ link.setWrap(true);
+ link.setHeight(26);
+ if
(!BrowserUtility.isBrowserPreIE9()) {
+
+ link.addClickHandler(new
ClickHandler() {
+ @Override
+ public void
onClick(ClickEvent event) {
+ ChartViewWindow
window = new ChartViewWindow(
+ title);
+
CompositeGroupD3GraphListView graph = new CompositeGroupD3MultiLineGraph(
+ groupId,
md.getId(), isAutoGroup);
+
window.addItem(graph);
+
graph.populateData();
+ window.show();
+ }
+ });
+ } else {
+ link.disable();
}
- });
- }else {
- link.disable();
- }
-
- //Value
- String convertedValue =
AbstractActivityView
-
.convertLastValueForDisplay(lastValue, md);
- StaticTextItem value =
AbstractActivityView
-
.newTextItem(convertedValue);
-
value.setVAlign(VerticalAlignment.TOP);
- value.setAlign(Alignment.RIGHT);
-
value.setWidth("100%");
-
- row.setItems(graphContainer,
link, value);
- row.setWidth100();
- //if graph content returned
- if
((!md.getName().trim().contains("Trait."))
- && (lastValue != -1))
{
+ //Value
+ String convertedValue =
AbstractActivityView
+
.convertLastValueForDisplay(lastValue, md);
+ StaticTextItem value =
AbstractActivityView
+
.newTextItem(convertedValue);
+
value.setVAlign(VerticalAlignment.TOP);
+
value.setAlign(Alignment.RIGHT);
+
value.setWidth("100%");
+
+ row.setItems(graphContainer,
link, value);
+ row.setWidth100();
+ //if graph content returned
+ if
((!md.getName().trim().contains("Trait."))
+ && (lastValue !=
-1)) {
+ column.addMember(row);
+ someChartedData = true;
+ }
+ }
+ if (!someChartedData) {// when
there are results but no chartable entries.
+ DynamicForm row =
AbstractActivityView
+
.createEmptyDisplayRow(AbstractActivityView.RECENT_MEASUREMENTS_GROUP_NONE);
column.addMember(row);
- someChartedData = true;
+ } else {
+ //insert see more link
+ DynamicForm row = new
DynamicForm();
+ String link = LinkManager
+
.getGroupMonitoringGraphsLink(context);
+
AbstractActivityView.addSeeMoreLink(row, link, column);
}
- }
- if (!someChartedData) {// when there
are results but no chartable entries.
- DynamicForm row =
AbstractActivityView
-
.createEmptyDisplayRow(AbstractActivityView.RECENT_MEASUREMENTS_GROUP_NONE);
- column.addMember(row);
+ //call out to 3rd party
javascript lib
+ new Timer() {
+ @Override
+ public void run() {
+
BrowserUtility.graphSparkLines();
+ }
+ }.schedule(200);
+
} else {
- //insert see more link
- DynamicForm row = new
DynamicForm();
- String link =
LinkManager.getGroupMonitoringGraphsLink(context);
-
AbstractActivityView.addSeeMoreLink(row, link, column);
+ DynamicForm row =
AbstractActivityView.createEmptyDisplayRow(
+
AbstractActivityView.RECENT_MEASUREMENTS_GROUP_NONE);
+ column.addMember(row);
}
- //call out to 3rd party javascript
lib
- new Timer(){
- @Override
- public void run() {
-
BrowserUtility.graphSparkLines();
- }
- }.schedule(200);
- } else {
- DynamicForm row =
AbstractActivityView.createEmptyDisplayRow(
-
-
AbstractActivityView.RECENT_MEASUREMENTS_GROUP_NONE);
- column.addMember(row);
+ setRefreshing(false);
}
- setRefreshing(false);
}
- };
-
- //make the asynchronous call for all the
measurement data
- if (end != -1 && start != -1) {
-
GWTServiceLookup.getMeasurementDataService().findDataForCompatibleGroup(
- groupId, definitionArrayIds, start, end,
60, callback);
- } else if (lastN != -1 && units != -1) {
- GWTServiceLookup.getMeasurementDataService()
-
.findDataForCompatibleGroupForLast(groupId, definitionArrayIds, lastN,
- units, 60, callback);
- } else {
- GWTServiceLookup.getMeasurementDataService()
-
.findDataForCompatibleGroupForLast(groupId, definitionArrayIds, 8,
- MeasurementUtility.UNIT_HOURS, 60,
callback);
- }
+ );
}
});
}
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/coregui/client/dashboard/portlets/resource/ResourceMetricsPortlet.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/coregui/client/dashboard/portlets/resource/ResourceMetricsPortlet.java
index d470663..862749d 100644
---
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/coregui/client/dashboard/portlets/resource/ResourceMetricsPortlet.java
+++
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/coregui/client/dashboard/portlets/resource/ResourceMetricsPortlet.java
@@ -41,8 +41,6 @@ import com.smartgwt.client.widgets.form.fields.events.ClickHandler;
import com.smartgwt.client.widgets.layout.VLayout;
import org.rhq.core.domain.common.EntityContext;
-import org.rhq.core.domain.configuration.Configuration;
-import org.rhq.core.domain.configuration.PropertySimple;
import org.rhq.core.domain.criteria.ResourceCriteria;
import org.rhq.core.domain.dashboard.DashboardPortlet;
import org.rhq.core.domain.measurement.MeasurementDefinition;
@@ -54,18 +52,18 @@ import org.rhq.core.domain.util.PageList;
import org.rhq.coregui.client.LinkManager;
import org.rhq.coregui.client.dashboard.Portlet;
import org.rhq.coregui.client.dashboard.PortletViewFactory;
-import
org.rhq.coregui.client.dashboard.portlets.PortletConfigurationEditorComponent.Constant;
import org.rhq.coregui.client.dashboard.portlets.groups.GroupMetricsPortlet;
import org.rhq.coregui.client.gwt.GWTServiceLookup;
import org.rhq.coregui.client.inventory.common.detail.summary.AbstractActivityView;
import
org.rhq.coregui.client.inventory.common.detail.summary.AbstractActivityView.ChartViewWindow;
+import org.rhq.coregui.client.inventory.common.graph.CustomDateRangeState;
import org.rhq.coregui.client.inventory.resource.detail.monitoring.D3GraphListView;
import org.rhq.coregui.client.inventory.resource.type.ResourceTypeRepository;
import org.rhq.coregui.client.util.BrowserUtility;
import org.rhq.coregui.client.util.Log;
-import org.rhq.coregui.client.util.MeasurementUtility;
-/**This portlet allows the end user to customize the metric display
+/**
+ * This portlet allows the end user to customize the metric display
*
* @author Simeon Pinder
*/
@@ -106,45 +104,11 @@ public class ResourceMetricsPortlet extends GroupMetricsPortlet {
@Override
protected void getRecentMetrics() {
final DashboardPortlet storedPortlet = this.portletWindow.getStoredPortlet();
- final Configuration portletConfig = storedPortlet.getConfiguration();
//display container
final VLayout column = new VLayout();
column.setHeight(10);//pack
column.setWidth100();
- //initialize to defaults
- end = -1;
- start = -1;
- lastN = -1;
- units = -1;
-
- //result timeframe if enabled
- PropertySimple property = portletConfig.getSimple(Constant.METRIC_RANGE_ENABLE);
- if (null != property && property.getBooleanValue()) {//then proceed
setting
-
- boolean isAdvanced =
Boolean.valueOf(portletConfig.getSimpleValue(Constant.METRIC_RANGE_BEGIN_END_FLAG,
- Constant.METRIC_RANGE_BEGIN_END_FLAG_DEFAULT));
- if (isAdvanced) {
- //Advanced time settings
- String currentSetting =
portletConfig.getSimpleValue(Constant.METRIC_RANGE,
- Constant.METRIC_RANGE_DEFAULT);
- String[] range = currentSetting.split(",");
- if (range.length == 2) {
- start = Long.valueOf(range[0]);
- end = Long.valueOf(range[1]);
- }
- } else {
- //Simple time settings
- property = portletConfig.getSimple(Constant.METRIC_RANGE_LASTN);
- if (property != null) {
- lastN =
Integer.valueOf(portletConfig.getSimpleValue(Constant.METRIC_RANGE_LASTN,
- Constant.METRIC_RANGE_LASTN_DEFAULT));
- units =
Integer.valueOf(portletConfig.getSimpleValue(Constant.METRIC_RANGE_UNIT,
- Constant.METRIC_RANGE_UNIT_DEFAULT));
- }
- }
- }
-
//locate resource reference
ResourceCriteria criteria = new ResourceCriteria();
criteria.addFilterId(this.resourceId);
@@ -166,9 +130,8 @@ public class ResourceMetricsPortlet extends GroupMetricsPortlet {
final Resource resource = resourceComposite.getResource();
// Load the fully fetched ResourceType.
ResourceType resourceType = resource.getResourceType();
- ResourceTypeRepository.Cache.getInstance().getResourceTypes(
- resourceType.getId(),
- EnumSet.of(ResourceTypeRepository.MetadataType.measurements
),
+
ResourceTypeRepository.Cache.getInstance().getResourceTypes(resourceType.getId(),
+
EnumSet.of(ResourceTypeRepository.MetadataType.measurements),
new ResourceTypeRepository.TypeLoadedCallback() {
public void onTypesLoaded(ResourceType type) {
resource.setResourceType(type);
@@ -194,158 +157,152 @@ public class ResourceMetricsPortlet extends GroupMetricsPortlet {
.getId();
}
-
AsyncCallback<List<List<MeasurementDataNumericHighLowComposite>>>
callback = new
AsyncCallback<List<List<MeasurementDataNumericHighLowComposite>>>() {
- @Override
- public void onFailure(Throwable caught) {
- Log.debug("Error retrieving recent
metrics charting data for resource ["
- + resourceId + "]:" +
caught.getMessage());
- setRefreshing(false);
- }
+
GWTServiceLookup.getMeasurementDataService().findDataForResource(resourceId,
+ definitionArrayIds,
CustomDateRangeState.getInstance().getStartTime(),
+ CustomDateRangeState.getInstance().getEndTime(),
60,
+ new
AsyncCallback<List<List<MeasurementDataNumericHighLowComposite>>>() {
+ @Override
+ public void onFailure(Throwable caught) {
+ Log.debug("Error retrieving recent
metrics charting data for resource ["
+ + resourceId + "]:" +
caught.getMessage());
+ setRefreshing(false);
+ }
- @Override
- public void
onSuccess(List<List<MeasurementDataNumericHighLowComposite>> results) {
- if (!results.isEmpty()) {
- boolean someChartedData = false;
- //iterate over the retrieved charting
data
- for (int index = 0; index <
displayOrder.length; index++) {
- //retrieve the correct measurement
definition
- final MeasurementDefinition md =
measurementDefMap
- .get(displayOrder[index]);
-
- //load the data results for the given
metric definition
-
List<MeasurementDataNumericHighLowComposite> data = results
- .get(index);
-
- //locate last and minimum values.
- double lastValue = -1;
- double minValue =
Double.MAX_VALUE;//
- for
(MeasurementDataNumericHighLowComposite d : data) {
- if
((!Double.isNaN(d.getValue()))
- &&
(!String.valueOf(d.getValue()).contains("NaN"))) {
- if (d.getValue() <
minValue) {
- minValue = d.getValue();
+ @Override
+ public void onSuccess(
+
List<List<MeasurementDataNumericHighLowComposite>> results) {
+ if (!results.isEmpty()) {
+ boolean someChartedData = false;
+ //iterate over the retrieved charting
data
+ for (int index = 0; index <
displayOrder.length; index++) {
+ //retrieve the correct
measurement definition
+ final MeasurementDefinition md =
measurementDefMap
+ .get(displayOrder[index]);
+
+ //load the data results for the
given metric definition
+
List<MeasurementDataNumericHighLowComposite> data = results
+ .get(index);
+
+ //locate last and minimum
values.
+ double lastValue = -1;
+ double minValue =
Double.MAX_VALUE;//
+ for
(MeasurementDataNumericHighLowComposite d : data) {
+ if
((!Double.isNaN(d.getValue()))
+ &&
(!String.valueOf(d.getValue()).contains("NaN"))) {
+ if (d.getValue() <
minValue) {
+ minValue =
d.getValue();
+ }
+ lastValue =
d.getValue();
}
- lastValue = d.getValue();
}
- }
- //collapse the data into comma
delimited list for consumption by third party javascript library(jquery.sparkline)
- String commaDelimitedList =
"";
+ //collapse the data into comma
delimited list for consumption by third party javascript library(jquery.sparkline)
+ String commaDelimitedList =
"";
- for
(MeasurementDataNumericHighLowComposite d : data) {
- if
((!Double.isNaN(d.getValue()))
- &&
(!String.valueOf(d.getValue()).contains("NaN"))) {
- commaDelimitedList +=
d.getValue() + ",";
- }
- }
- DynamicForm row = new DynamicForm();
- row.setNumCols(3);
- row.setColWidths(65, "*",
100);
- row.setWidth100();
- row.setAutoHeight();
- row.setOverflow(Overflow.VISIBLE);
- HTMLFlow sparklineGraph = new
HTMLFlow();
- String contents = "<span
id='sparkline_" + index
- + "'
class='dynamicsparkline' width='0' " + "values='"
- + commaDelimitedList +
"'>...</span>";
-
sparklineGraph.setContents(contents);
-
sparklineGraph.setContentsType(ContentsType.PAGE);
- //disable scrollbars on span
- sparklineGraph.setScrollbarSize(0);
-
- CanvasItem sparklineContainer = new
CanvasItem();
-
sparklineContainer.setShowTitle(false);
- sparklineContainer.setHeight(16);
- sparklineContainer.setWidth(60);
-
sparklineContainer.setCanvas(sparklineGraph);
-
- //Link/title element
- final String title =
md.getDisplayName();
- LinkItem link =
AbstractActivityView.newLinkItem(title, null);
- link.setTooltip(title);
-
link.setTitleVAlign(VerticalAlignment.TOP);
- link.setAlign(Alignment.LEFT);
- link.setClipValue(true);
- link.setWrap(true);
- link.setHeight(26);
- link.setWidth("100%");
-
if(!BrowserUtility.isBrowserPreIE9()){
- link.addClickHandler(new
ClickHandler() {
- @Override
- public void
onClick(ClickEvent event) {
- window = new
ChartViewWindow(title);
-
- graphView =
D3GraphListView
-
.createSingleGraph(resourceComposite.getResource(),
- md.getId(),
true);
-
-
window.addItem(graphView);
- window.show();
+ for
(MeasurementDataNumericHighLowComposite d : data) {
+ if
((!Double.isNaN(d.getValue()))
+ &&
(!String.valueOf(d.getValue()).contains("NaN"))) {
+ commaDelimitedList +=
d.getValue() + ",";
}
- });
- }else{
- link.disable();
- }
-
-
- //Value
- String convertedValue;
- convertedValue =
AbstractActivityView.convertLastValueForDisplay(
- lastValue, md);
- StaticTextItem value =
AbstractActivityView
- .newTextItem(convertedValue);
-
value.setVAlign(VerticalAlignment.TOP);
- value.setAlign(Alignment.RIGHT);
+ }
+ DynamicForm row = new
DynamicForm();
+ row.setNumCols(3);
+ row.setColWidths(65,
"*", 100);
+ row.setWidth100();
+ row.setAutoHeight();
+
row.setOverflow(Overflow.VISIBLE);
+ HTMLFlow sparklineGraph = new
HTMLFlow();
+ String contents = "<span
id='sparkline_" + index
+ + "'
class='dynamicsparkline' width='0' " + "values='"
+ + commaDelimitedList +
"'>...</span>";
+
sparklineGraph.setContents(contents);
+
sparklineGraph.setContentsType(ContentsType.PAGE);
+ //disable scrollbars on span
+
sparklineGraph.setScrollbarSize(0);
+
+ CanvasItem sparklineContainer =
new CanvasItem();
+
sparklineContainer.setShowTitle(false);
+
sparklineContainer.setHeight(16);
+ sparklineContainer.setWidth(60);
+
sparklineContainer.setCanvas(sparklineGraph);
+
+ //Link/title element
+ final String title =
md.getDisplayName();
+ LinkItem link =
AbstractActivityView.newLinkItem(title, null);
+ link.setTooltip(title);
+
link.setTitleVAlign(VerticalAlignment.TOP);
+ link.setAlign(Alignment.LEFT);
+ link.setClipValue(true);
+ link.setWrap(true);
+ link.setHeight(26);
+ link.setWidth("100%");
+ if
(!BrowserUtility.isBrowserPreIE9()) {
+ link.addClickHandler(new
ClickHandler() {
+ @Override
+ public void
onClick(ClickEvent event) {
+ window = new
ChartViewWindow(title);
+
+ graphView =
D3GraphListView.createSingleGraph(
+
resourceComposite.getResource(), md.getId(),
+ true);
+
+
window.addItem(graphView);
+ window.show();
+ }
+ });
+ } else {
+ link.disable();
+ }
- row.setItems(sparklineContainer,
link, value);
- row.setWidth100();
+ //Value
+ String convertedValue;
+ convertedValue =
AbstractActivityView
+
.convertLastValueForDisplay(lastValue, md);
+ StaticTextItem value =
AbstractActivityView
+
.newTextItem(convertedValue);
+
value.setVAlign(VerticalAlignment.TOP);
+ value.setAlign(Alignment.RIGHT);
+
+ row.setItems(sparklineContainer,
link, value);
+ row.setWidth100();
+
+ //if graph content returned
+ if
((!md.getName().trim().contains("Trait."))
+ && (lastValue != -1))
{
+ column.addMember(row);
+ someChartedData = true;
+ }
+ }
+ if (!someChartedData) {// when there
are results but no chartable entries.
+ DynamicForm row =
AbstractActivityView.createEmptyDisplayRow(
- //if graph content returned
- if
((!md.getName().trim().contains("Trait.")) && (lastValue != -1)) {
+
AbstractActivityView.RECENT_MEASUREMENTS_NONE);
column.addMember(row);
- someChartedData = true;
+ } else {
+ //insert see more link
+ DynamicForm row = new
DynamicForm();
+ String link = LinkManager
+
.getResourceMonitoringGraphsLink(resourceId);
+
AbstractActivityView.addSeeMoreLink(row, link, column);
}
- }
- if (!someChartedData) {// when there are
results but no chartable entries.
- DynamicForm row =
AbstractActivityView.createEmptyDisplayRow(
-
-
AbstractActivityView.RECENT_MEASUREMENTS_NONE);
- column.addMember(row);
+ //call out to 3rd party javascript
lib
+ new Timer() {
+ @Override
+ public void run() {
+
BrowserUtility.graphSparkLines();
+ }
+ }.schedule(200);
} else {
- //insert see more link
- DynamicForm row = new DynamicForm();
- String link = LinkManager
-
.getResourceMonitoringGraphsLink(resourceId);
-
AbstractActivityView.addSeeMoreLink(row, link, column);
+ DynamicForm row =
AbstractActivityView
+
.createEmptyDisplayRow(AbstractActivityView.RECENT_MEASUREMENTS_NONE);
+ column.addMember(row);
}
- //call out to 3rd party javascript lib
- new Timer(){
- @Override
- public void run() {
-
BrowserUtility.graphSparkLines();
- }
- }.schedule(200);
- } else {
- DynamicForm row = AbstractActivityView
-
.createEmptyDisplayRow(AbstractActivityView.RECENT_MEASUREMENTS_NONE);
- column.addMember(row);
+ setRefreshing(false);
}
- setRefreshing(false);
}
- };
-
- //make the asynchronous call for all the measurement
data
- if (end != -1 && start != -1) {
-
GWTServiceLookup.getMeasurementDataService().findDataForResource(resourceId,
- definitionArrayIds, start, end, 60,
callback);
- } else if (lastN != -1 && units != -1) {
-
GWTServiceLookup.getMeasurementDataService().findDataForResourceForLast(
- resourceId, definitionArrayIds, lastN, units,
60, callback);
- } else {
-
GWTServiceLookup.getMeasurementDataService().findDataForResourceForLast(
- resourceId, definitionArrayIds, 8,
MeasurementUtility.UNIT_HOURS, 60,
- callback);
- }
+
+ );
+
}
});
}