modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/DriftConfigurationEditView.java
| 21 ++
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/ResourceDetailView.java
| 26 ++-
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/server/gwt/DriftGWTServiceImpl.java
| 8 -
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/drift/DriftManagerBean.java
| 80 +++++++++-
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/drift/DriftManagerLocal.java
| 33 ++++
5 files changed, 144 insertions(+), 24 deletions(-)
New commits:
commit c3a8220b3412606dc4b6de4350779ec7edb0e816
Author: Jay Shaughnessy <jshaughn(a)redhat.com>
Date: Wed Jun 29 17:57:22 2011 -0400
Drift GUI
- Get Delete Drift working
- Improve navigation after a drift config update
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/DriftConfigurationEditView.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/DriftConfigurationEditView.java
index 432d9b3..8d9c726 100644
---
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/DriftConfigurationEditView.java
+++
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/DriftConfigurationEditView.java
@@ -33,11 +33,13 @@ import org.rhq.core.domain.configuration.Configuration;
import org.rhq.core.domain.drift.DriftConfiguration;
import org.rhq.core.domain.drift.DriftConfigurationDefinition;
import org.rhq.enterprise.gui.coregui.client.CoreGUI;
+import org.rhq.enterprise.gui.coregui.client.LinkManager;
import org.rhq.enterprise.gui.coregui.client.RefreshableView;
import
org.rhq.enterprise.gui.coregui.client.components.configuration.ConfigurationEditor;
import
org.rhq.enterprise.gui.coregui.client.components.configuration.PropertyValueChangeEvent;
import
org.rhq.enterprise.gui.coregui.client.components.configuration.PropertyValueChangeListener;
import org.rhq.enterprise.gui.coregui.client.gwt.GWTServiceLookup;
+import
org.rhq.enterprise.gui.coregui.client.inventory.resource.detail.ResourceDetailView;
import org.rhq.enterprise.gui.coregui.client.util.message.Message;
import org.rhq.enterprise.gui.coregui.client.util.message.MessageCenter;
import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableIButton;
@@ -53,7 +55,6 @@ public class DriftConfigurationEditView extends LocatableVLayout
implements Prop
private EntityContext context;
private int driftConfigId;
- private DriftConfiguration driftConfig;
private boolean hasWriteAccess;
private ConfigurationEditor editor;
private ToolStrip buttonbar;
@@ -149,8 +150,22 @@ public class DriftConfigurationEditView extends LocatableVLayout
implements Prop
}
public void onSuccess(Void result) {
- Message message;
- message = new Message(MSG.view_drift_success_configurationUpdated(),
Message.Severity.Info);
+ Message message = new
Message(MSG.view_drift_success_configurationUpdated(), Message.Severity.Info);
+
+ switch (context.getType()) {
+ case Resource:
+ int resourceId = context.getResourceId();
+
+ String driftHistoryUrl =
LinkManager.getResourceTabLink(resourceId,
+ ResourceDetailView.Tab.DRIFT,
ResourceDetailView.ConfigurationSubTab.HISTORY);
+ driftHistoryUrl = driftHistoryUrl.substring(1); // chop off the
leading '#'
+ CoreGUI.goToView(driftHistoryUrl, message);
+
+ break;
+
+ default:
+ throw new IllegalArgumentException("Entity Context Type not
supported [" + context + "]");
+ }
}
});
}
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 858e0c2..b8031ea 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
@@ -85,17 +85,23 @@ public class ResourceDetailView extends
AbstractTwoLevelTabSetView<ResourceCompo
private static final String BASE_VIEW_PATH = "Resource";
public static class Tab {
- public static final String OPERATIONS = "Operations";
public static final String CONFIGURATION = "Configuration";
+ public static final String DRIFT = "Drift";
+ public static final String OPERATIONS = "Operations";
}
- public static class OperationsSubTab {
- public static final String SCHEDULES = "Schedules";
+ public static class ConfigurationSubTab {
+ public static final String CURRENT = "Current";
public static final String HISTORY = "History";
}
- public static class ConfigurationSubTab {
- public static final String CURRENT = "Current";
+ public static class DriftSubTab {
+ public static final String CONFIGURATION = "Configuration";
+ public static final String HISTORY = "History";
+ }
+
+ public static class OperationsSubTab {
+ public static final String SCHEDULES = "Schedules";
public static final String HISTORY = "History";
}
@@ -232,12 +238,12 @@ public class ResourceDetailView extends
AbstractTwoLevelTabSetView<ResourceCompo
configurationTab.registerSubTabs(this.configCurrent, this.configHistory);
tabs.add(configurationTab);
- driftTab = new TwoLevelTab(getTabSet().extendLocatorId("Drift"), new
ViewName("Drift", MSG
+ driftTab = new TwoLevelTab(getTabSet().extendLocatorId(Tab.DRIFT), new
ViewName(Tab.DRIFT, MSG
.view_tabs_common_drift()), "subsystems/drift/Drift_16.png");
- this.driftHistory = new SubTab(driftTab.extendLocatorId("History"), new
ViewName("History", MSG
- .view_tabs_common_history()), null);
- this.driftConfig = new SubTab(driftTab.extendLocatorId("Config"), new
ViewName("Config", MSG
- .view_tabs_common_configuration()), null);
+ this.driftHistory = new SubTab(driftTab.extendLocatorId(DriftSubTab.HISTORY), new
ViewName(DriftSubTab.HISTORY,
+ MSG.view_tabs_common_history()), null);
+ this.driftConfig = new
SubTab(driftTab.extendLocatorId(DriftSubTab.CONFIGURATION), new ViewName(
+ DriftSubTab.CONFIGURATION, MSG.view_tabs_common_configuration()), null);
driftTab.registerSubTabs(driftHistory, driftConfig);
tabs.add(driftTab);
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/server/gwt/DriftGWTServiceImpl.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/server/gwt/DriftGWTServiceImpl.java
index 9d0cd0f..3f7aae1 100644
---
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/server/gwt/DriftGWTServiceImpl.java
+++
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/server/gwt/DriftGWTServiceImpl.java
@@ -41,9 +41,7 @@ public class DriftGWTServiceImpl extends AbstractGWTServiceImpl
implements Drift
@Override
public int deleteDrifts(int[] driftIds) throws RuntimeException {
try {
- // TODO
- //return this.driftManager.deleteDrifts(getSessionSubject(), driftIds);
- return 0;
+ return this.driftManager.deleteDrifts(getSessionSubject(), driftIds);
} catch (Throwable t) {
throw getExceptionToThrowToClient(t);
}
@@ -52,9 +50,7 @@ public class DriftGWTServiceImpl extends AbstractGWTServiceImpl
implements Drift
@Override
public int deleteDriftsByContext(EntityContext entityContext) throws RuntimeException
{
try {
- // TODO
- //return this.driftManager.deleteDriftsByContext(getSessionSubject(),
entityContext);
- return 0;
+ return this.driftManager.deleteDriftsByContext(getSessionSubject(),
entityContext);
} catch (Throwable t) {
throw getExceptionToThrowToClient(t);
}
diff --git
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/drift/DriftManagerBean.java
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/drift/DriftManagerBean.java
index bb28468..5725d89 100644
---
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/drift/DriftManagerBean.java
+++
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/drift/DriftManagerBean.java
@@ -19,6 +19,8 @@
*/
package org.rhq.enterprise.server.drift;
+import static javax.ejb.TransactionAttributeType.REQUIRES_NEW;
+
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.File;
@@ -47,6 +49,8 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.Hibernate;
+import org.jboss.remoting.CannotConnectException;
+
import org.rhq.common.drift.ChangeSetReader;
import org.rhq.common.drift.ChangeSetReaderImpl;
import org.rhq.common.drift.DirectoryEntry;
@@ -75,8 +79,6 @@ import org.rhq.enterprise.server.core.AgentManagerLocal;
import org.rhq.enterprise.server.util.CriteriaQueryGenerator;
import org.rhq.enterprise.server.util.CriteriaQueryRunner;
-import static javax.ejb.TransactionAttributeType.REQUIRES_NEW;
-
@Stateless
public class DriftManagerBean implements DriftManagerLocal, DriftManagerRemote {
private final Log log = LogFactory.getLog(this.getClass());
@@ -102,6 +104,8 @@ public class DriftManagerBean implements DriftManagerLocal,
DriftManagerRemote {
@PersistenceContext(unitName = RHQConstants.PERSISTENCE_UNIT_NAME)
private EntityManager entityManager;
+ // use a new transaction when putting things on the JMS queue. see
+ //
http://management-platform.blogspot.com/2008/11/transaction-recovery-in-j...
@Override
@TransactionAttribute(REQUIRES_NEW)
public void addChangeSet(int resourceId, long zipSize, InputStream zipStream) throws
Exception {
@@ -114,6 +118,8 @@ public class DriftManagerBean implements DriftManagerLocal,
DriftManagerRemote {
connection.close();
}
+ // use a new transaction when putting things on the JMS queue. see
+ //
http://management-platform.blogspot.com/2008/11/transaction-recovery-in-j...
@Override
@TransactionAttribute(REQUIRES_NEW)
public void addFiles(int resourceId, long zipSize, InputStream zipStream) throws
Exception {
@@ -139,7 +145,7 @@ public class DriftManagerBean implements DriftManagerLocal,
DriftManagerRemote {
c.addFilterResourceId(resourceId);
List<DriftChangeSet> changeSets =
findDriftChangeSetsByCriteria(subjectManager.getOverlord(), c);
final int version = changeSets.size();
- // TODO: set caetgory based on changeset parsing
+ // TODO: set category based on changeset parsing
final DriftChangeSetCategory category = (0 == version) ?
DriftChangeSetCategory.COVERAGE
: DriftChangeSetCategory.DRIFT;
@@ -287,6 +293,66 @@ public class DriftManagerBean implements DriftManagerLocal,
DriftManagerRemote {
}
@Override
+ @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
+ public int deleteDriftsInNewTransaction(Subject subject, int... driftIds) {
+ int result = 0;
+
+ for (int driftId : driftIds) {
+ Drift doomed = entityManager.find(Drift.class, driftId);
+ if (null != doomed) {
+ entityManager.remove(doomed);
+ ++result;
+ }
+ }
+
+ return result;
+ }
+
+ @Override
+ public int deleteDrifts(Subject subject, int[] driftIds) {
+ // avoid big transactions by doing this one at a time. if this is too slow we can
chunk in bigger increments.
+ int result = 0;
+
+ for (int driftId : driftIds) {
+ result += driftManager.deleteDriftsInNewTransaction(subject, driftId);
+ }
+
+ return result;
+ }
+
+ @Override
+ public int deleteDriftsByContext(Subject subject, EntityContext entityContext) throws
RuntimeException {
+ int result = 0;
+ DriftCriteria criteria = new DriftCriteria();
+
+ switch (entityContext.getType()) {
+ case Resource:
+ criteria.addFilterResourceIds(entityContext.getResourceId());
+ break;
+
+ case SubsystemView:
+ // delete them all
+ break;
+
+ default:
+ throw new IllegalArgumentException("Entity Context Type not supported
[" + entityContext + "]");
+ }
+
+ List<Drift> drifts = driftManager.findDriftsByCriteria(subject, criteria);
+ if (!drifts.isEmpty()) {
+ int[] driftIds = new int[drifts.size()];
+ int i = 0;
+ for (Drift drift : drifts) {
+ driftIds[i++] = drift.getId();
+ }
+
+ result = driftManager.deleteDrifts(subject, driftIds);
+ }
+
+ return result;
+ }
+
+ @Override
public void deleteDriftConfiguration(Subject subject, EntityContext entityContext,
String driftConfigName) {
switch (entityContext.getType()) {
@@ -430,10 +496,14 @@ public class DriftManagerBean implements DriftManagerLocal,
DriftManagerRemote {
AgentClient agentClient =
agentManager.getAgentClient(subjectManager.getOverlord(), resourceId);
DriftAgentService service = agentClient.getDriftAgentService();
+ // this is a one-time on-demand call. If it fails throw an exception to make
sure the user knows it
+ // did not happen. But clean it up a bit if it's a connect exception
try {
service.detectDrift(resourceId, driftConfig);
- } catch (Exception e) {
- log.warn(" Unable to inform agent of drift detection request
[" + driftConfig + "]", e);
+ } catch (CannotConnectException e) {
+ throw new IllegalStateException(
+ "Agent could not be reached and may be down (see server logs for
more). Could not perform drift detection request ["
+ + driftConfig + "]");
}
break;
diff --git
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/drift/DriftManagerLocal.java
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/drift/DriftManagerLocal.java
index 3184e79..9bb630f 100644
---
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/drift/DriftManagerLocal.java
+++
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/drift/DriftManagerLocal.java
@@ -61,6 +61,39 @@ public interface DriftManagerLocal extends DriftManagerRemote {
void addFiles(int resourceId, long zipSize, InputStream zipStream) throws Exception;
/**
+ * Remove the specified drift in its own transaction. This is used for chunking
transactions and
+ * should not be exposed in a Remote interface.
+ *
+ * @param subject
+ * @param
+ * @param driftConfig
+ *
+ * @return the number of Drift records deleted
+ */
+ int deleteDriftsInNewTransaction(Subject subject, int... driftIds);
+
+ /**
+ * Remove the specified drifts. Ids not identifying an actual drift record will be
ignored.
+ *
+ * @param subject
+ * @param
+ * @param driftConfig
+ *
+ * @return the number of Drift records deleted
+ */
+ int deleteDrifts(Subject subject, int[] driftIds);
+
+ /**
+ * Remove all drifts on the specified entity context.
+ *
+ * @param subject
+ * @param entityContext the context
+ *
+ * @return the number of Drift records deleted
+ */
+ int deleteDriftsByContext(Subject subject, EntityContext entityContext) throws
RuntimeException;
+
+ /**
* Remove the provided driftConfig (identified by name) on the specified
entityContext.
* Agents, if available, will be notified of the change.
* @param subject