use of com.ms.silverking.cloud.topology.Node in project SilverKing by Morgan-Stanley.
the class RingTreeRecipe method _evenlyDistributeWeights.
private static double _evenlyDistributeWeights(Topology topology, Node node, Map<String, Double> nodeWeights, ExclusionSet exclusionList, HostGroupTable hostGroupTable, Set<String> hostGroups) {
Double weight;
weight = nodeWeights.get(node.getIDString());
if (weight == null) {
if (node.hasChildren()) {
double sum;
sum = 0.0;
for (Node child : node.getChildren()) {
sum += _evenlyDistributeWeights(topology, child, nodeWeights, exclusionList, hostGroupTable, hostGroups);
}
weight = sum;
} else {
if (!Sets.intersection(hostGroupTable.getHostGroups(node.getIDString()), hostGroups).isEmpty() && (!exclusionList.contains(node.getIDString()))) {
weight = WeightSpecifications.defaultWeight;
} else {
weight = 0.0;
}
}
nodeWeights.put(node.getIDString(), weight);
}
if (debug) {
System.out.printf("\t####\t%s\t%f\n", node.getIDString(), weight);
}
return weight;
}
use of com.ms.silverking.cloud.topology.Node in project SilverKing by Morgan-Stanley.
the class SingleRingZK method writeTree.
public static void writeTree(MetaClient mc, long topologyVersion, String configInstancePath, RingTree ringTree, Node parent) throws /*, String storagePolicyName*/
KeeperException, IOException {
assert configInstancePath != null;
if (parent.hasChildren()) {
SingleRingZK singleRingZK;
// singleRingZK = new SingleRingZK(mc, parent.getNodeClass(), topologyVersion, configInstancePath, parent.getIDString(), storagePolicyName);
singleRingZK = new SingleRingZK(mc, parent.getNodeClass(), topologyVersion, configInstancePath, parent.getIDString());
singleRingZK.writeToZK(ringTree.getMap(parent.getIDString()), null);
for (Node child : parent.getChildren()) {
writeTree(mc, topologyVersion, configInstancePath, ringTree, child);
}
}
}
use of com.ms.silverking.cloud.topology.Node in project SilverKing by Morgan-Stanley.
the class TopologyRingCreator method _create.
/**
* Create a new ring that is as similar as possible to the ring passed in so
* that we minimize the movement of data.
*
* @param sourceRing
* an immutable SingleRing that may or may not meet the
* requirements of the recipe
* @param recipe
* @return an immutable SingleRing (returned as a TopologyRing) that meets
* the requirements of the recipe
*/
private TopologyRing _create(SingleRing sourceRing, RingTreeRecipe recipe, String ringParentID) {
// This version ignores the source ring, _create2 takes the source into
// account
/*
* Single StoragePolicy applies. StoragePolicy has primary and secondary
* SubPolicy Each SubPolicy has multiple SubPolicyMembers
*
* Each SubPolicyMember has a logical ring associated with it - The set
* of nodes in each of these rings is disjoint with respect to all other
* ring node sets - Weights must be normalized for each member
*
* Loop structure: For {primary, secondary} For all SubPolicyMembers For
* all replicas
*/
Node parent;
NodeClass nodeClass;
parent = recipe.topology.getNodeByID(ringParentID);
nodeClass = parent.getChildNodeClass();
ProtoRegionList prList;
prList = ProtoRegionList.createEmpty();
for (SubPolicy subPolicy : recipe.storagePolicy.getSubPolicies()) {
prList = allocateSubPolicy(prList, subPolicy, ringParentID, recipe);
}
System.out.println("*********************");
System.out.println(prList);
return prList.toSingleRing(nodeClass, recipe);
}
use of com.ms.silverking.cloud.topology.Node in project SilverKing by Morgan-Stanley.
the class TopologyRingCreator method swap.
private SwapResult swap(ProtoRegionList prList, Node newNode, int ownedIndex, int nonownedIndex, long maxAllocation) {
Node existingNode;
ProtoRegion ownedRegion;
ProtoRegion nonownedRegion;
if (debug) {
System.out.printf("\nin swap %s ownedIndex %d nonownedIndex %d maxAllocation %d\n", newNode, ownedIndex, nonownedIndex, maxAllocation);
System.out.flush();
}
// First make sure that ownedRegion size <= maxAllocation
ownedRegion = prList.get(ownedIndex);
if (maxAllocation < ownedRegion.getRegionSize()) {
if (debug) {
System.out.println("reducing to max allocation: " + ownedRegion);
}
prList.splitProtoRegion(ownedIndex, maxAllocation);
if (nonownedIndex > ownedIndex) {
nonownedIndex++;
}
}
// Get the regions (get owned again since it might have been split)
ownedRegion = prList.get(ownedIndex);
nonownedRegion = prList.get(nonownedIndex);
if (debug) {
System.out.printf("ownedRegion: %s\n", ownedRegion);
System.out.printf("nonownedRegion: %s\n", nonownedRegion);
}
if (ownedRegion.getRegionSize() > nonownedRegion.getRegionSize()) {
if (debug) {
System.out.println("splitting ownedRegion");
}
prList.splitProtoRegion(ownedIndex, nonownedRegion.getRegionSize());
if (nonownedIndex > ownedIndex) {
nonownedIndex++;
}
} else if (ownedRegion.getRegionSize() < nonownedRegion.getRegionSize()) {
if (debug) {
System.out.println("splitting nonownedRegion");
}
prList.splitProtoRegion(nonownedIndex, ownedRegion.getRegionSize());
if (ownedIndex > nonownedIndex) {
ownedIndex++;
}
} else {
// no action necessary
if (debug) {
System.out.println("no region split necessary");
}
}
// Get the regions again since they might have been split
ownedRegion = prList.get(ownedIndex);
nonownedRegion = prList.get(nonownedIndex);
if (debug) {
System.out.printf("\townedRegion: %s\n", ownedRegion);
System.out.printf("\tnonownedRegion: %s\n", nonownedRegion);
}
assert ownedRegion.getRegionSize() == nonownedRegion.getRegionSize();
// Select victim
existingNode = nonownedRegion.getLastAddedOwnerNotIn(ownedRegion.getOwnersSet());
// Swap
nonownedRegion.replaceOwner(existingNode, newNode);
ownedRegion.replaceOwner(newNode, existingNode);
if (debug) {
System.out.println("After swap");
System.out.printf("\townedRegion: %s\n", ownedRegion);
System.out.printf("\tnonownedRegion: %s\n", nonownedRegion);
}
return new SwapResult(ownedIndex, nonownedIndex, ownedRegion.getRegionSize());
}
use of com.ms.silverking.cloud.topology.Node in project SilverKing by Morgan-Stanley.
the class TopologyRingCreator method allocateSubPolicy2.
private void allocateSubPolicy2(SingleRing sourceRing, ProtoRegionList prList, SubPolicy subPolicy, String ringParentID, RingTreeRecipe recipe) {
Node parent;
if (debug) {
System.out.println("TopologyRingCreator.allocateSubPolicy2()");
System.out.println("subPolicy: " + subPolicy);
System.out.flush();
}
parent = recipe.topology.getNodeByID(ringParentID);
for (SubPolicyMember member : subPolicy.getMembers()) {
allocateSubPolicyMember2(sourceRing, prList, member, recipe, parent, subPolicy.getReplicationType());
}
}
Aggregations