Skip to content

Commit

Permalink
WHIRR-52. Support all services on Rackspace Cloud Servers.
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/incubator/whirr/trunk@1028038 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
tomwhite committed Oct 27, 2010
1 parent c7b5b98 commit 59df44e
Show file tree
Hide file tree
Showing 15 changed files with 159 additions and 31 deletions.
2 changes: 2 additions & 0 deletions CHANGES.txt
Expand Up @@ -28,6 +28,8 @@ Trunk (unreleased changes)

WHIRR-112. Expand documentation. (tomwhite)

WHIRR-52. Support all services on Rackspace Cloud Servers. (tomwhite)

BUG FIXES

WHIRR-93. Fail on checkstyle violation. (tomwhite)
Expand Down
2 changes: 1 addition & 1 deletion cli/pom.xml
Expand Up @@ -51,7 +51,7 @@
</dependency>
<dependency>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-aws</artifactId>
<artifactId>jclouds-allcompute</artifactId>
</dependency>
<dependency>
<groupId>org.jclouds</groupId>
Expand Down
2 changes: 1 addition & 1 deletion core/pom.xml
Expand Up @@ -31,7 +31,7 @@
<dependencies>
<dependency>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-aws</artifactId>
<artifactId>jclouds-allcompute</artifactId>
</dependency>
<dependency>
<groupId>org.jclouds</groupId>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -52,7 +52,7 @@
<dependencies>
<dependency>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-aws</artifactId>
<artifactId>jclouds-allcompute</artifactId>
<version>${jclouds.version}</version>
</dependency>
<dependency>
Expand Down
29 changes: 26 additions & 3 deletions scripts/apache/cassandra/post-configure
Expand Up @@ -21,7 +21,30 @@
set -x
set -e

SELF_HOST=`/sbin/ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}'`
CLOUD_PROVIDER=
while getopts "c:" OPTION; do
case $OPTION in
c)
CLOUD_PROVIDER="$OPTARG"
shift $((OPTIND-1)); OPTIND=1
;;
esac
done

case $CLOUD_PROVIDER in
# We want the gossip protocol to use internal (private) addresses, and the
# client to use public addresses.
# See http://wiki.apache.org/cassandra/FAQ#cant_listen_on_ip_any
ec2)
PRIVATE_SELF_HOST=`wget -q -O - http://169.254.169.254/latest/meta-data/local-ipv4`
# EC2 is NATed
PUBLIC_SELF_HOST=$PRIVATE_SELF_HOST
;;
*)
PUBLIC_SELF_HOST=`/sbin/ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}'`
PRIVATE_SELF_HOST=`/sbin/ifconfig eth1 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}'`
;;
esac

config_file=/etc/cassandra/conf/storage-conf.xml

Expand All @@ -33,8 +56,8 @@ done

#TODO set replication
sed -i -e "s|<Seed>127.0.0.1</Seed>|$seeds|" $config_file
sed -i -e "s|<ListenAddress>localhost</ListenAddress>|<ListenAddress>$SELF_HOST</ListenAddress>|" $config_file
sed -i -e "s|<ThriftAddress>localhost</ThriftAddress>|<ThriftAddress>$SELF_HOST</ThriftAddress>|" $config_file
sed -i -e "s|<ListenAddress>localhost</ListenAddress>|<ListenAddress>$PRIVATE_SELF_HOST</ListenAddress>|" $config_file
sed -i -e "s|<ThriftAddress>localhost</ThriftAddress>|<ThriftAddress>$PUBLIC_SELF_HOST</ThriftAddress>|" $config_file

# Now that it's configured, start Cassandra
nohup /etc/rc.local &
23 changes: 21 additions & 2 deletions scripts/apache/zookeeper/post-configure
Expand Up @@ -18,12 +18,31 @@
# Configure Apache ZooKeeper after the ensemble has started.
#
# Call with arguments listing all the servers in the ensemble:
# post-configure <server-ip>*
# post-configure -c <cloud-provider> <server-ip>*

set -x
set -e

SELF_HOST=`/sbin/ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}'`
CLOUD_PROVIDER=
while getopts "c:" OPTION; do
case $OPTION in
c)
CLOUD_PROVIDER="$OPTARG"
shift $((OPTIND-1)); OPTIND=1
;;
esac
done

case $CLOUD_PROVIDER in
# Use private IP for SELF_HOST
# ZooKeeper listens on all addresses, not just the one specified in server.<id>
ec2)
SELF_HOST=`wget -q -O - http://169.254.169.254/latest/meta-data/local-ipv4`
;;
*)
SELF_HOST=`/sbin/ifconfig eth1 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}'`
;;
esac

myid_file=/var/log/zookeeper/txlog/myid
config_file=/etc/zookeeper/conf/zoo.cfg
Expand Down
48 changes: 48 additions & 0 deletions scripts/util/configure-hostnames
@@ -0,0 +1,48 @@
#!/usr/bin/env bash
#
# 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.
#

