Search in sources :

Example 1 with NamedRingConfiguration

use of com.ms.silverking.cloud.toporing.meta.NamedRingConfiguration 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;
    }
}
Also used : MetaClient(com.ms.silverking.cloud.toporing.meta.MetaClient) HostGroupTable(com.ms.silverking.cloud.config.HostGroupTable) RingConfiguration(com.ms.silverking.cloud.toporing.meta.RingConfiguration) NamedRingConfiguration(com.ms.silverking.cloud.toporing.meta.NamedRingConfiguration) RingConfigurationZK(com.ms.silverking.cloud.toporing.meta.RingConfigurationZK) ExclusionZK(com.ms.silverking.cloud.meta.ExclusionZK) NamedRingConfiguration(com.ms.silverking.cloud.toporing.meta.NamedRingConfiguration) Topology(com.ms.silverking.cloud.topology.Topology) StoragePolicyZK(com.ms.silverking.cloud.storagepolicy.StoragePolicyZK) IOException(java.io.IOException) StoragePolicyGroup(com.ms.silverking.cloud.storagepolicy.StoragePolicyGroup) WeightSpecifications(com.ms.silverking.cloud.toporing.meta.WeightSpecifications) TopologyZK(com.ms.silverking.cloud.topology.TopologyZK) CloudConfiguration(com.ms.silverking.cloud.meta.CloudConfiguration) ExclusionSet(com.ms.silverking.cloud.meta.ExclusionSet) HostGroupTableZK(com.ms.silverking.cloud.meta.HostGroupTableZK) KeeperException(org.apache.zookeeper.KeeperException)

Example 2 with NamedRingConfiguration

use of com.ms.silverking.cloud.toporing.meta.NamedRingConfiguration in project SilverKing by Morgan-Stanley.

the class DHTMetaWatcher method readRing.

// FIXME - think about zkidLimit
public void readRing(String ringName, long zkidLimit) throws KeeperException, IOException {
    com.ms.silverking.cloud.toporing.meta.MetaClient ringMC;
    // com.ms.silverking.cloud.meta.MetaClient             cloudMC;
    NamedRingConfiguration namedRingConfig;
    RingConfiguration ringConfig;
    InstantiatedRingTree ringTree;
    long ringConfigVersion;
    long configInstanceVersion;
    DHTMetaUpdate dhtMetaUpdate;
    int readAttemptIndex;
    int ringReadAttempts = 20;
    int ringReadRetryInvervalSeconds = 2;
    ZooKeeperExtended zk;
    // cloudMC = new com.ms.silverking.cloud.meta.MetaClient(ringConfig.getCloudConfiguration(),
    // zkConfig);
    zk = mc.getZooKeeper();
    // unresolved
    namedRingConfig = new NamedRingConfiguration(ringName, RingConfiguration.emptyTemplate);
    ringMC = new com.ms.silverking.cloud.toporing.meta.MetaClient(namedRingConfig, zkConfig);
    ringConfigVersion = zk.getVersionPriorTo(ringMC.getMetaPaths().getConfigPath(), zkidLimit);
    ringConfig = new RingConfigurationZK(ringMC).readFromZK(ringConfigVersion, null);
    // resolved
    namedRingConfig = new NamedRingConfiguration(ringName, ringConfig);
    ringMC = new com.ms.silverking.cloud.toporing.meta.MetaClient(namedRingConfig, zkConfig);
    if (enableLogging) {
        Log.warning("ringConfig\t", ringConfig);
    }
    configInstanceVersion = zk.getVersionPriorTo(ringMC.getMetaPaths().getConfigInstancePath(ringConfigVersion), zkidLimit);
    if (enableLogging) {
        Log.warning("configInstanceVersion: " + configInstanceVersion);
    }
    if (configInstanceVersion == -1) {
        configInstanceVersion = 0;
    }
    if (DHTConstants.isDaemon || Log.levelMet(Level.INFO)) {
        Log.warning("Waiting until valid " + ringMC.getMetaPaths().getConfigInstancePath(ringConfigVersion) + " " + configInstanceVersion);
    }
    SingleRingZK.waitUntilValid(ringMC, ringMC.getMetaPaths().getConfigInstancePath(ringConfigVersion), configInstanceVersion);
    if (DHTConstants.isDaemon || Log.levelMet(Level.INFO)) {
        Log.warning("Valid");
    }
    ringTree = null;
    readAttemptIndex = 0;
    while (ringTree == null) {
        try {
            // , weightsVersion);
            ringTree = SingleRingZK.readTree(ringMC, ringConfigVersion, configInstanceVersion);
        } catch (Exception e) {
            if (++readAttemptIndex >= ringReadAttempts) {
                throw new RuntimeException("Ring read failed", e);
            } else {
                ThreadUtil.sleepSeconds(ringReadRetryInvervalSeconds);
            }
        }
    }
    if (enableLogging) {
        Log.warning("\t\t###\t" + ringConfigVersion + "\t" + configInstanceVersion);
    }
    dhtMetaUpdate = new DHTMetaUpdate(dhtConfig, namedRingConfig, ringTree, mc);
    notifyListeners(dhtMetaUpdate);
// ringUpdateListener.newRingTree(new NamedRingConfiguration(ringName, ringConfig), ringTree);
// ringUpdateListener.newRingTree(ringTree.getMap(ringConfig.getRingParentName()));
}
Also used : RingConfigurationZK(com.ms.silverking.cloud.toporing.meta.RingConfigurationZK) NamedRingConfiguration(com.ms.silverking.cloud.toporing.meta.NamedRingConfiguration) ZooKeeperExtended(com.ms.silverking.cloud.zookeeper.ZooKeeperExtended) InstantiatedRingTree(com.ms.silverking.cloud.toporing.InstantiatedRingTree) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException) RingConfiguration(com.ms.silverking.cloud.toporing.meta.RingConfiguration) NamedRingConfiguration(com.ms.silverking.cloud.toporing.meta.NamedRingConfiguration)

