Java Code Examples for org.apache.commons.collections.MapUtils#getLongValue()

The following examples show how to use org.apache.commons.collections.MapUtils#getLongValue() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RedisCenterImpl.java    From cachecloud with Apache License 2.0 6 votes vote down vote up
@Override
public Map<String, Long> getInstanceSlowLogCountMapByAppId(Long appId, Date startDate, Date endDate) {
    try {
        List<Map<String, Object>> list = instanceSlowLogDao.getInstanceSlowLogCountMapByAppId(appId, startDate, endDate);
        if (CollectionUtils.isEmpty(list)) {
            return Collections.emptyMap();
        }
        Map<String, Long> resultMap = new LinkedHashMap<String, Long>();
        for (Map<String, Object> map : list) {
            long count = MapUtils.getLongValue(map, "count");
            String hostPort = MapUtils.getString(map, "hostPort");
            if (StringUtils.isNotBlank(hostPort)) {
                resultMap.put(hostPort, count);
            }
        }
        return resultMap;
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        return Collections.emptyMap();
    }
}
 
Example 2
Source File: RedisCenterImpl.java    From cachecloud with Apache License 2.0 5 votes vote down vote up
private Long getCommonCount(Map<?, ?> infoMap, RedisConstant redisConstant, String commond) {
    Object constantObject =
            infoMap.get(redisConstant) == null ? infoMap.get(redisConstant.getValue()) : infoMap.get(redisConstant);
    if (constantObject != null && (constantObject instanceof Map)) {
        Map constantMap = (Map) constantObject;
        if (constantMap == null || constantMap.get(commond) == null) {
            return null;
        }
        return MapUtils.getLongValue(constantMap, commond);
    }
    return null;
}
 
Example 3
Source File: S3MapReduceCpOptionsParser.java    From circus-train with Apache License 2.0 4 votes vote down vote up
protected S3MapReduceCpOptions parse(Map<String, Object> copierOptions) {
  if (copierOptions == null) {
    LOG.debug("Null copier options: nothing to parse");
    return optionsBuilder.build();
  }

  optionsBuilder
      .credentialsProvider(MoreMapUtils.getUri(copierOptions, CREDENTIAL_PROVIDER, defaultCredentialsProvider));

  long multipartUploadPartSize = MapUtils.getLongValue(copierOptions, MULTIPART_UPLOAD_CHUNK_SIZE,
      ConfigurationVariable.MULTIPART_UPLOAD_THRESHOLD.defaultLongValue());
  if (multipartUploadPartSize <= 0) {
    throw new IllegalArgumentException("Parameter " + MULTIPART_UPLOAD_CHUNK_SIZE + " must be greater than zero");
  }
  optionsBuilder.multipartUploadPartSize(multipartUploadPartSize);

  optionsBuilder.s3ServerSideEncryption(MapUtils.getBoolean(copierOptions, S3_SERVER_SIDE_ENCRYPTION, true));

  optionsBuilder.storageClass(
      MapUtils.getString(copierOptions, STORAGE_CLASS, ConfigurationVariable.STORAGE_CLASS.defaultValue()));

  long maxBandwidth = MapUtils.getLongValue(copierOptions, TASK_BANDWIDTH,
      ConfigurationVariable.MAX_BANDWIDTH.defaultLongValue());
  if (maxBandwidth <= 0) {
    throw new IllegalArgumentException(
        "Parameter " + TASK_BANDWIDTH + " must be a positive number greater then zero");
  }
  optionsBuilder.maxBandwidth(maxBandwidth);

  int numberOfUploadWorkers = MapUtils.getIntValue(copierOptions, NUMBER_OF_WORKERS_PER_MAP,
      ConfigurationVariable.NUMBER_OF_UPLOAD_WORKERS.defaultIntValue());
  if (numberOfUploadWorkers <= 0) {
    throw new IllegalArgumentException(
        "Parameter " + NUMBER_OF_WORKERS_PER_MAP + " must be a positive number greater than zero");
  }
  optionsBuilder.numberOfUploadWorkers(numberOfUploadWorkers);

  long multipartUploadThreshold = MapUtils.getLongValue(copierOptions, MULTIPART_UPLOAD_THRESHOLD,
      ConfigurationVariable.MULTIPART_UPLOAD_THRESHOLD.defaultLongValue());
  if (multipartUploadThreshold <= 0) {
    throw new IllegalArgumentException("Parameter " + MULTIPART_UPLOAD_THRESHOLD + " must be greater than zero");
  }
  optionsBuilder.multipartUploadThreshold(multipartUploadThreshold);

  int maxMaps = MapUtils.getIntValue(copierOptions, MAX_MAPS, ConfigurationVariable.MAX_MAPS.defaultIntValue());
  if (maxMaps <= 0) {
    throw new IllegalArgumentException("Parameter " + MAX_MAPS + " must be a positive number greater than zero");
  }
  optionsBuilder.maxMaps(maxMaps);

  optionsBuilder.copyStrategy(
      MapUtils.getString(copierOptions, COPY_STRATEGY, ConfigurationVariable.COPY_STRATEGY.defaultValue()));

  Path logPath = MoreMapUtils.getHadoopPath(copierOptions, LOG_PATH, null);
  if (logPath != null) {
    optionsBuilder.logPath(logPath);
  }

  optionsBuilder.region(MapUtils.getString(copierOptions, REGION, ConfigurationVariable.REGION.defaultValue()));

  optionsBuilder.ignoreFailures(MapUtils.getBoolean(copierOptions, IGNORE_FAILURES,
      ConfigurationVariable.IGNORE_FAILURES.defaultBooleanValue()));

  optionsBuilder.s3EndpointUri(
      MoreMapUtils.getUri(copierOptions, S3_ENDPOINT_URI, ConfigurationVariable.S3_ENDPOINT_URI.defaultURIValue()));

  int uploadRetryCount = MapUtils.getInteger(copierOptions, UPLOAD_RETRY_COUNT,
      ConfigurationVariable.UPLOAD_RETRY_COUNT.defaultIntValue());
  if (uploadRetryCount < 0) {
    throw new IllegalArgumentException("Parameter " + UPLOAD_RETRY_COUNT + " must be a positive number");
  }
  optionsBuilder.uploadRetryCount(uploadRetryCount);

  long uploadRetryDelaysMs = MapUtils.getLong(copierOptions, UPLOAD_RETRY_DELAY_MS,
      ConfigurationVariable.UPLOAD_RETRY_DELAY_MS.defaultLongValue());
  optionsBuilder.uploadRetryDelayMs(uploadRetryDelaysMs);
  if (uploadRetryDelaysMs < 0) {
    throw new IllegalArgumentException("Parameter " + UPLOAD_RETRY_DELAY_MS + " must be a positive number");
  }

  int uploadBufferSize = MapUtils.getInteger(copierOptions, UPLOAD_BUFFER_SIZE,
      ConfigurationVariable.UPLOAD_BUFFER_SIZE.defaultIntValue());
  if (uploadBufferSize < 0) {
    throw new IllegalArgumentException("Parameter " + UPLOAD_BUFFER_SIZE + " must be a positive number");
  }
  optionsBuilder.uploadBufferSize(uploadBufferSize);

  optionsBuilder.cannedAcl(MapUtils.getString(copierOptions, CANNED_ACL, ConfigurationVariable.CANNED_ACL.defaultValue()));

  optionsBuilder.assumeRole(MapUtils.getString(copierOptions, ASSUME_ROLE, ConfigurationVariable.ASSUME_ROLE.defaultValue()));

  return optionsBuilder.build();
}
 