# Ensure that hostnames resolve correctly.

set -x
set -e

CLOUD_PROVIDER=
while getopts "c:" OPTION; do
case $OPTION in
c)
CLOUD_PROVIDER="$OPTARG"
shift $((OPTIND-1)); OPTIND=1
;;
esac
done

case $CLOUD_PROVIDER in
cloudservers)
if which dpkg &> /dev/null; then
PRIVATE_IP=`/sbin/ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}'`
HOSTNAME=`echo $PRIVATE_IP | tr . -`.static.cloud-ips.com
echo $HOSTNAME > /etc/hostname
sed -i -e "s/$PRIVATE_IP.*/$PRIVATE_IP $HOSTNAME/" /etc/hosts
set +e
/etc/init.d/hostname restart
set -e
sleep 2
hostname
fi
;;
esac
2 changes: 1 addition & 1 deletion services/cassandra/pom.xml
Expand Up @@ -43,7 +43,7 @@
</dependency>
<dependency>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-aws</artifactId>
<artifactId>jclouds-allcompute</artifactId>
</dependency>
<dependency>
<groupId>org.jclouds</groupId>
Expand Down
Expand Up @@ -54,7 +54,9 @@
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.Template;
import org.jclouds.compute.domain.TemplateBuilder;
import org.jclouds.compute.options.RunScriptOptions;
import org.jclouds.compute.predicates.NodePredicates;
import org.jclouds.domain.Credentials;
import org.jclouds.io.Payload;
import org.jclouds.ssh.ExecResponse;
import org.slf4j.Logger;
Expand Down Expand Up @@ -121,14 +123,21 @@ public Cluster launchCluster(ClusterSpec clusterSpec) throws IOException {
// Pass list of all servers in cluster to configure script.
String servers = Joiner.on(' ').join(getPrivateIps(seeds));
Payload configureScript = newStringPayload(runUrls(clusterSpec.getRunUrlBase(),
"apache/cassandra/post-configure " + servers));
String.format("apache/cassandra/post-configure -c %s %s",
clusterSpec.getProvider(),
servers)));
// Use private key to run script
Credentials credentials = new Credentials(
Iterables.get(nodes, 0).getCredentials().identity,
clusterSpec.readPrivateKey());

