Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
WHIRR-114. Support + character in version number.
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/incubator/whirr/trunk@1027637 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
tomwhite committed Oct 26, 2010
1 parent b543c0c commit 5803de8
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGES.txt
Expand Up @@ -52,6 +52,8 @@ Trunk (unreleased changes)
WHIRR-113. Hadoop cluster instances should all start in the same location.
(tomwhite)

WHIRR-114. Support + character in version number. (tomwhite)

Release 0.1.0 - 2010-09-02

INCOMPATIBLE CHANGES
Expand Down
28 changes: 25 additions & 3 deletions core/src/main/java/org/apache/whirr/service/ClusterSpec.java
Expand Up @@ -30,6 +30,8 @@

import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.List;
import java.util.Set;

Expand Down Expand Up @@ -58,6 +60,7 @@ public enum Property {
HARDWARE_ID(String.class, false),
LOCATION_ID(String.class, false),
CLIENT_CIDRS(String.class, true),
VERSION(String.class, false),
RUN_URL_BASE(String.class, false);

private Class<?> type;
Expand Down Expand Up @@ -154,6 +157,7 @@ public static List<InstanceTemplate> parse(String... strings) {
private String hardwareId;
private String locationId;
private List<String> clientCidrs;
private String version;
private String runUrlBase;

private Configuration config;
Expand Down Expand Up @@ -196,7 +200,17 @@ public ClusterSpec(Configuration config)
setHardwareId(config.getString(Property.HARDWARE_ID.getConfigName()));
setLocationId(config.getString(Property.LOCATION_ID.getConfigName()));
setClientCidrs(c.getList(Property.CLIENT_CIDRS.getConfigName()));
setRunUrlBase(c.getString(Property.RUN_URL_BASE.getConfigName()));
setVersion(c.getString(Property.VERSION.getConfigName()));
String runUrlBase = c.getString(Property.RUN_URL_BASE.getConfigName());
if (runUrlBase == null) {
try {
runUrlBase = String.format("http://whirr.s3.amazonaws.com/%s/",
URLEncoder.encode(getVersion(), "UTF-8"));
} catch (UnsupportedEncodingException e) {
throw new ConfigurationException(e);
}
}
setRunUrlBase(runUrlBase);
this.config = c;
}

Expand Down Expand Up @@ -264,7 +278,9 @@ public String getLocationId() {
public List<String> getClientCidrs() {
return clientCidrs;
}

public String getVersion() {
return version;
}
public String getRunUrlBase() {
return runUrlBase;
}
Expand Down Expand Up @@ -354,6 +370,10 @@ public void setLocationId(String locationId) {
public void setClientCidrs(List<String> clientCidrs) {
this.clientCidrs = clientCidrs;
}

public void setVersion(String version) {
this.version = version;
}

public void setRunUrlBase(String runUrlBase) {
this.runUrlBase = runUrlBase;
Expand All @@ -378,6 +398,7 @@ public boolean equals(Object o) {
&& Objects.equal(hardwareId, that.hardwareId)
&& Objects.equal(locationId, that.locationId)
&& Objects.equal(clientCidrs, that.clientCidrs)
&& Objects.equal(version, that.version)
&& Objects.equal(runUrlBase, that.runUrlBase)
;
}
Expand All @@ -387,7 +408,7 @@ public boolean equals(Object o) {
public int hashCode() {
return Objects.hashCode(instanceTemplates, serviceName,
provider, identity, credential, clusterName, publicKey,
privateKey, imageId, hardwareId, locationId, clientCidrs,
privateKey, imageId, hardwareId, locationId, clientCidrs, version,
runUrlBase);
}

Expand All @@ -405,6 +426,7 @@ public String toString() {
.add("instanceSizeId", hardwareId)
.add("locationId", locationId)
.add("clientCidrs", clientCidrs)
.add("version", version)
.add("runUrlBase", runUrlBase)
.toString();
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/resources/whirr-default.properties
Expand Up @@ -12,4 +12,4 @@

whirr.private-key-file=${sys:user.home}/.ssh/id_rsa
whirr.public-key-file=${sys:user.home}/.ssh/id_rsa.pub
whirr.run-url-base=http://whirr.s3.amazonaws.com/${version}/
whirr.version=${version}
13 changes: 11 additions & 2 deletions core/src/test/java/org/apache/whirr/service/ClusterSpecTest.java
Expand Up @@ -18,6 +18,7 @@

package org.apache.whirr.service;

import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.startsWith;
import static org.junit.Assert.assertThat;

Expand All @@ -41,8 +42,16 @@ public void testDefaultsCanBeOverridden() throws ConfigurationException {
conf.setProperty(ClusterSpec.Property.RUN_URL_BASE.getConfigName(),
"http://example.org");
ClusterSpec spec = new ClusterSpec(conf);
assertThat(spec.getRunUrlBase(),
startsWith("http://example.org"));
assertThat(spec.getRunUrlBase(), is("http://example.org"));
}

@Test
public void testVersionInRunUrlbaseIsUrlEncoded()
throws ConfigurationException {
Configuration conf = new PropertiesConfiguration();
conf.setProperty(ClusterSpec.Property.VERSION.getConfigName(), "0.1.0+1");
ClusterSpec spec = new ClusterSpec(conf);
assertThat(spec.getRunUrlBase(),
is("http://whirr.s3.amazonaws.com/0.1.0%2B1/"));
}
}

0 comments on commit 5803de8

Please sign in to comment.