@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);
  }
Beispiel #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");
    }
  }
  /**
   * Invokes AdminDistributedSystem.shutDownAllMembers() which disconnects all members but leaves
   * the vms up (because hydra threads remain) including the possibility of this vm being
   * disconnected, then this actually stops those vms (except this vm if it was targeted in the
   * shutDownAllMembers...this vm will remain up but disconnect). Stopped vms are stopped with
   * ON_DEMAND restart. This returns when the vms disconnected by shutDownAllMembers() (other than
   * this one) are all stopped .
   *
   * @param adminDS The admin distributed system instance to use to call shutdownAllMembers.
   * @param stopModes The stop modes to choose from.
   * @return An Array [0] List of {@link ClientVmInfo} instances describing the VMs that were
   *     stopped. [1] Set, the return from shutdownAllMembers()
   * @throws AdminException if the shutDownAllMembers call throws this exception.
   */
  public static Object[] shutDownAllMembers(
      AdminDistributedSystem adminDS, List<String> stopModes) {
    if (adminDS == null) {
      throw new HydraRuntimeException("AdminDistributedSystem cannot be null");
    }

    // Invoke shutDownAllMembers
    Log.getLogWriter().info("AdminDS " + adminDS + " is shutting down all members...");
    Set<DistributedMember> memberSet;
    try {
      long startTime = System.currentTimeMillis();
      memberSet = adminDS.shutDownAllMembers();
      long duration = System.currentTimeMillis() - startTime;
      Log.getLogWriter()
          .info(
              "AdminDS "
                  + adminDS
                  + " shut down (disconnected) the following members "
                  + "(vms remain up): "
                  + memberSet
                  + "; shutDownAll duration "
                  + duration
                  + "ms");
    } catch (AdminException e1) {
      throw new TestException(TestHelper.getStackTrace(e1));
    }

    // Now actually stop the vms.
    // First get the ClientVmInfos for the members that shutDownAllMembers
    // disconnected.
    List<ClientVmInfo> allClientInfos = new ArrayList(); // all members that were shutdown
    List<ClientVmInfo> allOtherClientInfos =
        new ArrayList(); // all members that were shutdown except this member
    ClientVmInfo thisClientInfo =
        null; // this member, or will remain null if this member was not shutdown
    List<String> stopModesToUse = new ArrayList();
    for (DistributedMember aMember : memberSet) {
      Integer vmId = null;
      try {
        vmId =
            new Integer(RemoteTestModule.Master.getVmid(aMember.getHost(), aMember.getProcessId()));
      } catch (java.rmi.RemoteException e) {
        throw new HydraRuntimeException("Unable to get vmID for " + aMember + ": " + e);
      }
      ClientVmInfo infoFromBB =
          (ClientVmInfo) StopStartBB.getBB().getSharedMap().get("StopStartVMInfo_for_vmid_" + vmId);
      String clientName = null;
      if (infoFromBB != null) {
        clientName = infoFromBB.getClientName();
      }
      ClientVmInfo info = new ClientVmInfo(vmId, clientName, null);
      allClientInfos.add(info);
      if (vmId == RemoteTestModule.getMyVmid()) {
        // shutdownAll disconnected this vm
        thisClientInfo = info;
      } else { // aMember is not the current vm
        allOtherClientInfos.add(info);
      }
      stopModesToUse.add(
          stopModes.get(TestConfig.tab().getRandGen().nextInt(0, stopModes.size() - 1)));
    }

    // now actually stop the vms; if this vm is included, do it last
    Object[] returnArr = new Object[2];
    if (thisClientInfo == null) { // shutDownAllMembers did not disconnect this vm
      // we can just stop all of them now and this vm lives on
      StopStartVMs.stopVMs(allClientInfos, stopModesToUse); // restart is ON_DEMAND
      returnArr[0] = allClientInfos;
    } else { // this vm was disconnected by shutDownAllMembers
      // first shutdown all other members except this one
      StopStartVMs.stopVMs(allOtherClientInfos, stopModesToUse.subList(0, stopModesToUse.size()));
      returnArr[0] = allOtherClientInfos;
    }
    returnArr[1] = memberSet;
    return returnArr;
  }