Search in sources :

Example 1 with ServiceInfoSnapshot

use of de.dytanic.cloudnet.driver.service.ServiceInfoSnapshot in project SickCore by SickMC.

the class ListCommand method openServerInv.

private void openServerInv(BukkitPlayer bukkitPlayer) {
    HeadDatabaseAPI api = HeadDBAPI.getApi();
    PagedInventoryBuilder builder = new PagedInventoryBuilder(bukkitPlayer, "§6List");
    for (ServiceInfoSnapshot service : CloudNetDriver.getInstance().getCloudServiceProvider().getStartedCloudServices()) {
        if (service.getName().startsWith("Proxy-"))
            continue;
        ItemStack itemStack = null;
        if (service.getName().startsWith("Lobby"))
            itemStack = api.getItemHead("30032");
        if (service.getName().startsWith("Build"))
            itemStack = api.getItemHead("157");
        if (service.getName().startsWith("Survival"))
            itemStack = api.getItemHead("50099");
        if (itemStack == null)
            itemStack = api.getItemHead("8767");
        builder.addItem(new ItemBuilder(itemStack, bukkitPlayer).setName("§6" + service.getName()).setLore("§7Players: §6" + sadsadsd, "§7Group: §6" + service.getGroupName(), "§7Click to connect to this server!"), service.getOnlineCount(), event -> {
            bukkitPlayer.api().cloud().cloudAPI().connect(service);
            DefaultSounds.levelUP.play(bukkitPlayer);
            bukkitPlayer.getPlayer().sendMessage((String) bukkitPlayer.api().languageObject("§7You were teleported to the server " + service.getName() + "!", "§7Du wurdest zum Server " + service.getName() + " teleportiert!"));
        });
    }
    builder.open();
}
Also used : ItemBuilder(me.anton.sickcore.api.utils.minecraft.bukkit.item.ItemBuilder) ServiceInfoSnapshot(de.dytanic.cloudnet.driver.service.ServiceInfoSnapshot) PagedInventoryBuilder(me.anton.sickcore.api.utils.minecraft.bukkit.inventory.PagedInventoryBuilder) HeadDatabaseAPI(me.arcaniax.hdb.api.HeadDatabaseAPI) ItemStack(org.bukkit.inventory.ItemStack)

Example 2 with ServiceInfoSnapshot

use of de.dytanic.cloudnet.driver.service.ServiceInfoSnapshot in project SickCore by SickMC.

the class MaintenanceModule method enable.

public void enable(boolean secure) {
    this.secure = secure;
    active = true;
    Document document = config.getDocument();
    document.replace("active", true);
    if (secure)
        document.replace("secureMode", true);
    config.update(document);
    for (ServiceInfoSnapshot service : CloudNetDriver.getInstance().getCloudServiceProvider().getCloudServices()) {
        if (!service.getName().startsWith("Lobby-"))
            return;
        CloudNetDriver.getInstance().getServicesRegistry().getFirstService(IPlayerManager.class).onlinePlayers().asPlayers().forEach(player -> {
            if (!secure)
                if (!new CloudAPIPlayer(player.getUniqueId()).api().isTeam())
                    player.getPlayerExecutor().kick("Maintenance is now enabled!");
                else if (!player.getUniqueId().equals(UUID.fromString("84c7eef5-ae2c-4ebb-a006-c3ee07643d79")))
                    player.getPlayerExecutor().kick("Maintenance is now enabled!");
        });
    }
}
Also used : CloudAPIPlayer(me.anton.sickcore.api.player.cloudPlayer.CloudAPIPlayer) ServiceInfoSnapshot(de.dytanic.cloudnet.driver.service.ServiceInfoSnapshot) IPlayerManager(de.dytanic.cloudnet.ext.bridge.player.IPlayerManager) Document(org.bson.Document)

Example 3 with ServiceInfoSnapshot

use of de.dytanic.cloudnet.driver.service.ServiceInfoSnapshot in project CloudNet-v3 by CloudNetService.

the class CommandReport method postReportOutput.