Example 3 with NamedRingConfiguration

use of com.ms.silverking.cloud.toporing.meta.NamedRingConfiguration in project SilverKing by Morgan-Stanley.

the class DHTMetaReader method readRing.

public DHTMetaUpdate readRing(String ringName, long ringConfigVersion, long configInstanceVersion) throws KeeperException, IOException {
    com.ms.silverking.cloud.toporing.meta.MetaClient ringMC;
    NamedRingConfiguration namedRingConfig;
    RingConfiguration ringConfig;
    InstantiatedRingTree ringTree;
    // long                ringConfigVersion;
    // long                configInstanceVersion;
    int readAttemptIndex;
    int ringReadAttempts = 20;
    int ringReadRetryInvervalSeconds = 2;
    ZooKeeperExtended zk;
    zk = mc.getZooKeeper();
    if (EmbeddedSK.embedded()) {
        namedRingConfig = EmbeddedSK.getEmbeddedNamedRingConfiguration(ringName);
    } else {
        // unresolved
        namedRingConfig = new NamedRingConfiguration(ringName, RingConfiguration.emptyTemplate);
        ringMC = new com.ms.silverking.cloud.toporing.meta.MetaClient(namedRingConfig, zkConfig);
        // ringConfigVersion = zk.getVersionPriorTo(ringMC.getMetaPaths().getConfigPath(), zkidLimit);
        try {
            ringConfig = new RingConfigurationZK(ringMC).readFromZK(ringConfigVersion, null);
        } catch (Exception e) {
            Log.warning("Ignoring: ", e);
            ringConfig = new RingConfiguration(new CloudConfiguration(null, null, null), null, null, null, null, null);
        }
        // resolved
        namedRingConfig = new NamedRingConfiguration(ringName, ringConfig);
        if (enableLogging) {
            Log.warning("ringConfig\t", ringConfig);
        }
    }
    ringMC = new com.ms.silverking.cloud.toporing.meta.MetaClient(namedRingConfig, zkConfig);
    // configInstanceVersion = zk.getVersionPriorTo(ringMC.getMetaPaths().getConfigInstancePath(ringConfigVersion), zkidLimit);
    if (enableLogging) {
        Log.warning("configInstanceVersion: " + configInstanceVersion);
    }
    if (configInstanceVersion < 0) {
        throw new RuntimeException("Invalid configInstanceVersion: " + configInstanceVersion);
    }
    // if (configInstanceVersion == -1) {
    // configInstanceVersion = 0;
    // }
    // FUTURE - we shouldn't get here unless it's valid. Think about error messages if invalid, instead of waiting.
    Log.warning("Waiting until valid " + ringMC.getMetaPaths().getConfigInstancePath(ringConfigVersion) + " " + configInstanceVersion);
    SingleRingZK.waitUntilValid(ringMC, ringMC.getMetaPaths().getConfigInstancePath(ringConfigVersion), configInstanceVersion);
    Log.warning("Valid");
    ringTree = null;
    readAttemptIndex = 0;
    while (ringTree == null) {
        try {
            // , weightsVersion);
            ringTree = SingleRingZK.readTree(ringMC, ringConfigVersion, configInstanceVersion);
        } catch (Exception e) {
            if (++readAttemptIndex >= ringReadAttempts) {
                throw new RuntimeException("Ring read failed", e);
            } else {
                ThreadUtil.sleepSeconds(ringReadRetryInvervalSeconds);
            }
        }
    }
    if (enableLogging) {
        Log.warning("\t\t###\t" + ringConfigVersion + "\t" + configInstanceVersion);
    }
    return new DHTMetaUpdate(dhtConfig, namedRingConfig, ringTree, mc);
}
Also used : RingConfigurationZK(com.ms.silverking.cloud.toporing.meta.RingConfigurationZK) NamedRingConfiguration(com.ms.silverking.cloud.toporing.meta.NamedRingConfiguration) ZooKeeperExtended(com.ms.silverking.cloud.zookeeper.ZooKeeperExtended) InstantiatedRingTree(com.ms.silverking.cloud.toporing.InstantiatedRingTree) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException) RingConfiguration(com.ms.silverking.cloud.toporing.meta.RingConfiguration) NamedRingConfiguration(com.ms.silverking.cloud.toporing.meta.NamedRingConfiguration) CloudConfiguration(com.ms.silverking.cloud.meta.CloudConfiguration)

