Search in sources :

Example 21 with ClusterMapper

use of voldemort.xml.ClusterMapper in project voldemort by voldemort.

the class RebalanceControllerCLI method main.

public static void main(String[] args) throws Exception {
    setupParser();
    OptionSet options = getValidOptions(args);
    // Bootstrap & fetch current cluster/stores
    String bootstrapURL = (String) options.valueOf("url");
    int parallelism = RebalanceController.MAX_PARALLEL_REBALANCING;
    if (options.has("parallelism")) {
        parallelism = (Integer) options.valueOf("parallelism");
    }
    long proxyPauseSec = RebalanceController.PROXY_PAUSE_IN_SECONDS;
    if (options.has("proxy-pause")) {
        proxyPauseSec = (Long) options.valueOf("proxy-pause");
    }
    RebalanceController rebalanceController = new RebalanceController(bootstrapURL, parallelism, proxyPauseSec);
    Cluster currentCluster = rebalanceController.getCurrentCluster();
    List<StoreDefinition> currentStoreDefs = rebalanceController.getCurrentStoreDefs();
    // If this test doesn't pass, something is wrong in prod!
    RebalanceUtils.validateClusterStores(currentCluster, currentStoreDefs);
    // Determine final cluster/stores and validate them
    String finalClusterXML = (String) options.valueOf("final-cluster");
    Cluster finalCluster = new ClusterMapper().readCluster(new File(finalClusterXML));
    List<StoreDefinition> finalStoreDefs = currentStoreDefs;
    if (options.has("final-stores")) {
        String storesXML = (String) options.valueOf("final-stores");
        finalStoreDefs = new StoreDefinitionsMapper().readStoreList(new File(storesXML));
    }
    RebalanceUtils.validateClusterStores(finalCluster, finalStoreDefs);
    RebalanceUtils.validateCurrentFinalCluster(currentCluster, finalCluster);
    // Process optional "planning" arguments
    int batchSize = CmdUtils.valueOf(options, "batch-size", RebalancePlan.BATCH_SIZE);
    String outputDir = null;
    if (options.has("output-dir")) {
        outputDir = (String) options.valueOf("output-dir");
    }
    RebalancePlan rebalancePlan = new RebalancePlan(currentCluster, currentStoreDefs, finalCluster, finalStoreDefs, batchSize, outputDir);
    boolean resetQuota = !options.has("no-reset-quota");
    Set<String> storeNames = Sets.newHashSet();
    for (StoreDefinition storeDef : finalStoreDefs) {
        storeNames.add(storeDef.getName());
    }
    QuotaResetter quotaResetter = new QuotaResetter(bootstrapURL, storeNames, rebalancePlan.getFinalCluster().getNodeIds());
    // before rebalance, remember and disable quota enforcement settings
    if (resetQuota) {
        quotaResetter.rememberAndDisableQuota();
    }
    // Plan & execute rebalancing.
    rebalanceController.rebalance(rebalancePlan);
    // after rebalance, reset quota values and recover quota enforcement
    if (resetQuota) {
        quotaResetter.resetQuotaAndRecoverEnforcement();
    }
}
Also used : RebalancePlan(voldemort.client.rebalance.RebalancePlan) StoreDefinitionsMapper(voldemort.xml.StoreDefinitionsMapper) Cluster(voldemort.cluster.Cluster) ClusterMapper(voldemort.xml.ClusterMapper) RebalanceController(voldemort.client.rebalance.RebalanceController) StoreDefinition(voldemort.store.StoreDefinition) QuotaResetter(voldemort.client.rebalance.QuotaResetter) OptionSet(joptsimple.OptionSet) File(java.io.File)

Example 22 with ClusterMapper

use of voldemort.xml.ClusterMapper in project voldemort by voldemort.

the class RebalancePlanCLI method main.

public static void main(String[] args) throws Exception {
    setupParser();
    OptionSet options = getValidOptions(args);
    // Required args
    String currentClusterXML = (String) options.valueOf("current-cluster");
    String currentStoresXML = (String) options.valueOf("current-stores");
    String finalClusterXML = (String) options.valueOf("final-cluster");
    // Required args for some use cases
    String finalStoresXML = new String(currentStoresXML);
    if (options.has("final-stores")) {
        finalStoresXML = (String) options.valueOf("final-stores");
    }
    Cluster currentCluster = new ClusterMapper().readCluster(new File(currentClusterXML));
    List<StoreDefinition> currentStoreDefs = new StoreDefinitionsMapper().readStoreList(new File(currentStoresXML));
    Cluster finalCluster = new ClusterMapper().readCluster(new File(finalClusterXML));
    List<StoreDefinition> finalStoreDefs = new StoreDefinitionsMapper().readStoreList(new File(finalStoresXML));
    // Optional args
    int batchSize = CmdUtils.valueOf(options, "batch-size", RebalancePlan.BATCH_SIZE);
    String outputDir = null;
    if (options.has("output-dir")) {
        outputDir = (String) options.valueOf("output-dir");
    }
    new RebalancePlan(currentCluster, currentStoreDefs, finalCluster, finalStoreDefs, batchSize, outputDir);
}
Also used : RebalancePlan(voldemort.client.rebalance.RebalancePlan) StoreDefinition(voldemort.store.StoreDefinition) StoreDefinitionsMapper(voldemort.xml.StoreDefinitionsMapper) Cluster(voldemort.cluster.Cluster) ClusterMapper(voldemort.xml.ClusterMapper) OptionSet(joptsimple.OptionSet) File(java.io.File)

Example 23 with ClusterMapper

