geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jinmeil...@apache.org
Subject [geode] branch develop updated: Revert "GEODE-6779: fix issue with Bean check variations (#3798)"
Date Wed, 17 Jul 2019 00:04:27 GMT
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 0983347  Revert "GEODE-6779: fix issue with Bean check variations (#3798)"
0983347 is described below

commit 098334782a641b07aa1c909675f92042b91cd782
Author: Jinmei Liao <jiliao@pivotal.io>
AuthorDate: Tue Jul 16 17:03:58 2019 -0700

    Revert "GEODE-6779: fix issue with Bean check variations (#3798)"
    
    This reverts commit 786dfe9f
---
 .../apache/geode/management/cli/GfshCommand.java   | 33 -----------
 .../cli/commands/CompactDiskStoreCommand.java      | 15 +++--
 .../cli/commands/CreateDiskStoreCommand.java       | 22 ++++++-
 .../internal/cli/commands/CreateRegionCommand.java | 27 ++++++---
 .../cli/commands/GfshCommandJUnitTest.java         | 67 ++++------------------
 5 files changed, 59 insertions(+), 105 deletions(-)

diff --git a/geode-core/src/main/java/org/apache/geode/management/cli/GfshCommand.java b/geode-core/src/main/java/org/apache/geode/management/cli/GfshCommand.java
index 9e47345..3591086 100644
--- a/geode-core/src/main/java/org/apache/geode/management/cli/GfshCommand.java
+++ b/geode-core/src/main/java/org/apache/geode/management/cli/GfshCommand.java
@@ -19,9 +19,7 @@ import java.util.List;
 import java.util.Set;
 import java.util.concurrent.TimeUnit;
 import java.util.function.Supplier;
-import java.util.stream.Stream;
 
-import org.apache.logging.log4j.Logger;
 import org.apache.shiro.subject.Subject;
 import org.springframework.shell.core.CommandMarker;
 
@@ -36,8 +34,6 @@ import org.apache.geode.distributed.DistributedMember;
 import org.apache.geode.distributed.internal.InternalLocator;
 import org.apache.geode.internal.Version;
 import org.apache.geode.internal.cache.InternalCache;
-import org.apache.geode.internal.logging.LogService;
-import org.apache.geode.management.DistributedSystemMXBean;
 import org.apache.geode.management.ManagementService;
 import org.apache.geode.management.api.ClusterManagementService;
 import org.apache.geode.management.internal.cli.CliUtil;
@@ -49,7 +45,6 @@ import org.apache.geode.security.ResourcePermission;
 
 @Experimental
 public abstract class GfshCommand implements CommandMarker {
-  private static final Logger logger = LogService.getLogger();
   public static final String EXPERIMENTAL = "(Experimental) ";
   private InternalCache cache;
 
@@ -255,32 +250,4 @@ public abstract class GfshCommand implements CommandMarker {
     return false;
 
   }
-
-  public boolean diskStoreBeanAndMemberBeanDiskStoreExists(DistributedSystemMXBean dsMXBean,
-      String memberName,
-      String diskStore) {
-    return diskStoreBeanExists(dsMXBean, memberName, diskStore) &&
-        memberBeanDiskStoreExists(dsMXBean, memberName, diskStore);
-  }
-
-  private boolean diskStoreBeanExists(DistributedSystemMXBean dsMXBean, String memberName,
-      String diskStore) {
-    try {
-      dsMXBean.fetchDiskStoreObjectName(memberName, diskStore);
-      return true;
-    } catch (Exception e) {
-      if (!e.getMessage().toLowerCase().contains("not found")) {
-        logger.warn("Unable to retrieve Disk Store ObjectName for member: {}, diskstore:
{} - {}",
-            memberName, diskStore, e.getMessage());
-      }
-    }
-    return false;
-  }
-
-  private boolean memberBeanDiskStoreExists(DistributedSystemMXBean dsMXBean, String memberName,
-      String diskStore) {
-    return (Stream.of(dsMXBean.listMemberDiskstore().get(memberName))
-        .filter(dsName -> dsName.equals(diskStore))
-        .findFirst().orElse(null) != null);
-  }
 }
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/CompactDiskStoreCommand.java
b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/CompactDiskStoreCommand.java
index 62c5bfb..f31a578 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/CompactDiskStoreCommand.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/CompactDiskStoreCommand.java
@@ -22,8 +22,8 @@ import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
-import java.util.stream.Stream;
 
