From 8c18534d3b001cad0fbd3e0b292e910ce80a2cba Mon Sep 17 00:00:00 2001 From: Napster Date: Sun, 11 Mar 2018 08:20:23 +0100 Subject: [PATCH] Adjust quarterdeck backend naming --- .../db/repositories/impl/rest/RestRepo.java | 4 +- FredBoat/fredboat.example.yaml | 16 +-- .../fredboat/config/RepoConfiguration.java | 30 ++--- .../config/property/BackendConfig.java | 12 +- .../property/BackendConfigProperties.java | 112 ++++++++++-------- docker-compose.yml | 20 ++-- 6 files changed, 107 insertions(+), 87 deletions(-) diff --git a/Database/src/main/java/fredboat/db/repositories/impl/rest/RestRepo.java b/Database/src/main/java/fredboat/db/repositories/impl/rest/RestRepo.java index e0cf315ea..977f26d87 100644 --- a/Database/src/main/java/fredboat/db/repositories/impl/rest/RestRepo.java +++ b/Database/src/main/java/fredboat/db/repositories/impl/rest/RestRepo.java @@ -39,7 +39,7 @@ /** * Created by napster on 17.02.18. * - * Counterpart to the EntityController of the Backend module. + * Counterpart to the EntityController of the Quarterdeck module. */ public abstract class RestRepo> implements Repo { @@ -56,7 +56,7 @@ public abstract class RestRepo entityClass, Http http, Gson gson, String auth) { this.path = path; diff --git a/FredBoat/fredboat.example.yaml b/FredBoat/fredboat.example.yaml index 8f3d77e36..9f727cc9a 100644 --- a/FredBoat/fredboat.example.yaml +++ b/FredBoat/fredboat.example.yaml @@ -83,13 +83,15 @@ audio-sources: ################################################################ backend: - # Host address of your backend, including port. Example: https://such.example.com:4269/ - # No need set the host when running the whole FredBoat in docker. - host: "" - # Admin username and pass that you configured in the backend.yaml. - # Do not leave any of them empty. - user: "" - pass: "" + quarterdeck: + # Host address of your quarterdeck backend, including port unless you are using a reverse proxy. + # Example: https://such.example.com:4269/ + # No need set the host when running the whole FredBoat in docker. + host: "" + # Admin username and pass that you configured in the quarterdeck.yaml. + # Do not leave any of them empty. + user: "" + pass: "" credentials: diff --git a/FredBoat/src/main/java/fredboat/config/RepoConfiguration.java b/FredBoat/src/main/java/fredboat/config/RepoConfiguration.java index ef0bde20d..13ed68a17 100644 --- a/FredBoat/src/main/java/fredboat/config/RepoConfiguration.java +++ b/FredBoat/src/main/java/fredboat/config/RepoConfiguration.java @@ -52,20 +52,20 @@ public class RepoConfiguration { private static final Logger log = LoggerFactory.getLogger(RepoConfiguration.class); - private final BackendConfig backendConfig; + private final BackendConfig.Quarterdeck quarterdeckConfig; private final Gson gson = new Gson(); private final Http http = BotController.HTTP; //todo replace public RepoConfiguration(BackendConfig backendConfig, ShutdownHandler shutdownHandler) throws InterruptedException { - this.backendConfig = backendConfig; + this.quarterdeckConfig = backendConfig.getQuarterdeck(); - log.info("Contacting the backend"); + log.info("Contacting the quarterdeck backend"); String[] apiVersions = null; int attempts = 0; Exception lastException = null; while ((apiVersions == null || apiVersions.length < 1) && attempts < 100) { //total time is 100 sec try { - String s = http.get(backendConfig.getHost() + "info/api/versions").auth(backendConfig.getBasicAuth()).asString(); + String s = http.get(quarterdeckConfig.getHost() + "info/api/versions").auth(quarterdeckConfig.getBasicAuth()).asString(); apiVersions = gson.fromJson(s, String[].class); } catch (Exception ignored) { lastException = ignored; @@ -75,7 +75,7 @@ public RepoConfiguration(BackendConfig backendConfig, ShutdownHandler shutdownHa } if (apiVersions == null || apiVersions.length < 1) { - log.error("Could not contact the backend. Please make sure it is started and configuration values are correct", lastException); + log.error("Could not contact the quarterdeck backend. Please make sure it is started and configuration values are correct", lastException); shutdownHandler.shutdown(ExitCodes.EXIT_CODE_ERROR); return; } @@ -84,52 +84,52 @@ public RepoConfiguration(BackendConfig backendConfig, ShutdownHandler shutdownHa if (!v.startsWith("v")) return "v" + v; else return v; }).collect(Collectors.toList()); - log.info("Supported Backend API versions: {}", String.join(", ", supportedApiVersions)); + log.info("Supported Quarterdeck API versions: {}", String.join(", ", supportedApiVersions)); String ourVersion = Integer.toString(RestRepo.API_VERSION); if (supportedApiVersions.contains(ourVersion) || supportedApiVersions.contains("v" + ourVersion)) { - log.info("Using Backend API v{}", ourVersion); + log.info("Using Quaterdeck API v{}", ourVersion); } else { - log.error("Backend API does not support our expected version v{}. Update the backend, or roll back this FredBoat version!", ourVersion); + log.error("Quarterdeck API does not support our expected version v{}. Update quarterdeck, or roll back this FredBoat version!", ourVersion); shutdownHandler.shutdown(ExitCodes.EXIT_CODE_ERROR); } } @Bean public BlacklistRepo blacklistRepo() { - return new RestBlacklistRepo(backendConfig.getHost(), http, gson, backendConfig.getBasicAuth()); + return new RestBlacklistRepo(quarterdeckConfig.getHost(), http, gson, quarterdeckConfig.getBasicAuth()); } @Bean public GuildConfigRepo guildConfigRepo() { - return new RestGuildConfigRepo(backendConfig.getHost(), http, gson, backendConfig.getBasicAuth()); + return new RestGuildConfigRepo(quarterdeckConfig.getHost(), http, gson, quarterdeckConfig.getBasicAuth()); } @Bean public GuildDataRepo guildDataRepo() { - return new RestGuildDataRepo(backendConfig.getHost(), http, gson, backendConfig.getBasicAuth()); + return new RestGuildDataRepo(quarterdeckConfig.getHost(), http, gson, quarterdeckConfig.getBasicAuth()); } @Bean public GuildModulesRepo guildModulesRepo() { - return new RestGuildModulesRepo(backendConfig.getHost(), http, gson, backendConfig.getBasicAuth()); + return new RestGuildModulesRepo(quarterdeckConfig.getHost(), http, gson, quarterdeckConfig.getBasicAuth()); } @Bean public GuildPermsRepo guildPermsRepo() { - return new RestGuildPermsRepo(backendConfig.getHost(), http, gson, backendConfig.getBasicAuth()); + return new RestGuildPermsRepo(quarterdeckConfig.getHost(), http, gson, quarterdeckConfig.getBasicAuth()); } @Bean public PrefixRepo prefixRepo() { - return new RestPrefixRepo(backendConfig.getHost(), http, gson, backendConfig.getBasicAuth()); + return new RestPrefixRepo(quarterdeckConfig.getHost(), http, gson, quarterdeckConfig.getBasicAuth()); } @Nullable @Bean public SearchResultRepo searchResultRepo() { - return new RestSearchResultRepo(backendConfig.getHost(), http, gson, backendConfig.getBasicAuth()); + return new RestSearchResultRepo(quarterdeckConfig.getHost(), http, gson, quarterdeckConfig.getBasicAuth()); } } diff --git a/FredBoat/src/main/java/fredboat/config/property/BackendConfig.java b/FredBoat/src/main/java/fredboat/config/property/BackendConfig.java index c5ec25e62..9475f63ec 100644 --- a/FredBoat/src/main/java/fredboat/config/property/BackendConfig.java +++ b/FredBoat/src/main/java/fredboat/config/property/BackendConfig.java @@ -29,11 +29,15 @@ */ public interface BackendConfig { - String getHost(); + Quarterdeck getQuarterdeck(); - String getUser(); + interface Quarterdeck { + String getHost(); - String getPass(); + String getUser(); - String getBasicAuth(); + String getPass(); + + String getBasicAuth(); + } } diff --git a/FredBoat/src/main/java/fredboat/config/property/BackendConfigProperties.java b/FredBoat/src/main/java/fredboat/config/property/BackendConfigProperties.java index 75218979a..bc9a4bfe7 100644 --- a/FredBoat/src/main/java/fredboat/config/property/BackendConfigProperties.java +++ b/FredBoat/src/main/java/fredboat/config/property/BackendConfigProperties.java @@ -38,71 +38,85 @@ public class BackendConfigProperties implements BackendConfig { private static final Logger log = LoggerFactory.getLogger(BackendConfigProperties.class); - private String host = ""; - private String user = ""; - private String pass = ""; - private String auth = ""; + private Quarterdeck quarterdeck = new Quarterdeck(); @Override - public String getHost() { - return host; + public Quarterdeck getQuarterdeck() { + return quarterdeck; } - @Override - public String getUser() { - return user; + public void setQuarterdeck(Quarterdeck quarterdeck) { + this.quarterdeck = quarterdeck; } - @Override - public String getPass() { - return pass; - } + public static class Quarterdeck implements BackendConfig.Quarterdeck { - @Override - public String getBasicAuth() { - if (auth.isEmpty()) { - auth = okhttp3.Credentials.basic(getUser(), getPass()); + private String host = ""; + private String user = ""; + private String pass = ""; + private String auth = ""; + + @Override + public String getHost() { + return host; } - return auth; - } - public void setHost(String host) { - this.host = host; - //noinspection ConstantConditions - if (host == null || host.isEmpty()) { - if ("docker".equals(System.getenv("ENV"))) { - log.info("No backend host found, docker environment detected. Using default backend url"); - this.host = "http://backend:4269/"; - } else { - String message = "No backend host provided in a non-docker environment. FredBoat cannot work without a backend."; - log.error(message); - throw new RuntimeException(message); + @Override + public String getUser() { + return user; + } + + @Override + public String getPass() { + return pass; + } + + @Override + public String getBasicAuth() { + if (auth.isEmpty()) { + auth = okhttp3.Credentials.basic(getUser(), getPass()); } + return auth; } - //fix up a missing trailing slash - if (!this.host.endsWith("/")) { - this.host += "/"; + public void setHost(String host) { + this.host = host; + //noinspection ConstantConditions + if (host == null || host.isEmpty()) { + if ("docker".equals(System.getenv("ENV"))) { + log.info("No quarterdeck host found, docker environment detected. Using default quarterdeck url"); + this.host = "http://quarterdeck:4269/"; + } else { + String message = "No quarterdeck host provided in a non-docker environment. FredBoat cannot work without quarterdeck."; + log.error(message); + throw new RuntimeException(message); + } + } + + //fix up a missing trailing slash + if (!this.host.endsWith("/")) { + this.host += "/"; + } } - } - public void setUser(String user) { - this.user = user; - //noinspection ConstantConditions - if (user == null || user.isEmpty()) { - String message = "No backend user provided."; - log.error(message); - throw new RuntimeException(message); + public void setUser(String user) { + this.user = user; + //noinspection ConstantConditions + if (user == null || user.isEmpty()) { + String message = "No quarterdeck user provided."; + log.error(message); + throw new RuntimeException(message); + } } - } - public void setPass(String pass) { - this.pass = pass; - //noinspection ConstantConditions - if (pass == null || pass.isEmpty()) { - String message = "No backend pass provided."; - log.error(message); - throw new RuntimeException(message); + public void setPass(String pass) { + this.pass = pass; + //noinspection ConstantConditions + if (pass == null || pass.isEmpty()) { + String message = "No quarterdeck pass provided."; + log.error(message); + throw new RuntimeException(message); + } } } } diff --git a/docker-compose.yml b/docker-compose.yml index 54f45c6de..ce5a9c4e9 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -34,34 +34,34 @@ services: #- postgres-data-volume:/var/lib/postgresql/data ################################################################################ - ## Backend + ## Quarterdeck (Database Backend) ################################################################################ - backend: + quarterdeck: # pick one of these: stable or dev # dev receives more frequent updates than stable but may have more bugs / things breaking # versions (example: v2) receive continous non-breaking (best effort) updates via watchtower. switching between versions # (example: going from v2 to v3) usually requires manual migration. what exactly is needed is published on the # FredBoat selfhosting website and/or the selfhosters channel (see top of this file for how to get to these places) # Once you use the dev branch, you may not be able to go back to stable without deleting your database. - image: fredboat/backend:stable-v1 - #image: fredboat/backend:dev-v1 + image: fredboat/quarterdeck:stable-v1 + #image: fredboat/quarterdeck:dev-v1 restart: always labels: - "com.centurylinklabs.watchtower.enable=true" depends_on: - db volumes: - - ./backend.yaml:/opt/Backend/backend.yaml - - ./backend_logs:/opt/Backend/logs + - ./quarterdeck.yaml:/opt/Quarterdeck/quarterdeck.yaml + - ./quarterdeck_logs:/opt/Quarterdeck/logs # Need a bigger memory size or any other custom JVM args? uncomment and edit the line below accordingly - #entrypoint: java -Xmx128m -jar Backend.jar + #entrypoint: java -Xmx128m -jar Quarterdeck.jar ################################################################################ ## FredBoat ################################################################################ bot: - # for choosing between stable or dev, read the paragraph above in the backend - # IMPORTANT: both backend and fredboat need to either be on the stable, or on the dev branch + # for choosing between stable or dev, read the paragraph above in the Quarterdeck section + # IMPORTANT: both quarterdeck and fredboat need to either be on the stable, or on the dev branch image: fredboat/fredboat:stable-v3 #image: fredboat/fredboat:dev-v3 #build: ./FredBoat #useful alternative for developers @@ -70,7 +70,7 @@ services: labels: - "com.centurylinklabs.watchtower.enable=true" depends_on: - - backend + - quarterdeck ports: - 1356:1356 volumes: