You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ko...@apache.org on 2013/10/23 20:50:55 UTC

[1/2] git commit: updated refs/heads/master to 4b530c8

Updated Branches:
  refs/heads/master 7edb4d377 -> 4b530c874


Safe properties loader

- new utility method introduced in PropertiesUtil to load properties objects from files
- RegionManagerImpl modified to use the utility method
- Tests added for both

Signed-off-by: Laszlo Hornyak <la...@gmail.com>


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

Branch: refs/heads/master
Commit: 4b530c874f40242075b870bd49ecfc8994e74276
Parents: b4e972d
Author: Laszlo Hornyak <la...@gmail.com>
Authored: Wed Oct 23 20:26:19 2013 +0200
Committer: Laszlo Hornyak <la...@gmail.com>
Committed: Wed Oct 23 20:50:00 2013 +0200

----------------------------------------------------------------------
 .../cloudstack/region/RegionManagerImpl.java    |  2 +-
 .../cloudstack/region/RegionManagerTest.java    | 29 ++++++--------
 utils/src/com/cloud/utils/PropertiesUtil.java   | 16 ++++++++
 .../com/cloud/utils/PropertiesUtilsTest.java    | 41 ++++++++++++++++++++
 4 files changed, 69 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4b530c87/server/src/org/apache/cloudstack/region/RegionManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/org/apache/cloudstack/region/RegionManagerImpl.java b/server/src/org/apache/cloudstack/region/RegionManagerImpl.java
