[ 
https://issues.apache.org/jira/browse/GEODE-3258?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16117531#comment-16117531
 ] 

ASF GitHub Bot commented on GEODE-3258:
---------------------------------------

Github user YehEmily commented on a diff in the pull request:

    https://github.com/apache/geode/pull/687#discussion_r131787125
  
    --- Diff: 
geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ListDiskStoreCommand.java
 ---
    @@ -0,0 +1,120 @@
    +/*
    + * 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.InternalCache;
    +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.CliUtil;
    +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 ListDiskStoreCommand 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 listDiskStore() {
    +    try {
    +      Set<DistributedMember> dataMembers = 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);
    +    }
    +  }
    +
    +  public Set<DistributedMember> getNormalMembers(final InternalCache 
cache) {
    --- End diff --
    
    I think I had some kind of reason for keeping this method out of the Utils 
class, but I can't remember it anymore... I made the fix and everything seems 
fine, though! Thank you for your feedback!


> Refactor DiskStoreCommands
> --------------------------
>
>                 Key: GEODE-3258
>                 URL: https://issues.apache.org/jira/browse/GEODE-3258
>             Project: Geode
>          Issue Type: Sub-task
>          Components: gfsh
>            Reporter: Emily Yeh
>            Assignee: Emily Yeh
>
> {{DiskStoreCommands.java}} is a large class that contains multiple commands. 
> Each command should be refactored into a separate class, and the methods 
> shared by the commands should be refactored into a new and appropriately 
> named class of their own.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to