@Override
  public void execute(FunctionContext context) {
    StringBuilder str1 = new StringBuilder();
    Map<String, String> resultMap = null;
    try {
      Cache cache = CacheFactory.getAnyInstance();
      DistributedMember member = cache.getDistributedSystem().getDistributedMember();
      long freeMemoeryBeforeGC = Runtime.getRuntime().freeMemory();
      long totalMemoryBeforeGC = Runtime.getRuntime().totalMemory();
      long timeBeforeGC = System.currentTimeMillis();
      Runtime.getRuntime().gc();

      long freeMemoeryAfterGC = Runtime.getRuntime().freeMemory();
      long totalMemoryAfterGC = Runtime.getRuntime().totalMemory();
      long timeAfterGC = System.currentTimeMillis();

      long megaBytes = 131072;
      resultMap = new HashMap<String, String>();
      resultMap.put("MemberId", member.getId());
      resultMap.put(
          "HeapSizeBeforeGC",
          String.valueOf((totalMemoryBeforeGC - freeMemoeryBeforeGC) / megaBytes));
      resultMap.put(
          "HeapSizeAfterGC", String.valueOf((totalMemoryAfterGC - freeMemoeryAfterGC) / megaBytes));
      resultMap.put("TimeSpentInGC", String.valueOf(timeAfterGC - timeBeforeGC));
    } catch (Exception ex) {
      str1.append(
          "Exception in GC:" + ex.getMessage() + CliUtil.stackTraceAsString((Throwable) ex));
      context.getResultSender().lastResult(str1.toString());
    }
    context.getResultSender().lastResult(resultMap);
  }