index 046779f..40ac46c 100755
--- a/server/src/org/apache/cloudstack/region/RegionManagerImpl.java
+++ b/server/src/org/apache/cloudstack/region/RegionManagerImpl.java
@@ -80,7 +80,7 @@ public class RegionManagerImpl extends ManagerBase implements RegionManager, Man
             dbProps = new Properties();
         }
         try {
-            dbProps.load(new FileInputStream(dbPropsFile));
+            PropertiesUtil.loadFromFile(dbProps, dbPropsFile);
         } catch (IOException e) {
             s_logger.fatal("Unable to load db properties file, pl. check the classpath and file path configuration", e);
             return false;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4b530c87/server/test/org/apache/cloudstack/region/RegionManagerTest.java
----------------------------------------------------------------------
diff --git a/server/test/org/apache/cloudstack/region/RegionManagerTest.java b/server/test/org/apache/cloudstack/region/RegionManagerTest.java
index db6bf20..d1d6de4 100644
--- a/server/test/org/apache/cloudstack/region/RegionManagerTest.java
+++ b/server/test/org/apache/cloudstack/region/RegionManagerTest.java
@@ -18,33 +18,20 @@
 package org.apache.cloudstack.region;
 
 
+import java.util.HashMap;
+
+import javax.naming.ConfigurationException;
+
 import junit.framework.Assert;
-import junit.framework.TestCase;
 
-import org.apache.cloudstack.api.command.admin.domain.DeleteDomainCmd;
-import org.apache.cloudstack.context.CallContext;
 import org.apache.cloudstack.region.dao.RegionDao;
-
-import org.apache.log4j.Logger;
-import org.junit.Before;
 import org.junit.Test;
 import org.mockito.Mockito;
 
 import com.cloud.exception.InvalidParameterValueException;
-import com.cloud.user.Account;
-import com.cloud.user.dao.AccountDao;
-
-
 
-public class RegionManagerTest extends TestCase {
-    private static final Logger s_logger = Logger.getLogger(RegionManagerTest.class);
+public class RegionManagerTest {
 
-    @Before
-    @Override
-    protected void setUp() {
-
-    }
-    
     @Test
     public void testUniqueName() {
     	RegionManagerImpl regionMgr = new RegionManagerImpl();
@@ -59,4 +46,10 @@ public class RegionManagerTest extends TestCase {
     	}
     }
 
+    @Test
+    public void configure() throws ConfigurationException {
+        RegionManagerImpl regionManager = new RegionManagerImpl();
+        regionManager.configure("foo", new HashMap<String, Object>());
+        Assert.assertTrue(regionManager.getId() != 0);
+    }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4b530c87/utils/src/com/cloud/utils/PropertiesUtil.java
----------------------------------------------------------------------
diff --git a/utils/src/com/cloud/utils/PropertiesUtil.java b/utils/src/com/cloud/utils/PropertiesUtil.java
index e256fce..6db66ff 100755
--- a/utils/src/com/cloud/utils/PropertiesUtil.java
+++ b/utils/src/com/cloud/utils/PropertiesUtil.java
@@ -27,6 +27,7 @@ import java.util.Map;
 import java.util.Properties;
 import java.util.Set;
 
+import org.apache.commons.io.IOUtils;
 import org.apache.log4j.Logger;
 
 public class PropertiesUtil {
@@ -156,4 +157,19 @@ public class PropertiesUtil {
         }
         return configMap;
     }
+
+    /**
+     * Load a Properties object with contents from a File.
+     * @param properties the properties object to be loaded
+     * @param file  the file to load from
+     * @throws IOException 
+     */
+    public static void loadFromFile(Properties properties, File file) throws IOException {
+        InputStream stream = new FileInputStream(file);
+        try {
+            properties.load(stream);
+        } finally {
+            IOUtils.closeQuietly(stream);
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4b530c87/utils/test/com/cloud/utils/PropertiesUtilsTest.java
----------------------------------------------------------------------
diff --git a/utils/test/com/cloud/utils/PropertiesUtilsTest.java b/utils/test/com/cloud/utils/PropertiesUtilsTest.java
new file mode 100644
index 0000000..5ebe095
--- /dev/null
+++ b/utils/test/com/cloud/utils/PropertiesUtilsTest.java
@@ -0,0 +1,41 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package com.cloud.utils;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Properties;
+
+import org.apache.commons.io.FileUtils;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class PropertiesUtilsTest {
+    @Test
+    public void findConfigFile() {
+        File configFile = PropertiesUtil.findConfigFile("notexistingresource");
+        Assert.assertNull(configFile);
+    }
+    @Test
+    public void loadFromFile() throws IOException {
+        File file = File.createTempFile("test", ".properties");
+        FileUtils.writeStringToFile(file, "a=b\nc=d\n");
+        Properties properties = new Properties();
+        PropertiesUtil.loadFromFile(properties, file);
+        Assert.assertEquals("b", properties.get("a"));
+    }
+}


[2/2] git commit: updated refs/heads/master to 4b530c8

Posted by ko...@apache.org.
Integer instantation removed

Two Integer object was created for each comparison, just in order to compare the two values.
This is replaced with Integer.compare()

Signed-off-by: Laszlo Hornyak <la...@gmail.com>


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

Branch: refs/heads/master
Commit: b4e972da035e1de36c154da396c06de11960501a
Parents: 7edb4d3
Author: Laszlo Hornyak <la...@gmail.com>
Authored: Wed Oct 23 19:33:48 2013 +0200
Committer: Laszlo Hornyak <la...@gmail.com>
Committed: Wed Oct 23 20:50:00 2013 +0200

----------------------------------------------------------------------
 .../engine/subsystem/api/storage/StrategyPriority.java         | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b4e972da/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/StrategyPriority.java
----------------------------------------------------------------------
diff --git a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/StrategyPriority.java b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/StrategyPriority.java
index 81034b1..e930d10 100644
--- a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/StrategyPriority.java
+++ b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/StrategyPriority.java
@@ -57,7 +57,7 @@ public class StrategyPriority {
         public int compare(SnapshotStrategy o1, SnapshotStrategy o2) {
             int i1 = o1.canHandle(snapshot).ordinal();
             int i2 = o2.canHandle(snapshot).ordinal();
-            return new Integer(i2).compareTo(new Integer(i1));
+            return Integer.compare(i2, i1);
         }
     }
 
@@ -74,7 +74,7 @@ public class StrategyPriority {
         public int compare(DataMotionStrategy o1, DataMotionStrategy o2) {
             int i1 = o1.canHandle(srcData, destData).ordinal();
             int i2 = o2.canHandle(srcData, destData).ordinal();
-            return new Integer(i2).compareTo(new Integer(i1));
+            return Integer.compare(i2, i1);
         }
     }
 
@@ -93,7 +93,7 @@ public class StrategyPriority {
         public int compare(DataMotionStrategy o1, DataMotionStrategy o2) {
             int i1 = o1.canHandle(volumeMap, srcHost, destHost).ordinal();
             int i2 = o2.canHandle(volumeMap, srcHost, destHost).ordinal();
-            return new Integer(i2).compareTo(new Integer(i1));
+            return Integer.compare(i2, i1);
         }
     }
 }