use of com.sohu.cache.entity.InstanceInfo in project cachecloud by sohutv.
the class InstanceRunInspector method inspect.
@Override
public boolean inspect(Map<InspectParamEnum, Object> paramMap) {
String host = MapUtils.getString(paramMap, InspectParamEnum.SPLIT_KEY);
List<InstanceInfo> list = (List<InstanceInfo>) paramMap.get(InspectParamEnum.INSTANCE_LIST);
for (InstanceInfo info : list) {
final int port = info.getPort();
final int type = info.getType();
long appId = info.getAppId();
if (TypeUtil.isRedisType(type)) {
boolean isRun = redisCenter.isRun(host, port);
Boolean isUpdate = updateInstanceByRun(isRun, info);
if (isUpdate == null) {
continue;
} else if (isUpdate) {
redisCenter.deployRedisCollection(appId, host, port);
redisCenter.deployRedisSlowLogCollection(appId, host, port);
} else {
redisCenter.unDeployRedisCollection(appId, host, port);
redisCenter.unDeployRedisSlowLogCollection(appId, host, port);
}
// 错误
if (isUpdate != null) {
alertInstanceInfo(info);
}
}
}
return true;
}
use of com.sohu.cache.entity.InstanceInfo in project cachecloud by sohutv.
the class AppAndInstanceAuthorityInterceptor method preHandle.
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
// 1. 获取用户
long userId = userLoginStatusService.getUserIdFromLoginStatus(request);
AppUser user = userService.get(userId);
// 2. 管理员直接跳过
if (AppUserTypeEnum.ADMIN_USER.value().equals(user.getType())) {
return true;
}
// 3. 应用id
String appId = request.getParameter("appId");
if (StringUtils.isNotBlank(appId)) {
checkUserAppPower(response, request.getSession(true), user, NumberUtils.toLong(appId));
}
// 4. 实例权限检测(其实也是应用)
String instanceId = request.getParameter("instanceId");
if (StringUtils.isNotBlank(instanceId)) {
InstanceInfo instanceInfo = instanceStatsCenter.getInstanceInfo(Long.parseLong(instanceId));
checkUserAppPower(response, request.getSession(true), user, instanceInfo.getAppId());
}
return true;
}
use of com.sohu.cache.entity.InstanceInfo in project cachecloud by sohutv.
the class RedisDeployCenterImpl method sentinelFailover.
@Override
public boolean sentinelFailover(long appId) throws Exception {
Assert.isTrue(appId > 0);
AppDesc appDesc = appDao.getAppDescById(appId);
Assert.isTrue(appDesc != null);
int type = appDesc.getType();
if (!TypeUtil.isRedisSentinel(type)) {
logger.warn("app={} is not sentinel", appDesc);
return false;
}
final List<InstanceInfo> instanceList = instanceDao.getInstListByAppId(appId);
if (instanceList == null || instanceList.isEmpty()) {
logger.warn("app={} instances is empty");
return false;
}
for (InstanceInfo instanceInfo : instanceList) {
int instanceType = instanceInfo.getType();
if (TypeUtil.isRedisSentinel(instanceType)) {
final String host = instanceInfo.getIp();
final int port = instanceInfo.getPort();
final String masterName = instanceInfo.getCmd();
if (StringUtils.isBlank(masterName)) {
logger.warn("{} cmd is null", instanceInfo);
continue;
}
boolean isRun = redisCenter.isRun(host, port);
if (!isRun) {
logger.warn("{} is not run");
continue;
}
boolean isSentinelFailOver = new IdempotentConfirmer() {
@Override
public boolean execute() {
Jedis jedis = new Jedis(host, port, Protocol.DEFAULT_TIMEOUT);
try {
String response = jedis.sentinelFailover(masterName);
return response != null && response.equalsIgnoreCase("OK");
} finally {
jedis.close();
}
}
}.run();
if (!isSentinelFailOver) {
logger.warn("{}:{} sentienl isSentinelFailOver error", host, port);
return false;
} else {
logger.warn("SentinelFailOver done! ");
break;
}
}
}
return true;
}
use of com.sohu.cache.entity.InstanceInfo in project cachecloud by sohutv.
the class RedisDeployCenterImpl method clusterFailover.
@Override
public boolean clusterFailover(long appId, int slaveInstanceId) throws Exception {
Assert.isTrue(appId > 0);
Assert.isTrue(slaveInstanceId > 0);
AppDesc appDesc = appDao.getAppDescById(appId);
Assert.isTrue(appDesc != null);
int type = appDesc.getType();
if (!TypeUtil.isRedisCluster(type)) {
logger.error("{} is not redis type", appDesc);
return false;
}
InstanceInfo instanceInfo = instanceDao.getInstanceInfoById(slaveInstanceId);
Assert.isTrue(instanceInfo != null);
String slaveHost = instanceInfo.getIp();
int slavePort = instanceInfo.getPort();
final Jedis slaveJedis = new Jedis(slaveHost, slavePort);
boolean isClusterFailOver = new IdempotentConfirmer() {
@Override
public boolean execute() {
String response = slaveJedis.clusterFailoverForce();
return response != null && response.equalsIgnoreCase("OK");
}
}.run();
if (!isClusterFailOver) {
logger.error("{}:{} clusterFailover failed", slaveHost, slavePort);
return false;
} else {
logger.warn("{}:{} clusterFailover Done! ", slaveHost, slavePort);
}
return true;
}
use of com.sohu.cache.entity.InstanceInfo in project cachecloud by sohutv.
the class ImportAppCenterImpl method saveInstance.
/**
* 保存实例信息
* @param appId
* @param host
* @param port
* @param maxMemory
* @param type
* @param cmd
* @return
*/
private InstanceInfo saveInstance(long appId, String host, int port, int maxMemory, int type, String cmd) {
InstanceInfo instanceInfo = new InstanceInfo();
instanceInfo.setAppId(appId);
MachineInfo machineInfo = machineCenter.getMachineInfoByIp(host);
instanceInfo.setHostId(machineInfo.getId());
instanceInfo.setConn(0);
instanceInfo.setMem(maxMemory);
instanceInfo.setStatus(InstanceStatusEnum.GOOD_STATUS.getStatus());
instanceInfo.setPort(port);
instanceInfo.setType(type);
instanceInfo.setCmd(cmd);
instanceInfo.setIp(host);
instanceDao.saveInstance(instanceInfo);
return instanceInfo;
}
Aggregations