Search in sources :

Example 1 with BytesToString

use of org.apache.geode.management.internal.cli.util.BytesToString in project geode by apache.

the class ExportLogsCommand method checkIfExportLogsOverflowsDisk.

/**
   * @throws ManagementException if export file size checking is enabled (fileSizeLimit > 0) and the
   *         space required on a cluster member to filter and zip up files to be exported exceeds
   *         the disk space available
   */
void checkIfExportLogsOverflowsDisk(String memberName, long fileSizeLimitBytes, long estimatedSize, long diskAvailable) {
    if (fileSizeLimitBytes > 0) {
        StringBuilder sb = new StringBuilder();
        BytesToString bytesToString = new BytesToString();
        if (estimatedSize > diskAvailable) {
            sb.append("Estimated disk space required (").append(bytesToString.of(estimatedSize)).append(") to consolidate logs on member ").append(memberName).append(" will exceed available disk space (").append(bytesToString.of(diskAvailable)).append(")");
            // FileTooBigException
            throw new ManagementException(sb.toString());
        }
    }
}
Also used : ManagementException(org.apache.geode.management.ManagementException) BytesToString(org.apache.geode.management.internal.cli.util.BytesToString)

Example 2 with BytesToString

use of org.apache.geode.management.internal.cli.util.BytesToString in project geode by apache.

the class GarbageCollectionFunction method execute.

@Override
public void execute(FunctionContext context) {
    BytesToString bytesToString = new BytesToString();
    Map<String, String> resultMap = null;
    try {
        Cache cache = CacheFactory.getAnyInstance();
        DistributedMember member = cache.getDistributedSystem().getDistributedMember();
        long freeMemoryBeforeGC = Runtime.getRuntime().freeMemory();
        long totalMemoryBeforeGC = Runtime.getRuntime().totalMemory();
        long timeBeforeGC = System.currentTimeMillis();
        Runtime.getRuntime().gc();
        long freeMemoryAfterGC = Runtime.getRuntime().freeMemory();
        long totalMemoryAfterGC = Runtime.getRuntime().totalMemory();
        long timeAfterGC = System.currentTimeMillis();
        resultMap = new HashMap<>();
        resultMap.put("MemberId", member.getId());
        resultMap.put("HeapSizeBeforeGC", bytesToString.of(totalMemoryBeforeGC - freeMemoryBeforeGC));
        resultMap.put("HeapSizeAfterGC", bytesToString.of(totalMemoryAfterGC - freeMemoryAfterGC));
        resultMap.put("TimeSpentInGC", String.valueOf(timeAfterGC - timeBeforeGC));
    } catch (Exception ex) {
        String message = "Exception in GC:" + ex.getMessage() + CliUtil.stackTraceAsString(ex);
        context.getResultSender().lastResult(message);
    }
    context.getResultSender().lastResult(resultMap);
}
Also used : DistributedMember(org.apache.geode.distributed.DistributedMember) BytesToString(org.apache.geode.management.internal.cli.util.BytesToString) BytesToString(org.apache.geode.management.internal.cli.util.BytesToString) Cache(org.apache.geode.cache.Cache)

Example 3 with BytesToString

use of org.apache.geode.management.internal.cli.util.BytesToString in project geode by apache.

the class SizeExportLogsFunction method execute.

@Override
public void execute(final FunctionContext context) {
    try {
        InternalCache cache = GemFireCacheImpl.getInstance();
        DistributionConfig config = cache.getInternalDistributedSystem().getConfig();
        Args args = (Args) context.getArguments();
        long diskAvailable = getDiskAvailable(config);
        long estimatedSize = estimateLogFileSize(cache.getMyId(), config.getLogFile(), config.getStatisticArchiveFile(), args);
        BytesToString bytesToString = new BytesToString();
        if (estimatedSize == 0 || estimatedSize < diskAvailable) {
            context.getResultSender().lastResult(Arrays.asList(estimatedSize));
        } else {
            StringBuilder sb = new StringBuilder().append("Estimated disk space required (").append(bytesToString.of(estimatedSize)).append(") to consolidate logs on member ").append(cache.getName()).append(" will exceed available disk space (").append(bytesToString.of(diskAvailable)).append(")");
            // FileTooBigException
            context.getResultSender().sendException(new ManagementException(sb.toString()));
        }
    } catch (Exception e) {
        e.printStackTrace();
        LOGGER.error(e.getMessage());
        context.getResultSender().sendException(e);
    }
}
Also used : DistributionConfig(org.apache.geode.distributed.internal.DistributionConfig) ManagementException(org.apache.geode.management.ManagementException) InternalCache(org.apache.geode.internal.cache.InternalCache) IOException(java.io.IOException) ManagementException(org.apache.geode.management.ManagementException) BytesToString(org.apache.geode.management.internal.cli.util.BytesToString)

Aggregations

BytesToString (org.apache.geode.management.internal.cli.util.BytesToString)3 ManagementException (org.apache.geode.management.ManagementException)2 IOException (java.io.IOException)1 Cache (org.apache.geode.cache.Cache)1 DistributedMember (org.apache.geode.distributed.DistributedMember)1 DistributionConfig (org.apache.geode.distributed.internal.DistributionConfig)1 InternalCache (org.apache.geode.internal.cache.InternalCache)1