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();
}
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!");
});
}
}
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();
}
}
}
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();
}
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()));
}
}
Aggregations