cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From frankzh...@apache.org
Subject git commit: updated refs/heads/4.2 to 3dc8d2f
Date Tue, 13 Aug 2013 00:56:31 GMT
Updated Branches:
  refs/heads/4.2 63b37214c -> 3dc8d2f94


Revert "ProcessUtil cleanup"

This reverts commit e821ed073acd4f93b9344d2b2f2197e6458a6304.

it's not a 4.2 blocker or critical


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/3dc8d2f9
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/3dc8d2f9
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/3dc8d2f9

Branch: refs/heads/4.2
Commit: 3dc8d2f94a61bdb83680a8c97d23623b34d3146e
Parents: 63b3721
Author: frank <frank.zhang@citrix.com>
Authored: Mon Aug 12 18:05:51 2013 -0700
Committer: frank <frank.zhang@citrix.com>
Committed: Mon Aug 12 18:05:51 2013 -0700

----------------------------------------------------------------------
 utils/src/com/cloud/utils/ProcessUtil.java      | 20 ++++---
 utils/test/com/cloud/utils/ProcessUtilTest.java | 57 --------------------
 2 files changed, 14 insertions(+), 63 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3dc8d2f9/utils/src/com/cloud/utils/ProcessUtil.java
----------------------------------------------------------------------
diff --git a/utils/src/com/cloud/utils/ProcessUtil.java b/utils/src/com/cloud/utils/ProcessUtil.java
index 7f16f98..c9fdf35 100644
--- a/utils/src/com/cloud/utils/ProcessUtil.java
+++ b/utils/src/com/cloud/utils/ProcessUtil.java
@@ -16,20 +16,24 @@
 // under the License.
 package com.cloud.utils;
 
+import java.io.BufferedReader;
 import java.io.File;
 import java.io.FileInputStream;
+import java.io.FileOutputStream;
 import java.io.IOException;
-import java.util.Properties;
+import java.io.InputStreamReader;
 
 import javax.naming.ConfigurationException;
 
-import org.apache.commons.io.FileUtils;
 import org.apache.log4j.Logger;
 
+import com.cloud.utils.PropertiesUtil;
 import com.cloud.utils.exception.CloudRuntimeException;
 import com.cloud.utils.script.OutputInterpreter;
 import com.cloud.utils.script.Script;
 
+import java.util.Properties;
+
 public class ProcessUtil {
     private static final Logger s_logger = Logger.getLogger(ProcessUtil.class.getName());
 
@@ -63,9 +67,11 @@ public class ProcessUtil {
 	            if (!pidFile.exists()) {
 	                throw new ConfigurationException("Unable to write to " + pidFile.getAbsolutePath()
+ ".  Are you sure you're running as root?");
 	            }
-
-	            final String pidLine = FileUtils.readFileToString(pidFile).trim();
-	            if (pidLine.isEmpty()) {
+	
+	            final FileInputStream is = new FileInputStream(pidFile);
+	            final BufferedReader reader = new BufferedReader(new InputStreamReader(is));
+	            final String pidLine = reader.readLine();
+	            if (pidLine == null) {
 	                throw new ConfigurationException("Java process is being started twice. 
If this is not true, remove " + pidFile.getAbsolutePath());
 	            }
 	            try {
@@ -95,7 +101,9 @@ public class ProcessUtil {
 	
 	        final String pid = parser.getLine();
 	
-	        FileUtils.writeStringToFile(pidFile, pid + "\n");
+	        final FileOutputStream strm = new FileOutputStream(pidFile);
+	        strm.write((pid + "\n").getBytes());
+	        strm.close();
 	    } catch (final IOException e) {
 	        throw new CloudRuntimeException("Unable to create the " + pidFile.getAbsolutePath()
+ ".  Are you running as root?", e);
 	    }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3dc8d2f9/utils/test/com/cloud/utils/ProcessUtilTest.java
----------------------------------------------------------------------
diff --git a/utils/test/com/cloud/utils/ProcessUtilTest.java b/utils/test/com/cloud/utils/ProcessUtilTest.java
deleted file mode 100644
index 266ae1a..0000000
--- a/utils/test/com/cloud/utils/ProcessUtilTest.java
+++ /dev/null
@@ -1,57 +0,0 @@
-package com.cloud.utils;
-
-import java.io.File;
-import java.io.IOException;
-
-import javax.naming.ConfigurationException;
-
-import junit.framework.Assert;
-
-import org.apache.commons.io.FileUtils;
-import org.apache.commons.lang.SystemUtils;
-import org.junit.After;
-import org.junit.Assume;
-import org.junit.Before;
-import org.junit.Test;
-
-public class ProcessUtilTest {
-
-    File pidFile;
-
-    @Before
-    public void setup() throws IOException {
-        pidFile = File.createTempFile("test", ".pid");
-    }
-
-    @After
-    public void cleanup() {
-        FileUtils.deleteQuietly(pidFile);
-    }
-
-    @Test
-    public void pidCheck() throws ConfigurationException, IOException {
-        Assume.assumeTrue(SystemUtils.IS_OS_LINUX);
-        FileUtils.writeStringToFile(pidFile, "123456\n");
-        ProcessUtil.pidCheck(pidFile.getParent(), pidFile.getName());
-        String pidStr = FileUtils.readFileToString(pidFile);
-        Assert.assertFalse("pid can not be blank", pidStr.isEmpty());
-        int pid = Integer.parseInt(pidStr.trim());
-        int maxPid = Integer.parseInt(FileUtils.readFileToString(new File("/proc/sys/kernel/pid_max")).trim());
-        Assert.assertTrue(pid <= maxPid);
-    }
-
-    @Test(expected = ConfigurationException.class)
-    public void pidCheckBadPid() throws ConfigurationException, IOException {
-        Assume.assumeTrue(SystemUtils.IS_OS_LINUX);
-        FileUtils.writeStringToFile(pidFile, "intentionally not number");
-        ProcessUtil.pidCheck(pidFile.getParent(), pidFile.getName());
-    }
-
-    @Test(expected = ConfigurationException.class)
-    public void pidCheckEmptyPid() throws ConfigurationException, IOException {
-        Assume.assumeTrue(SystemUtils.IS_OS_LINUX);
-        FileUtils.writeStringToFile(pidFile, "intentionally not number");
-        ProcessUtil.pidCheck(pidFile.getParent(), pidFile.getName());
-    }
-
-}


Mime
View raw message