传入主分支,在分支上修改代码

master
lijiayao 2024-04-18 21:34:38 +08:00
parent 3692f4cb80
commit cd903475ce
22 changed files with 238 additions and 186 deletions

1
.gitignore vendored
View File

@ -1,4 +1,5 @@
target/ target/
.idea
!.mvn/wrapper/maven-wrapper.jar !.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/ !**/src/main/**/target/
!**/src/test/**/target/ !**/src/test/**/target/

View File

@ -8,7 +8,7 @@ import com.aliyun.teautil.models.RuntimeOptions;
import com.yao.common.aliy.model.EcsSelectModel; import com.yao.common.aliy.model.EcsSelectModel;
import com.yao.common.config.AlyConfigProperties; import com.yao.common.config.AlyConfigProperties;
import com.yao.common.domain.aliy.InstanceInfo; import com.yao.common.domain.aliy.InstanceInfo;
import com.yao.gateWay.cache.GatewayAliYunCache; import com.yao.gateway.cache.GatewayNodeSetVinCache;
import lombok.extern.log4j.Log4j2; import lombok.extern.log4j.Log4j2;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -27,11 +27,11 @@ public class AliYunEcsService {
private final AlyConfigProperties alyConfigProperties; private final AlyConfigProperties alyConfigProperties;
private final Client client; private final Client client;
private final GatewayAliYunCache gatewayAliYunCache; private final GatewayNodeSetVinCache gatewayNodeSetVinCache;
public AliYunEcsService(AlyConfigProperties alyConfigProperties, Client client, GatewayAliYunCache gatewayAliYunCache) { public AliYunEcsService(AlyConfigProperties alyConfigProperties, Client client, GatewayNodeSetVinCache gatewayNodeSetVinCache) {
this.alyConfigProperties = alyConfigProperties; this.alyConfigProperties = alyConfigProperties;
this.client = client; this.client = client;
this.gatewayAliYunCache = gatewayAliYunCache; this.gatewayNodeSetVinCache = gatewayNodeSetVinCache;
} }
//todo----------------------------------------------------以下是查询代码-------------------------------------------- //todo----------------------------------------------------以下是查询代码--------------------------------------------
@ -122,7 +122,7 @@ public class AliYunEcsService {
String publicIP = item.getPublicIpAddress().substring(1, item.getPublicIpAddress().length() - 1); String publicIP = item.getPublicIpAddress().substring(1, item.getPublicIpAddress().length() - 1);
item.setPublicIpAddress(publicIP); item.setPublicIpAddress(publicIP);
//存入数据 //存入数据
gatewayAliYunCache.newInstance(item); gatewayNodeSetVinCache.newInstance(item);
log.info("公网IP:" + item.getPublicIpAddress()); log.info("公网IP:" + item.getPublicIpAddress());
} }
); );

View File

