geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kl...@apache.org
Subject [1/2] geode git commit: Move SelectExecStep back into DataCommandFunction
Date Mon, 05 Jun 2017 18:55:48 GMT
Repository: geode
Updated Branches:
  refs/heads/feature/GEODE-2632-21 16ea5e3c6 -> a9f939bb0


Move SelectExecStep back into DataCommandFunction


Project: http://git-wip-us.apache.org/repos/asf/geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/geode/commit/bce670aa
Tree: http://git-wip-us.apache.org/repos/asf/geode/tree/bce670aa
Diff: http://git-wip-us.apache.org/repos/asf/geode/diff/bce670aa

Branch: refs/heads/feature/GEODE-2632-21
Commit: bce670aa31142fb0195e916f479401592e673b6a
Parents: 16ea5e3
Author: Kirk Lund <klund@apache.org>
Authored: Mon Jun 5 11:05:48 2017 -0700
Committer: Kirk Lund <klund@apache.org>
Committed: Mon Jun 5 11:05:48 2017 -0700

----------------------------------------------------------------------
 .../internal/cli/commands/DataCommands.java     |   2 +-
 .../cli/functions/DataCommandFunction.java      | 100 ++++++++++++++
 .../internal/cli/functions/SelectExecStep.java  | 137 -------------------
 3 files changed, 101 insertions(+), 138 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/geode/blob/bce670aa/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/DataCommands.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/DataCommands.java
b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/DataCommands.java
index f665a67..887470d 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/DataCommands.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/DataCommands.java
@@ -44,10 +44,10 @@ import org.apache.geode.management.internal.cli.LogWrapper;
 import org.apache.geode.management.internal.cli.domain.DataCommandRequest;
 import org.apache.geode.management.internal.cli.domain.DataCommandResult;
 import org.apache.geode.management.internal.cli.functions.DataCommandFunction;
+import org.apache.geode.management.internal.cli.functions.DataCommandFunction.SelectExecStep;
 import org.apache.geode.management.internal.cli.functions.ExportDataFunction;
 import org.apache.geode.management.internal.cli.functions.ImportDataFunction;
 import org.apache.geode.management.internal.cli.functions.RebalanceFunction;
-import org.apache.geode.management.internal.cli.functions.SelectExecStep;
 import org.apache.geode.management.internal.cli.i18n.CliStrings;
 import org.apache.geode.management.internal.cli.multistep.CLIMultiStepHelper;
 import org.apache.geode.management.internal.cli.multistep.CLIStep;

http://git-wip-us.apache.org/repos/asf/geode/blob/bce670aa/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/DataCommandFunction.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/DataCommandFunction.java
b/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/DataCommandFunction.java
index ff7aa02..20e2701 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/DataCommandFunction.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/DataCommandFunction.java
@@ -913,6 +913,106 @@ public class DataCommandFunction extends FunctionAdapter implements
InternalEnti
     }
   }
 
