Java Code Examples for org.apache.commons.collections4.MapUtils#getLong()

The following examples show how to use org.apache.commons.collections4.MapUtils#getLong() . 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: CommitLagLimiter.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
public void acquire(ConsumeOffsetTracker tracker, String topic, ConsumeContext context) throws InterruptedException {
    long maxCommitLag = MapUtils.getLong(maxCommitLagMap, topic, -1L);
    if (maxCommitLag < 0) {
        return;
    }
    long lag = tracker.getCommitLag(topic, context);
    if (lag < maxCommitLag) {
        return;
    }

    commitLagLock.lock();
    try {
        while ((lag = tracker.getCommitLag(topic, context)) >= maxCommitLag) {
            LOGGER.warn("commit lag is over maxLag, block consuming...group={},topic={},qid={},lag={}",
                    context.getGroupId(), topic, context.getQid(), lag);
            getCondition(topic, context).await();
        }
    } finally {
        commitLagLock.unlock();
    }
}
 
Example 2
Source File: JiraContentFormatter.java    From incubator-pinot with Apache License 2.0 6 votes vote down vote up
/**
 * Apply the parameter map to given jira template, and format it as JiraEntity
 */
private JiraEntity buildJiraEntity(String jiraTemplate, Map<String, Object> templateValues,
    Multimap<String, String> dimensionFilters) {
  String jiraProject = MapUtils.getString(alertClientConfig, PROP_PROJECT, this.jiraAdminConfig.getJiraDefaultProjectKey());
  Long jiraIssueTypeId = MapUtils.getLong(alertClientConfig, PROP_ISSUE_TYPE, this.jiraAdminConfig.getJiraIssueTypeId());

  JiraEntity jiraEntity = new JiraEntity(jiraProject, jiraIssueTypeId, buildSummary(templateValues, dimensionFilters));
  jiraEntity.setAssignee(MapUtils.getString(alertClientConfig, PROP_ASSIGNEE, "")); // Default - Unassigned
  jiraEntity.setMergeGap(MapUtils.getLong(alertClientConfig, PROP_MERGE_GAP, -1L)); // Default - Always merge
  jiraEntity.setLabels(buildLabels(dimensionFilters));
  jiraEntity.setDescription(buildDescription(jiraTemplate, templateValues));
  jiraEntity.setComponents(ConfigUtils.getList(alertClientConfig.get(PROP_COMPONENTS)));
  jiraEntity.setSnapshot(buildSnapshot());
  Map<String, Object> customFieldsMap = ConfigUtils.getMap(alertClientConfig.get(PROP_CUSTOM));
  jiraEntity.setCustomFieldsMap(customFieldsMap);

  return jiraEntity;
}
 
Example 3
Source File: InstanceStatsCenterImpl.java    From cachecloud with Apache License 2.0 6 votes vote down vote up
@Override
public boolean saveStandardStats(Map<String, Object> infoMap, Map<String, Object> clusterInfoMap, String ip, int port, String dbType) {
    Assert.isTrue(infoMap != null && infoMap.size() > 0);
    Assert.isTrue(StringUtils.isNotBlank(ip));
    Assert.isTrue(port > 0);
    Assert.isTrue(infoMap.containsKey(ConstUtils.COLLECT_TIME), ConstUtils.COLLECT_TIME + " not in infoMap");
    long collectTime = MapUtils.getLong(infoMap, ConstUtils.COLLECT_TIME);
    StandardStats ss = new StandardStats();
    ss.setCollectTime(collectTime);
    ss.setIp(ip);
    ss.setPort(port);
    ss.setDbType(dbType);
    if (infoMap.containsKey(RedisConstant.DIFF.getValue())) {
        Map<String, Object> diffMap = (Map<String, Object>) infoMap.get(RedisConstant.DIFF.getValue());
        ss.setDiffMap(diffMap);
        infoMap.remove(RedisConstant.DIFF.getValue());
    } else {
        ss.setDiffMap(new HashMap<String, Object>(0));
    }
    ss.setInfoMap(infoMap);
    ss.setClusterInfoMap(clusterInfoMap);

    int mergeCount = instanceStatsDao.mergeStandardStats(ss);
    return mergeCount > 0;
}
 