Example 4
Source File: RedisIsolationPersistenceInspector.java    From cachecloud with Apache License 2.0 4 votes vote down vote up
@Override
public boolean inspect(Map<InspectParamEnum, Object> paramMap) {
    final String host = MapUtils.getString(paramMap, InspectParamEnum.SPLIT_KEY);
    List<InstanceInfo> list = (List<InstanceInfo>) paramMap.get(InspectParamEnum.INSTANCE_LIST);
    outer:
    for (InstanceInfo info : list) {
        final int port = info.getPort();
        final int type = info.getType();
        final long appId = info.getAppId();
        int status = info.getStatus();
        //非正常节点
        if (status != InstanceStatusEnum.GOOD_STATUS.getStatus()) {
            continue;
        }
        if (TypeUtil.isRedisDataType(type)) {
            Jedis jedis = redisCenter.getJedis(appId, host, port, REDIS_DEFAULT_TIME, REDIS_DEFAULT_TIME);
            try {
                Map<String, String> persistenceMap = parseMap(jedis);
                if (persistenceMap.isEmpty()) {
                    logger.error("{}:{} get persistenceMap failed", host, port);
                    continue;
                }
                if (!isAofEnabled(persistenceMap)) {
                    continue;
                }
                long aofCurrentSize = MapUtils.getLongValue(persistenceMap, RedisInfoEnum.aof_current_size.getValue());
                long aofBaseSize = MapUtils.getLongValue(persistenceMap, RedisInfoEnum.aof_base_size.getValue());
                //阀值大于60%
                long aofThresholdSize = (long) (aofBaseSize * 1.6);
                double percentage = getPercentage(aofCurrentSize, aofBaseSize);
                if (aofCurrentSize >= aofThresholdSize
                        //大于64Mb
                        && aofCurrentSize > (64 * 1024 * 1024)) {
                    //bgRewriteAof
                    boolean isInvoke = invokeBgRewriteAof(jedis);
                    if (!isInvoke) {
                        logger.error("{}:{} invokeBgRewriteAof failed", host, port);
                        continue;
                    } else {
                        logger.warn("{}:{} invokeBgRewriteAof started percentage={}", host, port, percentage);
                    }
                    while (true) {
                        try {
                            //before wait 1s
                            TimeUnit.SECONDS.sleep(1);
                            Map<String, String> loopMap = parseMap(jedis);
                            Integer aofRewriteInProgress = MapUtils.getInteger(loopMap, "aof_rewrite_in_progress", null);
                            if (aofRewriteInProgress == null) {
                                logger.error("loop watch:{}:{} return failed", host, port);
                                break;
                            } else if (aofRewriteInProgress <= 0) {
                                //bgrewriteaof Done
                                logger.warn("{}:{} bgrewriteaof Done lastSize:{}Mb,currentSize:{}Mb", host, port, getMb(aofCurrentSize), getMb(MapUtils.getLongValue(loopMap, "aof_current_size")));
                                break;
                            } else {
                                //wait 1s
                                TimeUnit.SECONDS.sleep(1);
                            }
                        } catch (Exception e) {
                            logger.error(e.getMessage(), e);
                        }
                    }
                } else {
                    if (percentage > 50D) {
                        long currentSize = getMb(aofCurrentSize);
                        logger.info("checked {}:{} aof increase percentage:{}% currentSize:{}Mb", host, port, percentage, currentSize > 0 ? currentSize : "<1");
                    }
                }
            } finally {
                jedis.close();
            }
        }
    }
    return true;
}