+import org.apache.commons.lang3.ArrayUtils;
 import org.springframework.shell.core.annotation.CliCommand;
 import org.springframework.shell.core.annotation.CliOption;
 
@@ -163,9 +163,16 @@ public class CompactDiskStoreCommand extends GfshCommand {
   private boolean diskStoreExists(String diskStoreName) {
     ManagementService managementService = getManagementService();
     DistributedSystemMXBean dsMXBean = managementService.getDistributedSystemMXBean();
+    Map<String, String[]> diskstore = dsMXBean.listMemberDiskstore();
 
-    return Stream.of(dsMXBean.listMembers())
-        .anyMatch(memberName -> diskStoreBeanAndMemberBeanDiskStoreExists(dsMXBean, memberName,
-            diskStoreName));
+    Set<Map.Entry<String, String[]>> entrySet = diskstore.entrySet();
+
+    for (Map.Entry<String, String[]> entry : entrySet) {
+      String[] value = entry.getValue();
+      if (diskStoreName != null && ArrayUtils.contains(value, diskStoreName)) {
+        return true;
+      }
+    }
+    return false;
   }
 }
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/CreateDiskStoreCommand.java
b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/CreateDiskStoreCommand.java
index 7167777..e741902 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/CreateDiskStoreCommand.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/CreateDiskStoreCommand.java
@@ -23,6 +23,7 @@ import java.util.Set;
 import java.util.concurrent.TimeUnit;
 
 import org.apache.commons.lang3.tuple.Pair;
+import org.apache.logging.log4j.Logger;
 import org.springframework.shell.core.annotation.CliCommand;
 import org.springframework.shell.core.annotation.CliOption;
 
@@ -35,6 +36,7 @@ import org.apache.geode.cache.execute.ResultCollector;
 import org.apache.geode.distributed.DistributedMember;
 import org.apache.geode.internal.cache.DiskStoreAttributes;
 import org.apache.geode.internal.cache.execute.AbstractExecution;
+import org.apache.geode.internal.logging.LogService;
 import org.apache.geode.management.DistributedSystemMXBean;
 import org.apache.geode.management.cli.CliMetaData;
 import org.apache.geode.management.cli.ConverterHint;
@@ -49,6 +51,7 @@ import org.apache.geode.management.internal.security.ResourceOperation;
 import org.apache.geode.security.ResourcePermission;
 
 public class CreateDiskStoreCommand extends SingleGfshCommand {
+  private static final Logger logger = LogService.getLogger();
   private static final int MBEAN_CREATION_WAIT_TIME = 10000;
 
   @CliCommand(value = CliStrings.CREATE_DISK_STORE, help = CliStrings.CREATE_DISK_STORE__HELP)
@@ -152,8 +155,21 @@ public class CreateDiskStoreCommand extends SingleGfshCommand {
 
     return poll(MBEAN_CREATION_WAIT_TIME, TimeUnit.MILLISECONDS,
         () -> membersToCreateDiskStoreOn.stream()
-            .allMatch(member -> diskStoreBeanAndMemberBeanDiskStoreExists(dsMXBean,
-                member.getName(), diskStore)));
+            .allMatch(m -> diskStoreBeanExists(dsMXBean, m.getName(), diskStore)));
+  }
+
+  private boolean diskStoreBeanExists(DistributedSystemMXBean dsMXBean, String memberName,
+      String diskStore) {
+    try {
+      dsMXBean.fetchDiskStoreObjectName(memberName, diskStore);
+      return true;
+    } catch (Exception e) {
+      if (!e.getMessage().toLowerCase().contains("not found")) {
+        logger.warn("Unable to retrieve Disk Store ObjectName for member: {}, diskstore:
{} - {}",
+            memberName, diskStore, e.getMessage());
+      }
+    }
+    return false;
   }
 
   @VisibleForTesting
@@ -202,7 +218,7 @@ public class CreateDiskStoreCommand extends SingleGfshCommand {
   }
 
   @SuppressWarnings("unchecked")
