use of com.sohu.cache.redis.RedisClusterReshard in project new-cloud by xie-summer.
the class AppDeployCenterImpl method addHorizontalNodes.
@Override
public boolean addHorizontalNodes(Long appId, String masterHost, String slaveHost, int memory) {
AppDesc appDesc = appDao.getAppDescById(appId);
// 1. 寻找主从节点的可用端口
Integer masterPort = machineCenter.getAvailablePort(masterHost, ConstUtils.CACHE_TYPE_REDIS_CLUSTER);
if (masterPort == null) {
logger.error("master host={} getAvailablePort is null", masterHost);
return false;
}
Integer slavePort = 0;
boolean hasSlave = StringUtils.isNotBlank(slaveHost);
if (hasSlave) {
slavePort = machineCenter.getAvailablePort(slaveHost, ConstUtils.CACHE_TYPE_REDIS_CLUSTER);
if (slavePort == null) {
logger.error("slave host={} getAvailablePort is null", slaveHost);
return false;
}
}
// 2. 启动主从节点
boolean isMasterCreate = redisDeployCenter.createRunNode(appDesc, masterHost, masterPort, memory, true);
if (!isMasterCreate) {
logger.error("createRunNode master failed {}:{}", masterHost, masterPort);
return false;
}
if (hasSlave) {
// 运行节点
boolean isSlaveCreate = redisDeployCenter.createRunNode(appDesc, slaveHost, slavePort, memory, true);
if (!isSlaveCreate) {
logger.error("createRunNode slave failed {}:{}", slaveHost, slavePort);
return false;
}
}
// 3. 获取应用下有效节点
Set<HostAndPort> clusterHosts = getEffectiveInstanceList(appId);
// 4. 添加新节点: meet,复制,不做slot分配
RedisClusterReshard clusterReshard = new RedisClusterReshard(clusterHosts, redisCenter, instanceReshardProcessDao);
boolean joinCluster = clusterReshard.joinCluster(appId, masterHost, masterPort, slaveHost, slavePort);
if (joinCluster) {
// 5. 保存实例,开启统计功能
saveInstance(appId, masterHost, masterPort, memory);
redisCenter.deployRedisCollection(appId, masterHost, masterPort);
if (hasSlave) {
saveInstance(appId, slaveHost, slavePort, memory);
redisCenter.deployRedisCollection(appId, slaveHost, slavePort);
}
}
return joinCluster;
}
use of com.sohu.cache.redis.RedisClusterReshard in project new-cloud by xie-summer.
the class AppDeployCenterImpl method startMigrateSlot.
private void startMigrateSlot(final InstanceReshardProcess instanceReshardProcess) {
final long appId = instanceReshardProcess.getAppId();
final long appAuditId = instanceReshardProcess.getAuditId();
final InstanceInfo targetInstanceInfo = instanceReshardProcess.getTargetInstanceInfo();
processThreadPool.execute(new Runnable() {
@Override
public void run() {
// 所有节点用户clustersetslot
Set<HostAndPort> clusterHosts = getEffectiveInstanceList(appId);
RedisClusterReshard clusterReshard = new RedisClusterReshard(clusterHosts, redisCenter, instanceReshardProcessDao);
// 添加进度
boolean joinCluster = clusterReshard.migrateSlot(instanceReshardProcess);
if (joinCluster) {
// 改变审核状态
appAuditDao.updateAppAudit(appAuditId, AppCheckEnum.APP_ALLOCATE_RESOURCE.value());
if (targetInstanceInfo != null && targetInstanceInfo.getStatus() != InstanceStatusEnum.GOOD_STATUS.getStatus()) {
targetInstanceInfo.setStatus(InstanceStatusEnum.GOOD_STATUS.getStatus());
instanceDao.update(targetInstanceInfo);
}
}
}
});
}
use of com.sohu.cache.redis.RedisClusterReshard in project cachecloud by sohutv.
the class AppDeployCenterImpl method addHorizontalNodes.
@Override
public boolean addHorizontalNodes(Long appId, String masterHost, String slaveHost, int memory) {
AppDesc appDesc = appDao.getAppDescById(appId);
// 1. 寻找主从节点的可用端口
Integer masterPort = machineCenter.getAvailablePort(masterHost, ConstUtils.CACHE_TYPE_REDIS_CLUSTER);
if (masterPort == null) {
logger.error("master host={} getAvailablePort is null", masterHost);
return false;
}
Integer slavePort = 0;
boolean hasSlave = StringUtils.isNotBlank(slaveHost);
if (hasSlave) {
slavePort = machineCenter.getAvailablePort(slaveHost, ConstUtils.CACHE_TYPE_REDIS_CLUSTER);
if (slavePort == null) {
logger.error("slave host={} getAvailablePort is null", slaveHost);
return false;
}
}
// 2. 启动主从节点
boolean isMasterCreate = redisDeployCenter.createRunNode(appDesc, masterHost, masterPort, memory, true);
if (!isMasterCreate) {
logger.error("createRunNode master failed {}:{}", masterHost, masterPort);
return false;
}
if (hasSlave) {
// 运行节点
boolean isSlaveCreate = redisDeployCenter.createRunNode(appDesc, slaveHost, slavePort, memory, true);
if (!isSlaveCreate) {
logger.error("createRunNode slave failed {}:{}", slaveHost, slavePort);
return false;
}
}
// 3. 获取应用下有效节点
Set<HostAndPort> clusterHosts = getEffectiveInstanceList(appId);
// 4. 添加新节点: meet,复制,不做slot分配
RedisClusterReshard clusterReshard = new RedisClusterReshard(clusterHosts, redisCenter, instanceReshardProcessDao);
boolean joinCluster = clusterReshard.joinCluster(appId, masterHost, masterPort, slaveHost, slavePort);
if (joinCluster) {
// 5. 保存实例,开启统计功能
saveInstance(appId, masterHost, masterPort, memory);
redisCenter.deployRedisCollection(appId, masterHost, masterPort);
if (hasSlave) {
saveInstance(appId, slaveHost, slavePort, memory);
redisCenter.deployRedisCollection(appId, slaveHost, slavePort);
}
}
return joinCluster;
}
use of com.sohu.cache.redis.RedisClusterReshard in project cachecloud by sohutv.
the class AppDeployCenterImpl method startMigrateSlot.
private void startMigrateSlot(final InstanceReshardProcess instanceReshardProcess) {
final long appId = instanceReshardProcess.getAppId();
final long appAuditId = instanceReshardProcess.getAuditId();
final InstanceInfo targetInstanceInfo = instanceReshardProcess.getTargetInstanceInfo();
processThreadPool.execute(new Runnable() {
@Override
public void run() {
// 所有节点用户clustersetslot
Set<HostAndPort> clusterHosts = getEffectiveInstanceList(appId);
RedisClusterReshard clusterReshard = new RedisClusterReshard(clusterHosts, redisCenter, instanceReshardProcessDao);
// 添加进度
boolean joinCluster = clusterReshard.migrateSlot(instanceReshardProcess);
if (joinCluster) {
// 改变审核状态
appAuditDao.updateAppAudit(appAuditId, AppCheckEnum.APP_ALLOCATE_RESOURCE.value());
if (targetInstanceInfo != null && targetInstanceInfo.getStatus() != InstanceStatusEnum.GOOD_STATUS.getStatus()) {
targetInstanceInfo.setStatus(InstanceStatusEnum.GOOD_STATUS.getStatus());
instanceDao.update(targetInstanceInfo);
}
}
}
});
}
Aggregations