Example 4
Source File: InstanceStatsCenterImpl.java    From cachecloud with Apache License 2.0 6 votes vote down vote up
private InstanceCommandStats parseCommand(long instanceId, String command,
        Map<String, Object> commandMap, boolean isCommand, int type) {
    Long collectTime = MapUtils.getLong(commandMap, ConstUtils.COLLECT_TIME, null);
    if (collectTime == null) {
        return null;
    }
    Long count;
    if (isCommand) {
        count = MapUtils.getLong(commandMap, "cmdstat_" + command.toLowerCase(), null);
    } else {
        count = MapUtils.getLong(commandMap, command.toLowerCase(), null);
    }
    if (count == null) {
        return null;
    }
    InstanceCommandStats stats = new InstanceCommandStats();
    stats.setCommandCount(count);
    stats.setCommandName(command);
    stats.setCollectTime(collectTime);
    stats.setCreateTime(DateUtil.getDateByFormat(String.valueOf(collectTime), "yyyyMMddHHmm"));
    stats.setModifyTime(DateUtil.getDateByFormat(String.valueOf(collectTime), "yyyyMMddHHmm"));
    stats.setInstanceId(instanceId);

    return stats;
}
 
Example 5
Source File: SysUserController.java    From open-capacity-platform with Apache License 2.0 6 votes vote down vote up
/**
 *  修改用户状态
 * @param params
 * @return
 * @author gitgeek
 */
@ApiOperation(value = "修改用户状态")
@GetMapping("/users/updateEnabled")
@ApiImplicitParams({
        @ApiImplicitParam(name = "id", value = "用户id", required = true, dataType = "Integer"),
        @ApiImplicitParam(name = "enabled",value = "是否启用", required = true, dataType = "Boolean")
})
@LogAnnotation(module="user-center",recordRequestParam=false)
@PreAuthorize("hasAnyAuthority('user:get/users/updateEnabled' ,'user:put/users/me')")
public Result updateEnabled(@RequestParam Map<String, Object> params){
    Long id = MapUtils.getLong(params, "id");
    if (id == 1L){
        return Result.failed("超级管理员不给予修改");
    }
    return appUserService.updateEnabled(params);
}
 
Example 6
Source File: CommitLagLimiter.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
public void acquire(ConsumeOffsetTracker tracker, String topic, ConsumeContext context) throws InterruptedException {
    long maxCommitLag = MapUtils.getLong(maxCommitLagMap, topic, -1L);
    if (maxCommitLag < 0) {
        return;
    }
    long lag = tracker.getCommitLag(topic, context);
    if (lag < maxCommitLag) {
        return;
    }

    commitLagLock.lock();
    try {
        while ((lag = tracker.getCommitLag(topic, context)) >= maxCommitLag) {
            LOGGER.warn("commit lag is over maxLag, block consuming...group={},topic={},qid={},lag={}",
                    context.getGroupId(), topic, context.getQid(), lag);
            getCondition(topic, context).await();
        }
    } finally {
        commitLagLock.unlock();
    }
}
 
Example 7
Source File: SysUserServiceImpl.java    From microservices-platform with Apache License 2.0 6 votes vote down vote up
@Override
public Result updateEnabled(Map<String, Object> params) {
    Long id = MapUtils.getLong(params, "id");
    Boolean enabled = MapUtils.getBoolean(params, "enabled");

    SysUser appUser = baseMapper.selectById(id);
    if (appUser == null) {
        return Result.failed("用户不存在");
    }
    appUser.setEnabled(enabled);
    appUser.setUpdateTime(new Date());

    int i = baseMapper.updateById(appUser);
    log.info("修改用户:{}", appUser);

    return i > 0 ? Result.succeed(appUser, "更新成功") : Result.failed("更新失败");
}
 
Example 8
Source File: SysUserServiceImpl.java    From open-capacity-platform with Apache License 2.0 6 votes vote down vote up
@Override
public Result updateEnabled(Map<String, Object> params) {
	Long id = MapUtils.getLong(params, "id");
	Boolean enabled = MapUtils.getBoolean(params, "enabled");

	SysUser appUser = sysUserDao.findById(id);
	if (appUser == null) {
		return Result.failed("用户不存在");
		//throw new IllegalArgumentException("用户不存在");
	}
	appUser.setEnabled(enabled);
	appUser.setUpdateTime(new Date());

	int i = sysUserDao.updateByOps(appUser);
	log.info("修改用户:{}", appUser);

	return i > 0 ? Result.succeed(appUser, "更新成功") : Result.failed("更新失败");
}
 
Example 9
Source File: CommitLagLimiter.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
public boolean tryAcquire(ConsumeOffsetTracker tracker, String topic, ConsumeContext context)  {
    long maxCommitLag = MapUtils.getLong(maxCommitLagMap, topic, -1L);
    if (maxCommitLag < 0) {
        return true;
    }
    long lag = tracker.getCommitLag(topic, context);

    return lag < maxCommitLag;
}
 
