Alon Bar-Lev has uploaded a new change for review. Change subject: host-deploy: remove usage commons-logging ......................................................................
host-deploy: remove usage commons-logging Change-Id: I0391bd92ecfbbc6289a10ac6d8fa6afde94ac1de Signed-off-by: Alon Bar-Lev <alo...@redhat.com> --- M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/utils/EngineSSHClient.java M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/utils/EngineSSHDialog.java M backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/archivers/tar/CachedTar.java M backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/archivers/tar/Tar.java 4 files changed, 20 insertions(+), 84 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/86/34086/1 diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/utils/EngineSSHClient.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/utils/EngineSSHClient.java index efd60b4..0e1b20d 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/utils/EngineSSHClient.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/utils/EngineSSHClient.java @@ -5,9 +5,6 @@ import java.security.KeyPair; import java.security.KeyStore; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - import org.ovirt.engine.core.common.businessentities.VDS; import org.ovirt.engine.core.common.config.Config; import org.ovirt.engine.core.common.config.ConfigValues; @@ -22,7 +19,6 @@ */ public class EngineSSHClient extends SSHClient { - private static final Log log = LogFactory.getLog(EngineSSHDialog.class); private VDS _vds; /** diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/utils/EngineSSHDialog.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/utils/EngineSSHDialog.java index 1de57bd..c0bb1ed 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/utils/EngineSSHDialog.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/utils/EngineSSHDialog.java @@ -5,8 +5,6 @@ import java.security.KeyPair; import java.security.KeyStore; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.ovirt.engine.core.common.businessentities.VDS; import org.ovirt.engine.core.utils.crypt.EngineEncryptionUtils; import org.ovirt.engine.core.uutils.ssh.SSHClient; @@ -17,7 +15,6 @@ */ public class EngineSSHDialog extends SSHDialog { - private static final Log log = LogFactory.getLog(EngineSSHDialog.class); VDS _vds; protected SSHClient _getSSHClient() { diff --git a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/archivers/tar/CachedTar.java b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/archivers/tar/CachedTar.java index 2d53a4f..5a90d65 100644 --- a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/archivers/tar/CachedTar.java +++ b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/archivers/tar/CachedTar.java @@ -5,8 +5,9 @@ import java.io.IOException; import java.io.OutputStream; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import org.ovirt.engine.core.common.config.Config; import org.ovirt.engine.core.common.config.ConfigValues; @@ -18,7 +19,7 @@ */ public class CachedTar { - private static final Log log = LogFactory.getLog(CachedTar.class); + private static final Logger log = LoggerFactory.getLogger(CachedTar.class); private long refreshInterval = 10000; private long nextCheckTime = 0; @@ -27,36 +28,20 @@ private File dir; private void create(long timestamp) throws IOException { - File temp = null; - OutputStream os = null; - try { - // must create within same directory - // so rename be atomic - temp = File.createTempFile( - this.archive.getName(), - "tmp", - this.archive.getParentFile() - ); - os = new FileOutputStream(temp); + // must create within same directory + // so rename be atomic + File temp = File.createTempFile( + this.archive.getName(), + "tmp", + this.archive.getParentFile() + ); + try (OutputStream os = new FileOutputStream(temp)) { Tar.doTar(os, this.dir); } catch(IOException e) { String message = String.format("Cannot create tarball '%1$s'", this.archive); log.error(message, e); throw new IOException(message, e); - } - finally { - try { - if (os != null) { - os.close(); - } - } - catch(IOException e) { - log.error( - String.format("Cannot close '%1$s'", temp), - e - ); - } } try { @@ -83,12 +68,12 @@ temp = null; } catch(IOException e) { - log.error(e); + log.error("Exception", e); throw e; } finally { if (temp != null && !temp.delete()) { - log.error(String.format("Cannot delete '%1$s'", temp.getAbsolutePath())); + log.error("Cannot delete '{}'", temp.getAbsolutePath()); } } } @@ -96,10 +81,8 @@ private void ensure() throws IOException { if (!this.archive.exists()) { log.info( - String.format( - "Tarball '%1$s' is missing, creating", - this.archive.getAbsolutePath() - ) + "Tarball '{}' is missing, creating", + this.archive.getAbsolutePath() ); this.nextCheckTime = System.currentTimeMillis() + this.refreshInterval; create(getTimestampRecursive(this.dir)); @@ -110,10 +93,8 @@ long treeTimestamp = getTimestampRecursive(this.dir); if (archive.lastModified() != treeTimestamp) { log.info( - String.format( - "Tarball '%1$s' is out of date, re-creating", - this.archive.getAbsolutePath() - ) + "Tarball '{}' is out of date, re-creating", + this.archive.getAbsolutePath() ); create(treeTimestamp); } diff --git a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/archivers/tar/Tar.java b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/archivers/tar/Tar.java index 86adfcb..d370183 100644 --- a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/archivers/tar/Tar.java +++ b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/archivers/tar/Tar.java @@ -8,9 +8,6 @@ import java.io.InputStream; import java.io.OutputStream; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - import org.apache.commons.compress.archivers.tar.TarArchiveEntry; import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream; @@ -18,8 +15,6 @@ * A simple recursive tar based on javatar. */ public class Tar { - - private static final Log log = LogFactory.getLog(Tar.class); private static void _recurse( TarArchiveOutputStream archive, @@ -51,29 +46,11 @@ entry.setMode(0600); } archive.putArchiveEntry(entry); - InputStream is = null; - try { - is = new FileInputStream(entry.getFile()); + try (InputStream is = new FileInputStream(entry.getFile())) { byte buffer[] = new byte[8192]; int n; while ((n = is.read(buffer)) != -1) { archive.write(buffer, 0, n); - } - } - finally { - if (is != null) { - try { - is.close(); - } - catch(IOException e) { - log.error( - String.format( - "Cannot close file '%1$s'", - entry.getFile().getAbsolutePath() - ), - e - ); - } } } archive.closeArchiveEntry(); @@ -102,25 +79,10 @@ ); } - TarArchiveOutputStream archive = null; - try { - archive = new TarArchiveOutputStream(os); + try (TarArchiveOutputStream archive = new TarArchiveOutputStream(os)) { // TODO: use LONGFILE_POSIX in newer version of commons-compress archive.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU); _recurse(archive, base, "./"); - } - finally { - if (archive != null) { - try { - archive.close(); - } - catch(IOException e) { - log.error( - String.format("Cannot close tar stream"), - e - ); - } - } } } -- To view, visit http://gerrit.ovirt.org/34086 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I0391bd92ecfbbc6289a10ac6d8fa6afde94ac1de Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Alon Bar-Lev <alo...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches