use of com.sohu.cache.entity.InstanceInfo in project cachecloud by sohutv.
the class InstanceManageController method doInitInstanceConfigChange.
/**
* 处理实例配置修改
*
* @param appAuditId 审批id
*/
@RequestMapping(value = "/initInstanceConfigChange")
public ModelAndView doInitInstanceConfigChange(HttpServletRequest request, HttpServletResponse response, Model model, Long appAuditId) {
// 申请原因
AppAudit appAudit = appService.getAppAuditById(appAuditId);
model.addAttribute("appAudit", appAudit);
// 用第一个参数存实例id
Long instanceId = NumberUtils.toLong(appAudit.getParam1());
Map<String, String> redisConfigList = redisCenter.getRedisConfigList(instanceId.intValue());
model.addAttribute("redisConfigList", redisConfigList);
// 实例
InstanceInfo instanceInfo = instanceStatsCenter.getInstanceInfo(instanceId);
model.addAttribute("instanceInfo", instanceInfo);
model.addAttribute("appId", appAudit.getAppId());
model.addAttribute("appAuditId", appAuditId);
// 修改配置的键值对
model.addAttribute("instanceConfigKey", appAudit.getParam2());
model.addAttribute("instanceConfigValue", appAudit.getParam3());
return new ModelAndView("manage/appAudit/initInstanceConfigChange");
}
use of com.sohu.cache.entity.InstanceInfo in project cachecloud by sohutv.
the class ObjectConvert method assembleInstance.
/**
* 将实例列表转化为ip1:port1 ip2:port2
*
* @param instanceList
* @return
*/
public static String assembleInstance(List<InstanceInfo> instanceList) {
if (instanceList.isEmpty()) {
return null;
}
StringBuilder instanceBuilder = new StringBuilder();
for (int i = 0; i < instanceList.size(); i++) {
InstanceInfo instanceInfo = instanceList.get(i);
if (instanceInfo.isOffline()) {
continue;
}
if (i > 0) {
instanceBuilder.append(" ");
}
instanceBuilder.append(instanceInfo.getIp()).append(":").append(instanceInfo.getPort());
}
return StringUtils.trim(instanceBuilder.toString());
}
use of com.sohu.cache.entity.InstanceInfo in project cachecloud by sohutv.
the class HostInspectHandler method getSplitMap.
@Override
protected Map<String, List<InstanceInfo>> getSplitMap() {
List<InstanceInfo> list = getAllInstanceList();
Map<String, List<InstanceInfo>> hostMap = new TreeMap<String, List<InstanceInfo>>();
for (InstanceInfo instanceInfo : list) {
String host = instanceInfo.getIp();
if (hostMap.containsKey(host)) {
hostMap.get(host).add(instanceInfo);
} else {
List<InstanceInfo> hostInstances = new ArrayList<InstanceInfo>();
hostInstances.add(instanceInfo);
hostMap.put(host, hostInstances);
}
}
return hostMap;
}
use of com.sohu.cache.entity.InstanceInfo in project cachecloud by sohutv.
the class RedisIsolationPersistenceInspector method inspect.
@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();
int status = info.getStatus();
//非正常节点
if (status != InstanceStatusEnum.GOOD_STATUS.getStatus()) {
continue;
}
if (TypeUtil.isRedisDataType(type)) {
Jedis jedis = new Jedis(host, port, 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, "aof_current_size");
long aofBaseSize = MapUtils.getLongValue(persistenceMap, "aof_base_size");
//阀值大于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;
}
use of com.sohu.cache.entity.InstanceInfo in project cachecloud by sohutv.
the class RedisDeployCenterImpl method addSentinel.
@Override
public boolean addSentinel(long appId, String sentinelHost) {
AppDesc appDesc = appDao.getAppDescById(appId);
JedisSentinelPool jedisSentinelPool = redisCenter.getJedisSentinelPool(appDesc);
if (jedisSentinelPool == null) {
return false;
}
List<InstanceInfo> instanceInfos = instanceDao.getInstListByAppId(appId);
String masterName = null;
for (Iterator<InstanceInfo> i = instanceInfos.iterator(); i.hasNext(); ) {
InstanceInfo instanceInfo = i.next();
if (instanceInfo.getType() != ConstUtils.CACHE_REDIS_SENTINEL) {
i.remove();
continue;
}
if (masterName == null && StringUtils.isNotBlank(instanceInfo.getCmd())) {
masterName = instanceInfo.getCmd();
}
}
Jedis jedis = null;
String masterHost = null;
Integer masterPort = null;
try {
jedis = jedisSentinelPool.getResource();
masterHost = jedis.getClient().getHost();
masterPort = jedis.getClient().getPort();
} catch (Exception e) {
logger.error(e.getMessage(), e);
} finally {
jedis.close();
jedisSentinelPool.destroy();
}
boolean isRun = runSentinel(sentinelHost, masterName, masterHost, masterPort, appId);
if (!isRun) {
return false;
}
return true;
}
Aggregations