Example 4 with NamedRingConfiguration

use of com.ms.silverking.cloud.toporing.meta.NamedRingConfiguration in project SilverKing by Morgan-Stanley.

the class SKAdmin method readCurrentTree.

public InstantiatedRingTree readCurrentTree() throws KeeperException, IOException {
    DHTRingCurTargetZK curTargetZK;
    Triple<String, Long, Long> curRingAndVersionPair;
    InstantiatedRingTree ringTree;
    curTargetZK = new DHTRingCurTargetZK(dhtMC, dhtConfig);
    curRingAndVersionPair = curTargetZK.getCurRingAndVersionPair();
    ringTree = SingleRingZK.readTree(new com.ms.silverking.cloud.toporing.meta.MetaClient(new NamedRingConfiguration(dhtConfig.getRingName(), ringConfig), dhtMC.getZooKeeper().getZKConfig()), curRingAndVersionPair.getTail());
    return ringTree;
}
Also used : DHTRingCurTargetZK(com.ms.silverking.cloud.dht.meta.DHTRingCurTargetZK) NamedRingConfiguration(com.ms.silverking.cloud.toporing.meta.NamedRingConfiguration) InstantiatedRingTree(com.ms.silverking.cloud.toporing.InstantiatedRingTree)

Aggregations

NamedRingConfiguration (com.ms.silverking.cloud.toporing.meta.NamedRingConfiguration)4 InstantiatedRingTree (com.ms.silverking.cloud.toporing.InstantiatedRingTree)3 RingConfiguration (com.ms.silverking.cloud.toporing.meta.RingConfiguration)3 RingConfigurationZK (com.ms.silverking.cloud.toporing.meta.RingConfigurationZK)3 IOException (java.io.IOException)3 KeeperException (org.apache.zookeeper.KeeperException)3 CloudConfiguration (com.ms.silverking.cloud.meta.CloudConfiguration)2 ZooKeeperExtended (com.ms.silverking.cloud.zookeeper.ZooKeeperExtended)2 HostGroupTable (com.ms.silverking.cloud.config.HostGroupTable)1 DHTRingCurTargetZK (com.ms.silverking.cloud.dht.meta.DHTRingCurTargetZK)1 ExclusionSet (com.ms.silverking.cloud.meta.ExclusionSet)1 ExclusionZK (com.ms.silverking.cloud.meta.ExclusionZK)1 HostGroupTableZK (com.ms.silverking.cloud.meta.HostGroupTableZK)1 StoragePolicyGroup (com.ms.silverking.cloud.storagepolicy.StoragePolicyGroup)1 StoragePolicyZK (com.ms.silverking.cloud.storagepolicy.StoragePolicyZK)1 Topology (com.ms.silverking.cloud.topology.Topology)1 TopologyZK (com.ms.silverking.cloud.topology.TopologyZK)1 MetaClient (com.ms.silverking.cloud.toporing.meta.MetaClient)1 WeightSpecifications (com.ms.silverking.cloud.toporing.meta.WeightSpecifications)1