[rhq] modules/core
John Sanda
jsanda at fedoraproject.org
Mon Aug 6 16:42:07 UTC 2012
modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/DriftFilesSender.java | 42 +++++++---
1 file changed, 32 insertions(+), 10 deletions(-)
New commits:
commit 5b37f7a17ef64863a810a5b92cbf885eca05dda3
Author: John Sanda <jsanda at redhat.com>
Date: Mon Aug 6 12:38:46 2012 -0400
[BZ 838861] Handle empty zip file on java 7
Since an exception is not thrown when closing a ZipOutputStream on an
empty zip file in Java 7, I have added logic to check whether or not the
zip file has any content. sendChangeSetContentToServer is called only if
the content file is non-empty. The logging logic has been updated as
well so that we only log an error message when failing to close the
output stream only when the content file is non-empty. This keeps the
logging clean and consistent across Java 6 and 7.
diff --git a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/DriftFilesSender.java b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/DriftFilesSender.java
index 59d3054..266b666 100644
--- a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/DriftFilesSender.java
+++ b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/DriftFilesSender.java
@@ -1,20 +1,25 @@
package org.rhq.core.pc.drift;
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipOutputStream;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+
import org.rhq.common.drift.ChangeSetReader;
import org.rhq.common.drift.FileEntry;
import org.rhq.common.drift.Headers;
import org.rhq.core.domain.drift.DriftFile;
import org.rhq.core.util.stream.StreamUtil;
-import java.io.*;
-import java.util.List;
-import java.util.Map;
-import java.util.TreeMap;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipOutputStream;
-
public class DriftFilesSender implements Runnable {
private Log log = LogFactory.getLog(DriftFilesSender.class);
@@ -52,6 +57,7 @@ public class DriftFilesSender implements Runnable {
@Override
public void run() {
ZipOutputStream stream = null;
+ int numContentFiles = 0;
try {
if (log.isInfoEnabled()) {
log.info("Preparing to send content to server for " + defToString());
@@ -89,6 +95,7 @@ public class DriftFilesSender implements Runnable {
log.debug("Adding " + file.getPath() + " to " + contentFileName);
}
addFileToContentZipFile(stream, driftFile, file);
+ ++numContentFiles;
}
} else {
Map<String, FileEntry> fileEntries = createSnapshotIndex();
@@ -106,15 +113,18 @@ public class DriftFilesSender implements Runnable {
log.debug("Adding " + file.getPath() + " to " + contentFileName);
}
addFileToContentZipFile(stream, driftFile, file);
+ ++numContentFiles;
}
}
}
+ if (numContentFiles > 0) {
+ driftClient.sendChangeSetContentToServer(resourceId, headers.getDriftDefinitionName(), zipFile);
+ }
+
stream.close();
stream = null;
- driftClient.sendChangeSetContentToServer(resourceId, headers.getDriftDefinitionName(), zipFile);
-
if (log.isInfoEnabled()) {
long endTime = System.currentTimeMillis();
log.info("Finished submitting request to send content to server in " + (endTime - startTime) +
@@ -122,7 +132,19 @@ public class DriftFilesSender implements Runnable {
}
} catch (IOException e) {
- log.error("Failed to send drift files.", e);
+ if (numContentFiles > 0) {
+ // Only log an error message if the content zip file is not empty. With
+ // Java 6, closing an empty ZipOutputStream causes an exception which we
+ // can ignore. On Java 7 however, no exception is thrown when closing an
+ // empty ZipOutputStream. This check keeps the error reporting logic
+ // consistent across Java 6 and 7 such that we only log an error message
+ // when we fail to close the output stream when the content zip file is
+ // not empty. See https://bugzilla.redhat.com/show_bug.cgi?id=838681 for
+ // more info.
+ //
+ // jsanda
+ log.error("Failed to send drift files.", e);
+ }
} finally {
if (stream != null) {
try {
More information about the rhq-commits
mailing list