private void postReportOutput(Writer w, long millis) throws IOException {
    try (PrintWriter writer = new PrintWriter(w, true)) {
        writer.println("Report from " + new SimpleDateFormat("dd.MM.yyyy HH:mm:ss").format(millis));
        writer.println();
        writer.println("Last Event Publisher Class: " + CloudNetReportModule.getInstance().getEventClass());
        writer.println();
        writer.println("Last log lines");
        for (LogEntry logEntry : CloudNet.getInstance().getQueuedConsoleLogHandler().getCachedQueuedLogEntries()) {
            if (logEntry.getMessages() != null) {
                for (String message : logEntry.getMessages()) {
                    if (message != null) {
                        writer.println("[" + LOG_FORMAT.format(logEntry.getTimeStamp()) + "] " + logEntry.getLogLevel().getUpperName() + " | Thread: " + logEntry.getThread().getName() + " | Class: " + logEntry.getClazz().getName() + ": " + message);
                        if (logEntry.getThrowable() != null) {
                            logEntry.getThrowable().printStackTrace(writer);
                        }
                    }
                }
            }
        }
        writer.println();
        writer.println("###################################################################################");
        System.getProperties().store(writer, "System Properties");
        writer.println();
        Collection<Map.Entry<Thread, StackTraceElement[]>> threads = Thread.getAllStackTraces().entrySet();
        writer.println("Threads: " + threads.size());
        for (Map.Entry<Thread, StackTraceElement[]> entry : threads) {
            writer.println("Thread " + entry.getKey().getId() + " | " + entry.getKey().getName() + " | " + entry.getKey().getState());
            writer.println("- Daemon: " + entry.getKey().isDaemon() + " | isAlive: " + entry.getKey().isAlive() + " | Priority: " + entry.getKey().getPriority());
            writer.println("- Context ClassLoader: " + (entry.getKey().getContextClassLoader() != null ? entry.getKey().getContextClassLoader().getClass().getName() : "not defined"));
            writer.println("- ThreadGroup: " + entry.getKey().getThreadGroup().getName());
            writer.println();
            writer.println("- Stack");
            writer.println();
            for (StackTraceElement element : entry.getValue()) {
                writer.println(element.toString());
            }
            writer.println();
        }
        writer.println("###################################################################################");
        writer.println("Remote nodes: ");
        for (IClusterNodeServer clusterNodeServer : CloudNet.getInstance().getClusterNodeServerProvider().getNodeServers()) {
            writer.println("Node: " + clusterNodeServer.getNodeInfo().getUniqueId() + " | Connected: " + clusterNodeServer.isConnected());
            gson.toJson(clusterNodeServer.getNodeInfo(), writer);
            if (clusterNodeServer.getNodeInfoSnapshot() != null) {
                writer.println();
                gson.toJson(clusterNodeServer.getNodeInfoSnapshot(), writer);
            }
            writer.println();
        }
        writer.println("###################################################################################");
        writer.println("Services: " + CloudNetDriver.getInstance().getCloudServiceProvider().getCloudServices().size());
        for (ServiceInfoSnapshot serviceInfoSnapshot : CloudNetDriver.getInstance().getCloudServiceProvider().getCloudServices()) {
            writer.println("* Service " + serviceInfoSnapshot.getServiceId().getName() + " | " + serviceInfoSnapshot.getServiceId().getUniqueId());
            gson.toJson(serviceInfoSnapshot, writer);
            writer.println();
            writer.println("Console receivedMessages:");
            for (String entry : serviceInfoSnapshot.provider().getCachedLogMessages()) {
                writer.println(entry);
            }
            writer.println();
        }
        writer.println("###################################################################################");
        writer.println("Commands:");
        for (CommandInfo commandInfo : CloudNet.getInstance().getCommandMap().getCommandInfos()) {
            gson.toJson(commandInfo, writer);
            writer.println();
        }
        writer.println("###################################################################################");
        writer.println("Modules:");
        for (IModuleWrapper moduleWrapper : CloudNetDriver.getInstance().getModuleProvider().getModules()) {
            writer.println(moduleWrapper.getModuleConfiguration().getName() + " | " + moduleWrapper.getModuleLifeCycle());
            writer.println();
            gson.toJson(moduleWrapper.getModuleConfigurationSource(), writer);
            writer.println();
            writer.println("- ModuleTasks");
            for (Map.Entry<ModuleLifeCycle, List<IModuleTaskEntry>> moduleLifeCycleListEntry : moduleWrapper.getModuleTasks().entrySet()) {
                writer.println("ModuleTask: " + moduleLifeCycleListEntry.getKey());
                for (IModuleTaskEntry moduleTaskEntry : moduleLifeCycleListEntry.getValue()) {
                    writer.println("Order: " + moduleTaskEntry.getTaskInfo().order() + " | " + moduleTaskEntry.getHandler().getName());
                }
            }
            writer.println();
        }
        writer.println("###################################################################################");
        writer.println("Service Registry:");
        for (Class<?> c : CloudNetDriver.getInstance().getServicesRegistry().getProvidedServices()) {
            writer.println("Registry Item Class: " + c.getName());
            for (Object item : CloudNetDriver.getInstance().getServicesRegistry().getServices(c)) {
                writer.println("- " + item.getClass().getName());
            }
            writer.println();
        }
    }
}
Also used : IModuleWrapper(de.dytanic.cloudnet.driver.module.IModuleWrapper) IModuleTaskEntry(de.dytanic.cloudnet.driver.module.IModuleTaskEntry) LogEntry(de.dytanic.cloudnet.common.logging.LogEntry) IModuleTaskEntry(de.dytanic.cloudnet.driver.module.IModuleTaskEntry) CommandInfo(de.dytanic.cloudnet.common.command.CommandInfo) ServiceInfoSnapshot(de.dytanic.cloudnet.driver.service.ServiceInfoSnapshot) ModuleLifeCycle(de.dytanic.cloudnet.driver.module.ModuleLifeCycle) IClusterNodeServer(de.dytanic.cloudnet.cluster.IClusterNodeServer) List(java.util.List) SimpleDateFormat(java.text.SimpleDateFormat) Map(java.util.Map) LogEntry(de.dytanic.cloudnet.common.logging.LogEntry)

