Skip to content

Commit

Permalink
Merge pull request #44 from comroid-git/module-protos
Browse files Browse the repository at this point in the history
Store Module configuration in Database
  • Loading branch information
burdoto authored Dec 19, 2023
2 parents 6a6de9d + d8273d0 commit 14c4279
Show file tree
Hide file tree
Showing 68 changed files with 1,043 additions and 393 deletions.
7 changes: 7 additions & 0 deletions docs/abstract_entity_versions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
abstract entity version log

# 0 / null
no version / outdated

# 1 - server module migration update
this version introduces module settings via separate entities
16 changes: 9 additions & 7 deletions src/agent/main/java/org/comroid/mcsd/agent/AgentRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,18 @@
import org.comroid.api.DelegateStream;
import org.comroid.api.Polyfill;
import org.comroid.mcsd.agent.controller.ConsoleController;
import org.comroid.mcsd.core.MCSD;
import org.comroid.mcsd.core.ServerManager;
import org.comroid.mcsd.core.entity.*;
import org.comroid.mcsd.core.entity.server.Server;
import org.comroid.mcsd.core.entity.system.Agent;
import org.comroid.mcsd.core.module.console.ConsoleModule;
import org.comroid.mcsd.core.module.status.BackupModule;
import org.comroid.mcsd.core.module.local.LocalExecutionModule;
import org.comroid.mcsd.core.module.status.UpdateModule;
import org.comroid.mcsd.core.module.status.StatusModule;
import org.comroid.mcsd.core.repo.ServerRepo;
import org.comroid.mcsd.core.repo.ShRepo;
import org.comroid.mcsd.core.repo.server.ServerRepo;
import org.comroid.mcsd.core.util.ApplicationContextProvider;
import org.comroid.mcsd.util.Utils;
import org.comroid.util.Streams;
import org.jetbrains.annotations.NotNull;
Expand All @@ -25,8 +28,6 @@
import org.springframework.stereotype.Service;

import java.io.PrintStream;
import java.time.Duration;
import java.time.Instant;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -202,7 +203,7 @@ public String detach(String[] args, ConsoleController.Connection con) {
attached = null;
return "Detached";
}