Example 10
Source File: CommitLagLimiter.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
public void release(ConsumeOffsetTracker tracker, String topic, ConsumeContext context) {
    long maxCommitLag = MapUtils.getLong(maxCommitLagMap, topic, -1L);
    if (maxCommitLag < 0) {
        return;
    }
    if (tracker.getCommitLag(topic, context) >= maxCommitLag) {
        return;
    }
    commitLagLock.lock();
    try {
        getCondition(topic, context).signal();
    } finally {
        commitLagLock.unlock();
    }
}
 
Example 11
Source File: WechatOAuth2Template.java    From cola with MIT License 5 votes vote down vote up
@SuppressWarnings("unchecked")
private AccessGrant getAccessToken(StringBuilder accessTokenRequestUrl) {

	log.info("获取access_token, 请求URL: " + accessTokenRequestUrl.toString());

	String response = getRestTemplate().getForObject(accessTokenRequestUrl.toString(), String.class);

	log.info("获取access_token, 响应内容: " + response);

	Map<String, Object> result = null;
	try {
		result = new ObjectMapper().readValue(response, Map.class);
	} catch (Exception e) {
		e.printStackTrace();
	}

	//返回错误码时直接返回空
	if (StringUtils.isNotBlank(MapUtils.getString(result, "errcode"))) {
		String errcode = MapUtils.getString(result, "errcode");
		String errmsg = MapUtils.getString(result, "errmsg");
		throw new RuntimeException("获取access token失败, errcode:" + errcode + ", errmsg:" + errmsg);
	}

	WechatAccessGrant accessToken = new WechatAccessGrant(
			MapUtils.getString(result, "access_token"),
			MapUtils.getString(result, "scope"),
			MapUtils.getString(result, "refresh_token"),
			MapUtils.getLong(result, "expires_in"));

	accessToken.setOpenId(MapUtils.getString(result, "openid"));

	return accessToken;
}
 
Example 12
Source File: WechatMpOAuth2Template.java    From cola with MIT License 5 votes vote down vote up
@SuppressWarnings("unchecked")
private AccessGrant getAccessToken(StringBuilder accessTokenRequestUrl) {

	log.info("获取access_token, 请求URL: " + accessTokenRequestUrl.toString());

	String response = getRestTemplate().getForObject(accessTokenRequestUrl.toString(), String.class);

	log.info("获取access_token, 响应内容: " + response);

	Map<String, Object> result = null;
	try {
		result = new ObjectMapper().readValue(response, Map.class);
	} catch (Exception e) {
		e.printStackTrace();
	}

	//返回错误码时直接返回空
	if (StringUtils.isNotBlank(MapUtils.getString(result, "errcode"))) {
		String errcode = MapUtils.getString(result, "errcode");
		String errmsg = MapUtils.getString(result, "errmsg");
		throw new RuntimeException("获取access token失败, errcode:" + errcode + ", errmsg:" + errmsg);
	}

	WechatMpAccessGrant accessToken = new WechatMpAccessGrant(
			MapUtils.getString(result, "access_token"),
			MapUtils.getString(result, "scope"),
			MapUtils.getString(result, "refresh_token"),
			MapUtils.getLong(result, "expires_in"));

	accessToken.setOpenId(MapUtils.getString(result, "openid"));

	return accessToken;
}
 
Example 13
Source File: CommitLagLimiter.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
public boolean tryAcquire(ConsumeOffsetTracker tracker, String topic, ConsumeContext context)  {
    long maxCommitLag = MapUtils.getLong(maxCommitLagMap, topic, -1L);
    if (maxCommitLag < 0) {
        return true;
    }
    long lag = tracker.getCommitLag(topic, context);

    return lag < maxCommitLag;
}
 
Example 14
Source File: CommitLagLimiter.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
public void release(ConsumeOffsetTracker tracker, String topic, ConsumeContext context) {
    long maxCommitLag = MapUtils.getLong(maxCommitLagMap, topic, -1L);
    if (maxCommitLag < 0) {
        return;
    }
    if (tracker.getCommitLag(topic, context) >= maxCommitLag) {
        return;
    }
    commitLagLock.lock();
    try {
        getCondition(topic, context).signal();
    } finally {
        commitLagLock.unlock();
    }
}
 
