use of com.ms.silverking.cloud.dht.meta.DHTRingCurTargetZK in project SilverKing by Morgan-Stanley.
the class DependencyWatcher method setRing.
private void setRing(long ringConfigVersion) throws KeeperException {
long configInstanceVersion;
String newInstancePath;
DHTRingCurTargetZK dhtRingCurTargetZK;
String ringName;
configInstanceVersion = mc.getLatestConfigInstanceVersion(ringConfigVersion);
mc.getLatestConfigInstanceVersion(ringConfigVersion);
dhtRingCurTargetZK = new DHTRingCurTargetZK(dhtMC, dhtMC.getDHTConfiguration());
ringName = dhtMC.getDHTConfiguration().getRingName();
dhtRingCurTargetZK.setCurRingAndVersionPair(ringName, ringConfigVersion, configInstanceVersion);
dhtRingCurTargetZK.setTargetRingAndVersionPair(ringName, ringConfigVersion, configInstanceVersion);
Log.warningf("Ring %s config %d instance %d", ringName, ringConfigVersion, configInstanceVersion);
}
use of com.ms.silverking.cloud.dht.meta.DHTRingCurTargetZK in project SilverKing by Morgan-Stanley.
the class SKAdmin method getRing.
private static Pair<RingConfiguration, InstantiatedRingTree> getRing(DHTConfiguration dhtConfig, com.ms.silverking.cloud.dht.meta.MetaClient dhtMC) throws IOException, KeeperException {
String ringName;
Pair<Long, Long> ringVersion;
DHTRingCurTargetZK dhtRingCurTargetZK;
Triple<String, Long, Long> curRingNameAndVersion;
RingConfiguration ringConfig;
RingConfigurationZK ringConfigZK;
InstantiatedRingTree ringTree;
com.ms.silverking.cloud.toporing.meta.MetaClient ringMC;
dhtRingCurTargetZK = new DHTRingCurTargetZK(dhtMC, dhtConfig);
curRingNameAndVersion = dhtRingCurTargetZK.getCurRingAndVersionPair();
if (curRingNameAndVersion == null) {
return null;
}
ringName = curRingNameAndVersion.getHead();
ringVersion = curRingNameAndVersion.getTail();
ringMC = com.ms.silverking.cloud.toporing.meta.MetaClient.createMetaClient(ringName, ringVersion.getV1(), dhtMC.getZooKeeper().getZKConfig());
ringConfigZK = new RingConfigurationZK(ringMC);
ringConfig = ringConfigZK.readFromZK(ringVersion.getV1(), null);
// ringTree = SingleRingZK.readTree(ringMC, ringVersion);
// FUTURE - think about whether or not we should keep this, currently unused
ringTree = null;
return new Pair<>(ringConfig, ringTree);
}
use of com.ms.silverking.cloud.dht.meta.DHTRingCurTargetZK in project SilverKing by Morgan-Stanley.
the class EmbeddedSK method createEmbeddedSKInstance.
public static ClientDHTConfiguration createEmbeddedSKInstance(String dhtName, String gridConfigName, String ringName, int replication) {
try {
int zkPort;
Path tempDir;
File zkDir;
File skDir;
ZooKeeperConfig zkConfig;
// 0) Create LWT work pools
LWTPoolProvider.createDefaultWorkPools();
// 1) Start an embedded ZooKeeper
Log.warning("Creating embedded ZooKeeper");
try {
tempDir = Files.createTempDirectory(null);
zkDir = new File(tempDir.toFile(), "zookeeper");
zkDir.mkdirs();
skDir = new File(tempDir.toFile(), "silverking");
skDir.mkdirs();
} catch (IOException ioe) {
throw new RuntimeException(ioe);
}
zkPort = LocalZKImpl.startLocalZK(zkDir.getAbsolutePath());
zkConfig = new ZooKeeperConfig(InetAddress.getLoopbackAddress().getHostAddress() + ":" + zkPort);
Log.warning("Embedded ZooKeeper running at: " + zkConfig);
DHTNodeConfiguration.setDataBasePath(skDir.getAbsolutePath() + "/data");
// 2) Create ring in ZK
Log.warning("Creating ring");
StaticRingCreator.createStaticRing(ringName, zkConfig, ImmutableSet.of(IPAddrUtil.localIPString()), replication);
Log.warning("Created: " + ringName);
// 3) Create DHT Config in ZK
DHTConfiguration dhtConfig;
MetaClient dhtMC;
DHTConfigurationZK dhtConfigZK;
ClientDHTConfiguration clientDHTConfig;
int dhtPort;
Log.warning("Creating DHT configuration in ZK");
if (skPort <= 0) {
// FIXME
dhtPort = ThreadLocalRandom.current().nextInt(10000, 20000);
} else {
dhtPort = skPort;
}
clientDHTConfig = new ClientDHTConfiguration(dhtName, dhtPort, zkConfig);
dhtMC = new MetaClient(clientDHTConfig);
dhtConfigZK = new DHTConfigurationZK(dhtMC);
dhtConfig = DHTConfiguration.emptyTemplate.ringName(ringName).port(dhtPort).passiveNodeHostGroups("").hostGroupToClassVarsMap(new HashMap<String, String>());
dhtConfigZK.writeToZK(dhtConfig, null);
Log.warning("Created DHT configuration in ZK");
// 4) Set cur and target rings
DHTRingCurTargetZK curTargetZK;
Log.warning("Setting ring targets");
curTargetZK = new DHTRingCurTargetZK(dhtMC, dhtConfig);
curTargetZK.setCurRingAndVersionPair(ringName, 0, 0);
curTargetZK.setTargetRingAndVersionPair(ringName, 0, 0);
Log.warning("Ring targets set");
// 4) Start DHTNode
Log.warning("Starting DHTNode");
new DHTNode(dhtName, zkConfig, 0, false, false);
Log.warning("DHTNode started");
// 5) Return the configuration to the caller
return clientDHTConfig;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of com.ms.silverking.cloud.dht.meta.DHTRingCurTargetZK in project SilverKing by Morgan-Stanley.
the class MasterModeDependencyWatcher method readMasterRingTree.
private Pair<RingTree, Triple<String, Long, Long>> readMasterRingTree(com.ms.silverking.cloud.dht.meta.MetaClient dhtMC, DHTConfiguration dhtConfig) throws KeeperException, IOException {
DHTRingCurTargetZK dhtRingCurTargetZK;
Triple<String, Long, Long> masterRingAndVersionPair;
RingTree ringTree;
dhtRingCurTargetZK = new DHTRingCurTargetZK(dhtMC, dhtConfig);
masterRingAndVersionPair = dhtRingCurTargetZK.getMasterRingAndVersionPair();
if (masterRingAndVersionPair == null) {
throw new RuntimeException("Can't find master ring");
} else {
ringTree = SingleRingZK.readTree(mc, masterRingAndVersionPair.getV2(), masterRingAndVersionPair.getV3());
return new Pair<>(ringTree, masterRingAndVersionPair);
}
}
use of com.ms.silverking.cloud.dht.meta.DHTRingCurTargetZK in project SilverKing by Morgan-Stanley.
the class SKAdmin method verifyServerEligibility.
private void verifyServerEligibility(Set<String> servers, SKAdminCommand[] commands) throws KeeperException {
if (Arrays.contains(commands, SKAdminCommand.StartNodes)) {
Set<String> candidateServers;
Set<String> ineligibleServers;
DHTRingCurTargetZK dhtRingCurTargetZK;
InstanceExclusionZK instanceExclusionZK;
dhtRingCurTargetZK = new DHTRingCurTargetZK(dhtMC, dhtMC.getDHTConfiguration());
instanceExclusionZK = new InstanceExclusionZK(dhtMC);
Log.warning("Verifying server eligibility for start");
candidateServers = new HashSet<>(servers);
ineligibleServers = HealthMonitor.removeIneligibleServers(candidateServers, dhtRingCurTargetZK, instanceExclusionZK);
if (ineligibleServers.size() > 0) {
for (String ineligibleServer : ineligibleServers) {
Log.warning("Ineligible server: ", ineligibleServer);
}
if (!options.forceInclusionOfUnsafeExcludedServers) {
throw new IneligibleServerException("Attempted to start ineligible servers: " + CollectionUtil.toString(ineligibleServers, ','));
} else {
Log.countdownWarning("*** Including unsafe excluded servers. This may result in data loss ***", unsafeWarningCountdown);
}
} else {
Log.warning("Server eligibility verified");
}
}
}
Aggregations