Java Code Examples for org.apache.commons.collections.MapUtils#getString()
The following examples show how to use
org.apache.commons.collections.MapUtils#getString() .
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 |
@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 | 6 votes |
@Override public HostAndPort getMaster(String ip, int port, String password) { JedisPool jedisPool = maintainJedisPool(ip, port, password); Jedis jedis = null; try { jedis = jedisPool.getResource(); String info = jedis.info(RedisConstant.Replication.getValue()); Map<RedisConstant, Map<String, Object>> infoMap = processRedisStats(info); Map<String, Object> map = infoMap.get(RedisConstant.Replication); if (map == null) { return null; } String masterHost = MapUtils.getString(map, RedisInfoEnum.master_host.getValue(), null); int masterPort = MapUtils.getInteger(map, RedisInfoEnum.master_port.getValue(), 0); if (StringUtils.isNotBlank(masterHost) && masterPort > 0) { return new HostAndPort(masterHost, masterPort); } return null; } catch (Exception e) { logger.error("{}:{} getMaster failed {}", ip, port, e.getMessage(), e); return null; } finally { if (jedis != null) jedis.close(); } }
Example 3
Source File: MachineCenterImpl.java From cachecloud with Apache License 2.0 | 6 votes |
@Override public Map<String, Integer> getMachineInstanceCountMap() { List<Map<String,Object>> mapList = instanceDao.getMachineInstanceCountMap(); if (CollectionUtils.isEmpty(mapList)) { return Collections.emptyMap(); } Map<String, Integer> resultMap = new HashMap<String, Integer>(); for(Map<String,Object> map : mapList) { String ip = MapUtils.getString(map, "ip", ""); if (StringUtils.isBlank(ip)) { continue; } int count = MapUtils.getIntValue(map, "count"); resultMap.put(ip, count); } return resultMap; }
Example 4
Source File: S3S3CopierOptions.java From circus-train with Apache License 2.0 | 5 votes |
private URI s3Endpoint(String keyName) { String endpoint = MapUtils.getString(copierOptions, keyName, null); if (endpoint == null) { return null; } return URI.create(endpoint); }
Example 5
Source File: RedisCenterImpl.java From cachecloud with Apache License 2.0 | 5 votes |
@Override public String getRedisVersion(long appId, String ip, int port) { Map<RedisConstant, Map<String, Object>> infoAllMap = getInfoStats(appId, ip, port); if (MapUtils.isEmpty(infoAllMap)) { return null; } Map<String, Object> serverMap = infoAllMap.get(RedisConstant.Server); if (MapUtils.isEmpty(serverMap)) { return null; } return MapUtils.getString(serverMap, "redis_version"); }
Example 6
Source File: InspectorJob.java From cachecloud with Apache License 2.0 | 5 votes |
@Override public void action(JobExecutionContext context) { try { long start = System.currentTimeMillis(); SchedulerContext schedulerContext = context.getScheduler().getContext(); ApplicationContext applicationContext = (ApplicationContext) schedulerContext.get(APPLICATION_CONTEXT_KEY); // 应用相关 InspectHandler inspectHandler; JobDataMap jobDataMap = context.getMergedJobDataMap(); String inspectorType = MapUtils.getString(jobDataMap, "inspectorType"); if (StringUtils.isBlank(inspectorType)) { logger.error("=====================InspectorJob:inspectorType is null====================="); return; } else if (inspectorType.equals("host")) { inspectHandler = applicationContext.getBean("hostInspectHandler", InspectHandler.class); } else if (inspectorType.equals("app")) { inspectHandler = applicationContext.getBean("appInspectHandler", InspectHandler.class); } else { logger.error("=====================InspectorJob:inspectorType not match:{}=====================", inspectorType); return; } inspectHandler.handle(); long end = System.currentTimeMillis(); logger.info("=====================InspectorJob {} Done! cost={} ms=====================", inspectHandler.getClass().getSimpleName(), (end - start)); } catch (Exception e) { logger.error(e.getMessage(), e); throw new RuntimeException(e); } }
Example 7
Source File: S3S3CopierOptions.java From circus-train with Apache License 2.0 | 5 votes |
public CannedAccessControlList getCannedAcl() { String cannedAcl = MapUtils.getString(copierOptions, Keys.CANNED_ACL.keyName(), null); if (cannedAcl != null) { return CannedAclUtils.toCannedAccessControlList(cannedAcl); } return null; }
Example 8
Source File: RangerScriptTemplateConditionEvaluator.java From ranger with Apache License 2.0 | 5 votes |
@Override public void init() { if (LOG.isDebugEnabled()) { LOG.debug("==> RangerScriptTemplateConditionEvaluator.init(" + condition + ")"); } super.init(); if(CollectionUtils.isNotEmpty(condition.getValues())) { String expectedScriptReturn = condition.getValues().get(0); if(StringUtils.isNotBlank(expectedScriptReturn)) { if(StringUtils.equalsIgnoreCase(expectedScriptReturn, "false") || StringUtils.equalsIgnoreCase(expectedScriptReturn, "no")) { reverseResult = true; } script = MapUtils.getString(conditionDef.getEvaluatorOptions(), "scriptTemplate"); if(script != null) { script = script.trim(); } } } if (LOG.isDebugEnabled()) { LOG.debug("<== RangerScriptTemplateConditionEvaluator.init(" + condition + "): script=" + script + "; reverseResult=" + reverseResult); } }
Example 9
Source File: WeixinOAuth2Template.java From paascloud-master with Apache License 2.0 | 5 votes |
@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) { log.error("getAccessToken={}", e.getMessage(), e); } //返回错误码时直接返回空 if (StringUtils.isNotBlank(MapUtils.getString(result, ERR_CODE))) { String errCode = MapUtils.getString(result, ERR_CODE); String errMsg = MapUtils.getString(result, ERR_MSG); throw new RuntimeException("获取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 10
Source File: InputSimulate.java From ambari-logsearch with Apache License 2.0 | 5 votes |
private String imitateRandomLogFile() { int typePos = random.nextInt(types.size()); String type = types.get(typePos); String filePath = MapUtils.getString(typeToFilePath, type, "path of " + type); ((InputDescriptorImpl)getInputDescriptor()).setType(type); setFilePath(filePath); return type; }
Example 11
Source File: LogSearchConfigZKHelper.java From ambari-logsearch with Apache License 2.0 | 5 votes |
/** * Create ZK curator client from a configuration (map holds the configs for that) * @param properties key/value pairs that holds configurations for the zookeeper client * @return zookeeper client */ public static CuratorFramework createZKClient(Map<String, String> properties) { String root = MapUtils.getString(properties, ZK_ROOT_NODE_PROPERTY, DEFAULT_ZK_ROOT); logger.info("Connecting to ZooKeeper at " + properties.get(ZK_CONNECT_STRING_PROPERTY) + root); return CuratorFrameworkFactory.builder() .connectString(properties.get(ZK_CONNECT_STRING_PROPERTY) + root) .retryPolicy(getRetryPolicy(properties.get(ZK_CONNECTION_RETRY_TIMEOUT_PROPERTY))) .connectionTimeoutMs(getIntProperty(properties, ZK_CONNECTION_TIMEOUT_PROPERTY, DEFAULT_CONNECTION_TIMEOUT)) .sessionTimeoutMs(getIntProperty(properties, ZK_SESSION_TIMEOUT_PROPERTY, DEFAULT_SESSION_TIMEOUT)) .build(); }
Example 12
Source File: WeixinOAuth2Template.java From pre with GNU General Public License v3.0 | 5 votes |
@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); } 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 13
Source File: ScheduleReliableController.java From reliable with Apache License 2.0 | 5 votes |
@RequestMapping(value = "/clean", method = RequestMethod.GET) public boolean clean() { List<String> cleanStatusList = new ArrayList<>(); cleanStatusList.add(MessageStatus.OK.toString()); cleanStatusList.add(MessageStatus.BLANK.toString()); CriteriaBuilder.ResultMappedBuilder builder = CriteriaBuilder.buildResultMapped(ReliableMessage.class); builder.resultKey("id"); builder.and().eq("underConstruction", false); builder.and().in("status", cleanStatusList); Criteria.ResultMappedCriteria resultMappedCriteria = builder.get(); List<Map<String, Object>> list = this.reliableMessageService.listByResultMap(resultMappedCriteria); for (Map<String, Object> map : list) { String id = MapUtils.getString(map, "id"); if (StringUtil.isNullOrEmpty(id)) continue; this.messageResultService.removeByMessageId(id); this.reliableMessageService.remove(id); } return true; }
Example 14
Source File: ClientReportCostDistriServiceImpl.java From cachecloud with Apache License 2.0 | 4 votes |
private AppClientCostTimeStat generate(String clientIp, long collectTime, long reportTime, Map<String, Object> map) { try { Integer count = MapUtils.getInteger(map, ClientReportConstant.COST_COUNT, 0); String command = MapUtils.getString(map, ClientReportConstant.COST_COMMAND, ""); if (StringUtils.isBlank(command)) { logger.warn("command is empty!"); return null; } String hostPort = MapUtils.getString(map, ClientReportConstant.COST_HOST_PORT, ""); if (StringUtils.isBlank(hostPort)) { logger.warn("hostPort is empty", hostPort); return null; } int index = hostPort.indexOf(":"); if (index <= 0) { logger.warn("hostPort {} format is wrong", hostPort); return null; } String host = hostPort.substring(0, index); int port = NumberUtils.toInt(hostPort.substring(index + 1)); // 实例信息 InstanceInfo instanceInfo = clientReportInstanceService.getInstanceInfoByHostPort(host, port); if (instanceInfo == null) { // logger.warn("instanceInfo is empty, host is {}, port is {}", host, port); return null; } long appId = instanceInfo.getAppId(); // 耗时分布详情 double mean = MapUtils.getDouble(map, ClientReportConstant.COST_TIME_MEAN, 0.0); Integer median = MapUtils.getInteger(map, ClientReportConstant.COST_TIME_MEDIAN, 0); Integer ninetyPercentMax = MapUtils.getInteger(map, ClientReportConstant.COST_TIME_90_MAX, 0); Integer ninetyNinePercentMax = MapUtils.getInteger(map, ClientReportConstant.COST_TIME_99_MAX, 0); Integer hunredMax = MapUtils.getInteger(map, ClientReportConstant.COST_TIME_100_MAX, 0); AppClientCostTimeStat stat = new AppClientCostTimeStat(); stat.setAppId(appId); stat.setClientIp(clientIp); stat.setReportTime(new Date(reportTime)); stat.setCollectTime(collectTime); stat.setCreateTime(new Date()); stat.setCommand(command); stat.setCount(count); stat.setInstanceHost(host); stat.setInstancePort(port); stat.setMean(NumberUtils.toDouble(new DecimalFormat("#.00").format(mean))); stat.setMedian(median); stat.setNinetyPercentMax(ninetyPercentMax); stat.setNinetyNinePercentMax(ninetyNinePercentMax); stat.setHundredMax(hunredMax); stat.setInstanceId(instanceInfo.getId()); return stat; } catch (Exception e) { logger.error(e.getMessage(), e); return null; } }
Example 15
Source File: ScheduleReliableController.java From reliable with Apache License 2.0 | 4 votes |
@RequestMapping(value = "/tryToFinish", method = RequestMethod.GET) public boolean tryToFinish() { Date createAt = new Date(System.currentTimeMillis() - checkStatusDuration); CriteriaBuilder.ResultMappedBuilder builder = CriteriaBuilder.buildResultMapped(ReliableMessage.class); builder.resultKey("id").resultKey("svcDone").resultKey("svcList").resultKey("retryCount").resultKey("retryMax").resultKey("tcc").resultKey("body"); builder.and().eq("status", MessageStatus.SEND); builder.and().lt("createAt", createAt); Criteria.ResultMappedCriteria resultMappedCriteria = builder.get(); List<Map<String, Object>> list = this.reliableMessageService.listByResultMap(resultMappedCriteria); if (list.isEmpty()) return true; Date date = new Date(); for (Map<String, Object> map : list) { List<String> svcList = (List<String>)MapUtils.getObject(map, "svcList"); String tcc = MapUtils.getString(map, "tcc"); Object bodyObj = MapUtils.getObject(map, "body"); GenericObject go = (GenericObject) bodyObj; ReliableMessage reliableMessage = new ReliableMessage(); reliableMessage.setId(MapUtils.getString(map, "id")); reliableMessage.setSvcDone(MapUtils.getString(map, "svcDone")); reliableMessage.setSvcList(svcList); reliableMessage.setBody(go); reliableMessage.setTcc(tcc); reliableMessage.setRetryCount(MapUtils.getLongValue(map, "retryCount")); reliableMessage.setRetryMax(MapUtils.getIntValue(map, "retryMax")); String svcDone = reliableMessage.getSvcDone(); if (StringUtil.isNullOrEmpty(svcDone)) continue; boolean flag = true; for (String svc : svcList) { flag &= svcDone.contains(svc); } if (reliableMessage.getTcc().equals(TCCTopic._TCC_TRY.name())) { if (!flag) { if (reliableMessage.getRetryCount() >= reliableMessage.getRetryMax()) { cancel(reliableMessage.getId()); } } } else { if (flag) { RefreshCondition<ReliableMessage> reliableMessageRefreshCondition = new RefreshCondition<>(); reliableMessageRefreshCondition.refresh("status", MessageStatus.OK); reliableMessageRefreshCondition.refresh("refreshAt", date); reliableMessageRefreshCondition.and().eq("id", reliableMessage.getId()); this.reliableMessageService.refresh(reliableMessageRefreshCondition); try { this.nextBusiness.produce(reliableMessage.getId(),reliableMessageService,producer); }catch (Exception e) { } } } } return true; }
Example 16
Source File: ClientReportExceptionServiceImpl.java From cachecloud with Apache License 2.0 | 4 votes |
private AppClientExceptionStat generate(String clientIp, long collectTime, long reportTime, Map<String, Object> map) { // 异常信息 String exceptionClass = MapUtils.getString(map, ClientReportConstant.EXCEPTION_CLASS, ""); Long exceptionCount = MapUtils.getLong(map, ClientReportConstant.EXCEPTION_COUNT, 0L); int exceptionType = MapUtils.getInteger(map, ClientReportConstant.EXCEPTION_TYPE, ClientExceptionType.REDIS_TYPE.getType()); String host = null; Integer port = null; Integer instanceId = null; long appId; if (ClientExceptionType.REDIS_TYPE.getType() == exceptionType) { // 实例host:port String hostPort = MapUtils.getString(map, ClientReportConstant.EXCEPTION_HOST_PORT, ""); if (StringUtils.isEmpty(hostPort)) { logger.warn("hostPort is empty", hostPort); return null; } int index = hostPort.indexOf(":"); if (index <= 0) { logger.warn("hostPort {} format is wrong", hostPort); return null; } host = hostPort.substring(0, index); port = NumberUtils.toInt(hostPort.substring(index + 1)); // 实例信息 InstanceInfo instanceInfo = clientReportInstanceService.getInstanceInfoByHostPort(host, port); if (instanceInfo == null) { // logger.warn("instanceInfo is empty, host is {}, port is {}", host, port); return null; } // 实例id instanceId = instanceInfo.getId(); // 应用id appId = instanceInfo.getAppId(); } else { List<AppClientVersion> appClientVersion = appClientVersionDao.getByClientIp(clientIp); if (CollectionUtils.isNotEmpty(appClientVersion)) { appId = appClientVersion.get(0).getAppId(); } else { appId = 0; } } // 组装AppClientExceptionStat AppClientExceptionStat stat = new AppClientExceptionStat(); stat.setAppId(appId); stat.setClientIp(clientIp); stat.setReportTime(new Date(reportTime)); stat.setCollectTime(collectTime); stat.setCreateTime(new Date()); stat.setExceptionClass(exceptionClass); stat.setExceptionCount(exceptionCount); stat.setInstanceHost(host); stat.setInstancePort(port); stat.setInstanceId(instanceId); stat.setType(exceptionType); return stat; }
Example 17
Source File: ClientReportValueDistriServiceImplV2.java From cachecloud with Apache License 2.0 | 4 votes |
private AppClientValueDistriStatTotal generate(long collectTime, long reportTime, Map<String, Object> map) { String valueDistri = MapUtils.getString(map, ClientReportConstant.VALUE_DISTRI, ""); ValueSizeDistriEnum valueSizeDistriEnum = ValueSizeDistriEnum.getByValue(valueDistri); if (valueSizeDistriEnum == null) { logger.warn("valueDistri {} is wrong, not in enums {}", valueDistri, ValueSizeDistriEnum.values()); } // 次数 Integer count = MapUtils.getInteger(map, ClientReportConstant.VALUE_COUNT, 0); // 命令 String command = MapUtils.getString(map, ClientReportConstant.VALUE_COMMAND, ""); if (StringUtils.isBlank(command)) { logger.warn("command is empty!"); return null; } if (excludeCommands.contains(command)) { return null; } // 实例host:port String hostPort = MapUtils.getString(map, ClientReportConstant.VALUE_HOST_PORT, ""); if (StringUtils.isEmpty(hostPort)) { logger.warn("hostPort is empty", hostPort); return null; } int index = hostPort.indexOf(":"); if (index <= 0) { logger.warn("hostPort {} format is wrong", hostPort); return null; } String host = hostPort.substring(0, index); int port = NumberUtils.toInt(hostPort.substring(index + 1)); // 实例信息 InstanceInfo instanceInfo = clientReportInstanceService.getInstanceInfoByHostPort(host, port); if (instanceInfo == null) { // logger.warn("instanceInfo is empty, host is {}, port is {}", // host, port); return null; } AppClientValueDistriStatTotal stat = new AppClientValueDistriStatTotal(); stat.setAppId(instanceInfo.getAppId()); stat.setCollectTime(collectTime); stat.setUpdateTime(new Date()); stat.setCommand(command); stat.setDistributeType(valueSizeDistriEnum.getType()); stat.setCount(count); return stat; }
Example 18
Source File: RedisIsolationPersistenceInspector.java From cachecloud with Apache License 2.0 | 4 votes |
@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; }
Example 19
Source File: S3S3CopierOptions.java From circus-train with Apache License 2.0 | 4 votes |
public String getAssumedRole() { return MapUtils.getString(copierOptions, Keys.ASSUME_ROLE.keyName(), null); }
Example 20
Source File: Parrot.java From x7 with Apache License 2.0 | 2 votes |
public String getName(){ return MapUtils.getString(viewMap,""+id); }