Committed by
Gerrit Code Review
[ONOS-5184] Allow configuring cluster partition size
Adds a new parameter to onos-form-cluster: -s <partition-size> to allow specifying the partition size to be used when creating the cluster. Change-Id: I4c31d6e97fe0fd811831296f41a09160bebb58de
Showing
5 changed files
with
46 additions
and
8 deletions
| ... | @@ -34,6 +34,16 @@ public interface ClusterAdminService extends ClusterService { | ... | @@ -34,6 +34,16 @@ public interface ClusterAdminService extends ClusterService { |
| 34 | void formCluster(Set<ControllerNode> nodes); | 34 | void formCluster(Set<ControllerNode> nodes); |
| 35 | 35 | ||
| 36 | /** | 36 | /** |
| 37 | + * Forms cluster configuration based on the specified set of node | ||
| 38 | + * information. This method resets and restarts the controller | ||
| 39 | + * instance. | ||
| 40 | + * | ||
| 41 | + * @param nodes set of nodes that form the cluster | ||
| 42 | + * @param partitionSize number of nodes to compose a partition | ||
| 43 | + */ | ||
| 44 | + void formCluster(Set<ControllerNode> nodes, int partitionSize); | ||
| 45 | + | ||
| 46 | + /** | ||
| 37 | * Adds a new controller node to the cluster. | 47 | * Adds a new controller node to the cluster. |
| 38 | * | 48 | * |
| 39 | * @param nodeId controller node identifier | 49 | * @param nodeId controller node identifier | ... | ... |
| ... | @@ -71,6 +71,7 @@ public class ClusterManager | ... | @@ -71,6 +71,7 @@ public class ClusterManager |
| 71 | implements ClusterService, ClusterAdminService { | 71 | implements ClusterService, ClusterAdminService { |
| 72 | 72 | ||
| 73 | public static final String INSTANCE_ID_NULL = "Instance ID cannot be null"; | 73 | public static final String INSTANCE_ID_NULL = "Instance ID cannot be null"; |
| 74 | + private static final int DEFAULT_PARTITION_SIZE = 3; | ||
| 74 | private final Logger log = getLogger(getClass()); | 75 | private final Logger log = getLogger(getClass()); |
| 75 | 76 | ||
| 76 | private ClusterStoreDelegate delegate = new InternalStoreDelegate(); | 77 | private ClusterStoreDelegate delegate = new InternalStoreDelegate(); |
| ... | @@ -146,10 +147,15 @@ public class ClusterManager | ... | @@ -146,10 +147,15 @@ public class ClusterManager |
| 146 | 147 | ||
| 147 | @Override | 148 | @Override |
| 148 | public void formCluster(Set<ControllerNode> nodes) { | 149 | public void formCluster(Set<ControllerNode> nodes) { |
| 150 | + formCluster(nodes, DEFAULT_PARTITION_SIZE); | ||
| 151 | + } | ||
| 152 | + | ||
| 153 | + @Override | ||
| 154 | + public void formCluster(Set<ControllerNode> nodes, int partitionSize) { | ||
| 149 | checkNotNull(nodes, "Nodes cannot be null"); | 155 | checkNotNull(nodes, "Nodes cannot be null"); |
| 150 | checkArgument(!nodes.isEmpty(), "Nodes cannot be empty"); | 156 | checkArgument(!nodes.isEmpty(), "Nodes cannot be empty"); |
| 151 | 157 | ||
| 152 | - ClusterMetadata metadata = new ClusterMetadata("default", nodes, buildDefaultPartitions(nodes)); | 158 | + ClusterMetadata metadata = new ClusterMetadata("default", nodes, buildDefaultPartitions(nodes, partitionSize)); |
| 153 | clusterMetadataAdminService.setClusterMetadata(metadata); | 159 | clusterMetadataAdminService.setClusterMetadata(metadata); |
| 154 | try { | 160 | try { |
| 155 | log.warn("Shutting down container for cluster reconfiguration!"); | 161 | log.warn("Shutting down container for cluster reconfiguration!"); |
| ... | @@ -183,13 +189,13 @@ public class ClusterManager | ... | @@ -183,13 +189,13 @@ public class ClusterManager |
| 183 | } | 189 | } |
| 184 | } | 190 | } |
| 185 | 191 | ||
| 186 | - private static Set<Partition> buildDefaultPartitions(Collection<ControllerNode> nodes) { | 192 | + private static Set<Partition> buildDefaultPartitions(Collection<ControllerNode> nodes, int partitionSize) { |
| 187 | List<ControllerNode> sorted = new ArrayList<>(nodes); | 193 | List<ControllerNode> sorted = new ArrayList<>(nodes); |
| 188 | Collections.sort(sorted, (o1, o2) -> o1.id().toString().compareTo(o2.id().toString())); | 194 | Collections.sort(sorted, (o1, o2) -> o1.id().toString().compareTo(o2.id().toString())); |
| 189 | Set<Partition> partitions = Sets.newHashSet(); | 195 | Set<Partition> partitions = Sets.newHashSet(); |
| 190 | // add partitions | 196 | // add partitions |
| 191 | int length = nodes.size(); | 197 | int length = nodes.size(); |
| 192 | - int count = Math.min(3, length); | 198 | + int count = Math.min(partitionSize, length); |
| 193 | for (int i = 0; i < length; i++) { | 199 | for (int i = 0; i < length; i++) { |
| 194 | int index = i; | 200 | int index = i; |
| 195 | Set<NodeId> set = new HashSet<>(count); | 201 | Set<NodeId> set = new HashSet<>(count); | ... | ... |
| ... | @@ -6,10 +6,11 @@ | ... | @@ -6,10 +6,11 @@ |
| 6 | [ $# -lt 2 ] && echo "usage: $(basename $0) ip1 ip2..." && exit 1 | 6 | [ $# -lt 2 ] && echo "usage: $(basename $0) ip1 ip2..." && exit 1 |
| 7 | 7 | ||
| 8 | # Scan arguments for user/password or other options... | 8 | # Scan arguments for user/password or other options... |
| 9 | -while getopts u:p: o; do | 9 | +while getopts u:p:s: o; do |
| 10 | case "$o" in | 10 | case "$o" in |
| 11 | u) user=$OPTARG;; | 11 | u) user=$OPTARG;; |
| 12 | p) password=$OPTARG;; | 12 | p) password=$OPTARG;; |
| 13 | + s) partitionsize=$OPTARG;; | ||
| 13 | esac | 14 | esac |
| 14 | done | 15 | done |
| 15 | ONOS_WEB_USER=${ONOS_WEB_USER:-onos} # ONOS WEB User defaults to 'onos' | 16 | ONOS_WEB_USER=${ONOS_WEB_USER:-onos} # ONOS WEB User defaults to 'onos' |
| ... | @@ -32,7 +33,11 @@ echo "{ \"nodes\": [ { \"ip\": \"$ip\" }" > $aux | ... | @@ -32,7 +33,11 @@ echo "{ \"nodes\": [ { \"ip\": \"$ip\" }" > $aux |
| 32 | for node in $nodes; do | 33 | for node in $nodes; do |
| 33 | echo ", { \"ip\": \"$node\" }" >> $aux | 34 | echo ", { \"ip\": \"$node\" }" >> $aux |
| 34 | done | 35 | done |
| 35 | -echo "], \"ipPrefix\": \"$ipPrefix.*\" }" >> $aux | 36 | +echo "], \"ipPrefix\": \"$ipPrefix.*\"" >> $aux |
| 37 | +if ! [ -z ${partitionsize} ]; then | ||
| 38 | + echo ", \"partitionSize\": $partitionsize" >> $aux | ||
| 39 | +fi | ||
| 40 | +echo " }" >> $aux | ||
| 36 | 41 | ||
| 37 | for node in $ip $nodes; do | 42 | for node in $ip $nodes; do |
| 38 | echo "Forming cluster on $node..." | 43 | echo "Forming cluster on $node..." | ... | ... |
| ... | @@ -7,10 +7,11 @@ | ... | @@ -7,10 +7,11 @@ |
| 7 | . $ONOS_ROOT/tools/build/envDefaults | 7 | . $ONOS_ROOT/tools/build/envDefaults |
| 8 | 8 | ||
| 9 | # Scan arguments for user/password or other options... | 9 | # Scan arguments for user/password or other options... |
| 10 | -while getopts u:p: o; do | 10 | +while getopts u:p:s: o; do |
| 11 | case "$o" in | 11 | case "$o" in |
| 12 | u) user=$OPTARG;; | 12 | u) user=$OPTARG;; |
| 13 | p) password=$OPTARG;; | 13 | p) password=$OPTARG;; |
| 14 | + s) partitionsize=$OPTARG;; | ||
| 14 | esac | 15 | esac |
| 15 | done | 16 | done |
| 16 | ONOS_WEB_USER=${ONOS_WEB_USER:-onos} # ONOS WEB User defaults to 'onos' | 17 | ONOS_WEB_USER=${ONOS_WEB_USER:-onos} # ONOS WEB User defaults to 'onos' |
| ... | @@ -29,6 +30,12 @@ else | ... | @@ -29,6 +30,12 @@ else |
| 29 | nodes="$@" | 30 | nodes="$@" |
| 30 | fi | 31 | fi |
| 31 | 32 | ||
| 33 | +if ! [ -z ${partitionsize} ]; then | ||
| 34 | + partitionarg="-s ${partitionsize}" | ||
| 35 | +else | ||
| 36 | + partitionarg= | ||
| 37 | +fi | ||
| 38 | + | ||
| 32 | set -x | 39 | set -x |
| 33 | 40 | ||
| 34 | -ssh $ONOS_USER@$node $ONOS_INSTALL_DIR/bin/onos-form-cluster -u $user -p $password $nodes | 41 | +ssh $ONOS_USER@$node $ONOS_INSTALL_DIR/bin/onos-form-cluster -u $user -p $partitionarg $password $nodes | ... | ... |
| ... | @@ -15,6 +15,7 @@ | ... | @@ -15,6 +15,7 @@ |
| 15 | */ | 15 | */ |
| 16 | package org.onosproject.rest.resources; | 16 | package org.onosproject.rest.resources; |
| 17 | 17 | ||
| 18 | +import com.fasterxml.jackson.databind.JsonNode; | ||
| 18 | import com.fasterxml.jackson.databind.node.ArrayNode; | 19 | import com.fasterxml.jackson.databind.node.ArrayNode; |
| 19 | import com.fasterxml.jackson.databind.node.ObjectNode; | 20 | import com.fasterxml.jackson.databind.node.ObjectNode; |
| 20 | import org.onosproject.cluster.ClusterAdminService; | 21 | import org.onosproject.cluster.ClusterAdminService; |
| ... | @@ -94,7 +95,16 @@ public class ClusterWebResource extends AbstractWebResource { | ... | @@ -94,7 +95,16 @@ public class ClusterWebResource extends AbstractWebResource { |
| 94 | ObjectNode root = (ObjectNode) mapper().readTree(config); | 95 | ObjectNode root = (ObjectNode) mapper().readTree(config); |
| 95 | 96 | ||
| 96 | List<ControllerNode> nodes = codec.decode((ArrayNode) root.path("nodes"), this); | 97 | List<ControllerNode> nodes = codec.decode((ArrayNode) root.path("nodes"), this); |
| 97 | - get(ClusterAdminService.class).formCluster(new HashSet<>(nodes)); | 98 | + JsonNode partitionSizeNode = root.get("partitionSize"); |
| 99 | + if (partitionSizeNode != null) { | ||
| 100 | + int partitionSize = partitionSizeNode.asInt(); | ||
| 101 | + if (partitionSize == 0) { | ||
| 102 | + return Response.notAcceptable(null).build(); | ||
| 103 | + } | ||
| 104 | + get(ClusterAdminService.class).formCluster(new HashSet<>(nodes), partitionSize); | ||
| 105 | + } else { | ||
| 106 | + get(ClusterAdminService.class).formCluster(new HashSet<>(nodes)); | ||
| 107 | + } | ||
| 98 | 108 | ||
| 99 | return Response.ok().build(); | 109 | return Response.ok().build(); |
| 100 | } | 110 | } | ... | ... |
-
Please register or login to post a comment