/*
@Command(usage = "<name> <version> <mode> [-na]")
public Object create(String[] args, ConsoleController.Connection con) {
if (!Utils.SuperAdmins.contains(con.getUser().getId()))
Expand Down Expand Up @@ -250,7 +251,7 @@ public Object create(String[] args, ConsoleController.Connection con) {
server.setOwner(con.getUser()).setName(name);
return serverRepo.save(server) + " created";
}

*/
@Command(usage = "")
public String shutdown(ConsoleController.Connection con) {
if (!Utils.SuperAdmins.contains(con.getUser().getId()))
Expand Down Expand Up @@ -278,12 +279,13 @@ public void handleResponse(Command.Delegate cmd, @NotNull Object response, Objec
out.println(response);
}

@Deprecated
public Stream<Server> streamServers() {
return Streams.of(bean(ServerRepo.class).findAllForAgent(getMe().getId()));
}

public Stream<String> streamServerStatusMsgs() {
return streamServers().map(Server::toString);
return bean(MCSD.class).servers().stream().map(Server::toString);
}

public void execute(String cmd, ConsoleController.Connection con) {
Expand Down
37 changes: 6 additions & 31 deletions src/agent/main/java/org/comroid/mcsd/agent/Program.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,18 @@
import org.comroid.mcsd.api.dto.McsdConfig;
import org.comroid.mcsd.core.MCSD;
import org.comroid.mcsd.core.ServerManager;
import org.comroid.mcsd.core.entity.Agent;
import org.comroid.mcsd.core.entity.Server;
import org.comroid.mcsd.core.entity.system.Agent;
import org.comroid.mcsd.core.entity.server.Server;
import org.comroid.mcsd.core.exception.EntityNotFoundException;
import org.comroid.mcsd.core.module.*;
import org.comroid.mcsd.core.module.discord.DiscordModule;
import org.comroid.mcsd.core.module.player.ConsolePlayerEventModule;
import org.comroid.mcsd.core.module.local.LocalExecutionModule;
import org.comroid.mcsd.core.module.local.LocalFileModule;
import org.comroid.mcsd.core.module.player.PlayerListModule;
import org.comroid.mcsd.core.module.status.StatusModule;
import org.comroid.mcsd.core.module.status.UptimeModule;
import org.comroid.mcsd.core.repo.AgentRepo;
import org.comroid.mcsd.core.repo.ServerRepo;
import org.comroid.mcsd.core.repo.system.AgentRepo;
import org.comroid.mcsd.core.repo.server.ServerRepo;
import org.comroid.util.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.ImportResource;
import org.springframework.context.annotation.Lazy;
import org.springframework.context.annotation.*;
import org.springframework.http.HttpStatus;

import java.util.List;
Expand Down Expand Up @@ -66,24 +55,10 @@ public Agent me(@Autowired AgentInfo agentInfo, @Autowired AgentRepo agents) {
.orElseThrow(() -> new EntityNotFoundException(Agent.class, agentInfo.getAgent()));
}

@Bean
public List<ServerModule.Factory<?>> serverModuleFactories() {
return List.of(
StatusModule.Factory,
LocalFileModule.Factory,
UptimeModule.Factory,
//todo: fix UpdateModule.Factory,
LocalExecutionModule.Factory,
//todo: fix BackupModule.Factory,
ConsolePlayerEventModule.Factory,
PlayerListModule.Factory,
DiscordModule.Factory
);
}

@Bean
@Unique
@Lazy(false)
@DependsOn("migrateEntities")
public List<Server> servers(@Autowired ServerRepo serverRepo, @Autowired Agent me) {
return Streams.of(serverRepo.findAllForAgent(me.getId())).toList();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,24 @@

import jakarta.servlet.http.HttpSession;
import lombok.extern.slf4j.Slf4j;
import org.comroid.api.IntegerAttribute;
import org.comroid.api.Named;
import org.comroid.mcsd.agent.AgentRunner;
import org.comroid.mcsd.core.MCSD;
import org.comroid.mcsd.core.entity.AbstractEntity;
import org.comroid.mcsd.core.entity.Agent;
import org.comroid.mcsd.core.entity.Server;
import org.comroid.mcsd.core.entity.User;
import org.comroid.mcsd.core.entity.system.Agent;
import org.comroid.mcsd.core.entity.server.Server;
import org.comroid.mcsd.core.entity.system.User;
import org.comroid.mcsd.core.exception.InsufficientPermissionsException;
import org.comroid.mcsd.core.repo.UserRepo;
import org.jetbrains.annotations.NotNull;
import org.comroid.mcsd.core.repo.system.UserRepo;
import org.comroid.mcsd.core.util.ApplicationContextProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import static org.comroid.mcsd.core.util.ApplicationContextProvider.bean;

@Slf4j
@Controller
Expand All @@ -43,7 +41,7 @@ public User user(HttpSession session) {
@ResponseBody
@GetMapping("/webapp/servers")
public List<Server> servers(HttpSession session) {
return runner.streamServers()
return bean(MCSD.class).servers().stream()
.filter(x->x.hasPermission(user(session), AbstractEntity.Permission.Any))
.toList();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
import org.comroid.api.Event;
import org.comroid.mcsd.agent.AgentRunner;
import org.comroid.mcsd.agent.config.WebSocketConfig;
import org.comroid.mcsd.core.entity.Server;
import org.comroid.mcsd.core.entity.User;
import org.comroid.mcsd.core.entity.server.Server;
import org.comroid.mcsd.core.entity.system.User;
import org.comroid.mcsd.core.module.local.LocalExecutionModule;
import org.comroid.mcsd.core.repo.UserRepo;
import org.comroid.mcsd.core.repo.system.UserRepo;
import org.intellij.lang.annotations.Language;
import org.jetbrains.annotations.Nullable;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down
Loading

0 comments on commit 14c4279

Please sign in to comment.