Skip to content
This repository has been archived by the owner on Apr 9, 2021. It is now read-only.

Commit

Permalink
Adjust quarterdeck backend naming
Browse files Browse the repository at this point in the history
  • Loading branch information
schnapster committed Mar 11, 2018
1 parent 75d3c5b commit 8c18534
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 87 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<I extends Serializable, E extends SaucedEntity<I, E>> implements Repo<I, E> {

Expand All @@ -56,7 +56,7 @@ public abstract class RestRepo<I extends Serializable, E extends SaucedEntity<I,

/**
* @param path base path of this resource, including the version and a trailing slash
* Example: http://backend:4269/v1/blacklist/
* Example: http://quarterdeck:4269/v1/blacklist/
*/
public RestRepo(String path, Class<E> entityClass, Http http, Gson gson, String auth) {
this.path = path;
Expand Down
16 changes: 9 additions & 7 deletions FredBoat/fredboat.example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
30 changes: 15 additions & 15 deletions FredBoat/src/main/java/fredboat/config/RepoConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand All @@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
}
20 changes: 10 additions & 10 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -70,7 +70,7 @@ services:
labels:
- "com.centurylinklabs.watchtower.enable=true"
depends_on:
- backend
- quarterdeck
ports:
- 1356:1356
volumes:
Expand Down

0 comments on commit 8c18534

Please sign in to comment.