[rhq] Branch 'release/jon3.1.x' - 2 commits - modules/core

John Sanda jsanda at fedoraproject.org
Mon Aug 6 18:04:29 UTC 2012


 modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/DriftFilesSender.java |   42 +++++++---
 modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/DriftManager.java     |    9 ++
 2 files changed, 41 insertions(+), 10 deletions(-)

New commits:
commit 03d3afa04e574d4e08d893d611cf37d2a85ba658
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 {


commit 3e03aff1a1a2c77ea533e97dc94ccc3dcea6bc85
Author: John Sanda <jsanda at redhat.com>
Date:   Mon Jun 18 09:44:17 2012 -0400

    [BZ 786614] Add some error logging  if we cannot find a resource container
    
    We should not be in state where the method getAbsoluteBaseDirectory is
    passed a resource id that does not have a corresponding resource
    container in the local inventory. If that does happen, we will now log
    an error message that includes the resource id and drift definition to
    facilitate further debugging. Then an IllegalArgumentException is
    thrown.

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 c6f605e..9136110 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
@@ -664,6 +664,15 @@ public class DriftManager extends AgentService implements DriftAgentService, Dri
         // get the resource entity stored in our local inventory
         InventoryManager im = getInventoryManager();
         ResourceContainer container = im.getResourceContainer(resourceId);
+
+        if (container == null) {
+            log.error("Cannot determine base directory for " + driftDefinition + ". No resource container found " +
+                "for resource id " + resourceId + ". You may want to restart the agent with the -u option so that " +
+                "the agent's local inventory is synchronized with and consistent with the server's inventory.");
+            throw new IllegalArgumentException("Cannot determine base directory for " + driftDefinition +
+                ". No resource container found for resource id " + resourceId);
+        }
+
         Resource resource = container.getResource();
 
         // find out the type of base location that is specified by the drift def




More information about the rhq-commits mailing list