Example 15
Source File: WeiXinOAuth2Template.java    From FEBS-Security with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private AccessGrant getAccessToken(StringBuilder accessTokenRequestUrl) {

    logger.info("获取access_token, 请求URL{} ", accessTokenRequestUrl.toString());
    String response = getRestTemplate().getForObject(accessTokenRequestUrl.toString(), String.class);
    logger.info("获取access_token, 响应内容{} ", response);

    Map<String, Object> result = null;
    try {
        result = new ObjectMapper().readValue(response, Map.class);
    } catch (Exception e) {
        logger.error("获取微信AccessToken失败", e);
    }

    if (StringUtils.isNotBlank(MapUtils.getString(result, "errcode"))) {
        String errcode = MapUtils.getString(result, "errcode");
        String errmsg = MapUtils.getString(result, "errmsg");
        throw new FebsCredentialExcetion("获取access token失败, errcode:" + errcode + ", errmsg:" + errmsg);
    }

    WeiXinAccessGrant accessToken = new WeiXinAccessGrant(
            MapUtils.getString(result, "access_token"),
            MapUtils.getString(result, "scope"),
            MapUtils.getString(result, "refresh_token"),
            MapUtils.getLong(result, "expires_in"));

    accessToken.setOpenId(MapUtils.getString(result, "openid"));

    return accessToken;
}
 
Example 16
Source File: SysUserController.java    From microservices-platform with Apache License 2.0 5 votes vote down vote up
/**
 * 修改用户状态
 *
 * @param params
 * @return
 */
@ApiOperation(value = "修改用户状态")
@GetMapping("/users/updateEnabled")
@ApiImplicitParams({
        @ApiImplicitParam(name = "id", value = "用户id", required = true, dataType = "Integer"),
        @ApiImplicitParam(name = "enabled", value = "是否启用", required = true, dataType = "Boolean")
})
public Result updateEnabled(@RequestParam Map<String, Object> params) {
    Long id = MapUtils.getLong(params, "id");
    if (checkAdmin(id)) {
        return Result.failed(ADMIN_CHANGE_MSG);
    }
    return appUserService.updateEnabled(params);
}
 
Example 17
Source File: DimensionWrapper.java    From incubator-pinot with Apache License 2.0 5 votes vote down vote up
private void warmUpAnomaliesCache(List<MetricEntity> nestedMetrics) {
  DatasetConfigDTO dataset = retrieveDatasetConfig(nestedMetrics);
  long cachingPeriodLookback = config.getProperties().containsKey(PROP_CACHE_PERIOD_LOOKBACK) ?
      MapUtils.getLong(config.getProperties(), PROP_CACHE_PERIOD_LOOKBACK) : ThirdEyeUtils
      .getCachingPeriodLookback(dataset.bucketTimeGranularity());

  long paddingBuffer = TimeUnit.DAYS.toMillis(1);
  AnomalySlice anomalySlice = new AnomalySlice()
      .withDetectionId(this.config.getId())
      .withStart(startTime - cachingPeriodLookback - paddingBuffer)
      .withEnd(endTime + paddingBuffer);
  Multimap<AnomalySlice, MergedAnomalyResultDTO> warmUpResults = this.provider.fetchAnomalies(Collections.singleton(anomalySlice));
  LOG.info("Warmed up anomalies cache for detection {} with {} anomalies - start: {} end: {}", config.getId(),
      warmUpResults.values().size(), (startTime - cachingPeriodLookback), endTime);
}
 
Example 18
Source File: AlertSearcher.java    From incubator-pinot with Apache License 2.0 4 votes vote down vote up
/**
 * Format and generate the final search result
 */
private Map<String, Object> getResult(AlertSearchQuery searchQuery, List<DetectionAlertConfigDTO> subscriptionGroups,
    List<DetectionConfigDTO> detectionConfigs) {
  long count;
  if (searchQuery.searchFilter.isEmpty()) {
    // if not filter is applied, execute count query
    count = this.detectionConfigDAO.count();
  } else {
    // count and limit the filtered results
    count = detectionConfigs.size();
    if (searchQuery.offset >= count) {
      // requested page is out of bound
      detectionConfigs.clear();
    } else {
      detectionConfigs = detectionConfigs.subList((int) searchQuery.offset,
          (int) Math.min(searchQuery.offset + searchQuery.limit, count));
    }
  }

  // format the results
  List<Map<String, Object>> alerts = detectionConfigs.parallelStream().map(config -> {
    try {
      return this.detectionConfigFormatter.format(config);
    } catch (Exception e) {
      LOG.warn("formatting detection config failed {}", config.getId(), e);
      return null;
    }
  }).filter(Objects::nonNull).collect(Collectors.toList());

  // join detections with subscription groups
  Multimap<Long, String> detectionIdToSubscriptionGroups = ArrayListMultimap.create();
  Multimap<Long, String> detectionIdToApplications = ArrayListMultimap.create();
  for (DetectionAlertConfigDTO subscriptionGroup : subscriptionGroups) {
    for (long detectionConfigId : subscriptionGroup.getVectorClocks().keySet()) {
      detectionIdToSubscriptionGroups.put(detectionConfigId, subscriptionGroup.getName());
      detectionIdToApplications.put(detectionConfigId, subscriptionGroup.getApplication());
    }
  }
  for (Map<String, Object> alert : alerts) {
    long id = MapUtils.getLong(alert, "id");
    alert.put("subscriptionGroup", detectionIdToSubscriptionGroups.get(id));
    alert.put("application", new TreeSet<>(detectionIdToApplications.get(id)));
  }

  return ImmutableMap.of("count", count, "limit", searchQuery.limit, "offset", searchQuery.offset, "elements",
      alerts);
}
 
