use of com.velocitypowered.api.proxy.server.ServerInfo in project Kuvel by AzisabaNetwork.
the class RedisLoadBalancerDiscovery method registerOrIgnore.
private void registerOrIgnore(ReplicaSet replicaSet, boolean isFetchedFromRedis) {
String uid = replicaSet.getMetadata().getUid();
if (kuvelServiceHandler.getReplicaSetUidAndServerNameMap().getServerNameFromUid(uid) != null) {
return;
}
String serverName = replicaSet.getMetadata().getLabels().getOrDefault(LabelKeys.SERVER_NAME.getKey(), null);
if (serverName == null) {
return;
}
try (Jedis jedis = jedisPool.getResource()) {
if (!isFetchedFromRedis) {
Collection<String> loadBalancerNames = jedis.hgetAll(RedisKeys.LOAD_BALANCERS_PREFIX.getKey() + groupName).values();
if (loadBalancerNames.contains(serverName) || plugin.getProxy().getServer(serverName).isPresent()) {
plugin.getLogger().info("Failed to add load balancer. Server name already occupied: " + serverName);
return;
}
}
kuvelServiceHandler.getReplicaSetUidAndServerNameMap().register(uid, serverName);
jedis.hset(RedisKeys.LOAD_BALANCERS_PREFIX.getKey() + groupName, uid, serverName);
redisConnectionLeader.publishNewLoadBalancer(uid, serverName);
RegisteredServer server = plugin.getProxy().registerServer(new ServerInfo(serverName, new InetSocketAddress("0.0.0.0", 0)));
kuvelServiceHandler.registerLoadBalancer(new LoadBalancer(plugin.getProxy(), server, new RoundRobinLoadBalancingStrategy(), uid));
}
}
use of com.velocitypowered.api.proxy.server.ServerInfo in project Kuvel by AzisabaNetwork.
the class KuvelServiceHandler method setAndRunServerDiscovery.
public void setAndRunServerDiscovery(@Nullable ServerDiscovery newServerDiscovery) {
if (serverDiscovery != null) {
serverDiscovery.shutdown();
}
serverDiscovery = newServerDiscovery;
if (serverDiscovery != null) {
HashMap<String, Pod> servers = serverDiscovery.getServersForStartup();
for (Entry<String, Pod> entry : servers.entrySet()) {
Pod pod = entry.getValue();
InetSocketAddress address = new InetSocketAddress(pod.getStatus().getPodIP(), 25565);
plugin.getProxy().registerServer(new ServerInfo(entry.getKey(), address));
for (LoadBalancer loadBalancer : loadBalancerServerMap.values()) {
if (pod.hasOwnerReferenceFor(loadBalancer.getReplicaSetUid())) {
loadBalancer.addEndpoint(entry.getKey());
}
}
}
serverDiscovery.start();
}
}
use of com.velocitypowered.api.proxy.server.ServerInfo in project Kuvel by AzisabaNetwork.
the class KuvelServiceHandler method registerPod.
public void registerPod(Pod pod, String serverName) {
InetSocketAddress address = new InetSocketAddress(pod.getStatus().getPodIP(), 25565);
plugin.getProxy().registerServer(new ServerInfo(serverName, address));
podUidAndServerNameMap.register(pod.getMetadata().getUid(), serverName);
for (LoadBalancer loadBalancer : loadBalancerServerMap.values()) {
if (pod.hasOwnerReferenceFor(loadBalancer.getReplicaSetUid())) {
loadBalancer.addEndpoint(serverName);
}
}
plugin.getLogger().info("Registered server: " + serverName + " (" + pod.getMetadata().getUid() + ")");
}
use of com.velocitypowered.api.proxy.server.ServerInfo in project Kuvel by AzisabaNetwork.
the class RedisSubscriber method subscribe.
public void subscribe() {
JedisPubSub subscriber = new JedisPubSub() {
@Override
public void onPMessage(String pattern, String channel, String message) {
String receivedGroupName = channel.split(":")[channel.split(":").length - 1];
if (!receivedGroupName.equalsIgnoreCase(groupName)) {
return;
}
if (channel.startsWith(RedisKeys.LEADER_CHANGED_NOTIFY_PREFIX.getKey()) || channel.startsWith(RedisKeys.LEADER_LEAVE_NOTIFY_PREFIX.getKey())) {
redisConnectionLeader.trySwitch();
return;
}
if (redisConnectionLeader.isLeader()) {
return;
}
if (channel.startsWith(RedisKeys.POD_ADDED_NOTIFY_PREFIX.getKey())) {
String podUid = message.split(":")[0];
String serverName = message.split(":")[1];
handler.registerPod(podUid, serverName);
} else if (channel.startsWith(RedisKeys.LOAD_BALANCER_ADDED_NOTIFY_PREFIX.getKey())) {
String replicaSetUid = message.split(":")[0];
String serverName = message.split(":")[1];
RegisteredServer server = plugin.getProxy().registerServer(new ServerInfo(serverName, new InetSocketAddress("0.0.0.0", 0)));
LoadBalancer loadBalancer = new LoadBalancer(plugin.getProxy(), server, new RoundRobinLoadBalancingStrategy(), replicaSetUid);
handler.registerLoadBalancer(loadBalancer);
} else if (channel.startsWith(RedisKeys.POD_DELETED_NOTIFY_PREFIX.getKey())) {
handler.unregisterPod(message);
} else if (channel.startsWith(RedisKeys.LOAD_BALANCER_DELETED_NOTIFY_PREFIX.getKey())) {
handler.unregisterLoadBalancer(message);
}
}
};
Runnable task = () -> {
try (Jedis jedis = jedisPool.getResource()) {
jedis.psubscribe(subscriber, RedisKeys.NOTIFY_CHANNEL_PREFIX.getKey() + "*:" + groupName);
}
};
runsOnExecutor(executorService, task);
}
use of com.velocitypowered.api.proxy.server.ServerInfo in project SubServers-2 by ME1312.
the class ExProxy method initialize.
/**
* Load Hosts, Servers, SubServers, and SubData Direct
*/
@Subscribe
public void initialize(ProxyInitializeEvent e) {
try {
running = true;
SmartFallback.dns_forward = config.get().getMap("Settings").getMap("Smart-Fallback", new ObjectMap<>()).getBoolean("DNS-Forward", false);
resetDate = Calendar.getInstance().getTime().getTime();
ConfigUpdater.updateConfig(new File(dir, "SubServers/sync.yml"));
config.reload();
synchronized (rPlayers) {
for (Player local : proxy.getAllPlayers()) {
CachedPlayer player = new CachedPlayer(local);
rPlayerLinkP.put(player.getUniqueId(), player.getProxyName().toLowerCase());
rPlayers.put(player.getUniqueId(), player);
ServerInfo server = local.getCurrentServer().map(ServerConnection::getServerInfo).orElse(null);
if (servers.containsKey(server))
rPlayerLinkS.put(player.getUniqueId(), servers.get(server));
}
}
subprotocol.unregisterCipher("AES");
subprotocol.unregisterCipher("AES-128");
subprotocol.unregisterCipher("AES-192");
subprotocol.unregisterCipher("AES-256");
subprotocol.unregisterCipher("RSA");
api.name = config.get().getMap("Settings").getMap("SubData").getString("Name");
if (config.get().getMap("Settings").getMap("SubData").getString("Password", "").length() > 0) {
subprotocol.registerCipher("AES", new AES(128, config.get().getMap("Settings").getMap("SubData").getString("Password")));
subprotocol.registerCipher("AES-128", new AES(128, config.get().getMap("Settings").getMap("SubData").getString("Password")));
subprotocol.registerCipher("AES-192", new AES(192, config.get().getMap("Settings").getMap("SubData").getString("Password")));
subprotocol.registerCipher("AES-256", new AES(256, config.get().getMap("Settings").getMap("SubData").getString("Password")));
Logger.get("SubData").info("AES Encryption Available");
}
if (new File(dir, "SubServers/subdata.rsa.key").exists()) {
try {
subprotocol.registerCipher("RSA", new RSA(new File(dir, "SubServers/subdata.rsa.key")));
Logger.get("SubData").info("RSA Encryption Available");
} catch (Exception x) {
x.printStackTrace();
}
}
reconnect = true;
Logger.get("SubData").info("");
Logger.get("SubData").info("Connecting to /" + config.get().getMap("Settings").getMap("SubData").getString("Address", "127.0.0.1:4391"));
connect(Logger.get("SubData"), null);
if (!posted) {
posted = true;
post();
}
} catch (IOException x) {
x.printStackTrace();
}
}
Aggregations