Search in sources :

Example 6 with ServerInfo

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));
    }
}
Also used : Jedis(redis.clients.jedis.Jedis) RoundRobinLoadBalancingStrategy(net.azisaba.kuvel.loadbalancer.strategy.impl.RoundRobinLoadBalancingStrategy) ServerInfo(com.velocitypowered.api.proxy.server.ServerInfo) InetSocketAddress(java.net.InetSocketAddress) RegisteredServer(com.velocitypowered.api.proxy.server.RegisteredServer) LoadBalancer(net.azisaba.kuvel.loadbalancer.LoadBalancer)

Example 7 with ServerInfo

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();
    }
}
Also used : Pod(io.fabric8.kubernetes.api.model.Pod) InetSocketAddress(java.net.InetSocketAddress) ServerInfo(com.velocitypowered.api.proxy.server.ServerInfo) LoadBalancer(net.azisaba.kuvel.loadbalancer.LoadBalancer)

Example 8 with ServerInfo

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() + ")");
}
Also used : InetSocketAddress(java.net.InetSocketAddress) ServerInfo(com.velocitypowered.api.proxy.server.ServerInfo) LoadBalancer(net.azisaba.kuvel.loadbalancer.LoadBalancer)

Example 9 with ServerInfo

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);
}
Also used : RoundRobinLoadBalancingStrategy(net.azisaba.kuvel.loadbalancer.strategy.impl.RoundRobinLoadBalancingStrategy) Jedis(redis.clients.jedis.Jedis) ServerInfo(com.velocitypowered.api.proxy.server.ServerInfo) InetSocketAddress(java.net.InetSocketAddress) RegisteredServer(com.velocitypowered.api.proxy.server.RegisteredServer) LoadBalancer(net.azisaba.kuvel.loadbalancer.LoadBalancer) JedisPubSub(redis.clients.jedis.JedisPubSub)

Example 10 with ServerInfo

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();
    }
}
Also used : CachedPlayer(net.ME1312.SubServers.Velocity.Server.CachedPlayer) RSA(net.ME1312.SubData.Client.Encryption.RSA) Player(com.velocitypowered.api.proxy.Player) CachedPlayer(net.ME1312.SubServers.Velocity.Server.CachedPlayer) PacketDisconnectPlayer(net.ME1312.SubServers.Client.Common.Network.Packet.PacketDisconnectPlayer) PacketExSyncPlayer(net.ME1312.SubServers.Velocity.Network.Packet.PacketExSyncPlayer) ServerInfo(com.velocitypowered.api.proxy.server.ServerInfo) IOException(java.io.IOException) File(java.io.File) IOException(java.io.IOException) AES(net.ME1312.SubData.Client.Encryption.AES) Subscribe(com.velocitypowered.api.event.Subscribe)

Aggregations

ServerInfo (com.velocitypowered.api.proxy.server.ServerInfo)12 InetSocketAddress (java.net.InetSocketAddress)8 Player (com.velocitypowered.api.proxy.Player)5 RegisteredServer (com.velocitypowered.api.proxy.server.RegisteredServer)5 LoadBalancer (net.azisaba.kuvel.loadbalancer.LoadBalancer)4 Subscribe (com.velocitypowered.api.event.Subscribe)3 CachedPlayer (net.ME1312.SubServers.Velocity.Server.CachedPlayer)3 Component (net.kyori.adventure.text.Component)3 Gson (com.google.gson.Gson)2 ServerConnection (com.velocitypowered.api.proxy.ServerConnection)2 BufferedReader (java.io.BufferedReader)2 InputStreamReader (java.io.InputStreamReader)2 URL (java.net.URL)2 Charset (java.nio.charset.Charset)2 java.util (java.util)2 TimeUnit (java.util.concurrent.TimeUnit)2 Pair (net.ME1312.Galaxi.Library.Container.Pair)2 ObjectMap (net.ME1312.Galaxi.Library.Map.ObjectMap)2 Try (net.ME1312.Galaxi.Library.Try)2 Util (net.ME1312.Galaxi.Library.Util)2