modules/core/client-api/src/main/java/org/rhq/core/clientapi/server/core/AgentRegistrationResults.java | 172 +++++-----
modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/DriftManager.java | 80 ++--
2 files changed, 131 insertions(+), 121 deletions(-)
New commits:
commit 4a6ec5f97390cc5b6a1956b0b904162ea7b2b319
Author: Jay Shaughnessy <jshaughn(a)redhat.com>
Date: Mon Nov 28 15:05:53 2011 -0500
[Bug 757201 - NPE in Server with drift report processing]
Not so much a fix as this was not reproducible, but some added
null protection and logging to try and ensure that a failure in
the "Ack" call does not cause a server-side failure. And to
capture more information if this happens again.
- note, some formatting changes were applied. the real changes are
lines 635-648.
diff --git a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/DriftManager.java b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/DriftManager.java
index c70b546..c713297 100644
--- a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/DriftManager.java
+++ b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/DriftManager.java
@@ -166,8 +166,8 @@ public class DriftManager extends AgentService implements DriftAgentService, Dri
private void syncWithServer(Resource resource, DriftDefinition driftDefinition) throws IOException {
Headers headers = createHeaders(resource.getId(), driftDefinition);
if (!changeSetMgr.changeSetExists(resource.getId(), headers)) {
- log.info("No snapshot found for " + toString(resource.getId(), driftDefinition) +
- ". Downloading snapshot from server");
+ log.info("No snapshot found for " + toString(resource.getId(), driftDefinition)
+ + ". Downloading snapshot from server");
DriftServerService driftServer = pluginContainerConfiguration.getServerServices().getDriftServerService();
DriftSnapshot snapshot = driftServer.getCurrentSnapshot(driftDefinition.getId());
@@ -179,18 +179,18 @@ public class DriftManager extends AgentService implements DriftAgentService, Dri
// this point we just return and allow the agent to generate the
// initial snapshot file.
if (log.isDebugEnabled()) {
- log.debug("The server does not have any change sets for " + toString(resource.getId(), driftDefinition)
- + ". An initial snapshot needs to be generated.");
+ log.debug("The server does not have any change sets for "
+ + toString(resource.getId(), driftDefinition) + ". An initial snapshot needs to be generated.");
}
return;
}
headers.setVersion(snapshot.getVersion());
- log.info("Preparing to write snapshot at version " + snapshot.getVersion() + " to disk for " +
- toString(resource.getId(), driftDefinition));
- File currentSnapshotFile = changeSetMgr.findChangeSet(resource.getId(), driftDefinition.getName(),
- COVERAGE);
+ log.info("Preparing to write snapshot at version " + snapshot.getVersion() + " to disk for "
+ + toString(resource.getId(), driftDefinition));
+ File currentSnapshotFile = changeSetMgr
+ .findChangeSet(resource.getId(), driftDefinition.getName(), COVERAGE);
writeSnapshotToFile(snapshot, currentSnapshotFile, headers);
if (driftDefinition.isPinned()) {
@@ -200,15 +200,16 @@ public class DriftManager extends AgentService implements DriftAgentService, Dri
DriftSnapshot pinnedSnapshot = driftServer.getSnapshot(driftDefinition.getId(), 0, 0);
Headers pinnedHeaders = createHeaders(resource.getId(), driftDefinition);
File pinnedSnapshotFile = new File(currentSnapshotFile.getParent(), "snapshot.pinned");
- log.info("Preparing to write pinned snapshot to disk for " + toString(resource.getId(), driftDefinition));
+ log.info("Preparing to write pinned snapshot to disk for "
+ + toString(resource.getId(), driftDefinition));
writeSnapshotToFile(pinnedSnapshot, pinnedSnapshotFile, pinnedHeaders);
if (snapshot.getVersion() > 0) {
// Drift was previously reported. We will fetch a snapshot of the
// latest change set and write that to disk so that we avoid reporting
// drift that has already been reported to the server.
- DriftSnapshot deltaSnapshot = driftServer.getSnapshot(driftDefinition.getId(),
- snapshot.getVersion(), snapshot.getVersion());
+ DriftSnapshot deltaSnapshot = driftServer.getSnapshot(driftDefinition.getId(), snapshot
+ .getVersion(), snapshot.getVersion());
File deltaFile = new File(currentSnapshotFile.getParentFile(), "drift-changeset.txt");
Headers deltaHeaders = createHeaders(resource.getId(), driftDefinition);
deltaHeaders.setVersion(snapshot.getVersion());
@@ -317,14 +318,14 @@ public class DriftManager extends AgentService implements DriftAgentService, Dri
} catch (IOException e) {
zipFile.delete();
throw new DriftDetectionException("Failed to create change set zip file " + zipFile.getPath(), e);
-// } finally {
-// try {
-// if (stream != null) {
-// stream.close();
-// }
-// } catch (IOException e) {
-// log.warn("An error occurred while trying to close change set zip file output stream", e);
-// }
+ // } finally {
+ // try {
+ // if (stream != null) {
+ // stream.close();
+ // }
+ // } catch (IOException e) {
+ // log.warn("An error occurred while trying to close change set zip file output stream", e);
+ // }
}
try {
@@ -541,8 +542,8 @@ public class DriftManager extends AgentService implements DriftAgentService, Dri
schedulesQueue.removeAndExecute(schedule.getResourceId(), schedule.getDriftDefinition(), new Runnable() {
@Override
public void run() {
- File currentSnapshot = changeSetMgr.findChangeSet(schedule.getResourceId(),
- schedule.getDriftDefinition().getName(), COVERAGE);
+ File currentSnapshot = changeSetMgr.findChangeSet(schedule.getResourceId(), schedule
+ .getDriftDefinition().getName(), COVERAGE);
File pinnedSnapshot = new File(currentSnapshot.getParentFile(), "snapshot.pinned");
pinnedSnapshot.delete();
@@ -557,8 +558,7 @@ public class DriftManager extends AgentService implements DriftAgentService, Dri
@Override
public void updateDriftDetection(int resourceId, DriftDefinition driftDef, DriftSnapshot driftSnapshot) {
- File currentSnapshot = changeSetMgr.findChangeSet(resourceId, driftDef.getName(),
- COVERAGE);
+ File currentSnapshot = changeSetMgr.findChangeSet(resourceId, driftDef.getName(), COVERAGE);
File pinnedSnapshot = new File(currentSnapshot.getParentFile(), "snapshot.pinned");
Headers headers = createHeaders(resourceId, driftDef);
@@ -606,8 +606,8 @@ public class DriftManager extends AgentService implements DriftAgentService, Dri
final DriftDetectionSchedule schedule = schedulesQueue.find(resourceId, defName);
if (schedule == null) {
if (log.isDebugEnabled()) {
- log.debug("Unable to pin snapshot for " + toString(resourceId, defName) + " - no detection schedule " +
- "found.");
+ log.debug("Unable to pin snapshot for " + toString(resourceId, defName) + " - no detection schedule "
+ + "found.");
}
return;
}
@@ -619,8 +619,9 @@ public class DriftManager extends AgentService implements DriftAgentService, Dri
@Override
public void ackChangeSet(int resourceId, String defName) {
- log.info("Received server change set ack for [resourceId: " + resourceId + ", driftDefinition:" +
- defName + "]");
+ log
+ .info("Received server change set ack for [resourceId: " + resourceId + ", driftDefinition:" + defName
+ + "]");
File resourceDir = new File(changeSetsDir, Integer.toString(resourceId));
File changeSetDir = new File(resourceDir, defName);
@@ -631,11 +632,20 @@ public class DriftManager extends AgentService implements DriftAgentService, Dri
return;
}
- File snapshot = changeSetMgr.findChangeSet(resourceId, defName, COVERAGE);
- File previousSnapshot = new File(snapshot.getParentFile(), snapshot.getName() + ".previous");
+ try {
+ File snapshot = changeSetMgr.findChangeSet(resourceId, defName, COVERAGE);
+ if (null == snapshot) {
+ log.warn("Cannot complete acknowledgement. Could not find coverage changeset for [" + resourceId + ","
+ + defName + "].");
+ return;
+ }
- previousSnapshot.delete();
- deleteZipFiles(changeSetDir, "changeset_");
+ File previousSnapshot = new File(snapshot.getParentFile(), snapshot.getName() + ".previous");
+ previousSnapshot.delete();
+
+ } finally {
+ deleteZipFiles(changeSetDir, "changeset_");
+ }
}
@Override
@@ -758,16 +768,16 @@ public class DriftManager extends AgentService implements DriftAgentService, Dri
private void writeSnapshotToFile(DriftSnapshot snapshot, File file, Headers headers) throws IOException {
ChangeSetWriter writer = changeSetMgr.getChangeSetWriter(file, headers);
try {
- for (Drift drift : snapshot.getDriftInstances()) {
+ for (Drift<?, ?> drift : snapshot.getDriftInstances()) {
switch (drift.getCategory()) {
case FILE_ADDED:
writer.write(addedFileEntry(drift.getPath(), drift.getNewDriftFile().getHashId()));
break;
case FILE_CHANGED:
- writer.write(changedFileEntry(drift.getPath(), drift.getOldDriftFile().getHashId(),
- drift.getNewDriftFile().getHashId()));
+ writer.write(changedFileEntry(drift.getPath(), drift.getOldDriftFile().getHashId(), drift
+ .getNewDriftFile().getHashId()));
break;
- default: // FILE_REMOVED
+ default: // FILE_REMOVED
writer.write(removedFileEntry(drift.getPath(), drift.getOldDriftFile().getHashId()));
}
}
commit f6eba2a3f0d31a45918664109034182de01ec970
Author: Jay Shaughnessy <jshaughn(a)redhat.com>
Date: Mon Nov 28 14:58:12 2011 -0500
Convert back to unix line terminators
diff --git a/modules/core/client-api/src/main/java/org/rhq/core/clientapi/server/core/AgentRegistrationResults.java b/modules/core/client-api/src/main/java/org/rhq/core/clientapi/server/core/AgentRegistrationResults.java
index f4e62d5..b284dcc 100644
--- a/modules/core/client-api/src/main/java/org/rhq/core/clientapi/server/core/AgentRegistrationResults.java
+++ b/modules/core/client-api/src/main/java/org/rhq/core/clientapi/server/core/AgentRegistrationResults.java
@@ -1,87 +1,87 @@
-/*
- * RHQ Management Platform
- * Copyright (C) 2005-2008 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, version 2, as
- * published by the Free Software Foundation, and/or the GNU Lesser
- * General Public License, version 2.1, also as published by the Free
- * Software Foundation.
- *
- * 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 and the GNU Lesser General Public License
- * for more details.
- *
- * You should have received a copy of the GNU General Public License
- * and the GNU Lesser General Public License along with this program;
- * if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.rhq.core.clientapi.server.core;
-
-import java.io.Serializable;
-import java.util.ArrayList;
-
-import org.rhq.core.domain.cloud.composite.FailoverListComposite;
-import org.rhq.core.domain.cloud.composite.FailoverListComposite.ServerEntry;
-
-/**
- * These are the results of a successful agent registration. After the agent has been registered by the server, this
- * object will contain the identification information assigned to the agent by the server. It will also contain the
- * list of servers this agent can fail over to in a high availability setup.
- *
- * @author John Mazzitelli
- */
-public class AgentRegistrationResults implements Serializable {
- private static final long serialVersionUID = 1L;
-
- private String agentToken;
- private FailoverListComposite failoverList;
-
- /**
- * The agent token that the agent must use in order to communicate with the server in the future.
- *
- * @return the agent's token assigned to it by the server
- */
- public String getAgentToken() {
- return agentToken;
- }
-
- /**
- * See {@link #getAgentToken()}.
- *
- * @param token
- */
- public void setAgentToken(String token) {
- agentToken = token;
- }
-
- /**
- * The FailoverListComposite that the agent must use in order to communicate with the server in the future.
- *
- * @return the FailoverListComposite assigned to it by the server (will not be <code>null</code> but may be empty)
- */
- public FailoverListComposite getFailoverList() {
- return failoverList != null ? failoverList : new FailoverListComposite(new ArrayList<ServerEntry>());
- }
-
- /**
- * See {@link #getFailoverList()}.
- *
- * @param failoverList
- */
- public void setFailoverList(FailoverListComposite failoverList) {
- this.failoverList = failoverList;
- }
-
- /**
- * @see java.lang.Object#toString()
- */
- @Override
- public String toString() {
- return "AgentRegistrationResults: [agent-token=" + this.agentToken + "]";
- }
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2008 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, version 2, as
+ * published by the Free Software Foundation, and/or the GNU Lesser
+ * General Public License, version 2.1, also as published by the Free
+ * Software Foundation.
+ *
+ * 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 and the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * and the GNU Lesser General Public License along with this program;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.rhq.core.clientapi.server.core;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+
+import org.rhq.core.domain.cloud.composite.FailoverListComposite;
+import org.rhq.core.domain.cloud.composite.FailoverListComposite.ServerEntry;
+
+/**
+ * These are the results of a successful agent registration. After the agent has been registered by the server, this
+ * object will contain the identification information assigned to the agent by the server. It will also contain the
+ * list of servers this agent can fail over to in a high availability setup.
+ *
+ * @author John Mazzitelli
+ */
+public class AgentRegistrationResults implements Serializable {
+ private static final long serialVersionUID = 1L;
+
+ private String agentToken;
+ private FailoverListComposite failoverList;
+
+ /**
+ * The agent token that the agent must use in order to communicate with the server in the future.
+ *
+ * @return the agent's token assigned to it by the server
+ */
+ public String getAgentToken() {
+ return agentToken;
+ }
+
+ /**
+ * See {@link #getAgentToken()}.
+ *
+ * @param token
+ */
+ public void setAgentToken(String token) {
+ agentToken = token;
+ }
+
+ /**
+ * The FailoverListComposite that the agent must use in order to communicate with the server in the future.
+ *
+ * @return the FailoverListComposite assigned to it by the server (will not be <code>null</code> but may be empty)
+ */
+ public FailoverListComposite getFailoverList() {
+ return failoverList != null ? failoverList : new FailoverListComposite(new ArrayList<ServerEntry>());
+ }
+
+ /**
+ * See {@link #getFailoverList()}.
+ *
+ * @param failoverList
+ */
+ public void setFailoverList(FailoverListComposite failoverList) {
+ this.failoverList = failoverList;
+ }
+
+ /**
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString() {
+ return "AgentRegistrationResults: [agent-token=" + this.agentToken + "]";
+ }
}
\ No newline at end of file