Permalink
Browse files

Merging updated EC2 tests to support multiple EC2 regions

  • Loading branch information...
1 parent 1065da5 commit e88d32d42b889a4f796e2bda924e103a3fb231ea @rsumbaly rsumbaly committed Jul 20, 2010
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -44,6 +44,8 @@ SshClusterStarter.ssh=ssh -o StrictHostKeyChecking=no -i ${sshPrivateKey} ${host
mv $VOLDEMORT_HOME/config/server.properties $VOLDEMORT_HOME/config/server.properties.bak ; \
grep -v "^node.id=" $VOLDEMORT_HOME/config/server.properties.bak > $VOLDEMORT_HOME/config/server.properties ; \
rm -rf ${voldemortHomeDirectory}/data ; \
+ rm -rf ${voldemortHomeDirectory}/config/.temp ; \
+ rm -rf ${voldemortHomeDirectory}/config/.version ; \
cd ${voldemortRootDirectory} ; \
./bin/voldemort-server.sh"
@@ -53,6 +55,8 @@ SshClusterStarter.ssh.nokey=ssh -o StrictHostKeyChecking=no ${hostUserId}@${host
mv $VOLDEMORT_HOME/config/server.properties $VOLDEMORT_HOME/config/server.properties.bak ; \
grep -v "^node.id=" $VOLDEMORT_HOME/config/server.properties.bak > $VOLDEMORT_HOME/config/server.properties ; \
rm -rf ${voldemortHomeDirectory}/data ; \
+ rm -rf ${voldemortHomeDirectory}/config/.temp ; \
+ rm -rf ${voldemortHomeDirectory}/config/.version ; \
cd ${voldemortRootDirectory} ; \
./bin/voldemort-server.sh"
@@ -20,12 +20,17 @@
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
import java.util.Random;
+import java.util.Set;
import org.apache.commons.lang.StringUtils;
+
import voldemort.cluster.Cluster;
import voldemort.cluster.Node;
+import voldemort.cluster.Zone;
/**
* ClusterGenerator generates a cluster.xml file given either a list of hosts or
@@ -88,11 +93,30 @@
*
* @return List of ClusterNodeDescriptor
*/
-
public List<ClusterNodeDescriptor> createClusterNodeDescriptors(List<String> hostNames,
int numPartitions) {
+ HashMap<Integer, List<String>> zoneToHostName = new HashMap<Integer, List<String>>();
+ zoneToHostName.put(Zone.DEFAULT_ZONE_ID, hostNames);
+ return createClusterNodeDescriptors(zoneToHostName, numPartitions);
+ }
+
+ /**
+ * Creates a list of ClusterNodeDescriptor instances
+ *
+ * @param zoneToHostNames A mapping from zone to list of host names
+ * @param numPartitions Number of partitions per host
+ *
+ * @return List of ClusterNodeDescriptor
+ */
+ private List<ClusterNodeDescriptor> createClusterNodeDescriptors(HashMap<Integer, List<String>> zoneToHostNames,
+ int numPartitions) {
+ int numHosts = 0;
+ for(List<String> hostNames: zoneToHostNames.values()) {
+ numHosts += hostNames.size();
+ }
+
// Create a list of integers [0..totalPartitions).
- int totalPartitions = hostNames.size() * numPartitions;
+ int totalPartitions = numHosts * numPartitions;
List<Integer> allPartitionIds = new ArrayList<Integer>();
for(int i = 0; i < totalPartitions; i++)
@@ -103,64 +127,107 @@
List<ClusterNodeDescriptor> list = new ArrayList<ClusterNodeDescriptor>();
- for(int i = 0; i < hostNames.size(); i++) {
- String hostName = hostNames.get(i);
- List<Integer> partitions = allPartitionIds.subList(i * numPartitions, (i + 1)
- * numPartitions);
- Collections.sort(partitions);
-
- ClusterNodeDescriptor cnd = new ClusterNodeDescriptor();
- cnd.setHostName(hostName);
- cnd.setId(i);
- cnd.setPartitions(partitions);
-
- list.add(cnd);
+ int nodeId = 0;
+ for(int zoneId = 0; zoneId < zoneToHostNames.size(); zoneId++) {
+ List<String> hostNames = zoneToHostNames.get(zoneId);
+
+ for(int i = 0; i < hostNames.size(); i++) {
+ String hostName = hostNames.get(i);
+ List<Integer> partitions = allPartitionIds.subList(nodeId * numPartitions,
+ (nodeId + 1) * numPartitions);
+ Collections.sort(partitions);
+
+ ClusterNodeDescriptor cnd = new ClusterNodeDescriptor();
+ cnd.setHostName(hostName);
+ cnd.setId(nodeId);
+ cnd.setPartitions(partitions);
+ cnd.setZoneId(zoneId);
+
+ nodeId++;
+ list.add(cnd);
+ }
}
return list;
}
- public List<ClusterNodeDescriptor> createClusterNodeDescriptors(List<String> hostNames,
+ /**
+ * Creates a list of ClusterNodeDescriptor instances
+ *
+ * @param zoneToHostNames A mapping from zone to list of host names
+ * @param cluster The cluster describing the various hosts
+ *
+ * @return List of ClusterNodeDescriptor
+ */
+ public List<ClusterNodeDescriptor> createClusterNodeDescriptors(HashMap<Integer, List<String>> zoneToHostNames,
Cluster cluster) {
- if (cluster.getNumberOfNodes() > hostNames.size())
+ if(cluster.getNumberOfZones() != zoneToHostNames.size())
+ throw new IllegalStateException("zone size does not match");
+
+ int numHosts = 0;
+ for(List<String> hostNames: zoneToHostNames.values()) {
+ numHosts += hostNames.size();
+ }
+
+ if(cluster.getNumberOfNodes() != numHosts)
throw new IllegalStateException("cluster size exceeds the number of available instances");
List<ClusterNodeDescriptor> list = new ArrayList<ClusterNodeDescriptor>();
- for(int i = 0; i < cluster.getNumberOfNodes(); i++) {
- Node node = cluster.getNodeById(i);
- String hostName = hostNames.get(i);
- List<Integer> partitions = node.getPartitionIds();
-
- ClusterNodeDescriptor cnd = new ClusterNodeDescriptor();
- cnd.setHostName(hostName);
- cnd.setId(i);
- cnd.setSocketPort(node.getSocketPort());
- cnd.setHttpPort(node.getHttpPort());
- cnd.setAdminPort(node.getAdminPort());
- cnd.setPartitions(partitions);
-
- list.add(cnd);
+
+ int nodeId = 0;
+ for(int zoneId = 0; zoneId < zoneToHostNames.size(); zoneId++) {
+ List<String> hostNames = zoneToHostNames.get(zoneId);
+
+ for(int i = 0; i < hostNames.size(); i++) {
+ Node node = cluster.getNodeById(nodeId);
+ String hostName = hostNames.get(i);
+ List<Integer> partitions = node.getPartitionIds();
+
+ ClusterNodeDescriptor cnd = new ClusterNodeDescriptor();
+ cnd.setHostName(hostName);
+ cnd.setId(nodeId);
+ cnd.setSocketPort(node.getSocketPort());
+ cnd.setHttpPort(node.getHttpPort());
+ cnd.setAdminPort(node.getAdminPort());
+ cnd.setPartitions(partitions);
+ cnd.setZoneId(zoneId);
+
+ nodeId++;
+ list.add(cnd);
+ }
}
return list;
}
+ /**
+ * @param hostNames <i>Internal</i> host name
+ * @param cluster Number of partitions <b>per host</b>
+ *
+ * @return List of ClusterNodeDescriptor
+ */
+ public List<ClusterNodeDescriptor> createClusterNodeDescriptors(List<String> hostNames,
+ Cluster cluster) {
+ HashMap<Integer, List<String>> zoneToHostName = new HashMap<Integer, List<String>>();
+ zoneToHostName.put(Zone.DEFAULT_ZONE_ID, hostNames);
+ return createClusterNodeDescriptors(zoneToHostName, cluster);
+ }
/**
* Creates a String representing the format used by cluster.xml given the
* cluster name, host names, and number of partitions for each host.
*
* @param clusterName Name of cluster
- * @param hostNames <i>Internal</i> host name
+ * @param zoneToHostNames Zone to list of HostNames map
* @param numPartitions Number of partitions <b>per host</b>
*
* @return String of formatted XML as used by cluster.xml
*/
public String createClusterDescriptor(String clusterName,
- List<String> hostNames,
+ HashMap<Integer, List<String>> zoneToHostNames,
int numPartitions) {
- List<ClusterNodeDescriptor> clusterNodeDescriptors = createClusterNodeDescriptors(hostNames,
+ List<ClusterNodeDescriptor> clusterNodeDescriptors = createClusterNodeDescriptors(zoneToHostNames,
numPartitions);
return createClusterDescriptor(clusterName, clusterNodeDescriptors);
@@ -185,22 +252,55 @@ public String createClusterDescriptor(String clusterName,
pw.println("<cluster>");
pw.println("\t<name>" + clusterName + "</name>");
+ StringBuffer nodesBuffer = new StringBuffer();
+ Set<Integer> zoneIds = new HashSet<Integer>();
for(ClusterNodeDescriptor cnd: clusterNodeDescriptors) {
String partitions = StringUtils.join(cnd.getPartitions(), ", ");
- pw.println("\t<server>");
- pw.println("\t\t<id>" + cnd.getId() + "</id>");
- pw.println("\t\t<host>" + cnd.getHostName() + "</host>");
- pw.println("\t\t<http-port>" + cnd.getHttpPort() + "</http-port>");
- pw.println("\t\t<socket-port>" + cnd.getSocketPort() + "</socket-port>");
- pw.println("\t\t<admin-port>" + cnd.getAdminPort() + "</admin-port>");
- pw.println("\t\t<partitions>" + partitions + "</partitions>");
- pw.println("\t</server>");
+ nodesBuffer.append("\t<server>\n");
+ nodesBuffer.append("\t\t<id>" + cnd.getId() + "</id>\n");
+ nodesBuffer.append("\t\t<host>" + cnd.getHostName() + "</host>\n");
+ nodesBuffer.append("\t\t<http-port>" + cnd.getHttpPort() + "</http-port>\n");
+ nodesBuffer.append("\t\t<socket-port>" + cnd.getSocketPort() + "</socket-port>\n");
+ nodesBuffer.append("\t\t<admin-port>" + cnd.getAdminPort() + "</admin-port>\n");
+ nodesBuffer.append("\t\t<partitions>" + partitions + "</partitions>\n");
+ nodesBuffer.append("\t\t<zone-id>" + cnd.getZoneId() + "</zone-id>\n");
+ nodesBuffer.append("\t</server>");
+
+ zoneIds.add(cnd.getZoneId());
}
+ // Insert zones
+ for(Integer zoneId: zoneIds) {
+ pw.println("\t<zone>");
+ pw.println("\t\t<zone-id>" + zoneId + "</zone-id>");
+ pw.println("\t\t<proximity-list>" + generateProximityList(zoneId, zoneIds.size())
+ + "</proximity-list>");
+ pw.println("\t</zone>");
+ }
+
+ // Insert servers
+ pw.println(nodesBuffer.toString());
pw.println("</cluster>");
return sw.toString();
}
-}
+ /**
+ * Generate sequential proximity list
+ *
+ * @param zoneId Id of the Zone for which the proximity List is being
+ * generated
+ * @param totalZones Total number of zones
+ * @return String of list of zones
+ */
+ private String generateProximityList(int zoneId, int totalZones) {
+ List<Integer> proximityList = new ArrayList<Integer>();
+ int currentZoneId = (zoneId + 1) % totalZones;
+ for(int i = 0; i < (totalZones - 1); i++) {
+ proximityList.add(currentZoneId);
+ currentZoneId = (currentZoneId + 1) % totalZones;
+ }
+ return StringUtils.join(proximityList, ", ");
+ }
+}
@@ -18,6 +18,8 @@
import java.util.List;
+import voldemort.cluster.Zone;
+
/**
* ClusterNodeDescriptor is a simple POJO for storing the attributes of a node
* as needed by the cluster.xml cluster descriptor file.
@@ -46,6 +48,12 @@
private static final int DEFAULT_ADMIN_PORT = DEFAULT_SOCKET_PORT + 1;
+ /**
+ * DEFAULT_ZONE_ID is Zone.DEFAULT_ZONE_ID
+ */
+
+ private static final int DEFAULT_ZONE_ID = Zone.DEFAULT_ZONE_ID;
+
private String hostName;
private int id;
@@ -56,8 +64,28 @@
private int adminPort = DEFAULT_ADMIN_PORT;
+ private int zoneId = DEFAULT_ZONE_ID;
+
private List<Integer> partitions;
+ /**
+ * Returns the Zone ID of this node
+ *
+ * @return Zone id of this node
+ */
+ public int getZoneId() {
+ return this.zoneId;
+ }
+
+ /**
+ * Assign the zone Id to this node.
+ *
+ * @param zoneId Zone Id
+ */
+ public void setZoneId(int zoneId) {
+ this.zoneId = zoneId;
+ }
+
/**
* Returns the host name (or IP address) of the node. This is the internal
* host name as seen by the other server nodes and clients on the same
@@ -0,0 +1,68 @@
+package voldemort.utils;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.util.List;
+
+import voldemort.routing.RoutingStrategyType;
+import voldemort.store.bdb.BdbStorageConfiguration;
+
+/**
+ * StoresGenerator generates the stores.xml file given either a store name along
+ * with zone specific replication factors. Currently hard-coding the serializers
+ * to string format
+ *
+ */
+public class StoresGenerator {
+
+ public String createStoreDescriptor(String storeName,
+ List<Integer> zoneRepFactor,
+ int requiredReads,
+ int requiredWrites,
+ int zoneCountReads,
+ int zoneCountWrites,
+ String routingStrategy) {
+ StringWriter sw = new StringWriter();
+ PrintWriter pw = new PrintWriter(sw);
+
+ pw.println("<stores>");
+ pw.println("\t<store>");
+ pw.println("\t\t<name>" + storeName + "</name>");
+ pw.println("\t\t<persistence>" + BdbStorageConfiguration.TYPE_NAME + "</persistence>");
+ pw.println("\t\t<routing>client</routing>");
+ pw.println("\t\t<routing-strategy>" + routingStrategy + "</routing-strategy>");
+
+ pw.println("\t\t<key-serializer>");
+ pw.println("\t\t\t<type>string</type>");
+ pw.println("\t\t\t<schema-info>UTF-8</schema-info>");
+ pw.println("\t\t</key-serializer>");
+ pw.println("\t\t<value-serializer>");
+ pw.println("\t\t\t<type>string</type>");
+ pw.println("\t\t\t<schema-info>UTF-8</schema-info>");
+ pw.println("\t\t</value-serializer>");
+
+ pw.println("\t\t<required-reads>" + requiredReads + "</required-reads>");
+ pw.println("\t\t<required-writes>" + requiredWrites + "</required-writes>");
+
+ pw.println("\t\t<zone-replication-factor>");
+ int zoneId = 0, totalReplicationFactor = 0;
+ for(int repFactor: zoneRepFactor) {
+ pw.println("\t\t\t<replication-factor zone-id=\"" + zoneId + "\">" + repFactor
+ + "</replication-factor>");
+ zoneId++;
+ totalReplicationFactor += repFactor;
+ }
+ pw.println("\t\t</zone-replication-factor>");
+ pw.println("\t\t<replication-factor>" + totalReplicationFactor + "</replication-factor>");
+
+ if(routingStrategy.compareTo(RoutingStrategyType.ZONE_STRATEGY) == 0) {
+ pw.println("\t\t<zone-count-reads>" + zoneCountReads + "</zone-count-reads>");
+ pw.println("\t\t<zone-count-writes>" + zoneCountWrites + "</zone-count-writes>");
+ }
+ pw.println("\t</store>");
+ pw.println("</stores>");
+
+ return sw.toString();
+ }
+
+}
Oops, something went wrong.

0 comments on commit e88d32d

Please sign in to comment.