http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/49d99d4e/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/commands/classloader.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/commands/classloader.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/commands/classloader.java deleted file mode 100644 index d06ff7d..0000000 --- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/commands/classloader.java +++ /dev/null @@ -1,323 +0,0 @@ -package com.gemstone.gemfire.internal.tools.gfsh.app.commands; - -import java.io.File; -import java.io.FileFilter; -import java.lang.reflect.Method; -import java.net.URI; -import java.net.URL; -import java.net.URLClassLoader; -import java.util.ArrayList; - -import com.gemstone.gemfire.DataSerializable; -import com.gemstone.gemfire.Instantiator; -import com.gemstone.gemfire.internal.tools.gfsh.app.CommandExecutable; -import com.gemstone.gemfire.internal.tools.gfsh.app.Gfsh; -import com.gemstone.gemfire.internal.tools.gfsh.app.cache.InstantiatorClassLoader; -import com.gemstone.gemfire.internal.tools.gfsh.app.misc.util.ClassFinder; -import com.gemstone.gemfire.internal.tools.gfsh.app.pogo.KeyType; -import com.gemstone.gemfire.internal.tools.gfsh.app.pogo.KeyTypeManager; - -public class classloader implements CommandExecutable -{ - private Gfsh gfsh; - - public classloader(Gfsh gfsh) - { - this.gfsh = gfsh; - } - - public void help() - { - gfsh.println("class [-c <fully-qualified class name>] [-id <class id>]"); - gfsh.println(" [-d <DataSerializables.txt>"); - gfsh.println(" [-jar <jar paths>]"); - gfsh.println(" [-dir <dir path>]"); - gfsh.println(" [-?]"); - gfsh.println(" Load Instantiator registered data classes. All data classes"); - gfsh.println(" that use a static block to register class ids via Instantiator"); - gfsh.println(" must be preloaded using this command. Note that this command"); - gfsh.println(" is NOT equivalent to setting CLASSPATH. As always, the classes"); - gfsh.println(" and jar files must be in the class path before starting gfsh."); - gfsh.println(" Please run 'gfsh -?' to see more details."); - gfsh.println(" -c <fully-qualified class name> Load the specified class."); - gfsh.println(" The specified class typically contains a static block"); - gfsh.println(" that registers class ids using GemFire Instantiator."); - gfsh.println(" -id <class id> if the class ID for the cass name specified with"); - gfsh.println(" the option '-c' is not defined by Instantiator then"); - gfsh.println(" the '-id' option must be used to assign the class id"); - gfsh.println(" that matches the instantiator class id defined in the"); - gfsh.println(" server's cache.xml file. This options is supported for"); - gfsh.println(" GFE 6.x or greater."); - gfsh.println(" -d <DataSerializables.txt> Load the classes listed"); - gfsh.println(" in the specified file. The file path can be relative"); - gfsh.println(" or absolute."); - gfsh.println(" -jar <jar paths> Load all classes in the jar paths. The jar paths"); - gfsh.println(" can be separated by ',', ';', or ':'. The jar paths"); - gfsh.println(" can be relative or absolute."); - gfsh.println(" -dir <directory> Load all classes in the directory."); - gfsh.println(" The directory path can be relative or absolute."); - gfsh.println(); - } - - public void execute(String command) throws Exception - { - if (command.startsWith("class -?")) { - help(); - } else if (command.startsWith("class -c")) { - class_c(command); - } else if (command.startsWith("class -id")) { - class_c(command); - } else if (command.startsWith("class -dir")) { - class_dir(command); - } else if (command.startsWith("class -d")) { - class_d(command); - } else if (command.startsWith("class -jar")) { - class_jar(command); - } else { - gfsh.println("Error: invalid command - " + command); - } - } - - private void class_c(String command) - { - ArrayList list = new ArrayList(); - gfsh.parseCommand(command, list); - - if (list.size() < 2) { - gfsh.println("Error: must specify an option. Run 'class -?' for options"); - return; - } - if (list.size() < 3) { - if (list.get(1).equals("-c")) { - gfsh.println("Error: must specify a fully-qualified class name"); - } else if (list.get(1).equals("-id")) { - gfsh.println("Error: must specify the class id"); - } - return; - } - - String className = null; - boolean classIdSpecified = false; - int classId = 0; - for (int i = 1; i < list.size(); i++) { - String val = (String)list.get(i); - if (val.equals("-c")) { - i++; - if (list.size() <= i) { - gfsh.println("Error: class name not specified"); - return; - } - className = (String)list.get(i); - } else if (val.equals("-id")) { - i++; - if (list.size() <= i) { - gfsh.println("Error: class id not specified"); - return; - } - classIdSpecified = true; - try { - classId = Integer.parseInt((String)list.get(i)); - } catch (Exception ex) { - gfsh.println("Error: " + ex.getMessage()); - } - } - } - - if (className == null) { - gfsh.println("Error: class name not specified"); - return; - } - - try { - final Class clazz = Class.forName(className); - if (classIdSpecified) { - Instantiator.register(new Instantiator(clazz, classId) - { - public DataSerializable newInstance() - { - DataSerializable obj = null; - try { - obj = (DataSerializable)clazz.newInstance(); - } catch (Exception ex) { - gfsh.println("Error: unable to create a new instance of " + clazz.getCanonicalName()); - if (gfsh.isDebug()) { - ex.printStackTrace(); - } - } - return obj; - } - }); - } - gfsh.println("class loaded: " + clazz.getName()); - } catch (Exception e) { - gfsh.println("Error: " + e.getClass().getSimpleName() + " - " + e.getMessage()); - if (gfsh.isDebug()) { - e.printStackTrace(); - } - } - } - - private void class_d(String command) - { - ArrayList list = new ArrayList(); - gfsh.parseCommand(command, list); - if (list.size() < 3) { - gfsh.println("Error: must specify the file path of DataSerializables.txt"); - return; - } - - String filePath = (String)list.get(2); - - try { - InstantiatorClassLoader.loadDataSerializables(filePath); - gfsh.println(); - gfsh.println("application classes successfully loaded: " + filePath); - } catch (Exception e) { - gfsh.println("Error: " + e.getClass().getSimpleName() + " - " + e.getMessage() + ". Aborted."); - if (gfsh.isDebug()) { - e.printStackTrace(); - } - } - } - - private void class_jar(String command) - { - ArrayList list = new ArrayList(); - gfsh.parseCommand(command, list); - if (list.size() < 3) { - gfsh.println("Error: must specify the jar paths"); - return; - } - - String jarPaths = (String)list.get(2); - if (jarPaths == null) { - return; - } - jarPaths = jarPaths.trim(); - if (jarPaths.length() == 0) { - return; - } - - String pathSeparator = System.getProperty("path.separator"); - try { - jarPaths = jarPaths.replace(pathSeparator.charAt(0), ','); - String split[] = jarPaths.split(","); - URL url[] = new URL[split.length]; - ArrayList<String> classNameList = new ArrayList(); - for (int i = 0; i < split.length; i++) { - String path = split[i]; - File file = new File(path); - URI uri = file.toURI(); - url[i] = uri.toURL(); - String[] classNames = ClassFinder.getAllClassNames(path); - for (int j = 0; j < classNames.length; j++) { - classNameList.add(classNames[j]); - } - } - URLClassLoader cl = new URLClassLoader(url); - for (String className : classNameList) { - Class<?> cls = Class.forName(className, true, cl); - - // KeyType registration - if (KeyType.class.isAssignableFrom(cls) && - cls.getSimpleName().matches(".*_v\\d++$") == false) - { - Method method = cls.getMethod("getKeyType", (Class[])null); - KeyType keyType = (KeyType)method.invoke(cls, (Object[])null); - KeyTypeManager.registerKeyType(keyType); - } - } - gfsh.println(); - gfsh.println("application classes successfully loaded from: " + jarPaths); - } catch (Exception ex) { - gfsh.println("Error: " + ex.getClass().getSimpleName() + " - " + ex.getMessage()); - if (gfsh.isDebug()) { - ex.printStackTrace(); - } - } - } - - private void class_dir(String command) - { - ArrayList list = new ArrayList(); - gfsh.parseCommand(command, list); - if (list.size() < 3) { - gfsh.println("Error: must specify the directory path"); - return; - } - - String dirPath = (String)list.get(2); - if (dirPath == null) { - return; - } - dirPath = dirPath.trim(); - if (dirPath.length() == 0) { - return; - } - - File file = new File(dirPath); - if (file.exists() == false) { - return; - } - - ArrayList<File> jarFileList = getJarFiles(file); - try { - ArrayList<String> classNameList = new ArrayList<String>(); - URL url[] = new URL[jarFileList.size()]; - int i = 0; - for (File file2 : jarFileList) { - URI uri = file2.toURI(); - url[i++] = uri.toURL(); - String[] classNames = ClassFinder.getAllClassNames(file2.getAbsolutePath()); - for (int j = 0; j < classNames.length; j++) { - classNameList.add(classNames[j]); - } - } - URLClassLoader cl = new URLClassLoader(url); - for (String className : classNameList) { - Class.forName(className, true, cl); - } - gfsh.println(); - gfsh.println("application classes successfully loaded from: " + dirPath); - } catch (Exception ex) { - gfsh.println("Error: " + ex.getClass().getSimpleName() + " - " + ex.getMessage()); - if (gfsh.isDebug()) { - ex.printStackTrace(); - } - } - } - - private ArrayList<File> getJarFiles(File dir) - { - return getJarFiles(dir, new ArrayList<File>()); - } - - private ArrayList<File> getJarFiles(File dir, ArrayList<File> fileList) - { - File files[] = dir.listFiles(new FileFilter() { - - public boolean accept(File pathname) - { - return (pathname.isDirectory() == false && pathname.getName().endsWith(".jar")); - } - }); - - for (int i = 0; i < files.length; i++) { - fileList.add(files[i]); - } - - File dirs[] = dir.listFiles(new FileFilter() { - - public boolean accept(File pathname) - { - return pathname.isDirectory(); - } - }); - - for (int i = 0; i < dirs.length; i++) { - fileList = getJarFiles(dirs[i], fileList); - } - - return fileList; - } -}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/49d99d4e/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/commands/clear.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/commands/clear.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/commands/clear.java deleted file mode 100644 index f874694..0000000 --- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/commands/clear.java +++ /dev/null @@ -1,197 +0,0 @@ -package com.gemstone.gemfire.internal.tools.gfsh.app.commands; - -import java.util.LinkedList; -import java.util.List; - -import com.gemstone.gemfire.cache.DataPolicy; -import com.gemstone.gemfire.cache.Region; -import com.gemstone.gemfire.cache.Scope; -import com.gemstone.gemfire.internal.tools.gfsh.aggregator.AggregateResults; -import com.gemstone.gemfire.internal.tools.gfsh.app.CommandExecutable; -import com.gemstone.gemfire.internal.tools.gfsh.app.Gfsh; -import com.gemstone.gemfire.internal.tools.gfsh.app.aggregator.Aggregator; -import com.gemstone.gemfire.internal.tools.gfsh.app.cache.data.MapMessage; -import com.gemstone.gemfire.internal.tools.gfsh.app.command.CommandClient; -import com.gemstone.gemfire.internal.tools.gfsh.app.command.task.RegionClearTask; -import com.gemstone.gemfire.internal.tools.gfsh.app.command.task.data.MemberInfo; -import com.gemstone.gemfire.internal.tools.gfsh.app.function.GfshData; -import com.gemstone.gemfire.internal.tools.gfsh.app.function.GfshFunction; -import com.gemstone.gemfire.internal.tools.gfsh.command.CommandResults; -import com.gemstone.gemfire.internal.tools.gfsh.util.RegionUtil; - -public class clear implements CommandExecutable -{ - private Gfsh gfsh; - - public clear(Gfsh gfsh) - { - this.gfsh = gfsh; - } - - public void help() - { - gfsh.println("clear [-a|-g|-s] [<region path>] | [-?]"); - gfsh.println(" Clear the local region. If <region path> is not specified"); - gfsh.println(" then it clears the current region. The region path"); - gfsh.println(" can be absolute or relative."); - gfsh.println(" -a Clear both the local region and the server region."); - gfsh.println(" The region clear will be distributed to other caches if the"); - gfsh.println(" scope is not Scope.LOCAL."); - gfsh.println(" -g Clear globally. Clear the local region and all server"); - gfsh.println(" regions regardless of scope. This option also clears server"); - gfsh.println(" regions with Scope.LOCAL. Use this option to clear partioned"); - gfsh.println(" regions. GFE 5.7 partitioned region is not supported."); - gfsh.println(" -s Clear only the server region. The local region is not cleared."); - gfsh.println(" The region clear will be distributed to other caches if the"); - gfsh.println(" scope is not Scope.LOCAL."); - gfsh.println(); - } - - public void execute(String command) throws Exception - { - if (command.startsWith("clear -?")) { - help(); - } else if (command.startsWith("clear -a")) { - clear_a(command); - } else if (command.startsWith("clear -g")) { - clear_g(command); - } else if (command.startsWith("clear -s")) { - clear_s(command); - } else { - clear_local(command); - } - } - - private void clear_local(String command) - { - LinkedList list = new LinkedList(); - gfsh.parseCommand(command, list); - String regionPath = null; - if (list.size() > 1) { - regionPath = (String)list.get(1); - } else { - regionPath = gfsh.getCurrentPath(); - } - clearLocalRegion(regionPath); - } - - private void clearLocalRegion(String regionPath) - { - Region region = gfsh.getCache().getRegion(regionPath); - if (region == null) { - gfsh.println("Error: Undefined region path " + regionPath); - } else { - region.localClear(); - gfsh.println("Local region cleared: " + region.getFullPath()); - } - } - - private void clear_a(String command) throws Exception - { - LinkedList list = new LinkedList(); - gfsh.parseCommand(command, list); - String regionPath = null; - if (list.size() > 2) { - regionPath = (String)list.get(2); - } else { - regionPath = gfsh.getCurrentPath(); - } - - clear_server(regionPath, false); - clearLocalRegion(regionPath); - } - - private void clear_g(String command) throws Exception - { - LinkedList list = new LinkedList(); - gfsh.parseCommand(command, list); - String regionPath = null; - if (list.size() > 2) { - regionPath = (String)list.get(2); - } else { - regionPath = gfsh.getCurrentPath(); - } - - clear_server(regionPath, true); - clearLocalRegion(regionPath); - } - - private void clear_s(String command) throws Exception - { - LinkedList list = new LinkedList(); - gfsh.parseCommand(command, list); - String regionPath = null; - if (list.size() > 2) { - regionPath = (String)list.get(2); - } else { - regionPath = gfsh.getCurrentPath(); - } - - clear_server(regionPath, false); - } - - private void clear_server(String regionPath, boolean global) throws Exception - { - if (regionPath == null) { - return; - } - - String currentPath = gfsh.getCurrentPath(); - String fullPath = gfsh.getFullPath(regionPath, currentPath); - if (fullPath == null) { - gfsh.println("Error: invalid region path"); - } else if (fullPath.equals("/")) { - gfsh.println("Error: cannot clear top level"); - } else { - - String confirmation = gfsh.getLine("This command will clear the region " + fullPath + " from the server(s). \nDo you want to proceed? (yes|no): "); - if (confirmation.equalsIgnoreCase("yes") == false) { - gfsh.println("Command aborted."); - return; - } - - if (global) { - - Aggregator aggregator = gfsh.getAggregator(); - List<AggregateResults> results = (List<AggregateResults>)gfsh.getAggregator().aggregate(new GfshFunction("clear", fullPath, null), gfsh.getAggregateRegionPath()); - - int i = 1; - for (AggregateResults aggregateResults : results) { - GfshData data = (GfshData)aggregateResults.getDataObject(); - if (data.getDataObject() != null) { - MapMessage message = (MapMessage)data.getDataObject(); - if (message.getBoolean("IsPeerClient")) { - continue; - } - } - MemberInfo memberInfo = data.getMemberInfo(); - gfsh.print(i + ". " + memberInfo.getMemberName() + "(" + memberInfo.getMemberId() + ")" + ": "); - if (aggregateResults.getCode() == AggregateResults.CODE_ERROR) { - gfsh.println("error - " + aggregateResults.getCodeMessage()); - if (gfsh.isDebug() && aggregateResults.getException() != null) { - aggregateResults.getException().printStackTrace(); - } - } else { - Region region = RegionUtil.getRegion(fullPath, Scope.LOCAL, DataPolicy.NORMAL, null); - gfsh.println("region cleared: " + region.getFullPath()); - } - i++; - } - } else { - CommandClient commandClient = gfsh.getCommandClient(); - CommandResults commandResults = commandClient.execute(new RegionClearTask(fullPath)); - MemberInfo memberInfo = (MemberInfo)commandResults.getDataObject(); - gfsh.print(memberInfo.getMemberName() + "(" + memberInfo.getMemberId() + ")" + ": "); - if (commandResults.getCode() == RegionClearTask.ERROR_REGION_CLEAR) { - gfsh.println("error - " + commandResults.getCodeMessage()); - if (gfsh.isDebug() && commandResults.getException() != null) { - commandResults.getException().printStackTrace(); - } - } else { - Region region = RegionUtil.getRegion(regionPath, Scope.LOCAL, DataPolicy.NORMAL, null); - gfsh.println("region cleared: " + region.getFullPath()); - } - } - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/49d99d4e/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/commands/connect.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/commands/connect.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/commands/connect.java deleted file mode 100644 index 121ad3e..0000000 --- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/commands/connect.java +++ /dev/null @@ -1,124 +0,0 @@ -package com.gemstone.gemfire.internal.tools.gfsh.app.commands; - -import java.util.ArrayList; - -import com.gemstone.gemfire.internal.tools.gfsh.app.CommandExecutable; -import com.gemstone.gemfire.internal.tools.gfsh.app.Gfsh; - -import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; - -public class connect implements CommandExecutable -{ - private Gfsh gfsh; - - public connect(Gfsh gfsh) - { - this.gfsh = gfsh; - } - - public void help() - { -// gfsh.println("connect [-s <host:port> | -l <host:port> [<server group>]] [-r <region path>] | [-?]"); - gfsh.println("connect [-s <host:port> | -l <host:port> [<server group>]] | [-?]"); - gfsh.println(" -s <host:port> Connect to the specified cache servers."); - gfsh.println(" -l <host:port> [<server group>] Connect to the specified locator"); - gfsh.println(" and the server group if specified."); - //TODO: with integrated gfsh, we should not allow command regions other than __command -// gfsh.println(" -r <region path> Use the specified region in making connection."); -// gfsh.println(" The default region path is '/__command'."); - gfsh.println(" -t <readTimeout> readTimeout in msec."); - gfsh.println(" The default value is 300000 ms (5 min)."); - gfsh.println(); - } - - public void execute(String command) throws Exception - { - if (command.startsWith("connect -?")) { - help(); - } else { - connect(command); - if (gfsh.isConnected()) { - gfsh.execute("refresh"); - } - } - } - - private void connect(String command) - { - ArrayList<String> list = new ArrayList(); - gfsh.parseCommand(command, list); - if (list.size() < 3) { - gfsh.println("Error: incomplete command."); - return; - } - String endpoints = null; - String locators = null; -// String regionPath = null; - String serverGroup = null; - int readTimeout = 300000; - try { - for (int i = 1; i < list.size(); i++) { - String token = list.get(i); - if (token.equals("-s")) { - i++; - endpoints = list.get(i); - } else if (token.equals("-l")) { - i++; - locators = list.get(i); - if (i < list.size() - 1) { - if (list.get(i+1).startsWith("-") == false) { - serverGroup = list.get(++i); - } - } - } /*else if (token.equals("-r")) { - i++; - regionPath = list.get(i); - }*/ else if (token.equals("-t")) { - i++; - readTimeout = Integer.parseInt(list.get(i)); - } - } - } catch (Exception ex) { - gfsh.println("Error: invalid command - " + command); - return; - } - - if (endpoints != null && locators != null) { - gfsh.println("Error: invalid command. -s and -l are not allowed together."); - } - -// if (regionPath != null) { -// gfsh.setCommandRegionPath(regionPath); -// } - if (endpoints != null) { - gfsh.setEndpoints(endpoints, false, null, readTimeout); - connect(); - } - if (locators != null) { - gfsh.setEndpoints(locators, true, serverGroup, readTimeout); - connect(); - } - } - - @SuppressFBWarnings(value="NM_METHOD_CONSTRUCTOR_CONFUSION",justification="This is method and not constructor") - private void connect() - { - try { - gfsh.reconnect(); - gfsh.setCurrentPath("/"); - gfsh.setCurrentRegion(null); - if (gfsh.isConnected()) { - gfsh.println("connected: " + gfsh.getEndpoints()); - } else { - gfsh.println("Error: Endpoints set but unable to connect: " + gfsh.getEndpoints()); - } - - } catch (Exception ex) { - gfsh.println(gfsh.getCauseMessage(ex)); - if (gfsh.isDebug()) { - ex.printStackTrace(); - } - } - - } -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/49d99d4e/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/commands/db.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/commands/db.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/commands/db.java deleted file mode 100644 index e9ac31a..0000000 --- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/commands/db.java +++ /dev/null @@ -1,312 +0,0 @@ -package com.gemstone.gemfire.internal.tools.gfsh.app.commands; - -import java.util.ArrayList; - -import com.gemstone.gemfire.cache.Cache; -import com.gemstone.gemfire.cache.CacheFactory; -import com.gemstone.gemfire.cache.Region; -import com.gemstone.gemfire.internal.tools.gfsh.app.CommandExecutable; -import com.gemstone.gemfire.internal.tools.gfsh.app.Gfsh; -import com.gemstone.gemfire.internal.tools.gfsh.app.util.DBUtil; - -/** - * Bulk copy to/from database. - * @author dpark - * - */ -public class db implements CommandExecutable -{ - private Gfsh gfsh; - - private DBUtil dbUtil; - - public db(Gfsh gfsh) - { - this.gfsh = gfsh; - } - - public void help() - { - gfsh.println("db [{<region path> | <oql>} {in | out} {<table name> | <sql>}]"); - gfsh.println(" [-k [<primary column>]]"); - gfsh.println(" [-v [primary column]]"); - gfsh.println(" [-b <batch size>]"); - gfsh.println("db [-driver <jdbc driver>]"); - gfsh.println(" [-url <jdbc url>]"); - gfsh.println(" [-u <user name>]"); - gfsh.println(" [-p <password>]"); - gfsh.println("db [-?]"); - gfsh.println(" Load database contents into a region or store region contents to."); - gfsh.println(" a database table. db has 2 distinctive commands. 'db -driver...'"); - gfsh.println(" to initialize database and 'db region_path...' to load/store "); - gfsh.println(" from/to database. Note that if the region is a partitioned region"); - gfsh.println(" then the 'out' option retrieves data only from the local dataset"); - gfsh.println(" the connected server due to the potentially large size of the"); - gfsh.println(" partitioend region."); - gfsh.println(); - gfsh.println(" {<region path> | <oql>} region path or OQL query statement. <region path>"); - gfsh.println(" stores all of the region entries into the database table."); - gfsh.println(" If <oql>, the query tuples must match table column names."); - gfsh.println(" {in | out} 'in' for load data into the region from the database"); - gfsh.println(" 'out' for store data out to the database from the region."); - gfsh.println(" {<table name> | <sql>} table name or SQL query statement. <table name>"); - gfsh.println(" loads the entire table contents."); - gfsh.println(); - gfsh.println(" Requirements:"); - gfsh.println(" The data class must have getter and setter methods for the matching"); - gfsh.println(" query tuples. db supports case-insensitive table column names."); - gfsh.println(" Examples:"); - gfsh.println(" To connect to a dababase:"); - gfsh.println(" db -driver com.mysql.jdbc.Driver -url jdbc:mysql://localhost/market \\"); - gfsh.println(" -u root -p root"); - gfsh.println(" To store the /prices region entries to the price_table database table:"); - gfsh.println(" db /prices out price_table"); - gfsh.println(" To load database query results to a region:"); - gfsh.println(" db /prices in \"select * from price_table"); - gfsh.println(); - } - - public void execute(String command) throws Exception - { - if (command.startsWith("db -?")) { - help(); - } else { - db(command); - } - } - - public String getDbInitCommand() - { - String dbSettings = null; - if (dbUtil != null) { - - String url = dbUtil.getUrl(); - String driverName = dbUtil.getDriverName(); - String userName = dbUtil.getUserName(); - - if (url == null || driverName == null) { - return null; - } - - dbSettings = "db "; - if (url != null) { - dbSettings += "-url " + url; - } - if (driverName != null) { - dbSettings += " -driver " + driverName; - } - if (userName != null) { - dbSettings += " -u " + userName; - } - } - return dbSettings; - } - - private void db(String command) throws Exception - { - ArrayList<String> list = new ArrayList(); - gfsh.parseCommand(command, list); - - - // options - boolean optionSpecified = false; - String driver = null; - String url = null; - String user = null; - String password = null; - boolean storeKeys = false; - boolean storeValues = false; - boolean isKeyPrimary = false; - boolean isValuePrimary = false; - String primaryColumn = null; - int batchSize = 1000; - for (int i = 0; i < list.size(); i++) { - String val = list.get(i); - if (val.equals("-driver")) { - i++; - if (list.size() > i) { - driver = list.get(i); - } - optionSpecified = true; - } else if (val.equals("-url")) { - i++; - if (list.size() > i) { - url = list.get(i); - } - optionSpecified = true; - } else if (val.equals("-u")) { - i++; - if (list.size() > i) { - user = list.get(i); - } - optionSpecified = true; - } else if (val.equals("-p")) { - i++; - if (list.size() > i) { - password = list.get(i); - } - optionSpecified = true; - } else if (val.equals("-k")) { - storeKeys = true; - if (list.size() > i+1 && list.get(i+1).startsWith("-") == false) { - i++; - primaryColumn = list.get(i); - isKeyPrimary = true; - } - } else if (val.equals("-v")) { - storeValues = true; - if (list.size() > i+1 && list.get(i+1).startsWith("-") == false) { - i++; - primaryColumn = list.get(i); - isValuePrimary = true; - } - } else if (val.equals("-b")) { - i++; - if (list.size() > i) { - val = list.get(i); - batchSize = Integer.parseInt(val); - } - } - } - - if (optionSpecified) { - if (driver == null) { - gfsh.println("Error: -driver not specified."); - return; - } - if (url == null) { - gfsh.println("Error: -url not specified."); - return; - } - - dbUtil = DBUtil.initialize(driver, url, user, password); - if (dbUtil != null) { - gfsh.println("Database connected."); - } - return; - } - - if (dbUtil == null) { - gfsh.println("Error: Not connected to database."); - return; - } - - // Data load/store - - // Parse command inputs - if (list.size() < 4) { - gfsh.println("Error: incomplete db command. Run db -? for help."); - return; - } - String fullPath = null; - String regionPath = list.get(1); - String directionType = list.get(2); - - - // region - Cache cache = CacheFactory.getAnyInstance(); - Region region = null; - String oql = null; - if (regionPath.startsWith("select ") == false) { - regionPath = gfsh.getFullPath(regionPath, gfsh.getCurrentPath()); - region = cache.getRegion(regionPath); - if (region == null) { - gfsh.println("Error: region undefined - " + regionPath); - return; - } - } else { - oql = regionPath; - } - - // in | out - boolean isIn = false; - if (directionType.equalsIgnoreCase("in")) { - isIn = true; - } else if (directionType.equalsIgnoreCase("out")) { - isIn = false; - } else { - gfsh.println("Error: invalid direction type - " + directionType); - return; - } - - // table or query - - if (isIn) { - String sql = list.get(3); // sql can be a table name. if table, select * is performed - dbIn(region, sql, primaryColumn); - } else { - String tableName = list.get(3); - if (storeKeys == false && storeValues == false) { - storeValues = true; - } - - // value primary overrides key primary. - // cannot have two primary columns. only one primary allowed. - if (isValuePrimary) { - isKeyPrimary = false; - } - int storeType = DBUtil.TYPE_VALUES; - if (storeKeys && storeValues) { - storeType = DBUtil.TYPE_KEYS_VALUES; - } else if (storeKeys) { - storeType = DBUtil.TYPE_KEYS; - } - dbOut(regionPath, tableName, storeType, primaryColumn, isKeyPrimary, batchSize); - } - } - - private void dbIn(Region region, String sql, String primaryColumn) throws Exception - { - long startTime = System.currentTimeMillis(); - int rowCount = dbUtil.loadDB(gfsh, region, gfsh.getQueryKeyClass(), gfsh.getValueClass(), sql, primaryColumn); - long stopTime = System.currentTimeMillis(); - - gfsh.println("db in complete"); - gfsh.println(" To (region): " + region.getFullPath()); - gfsh.println(" From (database): " + sql); - gfsh.println(" Row count: " + rowCount); - if (gfsh.isShowTime()) { - gfsh.println(" elapsed (msec): " + (stopTime - startTime)); - } - } - -// private void dbOut(Region region, String tableName, -// int storeType, String primaryColumn, -// boolean isKeyPrimary) throws Exception -// { -// long startTime = System.currentTimeMillis(); -// int rowCount = dbUtil.storeDB(gfsh, region, tableName, storeType, primaryColumn, isKeyPrimary); -// long stopTime = System.currentTimeMillis(); -// -// gfsh.println("db out complete"); -// gfsh.println(" Copied from: " + region.getFullPath()); -// gfsh.println(" Copied to: " + tableName); -// gfsh.println(" Row count: " + rowCount); -// if (gfsh.isShowTime()) { -// gfsh.println("elapsed (msec): " + (stopTime - startTime)); -// } -// } -// - private void dbOut(String regionPath, String tableName, - int storeType, String primaryColumn, - boolean isKeyPrimary, int batchSize) throws Exception - { - long startTime = System.currentTimeMillis(); - int rowCount = dbUtil.storeDB(gfsh, regionPath, tableName, storeType, primaryColumn, isKeyPrimary, batchSize); - long stopTime = System.currentTimeMillis(); - - if (rowCount == -1) { - return; - } - - gfsh.println("db out complete"); - gfsh.println(" From (region): " + regionPath); - gfsh.println(" To (database): " + tableName); - gfsh.println(" Row count: " + rowCount); - - if (gfsh.isShowTime()) { - gfsh.println(" elapsed (msec): " + (stopTime - startTime)); - } - - } -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/49d99d4e/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/commands/debug.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/commands/debug.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/commands/debug.java deleted file mode 100644 index 329d0aa..0000000 --- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/commands/debug.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.gemstone.gemfire.internal.tools.gfsh.app.commands; - -import java.util.ArrayList; - -import com.gemstone.gemfire.internal.tools.gfsh.app.CommandExecutable; -import com.gemstone.gemfire.internal.tools.gfsh.app.Gfsh; - -public class debug implements CommandExecutable { - private Gfsh gfsh; - - public debug(Gfsh gfsh) { - this.gfsh = gfsh; - } - - public void help() { - gfsh.println("debug [true|false] | [-?]"); - gfsh.println(" Toggle the debug setting. If debug is true then execptions"); - gfsh.println(" are printed to stdout."); - gfsh.println(); - } - - public void execute(String command) throws Exception { - if (command.startsWith("debug -?")) { - help(); - } else { - debug(command); - } - } - - private void debug(String command) { - ArrayList<String> list = new ArrayList(); - gfsh.parseCommand(command, list); - if (list.size() >= 2) { - if (list.get(1).equalsIgnoreCase("true") - || list.get(1).equalsIgnoreCase("false")) { - boolean enable = list.get(1).equalsIgnoreCase("true"); - gfsh.setDebug(enable); - } else { - gfsh.println("Invalid option:" + list.get(1)); - gfsh.println("Check help for valid options."); - return; - } - } else { - gfsh.setDebug(!gfsh.isDebug()); - } - gfsh.println("debug is " + (gfsh.isDebug() ? "on" : "off")); - } -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/49d99d4e/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/commands/deploy.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/commands/deploy.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/commands/deploy.java deleted file mode 100644 index 377b040..0000000 --- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/commands/deploy.java +++ /dev/null @@ -1,271 +0,0 @@ -package com.gemstone.gemfire.internal.tools.gfsh.app.commands; - -import java.io.File; -import java.io.FileFilter; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; - -import com.gemstone.gemfire.internal.tools.gfsh.aggregator.AggregateResults; -import com.gemstone.gemfire.internal.tools.gfsh.app.CommandExecutable; -import com.gemstone.gemfire.internal.tools.gfsh.app.Gfsh; -import com.gemstone.gemfire.internal.tools.gfsh.app.command.task.data.MemberInfo; -import com.gemstone.gemfire.internal.tools.gfsh.app.function.GfshData; -import com.gemstone.gemfire.internal.tools.gfsh.app.function.GfshFunction; - -public class deploy implements CommandExecutable -{ - private Gfsh gfsh; - - private static int BUFFER_SIZE = 10000; - - public deploy(Gfsh gfsh) - { - this.gfsh = gfsh; - } - - public void help() - { - gfsh.println("deploy [-jar <jar paths>]"); - gfsh.println(" [-dir [-r] <directory>]"); - gfsh.println(" [-?]"); - gfsh.println(" Deploys the specified jar or class files to all of the servers."); - gfsh.println(" -jar <jar paths> Load all classes in the jar paths. The jar paths"); - gfsh.println(" can be separated by ',', ';', or ':'. The jar paths"); - gfsh.println(" can be relative or absolute."); - gfsh.println(" -dir [-r] <directory> Load all jar files in the directory."); - gfsh.println(" '-r' recursively loads all jar files including sub-directories."); - gfsh.println(" The directory path can be relative or absolute."); - gfsh.println(); - } - - public void execute(String command) throws Exception - { - if (command.startsWith("deploy -?")) { - help(); - } else if (command.startsWith("deploy -dir")) { - deploy_dir(command); - } else if (command.startsWith("deploy -jar")) { - deploy_jar(command); - } else { - gfsh.println("Error: invalid command - " + command); - } - } - - private byte[] readJar(File file) throws FileNotFoundException, IOException - { - FileInputStream fis = new FileInputStream(file); - ArrayList<byte[]> byteList = new ArrayList<byte[]>(); - int bytesRead; - int lastBytesRead = 0; - byte buffer[]; - do { - buffer = new byte[BUFFER_SIZE]; - bytesRead = fis.read(buffer); - if (bytesRead != -1) { - lastBytesRead = bytesRead; - byteList.add(buffer); - } - } while (bytesRead != -1); - fis.close(); - - int lastIndex = byteList.size() - 1; - int bufferLength = lastIndex * BUFFER_SIZE + lastBytesRead; - int destPos = 0; - buffer = new byte[bufferLength]; - for (int j = 0; j < lastIndex; j++) { - byte srcBuffer[] = byteList.get(j); - destPos = j * BUFFER_SIZE; - System.arraycopy(srcBuffer, 0, buffer, destPos, srcBuffer.length); - } - if (lastIndex >= 0) { - byte srcBuffer[] = byteList.get(lastIndex); - destPos = lastIndex * BUFFER_SIZE; - System.arraycopy(srcBuffer, 0, buffer, destPos, lastBytesRead); - } - - return buffer; - } - - private void deploy(String[] jarPaths) - { - if (jarPaths == null || jarPaths.length == 0) { - gfsh.println("Error: must specify the jar path(s)"); - return; - } - - try { - String jarNames[] = new String[jarPaths.length]; - byte[][] payloadBuffers = new byte[jarPaths.length][]; - - // Read all jar files - for (int i = 0; i < jarPaths.length; i++) { - String path = jarPaths[i]; - if (path == null) { - continue; - } - path = path.trim(); - File file = new File(path); - jarNames[i] = file.getName(); - payloadBuffers[i] = readJar(file); - } - - // Send payloadBuffers to all servers - long startTime = System.currentTimeMillis(); - List<AggregateResults> results = (List<AggregateResults>) gfsh.getAggregator().aggregate( - new GfshFunction("deploy", null, new Object[] { "-jar", jarNames, payloadBuffers }), gfsh.getAggregateRegionPath()); - long stopTime = System.currentTimeMillis(); - - int i = 1; - for (AggregateResults aggregateResults : results) { - GfshData data = (GfshData)aggregateResults.getDataObject(); - MemberInfo memberInfo = data.getMemberInfo(); - String message = (String)data.getDataObject(); - gfsh.print(i + ". " + memberInfo.getMemberName() + "(" + memberInfo.getMemberId() + ")" + ": "); - gfsh.println(message); - i++; - } - - gfsh.print("deployed files: "); - for (i = 0; i < jarNames.length - 1; i++) { - gfsh.print(jarNames[i] + ", "); - } - if (jarNames.length > 0) { - gfsh.println(jarNames[jarNames.length - 1]); - } - gfsh.println(); - - if (gfsh.isShowTime()) { - gfsh.println("elapsed (msec): " + (stopTime - startTime)); - } - - } catch (Exception ex) { - gfsh.println("Error: " + ex.getClass().getSimpleName() + " - " + ex.getMessage()); - if (gfsh.isDebug()) { - ex.printStackTrace(); - } - } - } - - private void deploy_jar(String command) - { - ArrayList list = new ArrayList(); - gfsh.parseCommand(command, list); - if (list.size() < 3) { - gfsh.println("Error: must specify the jar path(s)"); - return; - } - - String jarPaths = ""; - for (int i = 2; i < list.size(); i++) { - jarPaths += list.get(i); - } - jarPaths = jarPaths.trim(); - - String pathSeparator = System.getProperty("path.separator"); - jarPaths = jarPaths.replace(pathSeparator.charAt(0), ','); - String split[] = jarPaths.split(","); - deploy(split); - } - - private void deploy_dir(String command) - { - ArrayList list = new ArrayList(); - gfsh.parseCommand(command, list); - if (list.size() < 3) { - gfsh.println("Error: must specify the directory path"); - return; - } - - String dirPath = (String)list.get(2); - if (dirPath == null) { - return; - } - dirPath = dirPath.trim(); - if (dirPath.length() == 0) { - gfsh.println("Error: directory not specified"); - return; - } - - File file = new File(dirPath); - if (file.exists() == false) { - gfsh.println("Error: direcotry " + dirPath + " does not exist"); - return; - } - - ArrayList<File> jarFileList = getJarFiles(file, false); - if (jarFileList.size() == 0) { - gfsh.println("jar files not found in directory " + dirPath); - return; - } - - String jarPaths[] = new String[jarFileList.size()]; - int i = 0; - for (File file2 : jarFileList) { - jarPaths[i++] = file2.getAbsolutePath(); - } - deploy(jarPaths); - -// byte[][] payloadBuffers = new byte[jarFileList.size()][]; -// try { -// -// // Read all jar files -// for (int i = 0; i < jarFileList.size(); i++) { -// File file2 = jarFileList.get(i); -// payloadBuffers[i] = readJar(file2); -// } -// -// // Determine the jar names -// for (int i = 0; i < jarFileList.size(); i++) { -// File file2 = jarFileList.get(i); -// jarPaths[i] = file2.getAbsolutePath(); -// } -// -// deploy(jarPaths); -// -// } catch (Exception ex) { -// gfsh.println("Error: " + ex.getClass().getSimpleName() + " - " + ex.getMessage()); -// if (gfsh.isDebug()) { -// ex.printStackTrace(); -// } -// } - } - - private ArrayList<File> getJarFiles(File dir, boolean recursive) - { - return getJarFiles(dir, new ArrayList<File>(), recursive); - } - - private ArrayList<File> getJarFiles(File dir, ArrayList<File> fileList, boolean recursive) - { - File files[] = dir.listFiles(new FileFilter() { - - public boolean accept(File pathname) - { - return (pathname.isDirectory() == false && pathname.getName().endsWith(".jar")); - } - }); - - for (int i = 0; i < files.length; i++) { - fileList.add(files[i]); - } - - if (recursive) { - File dirs[] = dir.listFiles(new FileFilter() { - - public boolean accept(File pathname) - { - return pathname.isDirectory(); - } - }); - - for (int i = 0; i < dirs.length; i++) { - fileList = getJarFiles(dirs[i], fileList, recursive); - } - } - - return fileList; - } -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/49d99d4e/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/commands/echo.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/commands/echo.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/commands/echo.java deleted file mode 100644 index 27a851c..0000000 --- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/commands/echo.java +++ /dev/null @@ -1,59 +0,0 @@ -package com.gemstone.gemfire.internal.tools.gfsh.app.commands; - -import java.util.ArrayList; - -import com.gemstone.gemfire.internal.tools.gfsh.app.CommandExecutable; -import com.gemstone.gemfire.internal.tools.gfsh.app.Gfsh; - -public class echo implements CommandExecutable -{ - private Gfsh gfsh; - - public echo(Gfsh gfsh) - { - this.gfsh = gfsh; - } - - public void help() - { - gfsh.println("echo [true|false] [<message>] | [-?]"); - gfsh.println(" Toggle the echo setting. If echo is true then input"); - gfsh.println(" commands are echoed to stdout. If <message> is specified"); - gfsh.println(" it is printed without toggling echo. It expands properties."); - gfsh.println(); - } - - public void execute(String command) throws Exception - { - if (command.startsWith("echo -?")) { - help(); - } else { - echo(command); - } - } - - private void echo(String command) - { - ArrayList<String> list = new ArrayList(); - gfsh.parseCommand(command, list); - if (list.size() >= 2) { - if (list.get(1).equalsIgnoreCase("true")) { - gfsh.setEcho(true); - } else if (list.get(1).equalsIgnoreCase("false")) { - gfsh.setEcho(false); - } else { - // message - // command is already trimmed. no need to trim - int index = command.indexOf(' '); - String message = command.substring(index+1); - gfsh.println(message); - return; - } - - } else { - gfsh.setEcho(!gfsh.isEcho()); - } - - gfsh.println("echo is " + (gfsh.isEcho() ? "true" : "false")); - } -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/49d99d4e/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/commands/fetch.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/commands/fetch.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/commands/fetch.java deleted file mode 100644 index 819d05a..0000000 --- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/commands/fetch.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.gemstone.gemfire.internal.tools.gfsh.app.commands; - -import java.util.LinkedList; - -import com.gemstone.gemfire.internal.tools.gfsh.app.CommandExecutable; -import com.gemstone.gemfire.internal.tools.gfsh.app.Gfsh; - -public class fetch implements CommandExecutable -{ - private Gfsh gfsh; - - public fetch(Gfsh gfsh) - { - this.gfsh = gfsh; - } - - public void help() - { - gfsh.println("fetch [-?] <size>"); - gfsh.println(" Set the fetch size of the query result set."); - gfsh.println(); - } - - public void execute(String command) throws Exception - { - if (command.startsWith("fetch -?")) { - help(); - } else { - fetch(command); - } - } - - private void fetch(String command) - { - LinkedList list = new LinkedList(); - gfsh.parseCommand(command, list); - if (list.size() < 2) { - gfsh.println("fetch = " + gfsh.getFetchSize()); - gfsh.println(" Use fetch <size> to set the fetch size"); - } else { - try { - gfsh.setFetchSize(Integer.parseInt(list.get(1).toString())); - } catch (Exception ex) { - System.out.println("Error: " + ex.getMessage()); - } - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/49d99d4e/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/commands/gc.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/commands/gc.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/commands/gc.java deleted file mode 100644 index ea77de3..0000000 --- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/commands/gc.java +++ /dev/null @@ -1,93 +0,0 @@ -package com.gemstone.gemfire.internal.tools.gfsh.app.commands; - -import java.util.LinkedList; -import java.util.List; - -import com.gemstone.gemfire.internal.tools.gfsh.aggregator.AggregateResults; -import com.gemstone.gemfire.internal.tools.gfsh.app.CommandExecutable; -import com.gemstone.gemfire.internal.tools.gfsh.app.Gfsh; -import com.gemstone.gemfire.internal.tools.gfsh.app.aggregator.Aggregator; -import com.gemstone.gemfire.internal.tools.gfsh.app.command.task.data.MemberInfo; -import com.gemstone.gemfire.internal.tools.gfsh.app.function.GfshData; -import com.gemstone.gemfire.internal.tools.gfsh.app.function.GfshFunction; - -public class gc implements CommandExecutable -{ - private Gfsh gfsh; - - public gc(Gfsh gfsh) - { - this.gfsh = gfsh; - } - - public void help() - { - gfsh.println("gc [-g] [-m <member id>] | [-?]"); - gfsh.println(" Force gc on the connected server or all of the servers."); - gfsh.println(" -g Force gc globally on all servers."); - gfsh.println(" -m <member id> Force gc on the specified member. The member id can"); - gfsh.println(" be obtained by executing 'size -m' or 'ls -m'"); - gfsh.println(); - } - - public void execute(String command) throws Exception - { - if (command.startsWith("gc -?")) { - help(); - } else if (command.startsWith("gc -g")) { - gc(command); - } else if (command.startsWith("gc -m")) { - gc(command); - } else { - gfsh.println("Error: invalid gc option."); - } - } - - private void gc(String command) throws Exception - { - LinkedList<String> list = new LinkedList(); - gfsh.parseCommand(command, list); - - boolean isGlobal = false; - String memberId = null; - if (command.startsWith("gc -m")) { - if (list.size() > 2) { - memberId = list.get(2); - } - } else if (command.startsWith("gc -g")) { - isGlobal = true; - } - - if (isGlobal == false && memberId == null) { - gfsh.println("Error: invalid option. 'gc -m' requires <member id>. Use 'size -m' or 'ls -m' to list member ids."); - return; - } - - String confirmation = gfsh.getLine("This command forc gc on the server(s).\nDo you want to proceed? (yes|no): "); - if (confirmation.equalsIgnoreCase("yes") == false) { - gfsh.println("Command aborted."); - return; - } - - Aggregator aggregator = gfsh.getAggregator(); - List<AggregateResults> results = (List<AggregateResults>)gfsh.getAggregator().aggregate(new GfshFunction("gc", gfsh.getCurrentPath(), memberId), gfsh.getAggregateRegionPath()); - int i = 1; - for (AggregateResults aggregateResults : results) { - GfshData data = (GfshData)aggregateResults.getDataObject(); - MemberInfo memberInfo = data.getMemberInfo(); - if (isGlobal || (memberId != null && memberId.equals(memberInfo.getMemberId()))) { - gfsh.print(i + ". " + memberInfo.getMemberName() + "(" + memberInfo.getMemberId() + ")" + ": "); - if (aggregateResults.getCode() == AggregateResults.CODE_ERROR) { - gfsh.println("error - " + aggregateResults.getCodeMessage()); - if (gfsh.isDebug() && aggregateResults.getException() != null) { - aggregateResults.getException().printStackTrace(); - } - } else { - gfsh.println("GC forced"); - } - } - i++; - } -// gfsh.getCommandClient().execute(new ForceGCTask()); - } -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/49d99d4e/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/commands/get.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/commands/get.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/commands/get.java deleted file mode 100644 index 2ea5dd6..0000000 --- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/commands/get.java +++ /dev/null @@ -1,143 +0,0 @@ -package com.gemstone.gemfire.internal.tools.gfsh.app.commands; - -import java.util.HashMap; -import java.util.LinkedList; -import java.util.Map; - -import com.gemstone.gemfire.internal.tools.gfsh.app.CommandExecutable; -import com.gemstone.gemfire.internal.tools.gfsh.app.Gfsh; -import com.gemstone.gemfire.internal.tools.gfsh.app.util.ObjectUtil; -import com.gemstone.gemfire.internal.tools.gfsh.app.util.PrintUtil; - -public class get implements CommandExecutable -{ - private Gfsh gfsh; - - public get(Gfsh gfsh) - { - this.gfsh = gfsh; - } - - public void help() - { - gfsh.println("get [<query predicate>] | [-k <number list>] | [-?]"); - gfsh.println(" Get value from the current region."); - gfsh.println(" <query predicate>: field=val1 and field2='val1' \\"); - gfsh.println(" and field3=to_date('<date>', '<format>')"); - gfsh.println(" Data formats: primitives, String, and java.util.Date"); - gfsh.println(" <decimal>b|B - Byte (e.g., 1b)"); - gfsh.println(" <decimal>c|C - Character (e.g., 1c)"); - gfsh.println(" <decimal>s|S - Short (e.g., 12s)"); - gfsh.println(" <decimal>i|I - Integer (e.g., 15 or 15i)"); - gfsh.println(" <decimal>l|L - Long (e.g., 20l)"); - gfsh.println(" <decimal>f|F - Float (e.g., 15.5 or 15.5f)"); - gfsh.println(" <decimal>d|D - Double (e.g., 20.0d)"); - gfsh.println(" '<string with \\ delimiter>' (e.g., '\\'Wow!\\'!' Hello, world')"); - gfsh.println(" to_date('<date string>', '<simple date format>')"); - gfsh.println(" (e.g., to_date('04/10/2009', 'MM/dd/yyyy')"); - gfsh.println(" -k <number list> Get values from the current region using the"); - gfsh.println(" enumerated keys. Use 'ls -k' to get the list"); - gfsh.println(" of enumerated keys."); - gfsh.println(" <number list> format: num1 num2 num3-num5 ... e.g., 'get -k 1 2 4 10-20'"); - gfsh.println(); - } - - public void execute(String command) throws Exception - { - if (command.startsWith("get -?")) { - help(); - } else if (command.startsWith("get -k")) { - get_k(command); - } else if (command.startsWith("get")) { - get(command); - } - } - - private void get(String command) throws Exception - { - if (gfsh.getCurrentRegion() == null) { - gfsh.println("Error: Region undefined. Use 'cd' to change region first before executing this command."); - return; - } - - LinkedList list = new LinkedList(); - gfsh.parseCommand(command, list); - if (list.size() < 2) { - gfsh.println("Error: get requires a query predicate"); - } else { - String input = (String) list.get(1); - Object key = null; - Object value; - if (input.startsWith("'")) { - int lastIndex = -1; - if (input.endsWith("'") == false) { - lastIndex = input.length(); - } else { - lastIndex = input.lastIndexOf("'"); - } - if (lastIndex <= 1) { - gfsh.println("Error: Invalid key. Empty string not allowed."); - return; - } - key = input.subSequence(1, lastIndex); // lastIndex exclusive - } else { - key = ObjectUtil.getPrimitive(gfsh, input, false); - if (key == null) { - key = gfsh.getQueryKey(list, 1); - } - } - if (key == null) { - return; - } - long startTime = System.currentTimeMillis(); - value = gfsh.getCurrentRegion().get(key); - long stopTime = System.currentTimeMillis(); - - if (value == null) { - gfsh.println("Key not found."); - return; - } - - HashMap keyMap = new HashMap(); - keyMap.put(1, key); - PrintUtil.printEntries(gfsh.getCurrentRegion(), keyMap, null); - if (gfsh.isShowTime()) { - gfsh.println("elapsed (msec): " + (stopTime - startTime)); - } - } - } - - private void get_k(String command) throws Exception - { - if (gfsh.getCurrentRegion() == null) { - gfsh.println("Error: Region undefined. Use 'cd' to change region first before executing this command."); - return; - } - - // get -k # - LinkedList list = new LinkedList(); - gfsh.parseCommand(command, list); - if (list.size() < 3) { - gfsh.println("Error: get -k requires number(s)"); - return; - } - - if (gfsh.getLsKeyList() == null) { - gfsh.println("Error: No keys obtained. Execute 'ls -k' first to obtain the keys"); - return; - } - - Map keyMap = gfsh.getKeyMap(list, 2); - long startTime = System.currentTimeMillis(); - gfsh.getCurrentRegion().getAll(keyMap.values()); - long stopTime = System.currentTimeMillis(); - if (gfsh.isShowResults()) { - PrintUtil.printEntries(gfsh.getCurrentRegion(), keyMap, null); - } else { - gfsh.println("Fetched: " + keyMap.size()); - } - if (gfsh.isShowTime()) { - gfsh.println("elapsed (msec): " + (stopTime - startTime)); - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/49d99d4e/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/commands/help.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/commands/help.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/commands/help.java deleted file mode 100644 index de09c8a..0000000 --- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/commands/help.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.gemstone.gemfire.internal.tools.gfsh.app.commands; - -import com.gemstone.gemfire.internal.tools.gfsh.app.CommandExecutable; -import com.gemstone.gemfire.internal.tools.gfsh.app.Gfsh; - -import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; - -public class help implements CommandExecutable -{ - private Gfsh gfsh; - - public help(Gfsh gfsh) - { - this.gfsh = gfsh; - } - - - @SuppressFBWarnings(value="NM_METHOD_CONSTRUCTOR_CONFUSION",justification="This is method and not constructor") - public void help() - { - gfsh.println("help or ?"); - gfsh.println(" List command descriptions"); - gfsh.println(); - } - - public void execute(String command) throws Exception - { - - if (command.startsWith("help -?")) { - help(); - } else { - String[] splitted = command.split(" "); - if (splitted.length > 1) { - gfsh.showHelp(splitted[1]); - } else { - gfsh.showHelp(); - } - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/49d99d4e/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/commands/index.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/commands/index.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/commands/index.java deleted file mode 100644 index 8c4bef0..0000000 --- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/commands/index.java +++ /dev/null @@ -1,395 +0,0 @@ -package com.gemstone.gemfire.internal.tools.gfsh.app.commands; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.LinkedList; -import java.util.List; - -import com.gemstone.gemfire.internal.tools.gfsh.aggregator.AggregateResults; -import com.gemstone.gemfire.internal.tools.gfsh.app.CommandExecutable; -import com.gemstone.gemfire.internal.tools.gfsh.app.Gfsh; -import com.gemstone.gemfire.internal.tools.gfsh.app.aggregator.Aggregator; -import com.gemstone.gemfire.internal.tools.gfsh.app.cache.data.Mappable; -import com.gemstone.gemfire.internal.tools.gfsh.app.command.task.data.MemberInfo; -import com.gemstone.gemfire.internal.tools.gfsh.app.function.GfshData; -import com.gemstone.gemfire.internal.tools.gfsh.app.function.GfshFunction; -import com.gemstone.gemfire.internal.tools.gfsh.app.util.PrintUtil; - -public class index implements CommandExecutable -{ - private Gfsh gfsh; - - private enum TASK { - LIST, - CREATE, - DELETE, - STATS - } - - private static List<String>mappableKeyList; - private static List<String>mappableStatsList; - - static { - mappableKeyList = new ArrayList(); - Collections.addAll(mappableKeyList, "Name", "Type", "Expression", "From"); - mappableStatsList = new ArrayList(); - Collections.addAll(mappableStatsList, "Name", "Type", "Expression", "From", "Keys", "Values", "Updates", "TotalUpdateTime", "TotalUses"); - } - - public index(Gfsh gfsh) - { - this.gfsh = gfsh; - } - - public void help() - { - gfsh.println("index [-m <member id>|-g] -n <index name> -e <expression> -from <from clause>"); - gfsh.println(" [-i <imports>]"); - gfsh.println(" [-primary|-functional] "); - gfsh.println(" [-r <region path>]"); - gfsh.println(" [-?]"); - gfsh.println(" Creates the specified index in the current or specified region."); - gfsh.println(" -m <member id> Execute the index command on the specified member only"); - gfsh.println(" -g Execute the index command on all members"); - gfsh.println(" -n <index name> Unique index name."); - gfsh.println(" -e Index expression."); - gfsh.println(" -from <from clause> From clause."); - gfsh.println(" [-i <imports>] Import statments separated by ; in double quotes,"); - gfsh.println(" e.g., -i \"import com.foo.ClassA;import com.fool.ClassB\""); - gfsh.println(" [-primary|-functional] Create a primary index or a functional index."); - gfsh.println(" Default: -functional"); - gfsh.println("index [-m <member id>|-g] [-all] [-r <region path>]"); - gfsh.println(" List indexes created in the current or specified region. Default: -g"); - gfsh.println(" -stats Display index statistics along with index info."); - gfsh.println(" -m <member id> Execute the index command on the specified member only"); - gfsh.println(" -g Execute the index command on all members"); - gfsh.println(" -all List indexes in all regions."); - gfsh.println(" [-r <region path>] Region path. If not specified, the current region"); - gfsh.println(" is used."); - gfsh.println("index -stats [-m <member id>|-g] [-all] [-r <region path>]"); - gfsh.println(" Display index statistics in the current or specified region. Default: -g"); - gfsh.println(" -m <member id> Execute the index command on the specified member only"); - gfsh.println(" -g Execute the index command on all members"); - gfsh.println(" -all Display statistics for all indexes in all regions."); - gfsh.println("index -d [-m <member id>|-g] -n <index name>|-region|-all [-r <region path>]"); - gfsh.println(" Delete the specified index in the current or specified region. Default: -g"); - gfsh.println(" -m <member id> Execute the index command on the specified member only"); - gfsh.println(" -g Execute the index command on all members"); - gfsh.println(" -all Delete indexes in all regions."); - gfsh.println(" -n <index name> Delete the specified index in the current or specified region."); - gfsh.println(" -region Delete all indexes in the current or specified region."); - } - - public void execute(String command) throws Exception - { - if (command.startsWith("index -?")) { - help(); - } else { - index(command); - } - } - - private void index(String command) throws Exception - { - LinkedList<String> list = new LinkedList(); - gfsh.parseCommand(command, list); - - String regionPath = null; - boolean all = false; - boolean delete = false; - boolean isRegion = false; - String indexName = null; - String expression = null; - String fromClause = null; - String imports = null; - boolean global = false; - String memberId = null; - boolean isFunctionalIndex = true; - boolean stats = false; - for (int i = 1; i < list.size(); i++) { - String token = list.get(i); - if (token.equals("-all")) { - all = true; - } else if (token.equals("-d")) { - delete = true; - } else if (token.equals("-region")) { - isRegion = true; - } else if (token.equals("-r")) { - if (i + 1 >= list.size()) { - gfsh.println("Error: '-r' requires region path"); - return; - } - regionPath = (String) list.get(++i); - } else if (token.equals("-n")) { - if (i + 1 >= list.size()) { - gfsh.println("Error: '-n' requires index name"); - return; - } - indexName = (String) list.get(++i); - } else if (token.equals("-e")) { - if (i + 1 >= list.size()) { - gfsh.println("Error: '-e' requires expression"); - return; - } - expression = (String) list.get(++i); - } else if (token.equals("-from")) { - if (i + 1 >= list.size()) { - gfsh.println("Error: '-from' requires from-clause"); - return; - } - fromClause = (String) list.get(++i); - } else if (token.equals("-i")) { - if (i + 1 >= list.size()) { - gfsh.println("Error: '-i' requires imports"); - return; - } - imports = (String) list.get(++i); - } else if (token.equals("-m")) { - if (i + 1 >= list.size()) { - gfsh.println("Error: '-m' requires member Id"); - return; - } - memberId = (String) list.get(++i); - } else if (token.equals("-g")) { - global = true; - } else if (token.equals("-primary")) { - isFunctionalIndex = false; - } else if (token.equals("-functional")) { - isFunctionalIndex = true; - } else if (token.equals("-stats")) { - stats = true; - } else { - gfsh.println("Error: invalid directive '" + token + "'"); - return; - } - } - - if (global && memberId != null) { - gfsh.println("Error: only one option is allowed: '-g' or '-m'"); - return; - } - if (delete && stats) { - gfsh.println("Error: only one option is allowed: '-d' or '-stats'"); - return; - } - - TASK task = TASK.LIST; - if (delete) { - task = TASK.DELETE; - } else if (indexName == null) { - task = TASK.LIST; - } else if (stats) { - task = TASK.STATS; - } else { - task = TASK.CREATE; - } - - - switch (task) { - case LIST: - listIndexes(regionPath, memberId, all, stats); - break; - case CREATE: - createIndexes(regionPath, memberId, indexName, isFunctionalIndex, expression, fromClause, imports); - break; - case DELETE: - if (indexName != null && (all || isRegion)) { - gfsh.println("Error: '-n' not allowed with '-region' or '-all'"); - return; - } - if (indexName == null && all == false && isRegion == false) { - gfsh.println("Error: '-d' requires '-n', '-region' or '-all'"); - return; - } - com.gemstone.gemfire.internal.tools.gfsh.app.function.command.index.DeleteType deleteType; - if (all) { - deleteType = com.gemstone.gemfire.internal.tools.gfsh.app.function.command.index.DeleteType.DELETE_ALL_INDEXES; - } else if (isRegion) { - deleteType = com.gemstone.gemfire.internal.tools.gfsh.app.function.command.index.DeleteType.DELETE_REGION_INDEXES; - } else { - deleteType = com.gemstone.gemfire.internal.tools.gfsh.app.function.command.index.DeleteType.DELETE_INDEX; - } - deleteIndexes(deleteType, regionPath, memberId, indexName); - break; - } - - } - - private void listIndexes(String regionPath, String memberId, boolean isAll, boolean isStats) throws Exception - { - // Collect indexes from all members and display common and different sets - String currentPath = gfsh.getCurrentPath(); - if (regionPath == null) { - regionPath = currentPath; - } - String fullPath = gfsh.getFullPath(regionPath, currentPath); - - Aggregator aggregator = gfsh.getAggregator(); - long startTime = System.currentTimeMillis(); - List<AggregateResults> results = (List<AggregateResults>) gfsh.getAggregator().aggregate( - new GfshFunction("index", fullPath, new Object[] { "-list", memberId, isAll, isStats }), gfsh.getAggregateRegionPath()); - long stopTime = System.currentTimeMillis(); - int i = 0; - for (AggregateResults aggregateResults : results) { - GfshData data = (GfshData)aggregateResults.getDataObject(); - if (data != null) { - Object obj = data.getDataObject(); - if (obj instanceof List) { - List<Mappable> mappableList = (List<Mappable>)data.getDataObject(); - if (mappableList != null) { - gfsh.println(++i + ". " + data.getMemberInfo().getMemberId() + " (" + data.getMemberInfo().getMemberName() + "): "); - if (mappableList.size() > 0) { - Mappable mappable = mappableList.get(0); - if (mappable.size() < mappableStatsList.size()) { - isStats = false; - } - if (isStats) { - PrintUtil.printMappableList(mappableList, "Name", mappableStatsList); - } else { - PrintUtil.printMappableList(mappableList, "Name", mappableKeyList); - } - } - gfsh.println(); - } - } else if (obj != null) { - gfsh.println(++i + ". " + data.getMemberInfo().getMemberId() + " (" + data.getMemberInfo().getMemberName() + "): " + obj); - gfsh.println(); - } - } - } - if (i == 0) { - gfsh.println("Indexes not found"); - gfsh.println(); - } - } - - /** - * - * @param regionPath - * @param memberId If null, creates index on all members. - * @param indexName - * @param isFunctionalIndex - * @param expression - * @param fromClause - * @throws Exception - */ - private void createIndexes(String regionPath, - String memberId, - String indexName, - boolean isFunctionalIndex, - String expression, - String fromClause, - String imports) throws Exception - { - - if (indexName == null) { - gfsh.println("Error: '-n' (index name) is not specified."); - return; - } - if (expression == null) { - gfsh.println("Error: '-e' (index expression) is not specified."); - return; - } - if (fromClause == null) { - gfsh.println("Error: '-from' (from clause) is not specified."); - return; - } - - String currentPath = gfsh.getCurrentPath(); - String fullPath = gfsh.getFullPath(regionPath, currentPath); - - Aggregator aggregator = gfsh.getAggregator(); - long startTime = System.currentTimeMillis(); - List<AggregateResults> results = (List<AggregateResults>) gfsh.getAggregator().aggregate( - new GfshFunction("index", fullPath, new Object[] { "-create", memberId, indexName, isFunctionalIndex, expression, fromClause, imports }), gfsh.getAggregateRegionPath()); - long stopTime = System.currentTimeMillis(); - - int i = 0; - for (AggregateResults aggregateResults : results) { - - GfshData data = (GfshData) aggregateResults.getDataObject(); - if (data == null) { - i++; - gfsh.println(i + ". " + aggregateResults.getCodeMessage()); - } else { - MemberInfo memberInfo = data.getMemberInfo(); - Object value = data.getDataObject(); - if (value != null) { - i++; - gfsh.println(i + ". " + memberInfo.getMemberId() + " (" + memberInfo.getMemberName() + "): " + value); - } else if (aggregateResults.getCodeMessage() != null) { - i++; - gfsh.print(i + ". " + memberInfo.getMemberId() + " (" + memberInfo.getMemberName() + "): "); - gfsh.println(aggregateResults.getCodeMessage()); - } - } - } - gfsh.println(); - if (gfsh.isShowTime()) { - gfsh.println("elapsed (msec): " + (stopTime - startTime)); - } - } - - private void deleteIndexes(com.gemstone.gemfire.internal.tools.gfsh.app.function.command.index.DeleteType deleteType, String regionPath, String memberId, String indexName) throws Exception - { - String message = ""; - switch (deleteType) { - case DELETE_INDEX: - case DELETE_REGION_INDEXES: - if (regionPath == null) { - regionPath = gfsh.getCurrentPath(); - } - break; - } - - // Collect indexes from all members and display common and different sets - String currentPath = gfsh.getCurrentPath(); - String fullPath = gfsh.getFullPath(regionPath, currentPath); - - switch (deleteType) { - case DELETE_INDEX: - message = "This command will remove the " + indexName + " index from the " + fullPath + "region. \nDo you want to proceed? (yes|no): "; - break; - case DELETE_REGION_INDEXES: - message = "This command will remove all of the indexes in the " + fullPath + " region. \nDo you want to proceed? (yes|no): "; - break; - case DELETE_ALL_INDEXES: - message = "This command will remove all of the indexes from all of the members. \nDo you want to proceed? (yes|no): "; - break; - } - String confirmation = gfsh.getLine(message); - if (confirmation.equalsIgnoreCase("yes") == false) { - gfsh.println("Command aborted."); - return; - } - - Aggregator aggregator = gfsh.getAggregator(); - long startTime = System.currentTimeMillis(); - List<AggregateResults> results = (List<AggregateResults>) gfsh.getAggregator().aggregate( - new GfshFunction("index", fullPath, new Object[] { "-delete", deleteType, memberId, indexName }), gfsh.getAggregateRegionPath()); - long stopTime = System.currentTimeMillis(); - - int i = 0; - for (AggregateResults aggregateResults : results) { - - GfshData data = (GfshData) aggregateResults.getDataObject(); - if (data == null) { - i++; - gfsh.println(i + ". " + aggregateResults.getCodeMessage()); - } else { - MemberInfo memberInfo = data.getMemberInfo(); - Object value = data.getDataObject(); - if (value != null) { - i++; - gfsh.print(i + ". " + memberInfo.getMemberId() + " (" + memberInfo.getMemberName() + "): "); - gfsh.println(value); - } - } - } - gfsh.println(); - if (gfsh.isShowTime()) { - gfsh.println("elapsed (msec): " + (stopTime - startTime)); - } - } - -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/49d99d4e/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/commands/key.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/commands/key.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/commands/key.java deleted file mode 100644 index 116e4ee..0000000 --- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/commands/key.java +++ /dev/null @@ -1,67 +0,0 @@ -package com.gemstone.gemfire.internal.tools.gfsh.app.commands; - -import java.util.LinkedList; -import java.util.List; - -import com.gemstone.gemfire.internal.tools.gfsh.app.CommandExecutable; -import com.gemstone.gemfire.internal.tools.gfsh.app.Gfsh; -import com.gemstone.gemfire.internal.tools.gfsh.app.util.PrintUtil; - -public class key implements CommandExecutable -{ - private Gfsh gfsh; - - public key(Gfsh gfsh) - { - this.gfsh = gfsh; - } - - public void help() - { - gfsh.println("key [-l] [<class name>] | [-?]"); - gfsh.println(" Set the key class to be used for the 'get', 'put' and 'query'"); - gfsh.println(" commands. Use the 'value' command to set the value class name."); - gfsh.println(" -l List the last enumerated keys. These keys were obtained"); - gfsh.println(" by executing one of the following commands: "); - gfsh.println(" " + gfsh.getEnumCommands()); - gfsh.println(); - } - - public void execute(String command) throws Exception - { - if (command.startsWith("key -?")) { - help(); - } else if (command.startsWith("key -l")) { - key_l(); - } else { - key(command); - } - } - - private void key(String command) throws Exception - { - LinkedList list = new LinkedList(); - gfsh.parseCommand(command, list); - if (list.size() < 2) { - gfsh.println("key = " + gfsh.getQueryKeyClassName()); - gfsh.println(" Use key <class name> to set the key class"); - } else { - if (list.size() > 1) { - gfsh.setKeyClass((String) list.get(1)); - } - } - } - - private void key_l() throws Exception - { - List keyList = gfsh.getLsKeyList(); - if (gfsh.getLsKeyList() == null) { - gfsh.println("Error: Key list undefined. The folowing commands create the key list: "); - gfsh.println(" " + gfsh.getEnumCommands()); - return; - } - - PrintUtil.printList(keyList); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/49d99d4e/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/commands/local.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/commands/local.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/commands/local.java deleted file mode 100644 index 1f51742..0000000 --- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/commands/local.java +++ /dev/null @@ -1,101 +0,0 @@ -package com.gemstone.gemfire.internal.tools.gfsh.app.commands; - -import java.util.LinkedList; -import java.util.List; - -import com.gemstone.gemfire.cache.query.Query; -import com.gemstone.gemfire.cache.query.QueryService; -import com.gemstone.gemfire.cache.query.SelectResults; -import com.gemstone.gemfire.internal.tools.gfsh.app.CommandExecutable; -import com.gemstone.gemfire.internal.tools.gfsh.app.Gfsh; -import com.gemstone.gemfire.internal.tools.gfsh.app.Nextable; -import com.gemstone.gemfire.internal.tools.gfsh.app.util.PrintUtil; - -public class local implements CommandExecutable, Nextable -{ - private Gfsh gfsh; - private SelectResults selectResults; - int lastRowPrinted = 0; - - public local(Gfsh gfsh) - { - this.gfsh = gfsh; - } - - public void help() - { - gfsh.println("local [-?] <query>"); - gfsh.println(" Execute the specified query on the local cache."); - gfsh.println(); - } - - public void execute(String command) throws Exception - { - if (command.startsWith("local -?")) { - help(); - } else { - local(command); - } - } - - public List next(Object userData) throws Exception - { - if (selectResults == null) { - return null; - } - - if (gfsh.isShowResults()) { - int rowsPrinted = PrintUtil.printSelectResults(selectResults, lastRowPrinted, lastRowPrinted+1, gfsh.getFetchSize()); - lastRowPrinted = lastRowPrinted + rowsPrinted; - gfsh.println("Fetch size: " + gfsh.getFetchSize()); - gfsh.println(" Results: " + selectResults.size() - + ", Returned: " + lastRowPrinted + "/" + selectResults.size()); - } else { - gfsh.println("Fetch size: " + gfsh.getFetchSize()); - gfsh.println(" Results: " + selectResults.size()); - } - return null; - } - - private void local(String command) throws Exception - { - LinkedList list = new LinkedList(); - gfsh.parseCommand(command, list); - if (list.size() < 2) { - gfsh.println("Error: local requires a query statment"); - } else { - String queryString = ""; - for (int i = 1; i < list.size(); i++) { - queryString += list.get(i) + " "; - } - QueryService queryService = gfsh.getCache().getQueryService(); - Query query = queryService.newQuery(queryString); - - long startTime = System.currentTimeMillis(); - Object obj = query.execute(); - long stopTime = System.currentTimeMillis(); - - selectResults = null; - if (obj instanceof SelectResults) { - selectResults = (SelectResults)obj; - if (gfsh.isShowResults()) { - int rowsPrinted = PrintUtil.printSelectResults(selectResults, 0, 1, gfsh.getFetchSize()); - lastRowPrinted = rowsPrinted; - gfsh.println("Fetch size: " + gfsh.getFetchSize()); - gfsh.println(" Results: " + selectResults.size() - + ", Returned: " + lastRowPrinted + "/" + selectResults.size()); - next n = (next)gfsh.getCommand("next"); - n.setCommand(getClass().getSimpleName()); - } else { - gfsh.println("Fetch size: " + gfsh.getFetchSize()); - gfsh.println(" Results: " + selectResults.size()); - } - } else { - gfsh.println("Results: " + obj); - } - if (gfsh.isShowTime()) { - gfsh.println("elapsed (msec): " + (stopTime - startTime)); - } - } - } -}
