Search in sources :

Example 6 with InstanceInfo

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;
}
Also used : List(java.util.List) InstanceInfo(com.sohu.cache.entity.InstanceInfo)

Example 7 with InstanceInfo

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;
}
Also used : AppUser(com.sohu.cache.entity.AppUser) InstanceInfo(com.sohu.cache.entity.InstanceInfo)

Example 8 with InstanceInfo

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;
}
Also used : Jedis(redis.clients.jedis.Jedis) IdempotentConfirmer(com.sohu.cache.util.IdempotentConfirmer) AppDesc(com.sohu.cache.entity.AppDesc) InstanceInfo(com.sohu.cache.entity.InstanceInfo)

Example 9 with InstanceInfo

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;
}
Also used : Jedis(redis.clients.jedis.Jedis) IdempotentConfirmer(com.sohu.cache.util.IdempotentConfirmer) AppDesc(com.sohu.cache.entity.AppDesc) InstanceInfo(com.sohu.cache.entity.InstanceInfo)

Example 10 with InstanceInfo

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;
}
Also used : MachineInfo(com.sohu.cache.entity.MachineInfo) InstanceInfo(com.sohu.cache.entity.InstanceInfo)

Aggregations

InstanceInfo (com.sohu.cache.entity.InstanceInfo)45 AppDesc (com.sohu.cache.entity.AppDesc)11 List (java.util.List)7 Jedis (redis.clients.jedis.Jedis)7 InstanceStats (com.sohu.cache.entity.InstanceStats)6 MachineInfo (com.sohu.cache.entity.MachineInfo)5 ArrayList (java.util.ArrayList)5 IdempotentConfirmer (com.sohu.cache.util.IdempotentConfirmer)3 Date (java.util.Date)3 HashMap (java.util.HashMap)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 ModelAndView (org.springframework.web.servlet.ModelAndView)3 InstanceCommandStats (com.sohu.cache.entity.InstanceCommandStats)2 InstanceSlotModel (com.sohu.cache.entity.InstanceSlotModel)2 AppDetailVO (com.sohu.cache.web.vo.AppDetailVO)2 BaseTest (com.sohu.test.BaseTest)2 HashSet (java.util.HashSet)2 TreeMap (java.util.TreeMap)2 Test (org.junit.Test)2 HostAndPort (redis.clients.jedis.HostAndPort)2