-  private List<DiskStoreDetails> getDiskStoreListing(Set<DistributedMember> members)
{
+  List<DiskStoreDetails> getDiskStoreListing(Set<DistributedMember> members)
{
     final Execution membersFunctionExecutor = getMembersFunctionExecutor(members);
     if (membersFunctionExecutor instanceof AbstractExecution) {
       ((AbstractExecution) membersFunctionExecutor).setIgnoreDepartedMembers(true);
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/CreateRegionCommand.java
b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/CreateRegionCommand.java
index 5983778..ccdedda 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/CreateRegionCommand.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/CreateRegionCommand.java
@@ -18,11 +18,12 @@ import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.List;
+import java.util.Map;
 import java.util.Set;
 import java.util.stream.Collectors;
-import java.util.stream.Stream;
 
 import joptsimple.internal.Strings;
+import org.apache.commons.lang3.ArrayUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.lang3.builder.EqualsBuilder;
 import org.springframework.shell.core.annotation.CliCommand;
@@ -315,7 +316,7 @@ public class CreateRegionCommand extends SingleGfshCommand {
           !colocatedRegionBean.getRegionType().equals("PERSISTENT_PARTITION")) {
         return ResultModel.createError(CliStrings.format(
             CliStrings.CREATE_REGION__MSG__COLOCATEDWITH_REGION_0_IS_NOT_PARTITIONEDREGION,
-            prColocatedWith));
+            (Object) prColocatedWith));
       }
     }
 
@@ -564,12 +565,12 @@ public class CreateRegionCommand extends SingleGfshCommand {
     }
 
     String[] regionsOnPath = regionPathData.getRegionsOnParentPath();
-
-    RegionConfig currentConfig = config.getRegions().stream()
-        .filter(r1 -> r1.getName().equals(regionsOnPath[0]))
+    RegionConfig rootConfig = config.getRegions().stream()
+        .filter(r -> r.getName().equals(regionsOnPath[0]))
         .findFirst()
         .get();
 
