http://git-wip-us.apache.org/repos/asf/geode/blob/645a32d0/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/GCCommand.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/GCCommand.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/GCCommand.java deleted file mode 100644 index 4884d6d..0000000 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/GCCommand.java +++ /dev/null @@ -1,131 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more contributor license - * agreements. See the NOTICE file distributed with this work for additional information regarding - * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. You may obtain a - * copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. - */ - -package org.apache.geode.management.internal.cli.commands; - -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import org.springframework.shell.core.annotation.CliCommand; -import org.springframework.shell.core.annotation.CliOption; - -import org.apache.geode.cache.execute.Function; -import org.apache.geode.distributed.DistributedMember; -import org.apache.geode.internal.cache.InternalCache; -import org.apache.geode.management.cli.CliMetaData; -import org.apache.geode.management.cli.ConverterHint; -import org.apache.geode.management.cli.Result; -import org.apache.geode.management.internal.cli.CliUtil; -import org.apache.geode.management.internal.cli.LogWrapper; -import org.apache.geode.management.internal.cli.functions.GarbageCollectionFunction; -import org.apache.geode.management.internal.cli.i18n.CliStrings; -import org.apache.geode.management.internal.cli.result.CompositeResultData; -import org.apache.geode.management.internal.cli.result.ResultBuilder; -import org.apache.geode.management.internal.cli.result.TabularResultData; -import org.apache.geode.management.internal.security.ResourceOperation; -import org.apache.geode.security.ResourcePermission; - -public class GCCommand implements GfshCommand { - @CliCommand(value = CliStrings.GC, help = CliStrings.GC__HELP) - @CliMetaData(relatedTopic = {CliStrings.TOPIC_GEODE_DEBUG_UTIL}) - @ResourceOperation(resource = ResourcePermission.Resource.CLUSTER, - operation = ResourcePermission.Operation.MANAGE) - public Result gc( - @CliOption(key = {CliStrings.GROUP, CliStrings.GROUPS}, - help = CliStrings.GC__GROUP__HELP) String[] groups, - @CliOption(key = CliStrings.MEMBER, optionContext = ConverterHint.ALL_MEMBER_IDNAME, - help = CliStrings.GC__MEMBER__HELP) String memberId) { - InternalCache cache = getCache(); - Result result; - CompositeResultData gcResultTable = ResultBuilder.createCompositeResultData(); - TabularResultData resultTable = gcResultTable.addSection().addTable("Table1"); - String headerText = "GC Summary"; - resultTable.setHeader(headerText); - Set<DistributedMember> dsMembers = new HashSet<>(); - if (memberId != null && memberId.length() > 0) { - DistributedMember member = CliUtil.getDistributedMemberByNameOrId(memberId); - if (member == null) { - return ResultBuilder - .createGemFireErrorResult(memberId + CliStrings.GC__MSG__MEMBER_NOT_FOUND); - } - dsMembers.add(member); - result = executeAndBuildResult(resultTable, dsMembers); - } else if (groups != null && groups.length > 0) { - for (String group : groups) { - dsMembers.addAll(cache.getDistributedSystem().getGroupMembers(group)); - } - result = executeAndBuildResult(resultTable, dsMembers); - - } else { - // gc on entire cluster - // exclude locators - dsMembers = CliUtil.getAllNormalMembers(cache); - result = executeAndBuildResult(resultTable, dsMembers); - - } - return result; - } - - private Result executeAndBuildResult(TabularResultData resultTable, - Set<DistributedMember> dsMembers) { - try { - List<?> resultList; - Function garbageCollectionFunction = new GarbageCollectionFunction(); - resultList = - (List<?>) CliUtil.executeFunction(garbageCollectionFunction, null, dsMembers).getResult(); - - for (Object object : resultList) { - if (object instanceof Exception) { - LogWrapper.getInstance().fine("Exception in GC " + ((Throwable) object).getMessage(), - ((Throwable) object)); - continue; - } else if (object instanceof Throwable) { - LogWrapper.getInstance().fine("Exception in GC " + ((Throwable) object).getMessage(), - ((Throwable) object)); - continue; - } - - if (object != null) { - if (object instanceof String) { - // unexpected exception string - cache may be closed or something - return ResultBuilder.createUserErrorResult((String) object); - } else { - Map<String, String> resultMap = (Map<String, String>) object; - toTabularResultData(resultTable, resultMap.get("MemberId"), - resultMap.get("HeapSizeBeforeGC"), resultMap.get("HeapSizeAfterGC"), - resultMap.get("TimeSpentInGC")); - } - } else { - LogWrapper.getInstance().fine("ResultMap was null "); - } - } - } catch (Exception e) { - String stack = CliUtil.stackTraceAsString(e); - LogWrapper.getInstance().info("GC exception is " + stack); - return ResultBuilder.createGemFireErrorResult(e.getMessage() + ": " + stack); - } - return ResultBuilder.buildResult(resultTable); - } - - private void toTabularResultData(TabularResultData table, String memberId, String heapSizeBefore, - String heapSizeAfter, String timeTaken) { - table.accumulate(CliStrings.GC__MSG__MEMBER_NAME, memberId); - table.accumulate(CliStrings.GC__MSG__HEAP_SIZE_BEFORE_GC, heapSizeBefore); - table.accumulate(CliStrings.GC__MSG__HEAP_SIZE_AFTER_GC, heapSizeAfter); - table.accumulate(CliStrings.GC__MSG__TOTAL_TIME_IN_GC, timeTaken); - } -}
http://git-wip-us.apache.org/repos/asf/geode/blob/645a32d0/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/GfshHelpCommand.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/GfshHelpCommand.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/GfshHelpCommand.java deleted file mode 100644 index 4cb6194..0000000 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/GfshHelpCommand.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more contributor license - * agreements. See the NOTICE file distributed with this work for additional information regarding - * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. You may obtain a - * copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. - */ - -package org.apache.geode.management.internal.cli.commands; - -import org.springframework.shell.core.annotation.CliCommand; -import org.springframework.shell.core.annotation.CliOption; - -import org.apache.geode.management.cli.CliMetaData; -import org.apache.geode.management.cli.ConverterHint; -import org.apache.geode.management.cli.Result; -import org.apache.geode.management.internal.cli.CommandManager; -import org.apache.geode.management.internal.cli.CommandManagerAware; -import org.apache.geode.management.internal.cli.i18n.CliStrings; -import org.apache.geode.management.internal.cli.result.ResultBuilder; - -public class GfshHelpCommand implements GfshCommand, CommandManagerAware { - private CommandManager commandManager = null; - - public void setCommandManager(CommandManager commandManager) { - this.commandManager = commandManager; - } - - @CliCommand(value = CliStrings.HELP, help = CliStrings.HELP__HELP) - @CliMetaData(shellOnly = true, relatedTopic = {CliStrings.TOPIC_GEODE_HELP}) - public Result obtainHelp( - @CliOption(key = {"", CliStrings.SH__COMMAND}, optionContext = ConverterHint.HELP, - help = "Command name to provide help for") String buffer) { - return ResultBuilder.createInfoResult(commandManager.obtainHelp(buffer)); - } - - @CliCommand(value = CliStrings.HINT, help = CliStrings.HINT__HELP) - @CliMetaData(shellOnly = true, relatedTopic = {CliStrings.TOPIC_GEODE_HELP}) - public Result hint( - @CliOption(key = {"", CliStrings.HINT__TOPICNAME}, optionContext = ConverterHint.HINT, - help = CliStrings.HINT__TOPICNAME__HELP) String topicName) { - return ResultBuilder.createInfoResult(commandManager.obtainHint(topicName)); - } -} http://git-wip-us.apache.org/repos/asf/geode/blob/645a32d0/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/GfshHelpCommands.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/GfshHelpCommands.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/GfshHelpCommands.java new file mode 100644 index 0000000..5fd7988 --- /dev/null +++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/GfshHelpCommands.java @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license + * agreements. See the NOTICE file distributed with this work for additional information regarding + * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. You may obtain a + * copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ +package org.apache.geode.management.internal.cli.commands; + +import org.apache.geode.management.cli.CliMetaData; +import org.apache.geode.management.cli.ConverterHint; +import org.apache.geode.management.cli.Result; +import org.apache.geode.management.internal.cli.CommandManager; +import org.apache.geode.management.internal.cli.CommandManagerAware; +import org.apache.geode.management.internal.cli.i18n.CliStrings; +import org.apache.geode.management.internal.cli.result.ResultBuilder; +import org.springframework.shell.core.CommandMarker; +import org.springframework.shell.core.annotation.CliCommand; +import org.springframework.shell.core.annotation.CliOption; + +/** + * @since GemFire 7.0 + */ +public class GfshHelpCommands implements GfshCommand, CommandManagerAware { + private CommandManager commandManager = null; + + public void setCommandManager(CommandManager commandManager) { + this.commandManager = commandManager; + } + + @CliCommand(value = CliStrings.HELP, help = CliStrings.HELP__HELP) + @CliMetaData(shellOnly = true, relatedTopic = {CliStrings.TOPIC_GEODE_HELP}) + public Result obtainHelp( + @CliOption(key = {"", CliStrings.SH__COMMAND}, optionContext = ConverterHint.HELP, + help = "Command name to provide help for") String buffer) { + + return ResultBuilder.createInfoResult(commandManager.obtainHelp(buffer)); + } + + @CliCommand(value = CliStrings.HINT, help = CliStrings.HINT__HELP) + @CliMetaData(shellOnly = true, relatedTopic = {CliStrings.TOPIC_GEODE_HELP}) + public Result hint(@CliOption(key = {"", CliStrings.HINT__TOPICNAME}, + optionContext = ConverterHint.HINT, help = CliStrings.HINT__TOPICNAME) String topicName) { + + return ResultBuilder.createInfoResult(commandManager.obtainHint(topicName)); + } + +} http://git-wip-us.apache.org/repos/asf/geode/blob/645a32d0/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/GfshHintCommand.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/GfshHintCommand.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/GfshHintCommand.java deleted file mode 100644 index ccc1900..0000000 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/GfshHintCommand.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more contributor license - * agreements. See the NOTICE file distributed with this work for additional information regarding - * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. You may obtain a - * copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. - */ - -package org.apache.geode.management.internal.cli.commands; - -import org.springframework.shell.core.annotation.CliCommand; -import org.springframework.shell.core.annotation.CliOption; - -import org.apache.geode.management.cli.CliMetaData; -import org.apache.geode.management.cli.ConverterHint; -import org.apache.geode.management.cli.Result; -import org.apache.geode.management.internal.cli.CommandManager; -import org.apache.geode.management.internal.cli.CommandManagerAware; -import org.apache.geode.management.internal.cli.i18n.CliStrings; -import org.apache.geode.management.internal.cli.result.ResultBuilder; - -public class GfshHintCommand implements GfshCommand, CommandManagerAware { - private CommandManager commandManager = null; - - public void setCommandManager(CommandManager commandManager) { - this.commandManager = commandManager; - } - - @CliCommand(value = CliStrings.HINT, help = CliStrings.HINT__HELP) - @CliMetaData(shellOnly = true, relatedTopic = {CliStrings.TOPIC_GEODE_HELP}) - public Result hint(@CliOption(key = {"", CliStrings.HINT__TOPICNAME}, - optionContext = ConverterHint.HINT, help = CliStrings.HINT__TOPICNAME) String topicName) { - return ResultBuilder.createInfoResult(commandManager.obtainHint(topicName)); - } -} http://git-wip-us.apache.org/repos/asf/geode/blob/645a32d0/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/IndexCommands.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/IndexCommands.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/IndexCommands.java new file mode 100644 index 0000000..4734b4c --- /dev/null +++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/IndexCommands.java @@ -0,0 +1,668 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license + * agreements. See the NOTICE file distributed with this work for additional information regarding + * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. You may obtain a + * copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ +package org.apache.geode.management.internal.cli.commands; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.TreeSet; +import java.util.concurrent.atomic.AtomicReference; + +import org.apache.commons.lang.ArrayUtils; +import org.springframework.shell.core.annotation.CliCommand; +import org.springframework.shell.core.annotation.CliOption; + +import org.apache.geode.SystemFailure; +import org.apache.geode.cache.Cache; +import org.apache.geode.cache.CacheFactory; +import org.apache.geode.cache.Region; +import org.apache.geode.cache.execute.Execution; +import org.apache.geode.cache.execute.FunctionInvocationTargetException; +import org.apache.geode.cache.execute.ResultCollector; +import org.apache.geode.distributed.DistributedMember; +import org.apache.geode.internal.cache.execute.AbstractExecution; +import org.apache.geode.internal.lang.StringUtils; +import org.apache.geode.management.cli.CliMetaData; +import org.apache.geode.management.cli.ConverterHint; +import org.apache.geode.management.cli.Result; +import org.apache.geode.management.internal.cli.CliUtil; +import org.apache.geode.management.internal.cli.domain.IndexDetails; +import org.apache.geode.management.internal.cli.domain.IndexDetails.IndexStatisticsDetails; +import org.apache.geode.management.internal.cli.domain.IndexInfo; +import org.apache.geode.management.internal.cli.functions.CliFunctionResult; +import org.apache.geode.management.internal.cli.functions.CreateDefinedIndexesFunction; +import org.apache.geode.management.internal.cli.functions.CreateIndexFunction; +import org.apache.geode.management.internal.cli.functions.DestroyIndexFunction; +import org.apache.geode.management.internal.cli.functions.ListIndexFunction; +import org.apache.geode.management.internal.cli.i18n.CliStrings; +import org.apache.geode.management.internal.cli.result.ErrorResultData; +import org.apache.geode.management.internal.cli.result.InfoResultData; +import org.apache.geode.management.internal.cli.result.ResultBuilder; +import org.apache.geode.management.internal.cli.result.TabularResultData; +import org.apache.geode.management.internal.configuration.domain.XmlEntity; +import org.apache.geode.management.internal.security.ResourceOperation; +import org.apache.geode.security.ResourcePermission.Operation; +import org.apache.geode.security.ResourcePermission.Resource; +import org.apache.geode.security.ResourcePermission.Target; + +/** + * The IndexCommands class encapsulates all GemFire shell (Gfsh) commands related to indexes defined + * in GemFire. + * + * @see GfshCommand + * @see org.apache.geode.management.internal.cli.domain.IndexDetails + * @see org.apache.geode.management.internal.cli.functions.ListIndexFunction + * @since GemFire 7.0 + */ +@SuppressWarnings("unused") +public class IndexCommands implements GfshCommand { + + private static final CreateIndexFunction createIndexFunction = new CreateIndexFunction(); + private static final DestroyIndexFunction destroyIndexFunction = new DestroyIndexFunction(); + private static final CreateDefinedIndexesFunction createDefinedIndexesFunction = + new CreateDefinedIndexesFunction(); + private static final Set<IndexInfo> indexDefinitions = + Collections.synchronizedSet(new HashSet<IndexInfo>()); + + @CliCommand(value = CliStrings.LIST_INDEX, help = CliStrings.LIST_INDEX__HELP) + @CliMetaData(relatedTopic = {CliStrings.TOPIC_GEODE_REGION, CliStrings.TOPIC_GEODE_DATA}) + @ResourceOperation(resource = Resource.CLUSTER, operation = Operation.READ, target = Target.QUERY) + public Result listIndex(@CliOption(key = CliStrings.LIST_INDEX__STATS, + specifiedDefaultValue = "true", unspecifiedDefaultValue = "false", + help = CliStrings.LIST_INDEX__STATS__HELP) final boolean showStats) { + try { + return toTabularResult(getIndexListing(), showStats); + } catch (FunctionInvocationTargetException ignore) { + return ResultBuilder.createGemFireErrorResult( + CliStrings.format(CliStrings.COULD_NOT_EXECUTE_COMMAND_TRY_AGAIN, CliStrings.LIST_INDEX)); + } catch (VirtualMachineError e) { + SystemFailure.initiateFailure(e); + throw e; + } catch (Throwable t) { + SystemFailure.checkFailure(); + getCache().getLogger().error(t); + return ResultBuilder.createGemFireErrorResult( + String.format(CliStrings.LIST_INDEX__ERROR_MESSAGE, toString(t, isDebugging()))); + } + } + + @SuppressWarnings("unchecked") + protected List<IndexDetails> getIndexListing() { + final Execution functionExecutor = getMembersFunctionExecutor(getMembers(getCache())); + + if (functionExecutor instanceof AbstractExecution) { + ((AbstractExecution) functionExecutor).setIgnoreDepartedMembers(true); + } + + final ResultCollector<?, ?> resultsCollector = + functionExecutor.execute(new ListIndexFunction()); + + final List<?> results = (List<?>) resultsCollector.getResult(); + final List<IndexDetails> indexDetailsList = new ArrayList<>(results.size()); + + for (Object result : results) { + if (result instanceof Set) { // ignore FunctionInvocationTargetExceptions and other Exceptions + indexDetailsList.addAll((Set<IndexDetails>) result); + } + } + + Collections.sort(indexDetailsList); + + return indexDetailsList; + } + + protected Result toTabularResult(final List<IndexDetails> indexDetailsList, + final boolean showStats) { + if (!indexDetailsList.isEmpty()) { + final TabularResultData indexData = ResultBuilder.createTabularResultData(); + + for (final IndexDetails indexDetails : indexDetailsList) { + indexData.accumulate("Member Name", + StringUtils.defaultString(indexDetails.getMemberName())); + indexData.accumulate("Member ID", indexDetails.getMemberId()); + indexData.accumulate("Region Path", indexDetails.getRegionPath()); + indexData.accumulate("Name", indexDetails.getIndexName()); + indexData.accumulate("Type", StringUtils.defaultString(indexDetails.getIndexType())); + indexData.accumulate("Indexed Expression", indexDetails.getIndexedExpression()); + indexData.accumulate("From Clause", indexDetails.getFromClause()); + + if (showStats) { + final IndexStatisticsDetailsAdapter adapter = + new IndexStatisticsDetailsAdapter(indexDetails.getIndexStatisticsDetails()); + + indexData.accumulate("Uses", adapter.getTotalUses()); + indexData.accumulate("Updates", adapter.getNumberOfUpdates()); + indexData.accumulate("Update Time", adapter.getTotalUpdateTime()); + indexData.accumulate("Keys", adapter.getNumberOfKeys()); + indexData.accumulate("Values", adapter.getNumberOfValues()); + } + } + + return ResultBuilder.buildResult(indexData); + } else { + return ResultBuilder.createInfoResult(CliStrings.LIST_INDEX__INDEXES_NOT_FOUND_MESSAGE); + } + } + + @CliCommand(value = CliStrings.CREATE_INDEX, help = CliStrings.CREATE_INDEX__HELP) + @CliMetaData(relatedTopic = {CliStrings.TOPIC_GEODE_REGION, CliStrings.TOPIC_GEODE_DATA}) + // TODO : Add optionContext for indexName + @ResourceOperation(resource = Resource.CLUSTER, operation = Operation.MANAGE, + target = Target.QUERY) + public Result createIndex(@CliOption(key = CliStrings.CREATE_INDEX__NAME, mandatory = true, + help = CliStrings.CREATE_INDEX__NAME__HELP) final String indexName, + + @CliOption(key = CliStrings.CREATE_INDEX__EXPRESSION, mandatory = true, + help = CliStrings.CREATE_INDEX__EXPRESSION__HELP) final String indexedExpression, + + @CliOption(key = CliStrings.CREATE_INDEX__REGION, mandatory = true, + optionContext = ConverterHint.REGION_PATH, + help = CliStrings.CREATE_INDEX__REGION__HELP) String regionPath, + + @CliOption(key = {CliStrings.MEMBER, CliStrings.MEMBERS}, + optionContext = ConverterHint.MEMBERIDNAME, + help = CliStrings.CREATE_INDEX__MEMBER__HELP) final String[] memberNameOrID, + + @CliOption(key = CliStrings.CREATE_INDEX__TYPE, unspecifiedDefaultValue = "range", + optionContext = ConverterHint.INDEX_TYPE, + help = CliStrings.CREATE_INDEX__TYPE__HELP) final String indexType, + + @CliOption(key = {CliStrings.GROUP, CliStrings.GROUPS}, + optionContext = ConverterHint.MEMBERGROUP, + help = CliStrings.CREATE_INDEX__GROUP__HELP) final String[] group) { + + Result result; + AtomicReference<XmlEntity> xmlEntity = new AtomicReference<>(); + + try { + final Cache cache = CacheFactory.getAnyInstance(); + + int idxType; + + // Index type check + if ("range".equalsIgnoreCase(indexType)) { + idxType = IndexInfo.RANGE_INDEX; + } else if ("hash".equalsIgnoreCase(indexType)) { + idxType = IndexInfo.HASH_INDEX; + } else if ("key".equalsIgnoreCase(indexType)) { + idxType = IndexInfo.KEY_INDEX; + } else { + return ResultBuilder + .createUserErrorResult(CliStrings.CREATE_INDEX__INVALID__INDEX__TYPE__MESSAGE); + } + + if (indexName == null || indexName.isEmpty()) { + return ResultBuilder.createUserErrorResult(CliStrings.CREATE_INDEX__INVALID__INDEX__NAME); + } + + if (indexedExpression == null || indexedExpression.isEmpty()) { + return ResultBuilder.createUserErrorResult(CliStrings.CREATE_INDEX__INVALID__EXPRESSION); + } + + if (StringUtils.isBlank(regionPath) || regionPath.equals(Region.SEPARATOR)) { + return ResultBuilder.createUserErrorResult(CliStrings.CREATE_INDEX__INVALID__REGIONPATH); + } + + if (!regionPath.startsWith(Region.SEPARATOR)) { + regionPath = Region.SEPARATOR + regionPath; + } + + IndexInfo indexInfo = new IndexInfo(indexName, indexedExpression, regionPath, idxType); + + final Set<DistributedMember> targetMembers = CliUtil.findMembers(group, memberNameOrID); + + if (targetMembers.isEmpty()) { + return ResultBuilder.createUserErrorResult(CliStrings.NO_MEMBERS_FOUND_MESSAGE); + } + + final ResultCollector<?, ?> rc = + CliUtil.executeFunction(createIndexFunction, indexInfo, targetMembers); + + final List<Object> funcResults = (List<Object>) rc.getResult(); + final Set<String> successfulMembers = new TreeSet<>(); + final Map<String, Set<String>> indexOpFailMap = new HashMap<>(); + + for (final Object funcResult : funcResults) { + if (funcResult instanceof CliFunctionResult) { + final CliFunctionResult cliFunctionResult = (CliFunctionResult) funcResult; + + if (cliFunctionResult.isSuccessful()) { + successfulMembers.add(cliFunctionResult.getMemberIdOrName()); + + if (xmlEntity.get() == null) { + xmlEntity.set(cliFunctionResult.getXmlEntity()); + } + } else { + final String exceptionMessage = cliFunctionResult.getMessage(); + Set<String> failedMembers = indexOpFailMap.get(exceptionMessage); + + if (failedMembers == null) { + failedMembers = new TreeSet<>(); + } + failedMembers.add(cliFunctionResult.getMemberIdOrName()); + indexOpFailMap.put(exceptionMessage, failedMembers); + } + } + } + + if (!successfulMembers.isEmpty()) { + + final InfoResultData infoResult = ResultBuilder.createInfoResultData(); + infoResult.addLine(CliStrings.CREATE_INDEX__SUCCESS__MSG); + infoResult.addLine(CliStrings.format(CliStrings.CREATE_INDEX__NAME__MSG, indexName)); + infoResult.addLine( + CliStrings.format(CliStrings.CREATE_INDEX__EXPRESSION__MSG, indexedExpression)); + infoResult.addLine(CliStrings.format(CliStrings.CREATE_INDEX__REGIONPATH__MSG, regionPath)); + infoResult.addLine(CliStrings.CREATE_INDEX__MEMBER__MSG); + + int num = 0; + + for (final String memberId : successfulMembers) { + ++num; + infoResult.addLine( + CliStrings.format(CliStrings.CREATE_INDEX__NUMBER__AND__MEMBER, num, memberId)); + } + result = ResultBuilder.buildResult(infoResult); + + } else { + // Group members by the exception thrown. + final ErrorResultData erd = ResultBuilder.createErrorResultData(); + erd.addLine(CliStrings.format(CliStrings.CREATE_INDEX__FAILURE__MSG, indexName)); + + final Set<String> exceptionMessages = indexOpFailMap.keySet(); + + for (final String exceptionMessage : exceptionMessages) { + erd.addLine(exceptionMessage); + erd.addLine(CliStrings.CREATE_INDEX__EXCEPTION__OCCURRED__ON); + final Set<String> memberIds = indexOpFailMap.get(exceptionMessage); + + int num = 0; + for (final String memberId : memberIds) { + ++num; + erd.addLine( + CliStrings.format(CliStrings.CREATE_INDEX__NUMBER__AND__MEMBER, num, memberId)); + } + } + result = ResultBuilder.buildResult(erd); + } + } catch (Exception e) { + result = ResultBuilder.createGemFireErrorResult(e.getMessage()); + } + + if (xmlEntity.get() != null) { + persistClusterConfiguration(result, + () -> getSharedConfiguration().addXmlEntity(xmlEntity.get(), group)); + } + + return result; + } + + @CliCommand(value = CliStrings.DESTROY_INDEX, help = CliStrings.DESTROY_INDEX__HELP) + @CliMetaData(relatedTopic = {CliStrings.TOPIC_GEODE_REGION, CliStrings.TOPIC_GEODE_DATA}) + @ResourceOperation(resource = Resource.CLUSTER, operation = Operation.MANAGE, + target = Target.QUERY) + public Result destroyIndex( + @CliOption(key = CliStrings.DESTROY_INDEX__NAME, unspecifiedDefaultValue = "", + help = CliStrings.DESTROY_INDEX__NAME__HELP) final String indexName, + + @CliOption(key = CliStrings.DESTROY_INDEX__REGION, optionContext = ConverterHint.REGION_PATH, + help = CliStrings.DESTROY_INDEX__REGION__HELP) final String regionPath, + + @CliOption(key = {CliStrings.MEMBER, CliStrings.MEMBERS}, + optionContext = ConverterHint.MEMBERIDNAME, + help = CliStrings.DESTROY_INDEX__MEMBER__HELP) final String[] memberNameOrID, + + @CliOption(key = {CliStrings.GROUP, CliStrings.GROUPS}, + optionContext = ConverterHint.MEMBERGROUP, + help = CliStrings.DESTROY_INDEX__GROUP__HELP) final String[] group) { + + Result result; + + if (StringUtils.isBlank(indexName) && StringUtils.isBlank(regionPath) + && ArrayUtils.isEmpty(group) && ArrayUtils.isEmpty(memberNameOrID)) { + return ResultBuilder.createUserErrorResult( + CliStrings.format(CliStrings.PROVIDE_ATLEAST_ONE_OPTION, CliStrings.DESTROY_INDEX)); + } + + final Cache cache = CacheFactory.getAnyInstance(); + String regionName = null; + if (regionPath != null) { + regionName = regionPath.startsWith("/") ? regionPath.substring(1) : regionPath; + } + IndexInfo indexInfo = new IndexInfo(indexName, regionName); + Set<DistributedMember> targetMembers = CliUtil.findMembers(group, memberNameOrID); + + if (targetMembers.isEmpty()) { + return ResultBuilder.createUserErrorResult(CliStrings.NO_MEMBERS_FOUND_MESSAGE); + } + + ResultCollector rc = CliUtil.executeFunction(destroyIndexFunction, indexInfo, targetMembers); + List<Object> funcResults = (List<Object>) rc.getResult(); + + Set<String> successfulMembers = new TreeSet<>(); + Map<String, Set<String>> indexOpFailMap = new HashMap<>(); + + AtomicReference<XmlEntity> xmlEntity = new AtomicReference<>(); + for (Object funcResult : funcResults) { + if (!(funcResult instanceof CliFunctionResult)) { + continue; + } + + CliFunctionResult cliFunctionResult = (CliFunctionResult) funcResult; + + if (cliFunctionResult.isSuccessful()) { + successfulMembers.add(cliFunctionResult.getMemberIdOrName()); + if (xmlEntity.get() == null) { + xmlEntity.set(cliFunctionResult.getXmlEntity()); + } + } else { + String exceptionMessage = cliFunctionResult.getMessage(); + Set<String> failedMembers = indexOpFailMap.get(exceptionMessage); + + if (failedMembers == null) { + failedMembers = new TreeSet<>(); + } + failedMembers.add(cliFunctionResult.getMemberIdOrName()); + indexOpFailMap.put(exceptionMessage, failedMembers); + } + } + + if (!successfulMembers.isEmpty()) { + InfoResultData infoResult = ResultBuilder.createInfoResultData(); + + if (StringUtils.isNotBlank(indexName)) { + if (StringUtils.isNotBlank(regionPath)) { + infoResult.addLine(CliStrings.format(CliStrings.DESTROY_INDEX__ON__REGION__SUCCESS__MSG, + indexName, regionPath)); + } else { + infoResult.addLine(CliStrings.format(CliStrings.DESTROY_INDEX__SUCCESS__MSG, indexName)); + } + } else { + if (StringUtils.isNotBlank(regionPath)) { + infoResult.addLine(CliStrings + .format(CliStrings.DESTROY_INDEX__ON__REGION__ONLY__SUCCESS__MSG, regionPath)); + } else { + infoResult.addLine(CliStrings.DESTROY_INDEX__ON__MEMBERS__ONLY__SUCCESS__MSG); + } + } + + int num = 0; + for (String memberId : successfulMembers) { + infoResult.addLine(CliStrings.format( + CliStrings.format(CliStrings.DESTROY_INDEX__NUMBER__AND__MEMBER, ++num, memberId))); + } + result = ResultBuilder.buildResult(infoResult); + + } else { + + ErrorResultData erd = ResultBuilder.createErrorResultData(); + if (StringUtils.isNotBlank(indexName)) { + erd.addLine(CliStrings.format(CliStrings.DESTROY_INDEX__FAILURE__MSG, indexName)); + } else { + erd.addLine("Indexes could not be destroyed for following reasons"); + } + + Set<String> exceptionMessages = indexOpFailMap.keySet(); + + for (String exceptionMessage : exceptionMessages) { + erd.addLine(CliStrings.format(CliStrings.DESTROY_INDEX__REASON_MESSAGE, exceptionMessage)); + erd.addLine(CliStrings.DESTROY_INDEX__EXCEPTION__OCCURRED__ON); + + Set<String> memberIds = indexOpFailMap.get(exceptionMessage); + int num = 0; + + for (String memberId : memberIds) { + erd.addLine(CliStrings.format( + CliStrings.format(CliStrings.DESTROY_INDEX__NUMBER__AND__MEMBER, ++num, memberId))); + } + erd.addLine(""); + } + result = ResultBuilder.buildResult(erd); + } + if (xmlEntity.get() != null) { + persistClusterConfiguration(result, + () -> getSharedConfiguration().deleteXmlEntity(xmlEntity.get(), group)); + } + + return result; + } + + @CliCommand(value = CliStrings.DEFINE_INDEX, help = CliStrings.DEFINE_INDEX__HELP) + @CliMetaData(relatedTopic = {CliStrings.TOPIC_GEODE_REGION, CliStrings.TOPIC_GEODE_DATA}) + // TODO : Add optionContext for indexName + @ResourceOperation(resource = Resource.CLUSTER, operation = Operation.MANAGE, + target = Target.QUERY) + public Result defineIndex(@CliOption(key = CliStrings.DEFINE_INDEX_NAME, mandatory = true, + help = CliStrings.DEFINE_INDEX__HELP) final String indexName, + + @CliOption(key = CliStrings.DEFINE_INDEX__EXPRESSION, mandatory = true, + help = CliStrings.DEFINE_INDEX__EXPRESSION__HELP) final String indexedExpression, + + @CliOption(key = CliStrings.DEFINE_INDEX__REGION, mandatory = true, + optionContext = ConverterHint.REGION_PATH, + help = CliStrings.DEFINE_INDEX__REGION__HELP) String regionPath, + + @CliOption(key = CliStrings.DEFINE_INDEX__TYPE, unspecifiedDefaultValue = "range", + optionContext = ConverterHint.INDEX_TYPE, + help = CliStrings.DEFINE_INDEX__TYPE__HELP) final String indexType) { + + Result result; + XmlEntity xmlEntity = null; + + int idxType; + + // Index type check + if ("range".equalsIgnoreCase(indexType)) { + idxType = IndexInfo.RANGE_INDEX; + } else if ("hash".equalsIgnoreCase(indexType)) { + idxType = IndexInfo.HASH_INDEX; + } else if ("key".equalsIgnoreCase(indexType)) { + idxType = IndexInfo.KEY_INDEX; + } else { + return ResultBuilder + .createUserErrorResult(CliStrings.DEFINE_INDEX__INVALID__INDEX__TYPE__MESSAGE); + } + + if (indexName == null || indexName.isEmpty()) { + return ResultBuilder.createUserErrorResult(CliStrings.DEFINE_INDEX__INVALID__INDEX__NAME); + } + + if (indexedExpression == null || indexedExpression.isEmpty()) { + return ResultBuilder.createUserErrorResult(CliStrings.DEFINE_INDEX__INVALID__EXPRESSION); + } + + if (StringUtils.isBlank(regionPath) || regionPath.equals(Region.SEPARATOR)) { + return ResultBuilder.createUserErrorResult(CliStrings.DEFINE_INDEX__INVALID__REGIONPATH); + } + + if (!regionPath.startsWith(Region.SEPARATOR)) { + regionPath = Region.SEPARATOR + regionPath; + } + + IndexInfo indexInfo = new IndexInfo(indexName, indexedExpression, regionPath, idxType); + indexDefinitions.add(indexInfo); + + final InfoResultData infoResult = ResultBuilder.createInfoResultData(); + infoResult.addLine(CliStrings.DEFINE_INDEX__SUCCESS__MSG); + infoResult.addLine(CliStrings.format(CliStrings.DEFINE_INDEX__NAME__MSG, indexName)); + infoResult + .addLine(CliStrings.format(CliStrings.DEFINE_INDEX__EXPRESSION__MSG, indexedExpression)); + infoResult.addLine(CliStrings.format(CliStrings.DEFINE_INDEX__REGIONPATH__MSG, regionPath)); + result = ResultBuilder.buildResult(infoResult); + + return result; + } + + @CliCommand(value = CliStrings.CREATE_DEFINED_INDEXES, help = CliStrings.CREATE_DEFINED__HELP) + @CliMetaData(relatedTopic = {CliStrings.TOPIC_GEODE_REGION, CliStrings.TOPIC_GEODE_DATA}) + @ResourceOperation(resource = Resource.CLUSTER, operation = Operation.MANAGE, + target = Target.QUERY) + // TODO : Add optionContext for indexName + public Result createDefinedIndexes( + + @CliOption(key = {CliStrings.MEMBER, CliStrings.MEMBERS}, + optionContext = ConverterHint.MEMBERIDNAME, + help = CliStrings.CREATE_DEFINED_INDEXES__MEMBER__HELP) final String[] memberNameOrID, + + @CliOption(key = {CliStrings.GROUP, CliStrings.GROUPS}, + optionContext = ConverterHint.MEMBERGROUP, + help = CliStrings.CREATE_DEFINED_INDEXES__GROUP__HELP) final String[] group) { + + Result result; + AtomicReference<XmlEntity> xmlEntity = new AtomicReference<>(); + + if (indexDefinitions.isEmpty()) { + final InfoResultData infoResult = ResultBuilder.createInfoResultData(); + infoResult.addLine(CliStrings.DEFINE_INDEX__FAILURE__MSG); + return ResultBuilder.buildResult(infoResult); + } + + try { + final Set<DistributedMember> targetMembers = CliUtil.findMembers(group, memberNameOrID); + + if (targetMembers.isEmpty()) { + return ResultBuilder.createUserErrorResult(CliStrings.NO_MEMBERS_FOUND_MESSAGE); + } + + final Cache cache = CacheFactory.getAnyInstance(); + final ResultCollector<?, ?> rc = + CliUtil.executeFunction(createDefinedIndexesFunction, indexDefinitions, targetMembers); + + final List<Object> funcResults = (List<Object>) rc.getResult(); + final Set<String> successfulMembers = new TreeSet<>(); + final Map<String, Set<String>> indexOpFailMap = new HashMap<>(); + + for (final Object funcResult : funcResults) { + if (funcResult instanceof CliFunctionResult) { + final CliFunctionResult cliFunctionResult = (CliFunctionResult) funcResult; + + if (cliFunctionResult.isSuccessful()) { + successfulMembers.add(cliFunctionResult.getMemberIdOrName()); + + if (xmlEntity.get() == null) { + xmlEntity.set(cliFunctionResult.getXmlEntity()); + } + } else { + final String exceptionMessage = cliFunctionResult.getMessage(); + Set<String> failedMembers = indexOpFailMap.get(exceptionMessage); + + if (failedMembers == null) { + failedMembers = new TreeSet<>(); + } + failedMembers.add(cliFunctionResult.getMemberIdOrName()); + indexOpFailMap.put(exceptionMessage, failedMembers); + } + } + } + + if (!successfulMembers.isEmpty()) { + final InfoResultData infoResult = ResultBuilder.createInfoResultData(); + infoResult.addLine(CliStrings.CREATE_DEFINED_INDEXES__SUCCESS__MSG); + + int num = 0; + + for (final String memberId : successfulMembers) { + ++num; + infoResult.addLine(CliStrings + .format(CliStrings.CREATE_DEFINED_INDEXES__NUMBER__AND__MEMBER, num, memberId)); + } + result = ResultBuilder.buildResult(infoResult); + + } else { + // Group members by the exception thrown. + final ErrorResultData erd = ResultBuilder.createErrorResultData(); + + final Set<String> exceptionMessages = indexOpFailMap.keySet(); + + for (final String exceptionMessage : exceptionMessages) { + erd.addLine(exceptionMessage); + erd.addLine(CliStrings.CREATE_INDEX__EXCEPTION__OCCURRED__ON); + final Set<String> memberIds = indexOpFailMap.get(exceptionMessage); + + int num = 0; + for (final String memberId : memberIds) { + ++num; + erd.addLine(CliStrings.format(CliStrings.CREATE_DEFINED_INDEXES__NUMBER__AND__MEMBER, + num, memberId)); + } + } + result = ResultBuilder.buildResult(erd); + } + } catch (Exception e) { + result = ResultBuilder.createGemFireErrorResult(e.getMessage()); + } + + if (xmlEntity.get() != null) { + persistClusterConfiguration(result, + () -> getSharedConfiguration().addXmlEntity(xmlEntity.get(), group)); + } + return result; + } + + @CliCommand(value = CliStrings.CLEAR_DEFINED_INDEXES, help = CliStrings.CLEAR_DEFINED__HELP) + @CliMetaData(relatedTopic = {CliStrings.TOPIC_GEODE_REGION, CliStrings.TOPIC_GEODE_DATA}) + @ResourceOperation(resource = Resource.CLUSTER, operation = Operation.MANAGE, + target = Target.QUERY) + // TODO : Add optionContext for indexName + public Result clearDefinedIndexes() { + indexDefinitions.clear(); + final InfoResultData infoResult = ResultBuilder.createInfoResultData(); + infoResult.addLine(CliStrings.CLEAR_DEFINED_INDEX__SUCCESS__MSG); + return ResultBuilder.buildResult(infoResult); + } + + protected static class IndexStatisticsDetailsAdapter { + + private final IndexStatisticsDetails indexStatisticsDetails; + + protected IndexStatisticsDetailsAdapter(final IndexStatisticsDetails indexStatisticsDetails) { + this.indexStatisticsDetails = indexStatisticsDetails; + } + + public IndexStatisticsDetails getIndexStatisticsDetails() { + return indexStatisticsDetails; + } + + public String getNumberOfKeys() { + return getIndexStatisticsDetails() != null + ? StringUtils.defaultString(getIndexStatisticsDetails().getNumberOfKeys()) : ""; + } + + public String getNumberOfUpdates() { + return getIndexStatisticsDetails() != null + ? StringUtils.defaultString(getIndexStatisticsDetails().getNumberOfUpdates()) : ""; + } + + public String getNumberOfValues() { + return getIndexStatisticsDetails() != null + ? StringUtils.defaultString(getIndexStatisticsDetails().getNumberOfValues()) : ""; + } + + public String getTotalUpdateTime() { + return getIndexStatisticsDetails() != null + ? StringUtils.defaultString(getIndexStatisticsDetails().getTotalUpdateTime()) : ""; + } + + public String getTotalUses() { + return getIndexStatisticsDetails() != null + ? StringUtils.defaultString(getIndexStatisticsDetails().getTotalUses()) : ""; + } + } + +} http://git-wip-us.apache.org/repos/asf/geode/blob/645a32d0/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/IndexDefinition.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/IndexDefinition.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/IndexDefinition.java deleted file mode 100644 index 3d0e392..0000000 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/IndexDefinition.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more contributor license - * agreements. See the NOTICE file distributed with this work for additional information regarding - * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. You may obtain a - * copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. - */ - -package org.apache.geode.management.internal.cli.commands; - -import java.util.Collections; -import java.util.HashSet; -import java.util.Set; - -import org.apache.geode.management.internal.cli.domain.IndexInfo; - -public class IndexDefinition { - static final Set<IndexInfo> indexDefinitions = - Collections.synchronizedSet(new HashSet<IndexInfo>()); -} http://git-wip-us.apache.org/repos/asf/geode/blob/645a32d0/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/IndexStatisticsDetailsAdapter.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/IndexStatisticsDetailsAdapter.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/IndexStatisticsDetailsAdapter.java deleted file mode 100644 index 30d8157..0000000 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/IndexStatisticsDetailsAdapter.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more contributor license - * agreements. See the NOTICE file distributed with this work for additional information regarding - * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. You may obtain a - * copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. - */ - -package org.apache.geode.management.internal.cli.commands; - -import org.apache.geode.internal.lang.StringUtils; -import org.apache.geode.management.internal.cli.domain.IndexDetails; - -public class IndexStatisticsDetailsAdapter { - - private final IndexDetails.IndexStatisticsDetails indexStatisticsDetails; - - public IndexStatisticsDetailsAdapter( - final IndexDetails.IndexStatisticsDetails indexStatisticsDetails) { - this.indexStatisticsDetails = indexStatisticsDetails; - } - - public IndexDetails.IndexStatisticsDetails getIndexStatisticsDetails() { - return indexStatisticsDetails; - } - - public String getNumberOfKeys() { - return getIndexStatisticsDetails() != null - ? StringUtils.defaultString(getIndexStatisticsDetails().getNumberOfKeys()) : ""; - } - - public String getNumberOfUpdates() { - return getIndexStatisticsDetails() != null - ? StringUtils.defaultString(getIndexStatisticsDetails().getNumberOfUpdates()) : ""; - } - - public String getNumberOfValues() { - return getIndexStatisticsDetails() != null - ? StringUtils.defaultString(getIndexStatisticsDetails().getNumberOfValues()) : ""; - } - - public String getTotalUpdateTime() { - return getIndexStatisticsDetails() != null - ? StringUtils.defaultString(getIndexStatisticsDetails().getTotalUpdateTime()) : ""; - } - - public String getTotalUses() { - return getIndexStatisticsDetails() != null - ? StringUtils.defaultString(getIndexStatisticsDetails().getTotalUses()) : ""; - } -} http://git-wip-us.apache.org/repos/asf/geode/blob/645a32d0/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ListAsyncEventQueuesCommand.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ListAsyncEventQueuesCommand.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ListAsyncEventQueuesCommand.java deleted file mode 100644 index 8b3d1bd..0000000 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ListAsyncEventQueuesCommand.java +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more contributor license - * agreements. See the NOTICE file distributed with this work for additional information regarding - * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. You may obtain a - * copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. - */ - -package org.apache.geode.management.internal.cli.commands; - -import java.util.List; -import java.util.Map; -import java.util.Properties; -import java.util.Set; - -import org.springframework.shell.core.annotation.CliCommand; - -import org.apache.geode.SystemFailure; -import org.apache.geode.cache.execute.ResultCollector; -import org.apache.geode.distributed.DistributedMember; -import org.apache.geode.management.cli.Result; -import org.apache.geode.management.internal.cli.CliUtil; -import org.apache.geode.management.internal.cli.domain.AsyncEventQueueDetails; -import org.apache.geode.management.internal.cli.functions.CliFunctionResult; -import org.apache.geode.management.internal.cli.functions.ListAsyncEventQueuesFunction; -import org.apache.geode.management.internal.cli.i18n.CliStrings; -import org.apache.geode.management.internal.cli.result.ResultBuilder; -import org.apache.geode.management.internal.cli.result.TabularResultData; -import org.apache.geode.management.internal.security.ResourceOperation; -import org.apache.geode.security.ResourcePermission; - -public class ListAsyncEventQueuesCommand implements GfshCommand { - @CliCommand(value = CliStrings.LIST_ASYNC_EVENT_QUEUES, - help = CliStrings.LIST_ASYNC_EVENT_QUEUES__HELP) - @ResourceOperation(resource = ResourcePermission.Resource.CLUSTER, - operation = ResourcePermission.Operation.READ) - public Result listAsyncEventQueues() { - try { - TabularResultData tabularData = ResultBuilder.createTabularResultData(); - boolean accumulatedData = false; - - Set<DistributedMember> targetMembers = CliUtil.findMembers(null, null); - - if (targetMembers.isEmpty()) { - return ResultBuilder.createUserErrorResult(CliStrings.NO_MEMBERS_FOUND_MESSAGE); - } - - ResultCollector<?, ?> rc = CliUtil.executeFunction(new ListAsyncEventQueuesFunction(), - new Object[] {}, targetMembers); - List<CliFunctionResult> results = CliFunctionResult.cleanResults((List<?>) rc.getResult()); - - for (CliFunctionResult result : results) { - if (result.getThrowable() != null) { - tabularData.accumulate("Member", result.getMemberIdOrName()); - tabularData.accumulate("Result", "ERROR: " + result.getThrowable().getClass().getName() - + ": " + result.getThrowable().getMessage()); - accumulatedData = true; - tabularData.setStatus(Result.Status.ERROR); - } else { - AsyncEventQueueDetails[] details = (AsyncEventQueueDetails[]) result.getSerializables(); - for (AsyncEventQueueDetails detail : details) { - tabularData.accumulate("Member", result.getMemberIdOrName()); - tabularData.accumulate("ID", detail.getId()); - tabularData.accumulate("Batch Size", detail.getBatchSize()); - tabularData.accumulate("Persistent", detail.isPersistent()); - tabularData.accumulate("Disk Store", detail.getDiskStoreName()); - tabularData.accumulate("Max Memory", detail.getMaxQueueMemory()); - - Properties listenerProperties = detail.getListenerProperties(); - if (listenerProperties == null || listenerProperties.size() == 0) { - tabularData.accumulate("Listener", detail.getListener()); - } else { - StringBuilder propsStringBuilder = new StringBuilder(); - propsStringBuilder.append('('); - boolean firstProperty = true; - for (Map.Entry<Object, Object> property : listenerProperties.entrySet()) { - if (!firstProperty) { - propsStringBuilder.append(','); - } else { - firstProperty = false; - } - propsStringBuilder.append(property.getKey()).append('=') - .append(property.getValue()); - } - propsStringBuilder.append(')'); - - tabularData.accumulate("Listener", - detail.getListener() + propsStringBuilder.toString()); - } - accumulatedData = true; - } - } - } - - if (!accumulatedData) { - return ResultBuilder - .createInfoResult(CliStrings.LIST_ASYNC_EVENT_QUEUES__NO_QUEUES_FOUND_MESSAGE); - } - - return ResultBuilder.buildResult(tabularData); - } catch (VirtualMachineError e) { - SystemFailure.initiateFailure(e); - throw e; - } catch (Throwable th) { - SystemFailure.checkFailure(); - return ResultBuilder.createGemFireErrorResult( - CliStrings.format(CliStrings.LIST_ASYNC_EVENT_QUEUES__ERROR_WHILE_LISTING_REASON_0, - new Object[] {th.getMessage()})); - } - } -} http://git-wip-us.apache.org/repos/asf/geode/blob/645a32d0/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ListDeployedCommand.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ListDeployedCommand.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ListDeployedCommand.java deleted file mode 100644 index 4c2bc53..0000000 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ListDeployedCommand.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more contributor license - * agreements. See the NOTICE file distributed with this work for additional information regarding - * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. You may obtain a - * copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. - */ - -package org.apache.geode.management.internal.cli.commands; - -import java.util.List; -import java.util.Set; - -import org.springframework.shell.core.annotation.CliCommand; -import org.springframework.shell.core.annotation.CliOption; - -import org.apache.geode.SystemFailure; -import org.apache.geode.cache.execute.ResultCollector; -import org.apache.geode.distributed.DistributedMember; -import org.apache.geode.management.cli.CliMetaData; -import org.apache.geode.management.cli.Result; -import org.apache.geode.management.internal.cli.CliUtil; -import org.apache.geode.management.internal.cli.functions.CliFunctionResult; -import org.apache.geode.management.internal.cli.functions.ListDeployedFunction; -import org.apache.geode.management.internal.cli.i18n.CliStrings; -import org.apache.geode.management.internal.cli.result.ResultBuilder; -import org.apache.geode.management.internal.cli.result.TabularResultData; -import org.apache.geode.management.internal.security.ResourceOperation; -import org.apache.geode.security.ResourcePermission; - -public class ListDeployedCommand implements GfshCommand { - private final ListDeployedFunction listDeployedFunction = new ListDeployedFunction(); - - /** - * List all currently deployed JARs for members of a group or for all members. - * - * @param group Group for which to list JARs or null for all members - * @return List of deployed JAR files - */ - @CliCommand(value = {CliStrings.LIST_DEPLOYED}, help = CliStrings.LIST_DEPLOYED__HELP) - @CliMetaData(relatedTopic = {CliStrings.TOPIC_GEODE_CONFIG}) - @ResourceOperation(resource = ResourcePermission.Resource.CLUSTER, - operation = ResourcePermission.Operation.READ) - public Result listDeployed(@CliOption(key = {CliStrings.GROUP, CliStrings.GROUPS}, - help = CliStrings.LIST_DEPLOYED__GROUP__HELP) String[] group) { - - try { - TabularResultData tabularData = ResultBuilder.createTabularResultData(); - boolean accumulatedData = false; - - Set<DistributedMember> targetMembers = CliUtil.findMembers(group, null); - - if (targetMembers.isEmpty()) { - return ResultBuilder.createUserErrorResult(CliStrings.NO_MEMBERS_FOUND_MESSAGE); - } - - ResultCollector<?, ?> rc = - CliUtil.executeFunction(this.listDeployedFunction, null, targetMembers); - List<CliFunctionResult> results = CliFunctionResult.cleanResults((List<?>) rc.getResult()); - - for (CliFunctionResult result : results) { - if (result.getThrowable() != null) { - tabularData.accumulate("Member", result.getMemberIdOrName()); - tabularData.accumulate("JAR", ""); - tabularData.accumulate("JAR Location", - "ERROR: " + result.getThrowable().getClass().getName() + ": " - + result.getThrowable().getMessage()); - accumulatedData = true; - tabularData.setStatus(Result.Status.ERROR); - } else { - String[] strings = (String[]) result.getSerializables(); - for (int i = 0; i < strings.length; i += 2) { - tabularData.accumulate("Member", result.getMemberIdOrName()); - tabularData.accumulate("JAR", strings[i]); - tabularData.accumulate("JAR Location", strings[i + 1]); - accumulatedData = true; - } - } - } - - if (!accumulatedData) { - return ResultBuilder.createInfoResult(CliStrings.LIST_DEPLOYED__NO_JARS_FOUND_MESSAGE); - } - return ResultBuilder.buildResult(tabularData); - - } catch (VirtualMachineError e) { - SystemFailure.initiateFailure(e); - throw e; - } catch (Throwable th) { - SystemFailure.checkFailure(); - return ResultBuilder.createGemFireErrorResult("Exception while attempting to list deployed: " - + th.getClass().getName() + ": " + th.getMessage()); - } - } -} http://git-wip-us.apache.org/repos/asf/geode/blob/645a32d0/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ListDiskStoresCommand.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ListDiskStoresCommand.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ListDiskStoresCommand.java deleted file mode 100644 index c7d5a1e..0000000 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ListDiskStoresCommand.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more contributor license - * agreements. See the NOTICE file distributed with this work for additional information regarding - * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. You may obtain a - * copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. - */ - -package org.apache.geode.management.internal.cli.commands; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Set; - -import org.springframework.shell.core.annotation.CliCommand; - -import org.apache.geode.SystemFailure; -import org.apache.geode.cache.execute.Execution; -import org.apache.geode.cache.execute.FunctionInvocationTargetException; -import org.apache.geode.cache.execute.ResultCollector; -import org.apache.geode.distributed.DistributedMember; -import org.apache.geode.internal.cache.execute.AbstractExecution; -import org.apache.geode.management.cli.CliMetaData; -import org.apache.geode.management.cli.Result; -import org.apache.geode.management.internal.cli.domain.DiskStoreDetails; -import org.apache.geode.management.internal.cli.functions.ListDiskStoresFunction; -import org.apache.geode.management.internal.cli.i18n.CliStrings; -import org.apache.geode.management.internal.cli.result.ResultBuilder; -import org.apache.geode.management.internal.cli.result.ResultDataException; -import org.apache.geode.management.internal.cli.result.TabularResultData; -import org.apache.geode.management.internal.security.ResourceOperation; -import org.apache.geode.security.ResourcePermission; - -public class ListDiskStoresCommand implements GfshCommand { - @CliCommand(value = CliStrings.LIST_DISK_STORE, help = CliStrings.LIST_DISK_STORE__HELP) - @CliMetaData(relatedTopic = {CliStrings.TOPIC_GEODE_DISKSTORE}) - @ResourceOperation(resource = ResourcePermission.Resource.CLUSTER, - operation = ResourcePermission.Operation.READ) - public Result listDiskStores() { - try { - Set<DistributedMember> dataMembers = DiskStoreCommandsUtils.getNormalMembers(getCache()); - - if (dataMembers.isEmpty()) { - return ResultBuilder.createInfoResult(CliStrings.NO_CACHING_MEMBERS_FOUND_MESSAGE); - } - - return toTabularResult(getDiskStoreListing(dataMembers)); - } catch (FunctionInvocationTargetException ignore) { - return ResultBuilder.createGemFireErrorResult(CliStrings - .format(CliStrings.COULD_NOT_EXECUTE_COMMAND_TRY_AGAIN, CliStrings.LIST_DISK_STORE)); - } catch (VirtualMachineError e) { - SystemFailure.initiateFailure(e); - throw e; - } catch (Throwable t) { - SystemFailure.checkFailure(); - return ResultBuilder.createGemFireErrorResult( - String.format(CliStrings.LIST_DISK_STORE__ERROR_MESSAGE, toString(t, isDebugging()))); - } - } - - @SuppressWarnings("unchecked") - public List<DiskStoreDetails> getDiskStoreListing(Set<DistributedMember> members) { - final Execution membersFunctionExecutor = getMembersFunctionExecutor(members); - if (membersFunctionExecutor instanceof AbstractExecution) { - ((AbstractExecution) membersFunctionExecutor).setIgnoreDepartedMembers(true); - } - - final ResultCollector<?, ?> resultCollector = - membersFunctionExecutor.execute(new ListDiskStoresFunction()); - - final List<?> results = (List<?>) resultCollector.getResult(); - final List<DiskStoreDetails> distributedSystemMemberDiskStores = - new ArrayList<>(results.size()); - - for (final Object result : results) { - if (result instanceof Set) { // ignore FunctionInvocationTargetExceptions and other - // Exceptions... - distributedSystemMemberDiskStores.addAll((Set<DiskStoreDetails>) result); - } - } - - Collections.sort(distributedSystemMemberDiskStores); - - return distributedSystemMemberDiskStores; - } - - private Result toTabularResult(final List<DiskStoreDetails> diskStoreList) - throws ResultDataException { - if (!diskStoreList.isEmpty()) { - final TabularResultData diskStoreData = ResultBuilder.createTabularResultData(); - - for (final DiskStoreDetails diskStoreDetails : diskStoreList) { - diskStoreData.accumulate("Member Name", diskStoreDetails.getMemberName()); - diskStoreData.accumulate("Member Id", diskStoreDetails.getMemberId()); - diskStoreData.accumulate("Disk Store Name", diskStoreDetails.getName()); - diskStoreData.accumulate("Disk Store ID", diskStoreDetails.getId()); - } - - return ResultBuilder.buildResult(diskStoreData); - } else { - return ResultBuilder - .createInfoResult(CliStrings.LIST_DISK_STORE__DISK_STORES_NOT_FOUND_MESSAGE); - } - } -} http://git-wip-us.apache.org/repos/asf/geode/blob/645a32d0/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ListDurableClientCQsCommand.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ListDurableClientCQsCommand.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ListDurableClientCQsCommand.java deleted file mode 100644 index 011bfde..0000000 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ListDurableClientCQsCommand.java +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more contributor license - * agreements. See the NOTICE file distributed with this work for additional information regarding - * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. You may obtain a - * copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. - */ - -package org.apache.geode.management.internal.cli.commands; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.TreeMap; - -import org.springframework.shell.core.annotation.CliCommand; -import org.springframework.shell.core.annotation.CliOption; - -import org.apache.geode.cache.execute.ResultCollector; -import org.apache.geode.distributed.DistributedMember; -import org.apache.geode.management.cli.CliMetaData; -import org.apache.geode.management.cli.ConverterHint; -import org.apache.geode.management.cli.Result; -import org.apache.geode.management.internal.cli.CliUtil; -import org.apache.geode.management.internal.cli.domain.DurableCqNamesResult; -import org.apache.geode.management.internal.cli.functions.ListDurableCqNamesFunction; -import org.apache.geode.management.internal.cli.i18n.CliStrings; -import org.apache.geode.management.internal.cli.result.ResultBuilder; -import org.apache.geode.management.internal.cli.result.TabularResultData; -import org.apache.geode.management.internal.security.ResourceOperation; -import org.apache.geode.security.ResourcePermission; - -public class ListDurableClientCQsCommand implements GfshCommand { - DurableClientCommandsResultBuilder builder = new DurableClientCommandsResultBuilder(); - - @CliCommand(value = CliStrings.LIST_DURABLE_CQS, help = CliStrings.LIST_DURABLE_CQS__HELP) - @CliMetaData() - @ResourceOperation(resource = ResourcePermission.Resource.CLUSTER, - operation = ResourcePermission.Operation.READ) - public Result listDurableClientCQs( - @CliOption(key = CliStrings.LIST_DURABLE_CQS__DURABLECLIENTID, mandatory = true, - help = CliStrings.LIST_DURABLE_CQS__DURABLECLIENTID__HELP) final String durableClientId, - - @CliOption(key = {CliStrings.MEMBER, CliStrings.MEMBERS}, - help = CliStrings.LIST_DURABLE_CQS__MEMBER__HELP, - optionContext = ConverterHint.MEMBERIDNAME) final String[] memberNameOrId, - - @CliOption(key = {CliStrings.GROUP, CliStrings.GROUPS}, - help = CliStrings.LIST_DURABLE_CQS__GROUP__HELP, - optionContext = ConverterHint.MEMBERGROUP) final String[] group) { - Result result; - try { - - boolean noResults = true; - Set<DistributedMember> targetMembers = CliUtil.findMembers(group, memberNameOrId); - - if (targetMembers.isEmpty()) { - return ResultBuilder.createUserErrorResult(CliStrings.NO_MEMBERS_FOUND_MESSAGE); - } - - final ResultCollector<?, ?> rc = - CliUtil.executeFunction(new ListDurableCqNamesFunction(), durableClientId, targetMembers); - final List<DurableCqNamesResult> results = (List<DurableCqNamesResult>) rc.getResult(); - Map<String, List<String>> memberCqNamesMap = new TreeMap<>(); - Map<String, List<String>> errorMessageNodes = new HashMap<>(); - Map<String, List<String>> exceptionMessageNodes = new HashMap<>(); - - for (DurableCqNamesResult memberResult : results) { - if (memberResult != null) { - if (memberResult.isSuccessful()) { - memberCqNamesMap.put(memberResult.getMemberNameOrId(), memberResult.getCqNamesList()); - } else { - if (memberResult.isOpPossible()) { - builder.groupByMessage(memberResult.getExceptionMessage(), - memberResult.getMemberNameOrId(), exceptionMessageNodes); - } else { - builder.groupByMessage(memberResult.getErrorMessage(), - memberResult.getMemberNameOrId(), errorMessageNodes); - } - } - } - } - - if (!memberCqNamesMap.isEmpty()) { - TabularResultData table = ResultBuilder.createTabularResultData(); - Set<String> members = memberCqNamesMap.keySet(); - - for (String member : members) { - boolean isFirst = true; - List<String> cqNames = memberCqNamesMap.get(member); - for (String cqName : cqNames) { - if (isFirst) { - isFirst = false; - table.accumulate(CliStrings.MEMBER, member); - } else { - table.accumulate(CliStrings.MEMBER, ""); - } - table.accumulate(CliStrings.LIST_DURABLE_CQS__NAME, cqName); - } - } - result = ResultBuilder.buildResult(table); - } else { - String errorHeader = - CliStrings.format(CliStrings.LIST_DURABLE_CQS__FAILURE__HEADER, durableClientId); - result = ResultBuilder.buildResult( - builder.buildFailureData(null, exceptionMessageNodes, errorMessageNodes, errorHeader)); - } - } catch (Exception e) { - result = ResultBuilder.createGemFireErrorResult(e.getMessage()); - } - return result; - } -} http://git-wip-us.apache.org/repos/asf/geode/blob/645a32d0/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ListFunctionCommand.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ListFunctionCommand.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ListFunctionCommand.java deleted file mode 100644 index 81ef437..0000000 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ListFunctionCommand.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more contributor license - * agreements. See the NOTICE file distributed with this work for additional information regarding - * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. You may obtain a - * copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. - */ - -package org.apache.geode.management.internal.cli.commands; - -import java.util.Arrays; -import java.util.List; -import java.util.Set; - -import org.springframework.shell.core.annotation.CliCommand; -import org.springframework.shell.core.annotation.CliOption; - -import org.apache.geode.SystemFailure; -import org.apache.geode.cache.execute.ResultCollector; -import org.apache.geode.distributed.DistributedMember; -import org.apache.geode.management.cli.CliMetaData; -import org.apache.geode.management.cli.ConverterHint; -import org.apache.geode.management.cli.Result; -import org.apache.geode.management.internal.cli.CliUtil; -import org.apache.geode.management.internal.cli.functions.CliFunctionResult; -import org.apache.geode.management.internal.cli.functions.ListFunctionFunction; -import org.apache.geode.management.internal.cli.i18n.CliStrings; -import org.apache.geode.management.internal.cli.result.ResultBuilder; -import org.apache.geode.management.internal.cli.result.TabularResultData; -import org.apache.geode.management.internal.security.ResourceOperation; -import org.apache.geode.security.ResourcePermission; - -public class ListFunctionCommand implements GfshCommand { - private final ListFunctionFunction listFunctionFunction = new ListFunctionFunction(); - - @CliCommand(value = CliStrings.LIST_FUNCTION, help = CliStrings.LIST_FUNCTION__HELP) - @CliMetaData(relatedTopic = {CliStrings.TOPIC_GEODE_FUNCTION}) - @ResourceOperation(resource = ResourcePermission.Resource.CLUSTER, - operation = ResourcePermission.Operation.READ) - public Result listFunction( - @CliOption(key = CliStrings.LIST_FUNCTION__MATCHES, - help = CliStrings.LIST_FUNCTION__MATCHES__HELP) String matches, - @CliOption(key = {CliStrings.GROUP, CliStrings.GROUPS}, - optionContext = ConverterHint.MEMBERGROUP, - help = CliStrings.LIST_FUNCTION__GROUP__HELP) String[] groups, - @CliOption(key = {CliStrings.MEMBER, CliStrings.MEMBERS}, - optionContext = ConverterHint.MEMBERIDNAME, - help = CliStrings.LIST_FUNCTION__MEMBER__HELP) String[] members) { - TabularResultData tabularData = ResultBuilder.createTabularResultData(); - boolean accumulatedData = false; - Set<DistributedMember> targetMembers = CliUtil.findMembers(groups, members); - - if (targetMembers.isEmpty()) { - return ResultBuilder.createUserErrorResult(CliStrings.NO_MEMBERS_FOUND_MESSAGE); - } - - try { - ResultCollector<?, ?> rc = - CliUtil.executeFunction(this.listFunctionFunction, new Object[] {matches}, targetMembers); - List<CliFunctionResult> results = CliFunctionResult.cleanResults((List<?>) rc.getResult()); - - for (CliFunctionResult result : results) { - if (result.getThrowable() != null) { - tabularData.accumulate("Member", result.getMemberIdOrName()); - tabularData.accumulate("Function", "<ERROR: " + result.getThrowable().getMessage() + ">"); - accumulatedData = true; - tabularData.setStatus(Result.Status.ERROR); - } else if (result.isSuccessful()) { - String[] strings = (String[]) result.getSerializables(); - Arrays.sort(strings); - for (String string : strings) { - tabularData.accumulate("Member", result.getMemberIdOrName()); - tabularData.accumulate("Function", string); - accumulatedData = true; - } - } - } - - if (!accumulatedData) { - return ResultBuilder - .createInfoResult(CliStrings.LIST_FUNCTION__NO_FUNCTIONS_FOUND_ERROR_MESSAGE); - } - return ResultBuilder.buildResult(tabularData); - } catch (VirtualMachineError e) { - SystemFailure.initiateFailure(e); - throw e; - } catch (Throwable th) { - SystemFailure.checkFailure(); - return ResultBuilder.createGemFireErrorResult( - "Exception while attempting to list functions: " + th.getMessage()); - } - } -} http://git-wip-us.apache.org/repos/asf/geode/blob/645a32d0/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ListIndexCommand.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ListIndexCommand.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ListIndexCommand.java deleted file mode 100644 index 358cebd..0000000 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ListIndexCommand.java +++ /dev/null @@ -1,119 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more contributor license - * agreements. See the NOTICE file distributed with this work for additional information regarding - * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. You may obtain a - * copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. - */ - -package org.apache.geode.management.internal.cli.commands; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Set; - -import org.springframework.shell.core.annotation.CliCommand; -import org.springframework.shell.core.annotation.CliOption; - -import org.apache.geode.SystemFailure; -import org.apache.geode.cache.execute.Execution; -import org.apache.geode.cache.execute.FunctionInvocationTargetException; -import org.apache.geode.cache.execute.ResultCollector; -import org.apache.geode.internal.cache.execute.AbstractExecution; -import org.apache.geode.internal.lang.StringUtils; -import org.apache.geode.management.cli.CliMetaData; -import org.apache.geode.management.cli.Result; -import org.apache.geode.management.internal.cli.domain.IndexDetails; -import org.apache.geode.management.internal.cli.functions.ListIndexFunction; -import org.apache.geode.management.internal.cli.i18n.CliStrings; -import org.apache.geode.management.internal.cli.result.ResultBuilder; -import org.apache.geode.management.internal.cli.result.TabularResultData; -import org.apache.geode.management.internal.security.ResourceOperation; -import org.apache.geode.security.ResourcePermission; - -public class ListIndexCommand implements GfshCommand { - @CliCommand(value = CliStrings.LIST_INDEX, help = CliStrings.LIST_INDEX__HELP) - @CliMetaData(relatedTopic = {CliStrings.TOPIC_GEODE_REGION, CliStrings.TOPIC_GEODE_DATA}) - @ResourceOperation(resource = ResourcePermission.Resource.CLUSTER, - operation = ResourcePermission.Operation.READ, target = ResourcePermission.Target.QUERY) - public Result listIndex(@CliOption(key = CliStrings.LIST_INDEX__STATS, - specifiedDefaultValue = "true", unspecifiedDefaultValue = "false", - help = CliStrings.LIST_INDEX__STATS__HELP) final boolean showStats) { - try { - return toTabularResult(getIndexListing(), showStats); - } catch (FunctionInvocationTargetException ignore) { - return ResultBuilder.createGemFireErrorResult( - CliStrings.format(CliStrings.COULD_NOT_EXECUTE_COMMAND_TRY_AGAIN, CliStrings.LIST_INDEX)); - } catch (VirtualMachineError e) { - SystemFailure.initiateFailure(e); - throw e; - } catch (Throwable t) { - SystemFailure.checkFailure(); - getCache().getLogger().error(t); - return ResultBuilder.createGemFireErrorResult( - String.format(CliStrings.LIST_INDEX__ERROR_MESSAGE, toString(t, isDebugging()))); - } - } - - private Result toTabularResult(final List<IndexDetails> indexDetailsList, - final boolean showStats) { - if (!indexDetailsList.isEmpty()) { - final TabularResultData indexData = ResultBuilder.createTabularResultData(); - - for (final IndexDetails indexDetails : indexDetailsList) { - indexData.accumulate("Member Name", - StringUtils.defaultString(indexDetails.getMemberName())); - indexData.accumulate("Member ID", indexDetails.getMemberId()); - indexData.accumulate("Region Path", indexDetails.getRegionPath()); - indexData.accumulate("Name", indexDetails.getIndexName()); - indexData.accumulate("Type", StringUtils.defaultString(indexDetails.getIndexType())); - indexData.accumulate("Indexed Expression", indexDetails.getIndexedExpression()); - indexData.accumulate("From Clause", indexDetails.getFromClause()); - - if (showStats) { - final IndexStatisticsDetailsAdapter adapter = - new IndexStatisticsDetailsAdapter(indexDetails.getIndexStatisticsDetails()); - - indexData.accumulate("Uses", adapter.getTotalUses()); - indexData.accumulate("Updates", adapter.getNumberOfUpdates()); - indexData.accumulate("Update Time", adapter.getTotalUpdateTime()); - indexData.accumulate("Keys", adapter.getNumberOfKeys()); - indexData.accumulate("Values", adapter.getNumberOfValues()); - } - } - - return ResultBuilder.buildResult(indexData); - } else { - return ResultBuilder.createInfoResult(CliStrings.LIST_INDEX__INDEXES_NOT_FOUND_MESSAGE); - } - } - - List<IndexDetails> getIndexListing() { - final Execution functionExecutor = getMembersFunctionExecutor(getMembers(getCache())); - - if (functionExecutor instanceof AbstractExecution) { - ((AbstractExecution) functionExecutor).setIgnoreDepartedMembers(true); - } - - final ResultCollector<?, ?> resultsCollector = - functionExecutor.execute(new ListIndexFunction()); - final List<?> results = (List<?>) resultsCollector.getResult(); - final List<IndexDetails> indexDetailsList = new ArrayList<>(results.size()); - - for (Object result : results) { - if (result instanceof Set) { // ignore FunctionInvocationTargetExceptions and other Exceptions - indexDetailsList.addAll((Set<IndexDetails>) result); - } - } - Collections.sort(indexDetailsList); - return indexDetailsList; - } -} http://git-wip-us.apache.org/repos/asf/geode/blob/645a32d0/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ListMemberCommand.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ListMemberCommand.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ListMemberCommand.java deleted file mode 100644 index ea88c69..0000000 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ListMemberCommand.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more contributor license - * agreements. See the NOTICE file distributed with this work for additional information regarding - * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. You may obtain a - * copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. - */ - -package org.apache.geode.management.internal.cli.commands; - -import java.util.Set; -import java.util.TreeSet; - -import org.springframework.shell.core.annotation.CliCommand; -import org.springframework.shell.core.annotation.CliOption; - -import org.apache.geode.distributed.DistributedMember; -import org.apache.geode.internal.cache.InternalCache; -import org.apache.geode.management.cli.CliMetaData; -import org.apache.geode.management.cli.ConverterHint; -import org.apache.geode.management.cli.Result; -import org.apache.geode.management.internal.cli.CliUtil; -import org.apache.geode.management.internal.cli.LogWrapper; -import org.apache.geode.management.internal.cli.i18n.CliStrings; -import org.apache.geode.management.internal.cli.result.ResultBuilder; -import org.apache.geode.management.internal.cli.result.TabularResultData; -import org.apache.geode.management.internal.security.ResourceOperation; -import org.apache.geode.security.ResourcePermission; - -public class ListMemberCommand implements GfshCommand { - @CliCommand(value = {CliStrings.LIST_MEMBER}, help = CliStrings.LIST_MEMBER__HELP) - @CliMetaData(relatedTopic = CliStrings.TOPIC_GEODE_SERVER) - @ResourceOperation(resource = ResourcePermission.Resource.CLUSTER, - operation = ResourcePermission.Operation.READ) - public Result listMember(@CliOption(key = {CliStrings.GROUP}, unspecifiedDefaultValue = "", - optionContext = ConverterHint.MEMBERGROUP, - help = CliStrings.LIST_MEMBER__GROUP__HELP) String group) { - Result result; - - // TODO: Add the code for identifying the system services - try { - Set<DistributedMember> memberSet = new TreeSet<>(); - InternalCache cache = getCache(); - - // default get all the members in the DS - if (group.isEmpty()) { - memberSet.addAll(CliUtil.getAllMembers(cache)); - } else { - memberSet.addAll(cache.getDistributedSystem().getGroupMembers(group)); - } - - if (memberSet.isEmpty()) { - result = ResultBuilder.createInfoResult(CliStrings.LIST_MEMBER__MSG__NO_MEMBER_FOUND); - } else { - TabularResultData resultData = ResultBuilder.createTabularResultData(); - for (DistributedMember member : memberSet) { - resultData.accumulate("Name", member.getName()); - resultData.accumulate("Id", member.getId()); - } - - result = ResultBuilder.buildResult(resultData); - } - } catch (Exception e) { - result = ResultBuilder - .createGemFireErrorResult("Could not fetch the list of members. " + e.getMessage()); - LogWrapper.getInstance().warning(e.getMessage(), e); - } - return result; - } -}