try {
LOG.info("Running configuration script");
Map<? extends NodeMetadata, ExecResponse> responses = computeService
.runScriptOnNodesMatching(
NodePredicates.runningWithTag(clusterSpec.getClusterName()),
configureScript);
configureScript,
RunScriptOptions.Builder.overrideCredentialsWith(credentials));
assert responses.size() > 0 : "no nodes matched "
+ clusterSpec.getClusterName();
} catch (RunScriptOnNodesException e) {
Expand Down
2 changes: 1 addition & 1 deletion services/hadoop/pom.xml
Expand Up @@ -43,7 +43,7 @@
</dependency>
<dependency>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-aws</artifactId>
<artifactId>jclouds-allcompute</artifactId>
</dependency>
<dependency>
<groupId>org.jclouds</groupId>
Expand Down
Expand Up @@ -90,6 +90,7 @@ public HadoopCluster launchCluster(ClusterSpec clusterSpec) throws IOException {
String hadoopInstallRunUrl = clusterSpec.getConfiguration().getString(
"whirr.hadoop-install-runurl", "apache/hadoop/install");
Payload nnjtBootScript = newStringPayload(runUrls(clusterSpec.getRunUrlBase(),
String.format("util/configure-hostnames -c %s", clusterSpec.getProvider()),
"sun/java/install",
String.format("%s nn,jt -c %s", hadoopInstallRunUrl,
clusterSpec.getProvider())));
Expand Down Expand Up @@ -142,6 +143,7 @@ public HadoopCluster launchCluster(ClusterSpec clusterSpec) throws IOException {

// Launch slaves (DN and TT)
Payload slaveBootScript = newStringPayload(runUrls(clusterSpec.getRunUrlBase(),
String.format("util/configure-hostnames -c %s", clusterSpec.getProvider()),
"sun/java/install",
String.format("%s dn,tt -n %s -j %s -c %s",
hadoopInstallRunUrl,
Expand All @@ -154,7 +156,7 @@ public HadoopCluster launchCluster(ClusterSpec clusterSpec) throws IOException {
.installPrivateKey(clusterSpec.getPrivateKey())
.authorizePublicKey(clusterSpec.getPublicKey()));

strategy.configureTemplateBuilder(clusterSpec, slaveTemplateBuilder);
slaveTemplateBuilder.fromTemplate(masterTemplate); // base on master
slaveTemplateBuilder.locationId(masterTemplate.getLocation().getId());

Template slaveTemplate = slaveTemplateBuilder.build();
Expand Down
2 changes: 1 addition & 1 deletion services/zookeeper/pom.xml
Expand Up @@ -43,7 +43,7 @@
</dependency>
<dependency>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-aws</artifactId>
<artifactId>jclouds-allcompute</artifactId>
</dependency>
<dependency>
<groupId>org.jclouds</groupId>
Expand Down
Expand Up @@ -52,7 +52,9 @@
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.Template;
import org.jclouds.compute.domain.TemplateBuilder;
import org.jclouds.compute.options.RunScriptOptions;
import org.jclouds.compute.predicates.NodePredicates;
import org.jclouds.domain.Credentials;
import org.jclouds.io.Payload;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -116,11 +118,19 @@ public ZooKeeperCluster launchCluster(ClusterSpec clusterSpec) throws IOExceptio
// Position is significant: i-th server has id i.
String servers = Joiner.on(' ').join(getPrivateIps(nodes));
Payload configureScript = newStringPayload(runUrls(clusterSpec.getRunUrlBase(),
"apache/zookeeper/post-configure " + servers));
String.format("apache/zookeeper/post-configure -c %s %s",
clusterSpec.getProvider(),
servers)));
// Use private key to run script
Credentials credentials = new Credentials(
Iterables.get(nodes, 0).getCredentials().identity,
clusterSpec.readPrivateKey());
try {
LOG.info("Running configuration script");
computeService.runScriptOnNodesMatching(NodePredicates.runningWithTag(
clusterSpec.getClusterName()), configureScript);
clusterSpec.getClusterName()),
configureScript,
RunScriptOptions.Builder.overrideCredentialsWith(credentials));
} catch (RunScriptOnNodesException e) {
// TODO: retry
throw new IOException(e);
Expand All @@ -138,11 +148,11 @@ private List<String> getPrivateIps(List<NodeMetadata> nodes) {
@Override
public String apply(NodeMetadata node) {
try {
return InetAddress.getByName(Iterables.get(node.getPrivateAddresses(), 0)).getHostAddress();
} catch (UnknownHostException e) {
Throwables.propagate(e);
return null;
}
return InetAddress.getByName(Iterables.get(node.getPrivateAddresses(), 0)).getHostAddress();
} catch (UnknownHostException e) {
Throwables.propagate(e);
return null;
}
}
});
}
Expand All @@ -153,9 +163,9 @@ private Set<Instance> getInstances(List<NodeMetadata> nodes) {
@Override
public Instance apply(NodeMetadata node) {
try {
return new Instance(node.getCredentials(), Collections.singleton(ZOOKEEPER_ROLE),
InetAddress.getByName(Iterables.get(node.getPublicAddresses(), 0)),
InetAddress.getByName(Iterables.get(node.getPrivateAddresses(), 0)));
return new Instance(node.getCredentials(), Collections.singleton(ZOOKEEPER_ROLE),
InetAddress.getByName(Iterables.get(node.getPublicAddresses(), 0)),
InetAddress.getByName(Iterables.get(node.getPrivateAddresses(), 0)));
} catch (UnknownHostException e) {
throw new RuntimeException(e);
}
Expand All @@ -169,12 +179,12 @@ private List<String> getHosts(List<NodeMetadata> nodes) {
@Override
public String apply(NodeMetadata node) {
String publicIp;
try {
publicIp = InetAddress.getByName(Iterables.get(node.getPublicAddresses(), 0)).getHostName();
} catch (UnknownHostException e) {
Throwables.propagate(e);
return null;
}
try {
publicIp = InetAddress.getByName(Iterables.get(node.getPublicAddresses(), 0)).getHostName();
} catch (UnknownHostException e) {
Throwables.propagate(e);
return null;
}
return String.format("%s:%d", publicIp, CLIENT_PORT);
}
});
Expand Down
15 changes: 15 additions & 0 deletions src/site/confluence/faq.confluence
Expand Up @@ -10,6 +10,21 @@ On EC2:

Another good resource is [Understanding Access Credentials for AWS/EC2|http://alestic.com/2009/11/ec2-credentials] by Eric Hammond.

h2. Can I specify my own private key?

Yes, by setting {{whirr.private-key-file}} (or {{\--private-key-file}} on the
command line). You should also set {{whirr.public-key-file}}
({{\--public-key-file}}) at the same time.

Private keys must not have a passphrase associated with them. You can check this
with:

{code}
grep ENCRYPTED ~/.ssh/id_rsa
{code}

If there is no passphrase then there will be no match.

h2. How do I access my cluster from a different network?

By default, access to clusters is restricted to the single IP address of the
Expand Down
2 changes: 1 addition & 1 deletion src/site/confluence/index.confluence
Expand Up @@ -16,7 +16,7 @@ the cloud provider and service combinations that have been tested.

||Cloud provider||Cassandra||Hadoop||ZooKeeper||
|Amazon EC2|Yes|Yes|Yes|
|Rackspace|No|No|No|
|Rackspace Cloud Servers|Yes|Yes|Yes|

h2. Download

Expand Down

0 comments on commit 59df44e

Please sign in to comment.