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/rm.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/commands/rm.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/commands/rm.java deleted file mode 100644 index dc4b7fb..0000000 --- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/commands/rm.java +++ /dev/null @@ -1,175 +0,0 @@ -package com.gemstone.gemfire.internal.tools.gfsh.app.commands; - -import java.util.LinkedList; -import java.util.List; -import java.util.Map; - -import com.gemstone.gemfire.cache.EntryNotFoundException; -import com.gemstone.gemfire.cache.Region; -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.function.GfshFunction; -import com.gemstone.gemfire.internal.tools.gfsh.app.util.ObjectUtil; - -public class rm implements CommandExecutable -{ - private Gfsh gfsh; - - public rm(Gfsh gfsh) - { - this.gfsh = gfsh; - } - - public void help() - { - gfsh.println("rm [-a|-g] [-k] <key>|<enum list>"); - gfsh.println(" Remove keys locally and/or remotely. If no options are specified,"); - gfsh.println(" it removes <key> from the local region only."); - gfsh.println(" -a Remove keys from both the local region and the server"); - gfsh.println(" region. This command will be distributed to other caches if"); - gfsh.println(" scope is not Scope.LOCAL."); - gfsh.println(" -g Remove keys globally. Remote from the local region and all"); - gfsh.println(" server regions regardless of scope. This option also removes"); - gfsh.println(" keys from server regions with Scope.LOCAL."); - gfsh.println(" -k Remove enumerated keys. If this option is not specified, then"); - gfsh.println(" <key> is expected."); - gfsh.println(); - } - - public void execute(String command) throws Exception - { - if (command.startsWith("rm -?")) { - help(); - } else { - rm(command); - } - } - - private void rm(String command) throws Exception - { - LinkedList<String> list = new LinkedList(); - gfsh.parseCommand(command, list); - String regionPath = null; - if (list.size() > 1) { - regionPath = (String)list.get(1); - } else { - gfsh.println("Error: must specify a region path to remove"); - return; - } - - boolean enumerated = false; - boolean removeAll = false; - boolean removeServer = false; - - String val; - int keyIndex = 0; - for (int i = 1; i < list.size(); i++) { - val = list.get(i); - if (val.equals("-a")) { - removeServer = true; - } else if (val.equals("-g")) { - removeAll = true; - } else if (val.equals("-k")) { - enumerated = true; - } else { - keyIndex = i; - break; - } - } - - Region region = gfsh.getCurrentRegion(); - String numbers; - Object key; - if (removeServer) { - - if (enumerated) { - Map keyMap = gfsh.getKeyMap(list, keyIndex); - Object keys[] = keyMap.values().toArray(); - for (Object k: keyMap.values()) { - region.remove(k); - gfsh.println("removed server: " + ObjectUtil.getPrintableObject(k)); - } - - } else { - key = gfsh.getQueryKey(list, keyIndex); - region.remove(key); - gfsh.println("removed server: " + ObjectUtil.getPrintableObject(key)); - } - - } else if (removeAll) { - - if (enumerated) { - Map keyMap = gfsh.getKeyMap(list, keyIndex); - Object keys[] = keyMap.values().toArray(); - - boolean serverError = false; - List<AggregateResults> results = (List<AggregateResults>)gfsh.getAggregator().aggregate(new GfshFunction(command, gfsh.getCurrentPath(), keys), gfsh.getAggregateRegionPath()); - for (Object k: keyMap.values()) { - try { - region.localDestroy(k); - } catch (Exception ex) { - // ignore - } - gfsh.println("removed all: " + ObjectUtil.getPrintableObject(k)); - } - for (AggregateResults aggregateResults : results) { - if (aggregateResults.getCode() == AggregateResults.CODE_ERROR) { - gfsh.println("Error from server: " + aggregateResults.getCodeMessage()); - } - } - if (serverError) { - gfsh.println("Error: One or more keys may have not been removed from the server(s)"); - } - } else { - key = gfsh.getQueryKey(list, keyIndex); - - List<AggregateResults> results = (List<AggregateResults>)gfsh.getAggregator().aggregate(new GfshFunction(command, gfsh.getCurrentPath(), new Object[] { key }), gfsh.getAggregateRegionPath()); - try { - region.localDestroy(key); - } catch (Exception ex) { - // ignore - } - boolean serverError = false; - for (AggregateResults aggregateResults : results) { - if (aggregateResults.getCode() == AggregateResults.CODE_ERROR) { - gfsh.println("Error from server: " + aggregateResults.getCodeMessage()); - serverError = true; - } - } - if (serverError) { - gfsh.println("Error: One or more keys may have not been removed from the server(s)"); - } else { - gfsh.println("removed: " + ObjectUtil.getPrintableObject(key)); - } - } - - } else { - // remove local - if (enumerated) { - Map keyMap = gfsh.getKeyMap(list, keyIndex); - for (Object k: keyMap.values()) { - // remove local - try { - region.localDestroy(k); - gfsh.println("removed local: " + ObjectUtil.getPrintableObject(k)); - } catch (EntryNotFoundException ex) { - gfsh.println("local (not found): " + ObjectUtil.getPrintableObject(k)); - } - - } - } else { - key = gfsh.getQueryKey(list, keyIndex); - // remove local - try { - region.localDestroy(key); - gfsh.println("removed local: " + ObjectUtil.getPrintableObject(key)); - } catch (EntryNotFoundException ex) { - gfsh.println("local (not found): " + ObjectUtil.getPrintableObject(key)); - } - } - } - } - - -}
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/rmdir.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/commands/rmdir.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/commands/rmdir.java deleted file mode 100644 index 71491c8..0000000 --- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/commands/rmdir.java +++ /dev/null @@ -1,249 +0,0 @@ -package com.gemstone.gemfire.internal.tools.gfsh.app.commands; - -import java.util.LinkedList; -import java.util.List; - -import com.gemstone.gemfire.cache.Cache; -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.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.aggregator.functions.util.RegionDestroyFunction; -import com.gemstone.gemfire.internal.tools.gfsh.app.command.CommandClient; -import com.gemstone.gemfire.internal.tools.gfsh.app.command.task.RegionDestroyTask; -import com.gemstone.gemfire.internal.tools.gfsh.app.command.task.data.MemberInfo; -import com.gemstone.gemfire.internal.tools.gfsh.command.CommandResults; -import com.gemstone.gemfire.internal.tools.gfsh.util.RegionUtil; - -public class rmdir implements CommandExecutable -{ - private Gfsh gfsh; - - public rmdir(Gfsh gfsh) - { - this.gfsh = gfsh; - } - - public void help() - { - gfsh.println("rmdir [-a|-g|-s] [-?] <region path>"); - gfsh.println(" Remove the local region if no options specified. The region path"); - gfsh.println(" can be absolute or relative."); - gfsh.println(" -a Remove both the local region and the server region."); - gfsh.println(" The region destroy will be distributed to other caches if the"); - gfsh.println(" scope is not Scope.LOCAL."); - gfsh.println(" -g Remove globally. Remove the local region and all server"); - gfsh.println(" regions regardless of scope. This option also removes server"); - gfsh.println(" regions with Scope.LOCAL."); - gfsh.println(" -s Remove only the server region. The local region is not destroyed."); - gfsh.println(" The region destroy 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("rmdir -?")) { - help(); - } else if (command.startsWith("rmdir -a")) { - rmdir_a(command); - } else if (command.startsWith("rmdir -g")) { - rmdir_g(command); - } else if (command.startsWith("rmdir -s")) { - rmdir_s(command); - } else { - rmdir_local(command); - } - } - - private void rmdir(String command) throws Exception - { - int index = command.indexOf(" "); - if (index == -1) { - gfsh.println("Error: rmdir requires a region path to remove"); - } else { - Cache cache = gfsh.getCache(); - Region region; - String newPath = command.substring(index).trim(); - String fullPath = gfsh.getFullPath(newPath, gfsh.getCurrentPath()); - if (fullPath == null) { - gfsh.println("Error: region path must be provided. mkdir <regionPath>"); - } else { - // absolute path - region = cache.getRegion(fullPath); - if (region == null) { - gfsh.println("Error: region does not exist - " + fullPath); - return; - } - region.close(); - gfsh.println("Region removed: " + fullPath); - } - } - } - - private void rmdir_local(String command) - { - LinkedList list = new LinkedList(); - gfsh.parseCommand(command, list); - String regionPath = null; - if (list.size() > 1) { - regionPath = (String)list.get(1); - } else { - gfsh.println("Error: must specify a region path to remove"); - return; - } - - remove_local(regionPath); - } - - private void rmdir_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 { - gfsh.println("Error: must specify a region path to remove"); - return; - } - - remove_server(regionPath, false); - remove_local(regionPath); - } - - private void rmdir_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 { - gfsh.println("Error: must specify a region path to remove"); - return; - } - - remove_server(regionPath, true); - remove_local(regionPath); - } - - private void rmdir_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 { - gfsh.println("Error: must specify a region path to remove"); - return; - } - - remove_server(regionPath, false); - } - - private void remove_local(String regionPath) - { - 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 remove top level"); - } else { - Region region = gfsh.getCache().getRegion(fullPath); - if (region == null) { - gfsh.println("Error: undefined region path " + fullPath); - return; - } - region.close(); - - // correct the current path if the removed region path - // lies in the current path - String currentSplit[] = currentPath.split("/"); - Cache cache = gfsh.getCache(); - Region currentRegion = null; - if (currentSplit.length > 1) { - currentRegion = region = cache.getRegion(currentSplit[1]); - if (region != null) { - for (int i = 2; i < currentSplit.length; i++) { - region = region.getSubregion(currentSplit[i]); - if (region == null) { - break; - } - currentRegion = region; - } - } - } - if (currentRegion == null) { - gfsh.setCurrentPath("/"); - } else { - gfsh.setCurrentPath(currentRegion.getFullPath()); - } - gfsh.setCurrentRegion(currentRegion); - - gfsh.println("Region removed from local VM: " + regionPath); - } - } - - private void remove_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 remove top level"); - } else { - - String confirmation = gfsh.getLine("This command will remove 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<CommandResults> aggregateList = (List<CommandResults>)aggregator.aggregate(new RegionDestroyFunction(fullPath), gfsh.getAggregateRegionPath()); - - int i = 1; - for (CommandResults commandResults : aggregateList) { - - MemberInfo memberInfo = (MemberInfo)commandResults.getDataObject(); - gfsh.print(i + ". " + memberInfo.getMemberName() + "(" + memberInfo.getMemberId() + ")" + ": "); - if (commandResults.getCode() == RegionDestroyTask.ERROR_REGION_DESTROY) { - gfsh.println("error - " + commandResults.getCodeMessage()); - } else { - Region region = RegionUtil.getRegion(fullPath, Scope.LOCAL, DataPolicy.NORMAL, null); - gfsh.println("region removed: " + region.getFullPath()); - } - i++; - } - } else { - CommandClient commandClient = gfsh.getCommandClient(); - CommandResults commandResults = commandClient.execute(new RegionDestroyTask(fullPath)); - MemberInfo memberInfo = (MemberInfo)commandResults.getDataObject(); - gfsh.print(memberInfo.getMemberName() + "(" + memberInfo.getMemberId() + ")" + ": "); - if (commandResults.getCode() == RegionDestroyTask.ERROR_REGION_DESTROY) { - gfsh.println("error - " + commandResults.getCodeMessage()); - } else { - Region region = RegionUtil.getRegion(regionPath, Scope.LOCAL, DataPolicy.NORMAL, null); - gfsh.println("region removed: " + 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/select.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/commands/select.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/commands/select.java deleted file mode 100644 index 9caf017..0000000 --- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/commands/select.java +++ /dev/null @@ -1,139 +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.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.command.task.QueryResults; -import com.gemstone.gemfire.internal.tools.gfsh.app.command.task.QueryTask; -import com.gemstone.gemfire.internal.tools.gfsh.app.util.PrintUtil; -import com.gemstone.gemfire.internal.tools.gfsh.command.CommandResults; - -public class select implements CommandExecutable, Nextable -{ - private final static int DEFAULT_LIMIT = 1000; - private final static int MAX_LIMIT = 5000; - - private Gfsh gfsh; - - private int limit = DEFAULT_LIMIT; - - public select(Gfsh gfsh) - { - this.gfsh = gfsh; - gfsh.setSelectLimit(limit); - } - - public void help() - { - gfsh.println("select [-l <limit>|-show] | -?"); - gfsh.println("select <tuples where ...> | -?"); - gfsh.println(" Execute the specified query in the remote cache."); - gfsh.println(" -l set the result set size limit, i.e.,"); - gfsh.println(" 'select ... from ... limit <limit>'. Note that gfsh automatically"); - gfsh.println(" appends 'limit' to your select statement. Do not add your own limit."); - gfsh.println(" The default limit is 1000. The allowed max limit is 5000."); - gfsh.println(" -show Displays the select limit value."); - gfsh.println(); - } - - public void execute(String command) throws Exception - { - LinkedList<String> list = new LinkedList(); - gfsh.parseCommand(command, list); - - String queryString = command; - - if (list.contains("-?")) { - help(); - } else { - for (int i = 1; i < list.size(); i++) { - String token = list.get(i); - if (token.equals("-l")) { - if (i + 1 >= list.size()) { - gfsh.println("Error: '-l' requires limit value"); - return; - } - int val = Integer.parseInt((String) list.get(++i)); - if (val > MAX_LIMIT) { - limit = MAX_LIMIT; - } else if (val < 0) { - limit = 0; - } else { - limit = val; - } - gfsh.setSelectLimit(limit); - return; - } else if (token.equals("-show")) { - select_show(); - return; - } - } - - queryString += " limit " + limit; - select(queryString, true); - } - } - - public List getRemoteKeys(String regionPath) throws Exception - { - List list = select("select * from " + regionPath + ".keySet limit " + limit, true); - return list; - } - - public void select_show() - { - gfsh.println("select limit = " + limit); - } - - public List select(String queryString, boolean nextEnabled) throws Exception - { - long startTime = System.currentTimeMillis(); - CommandResults cr = gfsh.getCommandClient().execute(new QueryTask(queryString, gfsh.getFetchSize(), nextEnabled)); - long stopTime = System.currentTimeMillis(); - if (cr.getCode() == QueryTask.ERROR_QUERY) { - gfsh.println(cr.getCodeMessage()); - return null; - } - QueryResults results = (QueryResults) cr.getDataObject(); - if (results == null) { - gfsh.println("No results"); - return null; - } - - List list = null; - Object obj = results.getResults(); - if (obj instanceof SelectResults) { - SelectResults sr = (SelectResults) results.getResults(); - list = sr.asList(); - int startRowNum = results.getReturnedSize() - sr.size() + 1; - if (gfsh.isShowResults()) { - int rowsPrinted = PrintUtil.printSelectResults(sr, 0, startRowNum, sr.size()); - gfsh.println("Fetch size: " + gfsh.getFetchSize() + ", Limit: " + limit); - gfsh.println(" Results: " + sr.size() - + ", Returned: " + results.getReturnedSize() + "/" + results.getActualSize()); - next n = (next)gfsh.getCommand("next"); - n.setCommand(getClass().getSimpleName()); - } else { - gfsh.println("Fetch size: " + gfsh.getFetchSize() + ", Limit: " + limit); - gfsh.println(" Results: " + sr.size() + - ", Returned: " + results.getReturnedSize() + "/" + results.getActualSize()); - } - } else { - gfsh.println("Results: " + obj); - } - if (gfsh.isShowTime()) { - gfsh.println("elapsed (msec): " + (stopTime - startTime)); - } - return list; - } - - public List next(Object userData) throws Exception - { - select(null, true); - return null; - } -} 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/show.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/commands/show.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/commands/show.java deleted file mode 100644 index acea0de..0000000 --- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/commands/show.java +++ /dev/null @@ -1,240 +0,0 @@ -package com.gemstone.gemfire.internal.tools.gfsh.app.commands; - -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.Collections; -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.misc.util.ReflectionUtil; - -import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; - -public class show implements CommandExecutable -{ - private Gfsh gfsh; - - public show(Gfsh gfsh) - { - this.gfsh = gfsh; - } - - public void help() - { - gfsh.println("show [-p [true|false]]"); - gfsh.println(" [-t [true|false]]"); - gfsh.println(" [-c|-k|-v]"); - gfsh.println(" [-table [true|false]"); - gfsh.println(" [-type [true|false]"); - gfsh.println(" [-col <collection entry print count>]"); - gfsh.println(); - gfsh.println(" [-?]"); - gfsh.println(" Show or toggle settings."); - gfsh.println(" <no option> Show all current settings."); - - gfsh.println(" -p Toggle print. If enabled, results are printed to stdout."); - gfsh.println(" -t Toggle the time taken to execute each command."); - gfsh.println(" -c Show configuration"); - gfsh.println(" -k Show key class fields. Use the 'key' command to set key class."); - gfsh.println(" -v Show value class fields. Use the 'value' command to set value class."); - gfsh.println(" -table Set the print format to the tabular or catalog form. The"); - gfsh.println(" tabular form prints in a table with a column header. The catalog"); - gfsh.println(" form prints in each row in a data structure form."); - gfsh.println(" -type Enable or disable printing the data type. This option is"); - gfsh.println(" valid only for the '-table false' option."); - gfsh.println(" -col <collection entry print count> In the catalog mode, gfsh"); - gfsh.println(" prints the contents of Map and Collection objects. By default, it"); - gfsh.println(" prints 5 entries per object. Use this option to change the count."); - gfsh.println(); - } - - public void execute(String command) throws Exception - { - if (command.startsWith("show -?")) { - help(); - } else if (command.startsWith("show -table")) { - show_table(command); - } else if (command.startsWith("show -type")) { - show_type(command); - } else if (command.startsWith("show -col")) { - show_count(command); - } else if (command.startsWith("show -p")) { - show_p(command); - } else if (command.startsWith("show -t")) { - show_t(command); - } else if (command.startsWith("show -c")) { - show_c(); - } else if (command.startsWith("show -k")) { - show_k(); - } else if (command.startsWith("show -v")) { - show_v(); - } else { - show(); - } - } - - private void show_table(String command) throws Exception - { - ArrayList<String> list = new ArrayList(); - gfsh.parseCommand(command, list); - if (list.size() >= 3) { - boolean enable = list.get(2).equalsIgnoreCase("true"); - gfsh.setTableFormat(enable); - } else { - gfsh.setTableFormat(!gfsh.isTableFormat()); - } - gfsh.println("show -table is " + (gfsh.isTableFormat() ? "true" : "false")); - - } - - private void show_type(String command) throws Exception - { - ArrayList<String> list = new ArrayList(); - gfsh.parseCommand(command, list); - if (list.size() >= 3) { - boolean enable = list.get(2).equalsIgnoreCase("true"); - gfsh.setPrintType(enable); - } else { - gfsh.setPrintType(!gfsh.isPrintType()); - } - gfsh.println("show -type is " + (gfsh.isPrintType() ? "true" : "false")); - - } - - private void show_count(String command) throws Exception - { - LinkedList list = new LinkedList(); - gfsh.parseCommand(command, list); - if (list.size() < 3) { - gfsh.println("Error: must specify <collection entry print count>. Current count is " + gfsh.getCollectionEntryPrintCount()); - return; - } - try { - int count = Integer.parseInt((String)list.get(2)); - gfsh.setCollectionEntryPrintCount(count); - } catch (Exception ex) { - gfsh.println("Error: " + ex.getClass().getSimpleName() + " - " + ex.getMessage()); - } - } - - public void show_p(String command) - { - ArrayList<String> list = new ArrayList(); - gfsh.parseCommand(command, list); - if (list.size() >= 3) { - boolean enable = list.get(2).equalsIgnoreCase("true"); - gfsh.setShowResults(enable); - } else { - gfsh.setShowResults(!gfsh.isShowResults()); - } - gfsh.println("show -p is " + (gfsh.isShowResults() ? "true" : "false")); - } - - private void show_t(String command) throws Exception - { - ArrayList<String> list = new ArrayList(); - gfsh.parseCommand(command, list); - if (list.size() >= 3) { - boolean enable = list.get(2).equalsIgnoreCase("true"); - gfsh.setShowResults(enable); - } else { - gfsh.setShowTime(!gfsh.isShowTime()); - } - gfsh.println("show -t is " + (gfsh.isShowTime() ? "true" : "false")); - } - - @SuppressFBWarnings(value="NM_METHOD_CONSTRUCTOR_CONFUSION",justification="This is method and not constructor") - public void show() - { - show_c(); - gfsh.println(); - show_k(); - gfsh.println(); - show_v(); - } - - public void show_c() - { - db dbCommand = (db)gfsh.getCommand("db"); -// String dbInit = dbCommand.getDbInitCommand(); - - gfsh.println(" connected = " + gfsh.isConnected()); - if (dbCommand/*dbInit*/ != null) { - gfsh.println(" db = " + /*dbInit*/dbCommand.getDbInitCommand()); - } - gfsh.println(" echo = " + gfsh.isEcho()); - if (gfsh.getEndpoints() == null && gfsh.getEndpoints() == null) { - gfsh.println(" locators = null"); - gfsh.println(" servers = null"); - } else { - if (gfsh.isLocator()) { - gfsh.println(" locators = " + gfsh.getEndpoints()); - if (gfsh.getServerGroup() == null) { - gfsh.println(" server group = <undefined>"); - } else { - gfsh.println(" server group = " + gfsh.getServerGroup()); - } - } else { - gfsh.println(" servers = " + gfsh.getEndpoints()); - } - gfsh.println(" read timeout = " + gfsh.getReadTimeout()); - } - - gfsh.println(" select limit = " + gfsh.getSelectLimit()); - gfsh.println(" fetch = " + gfsh.getFetchSize()); - gfsh.println(" key = " + gfsh.getQueryKeyClassName()); - gfsh.println(" value = " + gfsh.getValueClassName()); - gfsh.println(" show -p = " + gfsh.isShowResults()); - gfsh.println(" show -t = " + gfsh.isShowTime()); - gfsh.println(" show -table = " + gfsh.isTableFormat()); - gfsh.println(" show -type = " + gfsh.isPrintType()); - gfsh.println(" show -col = " + gfsh.getCollectionEntryPrintCount()); - gfsh.println(" zone (hours) = " + gfsh.getZoneDifference() / (60 * 60 * 1000)); -// gfsh.println("command region = " + gfsh.getCommandRegionPath()); - } - - public void show_k() - { - printClassSetters(gfsh.getQueryKeyClass(), "key"); - } - - public void show_v() - { - printClassSetters(gfsh.getValueClass(), "value"); - } - - private void printClassSetters(Class cls, String header) - { - if (cls == null) { - gfsh.println(header + " class: undefined"); - } else { - gfsh.println(header + " class " + cls.getName()); - gfsh.println("{"); - try { - Map<String, Method> setterMap = ReflectionUtil.getAllSettersMap(cls); - ArrayList list = new ArrayList(setterMap.keySet()); - Collections.sort(list); - for (Object object : list) { - Method method = setterMap.get(object); - if (isSupportedMethod(method)) { - gfsh.println(" " + method.getName().substring(3) + "::" - + method.getParameterTypes()[0].getCanonicalName()); -// gfsh.println(" " + method.getParameterTypes()[0].getCanonicalName() + " " + method.getName().substring(3)); - } - } - } catch (Exception e) { - e.printStackTrace(); - } - gfsh.println("}"); - } - } - - - private boolean isSupportedMethod(Method method) - { - return true; - } - -} 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/size.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/commands/size.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/commands/size.java deleted file mode 100644 index 21f7c49..0000000 --- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/commands/size.java +++ /dev/null @@ -1,281 +0,0 @@ -package com.gemstone.gemfire.internal.tools.gfsh.app.commands; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; - -import com.gemstone.gemfire.cache.Cache; -import com.gemstone.gemfire.cache.Region; -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.functions.util.LocalRegionInfoFunction; -import com.gemstone.gemfire.internal.tools.gfsh.app.cache.data.MapMessage; -import com.gemstone.gemfire.internal.tools.gfsh.app.cache.data.Mappable; -import com.gemstone.gemfire.internal.tools.gfsh.app.command.task.RegionSizeTask; -import com.gemstone.gemfire.internal.tools.gfsh.app.misc.util.StringUtil; -import com.gemstone.gemfire.internal.tools.gfsh.app.util.PrintUtil; -import com.gemstone.gemfire.internal.tools.gfsh.command.CommandResults; - -public class size implements CommandExecutable -{ - private Gfsh gfsh; - - public size(Gfsh gfsh) - { - this.gfsh = gfsh; - } - - public void help() - { - gfsh.println("size [-m|-s] | [-?] <region path>"); - gfsh.println(" Display the local and server region sizes. If no option"); - gfsh.println(" is provided then it displays the local region size"); - gfsh.println(" -m List all server member region sizes."); - gfsh.println(" -s Display the region size of the connected server."); - gfsh.println(); - } - - public void execute(String command) throws Exception - { - if (command.startsWith("size -?")) { - help(); - } else if (command.startsWith("size -m")) { - size_m(command); - } else if (command.startsWith("size -s")) { - size_s(command); - } else { - size(command); - } - } - - // local region size - private void size(String command) throws Exception - { - LinkedList list = new LinkedList(); - gfsh.parseCommand(command, list); - String regionPath; - if (list.size() == 1) { - regionPath = gfsh.getCurrentPath(); - } else if (list.size() == 2) { - regionPath = (String)list.get(1); - } else { - regionPath = (String)list.get(2); - } - - regionPath = regionPath.trim(); - if (regionPath.equals("/")) { - gfsh.println("Error: Invalid path. Root path not allowed."); - return; - } - - regionPath = gfsh.getFullPath(regionPath, gfsh.getCurrentPath()); - - gfsh.println(" Region: " + regionPath); - - // Local region - Cache cache = gfsh.getCache(); - Region region = cache.getRegion(regionPath); - if (region == null) { - gfsh.println("Error: region undefine - " + regionPath); - } else { - gfsh.println(" Local region size: " + region.size()); - } - } - - private void size_m(String command) throws Exception - { - if (gfsh.getAggregateRegionPath() == null) { - gfsh.println("Error: The aggregate region path is not specified. Use the command "); - gfsh.println("'connect -a <region path>' to specify any existing partitioned region path in the server."); - return; - } - LinkedList list = new LinkedList(); - gfsh.parseCommand(command, list); - String regionPath; - if (list.size() == 2) { - regionPath = gfsh.getCurrentPath(); - } else { - regionPath = (String) list.get(2); - } - - regionPath = gfsh.getFullPath(regionPath, gfsh.getCurrentPath()); - - if (regionPath.equals("/")) { - gfsh.println("Error: invalid region \"/\". Change to a valid region or specify the region path, i.e. size -a /foo"); - return; - } - - long startTime = System.currentTimeMillis(); - List<MapMessage> resultList = (List<MapMessage>)gfsh.getAggregator().aggregate(new LocalRegionInfoFunction(regionPath), gfsh.getAggregateRegionPath()); - long stopTime = System.currentTimeMillis(); - - String memberIdHeader = "Member Id"; - String memberNameHeader = "Member Name"; - String regionSizeHeader = "Region Size"; - - - // Find the max string sizes - int memberIdMax = memberIdHeader.length(); - int memberNameMax = memberNameHeader.length(); - int regionSizeMax = regionSizeHeader.length(); - boolean isPR = false; - boolean isPeerClient = false; - String returnedRegionPath = null; - HashMap<String, Mappable> infoMap = new HashMap<String, Mappable>(); - for (int i = 0; i < resultList.size(); i++) { - Mappable info = resultList.get(i); - try { - if (info.getByte("Code") == AggregateResults.CODE_ERROR) { - gfsh.println("Error: " + info.getString("CodeMessage")); - return; - } - } catch (Exception ex) { - // ignore - } - - isPR = info.getBoolean("IsPR"); - if (isPR) { - try { - isPeerClient = info.getBoolean("IsPeerClient"); - } catch (Exception ex) { - continue; - } - if (isPeerClient) { - continue; - } - } - - returnedRegionPath = info.getString("RegionPath"); - String memberId = info.getString("MemberId"); - if (memberIdMax < memberId.length()) { - memberIdMax = memberId.length(); - } - String memberName = info.getString("MemberName"); - if (memberName != null && memberNameMax < memberName.length()) { - memberNameMax = memberName.length(); - } - String val = Integer.toString(info.getInt("RegionSize")); - if (regionSizeMax < val.length()) { - regionSizeMax = val.length(); - } - infoMap.put(info.getString("MemberId"), info); - } - - ArrayList keyList = new ArrayList(infoMap.keySet()); - Collections.sort(keyList); - - - // display - gfsh.println(" Region: " + returnedRegionPath); - if (isPR) { - gfsh.println("Region Type: Partitioned"); - } else { - gfsh.println("Region Type: Replicated"); - } - gfsh.print(StringUtil.getRightPaddedString(memberIdHeader, memberIdMax, ' ')); - gfsh.print(" "); - gfsh.print(StringUtil.getRightPaddedString(memberNameHeader, memberNameMax, ' ')); - gfsh.print(" "); - gfsh.println(regionSizeHeader); - gfsh.print(StringUtil.getRightPaddedString("---------", memberIdMax, ' ')); - gfsh.print(" "); - gfsh.print(StringUtil.getRightPaddedString("-----------", memberNameMax, ' ')); - gfsh.print(" "); - gfsh.println(StringUtil.getRightPaddedString("-----------", regionSizeMax, ' ')); - - int totalRegionSize = 0; - for (int i = 0; i < keyList.size(); i++) { - Mappable info = infoMap.get(keyList.get(i)); - try { - if (info.getByte("Code") == AggregateResults.CODE_ERROR) { - gfsh.println("Error: " + info.getString("CodeMessage")); - return; - } - } catch (Exception ex) { - // ignore - } - isPR = info.getBoolean("IsPR"); - gfsh.print(StringUtil.getRightPaddedString(info.getString("MemberId"), memberIdMax, ' ')); - gfsh.print(" "); - gfsh.print(StringUtil.getRightPaddedString(info.getString("MemberName"), memberNameMax, ' ')); - gfsh.print(" "); - gfsh.println(StringUtil.getLeftPaddedString(Integer.toString(info.getInt("RegionSize")), regionSizeMax, ' ')); - totalRegionSize += info.getInt("RegionSize"); - } - - gfsh.println(); - if (isPR) { - gfsh.print(StringUtil.getLeftPaddedString("Total: ", - memberIdMax + memberNameMax + 2*2, ' ')); - gfsh.println(StringUtil.getLeftPaddedString(Integer.toString(totalRegionSize), regionSizeMax, ' ')); - } - gfsh.println(); - if (gfsh.isShowTime()) { - gfsh.println("elapsed (msec): " + (stopTime - startTime)); - } - } - - private void size_s(String command) throws Exception - { - LinkedList list = new LinkedList(); - gfsh.parseCommand(command, list); - String regionPath; - if (list.size() == 2) { - regionPath = gfsh.getCurrentPath(); - } else { - regionPath = (String) list.get(2); - } - regionPath = regionPath.trim(); - if (regionPath.equals("/")) { - gfsh.println("Error: Invalid path. Root path not allowed."); - return; - } - - regionPath = gfsh.getFullPath(regionPath, gfsh.getCurrentPath()); - - gfsh.println(" Region: " + regionPath); - - // Local region - Cache cache = gfsh.getCache(); - Region region = cache.getRegion(regionPath); - if (region == null) { - gfsh.println("Error: region undefine - " + regionPath); - } else { - gfsh.println(" Local region size: " + region.size()); - } - - // Server region - CommandResults results = gfsh.getCommandClient().execute(new RegionSizeTask(regionPath)); - Object obj = results.getDataObject(); - if (obj == null) { - gfsh.println("Error: Unable to get size from the server - " + results.getCodeMessage()); - } else { - ArrayList sizeList = new ArrayList(2); - sizeList.add(results.getDataObject()); - PrintUtil.printMappableList(sizeList); - } - } - - -// private void size(String command) throws Exception -// { -// LinkedList list = new LinkedList(); -// gfsh.parseCommand(command, list); -// -// if (list.size() < 2) { -// gfsh.println("Error: size requires <query predicate>"); -// } else { -// Object queryKey = gfsh.getQueryKey(list); -// if (queryKey == null) { -// return; -// } -// int size = gfsh.getLookupService().size(gfsh.getQueryRegionPath(), queryKey); -// gfsh.println("Size: " + size); -// } -// -// } - -} 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/value.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/commands/value.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/commands/value.java deleted file mode 100644 index a689051..0000000 --- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/commands/value.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 value implements CommandExecutable -{ - private Gfsh gfsh; - - public value(Gfsh gfsh) - { - this.gfsh = gfsh; - } - - public void help() - { - gfsh.println("value [-?] <class name>"); - gfsh.println(" Set the value class to be used for the 'put' command."); - gfsh.println(" Use the 'key' command to set the key class name."); - gfsh.println(); - } - - public void execute(String command) throws Exception - { - if (command.startsWith("value -?")) { - help(); - } else { - value(command); - } - } - - private void value(String command) throws Exception - { - LinkedList list = new LinkedList(); - gfsh.parseCommand(command, list); - if (list.size() < 2) { - gfsh.println("value = " + gfsh.getValueClassName()); - gfsh.println(" Use value <class name> to set the value class"); - } else { - if (list.size() > 1) { - gfsh.setValueClass((String) list.get(1)); - } - } - } - -} 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/which.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/commands/which.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/commands/which.java deleted file mode 100644 index 8d3ac52..0000000 --- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/commands/which.java +++ /dev/null @@ -1,189 +0,0 @@ -package com.gemstone.gemfire.internal.tools.gfsh.app.commands; - -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Set; - -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; -import com.gemstone.gemfire.internal.tools.gfsh.app.util.PrintUtil; - -public class which implements CommandExecutable -{ - private Gfsh gfsh; - - public which(Gfsh gfsh) - { - this.gfsh = gfsh; - } - - public void help() - { - gfsh.println("which [-p <region path>] [-r] <query predicate> | -k <number> | [-?]"); - gfsh.println(" Show the members and regions that have the specified key."); - gfsh.println(" -p <region path> The region path in which to find the specified key."); - gfsh.println(" -r Search recursively. It search all of the subregions including"); - gfsh.println(" the specified region or the current region if not specified."); - gfsh.println(" -k <number> Use an enumerated key. Use 'ls -k' to get the list"); - gfsh.println(" of enumerated keys. Only one key number is supported."); - 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("Examples: "); - gfsh.println(" which 'string' -- string key"); - gfsh.println(" which 10f -- float key"); - gfsh.println(" which -k 1"); - gfsh.println(" which -p /foo/yong -r x=10.0 and y=1 and date=to_date('04/10/2009', 'MM/dd/yyyy')"); - gfsh.println(); - } - - public void execute(String command) throws Exception - { - if (command.startsWith("which -?")) { - help(); - } else { - which(command); - } - } - - private Object getKeyFromInput(List list, int index) throws Exception - { - String input = (String) list.get(index); - Object key = null; - 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 null; - } - key = input.substring(1, lastIndex); // lastIndex exclusive - } else { - key = gfsh.getQueryKey(list, index); - } - return key; - } - - private void which(String command) throws Exception - { - LinkedList<String> list = new LinkedList(); - gfsh.parseCommand(command, list); - if (list.size() < 2) { - gfsh.println("Error: 'which' requires a query predicate or key number"); - return; - } - - String regionPath = gfsh.getCurrentPath(); - boolean recursive = false; - Object key = null; - for (int i = 1; i < list.size(); i++) { - String token = list.get(i); - if (token.equals("-p")) { - if (i + 1 >= list.size()) { - gfsh.println("Error: '-p' requires region path"); - return; - } - regionPath = list.get(++i); - } else if (token.equals("-r")) { - recursive = true; - } else if (token.equals("-k")) { - if (i + 1 >= list.size()) { - gfsh.println("Error: '-k' requires key number"); - return; - } - int keyNum = Integer.parseInt((String) list.get(++i)); - key = gfsh.getKeyFromKeyList(keyNum); - break; - } else { - int inputIndex = i; - key = getKeyFromInput(list, inputIndex); - break; - } - } - - if (key == null) { - gfsh.println("Error: Key is not defined."); - return; - } - executeWhich(regionPath, key, recursive); - } - - private void executeWhich(String regionPath, Object key, boolean recursive) throws Exception - { - 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("which", fullPath, new Object[] { key, recursive }), gfsh.getAggregateRegionPath()); - long stopTime = System.currentTimeMillis(); - - int i = 0; - for (AggregateResults aggregateResults : results) { - GfshData data = (GfshData) aggregateResults.getDataObject(); - if (aggregateResults.getCode() == AggregateResults.CODE_ERROR) { - gfsh.println("Error: " + aggregateResults.getCodeMessage()); - if (gfsh.isDebug() && aggregateResults.getException() != null) { - aggregateResults.getException().printStackTrace(); - } - break; - } - Object value = data.getDataObject(); - if (value != null) { - MemberInfo memberInfo = data.getMemberInfo(); - Map map = (Map) value; - Set<Map.Entry> entrySet = map.entrySet(); - if (map != null && map.size() > 0) { - i++; - gfsh.print(i + ". " + memberInfo.getMemberName() + " (" + memberInfo.getMemberId() + ")"); - Object obj = data.getUserData(); - if (obj != null) { - if (obj instanceof Map) { - Map infoMap = (Map)obj; - boolean isPrimary = (Boolean)infoMap.get("IsPrimary"); - int bucketId = (Integer)infoMap.get("BucketId"); - if (isPrimary) { - gfsh.println(" -- BucketId=" + bucketId + " *Primary PR*"); - } else { - gfsh.println(" -- BucketId=" + bucketId); - } - } - } else { - gfsh.println(); - } - PrintUtil.printEntries(map, map.size(), null, "Region", "Value", false, gfsh.isShowResults()); - gfsh.println(); - } - } - } - if (i == 0) { - gfsh.println("Key is not found."); - } - 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/zone.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/commands/zone.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/commands/zone.java deleted file mode 100644 index 4fb2c00..0000000 --- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/commands/zone.java +++ /dev/null @@ -1,49 +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 zone implements CommandExecutable -{ - private Gfsh gfsh; - - public zone(Gfsh gfsh) - { - this.gfsh = gfsh; - } - - public void help() - { - gfsh.println("zone [-?] <hours>"); - gfsh.println(" Set the zone difference. This value is added to all time-related data."); - gfsh.println(" For example, set this value to -3 if the data in the cache is"); - gfsh.println(" timestamped in EST and you are running this program in PST."); - gfsh.println(); - } - - public void execute(String command) throws Exception - { - if (command.startsWith("zone -?")) { - help(); - } else { - zone(command); - } - } - - // zone hours - // zone -3 - private void zone(String command) throws Exception - { - LinkedList list = new LinkedList(); - gfsh.parseCommand(command, list); - if (list.size() < 2) { - gfsh.println("zone = " + gfsh.getZoneDifference() / (60 * 60 * 1000)); - gfsh.println(" Use zone <hours> to change the zone hour difference"); - } else { - int hours = Integer.parseInt((String) list.get(1)); - gfsh.setZoneDifference(hours * 60 * 60 * 1000L);//FindBugs - integer multiplication cast to long - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/49d99d4e/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/function/GfshData.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/function/GfshData.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/function/GfshData.java deleted file mode 100644 index 1d8c631..0000000 --- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/function/GfshData.java +++ /dev/null @@ -1,86 +0,0 @@ -package com.gemstone.gemfire.internal.tools.gfsh.app.function; - -import java.io.DataInput; -import java.io.DataOutput; -import java.io.IOException; - -import com.gemstone.gemfire.DataSerializable; -import com.gemstone.gemfire.DataSerializer; -import com.gemstone.gemfire.cache.Cache; -import com.gemstone.gemfire.cache.CacheFactory; -import com.gemstone.gemfire.distributed.DistributedMember; -import com.gemstone.gemfire.internal.tools.gfsh.app.command.task.data.MemberInfo; - -public class GfshData implements DataSerializable -{ - private static final long serialVersionUID = 1L; - - private MemberInfo memberInfo; - private Object dataObject; - private Object userData; - - public GfshData() {} - - public GfshData(Object dataObject) - { - Cache cache = CacheFactory.getAnyInstance(); - memberInfo = new MemberInfo(); - DistributedMember member = cache.getDistributedSystem().getDistributedMember(); - memberInfo.setHost(member.getHost()); - memberInfo.setMemberId(member.getId()); - memberInfo.setMemberName(cache.getName()); - memberInfo.setPid(member.getProcessId()); - - this.dataObject = dataObject; - } - - public GfshData(MemberInfo memberInfo, Object dataObject) - { - this.memberInfo = memberInfo; - this.dataObject = dataObject; - } - - public MemberInfo getMemberInfo() - { - return memberInfo; - } - - public void setMemberInfo(MemberInfo memberInfo) - { - this.memberInfo = memberInfo; - } - - public Object getDataObject() - { - return dataObject; - } - - public void setDataObject(Object dataObject) - { - this.dataObject = dataObject; - } - - public Object getUserData() - { - return userData; - } - - public void setUserData(Object userData) - { - this.userData = userData; - } - - public void fromData(DataInput in) throws IOException, ClassNotFoundException - { - memberInfo = (MemberInfo)DataSerializer.readObject(in); - dataObject = DataSerializer.readObject(in); - userData = DataSerializer.readObject(in); - } - - public void toData(DataOutput out) throws IOException - { - DataSerializer.writeObject(memberInfo, out); - DataSerializer.writeObject(dataObject, out); - DataSerializer.writeObject(userData, out); - } -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/49d99d4e/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/function/GfshFunction.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/function/GfshFunction.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/function/GfshFunction.java deleted file mode 100644 index 65c7964..0000000 --- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/function/GfshFunction.java +++ /dev/null @@ -1,149 +0,0 @@ -package com.gemstone.gemfire.internal.tools.gfsh.app.function; - -import java.io.DataInput; -import java.io.DataOutput; -import java.io.IOException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; - -import com.gemstone.gemfire.DataSerializable; -import com.gemstone.gemfire.DataSerializer; -import com.gemstone.gemfire.cache.execute.FunctionContext; -import com.gemstone.gemfire.internal.tools.gfsh.aggregator.AggregateFunction; -import com.gemstone.gemfire.internal.tools.gfsh.aggregator.AggregateResults; -import com.gemstone.gemfire.internal.tools.gfsh.app.ServerExecutable; -import com.gemstone.gemfire.internal.tools.gfsh.app.command.task.data.MemberInfo; - -public class GfshFunction implements AggregateFunction, DataSerializable -{ - private static final long serialVersionUID = 1L; - - private String command; - private String regionPath; - private Object arg; - - public GfshFunction() - { - } - - public GfshFunction(String command, String regionPath, Object arg) - { - this.command = command; - this.regionPath = regionPath; - this.arg = arg; - } - - public String getCommand() - { - return command; - } - - public void setCommand(String command) - { - this.command = command; - } - - public Object getArg() - { - return arg; - } - - public void setArg(Object arg) - { - this.arg = arg; - } - - public String getRegionPath() - { - return regionPath; - } - - public void setRegionPath(String regionPath) - { - this.regionPath = regionPath; - } - - public AggregateResults run(FunctionContext context) - { - AggregateResults results = new AggregateResults(); - try { - String split[] = command.split(" "); - String className = split[0].trim(); - Class clas = Class.forName("com.gemstone.gemfire.internal.tools.gfsh.app.function.command." + className); - ServerExecutable se = (ServerExecutable)clas.newInstance(); - Object obj = se.execute(command, regionPath, arg); - results.setDataObject(obj); - results.setCode(se.getCode()); - results.setCodeMessage(se.getCodeMessage()); - } catch (Exception ex) { - results.setCode(AggregateResults.CODE_ERROR); - results.setCodeMessage(getCauseMessage(ex)); - results.setException(ex); - } - return results; - } - - private String getCauseMessage(Throwable ex) - { - Throwable cause = ex.getCause(); - String causeMessage = null; - if (cause != null) { - causeMessage = getCauseMessage(cause); - } else { - causeMessage = ex.getClass().getSimpleName(); - causeMessage += " -- " + ex.getMessage(); - } - return causeMessage; - } - - /** - * Returns a java.util.List of LocalRegionInfo objects; - */ - public synchronized Object aggregate(List list) - { - // 5.7: each bucket returns results. Discard all but one that is success - MemberInfo info; - HashMap map = new HashMap(); - for (int i = 0; i < list.size(); i++) { - AggregateResults results = (AggregateResults)list.get(i); - GfshData data = (GfshData)results.getDataObject(); - if (data == null) { - data = new GfshData(null); - } - info = data.getMemberInfo(); - AggregateResults mapResults = (AggregateResults)map.get(info.getMemberId()); - if (mapResults == null) { - map.put(info.getMemberId(), results); - } else if (mapResults.getCode() != AggregateResults.CODE_NORMAL) { - map.put(info.getMemberId(), results); - } - } - - return new ArrayList(map.values()); - } - - public synchronized Object aggregateDistributedSystems(Object[] results) - { - ArrayList list = new ArrayList(); - for (int i = 0; i < results.length; i++) { - list.add(results[i]); - } - return list; - } - - public void fromData(DataInput input) throws IOException, ClassNotFoundException - { - command = DataSerializer.readString(input); - regionPath = DataSerializer.readString(input); - arg = DataSerializer.readObject(input); - } - - public void toData(DataOutput output) throws IOException - { - DataSerializer.writeString(command, output); - DataSerializer.writeString(regionPath, output); - DataSerializer.writeObject(arg, output); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/49d99d4e/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/function/command/clear.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/function/command/clear.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/function/command/clear.java deleted file mode 100644 index 24a5c36..0000000 --- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/function/command/clear.java +++ /dev/null @@ -1,95 +0,0 @@ -package com.gemstone.gemfire.internal.tools.gfsh.app.function.command; - -import java.util.Iterator; -import java.util.Set; - -import com.gemstone.gemfire.cache.Cache; -import com.gemstone.gemfire.cache.CacheFactory; -import com.gemstone.gemfire.cache.Region; -import com.gemstone.gemfire.cache.partition.PartitionRegionHelper; -import com.gemstone.gemfire.internal.cache.BucketRegion; -import com.gemstone.gemfire.internal.cache.LocalDataSet; -import com.gemstone.gemfire.internal.cache.PartitionedRegion; -import com.gemstone.gemfire.internal.cache.ProxyBucketRegion; -import com.gemstone.gemfire.internal.cache.partitioned.Bucket; -import com.gemstone.gemfire.internal.tools.gfsh.aggregator.AggregateResults; -import com.gemstone.gemfire.internal.tools.gfsh.app.ServerExecutable; -import com.gemstone.gemfire.internal.tools.gfsh.app.cache.data.MapMessage; -import com.gemstone.gemfire.internal.tools.gfsh.app.function.GfshData; - -public class clear implements ServerExecutable -{ - private byte code = AggregateResults.CODE_NORMAL; - private String codeMessage = null; - - public Object execute(String command, String regionPath, Object arg) throws Exception - { - Cache cache = CacheFactory.getAnyInstance(); - Region region = cache.getRegion(regionPath); - - if (region == null) { - code = AggregateResults.CODE_ERROR; - codeMessage = "Undefined region: " + regionPath; - return null; - } - - MapMessage message = new MapMessage(); - - if (region instanceof PartitionedRegion) { - PartitionedRegion pr = (PartitionedRegion)region; - if (pr.getDataStore() == null) { - code = AggregateResults.CODE_NORMAL; - codeMessage = "No data store: " + regionPath; - message.put("IsPeerClient", true); - return new GfshData(message); - } - } - - message.put("IsPeerClient", false); - try { - synchronized (region) { - if (region instanceof PartitionedRegion) { - // PR clear is not supported. Must clear the local data set - // individually. - clearPartitionedRegion((PartitionedRegion)region); - } else { - region.clear(); - } - codeMessage = "Cleared"; - } - } catch (Exception ex) { - code = AggregateResults.CODE_ERROR; - codeMessage = ex.getMessage(); - } - return new GfshData(message); - } - - public byte getCode() - { - return code; - } - - public String getCodeMessage() - { - return codeMessage; - } - - private void clearPartitionedRegion(PartitionedRegion partitionedRegion) - { - LocalDataSet lds = (LocalDataSet)PartitionRegionHelper.getLocalPrimaryData(partitionedRegion); - Set<Integer>set = lds.getBucketSet(); // this returns bucket ids in the function context - for (Integer bucketId : set) { - Bucket bucket = partitionedRegion.getRegionAdvisor().getBucket(bucketId); - if (bucket instanceof ProxyBucketRegion == false) { - if (bucket instanceof BucketRegion) { - BucketRegion bucketRegion = (BucketRegion) bucket; - Set keySet = bucketRegion.keySet(); - for (Iterator iterator = keySet.iterator(); iterator.hasNext();) { - Object key = iterator.next(); - bucketRegion.remove(key); - } - } - } - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/49d99d4e/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/function/command/deploy.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/function/command/deploy.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/function/command/deploy.java deleted file mode 100644 index 1935815..0000000 --- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/function/command/deploy.java +++ /dev/null @@ -1,111 +0,0 @@ -package com.gemstone.gemfire.internal.tools.gfsh.app.function.command; - -import java.io.File; -import java.io.FileOutputStream; -import java.lang.reflect.Method; -import java.text.SimpleDateFormat; -import java.util.Date; - -import com.gemstone.gemfire.cache.Cache; -import com.gemstone.gemfire.cache.CacheFactory; -import com.gemstone.gemfire.internal.tools.gfsh.aggregator.AggregateResults; -import com.gemstone.gemfire.internal.tools.gfsh.app.ServerExecutable; -import com.gemstone.gemfire.internal.tools.gfsh.app.function.GfshData; -import com.gemstone.gemfire.internal.tools.gfsh.app.misc.util.ClassFinder; -import com.gemstone.gemfire.internal.tools.gfsh.app.misc.util.SystemClassPathManager; -import com.gemstone.gemfire.internal.tools.gfsh.app.pogo.KeyType; -import com.gemstone.gemfire.internal.tools.gfsh.app.pogo.KeyTypeManager; - -public class deploy implements ServerExecutable -{ - private final static String ENV_GEMFIRE_HOME = "GEMFIRE"; - - private byte code = AggregateResults.CODE_NORMAL; - private String codeMessage = null; - private final static SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyyMMddHHmm"); - - public Object execute(String command, String regionPath, Object arg) throws Exception - { - GfshData data = new GfshData(null); - - Cache cache = CacheFactory.getAnyInstance(); - - Object[] args = (Object[])arg; - - String operationType = (String)args[0]; - if (operationType.equals("-jar")) { - String jarNames[] = (String[])args[1]; - byte byteBuffers[][] = (byte[][])args[2]; - try { - String home = System.getenv(ENV_GEMFIRE_HOME); - String classDir = home + "/gfsh/plugins"; - File classDirFile = new File(classDir); - classDirFile.mkdirs(); - - // Store the jar files - String datedFilePaths[] = new String[jarNames.length]; - for (int i = 0; i < byteBuffers.length; i++) { - String filePath = classDir + "/" + getDatedJarName(jarNames[i]); - datedFilePaths[i] = filePath; - File file = new File(filePath); - FileOutputStream fos = new FileOutputStream(file); - fos.write(byteBuffers[i]); - fos.close(); - } - - // Add the jars to the class path - for (int i = 0; i < datedFilePaths.length; i++) { - File file = new File(datedFilePaths[i]); - SystemClassPathManager.addFile(file); - } - - // Register KeyTypes - for (int i = 0; i < datedFilePaths.length; i++) { - Class[] classes = ClassFinder.getAllClasses(datedFilePaths[i]); - for (int j = 0; j < classes.length; j++) { - Class<?> cls = classes[j]; - if (KeyType.class.isAssignableFrom(cls) && - cls.getSimpleName().matches(".*_v\\d++$")) - { - Method method = cls.getMethod("getKeyType", (Class[])null); - KeyType fieldType = (KeyType)method.invoke(cls, (Object[])null); - KeyTypeManager.registerSingleKeyType(fieldType); - } - } - } - - codeMessage = "deployed to " + classDirFile.getAbsolutePath(); - } catch (Exception ex) { - while (ex.getCause() != null) { - ex = (Exception)ex.getCause(); - } - codeMessage = ex.getMessage(); - if (codeMessage != null) - codeMessage = codeMessage.trim(); - if (codeMessage == null || codeMessage.length() == 0) { - codeMessage = ex.getClass().getSimpleName(); - } - } - - data.setDataObject(codeMessage); - } - - return data; - } - - private static String getDatedJarName(String jarName) - { - String nameNoExtension = jarName.substring(0, jarName.lastIndexOf(".jar")); - return nameNoExtension + ".v" + dateFormatter.format(new Date()) + ".jar"; - } - - public byte getCode() - { - return code; - } - - public String getCodeMessage() - { - return codeMessage; - } -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/49d99d4e/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/function/command/gc.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/function/command/gc.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/function/command/gc.java deleted file mode 100644 index e59568b..0000000 --- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/function/command/gc.java +++ /dev/null @@ -1,49 +0,0 @@ -package com.gemstone.gemfire.internal.tools.gfsh.app.function.command; - -import com.gemstone.gemfire.cache.Cache; -import com.gemstone.gemfire.cache.CacheFactory; -import com.gemstone.gemfire.internal.tools.gfsh.aggregator.AggregateResults; -import com.gemstone.gemfire.internal.tools.gfsh.app.ServerExecutable; -import com.gemstone.gemfire.internal.tools.gfsh.app.function.GfshData; - -import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; - -public class gc implements ServerExecutable -{ - private byte code = AggregateResults.CODE_NORMAL; - private String codeMessage = null; - - - @SuppressFBWarnings(value="DM_GC",justification="This is the desired functionality") - public Object execute(String command, String regionPath, Object arg) throws Exception - { - String memberId = (String)arg; - - if (memberId != null) { - Cache cache = CacheFactory.getAnyInstance(); - String thisMemberId = cache.getDistributedSystem().getDistributedMember().getId(); - if (memberId.equals(thisMemberId) == false) { - return new GfshData(null); - } - } - - try { - Runtime.getRuntime().gc(); //FindBugs - extremely dubious except in benchmarking code - } catch (Exception ex) { - code = AggregateResults.CODE_ERROR; - codeMessage = ex.getMessage(); - } - - return new GfshData(null); - } - - public byte getCode() - { - return code; - } - - public String getCodeMessage() - { - return codeMessage; - } -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/49d99d4e/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/function/command/index.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/function/command/index.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/function/command/index.java deleted file mode 100644 index 5614df0..0000000 --- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/function/command/index.java +++ /dev/null @@ -1,199 +0,0 @@ -package com.gemstone.gemfire.internal.tools.gfsh.app.function.command; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -import com.gemstone.gemfire.cache.Cache; -import com.gemstone.gemfire.cache.CacheFactory; -import com.gemstone.gemfire.cache.Region; -import com.gemstone.gemfire.cache.query.Index; -import com.gemstone.gemfire.cache.query.IndexStatistics; -import com.gemstone.gemfire.cache.query.IndexType; -import com.gemstone.gemfire.cache.query.QueryService; -import com.gemstone.gemfire.internal.tools.gfsh.aggregator.AggregateResults; -import com.gemstone.gemfire.internal.tools.gfsh.app.ServerExecutable; -import com.gemstone.gemfire.internal.tools.gfsh.app.cache.data.MapMessage; -import com.gemstone.gemfire.internal.tools.gfsh.app.cache.data.Mappable; -import com.gemstone.gemfire.internal.tools.gfsh.app.function.GfshData; - -public class index implements ServerExecutable -{ - public static enum DeleteType { - DELETE_INDEX, - DELETE_REGION_INDEXES, - DELETE_ALL_INDEXES - } - - private byte code = AggregateResults.CODE_NORMAL; - private String codeMessage = null; - - public Object execute(String command, String regionPath, Object arg) throws Exception - { - GfshData data = new GfshData(null); - - Cache cache = CacheFactory.getAnyInstance(); - - Region region = null; - if (regionPath != null) { - region = cache.getRegion(regionPath); - } - - String thisMemberId = cache.getDistributedSystem().getDistributedMember().getId(); - QueryService qs = cache.getQueryService(); - - Object[] args = (Object[])arg; - String memberId = null; - String indexName = null; - IndexType indexType; - boolean isFunctional; - String indexExpression; - String fromClause; - String imports; - - String operationType = (String)args[0]; - if (operationType.equals("-create")) { - - memberId = (String)args[1]; - if (memberId != null && memberId.equals(thisMemberId) == false) { - return data; - } - - indexName = (String)args[2]; - isFunctional = (Boolean)args[3]; - if (isFunctional) { - indexType = IndexType.FUNCTIONAL; - } else { - indexType = IndexType.PRIMARY_KEY; - } - indexExpression = (String)args[4]; - fromClause = (String)args[5]; - imports = (String)args[6]; - - try { - Index index = qs.createIndex(indexName, indexType, indexExpression, fromClause, imports); - codeMessage = "index created: " + indexName; - } catch (Exception ex) { - while (ex.getCause() != null) { - ex = (Exception)ex.getCause(); - } - codeMessage = ex.getMessage(); - if (codeMessage != null) - codeMessage = codeMessage.trim(); - if (codeMessage == null || codeMessage.length() == 0) { - codeMessage = ex.getClass().getSimpleName(); - } - } - - data.setDataObject(codeMessage); - - } else if (operationType.equals("-delete")) { - - DeleteType deleteType = (DeleteType)args[1]; - - memberId = (String)args[2]; - if (memberId != null && memberId.equals(thisMemberId) == false) { - return data; - } - indexName = (String)args[3]; - - switch (deleteType) { - case DELETE_ALL_INDEXES: - qs.removeIndexes(); - codeMessage = "all indexes deleted from the member"; - break; - - case DELETE_REGION_INDEXES: - try { - qs.removeIndexes(region); - codeMessage = "all indexes deleted from " + region.getFullPath(); - } catch (Exception ex) { - codeMessage = ex.getMessage(); - } - break; - - case DELETE_INDEX: - Index index = qs.getIndex(region, indexName); - if (index == null) { - codeMessage = "index does not exist"; - } else { - try { - qs.removeIndex(index); - codeMessage = "index deleted from " + region.getFullPath(); - } catch (Exception ex) { - codeMessage = ex.getMessage(); - if (codeMessage != null) - codeMessage = codeMessage.trim(); - if (codeMessage == null || codeMessage.length() == 0) { - codeMessage = ex.getClass().getSimpleName(); - } - } - } - break; - } - data.setDataObject(codeMessage); - - } else if (operationType.equals("-list")) { - - memberId = (String)args[1]; - if (memberId != null && memberId.equals(thisMemberId) == false) { - return data; - } - - boolean isAll = (Boolean)args[2]; - boolean isStats = (Boolean)args[3]; - - Collection<Index> col = null; - if (isAll) { - col = qs.getIndexes(); - } else if (region != null) { - col = qs.getIndexes(region); - } else { - codeMessage = "Invalid index command. Region path not specified."; - data.setDataObject(codeMessage); - return data; - } - - List<Mappable> mappableList = new ArrayList(); - for (Index index : col) { - indexName = index.getName(); - String type = index.getType().toString(); - indexExpression = index.getIndexedExpression(); - fromClause = index.getFromClause(); - - MapMessage mapMessage = new MapMessage(); - mapMessage.put("Name", indexName); - mapMessage.put("Type", type); - mapMessage.put("Expression", indexExpression); - mapMessage.put("From", fromClause); - if (isStats) { - try { - IndexStatistics stats = index.getStatistics(); - mapMessage.put("Keys", stats.getNumberOfKeys()); - mapMessage.put("Values", stats.getNumberOfValues()); - mapMessage.put("Updates", stats.getNumUpdates()); - mapMessage.put("TotalUpdateTime", stats.getTotalUpdateTime()); - mapMessage.put("TotalUses", stats.getTotalUses()); - } catch (Exception ex) { - // index not supported for pr - } - } - - mappableList.add(mapMessage); - } - data.setDataObject(mappableList); - } - - return data; - } - - public byte getCode() - { - return code; - } - - public String getCodeMessage() - { - return codeMessage; - } -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/49d99d4e/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/function/command/ls.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/function/command/ls.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/function/command/ls.java deleted file mode 100644 index ace1161..0000000 --- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/function/command/ls.java +++ /dev/null @@ -1,80 +0,0 @@ -package com.gemstone.gemfire.internal.tools.gfsh.app.function.command; - -import java.util.List; - -import com.gemstone.gemfire.cache.Cache; -import com.gemstone.gemfire.cache.CacheFactory; -import com.gemstone.gemfire.cache.Region; -import com.gemstone.gemfire.cache.server.CacheServer; -import com.gemstone.gemfire.internal.tools.gfsh.aggregator.AggregateResults; -import com.gemstone.gemfire.internal.tools.gfsh.app.ServerExecutable; -import com.gemstone.gemfire.internal.tools.gfsh.app.cache.data.ListMessage; -import com.gemstone.gemfire.internal.tools.gfsh.app.cache.data.MapMessage; -import com.gemstone.gemfire.internal.tools.gfsh.app.function.GfshData; - -public class ls implements ServerExecutable -{ - private byte code = AggregateResults.CODE_NORMAL; - private String codeMessage = null; - - public Object execute(String command, String regionPath, Object arg) throws Exception - { - Region region = CacheFactory.getAnyInstance().getRegion(regionPath); - if (region == null) { - code = AggregateResults.CODE_ERROR; - codeMessage = "Undefined region: " + regionPath; - return null; - } - - Cache cache = region.getCache(); - ListMessage topMessage = new ListMessage(); - if (command.startsWith("ls -c")) { - List<CacheServer> cacheServerList = cache.getCacheServers(); - if (cacheServerList.size() > 0) { - for (CacheServer cacheServer : cacheServerList) { - MapMessage cacheServerMessage = new MapMessage(); - String groups[] = cacheServer.getGroups(); - if (groups.length > 0) { - String groupsStr = ""; - for (int i = 0; i < groups.length; i++) { - groupsStr += groups[i]; - if (i < groups.length - 1) { - groupsStr += ", "; - } - } - cacheServerMessage.put("ServerGroups", groupsStr); - } else { - cacheServerMessage.put("ServerGroups", ""); - } - - cacheServerMessage.put("BindAddress", cacheServer.getBindAddress()); - cacheServerMessage.put("HostnameForClients", cacheServer.getHostnameForClients()); - cacheServerMessage.put("LoadPollInterval", cacheServer.getLoadPollInterval()); - cacheServerMessage.put("MaxConnections", cacheServer.getMaxConnections()); - cacheServerMessage.put("MaximumMessageCount", cacheServer.getMaximumMessageCount()); - cacheServerMessage.put("MaximumTimeBetweenPings", cacheServer.getMaximumTimeBetweenPings()); - cacheServerMessage.put("MaxThreads", cacheServer.getMaxThreads()); - cacheServerMessage.put("MessageTimeToLive", cacheServer.getMessageTimeToLive()); - cacheServerMessage.put("NotifyBySubscription", cacheServer.getNotifyBySubscription()); - cacheServerMessage.put("Port", cacheServer.getPort()); - cacheServerMessage.put("SocketBufferSize", cacheServer.getSocketBufferSize()); - cacheServerMessage.put("TcpNoDelay", cacheServer.getTcpNoDelay()); - - topMessage.add(cacheServerMessage); - } - } - } - - return new GfshData(topMessage); - } - - public byte getCode() - { - return code; - } - - public String getCodeMessage() - { - return codeMessage; - } -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/49d99d4e/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/function/command/pr.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/function/command/pr.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/function/command/pr.java deleted file mode 100644 index 4c991eb..0000000 --- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/function/command/pr.java +++ /dev/null @@ -1,118 +0,0 @@ -package com.gemstone.gemfire.internal.tools.gfsh.app.function.command; - -import java.util.ArrayList; -import java.util.List; -import java.util.Set; -import java.util.TreeMap; - -import com.gemstone.gemfire.cache.Cache; -import com.gemstone.gemfire.cache.CacheFactory; -import com.gemstone.gemfire.cache.Region; -import com.gemstone.gemfire.distributed.DistributedMember; -import com.gemstone.gemfire.distributed.internal.membership.InternalDistributedMember; -import com.gemstone.gemfire.internal.cache.BucketRegion; -import com.gemstone.gemfire.internal.cache.PartitionedRegion; -import com.gemstone.gemfire.internal.tools.gfsh.aggregator.AggregateResults; -import com.gemstone.gemfire.internal.tools.gfsh.app.ServerExecutable; -import com.gemstone.gemfire.internal.tools.gfsh.app.cache.data.MapMessage; -import com.gemstone.gemfire.internal.tools.gfsh.app.cache.data.Mappable; -import com.gemstone.gemfire.internal.tools.gfsh.app.function.GfshData; - -public class pr implements ServerExecutable -{ - private byte code = AggregateResults.CODE_NORMAL; - private String codeMessage = null; - - public Object execute(String command, String regionPath, Object arg) throws Exception - { - Cache cache = CacheFactory.getAnyInstance(); - - Object args[] = (Object[])arg; - - GfshData data = new GfshData(null); - try { - // Find the value from the partitioned region - if (regionPath == null || regionPath.equals("/")) { - code = AggregateResults.CODE_ERROR; - codeMessage = "Invalid region path " + regionPath; - return data; - } - Region region = cache.getRegion(regionPath); - if (region == null) { - code = AggregateResults.CODE_ERROR; - codeMessage = "Undefined region " + regionPath; - return data; - } - if (region instanceof PartitionedRegion == false) { - code = AggregateResults.CODE_ERROR; - codeMessage = "Not a partitioned region: " + regionPath; - return data; - } - - DistributedMember member = cache.getDistributedSystem().getDistributedMember(); - -// PartitionRegionInfoImpl info = (PartitionRegionInfoImpl)PartitionRegionHelper.getPartitionRegionInfo(region); -// info.getLowRedundancyBucketCount(); - PartitionedRegion pr = (PartitionedRegion)region; - if (pr.getDataStore() == null) { - // PROXY - no data store - code = AggregateResults.CODE_NORMAL; - codeMessage = "No data store: " + regionPath; - data.setUserData(pr.getPartitionAttributes().getTotalNumBuckets()); - return data; - } - Set<BucketRegion> set2 = pr.getDataStore().getAllLocalBucketRegions(); -// FindBugs - Unused -// TreeMap primaryMap = new TreeMap(); -// TreeMap redundantMap = new TreeMap(); -// for (BucketRegion br : set2) { -// TreeMap map = new TreeMap(); -// map.put("Size", br.size()); -// map.put("Bytes", br.getTotalBytes()); -// InternalDistributedMember m = pr.getBucketPrimary(br.getId()); -// if (m.getId().equals(member.getId())) { -// primaryMap.put(br.getId(), map); -// } else { -// redundantMap.put(br.getId(), map); -// } -// } - List<Mappable> primaryList = new ArrayList<Mappable>(); - List<Mappable> redundantList = new ArrayList<Mappable>(); - for (BucketRegion br : set2) { - MapMessage map = new MapMessage(); - map.put("BucketId", br.getId()); - map.put("Size", br.size()); - map.put("Bytes", br.getTotalBytes()); - InternalDistributedMember m = pr.getBucketPrimary(br.getId()); - if (m.getId().equals(member.getId())) { - primaryList.add(map); - } else { - redundantList.add(map); - } - } - - TreeMap map = new TreeMap(); -// map.put("Primary", primaryMap); -// map.put("Redundant", redundantMap); - map.put("Primary", primaryList); - map.put("Redundant", redundantList); - data.setDataObject(map); - data.setUserData(pr.getPartitionAttributes().getTotalNumBuckets()); - - } catch (Exception ex) { - code = AggregateResults.CODE_ERROR; - codeMessage = ex.getMessage(); - } - return data; - } - - public byte getCode() - { - return code; - } - - public String getCodeMessage() - { - return codeMessage; - } -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/49d99d4e/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/function/command/rebalance.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/function/command/rebalance.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/function/command/rebalance.java deleted file mode 100644 index 29cee32..0000000 --- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/function/command/rebalance.java +++ /dev/null @@ -1,129 +0,0 @@ -package com.gemstone.gemfire.internal.tools.gfsh.app.function.command; - -import java.util.Map; -import java.util.Set; -import java.util.TreeMap; -import java.util.concurrent.CancellationException; -import java.util.concurrent.TimeUnit; - -import com.gemstone.gemfire.cache.Cache; -import com.gemstone.gemfire.cache.CacheFactory; -import com.gemstone.gemfire.cache.control.RebalanceOperation; -import com.gemstone.gemfire.cache.control.RebalanceResults; -import com.gemstone.gemfire.cache.control.ResourceManager; -import com.gemstone.gemfire.cache.partition.PartitionRebalanceInfo; -import com.gemstone.gemfire.internal.tools.gfsh.aggregator.AggregateResults; -import com.gemstone.gemfire.internal.tools.gfsh.app.ServerExecutable; -import com.gemstone.gemfire.internal.tools.gfsh.app.function.GfshData; - -public class rebalance implements ServerExecutable -{ - private byte code = AggregateResults.CODE_NORMAL; - private String codeMessage = null; - - public Object execute(String command, String regionPath, Object arg) throws Exception - { - GfshData data = new GfshData(null); - Cache cache = CacheFactory.getAnyInstance(); - - // args[0] = memberId - // args[1] = simulate optional (default true) - // args[2] = timeout optional (default 20000 mesec) - - Object args[] = (Object[])arg; - boolean simulate = true; - String memberId = null; - if (args != null && args.length > 0) { - memberId = args[0].toString(); - } else { - return data; - } - if (args.length > 1) { - if (args[1] instanceof Boolean) { - simulate = (Boolean)args[1]; - } - } - long timeout = 60000; // 60 sec default - if (args.length > 2) { - timeout = (Long)args[2]; - } - - String thisMemberId = cache.getDistributedSystem().getDistributedMember().getId(); - if (memberId.equals(thisMemberId) == false) { - return data; - } - - try { - Map map = null; - if (simulate) { - map = simulate(); - } else { - map = rebalance(timeout); - } - data.setDataObject(map); - } catch (Exception ex) { - code = AggregateResults.CODE_ERROR; - codeMessage = ex.getMessage(); - } - return data; - } - - public byte getCode() - { - return code; - } - - public String getCodeMessage() - { - return codeMessage; - } - - private Map rebalance(long timeout) throws CancellationException, InterruptedException - { - Cache cache = CacheFactory.getAnyInstance(); - ResourceManager manager = cache.getResourceManager(); - RebalanceOperation op = manager.createRebalanceFactory().start(); - - // Timeout if it's taking too long. Rebalancing will still complete. - try { - RebalanceResults results = op.getResults(timeout, TimeUnit.MILLISECONDS); - return convertToMap(results); - } catch (Exception ex) { - return null; - } - } - - private Map simulate() throws CancellationException, InterruptedException - { - Cache cache = CacheFactory.getAnyInstance(); - ResourceManager manager = cache.getResourceManager(); - RebalanceOperation op = manager.createRebalanceFactory().simulate(); - RebalanceResults results = op.getResults(); - Set<PartitionRebalanceInfo> set = results.getPartitionRebalanceDetails(); - return convertToMap(results); - } - - private TreeMap convertToMap(RebalanceResults results) - { - TreeMap map = new TreeMap(); -// if (results.getPartitionRebalanceDetails() != null) { -// map.put("RebalanceDetails", results.getPartitionRebalanceDetails()); -// } -// Set<PartitionRebalanceInfo> set = results.getPartitionRebalanceDetails(); -// if (set != null) { -// for (PartitionRebalanceInfo info : set) { -// info. -// } -// } - map.put("TotalBucketCreateBytes", results.getTotalBucketCreateBytes()); - map.put("TotalBucketCreatesCompleted", results.getTotalBucketCreatesCompleted()); - map.put("TotalBucketCreateTime", results.getTotalBucketCreateTime()); - map.put("TotalBucketTransferBytes", results.getTotalBucketTransferBytes()); - map.put("TotalBucketTransfersCompleted", results.getTotalBucketTransfersCompleted()); - map.put("TotalBucketTransferTime", results.getTotalBucketTransferTime()); - map.put("TotalPrimaryTransfersCompleted", results.getTotalPrimaryTransfersCompleted()); - map.put("TotalPrimaryTransferTime", results.getTotalPrimaryTransferTime()); - map.put("TotalTime", results.getTotalTime()); - return map; - } -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/49d99d4e/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/function/command/rm.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/function/command/rm.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/function/command/rm.java deleted file mode 100644 index 0ca99aa..0000000 --- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/function/command/rm.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.gemstone.gemfire.internal.tools.gfsh.app.function.command; - -import com.gemstone.gemfire.cache.CacheFactory; -import com.gemstone.gemfire.cache.Region; -import com.gemstone.gemfire.internal.tools.gfsh.aggregator.AggregateResults; -import com.gemstone.gemfire.internal.tools.gfsh.app.ServerExecutable; -import com.gemstone.gemfire.internal.tools.gfsh.app.function.GfshData; - -public class rm implements ServerExecutable -{ - private byte code = AggregateResults.CODE_NORMAL; - private String codeMessage = null; - - public Object execute(String command, String regionPath, Object arg) throws Exception - { - Region region = CacheFactory.getAnyInstance().getRegion(regionPath); - if (region == null) { - code = AggregateResults.CODE_ERROR; - codeMessage = "Undefined region: " + regionPath; - return null; - } - Object[] keys = (Object[])arg; - - for (int i = 0; i < keys.length; i++) { - try { - region.remove(keys[i]); - } catch (Exception ex) { - // ignore - } - } - return new GfshData(null); - } - - public byte getCode() - { - return code; - } - - public String getCodeMessage() - { - return codeMessage; - } -}
