forked from voldemort/voldemort
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Partition balance analysis tool for more than two zones.
- Started a directory for all of our tools (src/java/voldemort/tools) - PartitionBalance : - broke this util out of ClusterInstance to make it more self-contained - this changed the declaration of a lot of the methods that invoked analyzeBalance and analyzeBalanceVerbose - ClusterInstanceTest : Added a bunch of tests to confirm that partition balance can be constructed (or not) for combinations of 2 & 3 zones
- Loading branch information
Showing
10 changed files
with
1,003 additions
and
363 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
/* | ||
* Copyright 2012-2013 LinkedIn, Inc | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
* use this file except in compliance with the License. You may obtain a copy of | ||
* the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
|
||
package voldemort.tools; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
import joptsimple.OptionException; | ||
import joptsimple.OptionParser; | ||
import joptsimple.OptionSet; | ||
|
||
import org.apache.log4j.Logger; | ||
|
||
import voldemort.cluster.Cluster; | ||
import voldemort.store.StoreDefinition; | ||
import voldemort.utils.ClusterInstance; | ||
import voldemort.utils.CmdUtils; | ||
import voldemort.utils.PartitionBalance; | ||
import voldemort.utils.Utils; | ||
import voldemort.xml.ClusterMapper; | ||
import voldemort.xml.StoreDefinitionsMapper; | ||
|
||
import com.google.common.base.Joiner; | ||
|
||
public class PartitionAnalysisCLI { | ||
|
||
private final static Logger logger = Logger.getLogger(PartitionAnalysisCLI.class); | ||
|
||
private static OptionParser parser; | ||
|
||
private static void setupParser() { | ||
parser = new OptionParser(); | ||
parser.accepts("help", "Print usage information"); | ||
parser.accepts("cluster", "Path to cluster xml") | ||
.withRequiredArg() | ||
.describedAs("cluster.xml"); | ||
parser.accepts("stores", "Path to store definition xml") | ||
.withRequiredArg() | ||
.describedAs("stores.xml"); | ||
} | ||
|
||
private static void printUsage() { | ||
StringBuilder help = new StringBuilder(); | ||
help.append("PartitionAnalysisCLI\n"); | ||
help.append(" Analyzes the partition layout of a cluster based on the storage " | ||
+ "definitions for that cluster. Determines how well balanced the " | ||
+ "partition layout is.\n"); | ||
help.append("Options:\n"); | ||
help.append(" Required:\n"); | ||
help.append(" --cluster <clusterXML>\n"); | ||
help.append(" --stores <storesXML>\n"); | ||
|
||
try { | ||
parser.printHelpOn(System.out); | ||
} catch(IOException e) { | ||
e.printStackTrace(); | ||
} | ||
System.out.print(help.toString()); | ||
} | ||
|
||
private static void printUsageAndDie(String errMessage) { | ||
printUsage(); | ||
Utils.croak("\n" + errMessage); | ||
} | ||
|
||
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, "cluster", "stores"); | ||
if(missing.size() > 0) { | ||
printUsageAndDie("Missing required arguments: " + Joiner.on(", ").join(missing)); | ||
} | ||
|
||
return options; | ||
} | ||
|
||
public static void main(String[] args) throws Exception { | ||
setupParser(); | ||
OptionSet options = getValidOptions(args); | ||
|
||
String clusterXML = (String) options.valueOf("cluster"); | ||
String storesXML = (String) options.valueOf("stores"); | ||
|
||
Cluster currentCluster = new ClusterMapper().readCluster(new File(clusterXML)); | ||
List<StoreDefinition> storeDefs = new StoreDefinitionsMapper().readStoreList(new File(storesXML)); | ||
|
||
PartitionBalance partitionBalance = new ClusterInstance(currentCluster, storeDefs).getPartitionBalance(); | ||
System.out.println(partitionBalance); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.