+  public static class SelectExecStep extends CLIMultiStepHelper.RemoteStep {
+    private static final Logger logger = LogService.getLogger();
+
+    private static final long serialVersionUID = 1L;
+
+    public SelectExecStep(Object[] arguments) {
+      super(DataCommandFunction.SELECT_STEP_EXEC, arguments);
+    }
+
+    @Override
+    public Result exec() {
+      String remainingQuery = (String) commandArguments[0];
+      boolean interactive = (Boolean) commandArguments[2];
+      DataCommandResult result = _select(remainingQuery);
+      int endCount = 0;
+      DataCommandFunction.cachedResult = result;
+      if (interactive) {
+        endCount = DataCommandFunction.getPageSize();
+      } else {
+        if (result.getSelectResult() != null) {
+          endCount = result.getSelectResult().size();
+        }
+      }
+      if (interactive) {
+        return result.pageResult(0, endCount, DataCommandFunction.SELECT_STEP_DISPLAY);
+      } else {
+        return CLIMultiStepHelper.createBannerResult(new String[] {}, new Object[] {},
+            DataCommandFunction.SELECT_STEP_END);
+      }
+    }
+
+    public DataCommandResult _select(String query) {
+      InternalCache cache = (InternalCache) CacheFactory.getAnyInstance();
+      DataCommandResult dataResult;
+
+      if (StringUtils.isEmpty(query)) {
+        dataResult = DataCommandResult.createSelectInfoResult(null, null, -1, null,
+            CliStrings.QUERY__MSG__QUERY_EMPTY, false);
+        return dataResult;
+      }
+
+      Object array[] = DataCommands.replaceGfshEnvVar(query, CommandExecutionContext.getShellEnv());
+      query = (String) array[1];
+      query = addLimit(query);
+
+      @SuppressWarnings("deprecation")
+      QCompiler compiler = new QCompiler();
+      Set<String> regionsInQuery;
+      try {
+        CompiledValue compiledQuery = compiler.compileQuery(query);
+        Set<String> regions = new HashSet<>();
+        compiledQuery.getRegionsInQuery(regions, null);
+
+        // authorize data read on these regions
+        for (String region : regions) {
+          cache.getSecurityService().authorizeRegionRead(region);
+        }
+
+        regionsInQuery = Collections.unmodifiableSet(regions);
+        if (regionsInQuery.size() > 0) {
+          Set<DistributedMember> members =
+              DataCommands.getQueryRegionsAssociatedMembers(regionsInQuery, cache, false);
+          if (members != null && members.size() > 0) {
+            DataCommandFunction function = new DataCommandFunction();
+            DataCommandRequest request = new DataCommandRequest();
+            request.setCommand(CliStrings.QUERY);
+            request.setQuery(query);
+            Subject subject = cache.getSecurityService().getSubject();
+            if (subject != null) {
+              request.setPrincipal(subject.getPrincipal());
+            }
+            dataResult = DataCommands.callFunctionForRegion(request, function, members);
+            dataResult.setInputQuery(query);
+            return dataResult;
+          } else {
+            return DataCommandResult.createSelectInfoResult(null, null, -1, null, CliStrings.format(
+                CliStrings.QUERY__MSG__REGIONS_NOT_FOUND, regionsInQuery.toString()), false);
+          }
+        } else {
+          return DataCommandResult.createSelectInfoResult(null, null, -1, null,
+              CliStrings.format(CliStrings.QUERY__MSG__INVALID_QUERY,
+                  "Region mentioned in query probably missing /"),
+              false);
+        }
+      } catch (QueryInvalidException qe) {
+        logger.error("{} Failed Error {}", query, qe.getMessage(), qe);
+        return DataCommandResult.createSelectInfoResult(null, null, -1, null,
+            CliStrings.format(CliStrings.QUERY__MSG__INVALID_QUERY, qe.getMessage()), false);
+      }
+    }
+
+    private String addLimit(String query) {
+      if (StringUtils.containsIgnoreCase(query, " limit")
+          || StringUtils.containsIgnoreCase(query, " count(")) {
+        return query;
+      }
+      return query + " limit " + DataCommandFunction.getFetchSize();
+    }
+  }
+
   public static class SelectQuitStep extends CLIMultiStepHelper.RemoteStep {
 
     public SelectQuitStep(Object[] arguments) {

http://git-wip-us.apache.org/repos/asf/geode/blob/bce670aa/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/SelectExecStep.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/SelectExecStep.java
b/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/SelectExecStep.java
deleted file mode 100644
index 8d9e57b..0000000
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/SelectExecStep.java
+++ /dev/null
@@ -1,137 +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.functions;
-
-import org.apache.commons.lang.StringUtils;
-import org.apache.geode.cache.CacheFactory;
-import org.apache.geode.cache.query.QueryInvalidException;
-import org.apache.geode.cache.query.internal.CompiledValue;
-import org.apache.geode.cache.query.internal.QCompiler;
-import org.apache.geode.distributed.DistributedMember;
-import org.apache.geode.internal.cache.InternalCache;
-import org.apache.geode.internal.logging.LogService;
-import org.apache.geode.management.cli.Result;
-import org.apache.geode.management.internal.cli.commands.DataCommands;
-import org.apache.geode.management.internal.cli.domain.DataCommandRequest;
-import org.apache.geode.management.internal.cli.domain.DataCommandResult;
-import org.apache.geode.management.internal.cli.i18n.CliStrings;
-import org.apache.geode.management.internal.cli.multistep.CLIMultiStepHelper;
-import org.apache.geode.management.internal.cli.remote.CommandExecutionContext;
-import org.apache.logging.log4j.Logger;
-import org.apache.shiro.subject.Subject;
-
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Set;
-
-public class SelectExecStep extends CLIMultiStepHelper.RemoteStep {
-  private static final Logger logger = LogService.getLogger();
-
-  private static final long serialVersionUID = 1L;
-
-  public SelectExecStep(Object[] arguments) {
-    super(DataCommandFunction.SELECT_STEP_EXEC, arguments);
-  }
-
-  @Override
-  public Result exec() {
-    String remainingQuery = (String) commandArguments[0];
-    boolean interactive = (Boolean) commandArguments[2];
-    DataCommandResult result = _select(remainingQuery);
-    int endCount = 0;
-    DataCommandFunction.cachedResult = result;
-    if (interactive) {
-      endCount = DataCommandFunction.getPageSize();
-    } else {
-      if (result.getSelectResult() != null) {
-        endCount = result.getSelectResult().size();
-      }
-    }
-    if (interactive) {
-      return result.pageResult(0, endCount, DataCommandFunction.SELECT_STEP_DISPLAY);
-    } else {
-      return CLIMultiStepHelper.createBannerResult(new String[] {}, new Object[] {},
-          DataCommandFunction.SELECT_STEP_END);
-    }
-  }
-
-  public DataCommandResult _select(String query) {
-    InternalCache cache = (InternalCache) CacheFactory.getAnyInstance();
-    DataCommandResult dataResult;
-
-    if (StringUtils.isEmpty(query)) {
-      dataResult = DataCommandResult.createSelectInfoResult(null, null, -1, null,
-          CliStrings.QUERY__MSG__QUERY_EMPTY, false);
-      return dataResult;
-    }
-
-    Object array[] = DataCommands.replaceGfshEnvVar(query, CommandExecutionContext.getShellEnv());
-    query = (String) array[1];
-    query = addLimit(query);
-
-    @SuppressWarnings("deprecation")
-    QCompiler compiler = new QCompiler();
-    Set<String> regionsInQuery;
-    try {
-      CompiledValue compiledQuery = compiler.compileQuery(query);
-      Set<String> regions = new HashSet<>();
-      compiledQuery.getRegionsInQuery(regions, null);
-
-      // authorize data read on these regions
-      for (String region : regions) {
-        cache.getSecurityService().authorizeRegionRead(region);
-      }
-
-      regionsInQuery = Collections.unmodifiableSet(regions);
-      if (regionsInQuery.size() > 0) {
-        Set<DistributedMember> members =
-            DataCommands.getQueryRegionsAssociatedMembers(regionsInQuery, cache, false);
-        if (members != null && members.size() > 0) {
-          DataCommandFunction function = new DataCommandFunction();
-          DataCommandRequest request = new DataCommandRequest();
-          request.setCommand(CliStrings.QUERY);
-          request.setQuery(query);
-          Subject subject = cache.getSecurityService().getSubject();
-          if (subject != null) {
-            request.setPrincipal(subject.getPrincipal());
-          }
-          dataResult = DataCommands.callFunctionForRegion(request, function, members);
-          dataResult.setInputQuery(query);
-          return dataResult;
-        } else {
-          return DataCommandResult.createSelectInfoResult(null, null, -1, null, CliStrings
-              .format(CliStrings.QUERY__MSG__REGIONS_NOT_FOUND, regionsInQuery.toString()),
false);
-        }
-      } else {
-        return DataCommandResult.createSelectInfoResult(null, null, -1, null,
-            CliStrings.format(CliStrings.QUERY__MSG__INVALID_QUERY,
-                "Region mentioned in query probably missing /"),
-            false);
-      }
-    } catch (QueryInvalidException qe) {
-      logger.error("{} Failed Error {}", query, qe.getMessage(), qe);
-      return DataCommandResult.createSelectInfoResult(null, null, -1, null,
-          CliStrings.format(CliStrings.QUERY__MSG__INVALID_QUERY, qe.getMessage()), false);
-    }
-  }
-
-  private String addLimit(String query) {
-    if (StringUtils.containsIgnoreCase(query, " limit")
-        || StringUtils.containsIgnoreCase(query, " count(")) {
-      return query;
-    }
-    return query + " limit " + DataCommandFunction.getFetchSize();
-  }
-}


Mime
View raw message