modules/enterprise/gui/coregui/src/main/java/com/google/gwt/user/rebind/rpc/TrackingProxyCreator.java | 44 ++ modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/Footer.java | 32 - modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/UserPermissionsManager.java | 127 ------- modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/UserSessionManager.java | 16 modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/admin/roles/RoleEditView.java | 29 + modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/admin/roles/RolesDataSource.java | 25 - modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/admin/roles/RolesView.java | 33 +- modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/admin/users/UserEditView.java | 39 +- modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/admin/users/UsersView.java | 39 +- modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertDataSource.java | 38 -- modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertPortletDataSource.java | 38 -- modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/gwt/GWTServiceLookup.java | 45 -- modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/ResourceGroupDetailView.java | 23 + modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/ResourceDetailView.java | 22 + modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/operation/RecentOperationsDataSource.java | 47 +- modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/operation/ScheduledOperationsDataSource.java | 45 +- modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/resource/ProblemResourcesDataSource.java | 44 +- modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/test/TestTopView.java | 12 modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/test/i18n/TestRemoteServiceStatisticsView.java | 89 +++++ modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/RPCDataSource.java | 11 modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/rpc/MonitoringRequestCallback.java | 104 ------ modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/rpc/RPCManager.java | 105 ------ modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/rpc/RPCTracker.java | 100 ++++++ modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/rpc/RemoteServiceStatistics.java | 162 ++++++++++ modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/rpc/TrackingRemoteServiceProxy.java | 110 ++++++ modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/rpc/TrackingRequestCallback.java | 89 +++++ modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/server/gwt/AbstractGWTServiceImpl.java | 22 - modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/user/rebind/rpc/TrackingServiceInterfaceProxyGenerator.java | 39 ++ modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/CoreGUI.gwt.xml | 6 29 files changed, 915 insertions(+), 620 deletions(-)
New commits: commit b46a3e405689a11e3bcdee5065fc1fd9b8b6a272 Author: Joseph Marques joseph@redhat.com Date: Sat Nov 27 03:48:09 2010 -0500
statistics view for all remote services executed since application startup
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/test/TestTopView.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/test/TestTopView.java index 522bc5d..92823f9 100644 --- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/test/TestTopView.java +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/test/TestTopView.java @@ -34,6 +34,7 @@ import org.rhq.enterprise.gui.coregui.client.inventory.resource.type.ResourceTyp import org.rhq.enterprise.gui.coregui.client.test.configuration.TestConfigurationView; import org.rhq.enterprise.gui.coregui.client.test.configuration.TestGroupConfigurationView; import org.rhq.enterprise.gui.coregui.client.test.i18n.TestPluralizationView; +import org.rhq.enterprise.gui.coregui.client.test.i18n.TestRemoteServiceStatisticsView;
/** * The Test top-level view. This view is "hidden", i.e. there are no links to it, so the user must go to the URL @@ -59,6 +60,7 @@ public class TestTopView extends AbstractSectionedLeftNavigationView { // view IDs for Misc section private static final ViewName MISC_SECTION_VIEW_ID = new ViewName("Misc"); private static final ViewName PAGE_PLURALIZATION_TEST = new ViewName("PluralizationTest"); + private static final ViewName PAGE_REMOTE_SERVICE_STATISTICS = new ViewName("Remote Service Statistics");
public TestTopView() { // This is a top level view, so our locator id can simply be our view id. @@ -127,6 +129,14 @@ public class TestTopView extends AbstractSectionedLeftNavigationView { } });
- return new NavigationSection(MISC_SECTION_VIEW_ID, pluralizationItem); + NavigationItem remoteServiceStatisticsItem = new NavigationItem(PAGE_REMOTE_SERVICE_STATISTICS, null, + new ViewFactory() { + public Canvas createView() { + return new TestRemoteServiceStatisticsView( + extendLocatorId(PAGE_REMOTE_SERVICE_STATISTICS.getName())); + } + }); + + return new NavigationSection(MISC_SECTION_VIEW_ID, pluralizationItem, remoteServiceStatisticsItem); } } diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/test/i18n/TestRemoteServiceStatisticsView.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/test/i18n/TestRemoteServiceStatisticsView.java new file mode 100644 index 0000000..cbc5bda --- /dev/null +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/test/i18n/TestRemoteServiceStatisticsView.java @@ -0,0 +1,89 @@ +/* + * RHQ Management Platform + * Copyright (C) 2005-2010 Red Hat, Inc. + * All rights reserved. + * + * 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.test.i18n; + +import java.util.List; + +import com.smartgwt.client.data.SortSpecifier; +import com.smartgwt.client.types.Alignment; +import com.smartgwt.client.types.SortDirection; +import com.smartgwt.client.widgets.grid.ListGridField; +import com.smartgwt.client.widgets.grid.ListGridRecord; + +import org.rhq.enterprise.gui.coregui.client.components.table.Table; +import org.rhq.enterprise.gui.coregui.client.util.rpc.RemoteServiceStatistics; +import org.rhq.enterprise.gui.coregui.client.util.rpc.RemoteServiceStatistics.Stat; + +/** + * A view that gives a display of statistics for all remote services executed since the application was loaded. + * + * @author Joseph Marques + */ +public class TestRemoteServiceStatisticsView extends Table { + + private static final SortSpecifier[] defaultSorts = new SortSpecifier[] { new SortSpecifier("average", + SortDirection.DESCENDING) }; + + public TestRemoteServiceStatisticsView(String locatorId) { + super(locatorId, "Remote Service Statistics", null, defaultSorts, null, false); + } + + @Override + protected void configureTable() { + ListGridField serviceName = new ListGridField("serviceName", "Service Name"); + ListGridField methodName = new ListGridField("methodName", "Method Name"); + ListGridField count = new ListGridField("count", "Count"); + count.setAlign(Alignment.CENTER); + ListGridField total = new ListGridField("total", "Total (ms)"); + total.setAlign(Alignment.RIGHT); + ListGridField average = new ListGridField("average", "Average (ms)"); + average.setAlign(Alignment.RIGHT); + ListGridField latest = new ListGridField("latest", "Latest (ms)"); + latest.setAlign(Alignment.RIGHT); + ListGridField slowest = new ListGridField("slowest", "Slowest (ms)"); + slowest.setAlign(Alignment.RIGHT); + ListGridField fastest = new ListGridField("fastest", "Fastest (ms)"); + fastest.setAlign(Alignment.RIGHT); + + getListGrid().setFields(serviceName, methodName, count, total, average, latest, slowest, fastest); + getListGrid().setRecords(transform(RemoteServiceStatistics.getAll())); + } + + private ListGridRecord[] transform(List<Stat> stats) { + ListGridRecord[] results = new ListGridRecord[stats.size()]; + for (int i = 0; i < stats.size(); i++) { + results[i] = transform(stats.get(i)); + } + return results; + } + + private ListGridRecord transform(Stat stat) { + ListGridRecord record = new ListGridRecord(); + record.setAttribute("serviceName", stat.getServiceName()); + record.setAttribute("methodName", stat.getMethodName()); + record.setAttribute("count", stat.getCount()); + record.setAttribute("total", stat.getTotal()); + record.setAttribute("average", stat.getTotal() / stat.getCount()); + record.setAttribute("latest", stat.getLatest()); + record.setAttribute("slowest", stat.getSlowest()); + record.setAttribute("fastest", stat.getFastest()); + return record; + } + +}
commit 2eebd5eb00a6a490cc8717afd040bed8750ac1c0 Author: Joseph Marques joseph@redhat.com Date: Sat Nov 27 03:45:43 2010 -0500
mechanism for client-side RPC lifecycle management
diff --git a/modules/enterprise/gui/coregui/src/main/java/com/google/gwt/user/rebind/rpc/TrackingProxyCreator.java b/modules/enterprise/gui/coregui/src/main/java/com/google/gwt/user/rebind/rpc/TrackingProxyCreator.java new file mode 100644 index 0000000..32ee120 --- /dev/null +++ b/modules/enterprise/gui/coregui/src/main/java/com/google/gwt/user/rebind/rpc/TrackingProxyCreator.java @@ -0,0 +1,44 @@ +/* + * RHQ Management Platform + * Copyright (C) 2010 Red Hat, Inc. + * All rights reserved. + * + * 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 com.google.gwt.user.rebind.rpc; + +import com.google.gwt.core.ext.typeinfo.JClassType; +import com.google.gwt.user.client.rpc.RemoteService; +import com.google.gwt.user.client.rpc.impl.RemoteServiceProxy; + +import org.rhq.enterprise.gui.coregui.client.util.rpc.TrackingRemoteServiceProxy; + +/** + * Creates a customized client-side proxy for a {@link RemoteService} interface. + * + * @see TrackingRemoteServiceProxy + * @author Joseph Marques + */ +public class TrackingProxyCreator extends ProxyCreator { + + public TrackingProxyCreator(JClassType type) { + super(type); + } + + @Override + protected Class<? extends RemoteServiceProxy> getProxySupertype() { + return TrackingRemoteServiceProxy.class; + } + +} diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/gwt/GWTServiceLookup.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/gwt/GWTServiceLookup.java index cd3cb71..d5cb3c0 100644 --- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/gwt/GWTServiceLookup.java +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/gwt/GWTServiceLookup.java @@ -19,16 +19,12 @@ package org.rhq.enterprise.gui.coregui.client.gwt;
import com.allen_sauer.gwt.log.client.Log; -import com.google.gwt.core.client.GWT; import com.google.gwt.http.client.RequestBuilder; -import com.google.gwt.http.client.RequestCallback; import com.google.gwt.user.client.rpc.RpcRequestBuilder; import com.google.gwt.user.client.rpc.ServiceDefTarget;
import org.rhq.enterprise.gui.coregui.client.CoreGUI; import org.rhq.enterprise.gui.coregui.client.UserSessionManager; -import org.rhq.enterprise.gui.coregui.client.util.rpc.MonitoringRequestCallback; -import org.rhq.enterprise.gui.coregui.client.util.rpc.RPCManager;
/** * This lookup service retrieves each RPC service and sets a @@ -193,51 +189,16 @@ public class GWTServiceLookup {
String sessionId = UserSessionManager.getSessionId(); if (sessionId != null) { - Log.debug("SessionRpcRequestBuilder is adding sessionId to request: " + sessionId); + Log.debug("SessionRpcRequestBuilder is adding sessionId(" + sessionId + ") to request(" + + serviceEntryPoint + ")"); rb.setHeader(UserSessionManager.SESSION_NAME, sessionId); } else { - Log.error("SessionRpcRequestBuilder built without a value for " + UserSessionManager.SESSION_NAME); + Log.error("SessionRpcRequestBuilder missing sessionId for request(" + serviceEntryPoint + ") "); }
return rb; }
- @Override - protected void doFinish(RequestBuilder rb) { - super.doFinish(rb); - - // TODO: alter callback handlers to capture timeout failure and retry (at least once) - // to add resilience to GWT service calls - - int callId = RPCManager.nextCallId(); - String callName = determineCallName(); - RequestCallback original = rb.getCallback(); - - MonitoringRequestCallback monitoringCallback = new MonitoringRequestCallback(callId, callName, original); - rb.setCallback(monitoringCallback); - - RPCManager.getInstance().register(monitoringCallback); - } - - private String determineCallName() { - if (!GWT.isScript()) { - // expensive name calculation only in dev-mode - StackTraceElement[] stack = new Exception().getStackTrace(); - - // Skip the first two stack elements to get to the proxy calling - for (int i = 2; i < stack.length; i++) { - StackTraceElement ste = stack[i]; - // e.g. "org.rhq.enterprise.gui.coregui.client.gwt.ResourceGWTService_Proxy.findResourcesByCriteria(ResourceGWTService_Proxy.java:36)" - if (ste.getClassName().startsWith("org.rhq.enterprise.gui.coregui.client.gwt")) { - return ste.getClassName().substring(ste.getClassName().lastIndexOf(".") + 1) + "." - + ste.getMethodName(); - } - } - return "unknown"; - } else { - return "production"; - } - } }
} diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/rpc/MonitoringRequestCallback.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/rpc/MonitoringRequestCallback.java deleted file mode 100644 index 51e6b40..0000000 --- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/rpc/MonitoringRequestCallback.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - * RHQ Management Platform - * Copyright (C) 2005-2010 Red Hat, Inc. - * All rights reserved. - * - * 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.util.rpc; - -import com.allen_sauer.gwt.log.client.Log; -import com.google.gwt.http.client.Request; -import com.google.gwt.http.client.RequestCallback; -import com.google.gwt.http.client.Response; -import com.google.gwt.user.client.Cookies; -import com.google.gwt.user.client.History; -import com.google.gwt.user.client.rpc.AsyncCallback; -import com.smartgwt.client.util.SC; - -import org.rhq.core.domain.auth.Subject; -import org.rhq.enterprise.gui.coregui.client.CoreGUI; -import org.rhq.enterprise.gui.coregui.client.Messages; -import org.rhq.enterprise.gui.coregui.client.UserSessionManager; - -/** - * @author Greg Hinkle - * @author Joseph Marques - */ -public class MonitoringRequestCallback implements RequestCallback { - - private static final Messages MSG = CoreGUI.getMessages(); - - private int id; - private String name; - private long start = System.currentTimeMillis(); - - private static final int STATUS_CODE_OK = 200; - - private RequestCallback callback; - - public MonitoringRequestCallback(int callId, String name, RequestCallback callback) { - this.name = name; - this.id = callId; - this.callback = callback; - } - - public void onError(Request request, Throwable exception) { - Log.trace("MonitoringRequestCallback(" + this + "): onError " + exception.getMessage()); - RPCManager.getInstance().failCall(this); - callback.onError(request, exception); - } - - public void onResponseReceived(Request request, Response response) { - Log.trace("MonitoringRequestCallback(" + this + "): " + response.getStatusCode() + "/" - + response.getStatusText()); - if (STATUS_CODE_OK == response.getStatusCode()) { - RPCManager.getInstance().succeedCall(this); - callback.onResponseReceived(request, response); - } else { - RPCManager.getInstance().failCall(this); - callback.onResponseReceived(request, response); - - // if we have a rich and coordinated client-side loggedIn state, do we need to check upon failure here? - UserSessionManager.checkLoginStatus(Cookies.getCookie("username"), null, new AsyncCallback<Subject>() { - @Override - public void onSuccess(Subject result) { - History.fireCurrentHistoryState(); - } - - @Override - public void onFailure(Throwable caught) { - SC.say(MSG.util_monitoringRequestCallback_error_checkServerStatusFailure()); - } - }); - } - } - - public int getId() { - return id; - } - - public String getName() { - return name; - } - - public long age() { - return System.currentTimeMillis() - start; - } - - public String toString() { - return "MonitoringRequestCallback{id=" + id + ", name=" + name + ", age=" + age() + "}"; - } - -} diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/rpc/RPCManager.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/rpc/RPCManager.java deleted file mode 100644 index b4799c3..0000000 --- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/rpc/RPCManager.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * RHQ Management Platform - * Copyright (C) 2005-2010 Red Hat, Inc. - * All rights reserved. - * - * 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.util.rpc; - -import java.util.HashSet; -import java.util.Set; - -import com.allen_sauer.gwt.log.client.Log; -import com.smartgwt.client.widgets.Img; - -import org.rhq.enterprise.gui.coregui.client.CoreGUI; -import org.rhq.enterprise.gui.coregui.client.Messages; - -/** - * @author Greg Hinkle - * @author Joseph Marques - */ -public class RPCManager { - - private static final Messages MSG = CoreGUI.getMessages(); - - private static final RPCManager INSTANCE = new RPCManager(); - private static int nextCallId = 0; - - private Set<MonitoringRequestCallback> inProgress = new HashSet<MonitoringRequestCallback>(); - - private Img activityIndicator; - - private RPCManager() { - activityIndicator = new Img("/coregui/images/ajax-loader.gif", 16, 16); - activityIndicator.setZIndex(10000); - activityIndicator.setLeft(10); - activityIndicator.setTop(40); - activityIndicator.draw(); - } - - public static int nextCallId() { - return nextCallId++; - } - - public static RPCManager getInstance() { - return INSTANCE; - } - - public void register(MonitoringRequestCallback callback) { - Log.debug("RPC register: " + callback); - - inProgress.add(callback); - refresh(); - } - - public void failCall(MonitoringRequestCallback callback) { - Log.trace("RPC failure: " + callback); - - inProgress.remove(callback); - refresh(); - } - - public void succeedCall(MonitoringRequestCallback callback) { - Log.trace("RPC success: " + callback); - - inProgress.remove(callback); - refresh(); - } - - public int getQueueDepth() { - return inProgress.size(); - } - - public void refresh() { - Log.trace("RPC queue depth is " + getQueueDepth()); - if (getQueueDepth() > 0) { - activityIndicator.show(); - - int numberOfActiveRequests = inProgress.size(); - String message = MSG.util_rpcManager_activeRequests(String.valueOf(numberOfActiveRequests)); - StringBuilder buf = new StringBuilder().append("<b>").append(message).append("</b>"); - for (MonitoringRequestCallback callback : inProgress) { - buf.append("<br/>"); - buf.append(callback); - } - - activityIndicator.setTooltip(buf.toString()); - } else { - activityIndicator.hide(); - } - } - -} diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/rpc/RPCTracker.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/rpc/RPCTracker.java new file mode 100644 index 0000000..e1eb7e2 --- /dev/null +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/rpc/RPCTracker.java @@ -0,0 +1,100 @@ +/* + * RHQ Management Platform + * Copyright (C) 2005-2010 Red Hat, Inc. + * All rights reserved. + * + * 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.util.rpc; + +import java.util.HashSet; +import java.util.Set; + +import com.allen_sauer.gwt.log.client.Log; +import com.smartgwt.client.widgets.Img; + +import org.rhq.enterprise.gui.coregui.client.CoreGUI; +import org.rhq.enterprise.gui.coregui.client.Messages; + +/** + * @author Greg Hinkle + * @author Joseph Marques + */ +public class RPCTracker { + + private static final Messages MSG = CoreGUI.getMessages(); + + private static final RPCTracker INSTANCE = new RPCTracker(); + + private Set<TrackingRequestCallback> inProgress = new HashSet<TrackingRequestCallback>(); + + private Img activityIndicator; + + private RPCTracker() { + activityIndicator = new Img("/coregui/images/ajax-loader.gif", 16, 16); + activityIndicator.setZIndex(10000); + activityIndicator.setLeft(10); + activityIndicator.setTop(40); + activityIndicator.draw(); + } + + public static RPCTracker getInstance() { + return INSTANCE; + } + + public void register(TrackingRequestCallback callback) { + Log.debug("RPCTracker register: " + callback); + + inProgress.add(callback); + refresh(); + } + + public void failCall(TrackingRequestCallback callback) { + Log.trace("RPCTracker failure: " + callback); + + inProgress.remove(callback); + refresh(); + } + + public void succeedCall(TrackingRequestCallback callback) { + Log.trace("RPCTracker success: " + callback); + + inProgress.remove(callback); + refresh(); + } + + public int getQueueDepth() { + return inProgress.size(); + } + + public void refresh() { + Log.trace("RPCTracker queue depth is " + getQueueDepth()); + if (getQueueDepth() > 0) { + activityIndicator.show(); + + int numberOfActiveRequests = inProgress.size(); + String message = MSG.util_rpcManager_activeRequests(String.valueOf(numberOfActiveRequests)); + StringBuilder buf = new StringBuilder().append("<b>").append(message).append("</b>"); + for (TrackingRequestCallback callback : inProgress) { + buf.append("<br/>"); + buf.append(callback); + } + + activityIndicator.setTooltip(buf.toString()); + } else { + activityIndicator.hide(); + } + } + +} diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/rpc/RemoteServiceStatistics.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/rpc/RemoteServiceStatistics.java new file mode 100644 index 0000000..eaea847 --- /dev/null +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/rpc/RemoteServiceStatistics.java @@ -0,0 +1,162 @@ +/* + * RHQ Management Platform + * Copyright (C) 2010 Red Hat, Inc. + * All rights reserved. + * + * 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.util.rpc; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * @author Joseph Marques + */ +public class RemoteServiceStatistics { + + public static class Stat { + private String serviceName; + private String methodName; + private int count; + private long total; + private long latest; + private long slowest; + private long fastest; + + protected Stat(String remoteService, long millis) { + // remoteService format "{ServiceName}_Proxy.{MethodName}" + this.serviceName = remoteService.substring(0, remoteService.indexOf("_Proxy")); + this.methodName = remoteService.substring(remoteService.indexOf('.') + 1); + count = 1; + total = latest = slowest = fastest = millis; + } + + private void record(long millis) { + count++; + total += millis; + latest = millis; + if (millis > slowest) { + slowest = millis; + } else if (millis < fastest) { + fastest = millis; + } + } + + public String getServiceName() { + return serviceName; + } + + public String getMethodName() { + return methodName; + } + + public int getCount() { + return count; + } + + public long getTotal() { + return total; + } + + public long getLatest() { + return latest; + } + + public long getSlowest() { + return slowest; + } + + public long getFastest() { + return fastest; + } + + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("serviceName=").append(serviceName).append(','); + builder.append("methodeName=").append(methodName).append(": "); + if (count < 1) { + builder.append("empty"); + } else { + builder.append("count=").append(count).append(','); + builder.append("total=").append(total).append(','); + builder.append("avg=").append(total / count).append(','); + builder.append("latest=").append(latest).append(','); + builder.append("slowest=").append(slowest).append(','); + builder.append("fastest=").append(fastest); + } + return builder.toString(); + } + + } + + private static Map<String, Stat> statistics = new HashMap<String, Stat>(); + + private RemoteServiceStatistics() { + // static access only + } + + public static void record(String remoteService, long millis) { + Stat stat = statistics.get(remoteService); + if (stat == null) { + stat = new Stat(remoteService, millis); + statistics.put(remoteService, stat); + } else { + stat.record(millis); + } + } + + public static String recordAndPrint(String remoteService, long millis) { + record(remoteService, millis); + return print(remoteService); + } + + public static String print(String remoteService) { + Stat stat = statistics.get(remoteService); + if (stat == null) { + stat = new Stat(remoteService, 0); + } + return "RemoteServiceStatistics: " + remoteService + ": " + stat.toString(); + } + + public static List<String> printAll() { + List<String> stats = new ArrayList<String>(); + + for (String remoteService : statistics.keySet()) { + stats.add(print(remoteService)); + } + + return stats; + } + + public static Stat get(String remoteService) { + Stat stat = statistics.get(remoteService); + if (stat == null) { + stat = new Stat(remoteService, 0); + } + return stat; + } + + public static List<Stat> getAll() { + List<Stat> stats = new ArrayList<Stat>(); + + for (String remoteService : statistics.keySet()) { + stats.add(statistics.get(remoteService)); + } + + return stats; + } +} diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/rpc/TrackingRemoteServiceProxy.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/rpc/TrackingRemoteServiceProxy.java new file mode 100644 index 0000000..1c2bbe0 --- /dev/null +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/rpc/TrackingRemoteServiceProxy.java @@ -0,0 +1,110 @@ +/* + * RHQ Management Platform + * Copyright (C) 2010 Red Hat, Inc. + * All rights reserved. + * + * 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.util.rpc; + +import java.util.HashSet; +import java.util.Set; + +import com.allen_sauer.gwt.log.client.Log; +import com.google.gwt.http.client.Request; +import com.google.gwt.http.client.RequestBuilder; +import com.google.gwt.http.client.RequestCallback; +import com.google.gwt.user.client.rpc.AsyncCallback; +import com.google.gwt.user.client.rpc.impl.RemoteServiceProxy; +import com.google.gwt.user.client.rpc.impl.Serializer; +import com.google.gwt.user.client.rpc.impl.RequestCallbackAdapter.ResponseReader; + +import org.rhq.enterprise.gui.coregui.client.UserSessionManager; + +/** + * A custom {@link RemoteServiceProxy} that injects additional management and monitoring functionality into the + * RPC lifecycle. Below are the list of extensions: + * + * <ul> + * <li>Conditionally sends requests based off of the client-side loggedIn state. Once the user's client-side session + * has expired, communication back to the server is halted by silently dropping requests. Obviously, for this to + * work, the methods that are used prior to being authenticated can not be wrapped with this proxy.</li> + * <li>Wrap the existing {@link RequestCallback} in a {@link TrackingRequestCallback}, which will provide 1) a + * fall-back mechanism for exceptions/errors that occur while the user is logged out, and 2) a notification + * mechanism to send the {@link RPCTracker} events which will tell the activityIndicator when to spin.</li> + * <li>Put the user's sessionId into the header of the request.</li> + * + * @author Joseph Marques + */ +public class TrackingRemoteServiceProxy extends RemoteServiceProxy { + + private static final Set<String> bypassMethods = new HashSet<String>(); + static { + bypassMethods.add("SubjectGWTService_Proxy.findSubjectsByCriteria"); + } + + public TrackingRemoteServiceProxy(String moduleBaseURL, String remoteServiceRelativePath, + String serializationPolicyName, Serializer serializer) { + super(moduleBaseURL, remoteServiceRelativePath, serializationPolicyName, serializer); + } + + /* + * This method is currently not called by the RPC framework. When it is, we can remove the sessionId + * logic from the GWTServiceLookup class. + * + * For background information, please see http://code.google.com/p/google-web-toolkit/issues/detail?id=5668 + */ + @Override + protected <T> RequestBuilder doPrepareRequestBuilder(ResponseReader responseReader, String methodName, + int invocationCount, String requestData, AsyncCallback<T> callback) { + + RequestBuilder rb = super.doPrepareRequestBuilder(responseReader, methodName, invocationCount, requestData, + callback); + + String sessionId = UserSessionManager.getSessionId(); + if (sessionId != null) { + Log.debug("SessionRpcRequestBuilder is adding sessionId to request for (" + methodName + ")"); + rb.setHeader(UserSessionManager.SESSION_NAME, sessionId); + } else { + Log.error("SessionRpcRequestBuilder missing sessionId for request (" + methodName + ")"); + } + + return rb; + } + + // TODO: add handled to capture timeout failure and retry (at least once) to add resilience to GWT service calls? + @Override + protected <T> RequestCallback doCreateRequestCallback(ResponseReader responseReader, String methodName, + int invocationCount, AsyncCallback<T> callback) { + + RequestCallback original = super.doCreateRequestCallback(responseReader, methodName, invocationCount, callback); + TrackingRequestCallback monitoringCallback = new TrackingRequestCallback(invocationCount, methodName, original); + + RPCTracker.getInstance().register(monitoringCallback); + + return monitoringCallback; + } + + @Override + protected <T> Request doInvoke(ResponseReader responseReader, String methodName, int invocationCount, + String requestData, AsyncCallback<T> callback) { + + Log.debug("RPC method invocation: " + methodName); + if (bypassMethods.contains(methodName) || !UserSessionManager.isLoggedOut()) { + return super.doInvoke(responseReader, methodName, invocationCount, requestData, callback); + } + + return null; + } +} diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/rpc/TrackingRequestCallback.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/rpc/TrackingRequestCallback.java new file mode 100644 index 0000000..38effc4 --- /dev/null +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/rpc/TrackingRequestCallback.java @@ -0,0 +1,89 @@ +/* + * RHQ Management Platform + * Copyright (C) 2005-2010 Red Hat, Inc. + * All rights reserved. + * + * 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.util.rpc; + +import com.allen_sauer.gwt.log.client.Log; +import com.google.gwt.http.client.Request; +import com.google.gwt.http.client.RequestCallback; +import com.google.gwt.http.client.Response; + +import org.rhq.enterprise.gui.coregui.client.UserSessionManager; + +/** + * @author Greg Hinkle + * @author Joseph Marques + */ +public class TrackingRequestCallback implements RequestCallback { + + private int id; + private String name; + private long start = System.currentTimeMillis(); + + private static final int STATUS_CODE_OK = 200; + + private RequestCallback callback; + + public TrackingRequestCallback(int callId, String name, RequestCallback callback) { + this.name = name; + this.id = callId; + this.callback = callback; + } + + public void onError(Request request, Throwable exception) { + Log.trace(toString() + ": onError " + exception.getMessage()); + + RemoteServiceStatistics.record(getName(), getAge()); + RPCTracker.getInstance().failCall(this); + if (UserSessionManager.isLoggedIn()) { // only handle failures if user still logged in + callback.onError(request, exception); + } + } + + public void onResponseReceived(Request request, Response response) { + Log.trace(toString() + ": " + response.getStatusCode() + "/" + response.getStatusText()); + + RemoteServiceStatistics.record(getName(), getAge()); + if (STATUS_CODE_OK == response.getStatusCode()) { + RPCTracker.getInstance().succeedCall(this); + callback.onResponseReceived(request, response); + } else { + RPCTracker.getInstance().failCall(this); + if (UserSessionManager.isLoggedIn()) { // only handle failures if user still logged in + callback.onResponseReceived(request, response); + } + } + } + + public int getId() { + return id; + } + + public String getName() { + return name; + } + + public long getAge() { + return System.currentTimeMillis() - start; + } + + public String toString() { + return "TracknigRequestCallback[id=" + id + ", name=" + name + ", age=" + getAge() + "]"; + } + +} diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/server/gwt/AbstractGWTServiceImpl.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/server/gwt/AbstractGWTServiceImpl.java index 364140f..569cef0 100644 --- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/server/gwt/AbstractGWTServiceImpl.java +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/server/gwt/AbstractGWTServiceImpl.java @@ -53,6 +53,8 @@ public abstract class AbstractGWTServiceImpl extends RemoteServiceServlet { if (Log.isTraceEnabled()) { printHeaders(req); } + + boolean continueProcessing = true; String sid = req.getHeader(UserSessionManager.SESSION_NAME); if (sid != null) { SubjectManagerLocal subjectManager = LookupUtil.getSubjectManager(); @@ -60,18 +62,22 @@ public abstract class AbstractGWTServiceImpl extends RemoteServiceServlet { Subject subject = subjectManager.getSubjectBySessionId(Integer.parseInt(sid)); sessionSubject.set(subject); } catch (Exception e) { - Log.error("Failed to validate request: sessionId was '" + sid + "', requestURL=" + req.getRequestURL()); + Log.debug("Failed to validate request: sessionId was '" + sid + "', requestURL=" + req.getRequestURL()); + continueProcessing = false; } } else { - Log.error("Failed to validate request: sessionId missing, requestURL=" + req.getRequestURL()); + Log.debug("Failed to validate request: sessionId missing, requestURL=" + req.getRequestURL()); + continueProcessing = false; }
- // TODO: only execute this if the session lookup was successful, otherwise fail in some deterministic fashion - // alter callback handlers to capture expected failure and retry (at least once) - // to add resilience to gwt service calls - long id = HibernatePerformanceMonitor.get().start(); - super.service(req, resp); - HibernatePerformanceMonitor.get().stop(id, "GWT Service Request"); + if (continueProcessing) { + // TODO: only execute this if the session lookup was successful, otherwise fail in some deterministic fashion + // alter callback handlers to capture expected failure and retry (at least once) + // to add resilience to gwt service calls + long id = HibernatePerformanceMonitor.get().start(); + super.service(req, resp); + HibernatePerformanceMonitor.get().stop(id, "GWT Service Request"); + } }
@SuppressWarnings("unchecked") diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/user/rebind/rpc/TrackingServiceInterfaceProxyGenerator.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/user/rebind/rpc/TrackingServiceInterfaceProxyGenerator.java new file mode 100644 index 0000000..9b1dda1 --- /dev/null +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/user/rebind/rpc/TrackingServiceInterfaceProxyGenerator.java @@ -0,0 +1,39 @@ +/* + * RHQ Management Platform + * Copyright (C) 2010 Red Hat, Inc. + * All rights reserved. + * + * 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.user.rebind.rpc; + +import com.google.gwt.core.ext.typeinfo.JClassType; +import com.google.gwt.user.rebind.rpc.ProxyCreator; +import com.google.gwt.user.rebind.rpc.ServiceInterfaceProxyGenerator; +import com.google.gwt.user.rebind.rpc.TrackingProxyCreator; + +/** + * A generator used to create remote service proxy wrappers that will inject additional management and monitoring + * hooks into the RPC lifecycle. + * + * @author Joseph Marques + */ +public class TrackingServiceInterfaceProxyGenerator extends ServiceInterfaceProxyGenerator { + + @Override + protected ProxyCreator createProxyCreator(JClassType remoteService) { + return new TrackingProxyCreator(remoteService); + } + +} diff --git a/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/CoreGUI.gwt.xml b/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/CoreGUI.gwt.xml index 3ef0391..c9d5224 100644 --- a/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/CoreGUI.gwt.xml +++ b/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/CoreGUI.gwt.xml @@ -57,6 +57,12 @@ <when-type-is class="org.rhq.enterprise.gui.coregui.client.components.upload.DynamicCallbackFormImpl"/> <when-property-is name="user.agent" value="ie6"/> </replace-with> + + + <generate-with class="org.rhq.enterprise.gui.coregui.user.rebind.rpc.TrackingServiceInterfaceProxyGenerator"> + <when-type-assignable class="com.google.gwt.user.client.rpc.RemoteService"/> + </generate-with> +
<!-- Limit compilation to your preferred browser(s) to speed up compile time.
commit 80285c831c0c923b339d5670f0930e95d63c0bf0 Author: Joseph Marques joseph@redhat.com Date: Sat Nov 27 03:04:47 2010 -0500
remove userStillLoggedIn method from datasource
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertDataSource.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertDataSource.java index 0427c31..b7fdeb5 100644 --- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertDataSource.java +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertDataSource.java @@ -177,31 +177,23 @@ public class AlertDataSource extends RPCDataSource<Alert> {
AlertCriteria criteria = getCriteria(request);
- //check for still logged in before submitting server side request - if (userStillLoggedIn()) { - this.alertService.findAlertsByCriteria(criteria, new AsyncCallback<PageList<Alert>>() { - - public void onFailure(Throwable caught) { - CoreGUI.getErrorHandler().handleError(MSG.view_alerts_loadFailed(), caught); - response.setStatus(RPCResponse.STATUS_FAILURE); - processResponse(request.getRequestId(), response); - } + this.alertService.findAlertsByCriteria(criteria, new AsyncCallback<PageList<Alert>>() {
- public void onSuccess(PageList<Alert> result) { - long fetchTime = System.currentTimeMillis() - start; - Log.info(result.size() + " alerts fetched in: " + fetchTime + "ms"); - response.setData(buildRecords(result)); - // For paging to work, we have to specify size of full result set. - response.setTotalRows(result.getTotalSize()); - processResponse(request.getRequestId(), response); - } - }); - } else {//dump request - response.setTotalRows(0); - processResponse(request.getRequestId(), response); - Log.debug("user not logged in. Not fetching any alerts now."); - } + public void onFailure(Throwable caught) { + CoreGUI.getErrorHandler().handleError(MSG.view_alerts_loadFailed(), caught); + response.setStatus(RPCResponse.STATUS_FAILURE); + processResponse(request.getRequestId(), response); + }
+ public void onSuccess(PageList<Alert> result) { + long fetchTime = System.currentTimeMillis() - start; + Log.info(result.size() + " alerts fetched in: " + fetchTime + "ms"); + response.setData(buildRecords(result)); + // For paging to work, we have to specify size of full result set. + response.setTotalRows(result.getTotalSize()); + processResponse(request.getRequestId(), response); + } + }); }
protected AlertCriteria getCriteria(DSRequest request) { diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertPortletDataSource.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertPortletDataSource.java index 64306ca..721b559 100644 --- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertPortletDataSource.java +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertPortletDataSource.java @@ -87,30 +87,22 @@ public class AlertPortletDataSource extends AlertDataSource { criteria.addFilterPriorities(AlertPriority.getByLegacyIndex(getAlertPriorityIndex())); }
- //check for still logged in before submitting server side request - if (userStillLoggedIn()) { - getAlertService().findAlertsByCriteria(criteria, new AsyncCallback<PageList<Alert>>() { - - public void onFailure(Throwable caught) { - CoreGUI.getErrorHandler().handleError(MSG.view_alerts_loadFailed(), caught); - response.setStatus(RPCResponse.STATUS_FAILURE); - processResponse(request.getRequestId(), response); - } + getAlertService().findAlertsByCriteria(criteria, new AsyncCallback<PageList<Alert>>() {
- public void onSuccess(PageList<Alert> result) { - long fetchTime = System.currentTimeMillis() - start; - Log.info(result.size() + " alerts fetched in: " + fetchTime + "ms"); - response.setData(buildRecords(result)); - response.setTotalRows(result.size()); - processResponse(request.getRequestId(), response); - } - }); - } else {//dump request - response.setTotalRows(0); - processResponse(request.getRequestId(), response); - //TODO: spinder 10/13/10: not sure if we should log anything here. Could be noisy in log with not a lot of gain. - Log.debug("user not logged in. Not fetching any alerts now."); - } + public void onFailure(Throwable caught) { + CoreGUI.getErrorHandler().handleError(MSG.view_alerts_loadFailed(), caught); + response.setStatus(RPCResponse.STATUS_FAILURE); + processResponse(request.getRequestId(), response); + } + + public void onSuccess(PageList<Alert> result) { + long fetchTime = System.currentTimeMillis() - start; + Log.info(result.size() + " alerts fetched in: " + fetchTime + "ms"); + response.setData(buildRecords(result)); + response.setTotalRows(result.size()); + processResponse(request.getRequestId(), response); + } + }); }
public int getAlertRangeCompleted() { diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/operation/RecentOperationsDataSource.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/operation/RecentOperationsDataSource.java index 8705262..1bab7a8 100644 --- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/operation/RecentOperationsDataSource.java +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/operation/RecentOperationsDataSource.java @@ -129,36 +129,29 @@ public class RecentOperationsDataSource extends } }
- if (userStillLoggedIn()) {//check session validity - GWTServiceLookup.getOperationService().findRecentCompletedOperations(pageSize, - new AsyncCallback<List<DisambiguationReport<ResourceOperationLastCompletedComposite>>>() { + GWTServiceLookup.getOperationService().findRecentCompletedOperations(pageSize, + new AsyncCallback<List<DisambiguationReport<ResourceOperationLastCompletedComposite>>>() {
- public void onFailure(Throwable throwable) { - CoreGUI.getErrorHandler().handleError(MSG.dataSource_recentOperations_error_fetchFailure(), - throwable); - } + public void onFailure(Throwable throwable) { + CoreGUI.getErrorHandler().handleError(MSG.dataSource_recentOperations_error_fetchFailure(), + throwable); + }
- public void onSuccess( - List<DisambiguationReport<ResourceOperationLastCompletedComposite>> recentOperationsList) { - - //translate DisambiguationReport into dataset entries - response.setData(buildList(recentOperationsList)); - //entry count - if (null != recentOperationsList) { - response.setTotalRows(recentOperationsList.size()); - } else { - response.setTotalRows(0); - } - //pass off for processing - processResponse(request.getRequestId(), response); + public void onSuccess( + List<DisambiguationReport<ResourceOperationLastCompletedComposite>> recentOperationsList) { + + //translate DisambiguationReport into dataset entries + response.setData(buildList(recentOperationsList)); + //entry count + if (null != recentOperationsList) { + response.setTotalRows(recentOperationsList.size()); + } else { + response.setTotalRows(0); } - }); - } else { - Log.debug("user not logged in. Not fetching recently completed operations."); - //answer datasource - response.setTotalRows(0); - processResponse(request.getRequestId(), response); - } + //pass off for processing + processResponse(request.getRequestId(), response); + } + }); }
/** Translates the DisambiguationReport of ResourceOperationLastCompletedComposites into specific diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/operation/ScheduledOperationsDataSource.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/operation/ScheduledOperationsDataSource.java index c88b58e..4bd84b0 100644 --- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/operation/ScheduledOperationsDataSource.java +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/operation/ScheduledOperationsDataSource.java @@ -123,35 +123,28 @@ public class ScheduledOperationsDataSource extends } }
- if (userStillLoggedIn()) { - GWTServiceLookup.getOperationService().findScheduledOperations(pageSize, - new AsyncCallback<List<DisambiguationReport<ResourceOperationScheduleComposite>>>() { + GWTServiceLookup.getOperationService().findScheduledOperations(pageSize, + new AsyncCallback<List<DisambiguationReport<ResourceOperationScheduleComposite>>>() {
- public void onFailure(Throwable throwable) { - CoreGUI.getErrorHandler().handleError(MSG.dataSource_scheduledOperations_error_fetchFailure(), - throwable); - } + public void onFailure(Throwable throwable) { + CoreGUI.getErrorHandler().handleError(MSG.dataSource_scheduledOperations_error_fetchFailure(), + throwable); + }
- public void onSuccess( - List<DisambiguationReport<ResourceOperationScheduleComposite>> scheduledOpsList) { - - //translate DisambiguationReport into dataset entries - response.setData(buildList(scheduledOpsList)); - //entry count - if (null != scheduledOpsList) { - response.setTotalRows(scheduledOpsList.size()); - } else { - response.setTotalRows(0); - } - //pass off for processing - processResponse(request.getRequestId(), response); + public void onSuccess(List<DisambiguationReport<ResourceOperationScheduleComposite>> scheduledOpsList) { + + //translate DisambiguationReport into dataset entries + response.setData(buildList(scheduledOpsList)); + //entry count + if (null != scheduledOpsList) { + response.setTotalRows(scheduledOpsList.size()); + } else { + response.setTotalRows(0); } - }); - } else { - Log.debug("user not logged in. Not fetching scheduled operations."); - response.setTotalRows(0); - processResponse(request.getRequestId(), response); - } + //pass off for processing + processResponse(request.getRequestId(), response); + } + }); }
/** Translates the DisambiguationReport of ProblemResourceComposites into specific diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/resource/ProblemResourcesDataSource.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/resource/ProblemResourcesDataSource.java index 7e65e88..4763217 100644 --- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/resource/ProblemResourcesDataSource.java +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/resource/ProblemResourcesDataSource.java @@ -119,34 +119,28 @@ public class ProblemResourcesDataSource extends RPCDataSource<DisambiguationRepo } }
- if (userStillLoggedIn()) { - GWTServiceLookup.getResourceService().findProblemResources(ctime, maxItems, - new AsyncCallback<List<DisambiguationReport<ProblemResourceComposite>>>() { + GWTServiceLookup.getResourceService().findProblemResources(ctime, maxItems, + new AsyncCallback<List<DisambiguationReport<ProblemResourceComposite>>>() {
- public void onFailure(Throwable throwable) { - CoreGUI.getErrorHandler().handleError(MSG.dataSource_problemResources_error_fetchFailure(), - throwable); - } + public void onFailure(Throwable throwable) { + CoreGUI.getErrorHandler().handleError(MSG.dataSource_problemResources_error_fetchFailure(), + throwable); + } + + public void onSuccess(List<DisambiguationReport<ProblemResourceComposite>> problemResourcesList) {
- public void onSuccess(List<DisambiguationReport<ProblemResourceComposite>> problemResourcesList) { - - //translate DisambiguationReport into dataset entries - response.setData(buildList(problemResourcesList)); - //entry count - if (null != problemResourcesList) { - response.setTotalRows(problemResourcesList.size()); - } else { - response.setTotalRows(0); - } - //pass off for processing - processResponse(request.getRequestId(), response); + //translate DisambiguationReport into dataset entries + response.setData(buildList(problemResourcesList)); + //entry count + if (null != problemResourcesList) { + response.setTotalRows(problemResourcesList.size()); + } else { + response.setTotalRows(0); } - }); - } else { - Log.debug("user not logged in. Not fetching resources with alerts/unavailability."); - response.setTotalRows(0); - processResponse(request.getRequestId(), response); - } + //pass off for processing + processResponse(request.getRequestId(), response); + } + }); }
/** Translates the DisambiguationReport of ProblemResourceComposites into specific diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/RPCDataSource.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/RPCDataSource.java index 7b5000d..93d53b3 100644 --- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/RPCDataSource.java +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/RPCDataSource.java @@ -50,7 +50,6 @@ import org.rhq.core.domain.util.PageList; import org.rhq.core.domain.util.PageOrdering; import org.rhq.enterprise.gui.coregui.client.CoreGUI; import org.rhq.enterprise.gui.coregui.client.Messages; -import org.rhq.enterprise.gui.coregui.client.UserSessionManager; import org.rhq.enterprise.gui.coregui.client.util.effects.ColoringUtility; import org.rhq.enterprise.gui.coregui.client.util.message.Message; import org.rhq.enterprise.gui.coregui.client.util.selenium.SeleniumUtility; @@ -507,17 +506,9 @@ public abstract class RPCDataSource<T> extends DataSource { textField.setRequired(required); LinkedHashMap<String, String> valueMap = new LinkedHashMap<String, String>(); valueMap.put(Boolean.TRUE.toString(), MSG.common_val_yes_lower()); - valueMap.put(Boolean.FALSE.toString(), MSG.common_val_no_lower()); + valueMap.put(Boolean.FALSE.toString(), MSG.common_val_no_lower()); textField.setValueMap(valueMap); return textField; }
- /** Quick method to determine if current user is still logged in. - * - * @return boolean indication of logged in status. - */ - protected boolean userStillLoggedIn() { - return UserSessionManager.isLoggedIn(); - } - }
commit de4814470ee0eb7be9814a08bcc36501dfdbc37d Author: Joseph Marques joseph@redhat.com Date: Sat Nov 27 03:01:54 2010 -0500
remove UserPermissionsManager, this isn't data we should be caching
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/UserPermissionsManager.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/UserPermissionsManager.java deleted file mode 100644 index 9554c5f..0000000 --- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/UserPermissionsManager.java +++ /dev/null @@ -1,127 +0,0 @@ -/* - * 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; - -import java.util.EnumSet; -import java.util.HashSet; -import java.util.Set; - -import com.allen_sauer.gwt.log.client.Log; -import com.google.gwt.user.client.Timer; -import com.google.gwt.user.client.rpc.AsyncCallback; - -import org.rhq.core.domain.authz.Permission; -import org.rhq.enterprise.gui.coregui.client.gwt.AuthorizationGWTServiceAsync; -import org.rhq.enterprise.gui.coregui.client.gwt.GWTServiceLookup; -import org.rhq.enterprise.gui.coregui.client.util.message.Message; -import org.rhq.enterprise.gui.coregui.client.util.message.MessageCenter; - -/** - * A singleton that is in charge of fetching and caching the current user's global permissions and their permissions for - * the currently selected Resource or group. The permissions are reloaded from the Server once per minute to ensure the - * permissions used by the GUI for button enablement etc. do not get too stale. - * - * @author Ian Springer - */ -public class UserPermissionsManager { - private static final Messages MSG = CoreGUI.getMessages(); - - private static final UserPermissionsManager INSTANCE = new UserPermissionsManager(); - private static final AuthorizationGWTServiceAsync AUTHORIZATION_SERVICE = GWTServiceLookup - .getAuthorizationService(); - private static final MessageCenter MESSAGE_CENTER = CoreGUI.getMessageCenter(); - private static final int REFRESH_INTERVAL = 60 * 1000; // 1 minute - - /** This is a reference to the last set of global perms returned to a caller. */ - private Set<Permission> globalPermissions = new HashSet<Permission>(Permission.GLOBAL_ALL.size()); - private boolean globalCacheDirty = true; - private PermissionsLoadedListener globalPermissionsLoadedListener; - - public static UserPermissionsManager getInstance() { - return INSTANCE; - } - - public void loadGlobalPermissions(PermissionsLoadedListener permissionsLoadedListener) { - if (this.globalCacheDirty) { - // Permissions are not cached. Kick off an async load and let it notify the caller when the load completes. - this.globalPermissionsLoadedListener = permissionsLoadedListener; - loadGlobalPermissions(); - } else { - // Permissions are cached - shoot em back to the caller. - permissionsLoadedListener.onPermissionsLoaded(this.globalPermissions); - } - } - - public Set<Permission> getGlobalPermissions() { - return this.globalPermissions; - } - - /** - * Clear all cached permissions. - */ - public void clearCache() { - // Clear global cache. - this.globalCacheDirty = true; - this.globalPermissions.clear(); - } - - private UserPermissionsManager() { - Timer timer = new Timer() { - public void run() { - Log.debug("Refreshing cached user permissions..."); - loadGlobalPermissions(); - } - }; - - // Cache is automatically refreshed once per minute. - timer.scheduleRepeating(REFRESH_INTERVAL); - } - - private void loadGlobalPermissions() { - AUTHORIZATION_SERVICE.getExplicitGlobalPermissions(new AsyncCallback<Set<Permission>>() { - public void onFailure(Throwable throwable) { - MESSAGE_CENTER.notify(new Message(MSG.util_userPerm_loadFailGlobal(), throwable, - Message.Severity.Error, EnumSet.of(Message.Option.BackgroundJobResult))); - UserPermissionsManager.this.globalPermissions.clear(); - UserPermissionsManager.this.globalCacheDirty = true; - notifyGlobalPermissionsLoadedListener(); - } - - public void onSuccess(Set<Permission> permissions) { - // Always update the existing Set, so callers won't end up with stale references. - setTo(UserPermissionsManager.this.globalPermissions, permissions); - UserPermissionsManager.this.globalCacheDirty = false; - notifyGlobalPermissionsLoadedListener(); - } - }); - } - - private void notifyGlobalPermissionsLoadedListener() { - if (this.globalPermissionsLoadedListener != null) { - this.globalPermissionsLoadedListener.onPermissionsLoaded(this.globalPermissions); - this.globalPermissionsLoadedListener = null; - } - } - - private static void setTo(Set<Permission> permissions1, Set<Permission> permissions2) { - permissions1.clear(); - permissions1.addAll(permissions2); - } -} diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/UserSessionManager.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/UserSessionManager.java index 179ecbe..661f5b0 100644 --- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/UserSessionManager.java +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/UserSessionManager.java @@ -22,8 +22,6 @@ */ package org.rhq.enterprise.gui.coregui.client;
-import java.util.Set; - import com.allen_sauer.gwt.log.client.Log; import com.google.gwt.http.client.Request; import com.google.gwt.http.client.RequestBuilder; @@ -35,7 +33,6 @@ import com.google.gwt.user.client.Timer; import com.google.gwt.user.client.rpc.AsyncCallback;
import org.rhq.core.domain.auth.Subject; -import org.rhq.core.domain.authz.Permission; import org.rhq.core.domain.criteria.SubjectCriteria; import org.rhq.core.domain.util.PageList; import org.rhq.enterprise.gui.coregui.client.gwt.GWTServiceLookup; @@ -63,7 +60,6 @@ public class UserSessionManager { private static int LOGOUT_DELAY = 5 * 1000; // wait 5 seconds for in-flight requests to complete before logout
public static final String SESSION_NAME = "RHQ_Session"; - private static final UserPermissionsManager USER_PERMISSIONS_MANAGER = UserPermissionsManager.getInstance();
private static final String LOCATOR_ID = "SessionManagerLogin";
@@ -320,14 +316,8 @@ public class UserSessionManager { //update savedSessionId for browser refresh saveSessionId(String.valueOf(sessionSubject.getSessionId())); } - - // Kick off async load of the user's global permissions. - USER_PERMISSIONS_MANAGER.loadGlobalPermissions(new PermissionsLoadedListener() { - public void onPermissionsLoaded(Set<Permission> permissions) { - // Once the permissions have been loaded, build the GUI. - CoreGUI.get().buildCoreUI(); - } - }); + + CoreGUI.get().buildCoreUI(); }
public void onFailure(Throwable caught) { @@ -374,8 +364,6 @@ public class UserSessionManager { Log.info("Destroying session timer..."); sessionTimer.cancel();
- USER_PERMISSIONS_MANAGER.clearCache(); - // log out the web session on the server-side in a delayed fashion, // allowing enough time to pass to let in-flight requests complete logoutTimer.schedule(LOGOUT_DELAY); diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/admin/roles/RoleEditView.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/admin/roles/RoleEditView.java index df0035b..800c7a0 100644 --- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/admin/roles/RoleEditView.java +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/admin/roles/RoleEditView.java @@ -20,6 +20,7 @@ package org.rhq.enterprise.gui.coregui.client.admin.roles;
import java.util.ArrayList; import java.util.Collections; +import java.util.EnumSet; import java.util.List; import java.util.Map; import java.util.Set; @@ -40,8 +41,6 @@ import org.rhq.core.domain.authz.Role; import org.rhq.core.domain.resource.group.LdapGroup; import org.rhq.enterprise.gui.coregui.client.BookmarkableView; import org.rhq.enterprise.gui.coregui.client.CoreGUI; -import org.rhq.enterprise.gui.coregui.client.PermissionsLoadedListener; -import org.rhq.enterprise.gui.coregui.client.UserPermissionsManager; import org.rhq.enterprise.gui.coregui.client.UserSessionManager; import org.rhq.enterprise.gui.coregui.client.ViewPath; import org.rhq.enterprise.gui.coregui.client.components.form.AbstractRecordEditor; @@ -50,6 +49,7 @@ import org.rhq.enterprise.gui.coregui.client.components.selector.AssignedItemsCh import org.rhq.enterprise.gui.coregui.client.components.selector.AssignedItemsChangedHandler; import org.rhq.enterprise.gui.coregui.client.gwt.GWTServiceLookup; import org.rhq.enterprise.gui.coregui.client.inventory.resource.selection.ResourceGroupSelector; +import org.rhq.enterprise.gui.coregui.client.util.message.Message;
/** * A form for viewing and/or editing an RHQ {@link Role role}. @@ -81,11 +81,19 @@ public class RoleEditView extends AbstractRecordEditor<RolesDataSource> implemen @Override public void renderView(ViewPath viewPath) { super.renderView(viewPath); - UserPermissionsManager.getInstance().loadGlobalPermissions(new PermissionsLoadedListener() { - public void onPermissionsLoaded(Set<Permission> globalPermissions) { - RoleEditView.this.hasManageSecurityPermission = globalPermissions.contains(Permission.MANAGE_SECURITY); + GWTServiceLookup.getAuthorizationService().getExplicitGlobalPermissions(new AsyncCallback<Set<Permission>>() { + @Override + public void onSuccess(Set<Permission> result) { + RoleEditView.this.hasManageSecurityPermission = result.contains(Permission.MANAGE_SECURITY); checkIfLdapConfigured(); } + + @Override + public void onFailure(Throwable caught) { + CoreGUI.getMessageCenter().notify( + new Message(MSG.util_userPerm_loadFailGlobal(), caught, Message.Severity.Error, EnumSet + .of(Message.Option.BackgroundJobResult))); + } }); }
@@ -128,16 +136,15 @@ public class RoleEditView extends AbstractRecordEditor<RolesDataSource> implemen }
private void init() { - final boolean isReadOnly = (!this.hasManageSecurityPermission || - (getRecordId() == RolesDataSource.ID_SUPERUSER) || - (getRecordId() == RolesDataSource.ID_ALL_RESOURCES)); + final boolean isReadOnly = (!this.hasManageSecurityPermission + || (getRecordId() == RolesDataSource.ID_SUPERUSER) || (getRecordId() == RolesDataSource.ID_ALL_RESOURCES)); init(isReadOnly); }
@Override protected Record createNewRecord() { Role role = new Role(); - @SuppressWarnings({"UnnecessaryLocalVariable"}) + @SuppressWarnings( { "UnnecessaryLocalVariable" }) Record roleRecord = RolesDataSource.getInstance().copyValues(role); return roleRecord; } @@ -197,7 +204,7 @@ public class RoleEditView extends AbstractRecordEditor<RolesDataSource> implemen label.setHeight(20); label.setPadding(5); this.ldapGroupsItem.setCanvas(label); - } + } }
this.permissionsItem.redraw(); @@ -266,7 +273,7 @@ public class RoleEditView extends AbstractRecordEditor<RolesDataSource> implemen
@Override protected void reset() { - super.reset(); + super.reset();
this.permissionsItem.reset(); this.groupSelector.reset(); diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/admin/roles/RolesDataSource.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/admin/roles/RolesDataSource.java index 8806a49..95090ba 100644 --- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/admin/roles/RolesDataSource.java +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/admin/roles/RolesDataSource.java @@ -40,8 +40,6 @@ import org.rhq.core.domain.authz.Role; import org.rhq.core.domain.criteria.RoleCriteria; import org.rhq.core.domain.resource.group.ResourceGroup; import org.rhq.core.domain.util.PageList; -import org.rhq.enterprise.gui.coregui.client.PermissionsLoadedListener; -import org.rhq.enterprise.gui.coregui.client.UserPermissionsManager; import org.rhq.enterprise.gui.coregui.client.admin.users.UsersDataSource; import org.rhq.enterprise.gui.coregui.client.gwt.GWTServiceLookup; import org.rhq.enterprise.gui.coregui.client.gwt.RoleGWTServiceAsync; @@ -77,7 +75,6 @@ public class RolesDataSource extends RPCDataSource<Role> { private static RolesDataSource INSTANCE;
private RoleGWTServiceAsync roleService = GWTServiceLookup.getRoleService(); - private Set<Permission> globalPermissions;
public static RolesDataSource getInstance() { if (INSTANCE == null) { @@ -90,12 +87,6 @@ public class RolesDataSource extends RPCDataSource<Role> { super(); List<DataSourceField> fields = addDataSourceFields(); addFields(fields); - - UserPermissionsManager.getInstance().loadGlobalPermissions(new PermissionsLoadedListener() { - public void onPermissionsLoaded(Set<Permission> permissions) { - RolesDataSource.this.globalPermissions = permissions; - } - }); }
@Override @@ -114,7 +105,8 @@ public class RolesDataSource extends RPCDataSource<Role> { 100, false); fields.add(descriptionField);
- DataSourceField resourceGroupsField = new DataSourceField(Field.RESOURCE_GROUPS, FieldType.ANY, "Resource Groups"); + DataSourceField resourceGroupsField = new DataSourceField(Field.RESOURCE_GROUPS, FieldType.ANY, + "Resource Groups"); fields.add(resourceGroupsField);
DataSourceField permissionsField = new DataSourceField(Field.PERMISSIONS, FieldType.ANY, "Permissions"); @@ -211,8 +203,8 @@ public class RolesDataSource extends RPCDataSource<Role> { to.setPermissions(permissions);
Record[] resourceGroupRecords = from.getAttributeAsRecordArray(Field.RESOURCE_GROUPS); - Set<ResourceGroup> resourceGroups = - ResourceGroupsDataSource.getInstance().buildDataObjects(resourceGroupRecords); + Set<ResourceGroup> resourceGroups = ResourceGroupsDataSource.getInstance().buildDataObjects( + resourceGroupRecords); to.setResourceGroups(resourceGroups);
Record[] subjectRecords = from.getAttributeAsRecordArray(Field.SUBJECTS); @@ -289,12 +281,11 @@ public class RolesDataSource extends RPCDataSource<Role> {
// Fetching criteria.fetchPermissions(true); - if (this.globalPermissions.contains(Permission.MANAGE_SECURITY)) { - criteria.fetchSubjects(true); - criteria.fetchResourceGroups(true); - } + + // TODO: instead of fetching subjects and resource groups, use a composite object that will pull the subject + // and resource group count across the wire. these counts will not required permission checks at all.
return criteria; } - + } diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/admin/roles/RolesView.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/admin/roles/RolesView.java index 57b3dc8..bde77b4 100644 --- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/admin/roles/RolesView.java +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/admin/roles/RolesView.java @@ -18,19 +18,22 @@ */ package org.rhq.enterprise.gui.coregui.client.admin.roles;
+import java.util.EnumSet; import java.util.Set;
+import com.google.gwt.user.client.rpc.AsyncCallback; import com.smartgwt.client.widgets.Canvas; import com.smartgwt.client.widgets.grid.ListGridField; import com.smartgwt.client.widgets.grid.ListGridRecord;
import org.rhq.core.domain.authz.Permission; import org.rhq.enterprise.gui.coregui.client.BookmarkableView; -import org.rhq.enterprise.gui.coregui.client.PermissionsLoadedListener; -import org.rhq.enterprise.gui.coregui.client.UserPermissionsManager; +import org.rhq.enterprise.gui.coregui.client.CoreGUI; import org.rhq.enterprise.gui.coregui.client.components.table.TableAction; import org.rhq.enterprise.gui.coregui.client.components.table.TableSection; import org.rhq.enterprise.gui.coregui.client.components.view.ViewName; +import org.rhq.enterprise.gui.coregui.client.gwt.GWTServiceLookup; +import org.rhq.enterprise.gui.coregui.client.util.message.Message;
/** * A table that lists all roles and provides the ability to view details of or delete those roles and to create new @@ -40,7 +43,7 @@ import org.rhq.enterprise.gui.coregui.client.components.view.ViewName; * @author Ian Springer */ public class RolesView extends TableSection<RolesDataSource> implements BookmarkableView { - + public static final ViewName VIEW_ID = new ViewName("Roles", MSG.view_adminSecurity_roles());
// TODO: We need a 24x24 version of the Role icon. @@ -88,14 +91,24 @@ public class RolesView extends TableSection<RolesDataSource> implements Bookmark });
addTableAction(extendLocatorId("New"), MSG.common_button_new(), new TableAction() { - private boolean[] hasManageSecurityPermission = new boolean[] {false}; + private boolean hasManageSecurity = false; + public boolean isEnabled(ListGridRecord[] selection) { - UserPermissionsManager.getInstance().loadGlobalPermissions(new PermissionsLoadedListener() { - public void onPermissionsLoaded(Set<Permission> globalPermissions) { - hasManageSecurityPermission[0] = globalPermissions.contains(Permission.MANAGE_SECURITY); - } - }); - return hasManageSecurityPermission[0]; + GWTServiceLookup.getAuthorizationService().getExplicitGlobalPermissions( + new AsyncCallback<Set<Permission>>() { + @Override + public void onSuccess(Set<Permission> result) { + hasManageSecurity = result.contains(Permission.MANAGE_SECURITY); + } + + @Override + public void onFailure(Throwable caught) { + CoreGUI.getMessageCenter().notify( + new Message(MSG.util_userPerm_loadFailGlobal(), caught, Message.Severity.Error, EnumSet + .of(Message.Option.BackgroundJobResult))); + } + }); + return hasManageSecurity; }
public void executeAction(ListGridRecord[] selection, Object actionValue) { diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/admin/users/UserEditView.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/admin/users/UserEditView.java index cf4650d..391c8f8 100644 --- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/admin/users/UserEditView.java +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/admin/users/UserEditView.java @@ -19,9 +19,11 @@ package org.rhq.enterprise.gui.coregui.client.admin.users;
import java.util.ArrayList; +import java.util.EnumSet; import java.util.List; import java.util.Set;
+import com.google.gwt.user.client.rpc.AsyncCallback; import com.smartgwt.client.data.Record; import com.smartgwt.client.types.Alignment; import com.smartgwt.client.widgets.Canvas; @@ -38,13 +40,15 @@ import com.smartgwt.client.widgets.grid.ListGridRecord; import org.rhq.core.domain.auth.Principal; import org.rhq.core.domain.auth.Subject; import org.rhq.core.domain.authz.Permission; -import org.rhq.enterprise.gui.coregui.client.UserPermissionsManager; +import org.rhq.enterprise.gui.coregui.client.CoreGUI; import org.rhq.enterprise.gui.coregui.client.UserSessionManager; import org.rhq.enterprise.gui.coregui.client.ViewPath; import org.rhq.enterprise.gui.coregui.client.components.form.AbstractRecordEditor; import org.rhq.enterprise.gui.coregui.client.components.form.EnhancedDynamicForm; import org.rhq.enterprise.gui.coregui.client.components.selector.AssignedItemsChangedEvent; import org.rhq.enterprise.gui.coregui.client.components.selector.AssignedItemsChangedHandler; +import org.rhq.enterprise.gui.coregui.client.gwt.GWTServiceLookup; +import org.rhq.enterprise.gui.coregui.client.util.message.Message;
/** * A form for viewing and/or editing an RHQ user (i.e. a {@link Subject}, and optionally an associated @@ -70,19 +74,30 @@ public class UserEditView extends AbstractRecordEditor<UsersDataSource> { public void renderView(ViewPath viewPath) { super.renderView(viewPath);
- Set<Permission> globalPermissions = UserPermissionsManager.getInstance().getGlobalPermissions(); - UserEditView.this.hasManageSecurityPermission = globalPermissions.contains(Permission.MANAGE_SECURITY); - Subject sessionSubject = UserSessionManager.getSessionSubject(); - boolean isEditingSelf = (sessionSubject.getId() == getRecordId()); - boolean isReadOnly = (!UserEditView.this.hasManageSecurityPermission && !isEditingSelf); - init(isReadOnly); + GWTServiceLookup.getAuthorizationService().getExplicitGlobalPermissions(new AsyncCallback<Set<Permission>>() { + @Override + public void onSuccess(Set<Permission> result) { + UserEditView.this.hasManageSecurityPermission = result.contains(Permission.MANAGE_SECURITY); + Subject sessionSubject = UserSessionManager.getSessionSubject(); + boolean isEditingSelf = (sessionSubject.getId() == getRecordId()); + boolean isReadOnly = (!UserEditView.this.hasManageSecurityPermission && !isEditingSelf); + init(isReadOnly); + } + + @Override + public void onFailure(Throwable caught) { + CoreGUI.getMessageCenter().notify( + new Message(MSG.util_userPerm_loadFailGlobal(), caught, Message.Severity.Error, EnumSet + .of(Message.Option.BackgroundJobResult))); + } + }); }
@Override protected Record createNewRecord() { Subject subject = new Subject(); subject.setFactive(true); - @SuppressWarnings({"UnnecessaryLocalVariable"}) + @SuppressWarnings( { "UnnecessaryLocalVariable" }) Record userRecord = UsersDataSource.getInstance().copyValues(subject, false); return userRecord; } @@ -90,7 +105,7 @@ public class UserEditView extends AbstractRecordEditor<UsersDataSource> { @Override protected void editRecord(Record record) { super.editRecord(record); - + // Don't allow the rhqadmin account to be disabled. if (getRecordId() == SUBJECT_ID_RHQADMIN) { FormItem activeField = getForm().getField(UsersDataSource.Field.FACTIVE); @@ -128,7 +143,7 @@ public class UserEditView extends AbstractRecordEditor<UsersDataSource> { // private boolean areRolesReadOnly(Record record) { boolean isLdap = Boolean.valueOf(record.getAttribute(UsersDataSource.Field.LDAP)); - return (!hasManageSecurityPermission || (getRecordId() == SUBJECT_ID_RHQADMIN) || isLdap); + return (!hasManageSecurityPermission || (getRecordId() == SUBJECT_ID_RHQADMIN) || isLdap); }
@Override @@ -156,7 +171,7 @@ public class UserEditView extends AbstractRecordEditor<UsersDataSource> { items.add(passwordItem);
final PasswordItem verifyPasswordItem = new PasswordItem(UsersDataSource.Field.PASSWORD_VERIFY); - final boolean[] initialPasswordChange = {true}; + final boolean[] initialPasswordChange = { true }; passwordItem.addChangedHandler(new ChangedHandler() { public void onChanged(ChangedEvent event) { if (initialPasswordChange[0]) { @@ -211,5 +226,5 @@ public class UserEditView extends AbstractRecordEditor<UsersDataSource> { super.reset(); this.roleSelector.reset(); } - + } diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/admin/users/UsersView.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/admin/users/UsersView.java index 6a9fffa..7a68363 100644 --- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/admin/users/UsersView.java +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/admin/users/UsersView.java @@ -19,22 +19,23 @@ package org.rhq.enterprise.gui.coregui.client.admin.users;
import java.util.ArrayList; +import java.util.EnumSet; import java.util.List; import java.util.Set;
-import com.smartgwt.client.data.Record; +import com.google.gwt.user.client.rpc.AsyncCallback; import com.smartgwt.client.widgets.Canvas; -import com.smartgwt.client.widgets.grid.CellFormatter; import com.smartgwt.client.widgets.grid.ListGridField; import com.smartgwt.client.widgets.grid.ListGridRecord;
import org.rhq.core.domain.authz.Permission; -import org.rhq.enterprise.gui.coregui.client.UserPermissionsManager; +import org.rhq.enterprise.gui.coregui.client.CoreGUI; import org.rhq.enterprise.gui.coregui.client.admin.AdministrationView; -import org.rhq.enterprise.gui.coregui.client.admin.roles.RolesDataSource; import org.rhq.enterprise.gui.coregui.client.components.table.TableAction; import org.rhq.enterprise.gui.coregui.client.components.table.TableSection; import org.rhq.enterprise.gui.coregui.client.components.view.ViewName; +import org.rhq.enterprise.gui.coregui.client.gwt.GWTServiceLookup; +import org.rhq.enterprise.gui.coregui.client.util.message.Message;
/** * A table that lists all users and provides the ability to view or edit details of users, delete users, or create new @@ -93,11 +94,13 @@ public class UsersView extends TableSection<UsersDataSource> { ListGridField departmentField = new ListGridField(UsersDataSource.Field.DEPARTMENT, 150); fields.add(departmentField);
- Set<Permission> globalPermissions = UserPermissionsManager.getInstance().getGlobalPermissions(); - if (globalPermissions.contains(Permission.MANAGE_SECURITY)) { + // TODO: instead of fetching roles, use a composite object that will pull the role count across the wire. + // this count will not required permission checks at all. + + /* ListGridField rolesField = new ListGridField(UsersDataSource.Field.ROLES, 250); rolesField.setCellFormatter(new CellFormatter() { - public String format(Object value, ListGridRecord record, int rowNum, int colNum) { + public String format(Object value, ListGridRecord record, int rowNum, int colNum) { Record[] roleRecords = record.getAttributeAsRecordArray(UsersDataSource.Field.ROLES); StringBuilder formattedValue = new StringBuilder(); for (int i = 0; i < roleRecords.length; i++) { @@ -112,7 +115,8 @@ public class UsersView extends TableSection<UsersDataSource> { } }); fields.add(rolesField); - } + + */
return fields; } @@ -143,9 +147,24 @@ public class UsersView extends TableSection<UsersDataSource> {
private TableAction createNewAction() { return new TableAction() { + private boolean hasManageSecurity = false; + public boolean isEnabled(ListGridRecord[] selection) { - Set<Permission> globalPermissions = UserPermissionsManager.getInstance().getGlobalPermissions(); - return globalPermissions.contains(Permission.MANAGE_SECURITY); + GWTServiceLookup.getAuthorizationService().getExplicitGlobalPermissions( + new AsyncCallback<Set<Permission>>() { + @Override + public void onSuccess(Set<Permission> result) { + hasManageSecurity = result.contains(Permission.MANAGE_SECURITY); + } + + @Override + public void onFailure(Throwable caught) { + CoreGUI.getMessageCenter().notify( + new Message(MSG.util_userPerm_loadFailGlobal(), caught, Message.Severity.Error, EnumSet + .of(Message.Option.BackgroundJobResult))); + } + }); + return hasManageSecurity; }
public void executeAction(ListGridRecord[] selection, Object actionValue) { diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/ResourceGroupDetailView.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/ResourceGroupDetailView.java index 9fdd4cc..0d7d3ca 100644 --- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/ResourceGroupDetailView.java +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/ResourceGroupDetailView.java @@ -20,6 +20,7 @@ package org.rhq.enterprise.gui.coregui.client.inventory.groups.detail;
import java.util.ArrayList; import java.util.EnumSet; +import java.util.HashSet; import java.util.List; import java.util.Set;
@@ -38,7 +39,6 @@ import org.rhq.core.domain.resource.group.ResourceGroup; import org.rhq.core.domain.resource.group.composite.ResourceGroupComposite; import org.rhq.core.domain.util.PageList; import org.rhq.enterprise.gui.coregui.client.CoreGUI; -import org.rhq.enterprise.gui.coregui.client.UserPermissionsManager; import org.rhq.enterprise.gui.coregui.client.ViewPath; import org.rhq.enterprise.gui.coregui.client.alert.GroupAlertHistoryView; import org.rhq.enterprise.gui.coregui.client.alert.definitions.GroupAlertDefinitionsView; @@ -59,6 +59,7 @@ import org.rhq.enterprise.gui.coregui.client.inventory.groups.detail.monitoring. import org.rhq.enterprise.gui.coregui.client.inventory.groups.detail.summary.OverviewView; import org.rhq.enterprise.gui.coregui.client.inventory.resource.ResourceSearchView; import org.rhq.enterprise.gui.coregui.client.inventory.resource.type.ResourceTypeRepository; +import org.rhq.enterprise.gui.coregui.client.util.message.Message;
/** * Be able to view members as a resource list, or edit members via selector. @@ -219,7 +220,24 @@ public class ResourceGroupDetailView extends AbstractTwoLevelTabSetView<Resource return tabs; }
- protected void updateTabContent(ResourceGroupComposite groupComposite) { + protected void updateTabContent(final ResourceGroupComposite groupComposite) { + GWTServiceLookup.getAuthorizationService().getExplicitGlobalPermissions(new AsyncCallback<Set<Permission>>() { + @Override + public void onSuccess(Set<Permission> result) { + updateTabContent(groupComposite, result); + } + + @Override + public void onFailure(Throwable caught) { + CoreGUI.getMessageCenter().notify( + new Message(MSG.util_userPerm_loadFailGlobal(), caught, Message.Severity.Error, EnumSet + .of(Message.Option.BackgroundJobResult))); + updateTabContent(groupComposite, new HashSet<Permission>()); + } + }); + } + + protected void updateTabContent(ResourceGroupComposite groupComposite, Set<Permission> globalPermissions) { boolean enabled; boolean visible; Canvas canvas; @@ -233,7 +251,6 @@ public class ResourceGroupDetailView extends AbstractTwoLevelTabSetView<Resource ((TwoLevelTab) top).getLayout().destroyViews(); }
- Set<Permission> globalPermissions = UserPermissionsManager.getInstance().getGlobalPermissions(); GroupCategory groupCategory = groupComposite.getResourceGroup().getGroupCategory(); Set<ResourceTypeFacet> facets = groupComposite.getResourceFacets().getFacets();
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/ResourceDetailView.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/ResourceDetailView.java index 514aaf7..c914b9d 100644 --- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/ResourceDetailView.java +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/ResourceDetailView.java @@ -20,6 +20,7 @@ package org.rhq.enterprise.gui.coregui.client.inventory.resource.detail;
import java.util.ArrayList; import java.util.EnumSet; +import java.util.HashSet; import java.util.List; import java.util.Set;
@@ -38,7 +39,6 @@ import org.rhq.core.domain.resource.composite.ResourceComposite; import org.rhq.core.domain.resource.composite.ResourcePermission; import org.rhq.core.domain.util.PageList; import org.rhq.enterprise.gui.coregui.client.CoreGUI; -import org.rhq.enterprise.gui.coregui.client.UserPermissionsManager; import org.rhq.enterprise.gui.coregui.client.ViewPath; import org.rhq.enterprise.gui.coregui.client.alert.ResourceAlertHistoryView; import org.rhq.enterprise.gui.coregui.client.alert.definitions.ResourceAlertDefinitionsView; @@ -222,7 +222,24 @@ public class ResourceDetailView extends AbstractTwoLevelTabSetView<ResourceCompo return new ResourceTitleBar(extendLocatorId("TitleBar")); }
- protected void updateTabContent(ResourceComposite resourceComposite) { + protected void updateTabContent(final ResourceComposite resourceComposite) { + GWTServiceLookup.getAuthorizationService().getExplicitGlobalPermissions(new AsyncCallback<Set<Permission>>() { + @Override + public void onSuccess(Set<Permission> result) { + updateTabContent(resourceComposite, result); + } + + @Override + public void onFailure(Throwable caught) { + CoreGUI.getMessageCenter().notify( + new Message(MSG.util_userPerm_loadFailGlobal(), caught, Message.Severity.Error, EnumSet + .of(Message.Option.BackgroundJobResult))); + updateTabContent(resourceComposite, new HashSet<Permission>()); + } + }); + } + + protected void updateTabContent(ResourceComposite resourceComposite, Set<Permission> globalPermissions) { boolean enabled; boolean visible; Canvas canvas; @@ -235,7 +252,6 @@ public class ResourceDetailView extends AbstractTwoLevelTabSetView<ResourceCompo ((TwoLevelTab) top).getLayout().destroyViews(); }
- Set<Permission> globalPermissions = UserPermissionsManager.getInstance().getGlobalPermissions(); ResourcePermission resourcePermissions = this.resourceComposite.getResourcePermission(); Set<ResourceTypeFacet> facets = this.resourceComposite.getResourceFacets().getFacets();
commit 4255f38b5d2e9d15ae0f78b809b2794133bbc97d Author: Joseph Marques joseph@redhat.com Date: Wed Nov 24 18:26:17 2010 -0500
remove unnecessary check for isLoggedIn
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/Footer.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/Footer.java index 0d94cc3..60d0502 100644 --- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/Footer.java +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/Footer.java @@ -18,7 +18,6 @@ */ package org.rhq.enterprise.gui.coregui.client;
-import com.allen_sauer.gwt.log.client.Log; import com.google.gwt.user.client.History; import com.google.gwt.user.client.Timer; import com.google.gwt.user.client.rpc.AsyncCallback; @@ -132,26 +131,21 @@ public class Footer extends LocatableToolStrip { AlertCriteria alertCriteria = new AlertCriteria(); alertCriteria.addFilterStartTime(System.currentTimeMillis() - (1000L * 60 * 60 * 8)); // last 8 hrs
- //check for still logged in before submitting server side request - if (UserSessionManager.isLoggedIn()) { - GWTServiceLookup.getAlertService().findAlertCountByCriteria(alertCriteria, new AsyncCallback<Long>() { - public void onFailure(Throwable caught) { - CoreGUI.getErrorHandler().handleError(MSG.view_core_error_1(), caught); - } + GWTServiceLookup.getAlertService().findAlertCountByCriteria(alertCriteria, new AsyncCallback<Long>() { + public void onFailure(Throwable caught) { + CoreGUI.getErrorHandler().handleError(MSG.view_core_error_1(), caught); + }
- public void onSuccess(Long result) { - if (result == 0L) { - setContents(MSG.view_core_recentAlerts("0")); - setIcon("subsystems/alert/Alert_LOW_16.png"); - } else { - setContents(MSG.view_core_recentAlerts(result.toString())); - setIcon("subsystems/alert/Alert_HIGH_16.png"); - } + public void onSuccess(Long result) { + if (result == 0L) { + setContents(MSG.view_core_recentAlerts("0")); + setIcon("subsystems/alert/Alert_LOW_16.png"); + } else { + setContents(MSG.view_core_recentAlerts(result.toString())); + setIcon("subsystems/alert/Alert_HIGH_16.png"); } - }); - } else {//dump request - Log.debug("user not logged in. Not fetching any alerts now."); - } + } + }); } }
rhq-commits@lists.fedorahosted.org