Example #2
0
 @Override
 public ArrayList<HashMap> doExecute(Map<String, Object> args) {
   Cache cache = CacheFactory.getAnyInstance();
   String regionPath = (String) args.get(ApiConstant.REGIONPATH);
   Region region = cache.getRegion(regionPath);
   ArrayList<HashMap> list = new ArrayList<HashMap>();
   if (region != null && region instanceof PartitionedRegion) {
     DistributedMember member = cache.getDistributedSystem().getDistributedMember();
     PartitionedRegion pr = (PartitionedRegion) region;
     if (pr.getDataStore() != null) {
       Set<BucketRegion> set2 = pr.getDataStore().getAllLocalBucketRegions();
       for (BucketRegion br : set2) {
         HashMap map = new HashMap();
         map.put("BucketId", br.getId());
         map.put("Size", br.size());
         map.put("Bytes", br.getTotalBytes());
         map.put("host", getHost());
         map.put("node", System.getProperty("NODE_NAME"));
         InternalDistributedMember m = pr.getBucketPrimary(br.getId());
         if (m != null && member.getId().equals(m.getId())) {
           map.put("type", "primary");
         } else {
           map.put("type", "redundant");
         }
         map.put("TotalNumBuckets", pr.getPartitionAttributes().getTotalNumBuckets());
         list.add(map);
       }
     }
   }
   return list;
 }
  @Override
  public void execute(FunctionContext context) {
    InternalLocator locator = InternalLocator.getLocator();
    GemFireCacheImpl cache = GemFireCacheImpl.getInstance();
    DistributedMember member = cache.getDistributedSystem().getDistributedMember();
    SharedConfigurationStatus status = locator.getSharedConfigurationStatus().getStatus();

    String memberId = member.getName();
    if (StringUtils.isBlank(memberId)) {
      memberId = member.getId();
    }

    CliFunctionResult result = new CliFunctionResult(memberId, new String[] {status.name()});
    context.getResultSender().lastResult(result);
  }
  /** test to validate that the start gateway sender starts the gateway sender on a member */
  public void testStopGatewayReceiver_onMember() {

    VM puneLocator = Host.getLocator();
    int punePort = (Integer) puneLocator.invoke(WANCommandTestBase.class, "getLocatorPort");

    Properties props = new Properties();
    props.setProperty(DistributionConfig.MCAST_PORT_NAME, "0");
    props.setProperty(DistributionConfig.LOCATORS_NAME, "localhost[" + punePort + "]");
    createDefaultSetup(props);

    Integer nyPort =
        (Integer)
            vm2.invoke(
                WANCommandTestBase.class, "createFirstRemoteLocator", new Object[] {2, punePort});

    vm3.invoke(WANCommandTestBase.class, "createAndStartReceiver", new Object[] {punePort});
    vm4.invoke(WANCommandTestBase.class, "createAndStartReceiver", new Object[] {punePort});
    vm5.invoke(WANCommandTestBase.class, "createAndStartReceiver", new Object[] {punePort});

    vm3.invoke(WANCommandTestBase.class, "verifyReceiverState", new Object[] {true});
    vm4.invoke(WANCommandTestBase.class, "verifyReceiverState", new Object[] {true});
    vm5.invoke(WANCommandTestBase.class, "verifyReceiverState", new Object[] {true});

    final DistributedMember vm1Member =
        (DistributedMember) vm3.invoke(WANCommandTestBase.class, "getMember");
    pause(10000);
    String command =
        CliStrings.STOP_GATEWAYRECEIVER
            + " --"
            + CliStrings.STOP_GATEWAYRECEIVER__MEMBER
            + "="
            + vm1Member.getId();

    CommandResult cmdResult = executeCommand(command);
    if (cmdResult != null) {
      String strCmdResult = commandResultToString(cmdResult);
      Log.getLogWriter()
          .info("testStopGatewayReceiver_onMember stringResult : " + strCmdResult + ">>>>");
      assertEquals(Result.Status.OK, cmdResult.getStatus());
      assertTrue(strCmdResult.contains("stopped on member"));
    } else {
      fail("testStopGatewayReceiver failed as did not get CommandResult");
    }

    vm3.invoke(WANCommandTestBase.class, "verifyReceiverState", new Object[] {false});
    vm4.invoke(WANCommandTestBase.class, "verifyReceiverState", new Object[] {true});
    vm5.invoke(WANCommandTestBase.class, "verifyReceiverState", new Object[] {true});
  }
  /**
   * Test wan commands for error in input 1> start gateway-sender command needs only one of member
   * or group.
   */
  public void testStopGatewayReceiver_ErrorConditions() {

    VM puneLocator = Host.getLocator();
    int punePort = (Integer) puneLocator.invoke(WANCommandTestBase.class, "getLocatorPort");

    Properties props = new Properties();
    props.setProperty(DistributionConfig.MCAST_PORT_NAME, "0");
    props.setProperty(DistributionConfig.LOCATORS_NAME, "localhost[" + punePort + "]");
    createDefaultSetup(props);

    Integer nyPort =
        (Integer)
            vm2.invoke(
                WANCommandTestBase.class, "createFirstRemoteLocator", new Object[] {2, punePort});

    vm3.invoke(WANCommandTestBase.class, "createReceiver", new Object[] {punePort});

    final DistributedMember vm1Member =
        (DistributedMember) vm3.invoke(WANCommandTestBase.class, "getMember");

    String command =
        CliStrings.STOP_GATEWAYRECEIVER
            + " --"
            + CliStrings.STOP_GATEWAYRECEIVER__MEMBER
            + "="
            + vm1Member.getId()
            + " --"
            + CliStrings.STOP_GATEWAYRECEIVER__GROUP
            + "=RG1";

    CommandResult cmdResult = executeCommand(command);
    if (cmdResult != null) {
      String strCmdResult = commandResultToString(cmdResult);
      Log.getLogWriter()
          .info("testStopGatewayReceiver_ErrorConditions stringResult : " + strCmdResult + ">>>>");
      assertEquals(Result.Status.ERROR, cmdResult.getStatus());
      assertTrue(strCmdResult.contains(CliStrings.PROVIDE_EITHER_MEMBER_OR_GROUP_MESSAGE));
    } else {
      fail("testStopGatewayReceiver_ErrorConditions failed as did not get CommandResult");
    }
  }