You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ch...@apache.org on 2013/06/17 20:18:33 UTC
[1/3] git commit: updated refs/heads/master to c88d8fb
Updated Branches:
refs/heads/master a2c7d3a8a -> c88d8fb3a
Removed String instantiation
String instantiation and redundant method call replaced with a constant.
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/ce8ada03
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/ce8ada03
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/ce8ada03
Branch: refs/heads/master
Commit: ce8ada030d3150087357d7135c3877c25a4702c2
Parents: a2c7d3a
Author: Laszlo Hornyak <la...@gmail.com>
Authored: Sat Jun 8 21:46:40 2013 +0200
Committer: Chip Childers <ch...@gmail.com>
Committed: Mon Jun 17 19:15:37 2013 +0100
----------------------------------------------------------------------
.../com/cloud/network/HAProxyConfigurator.java | 22 ++++++++------------
1 file changed, 9 insertions(+), 13 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/ce8ada03/core/src/com/cloud/network/HAProxyConfigurator.java
----------------------------------------------------------------------
diff --git a/core/src/com/cloud/network/HAProxyConfigurator.java b/core/src/com/cloud/network/HAProxyConfigurator.java
index 29fdf4a..162571f 100644
--- a/core/src/com/cloud/network/HAProxyConfigurator.java
+++ b/core/src/com/cloud/network/HAProxyConfigurator.java
@@ -33,7 +33,6 @@ import com.cloud.agent.api.to.LoadBalancerTO;
import com.cloud.agent.api.to.PortForwardingRuleTO;
import com.cloud.agent.api.to.LoadBalancerTO.DestinationTO;
import com.cloud.agent.api.to.LoadBalancerTO.StickinessPolicyTO;
-import com.cloud.agent.resource.virtualnetwork.VirtualRoutingResource;
import com.cloud.network.rules.LbStickinessMethod.StickinessMethodType;
import com.cloud.utils.net.NetUtils;
@@ -41,6 +40,7 @@ import com.cloud.utils.net.NetUtils;
public class HAProxyConfigurator implements LoadBalancerConfigurator {
private static final Logger s_logger = Logger.getLogger(HAProxyConfigurator.class);
+ private static final String blankLine = "\t ";
private static String[] globalSection = { "global",
"\tlog 127.0.0.1:3914 local0 warning",
"\tmaxconn 4096",
@@ -86,9 +86,9 @@ public class HAProxyConfigurator implements LoadBalancerConfigurator {
List<String> result = new ArrayList<String>();
result.addAll(Arrays.asList(globalSection));
- result.add(getBlankLine());
+ result.add(blankLine);
result.addAll(Arrays.asList(defaultsSection));
- result.add(getBlankLine());
+ result.add(blankLine);
if (pools.isEmpty()) {
// haproxy cannot handle empty listen / frontend or backend, so add
@@ -96,7 +96,7 @@ public class HAProxyConfigurator implements LoadBalancerConfigurator {
// on port 9
result.addAll(Arrays.asList(defaultListen));
}
- result.add(getBlankLine());
+ result.add(blankLine);
for (Map.Entry<String, List<PortForwardingRuleTO>> e : pools.entrySet()) {
List<String> poolRules = getRulesForPool(e.getKey(), e.getValue());
@@ -143,7 +143,7 @@ public class HAProxyConfigurator implements LoadBalancerConfigurator {
.append(rule.getDstPortRange()[0]).append(" check");
result.add(sb.toString());
}
- result.add(getBlankLine());
+ result.add(blankLine);
return result;
}
@@ -507,14 +507,10 @@ public class HAProxyConfigurator implements LoadBalancerConfigurator {
result.add(sb.toString());
}
- result.add(getBlankLine());
+ result.add(blankLine);
return result;
}
- private String getBlankLine() {
- return new String("\t ");
- }
-
private String generateStatsRule(LoadBalancerConfigCommand lbCmd,
String ruleName, String statsIp) {
StringBuilder rule = new StringBuilder("\nlisten ").append(ruleName)
@@ -534,7 +530,7 @@ public class HAProxyConfigurator implements LoadBalancerConfigurator {
List<String> result = new ArrayList<String>();
result.addAll(Arrays.asList(globalSection));
- result.add(getBlankLine());
+ result.add(blankLine);
result.addAll(Arrays.asList(defaultsSection));
if (!lbCmd.lbStatsVisibility.equals("disabled")) {
/* new rule : listen admin_page guestip/link-local:8081 */
@@ -568,7 +564,7 @@ public class HAProxyConfigurator implements LoadBalancerConfigurator {
}
}
- result.add(getBlankLine());
+ result.add(blankLine);
boolean has_listener = false;
for (LoadBalancerTO lbTO : lbCmd.getLoadBalancers()) {
if ( lbTO.isRevoked() ) {
@@ -578,7 +574,7 @@ public class HAProxyConfigurator implements LoadBalancerConfigurator {
result.addAll(poolRules);
has_listener = true;
}
- result.add(getBlankLine());
+ result.add(blankLine);
if ( !has_listener) {
// haproxy cannot handle empty listen / frontend or backend, so add
// a dummy listener
[2/3] git commit: updated refs/heads/master to c88d8fb
Posted by ch...@apache.org.
String instantiation is not needed
Removed a String instntiation, test case added
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/564013be
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/564013be
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/564013be
Branch: refs/heads/master
Commit: 564013bec0d4356232d93ac52a3e44638578bff0
Parents: ce8ada0
Author: Laszlo Hornyak <la...@gmail.com>
Authored: Sat Jun 8 21:39:52 2013 +0200
Committer: Chip Childers <ch...@gmail.com>
Committed: Mon Jun 17 19:17:22 2013 +0100
----------------------------------------------------------------------
utils/src/com/cloud/utils/net/NetUtils.java | 2 +-
utils/test/com/cloud/utils/net/NetUtilsTest.java | 5 +++++
2 files changed, 6 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/564013be/utils/src/com/cloud/utils/net/NetUtils.java
----------------------------------------------------------------------
diff --git a/utils/src/com/cloud/utils/net/NetUtils.java b/utils/src/com/cloud/utils/net/NetUtils.java
index 5c13454..6099379 100755
--- a/utils/src/com/cloud/utils/net/NetUtils.java
+++ b/utils/src/com/cloud/utils/net/NetUtils.java
@@ -257,7 +257,7 @@ public class NetUtils {
return ipFromInetAddress(addr);
}
- return new String("127.0.0.1");
+ return "127.0.0.1";
}
public static String ipFromInetAddress(InetAddress addr) {
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/564013be/utils/test/com/cloud/utils/net/NetUtilsTest.java
----------------------------------------------------------------------
diff --git a/utils/test/com/cloud/utils/net/NetUtilsTest.java b/utils/test/com/cloud/utils/net/NetUtilsTest.java
index 38fe21d..3cfc98f 100644
--- a/utils/test/com/cloud/utils/net/NetUtilsTest.java
+++ b/utils/test/com/cloud/utils/net/NetUtilsTest.java
@@ -168,4 +168,9 @@ public class NetUtilsTest extends TestCase {
newMac = NetUtils.generateMacOnIncrease(mac, 16);
assertTrue(newMac.equals("06:00:0f:00:45:67"));
}
+
+ @Test
+ public void testGetLocalIPString() {
+ assertNotNull(NetUtils.getLocalIPString());
+ }
}
[3/3] git commit: updated refs/heads/master to c88d8fb
Posted by ch...@apache.org.
use commons-lang StringUtils
commons-lang is already a transitive dependency of the utils project, which allows removing some duplicated functionality.
This patch replaces StringUtils.join(String, Object...) with it's commons-lang counterpart.
It also replaces calls to String join(Iterable<? extends Object>, String) in cases where an array is already exist and it is only wrapped into a List.
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/c88d8fb3
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/c88d8fb3
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/c88d8fb3
Branch: refs/heads/master
Commit: c88d8fb3a2f6c418c6c7af8ff702a93bcdb2d752
Parents: 564013b
Author: Laszlo Hornyak <la...@gmail.com>
Authored: Sun Jun 9 21:40:28 2013 +0200
Committer: Chip Childers <ch...@gmail.com>
Committed: Mon Jun 17 19:17:22 2013 +0100
----------------------------------------------------------------------
.../src/com/cloud/storage/s3/S3ManagerImpl.java | 10 +++-------
.../resource/NfsSecondaryStorageResource.java | 19 ++++++-------------
utils/src/com/cloud/utils/S3Utils.java | 4 ++--
utils/src/com/cloud/utils/StringUtils.java | 6 +-----
utils/test/com/cloud/utils/StringUtilsTest.java | 5 +++++
5 files changed, 17 insertions(+), 27 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c88d8fb3/server/src/com/cloud/storage/s3/S3ManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/storage/s3/S3ManagerImpl.java b/server/src/com/cloud/storage/s3/S3ManagerImpl.java
index 61e5573..91fa9c3 100644
--- a/server/src/com/cloud/storage/s3/S3ManagerImpl.java
+++ b/server/src/com/cloud/storage/s3/S3ManagerImpl.java
@@ -41,7 +41,6 @@ import java.util.Map;
import java.util.UUID;
import java.util.concurrent.Callable;
-import javax.annotation.PostConstruct;
import javax.ejb.Local;
import javax.inject.Inject;
import javax.naming.ConfigurationException;
@@ -193,13 +192,12 @@ public class S3ManagerImpl extends ManagerBase implements S3Manager {
}
- @SuppressWarnings("unchecked")
- private String determineLockId(final long accountId, final long templateId) {
+ static String determineLockId(final long accountId, final long templateId) {
// TBD The lock scope may be too coarse grained. Deletes need to lock
// the template across all zones where upload and download could
// probably safely scoped to the zone ...
- return join(asList("S3_TEMPLATE", accountId, templateId), "_");
+ return join("_", "S3_TEMPLATE", accountId, templateId);
}
@@ -397,9 +395,7 @@ public class S3ManagerImpl extends ManagerBase implements S3Manager {
throw new CloudRuntimeException(errMsg);
}
- final String installPath = join(
- asList("template", "tmpl", accountId,
- templateId), File.separator);
+ final String installPath = join(File.separator, "template", "tmpl", accountId, templateId);
final VMTemplateHostVO tmpltHost = new VMTemplateHostVO(
secondaryStorageHost.getId(), templateId,
now(), 100, Status.DOWNLOADED, null, null,
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c88d8fb3/services/secondary-storage/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java
----------------------------------------------------------------------
diff --git a/services/secondary-storage/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java b/services/secondary-storage/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java
index e7fa5b2..9ddba83 100755
--- a/services/secondary-storage/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java
+++ b/services/secondary-storage/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java
@@ -22,7 +22,6 @@ import static com.cloud.utils.S3Utils.putDirectory;
import static com.cloud.utils.StringUtils.join;
import static com.cloud.utils.db.GlobalLock.executeWithNoWaitLock;
import static java.lang.String.format;
-import static java.util.Arrays.asList;
import static org.apache.commons.lang.StringUtils.substringAfterLast;
import java.io.BufferedWriter;
@@ -217,19 +216,16 @@ SecondaryStorageResource {
}
}
- @SuppressWarnings("unchecked")
- private String determineS3TemplateDirectory(final Long accountId,
+ static String determineS3TemplateDirectory(final Long accountId,
final Long templateId) {
- return join(asList(TEMPLATE_ROOT_DIR, accountId, templateId),
- S3Utils.SEPARATOR);
+ return join(S3Utils.SEPARATOR, TEMPLATE_ROOT_DIR, accountId, templateId);
}
- @SuppressWarnings("unchecked")
private String determineStorageTemplatePath(final String storagePath,
final Long accountId, final Long templateId) {
- return join(
- asList(getRootDir(storagePath), TEMPLATE_ROOT_DIR, accountId,
- templateId), File.separator);
+ return join(File.separator,
+ getRootDir(storagePath), TEMPLATE_ROOT_DIR, accountId,
+ templateId);
}
private Answer execute(
@@ -405,10 +401,7 @@ SecondaryStorageResource {
s_logger.debug(String
.format("Determining key using account id %1$s and template id %2$s",
accountId, templateId));
- return join(
- asList(determineS3TemplateDirectory(
- accountId, templateId), file
- .getName()), S3Utils.SEPARATOR);
+ return join(S3Utils.SEPARATOR, determineS3TemplateDirectory(accountId, templateId), file.getName());
}
});
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c88d8fb3/utils/src/com/cloud/utils/S3Utils.java
----------------------------------------------------------------------
diff --git a/utils/src/com/cloud/utils/S3Utils.java b/utils/src/com/cloud/utils/S3Utils.java
index b7273a1..33a3ebd 100644
--- a/utils/src/com/cloud/utils/S3Utils.java
+++ b/utils/src/com/cloud/utils/S3Utils.java
@@ -155,8 +155,8 @@ public final class S3Utils {
try {
tempFile = createTempFile(
- join(asList(targetDirectory.getName(), currentTimeMillis(),
- "part"), "-"), "tmp", targetDirectory);
+ join("-", targetDirectory.getName(), currentTimeMillis(),
+ "part"), "tmp", targetDirectory);
tempFile.deleteOnExit();
if (LOGGER.isDebugEnabled()) {
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c88d8fb3/utils/src/com/cloud/utils/StringUtils.java
----------------------------------------------------------------------
diff --git a/utils/src/com/cloud/utils/StringUtils.java b/utils/src/com/cloud/utils/StringUtils.java
index 14ff4b1..359b169 100644
--- a/utils/src/com/cloud/utils/StringUtils.java
+++ b/utils/src/com/cloud/utils/StringUtils.java
@@ -16,8 +16,6 @@
// under the License.
package com.cloud.utils;
-import static java.util.Arrays.asList;
-
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
@@ -25,8 +23,6 @@ import java.util.regex.Pattern;
import org.owasp.esapi.StringUtilities;
-// StringUtils exists in Apache Commons Lang, but rather than import the entire JAR to our system, for now
-// just implement the method needed
public class StringUtils {
private static final char[] hexChar = {
'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'
@@ -50,7 +46,7 @@ public class StringUtils {
public static String join(final String delimiter,
final Object... components) {
- return join(asList(components), delimiter);
+ return org.apache.commons.lang.StringUtils.join(components, delimiter);
}
/**
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c88d8fb3/utils/test/com/cloud/utils/StringUtilsTest.java
----------------------------------------------------------------------
diff --git a/utils/test/com/cloud/utils/StringUtilsTest.java b/utils/test/com/cloud/utils/StringUtilsTest.java
index 3c162c7..796efba 100644
--- a/utils/test/com/cloud/utils/StringUtilsTest.java
+++ b/utils/test/com/cloud/utils/StringUtilsTest.java
@@ -103,4 +103,9 @@ public class StringUtilsTest {
assertEquals(result, expected);
}
+ @Test
+ public void testJoin() {
+ assertEquals("a-b-c", StringUtils.join("-", "a", "b", "c"));
+ assertEquals("", StringUtils.join("-"));
+ }
}