+    RegionConfig currentConfig = rootConfig;
     for (int i = 1; i < regionsOnPath.length; i++) {
       final String curRegionName = regionsOnPath[i];
       currentConfig = currentConfig.getRegions()
@@ -666,16 +667,24 @@ public class CreateRegionCommand extends SingleGfshCommand {
     DistributedSystemMXBean dsMBean = managementService.getDistributedSystemMXBean();
 
     String[] allRegionPaths = dsMBean.listAllRegionPaths();
-    return Arrays.asList(allRegionPaths).contains(regionPath);
+    return Arrays.stream(allRegionPaths).anyMatch(regionPath::equals);
   }
 
   private boolean diskStoreExists(String diskStoreName) {
     ManagementService managementService = getManagementService();
     DistributedSystemMXBean dsMXBean = managementService.getDistributedSystemMXBean();
+    Map<String, String[]> diskstore = dsMXBean.listMemberDiskstore();
+
+    Set<Map.Entry<String, String[]>> entrySet = diskstore.entrySet();
+
+    for (Map.Entry<String, String[]> entry : entrySet) {
+      String[] value = entry.getValue();
+      if (diskStoreName != null && ArrayUtils.contains(value, diskStoreName)) {
+        return true;
+      }
+    }
 
-    return Stream.of(dsMXBean.listMembers())
-        .anyMatch(memberName -> diskStoreBeanAndMemberBeanDiskStoreExists(dsMXBean, memberName,
-            diskStoreName));
+    return false;
   }
 
   DistributedSystemMXBean getDSMBean() {
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/GfshCommandJUnitTest.java
b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/GfshCommandJUnitTest.java
index 3d9e292..409e3fd 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/GfshCommandJUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/GfshCommandJUnitTest.java
@@ -14,45 +14,42 @@
  */
 package org.apache.geode.management.internal.cli.commands;
 
-import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.spy;
 
 import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.management.ObjectName;
 
 import org.junit.Before;
 import org.junit.Test;
-import org.mockito.Mockito;
 
-import org.apache.geode.management.DistributedSystemMXBean;
+import org.apache.geode.distributed.internal.InternalConfigurationPersistenceService;
 import org.apache.geode.management.cli.GfshCommand;
+import org.apache.geode.management.internal.cli.shell.Gfsh;
 import org.apache.geode.management.internal.exceptions.EntityNotFoundException;
 
 public class GfshCommandJUnitTest {
-  private String memberName = "memberONe";
-  private String diskStoreName = "diskStoreOne";
+
   private GfshCommand command;
+  private Gfsh gfsh;
+  private InternalConfigurationPersistenceService clusterConfigurationService;
 
   @Before
   public void before() throws Exception {
     command = spy(GfshCommand.class);
+    gfsh = mock(Gfsh.class);
+    clusterConfigurationService = mock(InternalConfigurationPersistenceService.class);
   }
 
   @Test
-  public void getMember() {
+  public void getMember() throws Exception {
     doReturn(null).when(command).findMember("test");
     assertThatThrownBy(() -> command.getMember("test")).isInstanceOf(EntityNotFoundException.class);
   }
 
   @Test
-  public void getMembers() {
+  public void getMembers() throws Exception {
     String[] members = {"member"};
     doReturn(Collections.emptySet()).when(command).findMembers(members, null);
     assertThatThrownBy(() -> command.getMembers(members, null))
@@ -60,52 +57,10 @@ public class GfshCommandJUnitTest {
   }
 
   @Test
-  public void getMembersIncludingLocators() {
+  public void getMembersIncludingLocators() throws Exception {
     String[] members = {"member"};
     doReturn(Collections.emptySet()).when(command).findMembersIncludingLocators(members,
null);
     assertThatThrownBy(() -> command.getMembersIncludingLocators(members, null))
         .isInstanceOf(EntityNotFoundException.class);
   }
-
-  @Test
-  public void diskStoreBeanAndMemberBeanDiskStoreExists() throws Exception {
-    Map<String, String[]> memberDiskStore = new HashMap<>();
-    memberDiskStore.put(memberName, new String[] {diskStoreName});
-    ObjectName objectName = new ObjectName("");
-
-    DistributedSystemMXBean distributedSystemMXBean = Mockito.mock(DistributedSystemMXBean.class);
-    doReturn(memberDiskStore).when(distributedSystemMXBean).listMemberDiskstore();
-    doReturn(objectName).when(distributedSystemMXBean).fetchDiskStoreObjectName(any(), any());
-
-    assertThat(command.diskStoreBeanAndMemberBeanDiskStoreExists(distributedSystemMXBean,
-        memberName, diskStoreName)).isTrue();
-  }
-
-  @Test
-  public void diskStoreBeanExistsAndMemberDiskStoreNotFound() throws Exception {
-    Map<String, String[]> memberDiskStore = new HashMap<>();
-    memberDiskStore.put(memberName, new String[] {});
-    ObjectName objectName = new ObjectName("");
-
-    DistributedSystemMXBean distributedSystemMXBean = Mockito.mock(DistributedSystemMXBean.class);
-    doReturn(memberDiskStore).when(distributedSystemMXBean).listMemberDiskstore();
-    doReturn(objectName).when(distributedSystemMXBean).fetchDiskStoreObjectName(any(), any());
-
-    assertThat(command.diskStoreBeanAndMemberBeanDiskStoreExists(distributedSystemMXBean,
-        memberName, diskStoreName)).isFalse();
-  }
-
-  @Test
-  public void diskStoreBeanNotFoundAndMemberDiskStoreExists() throws Exception {
-    Map<String, String[]> memberDiskStore = new HashMap<>();
-    memberDiskStore.put(memberName, new String[] {diskStoreName});
-
-    DistributedSystemMXBean distributedSystemMXBean = Mockito.mock(DistributedSystemMXBean.class);
-    doReturn(memberDiskStore).when(distributedSystemMXBean).listMemberDiskstore();
-    doThrow(new Exception("not found")).when(distributedSystemMXBean)
-        .fetchDiskStoreObjectName(any(), any());
-
-    assertThat(command.diskStoreBeanAndMemberBeanDiskStoreExists(distributedSystemMXBean,
-        memberName, diskStoreName)).isFalse();
-  }
 }


Mime
View raw message