Example 4 with ServiceInfoSnapshot

use of de.dytanic.cloudnet.driver.service.ServiceInfoSnapshot in project CloudNet-v3 by CloudNetService.

the class V1HttpHandlerServices method handleGet.

@Override
public void handleGet(String path, IHttpContext context) {
    if (context.request().pathParameters().containsKey("uuid")) {
        ServiceInfoSnapshot serviceInfoSnapshot = CloudNetDriver.getInstance().getCloudServiceProvider().getCloudServices().stream().filter(serviceInfoSnapshot12 -> serviceInfoSnapshot12.getServiceId().getUniqueId().toString().contains(context.request().pathParameters().get("uuid"))).findFirst().orElse(null);
        if (serviceInfoSnapshot == null) {
            serviceInfoSnapshot = CloudNetDriver.getInstance().getCloudServiceProvider().getCloudServices().stream().filter(serviceInfoSnapshot1 -> serviceInfoSnapshot1.getServiceId().getName().contains(context.request().pathParameters().get("uuid"))).findFirst().orElse(null);
        }
        if (serviceInfoSnapshot == null) {
            context.response().statusCode(HttpResponseCode.HTTP_NOT_FOUND).context().closeAfter(true).cancelNext();
            return;
        }
        if (context.request().pathParameters().containsKey("operation")) {
            switch(context.request().pathParameters().get("operation").toLowerCase()) {
                case "start":
                    {
                        serviceInfoSnapshot.provider().start();
                        context.response().statusCode(HttpResponseCode.HTTP_OK).header("Content-Type", "application/json").body(GSON.toJson(serviceInfoSnapshot));
                    }
                    break;
                case "stop":
                    {
                        serviceInfoSnapshot.provider().stop();
                        context.response().statusCode(HttpResponseCode.HTTP_OK).header("Content-Type", "application/json").body(GSON.toJson(serviceInfoSnapshot));
                    }
                    break;
                case "delete":
                    {
                        serviceInfoSnapshot.provider().delete();
                        context.response().statusCode(HttpResponseCode.HTTP_OK).header("Content-Type", "application/json").body(GSON.toJson(serviceInfoSnapshot));
                    }
                    break;
                case "log":
                    {
                        Queue<String> queue = serviceInfoSnapshot.provider().getCachedLogMessages();
                        StringBuilder stringBuilder = new StringBuilder();
                        for (String item : queue) {
                            stringBuilder.append(item).append("\n");
                        }
                        context.response().statusCode(HttpResponseCode.HTTP_OK).header("Content-Type", "text/plain").body(stringBuilder.toString());
                    }
                    break;
                case "log_json":
                    {
                        Queue<String> queue = serviceInfoSnapshot.provider().getCachedLogMessages();
                        context.response().statusCode(HttpResponseCode.HTTP_OK).header("Content-Type", "application/json").body(GSON.toJson(queue));
                    }
                    break;
            }
        } else {
            context.response().statusCode(HttpResponseCode.HTTP_OK).header("Content-Type", "application/json").body(GSON.toJson(serviceInfoSnapshot));
        }
        context.closeAfter(true).cancelNext();
        return;
    }
    context.response().header("Content-Type", "application/json").body(GSON.toJson(CloudNetDriver.getInstance().getCloudServiceProvider().getCloudServices().stream().filter(serviceInfoSnapshot -> {
        if (context.request().queryParameters().containsKey("name") && !context.request().queryParameters().get("name").contains(serviceInfoSnapshot.getServiceId().getName())) {
            return false;
        }
        if (context.request().queryParameters().containsKey("task") && !context.request().queryParameters().get("task").contains(serviceInfoSnapshot.getServiceId().getTaskName())) {
            return false;
        }
        return !context.request().queryParameters().containsKey("node") || context.request().queryParameters().get("node").contains(serviceInfoSnapshot.getServiceId().getNodeUniqueId());
    }).collect(Collectors.toList()))).statusCode(200).context().closeAfter(true).cancelNext();
}
Also used : CloudNetDriver(de.dytanic.cloudnet.driver.CloudNetDriver) IHttpContext(de.dytanic.cloudnet.driver.network.http.IHttpContext) ServiceInfoSnapshot(de.dytanic.cloudnet.driver.service.ServiceInfoSnapshot) HttpResponseCode(de.dytanic.cloudnet.driver.network.http.HttpResponseCode) V1HttpHandler(de.dytanic.cloudnet.http.V1HttpHandler) Queue(java.util.Queue) Collectors(java.util.stream.Collectors) ServiceInfoSnapshot(de.dytanic.cloudnet.driver.service.ServiceInfoSnapshot) Queue(java.util.Queue)

