use of com.ms.silverking.cloud.meta.ExclusionZK in project SilverKing by Morgan-Stanley.
the class StaticRingCreator method createStaticRing.
public static RingCreationResults createStaticRing(String ringName, ZooKeeperConfig zkConfig, Set<String> servers, int replication, UUIDBase myID) {
try {
MetaClient mc;
com.ms.silverking.cloud.meta.MetaClient cloudMC;
NamedRingConfiguration namedRingConfig;
RingConfiguration ringConfig;
RingTreeRecipe recipe;
Topology topology;
WeightSpecifications weightSpecs;
ExclusionSet exclusionSet;
StoragePolicyGroup storagePolicyGroup;
HostGroupTable hostGroupTable;
long ringConfigVersion;
CloudConfiguration cloudConfig;
String exclusionSpecsName;
String hostGroupTableName;
topology = StaticTopologyCreator.createTopology("topology." + myID, servers);
exclusionSpecsName = "exclusionSpecs." + myID;
hostGroupTableName = "hostGroupTable." + myID;
cloudConfig = new CloudConfiguration(topology.getName(), exclusionSpecsName, hostGroupTableName);
cloudMC = new com.ms.silverking.cloud.meta.MetaClient(cloudConfig, zkConfig);
new TopologyZK(cloudMC).writeToZK(topology, null);
new ExclusionZK(cloudMC).writeToZK(ExclusionSet.emptyExclusionSet(0));
mc = new MetaClient(NamedRingConfiguration.emptyTemplate.ringName(ringName), zkConfig);
ringConfig = new RingConfiguration(cloudConfig, "weightSpecsName", StaticTopologyCreator.parentID, SimpleStoragePolicyCreator.storagePolicyGroupName, SimpleStoragePolicyCreator.storagePolicyName, null);
new RingConfigurationZK(mc).writeToZK(ringConfig, null);
namedRingConfig = new NamedRingConfiguration(ringName, ringConfig);
mc = new MetaClient(namedRingConfig, zkConfig);
EmbeddedSK.setEmbeddedNamedRingConfiguration(ringName, namedRingConfig);
Log.warning(zkConfig);
ringConfigVersion = 0;
weightSpecs = new WeightSpecifications(0);
exclusionSet = ExclusionSet.emptyExclusionSet(0);
storagePolicyGroup = SimpleStoragePolicyCreator.createStoragePolicyGroup(replication);
new StoragePolicyZK(mc).writeToZK(storagePolicyGroup, null);
hostGroupTable = HostGroupTable.createHostGroupTable(servers, hostGroupName);
new HostGroupTableZK(cloudMC).writeToZK(hostGroupTable, null);
recipe = new RingTreeRecipe(topology, StaticTopologyCreator.parentID, weightSpecs, exclusionSet, storagePolicyGroup, SimpleStoragePolicyCreator.storagePolicyName, hostGroupTable, ImmutableSet.of(hostGroupName), ringConfigVersion, DHTUtil.currentTimeMillis());
Log.warning("Recipe.ringParent: " + recipe.ringParent);
RingTree ringTree;
String newInstancePath;
ringTree = RingTreeBuilder.create(recipe, null);
newInstancePath = mc.createConfigInstancePath(ringConfigVersion);
SingleRingZK.writeTree(mc, topology, newInstancePath, ringTree);
if (TopoRingConstants.verbose) {
System.out.println(ringTree);
System.out.println("Building complete");
}
return new RingCreationResults(exclusionSpecsName, hostGroupTableName, hostGroupTable, hostGroupName);
} catch (IOException ioe) {
Log.logErrorWarning(ioe);
return null;
} catch (KeeperException ke) {
Log.logErrorWarning(ke);
return null;
}
}
use of com.ms.silverking.cloud.meta.ExclusionZK in project SilverKing by Morgan-Stanley.
the class DHTRingMaster method readExclusions.
private ExclusionSet readExclusions(String ringName, long ringVersion) throws KeeperException, IOException {
ExclusionZK exclusionZK;
ExclusionSet instanceExclusionSet;
ExclusionSet exclusionSet;
com.ms.silverking.cloud.meta.MetaClient cloudMC;
com.ms.silverking.cloud.toporing.meta.MetaClient ringMC;
ringMC = com.ms.silverking.cloud.toporing.meta.MetaClient.createMetaClient(ringName, ringVersion, zkConfig);
cloudMC = ringMC.createCloudMC();
exclusionZK = new ExclusionZK(cloudMC);
try {
exclusionSet = exclusionZK.readLatestFromZK();
} catch (Exception e) {
Log.logErrorWarning(e);
Log.warningAsync("No ExclusionSet found. Using empty set.");
exclusionSet = ExclusionSet.emptyExclusionSet(0);
}
try {
instanceExclusionSet = new ExclusionSet(new ServerSetExtensionZK(mc, mc.getMetaPaths().getInstanceExclusionsPath()).readLatestFromZK());
} catch (Exception e) {
Log.logErrorWarning(e);
Log.warningAsync("No instance ExclusionSet found. Using empty set.");
instanceExclusionSet = ExclusionSet.emptyExclusionSet(0);
}
return ExclusionSet.union(exclusionSet, instanceExclusionSet);
}
use of com.ms.silverking.cloud.meta.ExclusionZK in project SilverKing by Morgan-Stanley.
the class RingMapState method readInitialExclusions.
/*
private void waitForExclusionSet() {
Log.warningf("waitForExclusionSet: %s", ringIDAndVersionPair);
exclusionSetLock.lock();
try {
while (!exclusionSetInitialized) {
try {
exclusionSetCV.await();
} catch (InterruptedException e) {
}
}
} finally {
exclusionSetLock.unlock();
}
Log.warningf("out waitForExclusionSet: %s", ringIDAndVersionPair);
}
*/
private void readInitialExclusions(MetaClient mc) throws KeeperException {
ExclusionZK exclusionZK;
ExclusionSet instanceExclusionSet;
ExclusionSet exclusionSet;
RingTree newRingTree;
ResolvedReplicaMap newResolvedReplicaMap;
Log.warning("RingMapState reading initial exclusions");
exclusionZK = new ExclusionZK(mc);
try {
exclusionSet = exclusionZK.readLatestFromZK();
} catch (Exception e) {
Log.logErrorWarning(e);
Log.warning("No ExclusionSet found. Using empty set.");
exclusionSet = ExclusionSet.emptyExclusionSet(0);
}
curExclusionSet = exclusionSet;
Log.warning("curExclusionSet initialized:\n", curExclusionSet);
try {
instanceExclusionSet = new ExclusionSet(new ServerSetExtensionZK(dhtMC, dhtMC.getMetaPaths().getInstanceExclusionsPath()).readLatestFromZK());
} catch (Exception e) {
Log.logErrorWarning(e);
Log.warning("No instance ExclusionSet found. Using empty set.");
instanceExclusionSet = ExclusionSet.emptyExclusionSet(0);
}
curInstanceExclusionSet = instanceExclusionSet;
Log.warning("curInstanceExclusionSet initialized:\n", curInstanceExclusionSet);
try {
newRingTree = RingTreeBuilder.removeExcludedNodes(rawRingTree, ExclusionSet.union(curExclusionSet, curInstanceExclusionSet));
} catch (Exception e) {
Log.logErrorWarning(e);
throw new RuntimeException(e);
}
newResolvedReplicaMap = newRingTree.getResolvedMap(ringConfig.getRingParentName(), new ReplicaNaiveIPPrioritizer());
ringTreeMinusExclusions = newRingTree;
resolvedReplicaMapMinusExclusions = newResolvedReplicaMap;
System.out.println("\tResolved Map");
resolvedReplicaMapMinusExclusions.display();
Log.warning("RingMapState done reading initial exclusions");
}
use of com.ms.silverking.cloud.meta.ExclusionZK in project SilverKing by Morgan-Stanley.
the class RingMapState2 method readInitialExclusions.
private void readInitialExclusions(MetaClient mc) throws KeeperException {
ExclusionZK exclusionZK;
ExclusionSet instanceExclusionSet;
ExclusionSet exclusionSet;
RingTree newRingTree;
ResolvedReplicaMap newResolvedReplicaMap;
Log.warning("RingMapState reading initial exclusions");
exclusionZK = new ExclusionZK(mc);
try {
exclusionSet = exclusionZK.readLatestFromZK();
} catch (Exception e) {
Log.logErrorWarning(e);
Log.warning("No ExclusionSet found. Using empty set.");
exclusionSet = ExclusionSet.emptyExclusionSet(0);
}
curExclusionSet = exclusionSet;
Log.warning("curExclusionSet initialized:\n", curExclusionSet);
try {
instanceExclusionSet = new ExclusionSet(new ServerSetExtensionZK(dhtMC, dhtMC.getMetaPaths().getInstanceExclusionsPath()).readLatestFromZK());
} catch (Exception e) {
Log.logErrorWarning(e);
Log.warning("No instance ExclusionSet found. Using empty set.");
instanceExclusionSet = ExclusionSet.emptyExclusionSet(0);
}
curInstanceExclusionSet = instanceExclusionSet;
Log.warning("curInstanceExclusionSet initialized:\n", curInstanceExclusionSet);
curUnionExclusionSet = ExclusionSet.union(curExclusionSet, curInstanceExclusionSet);
Log.warningf("curUnionExclusionSet initialized: %s", curUnionExclusionSet);
try {
newRingTree = RingTreeBuilder.removeExcludedNodes(rawRingTree, curUnionExclusionSet);
} catch (Exception e) {
Log.logErrorWarning(e);
throw new RuntimeException(e);
}
newResolvedReplicaMap = newRingTree.getResolvedMap(ringConfig.getRingParentName(), new SimpleIPDistancePrioritizer(nodeID, defaultIPDistanceMask));
ringTreeMinusExclusions = newRingTree;
resolvedReplicaMapMinusExclusions = newResolvedReplicaMap;
if (Log.levelMet(Level.INFO)) {
System.out.println("\tResolved Map");
resolvedReplicaMapMinusExclusions.display();
}
Log.warning("RingMapState done reading initial exclusions");
}
Aggregations