@ -2,12 +2,11 @@ package com.yao.common.mqtt;
import com.alibaba.fastjson2.JSONArray; import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject; import com.alibaba.fastjson2.JSONObject;
import com.yao.common.redis.service.RedisService; import com.yao.gateway.cache.GatewayVehicleLineNodeCache;
import lombok.extern.log4j.Log4j2; import lombok.extern.log4j.Log4j2;
import okhttp3.OkHttpClient; import okhttp3.OkHttpClient;
import okhttp3.Request; import okhttp3.Request;
import okhttp3.Response; import okhttp3.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.io.IOException; import java.io.IOException;
@ -21,11 +20,11 @@ import java.io.IOException;
@Log4j2 @Log4j2
public class MqttConnectService { public class MqttConnectService {
/** private GatewayVehicleLineNodeCache gatewayVehicleLineNodeCache;
* redis
*/ public MqttConnectService(GatewayVehicleLineNodeCache gatewayVehicleLineNodeCache) {
@Autowired this.gatewayVehicleLineNodeCache = gatewayVehicleLineNodeCache;
private RedisService redisService; }
//todo-----------------------连接mqtt方法------------------- //todo-----------------------连接mqtt方法-------------------
@ -37,7 +36,7 @@ public class MqttConnectService {
String URL = "http://" + ip + ":8080/public/cluster"; String URL = "http://" + ip + ":8080/public/cluster";
OkHttpClient client = new OkHttpClient(); OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder().url(URL).get().addHeader("User-Agent", "Apifox/1.0.0 (https://apifox.com)").addHeader("Accesstoken", "").build(); Request request = new Request.Builder().url(URL).get().addHeader("User-Agent", "Apifox/1.0.0 (https://apifox.com)").addHeader("Accesstoken", "").build();
redisService.setCacheSet("ECS", ip); gatewayVehicleLineNodeCache.address(ip);
Response response = null; Response response = null;
try { try {
response = client.newCall(request).execute(); response = client.newCall(request).execute();

View File

@ -151,7 +151,6 @@ public class RedisService {
} }
/** /**
* list * list
*
* @param key * @param key
* @return * @return
*/ */

View File

@ -1,13 +0,0 @@
package com.yao.gateWay.cache;
import org.springframework.stereotype.Component;
/**
* @Author: LiJiaYao
* @Date: 2024/4/18
* @Description: vin
*/
@Component
public class GatewayNodeSetVinCache {
}

View File

@ -1,9 +0,0 @@
package com.yao.gateWay.cache;
/**
* @Author: LiJiaYao
* @Date: 2024/4/18
* @Description:
*/
public class GatewayVehicleLineNodeCache {
}

View File

@ -1,4 +1,4 @@
package com.yao.gateWay.cache; package com.yao.gateway.cache;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Builder; import lombok.Builder;

View File

@ -0,0 +1,58 @@
package com.yao.gateway.cache;
import com.yao.gateway.cache.abs.GatewayNodeAbstract;
import lombok.extern.log4j.Log4j2;
import org.springframework.stereotype.Component;
import java.util.List;
/**
* @Author: LiJiaYao
* @Date: 2024/4/18
* @Description:
*/
@Component
@Log4j2
public class GatewayArithmeticCache extends GatewayNodeAbstract {
private static final String loadNode ="work:node:gateway";
private static final String cursor ="cursor";
/**
*
*/
public void count(){
redisService.setCacheObject(cursor, 0);
}
/**
*
* @return
*/
public Long increment(){
return redisService.increment(cursor, 1L);
}
/**
* loadNode
*/
public void remove(){
redisService.deleteObject(loadNode);
}
/**
*
* @param loadNodeList
*/
public void loadNode(List<String> loadNodeList){
redisService.setCacheList(loadNode, loadNodeList);
}
/**
* list
* @param count
* @return nodeId
*/
public String cacheList(Long count){
return redisService.getCacheList(loadNode, count % 100);
}
}

View File

@ -0,0 +1,20 @@
package com.yao.gateway.cache;
import com.yao.gateway.cache.abs.GatewayNodeAbstract;
import lombok.extern.log4j.Log4j2;
import org.springframework.stereotype.Component;
/**
* @Author: LiJiaYao
* @Date: 2024/4/18
* @Description:
*/
@Component
@Log4j2
public class GatewayBusinessCache extends GatewayNodeAbstract {
}

View File

@ -1,6 +1,6 @@
package com.yao.gateWay.cache; package com.yao.gateway.cache;
import com.yao.gateWay.cache.abs.GatewayNodeAbstract; import com.yao.gateway.cache.abs.GatewayNodeAbstract;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.List; import java.util.List;

View File

@ -1,6 +1,6 @@
package com.yao.gateWay.cache; package com.yao.gateway.cache;
import com.yao.gateWay.cache.abs.GatewayNodeAbstract; import com.yao.gateway.cache.abs.GatewayNodeAbstract;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;

View File

@ -1,6 +1,6 @@
package com.yao.gateWay.cache; package com.yao.gateway.cache;
import com.yao.gateWay.cache.abs.GatewayNodeAbstract; import com.yao.gateway.cache.abs.GatewayNodeAbstract;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
/** /**

View File

@ -1,6 +1,6 @@
package com.yao.gateWay.cache; package com.yao.gateway.cache;
import com.yao.gateWay.cache.abs.GatewayNodeAbstract; import com.yao.gateway.cache.abs.GatewayNodeAbstract;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
/** /**
@ -12,8 +12,4 @@ import org.springframework.stereotype.Component;
public class GatewayNodeScoreCache extends GatewayNodeAbstract { public class GatewayNodeScoreCache extends GatewayNodeAbstract {
} }

View File

@ -1,20 +1,19 @@
package com.yao.gateWay.cache; package com.yao.gateway.cache;
import com.aliyun.teautil.Common;
import com.yao.common.domain.aliy.InstanceInfo; import com.yao.common.domain.aliy.InstanceInfo;
import com.yao.gateWay.cache.abs.GatewayNodeAbstract; import com.yao.gateway.cache.abs.GatewayNodeAbstract;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.List;
import java.util.Set; import java.util.Set;
/** /**
* @Author: LiJiaYao * @Author: LiJiaYao
* @Date: 2024/4/18 * @Date: 2024/4/18
* @Description: * @Description: vin
*/ */
@Component @Component
public class GatewayAliYunCache extends GatewayNodeAbstract { public class GatewayNodeSetVinCache extends GatewayNodeAbstract {
/** /**
* *
*/ */
@ -37,4 +36,12 @@ public class GatewayAliYunCache extends GatewayNodeAbstract {
return redisService.getCacheSet(realKey); return redisService.getCacheSet(realKey);
} }
/**
* key
* @param realKey new:real:column
* @param info
*/
public void remote(String realKey,InstanceInfo info){
redisService.deleteCacheMapValue(realKey, Common.toJSONString(info));
}
} }

View File

@ -0,0 +1,44 @@
package com.yao.gateway.cache;
import com.yao.gateway.cache.abs.GatewayNodeAbstract;
import org.springframework.stereotype.Component;
import java.util.Set;
/**
* @Author: LiJiaYao
* @Date: 2024/4/18
* @Description:
*/
@Component
public class GatewayVehicleLineNodeCache extends GatewayNodeAbstract {
private final static String reconnectCar = "reconnectCar";
/**
*
* @param ip ip
*/
public void save(String ip){
redisService.setCacheSet(reconnectCar,ip);
}
/**
* ip
* @param ip ip
*/
public void address(String ip) {
redisService.setCacheSet("ECS", ip);
}
/**
* ecsip
*/
public Set<String> getAddress() {
return redisService.getCacheSet("ECS");
}
}

View File

@ -1,4 +1,4 @@
package com.yao.gateWay.cache.abs; package com.yao.gateway.cache.abs;
import com.yao.common.redis.service.RedisService; import com.yao.common.redis.service.RedisService;
@ -14,8 +14,4 @@ public abstract class GatewayNodeAbstract {
*/ */
public RedisService redisService; public RedisService redisService;
} }

View File

@ -18,7 +18,6 @@ public class LoadController {
private LoadService loadService; private LoadService loadService;
@PostMapping("/load") @PostMapping("/load")
public Result<?> loadInfo(){ public Result<?> loadInfo(){
String load = loadService.load(); return Result.success(loadService.load());
return Result.success(load);
} }
} }

View File

@ -1,9 +1,9 @@
package com.yao.server.service.impl; package com.yao.server.service.impl;
import com.yao.gateWay.cache.GateWayNodeInfo; import com.yao.gateway.cache.GateWayNodeInfo;
import com.yao.gateWay.cache.GatewayLoadNodeCache; import com.yao.gateway.cache.GatewayLoadNodeCache;
import com.yao.gateWay.cache.GatewayLoadSeriesCache; import com.yao.gateway.cache.GatewayLoadSeriesCache;
import com.yao.gateWay.cache.GatewayNodeCache; import com.yao.gateway.cache.GatewayNodeCache;
import com.yao.server.service.GatewayLoadService; import com.yao.server.service.GatewayLoadService;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;

View File

@ -3,10 +3,10 @@ package com.yao.server.service.impl;
import com.yao.common.config.Constants; import com.yao.common.config.Constants;
import com.yao.common.domain.WorkGateWayNode; import com.yao.common.domain.WorkGateWayNode;
import com.yao.common.mqtt.MqttConnectService; import com.yao.common.mqtt.MqttConnectService;
import com.yao.common.redis.service.RedisService; import com.yao.gateway.cache.GatewayArithmeticCache;
import com.yao.gateway.cache.GatewayVehicleLineNodeCache;
import com.yao.server.service.LoadService; import com.yao.server.service.LoadService;
import lombok.extern.log4j.Log4j2; import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.*; import java.util.*;
@ -21,20 +21,22 @@ import java.util.concurrent.CountDownLatch;
@Log4j2 @Log4j2
@Service @Service
public class LoadServiceImpl implements LoadService { public class LoadServiceImpl implements LoadService {
//网关算法缓存
@Autowired private final GatewayArithmeticCache gatewayArithmeticCache;
private RedisService redisService; // 网关连接车俩
private final GatewayVehicleLineNodeCache gatewayVehicleLineNodeCache;
private MqttConnectService mqttConnectService; private MqttConnectService mqttConnectService;
public LoadServiceImpl(MqttConnectService mqttConnectService) { public LoadServiceImpl(GatewayArithmeticCache gatewayArithmeticCache, GatewayVehicleLineNodeCache gatewayVehicleLineNodeCache, MqttConnectService mqttConnectService) {
this.gatewayArithmeticCache = gatewayArithmeticCache;
this.gatewayVehicleLineNodeCache = gatewayVehicleLineNodeCache;
this.mqttConnectService = mqttConnectService; this.mqttConnectService = mqttConnectService;
} }
@Override @Override
public String load() { public String load() {
//初始化序列 //初始化序列
redisService.setCacheObject("cursor", 0); gatewayArithmeticCache.count();
ArrayList<WorkGateWayNode> nodeIdList = carWorkGatewayNode(); ArrayList<WorkGateWayNode> nodeIdList = carWorkGatewayNode();
//100 //100
List<String> loadNodeList = new ArrayList<>(); List<String> loadNodeList = new ArrayList<>();
@ -68,13 +70,13 @@ public class LoadServiceImpl implements LoadService {
} }
} }
} }
redisService.deleteObject("work:node:gateway"); gatewayArithmeticCache.remove();
redisService.setCacheList("work:node:gateway", loadNodeList); gatewayArithmeticCache.loadNode(loadNodeList);
CountDownLatch countDownLatch = new CountDownLatch(300); CountDownLatch countDownLatch = new CountDownLatch(300);
new Thread(() -> { new Thread(() -> {
for (int i = 0; i < Constants.SUM; i++) { for (int i = 0; i < Constants.SUM; i++) {
long cursor = redisService.increment("cursor", 1L); long cursor = gatewayArithmeticCache.increment();
String cacheList = redisService.getCacheList("work:node:gateway", cursor % 100); String cacheList = gatewayArithmeticCache.cacheList(cursor);
log.info(cursor + "---------" + cacheList); log.info(cursor + "---------" + cacheList);
SitNode.sti(cacheList); SitNode.sti(cacheList);
countDownLatch.countDown(); countDownLatch.countDown();
@ -83,8 +85,8 @@ public class LoadServiceImpl implements LoadService {
new Thread(() -> { new Thread(() -> {
for (int i = 0; i < Constants.SUM; i++) { for (int i = 0; i < Constants.SUM; i++) {
long cursor = redisService.increment("cursor", 1L); long cursor = gatewayArithmeticCache.increment();
String cacheList = redisService.getCacheList("work:node:gateway", cursor % 100); String cacheList = gatewayArithmeticCache.cacheList(cursor);
log.info(cursor + "---------" + cacheList); log.info(cursor + "---------" + cacheList);
SitNode.sti(cacheList); SitNode.sti(cacheList);
countDownLatch.countDown(); countDownLatch.countDown();
@ -93,8 +95,8 @@ public class LoadServiceImpl implements LoadService {
new Thread(() -> { new Thread(() -> {
for (int i = 0; i < Constants.SUM; i++) { for (int i = 0; i < Constants.SUM; i++) {
Long cursor = redisService.increment("cursor", 1L); long cursor = gatewayArithmeticCache.increment();
String cacheList = redisService.getCacheList("work:node:gateway", cursor % 100); String cacheList = gatewayArithmeticCache.cacheList(cursor);
log.info(cursor + "---------" + cacheList); log.info(cursor + "---------" + cacheList);
SitNode.sti(cacheList); SitNode.sti(cacheList);
countDownLatch.countDown(); countDownLatch.countDown();
@ -123,7 +125,7 @@ public class LoadServiceImpl implements LoadService {
} }
public ArrayList<WorkGateWayNode> carWorkGatewayNode() { public ArrayList<WorkGateWayNode> carWorkGatewayNode() {
Set<String> ip = redisService.getCacheSet("ECS"); Set<String> ip = gatewayVehicleLineNodeCache.getAddress();
ArrayList<WorkGateWayNode> list = new ArrayList<>(); ArrayList<WorkGateWayNode> list = new ArrayList<>();
for (String s : ip) { for (String s : ip) {
Integer connectSize = mqttConnectService.connectMqtt(s); Integer connectSize = mqttConnectService.connectMqtt(s);
@ -170,6 +172,4 @@ class SitNode {
return map; return map;
} }
} }

View File

@ -1,11 +1,9 @@
package com.yao.server.test; package com.yao.server.test;
import com.aliyun.ecs20140526.Client;
import com.aliyun.ecs20140526.models.DescribeAvailableResourceRequest; import com.aliyun.ecs20140526.models.DescribeAvailableResourceRequest;
import com.aliyun.ecs20140526.models.DescribeAvailableResourceResponse; import com.aliyun.ecs20140526.models.DescribeAvailableResourceResponse;
import com.aliyun.tea.TeaException; import com.aliyun.tea.TeaException;
import com.aliyun.tea.TeaModel; import com.aliyun.tea.TeaModel;
import com.aliyun.teaopenapi.models.Config;
/** /**
* @Author: LiJiaYao * @Author: LiJiaYao

View File

@ -1,20 +1,16 @@
package com.yao.server.timer; package com.yao.server.timer;
import com.aliyun.teautil.Common;
import com.yao.common.aliy.AliYunEcsService; import com.yao.common.aliy.AliYunEcsService;
import com.yao.common.aliy.model.EcsSelectModel;
import com.yao.common.domain.aliy.InstanceInfo; import com.yao.common.domain.aliy.InstanceInfo;
import com.yao.common.domain.aliy.InstanceRequest;
import com.yao.common.mqtt.MqttConnectService; import com.yao.common.mqtt.MqttConnectService;
import com.yao.common.redis.service.RedisService; import com.yao.gateway.cache.GatewayNodeSetVinCache;
import com.yao.gateway.cache.GatewayVehicleLineNodeCache;
import lombok.extern.log4j.Log4j2; import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async; import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableAsync; import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.Scheduled; import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
@ -27,96 +23,60 @@ import java.util.Set;
@EnableAsync //开启异步支持 @EnableAsync //开启异步支持
@Component @Component
public class Timer { public class Timer {
private static final String realKey = "new:real:column";
@Autowired
private RedisService redisService;
private AliYunEcsService aliYunEcsService; private AliYunEcsService aliYunEcsService;
private MqttConnectService mqttConnectService; private MqttConnectService mqttConnectService;
// 阿里云缓存
private GatewayNodeSetVinCache gatewayNodeSetVinCache;
private GatewayVehicleLineNodeCache gatewayVehicleLineNodeCache;
public Timer(AliYunEcsService aliYunEcsService, MqttConnectService mqttConnectService) { public Timer(AliYunEcsService aliYunEcsService, MqttConnectService mqttConnectService, GatewayNodeSetVinCache gatewayAliYunCache, GatewayVehicleLineNodeCache gatewayVehicleLineNodeCache) {
this.aliYunEcsService = aliYunEcsService; this.aliYunEcsService = aliYunEcsService;
this.mqttConnectService = mqttConnectService; this.mqttConnectService = mqttConnectService;
this.gatewayNodeSetVinCache = gatewayAliYunCache;
this.gatewayVehicleLineNodeCache = gatewayVehicleLineNodeCache;
} }
@Async @Async
@Scheduled(cron = "0/20 * * * * ?") @Scheduled(cron = "0/20 * * * * ?")
public void timer() { public void timer() {
long startTime = System.currentTimeMillis(); // 记录开始时间 // 记录开始时间
long endTime = startTime + 10 * 60 * 1000; // 设置结束时间为10分钟后 long startTime = System.currentTimeMillis();
// redisService.deleteObject("new:real:column"); // 设置结束时间为10分钟后
Set<InstanceInfo> instance = redisService.getCacheSet("new:real:column"); long endTime = startTime + 10 * 60 * 1000;
// List<InstanceInfo> myFirstEcsInstance = null; Set<InstanceInfo> instance = gatewayNodeSetVinCache.get(realKey);
// try { if (instance.isEmpty()) {
// myFirstEcsInstance = aliYunEcsService.selectList(ecsSelectModelName("MyFirstEcsInstance")); try {
// for (InstanceInfo instanceInfo : myFirstEcsInstance) { aliYunEcsService.startCreate();
// String publicIpAddress = instanceInfo.getPublicIpAddress(); } catch (Exception e) {
// String instanceId = instanceInfo.getInstanceId(); throw new RuntimeException(e);
// InstanceRequest instanceRequest = new InstanceRequest(publicIpAddress, instanceId); }
// redisService.setCacheSet("new:real:column", instanceRequest); }
// } for (InstanceInfo s : instance) {
if (instance.isEmpty()) { Integer connectSize = mqttConnectService.connectMqtt(s.getPublicIpAddress());
// if (myFirstEcsInstance.isEmpty()) { List<String> instanceId = null;
String deleteInstanceId = null;
if (connectSize >= 79) {
//执行节点扩容
//返回实例的ID
if (!instanceId.isEmpty()) {
try { try {
aliYunEcsService.startCreate(); instanceId = aliYunEcsService.startCreate();
log.info("扩容成功!");
log.info("扩容的节点id为" + instanceId);
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
// }
}
for (InstanceInfo s : instance) {
Integer connectSize = mqttConnectService.connectMqtt(s.getPublicIpAddress());
List<String> instanceId = null;
String deleteInstanceId = null;
if (connectSize >= 80) {
//执行节点扩容
//返回实例的ID
if (!instanceId.isEmpty()) {
try {
instanceId = aliYunEcsService.startCreate();
log.info("扩容成功!");
log.info("扩容的节点id为" + instanceId);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
if (connectSize <= 20 && System.currentTimeMillis() < endTime) {
// if (!deleteInstanceId.isEmpty()) {
aliYunEcsService.delete(s.getInstanceId());
//删除实列以后再去把redis的值删除 再去通知重新上线
redisService.deleteCacheMapValue("new:real:column", Common.toJSONString(s));
redisService.setCacheSet("reconnectCar",s.getPublicIpAddress());
log.info("缩容成功!");
log.info("锁容的节点id为" + deleteInstanceId);
} }
} }
// } catch (Exception e) { if (connectSize <= 20 && System.currentTimeMillis() < endTime) {
// throw new RuntimeException(e); aliYunEcsService.delete(s.getInstanceId());
//删除实列以后再去把redis的值删除 再去通知重新上线
gatewayNodeSetVinCache.remote(realKey, s);
gatewayVehicleLineNodeCache.save(s.getPublicIpAddress());
log.info("缩容成功!");
log.info("锁容的节点id为" + deleteInstanceId);
}
} }
} }
}
/**
*
*
* @param instance
* @return
*/
// public EcsSelectModel ecsSelectModel(Set<InstanceInfo> instance) {
// List<String> instanceIdList = new ArrayList<>();
// for (InstanceInfo req : instance) {
// instanceIdList.add(req.getInstanceId());
// }
// EcsSelectModel ecsSelectModel = new EcsSelectModel();
// ecsSelectModel.setInstanceIdList(instanceIdList);
// return ecsSelectModel;
// }
// public EcsSelectModel ecsSelectModelName(String instanceName) {
// List<String> instanceIdList = new ArrayList<>();
// instanceIdList.add(instanceName);
// EcsSelectModel ecsSelectModel = new EcsSelectModel();
// ecsSelectModel.setInstanceIdList(instanceIdList);
// return ecsSelectModel;
// }
//}

View File

@ -20,13 +20,10 @@ import java.util.concurrent.CountDownLatch;
@SpringBootTest(classes = APISpringBootApplication.class) @SpringBootTest(classes = APISpringBootApplication.class)
public class LoadService1 { public class LoadService1 {
@Autowired
private RedisService redisService;
@Test @Test
public void load() { public void load() {
//初始化序列 //初始化序列
redisService.setCacheObject("cursor",0); // redisService.setCacheObject("cursor",0);
List<WorkGateWayNode> nodeIdList = new ArrayList() { List<WorkGateWayNode> nodeIdList = new ArrayList() {
{ {
@ -77,33 +74,33 @@ public class LoadService1 {
// for (int i = 0; i < 100; i++) { // for (int i = 0; i < 100; i++) {
// loadNodeList.add(nodeIdList.get(i % nodeIdList.size())); // loadNodeList.add(nodeIdList.get(i % nodeIdList.size()));
// } // }
redisService.deleteObject("work:node:gateway"); // redisService.deleteObject("work:node:gateway");
redisService.setCacheList("work:node:gateway",loadNodeList); // redisService.setCacheList("work:node:gateway",loadNodeList);
CountDownLatch countDownLatch = new CountDownLatch(300); CountDownLatch countDownLatch = new CountDownLatch(300);
new Thread(()->{ new Thread(()->{
for (int i = 0; i < 100; i++) { for (int i = 0; i < 100; i++) {
Long cursor = redisService.increment("cursor", 1L); // Long cursor = redisService.increment("cursor", 1L);
String cacheList = redisService.getCacheList("work:node:gateway", cursor % 100); // String cacheList = redisService.getCacheList("work:node:gateway", cursor % 100);
log.info(cursor+"---------"+cacheList); // log.info(cursor+"---------"+cacheList);
SitNode.sti(cacheList); // SitNode.sti(cacheList);
countDownLatch.countDown(); countDownLatch.countDown();
} }
}).start(); }).start();
new Thread(()->{ new Thread(()->{
for (int i = 0; i < 100; i++) { for (int i = 0; i < 100; i++) {
Long cursor = redisService.increment("cursor", 1L); // Long cursor = redisService.increment("cursor", 1L);
String cacheList = redisService.getCacheList("work:node:gateway", cursor % 100); // String cacheList = redisService.getCacheList("work:node:gateway", cursor % 100);
log.info(cursor+"---------"+cacheList); // log.info(cursor+"---------"+cacheList);
SitNode.sti(cacheList); // SitNode.sti(cacheList);
countDownLatch.countDown(); countDownLatch.countDown();
} }
}).start(); }).start();
new Thread(()->{ new Thread(()->{
for (int i = 0; i < 100; i++) { for (int i = 0; i < 100; i++) {
Long cursor = redisService.increment("cursor", 1L); // Long cursor = redisService.increment("cursor", 1L);
String cacheList = redisService.getCacheList("work:node:gateway", cursor % 100); // String cacheList = redisService.getCacheList("work:node:gateway", cursor % 100);
log.info(cursor+"---------"+cacheList); // log.info(cursor+"---------"+cacheList);
SitNode.sti(cacheList); // SitNode.sti(cacheList);
countDownLatch.countDown(); countDownLatch.countDown();
} }
}).start(); }).start();