Example 5 with ServiceInfoSnapshot

use of de.dytanic.cloudnet.driver.service.ServiceInfoSnapshot in project CloudNet-v3 by CloudNetService.

the class CommandCopy method execute.

@Override
public void execute(ICommandSender sender, String command, String[] args, String commandLine, Properties properties) {
    if (args.length == 0) {
        sender.sendMessage("cp <local service uniqueId | name> [excludes: spigot.jar;logs;plugins] | template=storage:prefix/name");
        return;
    }
    ServiceInfoSnapshot serviceInfoSnapshot = super.getCloudNet().getCloudServiceByNameOrUniqueId(args[0]);
    if (serviceInfoSnapshot != null) {
        SpecificCloudServiceProvider cloudServiceProvider = serviceInfoSnapshot.provider();
        ServiceTemplate targetTemplate;
        if (properties.containsKey("template")) {
            targetTemplate = ServiceTemplate.parse(properties.get("template"));
        } else {
            targetTemplate = Arrays.stream(serviceInfoSnapshot.getConfiguration().getTemplates()).filter(serviceTemplate -> serviceTemplate.getPrefix().equalsIgnoreCase(serviceInfoSnapshot.getServiceId().getTaskName()) && serviceTemplate.getName().equalsIgnoreCase("default")).findFirst().orElse(null);
        }
        if (targetTemplate == null) {
            sender.sendMessage(LanguageManager.getMessage("command-copy-service-no-default-template").replace("%name%", serviceInfoSnapshot.getServiceId().getName()));
            return;
        }
        List<ServiceDeployment> oldDeployments = new ArrayList<>(Arrays.asList(serviceInfoSnapshot.getConfiguration().getDeployments()));
        List<String> excludes = args.length == 2 ? Arrays.asList(args[1].split(";")) : Collections.emptyList();
        cloudServiceProvider.addServiceDeployment(new ServiceDeployment(targetTemplate, excludes));
        cloudServiceProvider.deployResources(true);
        oldDeployments.forEach(cloudServiceProvider::addServiceDeployment);
        sender.sendMessage(LanguageManager.getMessage("command-copy-success").replace("%name%", serviceInfoSnapshot.getServiceId().getName()).replace("%template%", targetTemplate.getStorage() + ":" + targetTemplate.getPrefix() + "/" + targetTemplate.getName()));
    }
}
Also used : ServiceDeployment(de.dytanic.cloudnet.driver.service.ServiceDeployment) ServiceInfoSnapshot(de.dytanic.cloudnet.driver.service.ServiceInfoSnapshot) java.util(java.util) Properties(de.dytanic.cloudnet.common.Properties) SpecificCloudServiceProvider(de.dytanic.cloudnet.driver.provider.service.SpecificCloudServiceProvider) ITabCompleter(de.dytanic.cloudnet.command.ITabCompleter) ServiceTemplate(de.dytanic.cloudnet.driver.service.ServiceTemplate) ICommandSender(de.dytanic.cloudnet.command.ICommandSender) Collectors(java.util.stream.Collectors) LanguageManager(de.dytanic.cloudnet.common.language.LanguageManager) ServiceInfoSnapshot(de.dytanic.cloudnet.driver.service.ServiceInfoSnapshot) ServiceTemplate(de.dytanic.cloudnet.driver.service.ServiceTemplate) SpecificCloudServiceProvider(de.dytanic.cloudnet.driver.provider.service.SpecificCloudServiceProvider) ServiceDeployment(de.dytanic.cloudnet.driver.service.ServiceDeployment)

