Search in sources :

Example 61 with OptionSet

use of joptsimple.OptionSet 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 62 with OptionSet

use of joptsimple.OptionSet 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 63 with OptionSet

use of joptsimple.OptionSet in project voldemort by voldemort.

the class RebalancePlanCLI method getValidOptions.

private static OptionSet getValidOptions(String[] args) {
    OptionSet options = null;
    try {
        options = parser.parse(args);
    } catch (OptionException oe) {
        printUsageAndDie("Exception when parsing arguments : " + oe.getMessage());
    }
    if (options.has("help")) {
        printUsage();
        System.exit(0);
    }
    Set<String> missing = CmdUtils.missing(options, "current-cluster", "current-stores", "final-cluster");
    if (missing.size() > 0) {
        printUsageAndDie("Missing required arguments: " + Joiner.on(", ").join(missing));
    }
    if (options.has("final-stores") && !options.has("final-cluster")) {
        printUsageAndDie("final-stores specified, but final-cluster not specified.");
    }
    return options;
}
Also used : OptionException(joptsimple.OptionException) OptionSet(joptsimple.OptionSet)

Example 64 with OptionSet

use of joptsimple.OptionSet in project voldemort by voldemort.

the class DeleteKeysCLI method main.

public static void main(String[] args) throws Exception {
    OptionParser parser = null;
    OptionSet options = null;
    try {
        parser = setupParser();
        options = parser.parse(args);
    } catch (OptionException oe) {
        parser.printHelpOn(System.out);
        printUsageAndDie("Exception when parsing arguments : " + oe.getMessage());
        return;
    }
    /* validate options */
    if (options.has("help")) {
        printUsage();
        return;
    }
    if (!options.hasArgument("url") || !options.hasArgument("stores") || !options.hasArgument("keyfile")) {
        printUsageAndDie("Missing a required argument.");
        return;
    }
    boolean deleteAllVersions = options.has("delete-all-versions");
    System.out.println("New Delete All versions value " + deleteAllVersions);
    String url = (String) options.valueOf("url");
    String keyFile = (String) options.valueOf("keyfile");
    keyFile.replace("~", System.getProperty("user.home"));
    int zoneId = Zone.DEFAULT_ZONE_ID;
    if (options.hasArgument("zone")) {
        zoneId = ((Integer) options.valueOf("zone")).intValue();
    }
    int qps = ((Integer) options.valueOf("qps")).intValue();
    int nodeid = ((Integer) options.valueOf("nodeid")).intValue();
    String adminUrl = "";
    if (nodeid != -1) {
        adminUrl = (String) options.valueOf("admin-url");
    }
    List<String> stores = null;
    if (options.hasArgument("stores")) {
        @SuppressWarnings("unchecked") List<String> list = (List<String>) options.valuesOf("stores");
        stores = list;
    }
    int checkKeysCount = 0;
    if (options.hasArgument("check-keys-exist")) {
        checkKeysCount = ((Integer) options.valueOf("check-keys-exist")).intValue();
        if (checkKeysCount <= 0) {
            throw new Exception("Expect a positive value for check-keys-exist");
        }
    }
    DeleteKeysCLI deleteKeysCLI = new DeleteKeysCLI(url, adminUrl, stores, keyFile, zoneId, qps, nodeid, deleteAllVersions, checkKeysCount);
    deleteKeysCLI.deleteKeys();
}
Also used : OptionException(joptsimple.OptionException) ArrayList(java.util.ArrayList) List(java.util.List) OptionSet(joptsimple.OptionSet) OptionParser(joptsimple.OptionParser) OptionException(joptsimple.OptionException) IOException(java.io.IOException)

Example 65 with OptionSet

use of joptsimple.OptionSet in project voldemort by voldemort.

the class ValidateNodeIdCLI method main.

public static void main(String[] args) throws IOException {
    OptionParser parser = null;
    OptionSet options = null;
    try {
        parser = setupParser();
        options = parser.parse(args);
    } catch (OptionException oe) {
        parser.printHelpOn(System.out);
        printUsageAndDie("Exception when parsing arguments : " + oe.getMessage());
        return;
    }
    /* validate options */
    if (options.has("help")) {
        printUsage();
        return;
    }
    if (!options.hasArgument("id") || !options.hasArgument("path")) {
        printUsageAndDie("Missing a required argument.");
        return;
    }
    String id = (String) options.valueOf("id");
    int expectedNodeId = Integer.parseInt(id);
    String clusterPaths = getFilePath(options, "path");
    String[] allPaths = clusterPaths.split(",");
    boolean isMatch = false;
    for (String path : allPaths) {
        path = path.replace("~", System.getProperty("user.home"));
        File filePath = new File(path);
        if (filePath.exists()) {
            isMatch = true;
            Cluster cluster = getCluster(filePath);
            Properties properties = new Properties();
            properties.setProperty(VoldemortConfig.ENABLE_NODE_ID_DETECTION, Boolean.toString(true));
            properties.setProperty(VoldemortConfig.VOLDEMORT_HOME, getTempDirPath());
            VoldemortConfig config = new VoldemortConfig(properties);
            int actualNodeId = VoldemortServer.getNodeId(config, cluster);
            if (actualNodeId != expectedNodeId) {
                throw new VoldemortApplicationException("Mismatch detected. Computed Node Id " + actualNodeId + " Expected " + expectedNodeId);
            } else {
                System.out.println("Expected and Computed node Id matched " + expectedNodeId);
            }
            config.setNodeId(actualNodeId);
            VoldemortServer.validateNodeId(config, cluster);
            System.out.println("Validation of node Id passed");
        }
    }
    if (!isMatch) {
        throw new VoldemortApplicationException("None of the paths matched the cluster.xml");
    }
}
Also used : VoldemortApplicationException(voldemort.VoldemortApplicationException) OptionException(joptsimple.OptionException) Cluster(voldemort.cluster.Cluster) OptionSet(joptsimple.OptionSet) Properties(java.util.Properties) OptionParser(joptsimple.OptionParser) File(java.io.File) VoldemortConfig(voldemort.server.VoldemortConfig)

Aggregations

OptionSet (joptsimple.OptionSet)121 OptionParser (joptsimple.OptionParser)93 File (java.io.File)40 OptionException (joptsimple.OptionException)22 IOException (java.io.IOException)20 List (java.util.List)16 Cluster (voldemort.cluster.Cluster)13 ArrayList (java.util.ArrayList)12 Test (org.junit.Test)12 StoreDefinition (voldemort.store.StoreDefinition)12 ClusterMapper (voldemort.xml.ClusterMapper)10 StoreDefinitionsMapper (voldemort.xml.StoreDefinitionsMapper)9 FileNotFoundException (java.io.FileNotFoundException)6 VoldemortException (voldemort.VoldemortException)6 BufferedReader (java.io.BufferedReader)5 Properties (java.util.Properties)5 OptionSpec (joptsimple.OptionSpec)5 Node (voldemort.cluster.Node)5 ByteArray (voldemort.utils.ByteArray)5 Closer (com.google.common.io.Closer)4