Example 19
Source File: AnomalyDetectorWrapper.java    From incubator-pinot with Apache License 2.0 4 votes vote down vote up
public AnomalyDetectorWrapper(DataProvider provider, DetectionConfigDTO config, long startTime, long endTime) {
  super(provider, config, startTime, endTime);

  Preconditions.checkArgument(this.config.getProperties().containsKey(PROP_SUB_ENTITY_NAME));
  this.entityName = MapUtils.getString(config.getProperties(), PROP_SUB_ENTITY_NAME);

  this.metricUrn = MapUtils.getString(config.getProperties(), PROP_METRIC_URN);
  this.metricEntity = MetricEntity.fromURN(this.metricUrn);
  this.metric = provider.fetchMetrics(Collections.singleton(this.metricEntity.getId())).get(this.metricEntity.getId());

  Preconditions.checkArgument(this.config.getProperties().containsKey(PROP_DETECTOR));
  this.detectorName = DetectionUtils.getComponentKey(MapUtils.getString(config.getProperties(), PROP_DETECTOR));
  Preconditions.checkArgument(this.config.getComponents().containsKey(this.detectorName));
  this.anomalyDetector = (AnomalyDetector) this.config.getComponents().get(this.detectorName);

  // emulate moving window or now
  this.isMovingWindowDetection = MapUtils.getBooleanValue(config.getProperties(), PROP_MOVING_WINDOW_DETECTION, false);
  // delays to wait for data becomes available
  this.windowDelay = MapUtils.getIntValue(config.getProperties(), PROP_WINDOW_DELAY, 0);
  // window delay unit
  this.windowDelayUnit = TimeUnit.valueOf(MapUtils.getString(config.getProperties(), PROP_WINDOW_DELAY_UNIT, "DAYS"));
  // detection window size
  this.windowSize = MapUtils.getIntValue(config.getProperties(), PROP_WINDOW_SIZE, 1);
  // detection window unit
  this.windowUnit = TimeUnit.valueOf(MapUtils.getString(config.getProperties(), PROP_WINDOW_UNIT, "DAYS"));
  // run frequency, used to determine moving windows for minute-level detection
  Map<String, Object> frequency = (Map<String, Object>) MapUtils.getMap(config.getProperties(), PROP_FREQUENCY);
  this.functionFrequency = new TimeGranularity(MapUtils.getIntValue(frequency, "size", 15), TimeUnit.valueOf(MapUtils.getString(frequency, "unit", "MINUTES")));

  MetricConfigDTO metricConfigDTO = this.provider.fetchMetrics(Collections.singletonList(this.metricEntity.getId())).get(this.metricEntity.getId());
  this.dataset = this.provider.fetchDatasets(Collections.singletonList(metricConfigDTO.getDataset()))
      .get(metricConfigDTO.getDataset());
  // date time zone for moving windows. use dataset time zone as default
  this.dateTimeZone = DateTimeZone.forID(MapUtils.getString(config.getProperties(), PROP_TIMEZONE, this.dataset.getTimezone()));

  String bucketStr = MapUtils.getString(config.getProperties(), PROP_BUCKET_PERIOD);
  this.bucketPeriod = bucketStr == null ? this.getBucketSizePeriodForDataset() : Period.parse(bucketStr);
  this.cachingPeriodLookback = config.getProperties().containsKey(PROP_CACHE_PERIOD_LOOKBACK) ?
      MapUtils.getLong(config.getProperties(), PROP_CACHE_PERIOD_LOOKBACK) : ThirdEyeUtils.getCachingPeriodLookback(this.dataset.bucketTimeGranularity());

  speedUpMinuteLevelDetection();
}