Aggregations

ServiceInfoSnapshot (de.dytanic.cloudnet.driver.service.ServiceInfoSnapshot)31 Collectors (java.util.stream.Collectors)8 EventListener (de.dytanic.cloudnet.driver.event.EventListener)6 NetworkServiceInfo (de.dytanic.cloudnet.ext.bridge.player.NetworkServiceInfo)5 Preconditions (com.google.common.base.Preconditions)4 HostAndPort (de.dytanic.cloudnet.driver.network.HostAndPort)4 BridgeHelper (de.dytanic.cloudnet.ext.bridge.BridgeHelper)4 PluginInfo (de.dytanic.cloudnet.ext.bridge.PluginInfo)4 NetworkConnectionInfo (de.dytanic.cloudnet.ext.bridge.player.NetworkConnectionInfo)4 ICloudService (de.dytanic.cloudnet.service.ICloudService)4 Wrapper (de.dytanic.cloudnet.wrapper.Wrapper)4 Map (java.util.Map)4 CloudNetDriver (de.dytanic.cloudnet.driver.CloudNetDriver)3 InetSocketAddress (java.net.InetSocketAddress)3 ServerInfo (com.velocitypowered.api.proxy.server.ServerInfo)2 LanguageManager (de.dytanic.cloudnet.common.language.LanguageManager)2 PacketClientServerServiceInfoPublisher (de.dytanic.cloudnet.driver.network.def.packet.PacketClientServerServiceInfoPublisher)2 ServiceEnvironmentType (de.dytanic.cloudnet.driver.service.ServiceEnvironmentType)2 BridgeServiceProperty (de.dytanic.cloudnet.ext.bridge.BridgeServiceProperty)2 WorldInfo (de.dytanic.cloudnet.ext.bridge.WorldInfo)2