This is an automated email from the ASF dual-hosted git repository.

jinmeiliao pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode.git


The following commit(s) were added to refs/heads/develop by this push:
     new 9223b16  GEODE-4527: get rid of static getAnyInstance or getInstance 
call to get the cache. (#1596)
9223b16 is described below

commit 9223b16fb97ee0d6cf2d02bd7b290b4e91227364
Author: jinmeiliao <jil...@pivotal.io>
AuthorDate: Tue Mar 13 15:41:27 2018 -0700

    GEODE-4527: get rid of static getAnyInstance or getInstance call to get the 
cache. (#1596)
---
 .../cli/commands/ChangeLogLevelCommand.java        | 136 ++++++++++-----------
 .../internal/cli/commands/QueryCommand.java        |   3 +-
 .../StatusClusterConfigServiceCommand.java         |   3 +-
 3 files changed, 68 insertions(+), 74 deletions(-)

diff --git 
a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ChangeLogLevelCommand.java
 
b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ChangeLogLevelCommand.java
index 6bd4fe8..aeeb2da 100644
--- 
a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ChangeLogLevelCommand.java
+++ 
b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ChangeLogLevelCommand.java
@@ -21,23 +21,22 @@ import java.util.Map;
 import java.util.Set;
 
 import org.apache.commons.lang.StringUtils;
+import org.apache.logging.log4j.Logger;
 import org.springframework.shell.core.annotation.CliCommand;
 import org.springframework.shell.core.annotation.CliOption;
 
-import org.apache.geode.LogWriter;
 import org.apache.geode.cache.execute.Execution;
 import org.apache.geode.cache.execute.Function;
 import org.apache.geode.cache.execute.FunctionService;
 import org.apache.geode.distributed.DistributedMember;
-import org.apache.geode.internal.cache.GemFireCacheImpl;
 import org.apache.geode.internal.cache.InternalCache;
+import org.apache.geode.internal.logging.LogService;
 import org.apache.geode.internal.logging.log4j.LogLevel;
 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.AbstractCliAroundInterceptor;
 import org.apache.geode.management.internal.cli.GfshParseResult;
-import org.apache.geode.management.internal.cli.LogWrapper;
 import 
org.apache.geode.management.internal.cli.functions.ChangeLogLevelFunction;
 import org.apache.geode.management.internal.cli.i18n.CliStrings;
 import org.apache.geode.management.internal.cli.result.CompositeResultData;
@@ -47,6 +46,8 @@ import 
org.apache.geode.management.internal.security.ResourceOperation;
 import org.apache.geode.security.ResourcePermission;
 
 public class ChangeLogLevelCommand extends GfshCommand {
+  private static Logger logger = LogService.getLogger();
+
   @CliCommand(value = CliStrings.CHANGE_LOGLEVEL, help = 
CliStrings.CHANGE_LOGLEVEL__HELP)
   @CliMetaData(relatedTopic = {CliStrings.TOPIC_LOGS},
       interceptor = 
"org.apache.geode.management.internal.cli.commands.ChangeLogLevelCommand$ChangeLogLevelCommandInterceptor")
@@ -60,91 +61,86 @@ public class ChangeLogLevelCommand extends GfshCommand {
       @CliOption(key = CliStrings.CHANGE_LOGLEVEL__LOGLEVEL,
           optionContext = ConverterHint.LOG_LEVEL, mandatory = true, 
unspecifiedDefaultValue = "",
           help = CliStrings.CHANGE_LOGLEVEL__LOGLEVEL__HELP) String logLevel) {
-    try {
-      if ((memberIds == null || memberIds.length == 0) && (grps == null || 
grps.length == 0)) {
-        return ResultBuilder
-            
.createUserErrorResult(CliStrings.CHANGE_LOGLEVEL__MSG__SPECIFY_GRP_OR_MEMBER);
-      }
 
-      InternalCache cache = getCache();
-      LogWriter logger = cache.getLogger();
+    if ((memberIds == null || memberIds.length == 0) && (grps == null || 
grps.length == 0)) {
+      return ResultBuilder
+          
.createUserErrorResult(CliStrings.CHANGE_LOGLEVEL__MSG__SPECIFY_GRP_OR_MEMBER);
+    }
 
-      Set<DistributedMember> dsMembers = new HashSet<>();
-      Set<DistributedMember> ds = getAllMembers();
+    InternalCache cache = getCache();
 
-      if (grps != null && grps.length > 0) {
-        for (String grp : grps) {
-          dsMembers.addAll(cache.getDistributedSystem().getGroupMembers(grp));
-        }
+    Set<DistributedMember> dsMembers = new HashSet<>();
+    Set<DistributedMember> ds = getAllMembers();
+
+    if (grps != null && grps.length > 0) {
+      for (String grp : grps) {
+        dsMembers.addAll(cache.getDistributedSystem().getGroupMembers(grp));
       }
+    }
 
-      if (memberIds != null && memberIds.length > 0) {
-        for (String member : memberIds) {
-          for (DistributedMember mem : ds) {
-            if (mem.getName() != null
-                && (mem.getName().equals(member) || 
mem.getId().equals(member))) {
-              dsMembers.add(mem);
-              break;
-            }
+    if (memberIds != null && memberIds.length > 0) {
+      for (String member : memberIds) {
+        for (DistributedMember mem : ds) {
+          if (mem.getName() != null
+              && (mem.getName().equals(member) || mem.getId().equals(member))) 
{
+            dsMembers.add(mem);
+            break;
           }
         }
       }
+    }
 
-      if (dsMembers.size() == 0) {
-        return ResultBuilder.createGemFireErrorResult(
-            "No members were found matching the given member IDs or groups.");
-      }
-
-      Function logFunction = new ChangeLogLevelFunction();
-      FunctionService.registerFunction(logFunction);
-      Object[] functionArgs = new Object[1];
-      functionArgs[0] = logLevel;
+    if (dsMembers.size() == 0) {
+      return ResultBuilder.createGemFireErrorResult(
+          "No members were found matching the given member IDs or groups.");
+    }
 
-      CompositeResultData compositeResultData = 
ResultBuilder.createCompositeResultData();
-      CompositeResultData.SectionResultData section = 
compositeResultData.addSection("section");
-      TabularResultData resultTable = section.addTable("ChangeLogLevel");
-      resultTable = resultTable.setHeader("Summary");
+    Function logFunction = new ChangeLogLevelFunction();
+    FunctionService.registerFunction(logFunction);
+    Object[] functionArgs = new Object[1];
+    functionArgs[0] = logLevel;
 
-      Execution execution = 
FunctionService.onMembers(dsMembers).setArguments(functionArgs);
-      if (execution == null) {
-        return 
ResultBuilder.createUserErrorResult(CliStrings.CHANGE_LOGLEVEL__MSG__CANNOT_EXECUTE);
-      }
-      List<?> resultList = (List<?>) 
execution.execute(logFunction).getResult();
-
-      for (Object object : resultList) {
-        try {
-          if (object instanceof Throwable) {
-            logger.warning(
-                "Exception in ChangeLogLevelFunction " + ((Throwable) 
object).getMessage(),
-                ((Throwable) object));
-            continue;
-          }
+    CompositeResultData compositeResultData = 
ResultBuilder.createCompositeResultData();
+    CompositeResultData.SectionResultData section = 
compositeResultData.addSection("section");
+    TabularResultData resultTable = section.addTable("ChangeLogLevel");
+    resultTable = resultTable.setHeader("Summary");
 
-          if (object != null) {
-            Map<String, String> resultMap = (Map<String, String>) object;
-            Map.Entry<String, String> entry = 
resultMap.entrySet().iterator().next();
+    Execution execution = 
FunctionService.onMembers(dsMembers).setArguments(functionArgs);
+    if (execution == null) {
+      return 
ResultBuilder.createUserErrorResult(CliStrings.CHANGE_LOGLEVEL__MSG__CANNOT_EXECUTE);
+    }
+    List<?> resultList =
+        (List<?>) this.executeFunction(logFunction, functionArgs, 
dsMembers).getResult();
+    for (Object object : resultList) {
+      try {
+        if (object instanceof Throwable) {
+          logger.warn("Exception in ChangeLogLevelFunction " + ((Throwable) 
object).getMessage(),
+              ((Throwable) object));
+          continue;
+        }
 
-            if (entry.getValue().contains("ChangeLogLevelFunction exception")) 
{
-              
resultTable.accumulate(CliStrings.CHANGE_LOGLEVEL__COLUMN_MEMBER, 
entry.getKey());
-              
resultTable.accumulate(CliStrings.CHANGE_LOGLEVEL__COLUMN_STATUS, "false");
-            } else {
-              
resultTable.accumulate(CliStrings.CHANGE_LOGLEVEL__COLUMN_MEMBER, 
entry.getKey());
-              
resultTable.accumulate(CliStrings.CHANGE_LOGLEVEL__COLUMN_STATUS, "true");
-            }
+        if (object != null) {
+          Map<String, String> resultMap = (Map<String, String>) object;
+          Map.Entry<String, String> entry = 
resultMap.entrySet().iterator().next();
 
+          if (entry.getValue().contains("ChangeLogLevelFunction exception")) {
+            resultTable.accumulate(CliStrings.CHANGE_LOGLEVEL__COLUMN_MEMBER, 
entry.getKey());
+            resultTable.accumulate(CliStrings.CHANGE_LOGLEVEL__COLUMN_STATUS, 
"false");
+          } else {
+            resultTable.accumulate(CliStrings.CHANGE_LOGLEVEL__COLUMN_MEMBER, 
entry.getKey());
+            resultTable.accumulate(CliStrings.CHANGE_LOGLEVEL__COLUMN_STATUS, 
"true");
           }
-        } catch (Exception ex) {
-          LogWrapper.getInstance(getCache()).warning("change log level command 
exception " + ex);
+
         }
+      } catch (Exception ex) {
+        logger.warn("change log level command exception " + ex);
       }
-
-      Result result = ResultBuilder.buildResult(compositeResultData);
-      logger.info("change log-level command result=" + result);
-      return result;
-    } catch (Exception ex) {
-      GemFireCacheImpl.getInstance().getLogger().error("GFSH Changeloglevel 
exception: " + ex);
-      return ResultBuilder.createUserErrorResult(ex.getMessage());
     }
+
+    Result result = ResultBuilder.buildResult(compositeResultData);
+    logger.info("change log-level command result=" + result);
+    return result;
+
   }
 
   public static class ChangeLogLevelCommandInterceptor extends 
AbstractCliAroundInterceptor {
diff --git 
a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/QueryCommand.java
 
b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/QueryCommand.java
index 7576d23..69d6985 100644
--- 
a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/QueryCommand.java
+++ 
b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/QueryCommand.java
@@ -27,7 +27,6 @@ import org.apache.shiro.subject.Subject;
 import org.springframework.shell.core.annotation.CliCommand;
 import org.springframework.shell.core.annotation.CliOption;
 
-import org.apache.geode.cache.CacheFactory;
 import org.apache.geode.cache.execute.FunctionService;
 import org.apache.geode.cache.execute.ResultCollector;
 import org.apache.geode.cache.query.QueryInvalidException;
@@ -68,7 +67,7 @@ public class QueryCommand extends GfshCommand {
   }
 
   private DataCommandResult select(String query) {
-    InternalCache cache = (InternalCache) CacheFactory.getAnyInstance();
+    InternalCache cache = getCache();
     DataCommandResult dataResult;
 
     if (StringUtils.isEmpty(query)) {
diff --git 
a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/StatusClusterConfigServiceCommand.java
 
b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/StatusClusterConfigServiceCommand.java
index 59e9ffe..cf4d232 100644
--- 
a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/StatusClusterConfigServiceCommand.java
+++ 
b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/StatusClusterConfigServiceCommand.java
@@ -22,7 +22,6 @@ import org.springframework.shell.core.annotation.CliCommand;
 
 import org.apache.geode.cache.execute.ResultCollector;
 import org.apache.geode.distributed.DistributedMember;
-import org.apache.geode.internal.cache.GemFireCacheImpl;
 import org.apache.geode.internal.cache.InternalCache;
 import org.apache.geode.management.cli.CliMetaData;
 import org.apache.geode.management.cli.Result;
@@ -47,7 +46,7 @@ public class StatusClusterConfigServiceCommand extends 
GfshCommand {
   @CliMetaData(relatedTopic = CliStrings.TOPIC_GEODE_LOCATOR)
   @ResourceOperation(resource = Resource.CLUSTER, operation = Operation.READ)
   public Result statusSharedConfiguration() {
-    final InternalCache cache = GemFireCacheImpl.getInstance();
+    final InternalCache cache = getCache();
     final Set<DistributedMember> locators = new HashSet<>(
         
cache.getDistributionManager().getAllHostedLocatorsWithSharedConfiguration().keySet());
     if (locators.isEmpty()) {

-- 
To stop receiving notification emails like this one, please contact
jinmeil...@apache.org.

Reply via email to