use of voldemort.xml.ClusterMapper in project voldemort by voldemort.

the class ReplaceNodeCLI method init.

private void init() {
    this.adminClient = new AdminClient(this.url);
    this.newAdminClient = new AdminClient(this.newUrl);
    this.cluster = adminClient.getAdminClientCluster();
    // Validate node exists in the old cluster
    this.cluster.getNodeById(nodeId);
    this.newCluster = newAdminClient.getAdminClientCluster();
    if (newCluster.getNumberOfNodes() > 1) {
        newNodeId = nodeId;
    } else {
        newNodeId = newCluster.getNodeIds().iterator().next().intValue();
    }
    this.clusterXml = getClusterXML();
    // Update your cluster XML based on the consensus
    this.cluster = new ClusterMapper().readCluster(new StringReader(clusterXml));
    this.storesXml = getStoresXML();
    this.storeDefinitions = new StoreDefinitionsMapper().readStoreList(new StringReader(storesXml), false);
}
Also used : StringReader(java.io.StringReader) StoreDefinitionsMapper(voldemort.xml.StoreDefinitionsMapper) ClusterMapper(voldemort.xml.ClusterMapper) AdminClient(voldemort.client.protocol.admin.AdminClient)

Example 24 with ClusterMapper

use of voldemort.xml.ClusterMapper in project voldemort by voldemort.

the class StreamingSlopPusherTest method replaceOneNode.

private void replaceOneNode(int nodeId) throws IOException {
    Cluster oldCluster = cluster;
    cluster = ServerTestUtils.getLocalClusterWithOneNodeReplaced(cluster, nodeId);
    metadataStore = ServerTestUtils.createMetadataStore(cluster, new StoreDefinitionsMapper().readStoreList(new File(storesXmlfile)));
    String newClusterXml = new ClusterMapper().writeCluster(cluster);
    AdminClient adminClient = ServerTestUtils.getAdminClient(oldCluster);
    for (Integer remoteNodeId : oldCluster.getNodeIds()) {
        try {
            adminClient.metadataMgmtOps.updateRemoteMetadata(remoteNodeId, MetadataStore.CLUSTER_KEY, newClusterXml);
        } catch (UnreachableStoreException e) {
        }
    }
}
Also used : StoreDefinitionsMapper(voldemort.xml.StoreDefinitionsMapper) Cluster(voldemort.cluster.Cluster) ClusterMapper(voldemort.xml.ClusterMapper) UnreachableStoreException(voldemort.store.UnreachableStoreException) File(java.io.File) AdminClient(voldemort.client.protocol.admin.AdminClient)

Example 25 with ClusterMapper

use of voldemort.xml.ClusterMapper in project voldemort by voldemort.

the class MetaOperationsTest method testMetaGet.

@Test
public void testMetaGet() throws Exception {
    Integer nodeId = 0;
    String tempDir = System.getProperty("java.io.tmpdir") + "temp" + System.currentTimeMillis();
    // get metadata and write to files
    AdminCommand.executeCommand(new String[] { "meta", "get", MetadataStore.CLUSTER_KEY + "," + MetadataStore.STORES_KEY, "-u", bsURL, "-n", nodeId.toString(), "-d", tempDir });
    // load metadata files
    String clusterFile = tempDir + "/" + MetadataStore.CLUSTER_KEY + "_" + nodeId;
    String storesFile = tempDir + "/" + MetadataStore.STORES_KEY + "_" + nodeId;
    assertTrue(Utils.isReadableFile(clusterFile));
    assertTrue(Utils.isReadableFile(storesFile));
    ClusterMapper clusterMapper = new ClusterMapper();
    StoreDefinitionsMapper storeDefsMapper = new StoreDefinitionsMapper();
    Cluster newCluster = clusterMapper.readCluster(new File(clusterFile));
    List<StoreDefinition> newStores = storeDefsMapper.readStoreList(new File(storesFile));
    // compare metadata objects
    assertTrue(newCluster.equals(cluster));
    assertTrue(newStores.size() == stores.size());
    for (StoreDefinition store : stores) {
        assertTrue(newStores.contains(store));
    }
}
Also used : StoreDefinition(voldemort.store.StoreDefinition) StoreDefinitionsMapper(voldemort.xml.StoreDefinitionsMapper) Cluster(voldemort.cluster.Cluster) ClusterMapper(voldemort.xml.ClusterMapper) File(java.io.File) Test(org.junit.Test)

Aggregations

ClusterMapper (voldemort.xml.ClusterMapper)41 StoreDefinitionsMapper (voldemort.xml.StoreDefinitionsMapper)26 Cluster (voldemort.cluster.Cluster)23 File (java.io.File)18 StoreDefinition (voldemort.store.StoreDefinition)18 StringReader (java.io.StringReader)13 OptionSet (joptsimple.OptionSet)10 Node (voldemort.cluster.Node)10 AdminClient (voldemort.client.protocol.admin.AdminClient)9 VoldemortException (voldemort.VoldemortException)8 Test (org.junit.Test)6 ByteArray (voldemort.utils.ByteArray)6 Versioned (voldemort.versioning.Versioned)6 OptionParser (joptsimple.OptionParser)5 IOException (java.io.IOException)4 InMemoryStorageEngine (voldemort.store.memory.InMemoryStorageEngine)4 FileNotFoundException (java.io.FileNotFoundException)3 ClientConfig (voldemort.client.ClientConfig)3 SocketStoreClientFactory (voldemort.client.SocketStoreClientFactory)3 BufferedReader (java.io.BufferedReader)2