Skip to content

Commit

Permalink
Run maps server as its own server (#12180)
Browse files Browse the repository at this point in the history
* Run maps server as its own server

This update does a few thing:

- The majority of the update, splits off the Maps server code
  from Lobby & starts up the maps server on its own. Auth needs
  to be reworked still.

- adds a class called 'ClientIdentifiers' that we can use consistently
  to send all needed HTTP headers. Updates Maps HTTP Clients to accept
  and use ClientIdentifiers to create those headers. So, we now more
  consistently send all needed headers (for all maps related APIs at least)

* Add missing 'shadowJar' dependency
  • Loading branch information
DanVanAtta authored Dec 5, 2023
1 parent 5c260c7 commit c740a17
Show file tree
Hide file tree
Showing 50 changed files with 460 additions and 368 deletions.
8 changes: 8 additions & 0 deletions .docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ services:
- DB_URL=database:5432/error_report
depends_on:
- database
maps-server:
build:
context: ../servers/maps/server/
dockerfile: Dockerfile
environment:
- DB_URL=database:5432/maps
depends_on:
- database
database:
image: postgres:10
environment:
Expand Down
9 changes: 9 additions & 0 deletions .docker/nginx/default.conf
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,13 @@ server {
proxy_set_header X-Forwarded-Proto $scheme;
proxy_read_timeout 90;
}

location /maps {
proxy_pass http://maps-server:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_read_timeout 90;
}
}
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -236,5 +236,6 @@ subprojects {

// compose builds need WAR files for packaging, so we must run the corresponding package (shadowJar) tasks
composeBuild.dependsOn ":servers:game-support:server:shadowJar"
composeBuild.dependsOn ":servers:maps:server:shadowJar"
composeBuild.dependsOn ":spitfire-server:dropwizard-server:shadowJar"
}
2 changes: 2 additions & 0 deletions game-app/game-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ dependencies {
implementation project(":game-app:map-data")
implementation project(":game-app:game-relay-server")
implementation project(":http-clients:lobby-client")
implementation project(":lib:http-client-lib")
implementation project(":lib:java-extras")
implementation project(":lib:swing-lib")
implementation project(":lib:websocket-client")
implementation project(":lib:xml-reader")
implementation project(":servers:maps:client")
testImplementation "org.awaitility:awaitility:$awaitilityVersion"
testImplementation "org.sonatype.goodies:goodies-prefs:$sonatypeGoodiesPrefsVersion"
testImplementation project(":lib:swing-lib-test-support")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
import java.util.List;
import lombok.experimental.UtilityClass;
import lombok.extern.slf4j.Slf4j;
import org.triplea.config.product.ProductVersionReader;
import org.triplea.domain.data.SystemIdLoader;
import org.triplea.http.client.lib.ClientIdentifiers;
import org.triplea.http.client.maps.listing.MapDownloadItem;
import org.triplea.http.client.maps.listing.MapsClient;

Expand All @@ -16,7 +19,13 @@ public class MapListingFetcher {
public static List<MapDownloadItem> getMapDownloadList() {
final var serverUri = ClientSetting.lobbyUri.getValueOrThrow();
try {
return MapsClient.newClient(serverUri).fetchMapListing();
return MapsClient.newClient(
serverUri,
ClientIdentifiers.builder()
.applicationVersion(ProductVersionReader.getCurrentVersion().toMajorMinorString())
.systemId(SystemIdLoader.load().getValue())
.build())
.fetchMapListing();
} catch (FeignException e) {
log.warn(
"Failed to download the list of available maps from TripleA servers.\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,11 @@ public boolean isCompatibleWithMapMinimumEngineVersion(final Version mapMinimumE
return major > mapMinimumEngineVersion.major
|| (major == mapMinimumEngineVersion.major && minor >= mapMinimumEngineVersion.minor);
}

/**
* @return String with 'major.minor' format.
*/
public String toMajorMinorString() {
return major + "." + minor;
}
}
2 changes: 2 additions & 0 deletions game-app/game-headed/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ dependencies {
implementation project(":game-app:map-data")
implementation project(":http-clients:lobby-client")
implementation project(":lib:feign-common")
implementation project(":lib:http-client-lib")
implementation project(":lib:java-extras")
implementation project(":lib:swing-lib")
implementation project(":lib:websocket-client")
implementation project(":servers:maps:client")
testImplementation "org.sonatype.goodies:goodies-prefs:$sonatypeGoodiesPrefsVersion"
testImplementation project(":lib:test-common")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import java.awt.Component;
import lombok.experimental.UtilityClass;
import org.triplea.http.client.lobby.moderator.toolbox.ModeratorToolboxClient;
import org.triplea.http.client.maps.admin.MapTagAdminClient;
import org.triplea.http.client.maps.listing.MapsClient;
import org.triplea.swing.JFrameBuilder;
import org.triplea.swing.SwingAction;
import org.triplea.swing.jpanel.JPanelBuilder;
Expand All @@ -18,7 +20,10 @@ public final class ToolBoxWindow {

/** Shows the moderator toolbox UI window. */
public static void showWindow(
final Component parent, final ModeratorToolboxClient moderatorToolboxClient) {
final Component parent,
final ModeratorToolboxClient moderatorToolboxClient,
final MapsClient mapsClient,
final MapTagAdminClient mapTagAdminClient) {
SwingAction.invokeNowOrLater(
() ->
JFrameBuilder.builder()
Expand All @@ -36,6 +41,8 @@ public static void showWindow(
TabFactory.builder()
.frame(frame)
.moderatorToolboxClient(moderatorToolboxClient)
.mapsClient(mapsClient)
.mapTagAdminClient(mapTagAdminClient)
.build()
.buildTabs())
.build())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,17 @@
import javax.swing.JTabbedPane;
import lombok.Builder;
import org.triplea.http.client.lobby.moderator.toolbox.ModeratorToolboxClient;
import org.triplea.http.client.maps.admin.MapTagAdminClient;
import org.triplea.http.client.maps.listing.MapsClient;
import org.triplea.swing.JTabbedPaneBuilder;

/** Factory class to construct the 'tabs' that go in the moderator toolbox tabbed window. */
@Builder
public final class TabFactory {
@Nonnull private final JFrame frame;
@Nonnull private final ModeratorToolboxClient moderatorToolboxClient;
@Nonnull private final MapsClient mapsClient;
@Nonnull private final MapTagAdminClient mapTagAdminClient;

public JTabbedPane buildTabs() {
return JTabbedPaneBuilder.builder()
Expand Down Expand Up @@ -64,18 +68,15 @@ private Component buildModeratorsTab() {
private Component buildMapsTab() {
return MapsTab.builder()
.parentWindowHeight(frame.getWidth())
.mapsTabModel(buildMapsTabModel())
.mapsTabModel(
MapsTabModel.builder()
.mapsClient(mapsClient)
.mapTagAdminClient(mapTagAdminClient)
.build())
.build()
.get();
}

private MapsTabModel buildMapsTabModel() {
return MapsTabModel.builder()
.mapsClient(moderatorToolboxClient.getMapsClient())
.mapTagAdminClient(moderatorToolboxClient.getMapTagAdminClient())
.build();
}

private Component buildEventLogTab() {
return new EventLogTab(moderatorToolboxClient.getToolboxEventLogClient()).get();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;
import lombok.Builder;
import org.triplea.http.client.maps.admin.MapTagMetaData;
import org.triplea.http.client.maps.listing.MapDownloadItem;
import org.triplea.http.client.maps.tag.admin.MapTagMetaData;
import org.triplea.java.ThreadRunner;
import org.triplea.swing.JComboBoxBuilder;
import org.triplea.swing.JSplitPaneBuilder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.triplea.http.client.GenericServerResponse;
import org.triplea.http.client.maps.admin.MapTagAdminClient;
import org.triplea.http.client.maps.admin.MapTagMetaData;
import org.triplea.http.client.maps.admin.UpdateMapTagRequest;
import org.triplea.http.client.maps.listing.MapDownloadItem;
import org.triplea.http.client.maps.listing.MapsClient;
import org.triplea.http.client.maps.tag.admin.MapTagAdminClient;
import org.triplea.http.client.maps.tag.admin.MapTagMetaData;
import org.triplea.http.client.maps.tag.admin.UpdateMapTagRequest;

@Slf4j
public class MapsTabModel {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
import games.strategy.triplea.settings.ClientSetting;
import games.strategy.triplea.ui.MacOsIntegration;
import javax.swing.JMenuBar;
import org.triplea.config.product.ProductVersionReader;
import org.triplea.domain.data.SystemIdLoader;
import org.triplea.http.client.lib.ClientIdentifiers;
import org.triplea.http.client.maps.admin.MapTagAdminClient;
import org.triplea.http.client.maps.listing.MapsClient;
import org.triplea.http.client.web.socket.client.connections.PlayerToLobbyConnection;
import org.triplea.sound.SoundOptions;
import org.triplea.swing.JMenuBuilder;
Expand Down Expand Up @@ -51,14 +56,25 @@ public LobbyMenu(
}

if (loginResult.isModerator()) {
ClientIdentifiers clientIdentifiers =
ClientIdentifiers.builder()
.applicationVersion(ProductVersionReader.getCurrentVersion().toMajorMinorString())
.systemId(SystemIdLoader.load().getValue())
.apiKey(loginResult.getApiKey().getValue())
.build();
add(
new JMenuBuilder("Admin", 'M')
.addMenuItem(
"Open Toolbox",
'T',
() ->
ToolBoxWindow.showWindow(
lobbyFrame, playerToLobbyConnection.getHttpModeratorToolboxClient()))
lobbyFrame,
playerToLobbyConnection.getHttpModeratorToolboxClient(),
MapsClient.newClient(
ClientSetting.lobbyUri.getValueOrThrow(), clientIdentifiers),
MapTagAdminClient.newClient(
ClientSetting.lobbyUri.getValueOrThrow(), clientIdentifiers)))
.build());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,7 @@ public static void main(final String[] args) {

LobbyHttpClientConfig.setConfig(
LobbyHttpClientConfig.builder()
.clientVersion(
ProductVersionReader.getCurrentVersion().getMajor()
+ "."
+ ProductVersionReader.getCurrentVersion().getMinor())
.clientVersion(ProductVersionReader.getCurrentVersion().toMajorMinorString())
.systemId(SystemIdLoader.load().getValue())
.build());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
import org.triplea.http.client.lobby.moderator.toolbox.log.ToolboxEventLogClient;
import org.triplea.http.client.lobby.moderator.toolbox.management.ToolboxModeratorManagementClient;
import org.triplea.http.client.lobby.moderator.toolbox.words.ToolboxBadWordsClient;
import org.triplea.http.client.maps.listing.MapsClient;
import org.triplea.http.client.maps.tag.admin.MapTagAdminClient;

@Getter
public class ModeratorToolboxClient {
Expand All @@ -21,8 +19,6 @@ public class ModeratorToolboxClient {
private final ToolboxModeratorManagementClient toolboxModeratorManagementClient;
private final ToolboxBadWordsClient toolboxBadWordsClient;
private final ToolboxEventLogClient toolboxEventLogClient;
private final MapsClient mapsClient;
private final MapTagAdminClient mapTagAdminClient;

private ModeratorToolboxClient(final URI lobbyUri, final ApiKey apiKey) {
toolboxAccessLogClient = ToolboxAccessLogClient.newClient(lobbyUri, apiKey);
Expand All @@ -31,8 +27,6 @@ private ModeratorToolboxClient(final URI lobbyUri, final ApiKey apiKey) {
toolboxModeratorManagementClient = ToolboxModeratorManagementClient.newClient(lobbyUri, apiKey);
toolboxBadWordsClient = ToolboxBadWordsClient.newClient(lobbyUri, apiKey);
toolboxEventLogClient = ToolboxEventLogClient.newClient(lobbyUri, apiKey);
mapsClient = MapsClient.newClient(lobbyUri);
mapTagAdminClient = MapTagAdminClient.newClient(lobbyUri, apiKey);
}

public static ModeratorToolboxClient newClient(final URI lobbyUri, final ApiKey apiKey) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package org.triplea.http.client.lib;

import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import lombok.Builder;

@Builder
public class ClientIdentifiers {
public static final String VERSION_HEADER = "Triplea-Version";
private static final String SYSTEM_ID_HEADER = "System-Id";

@Nonnull private final String applicationVersion;
@Nonnull private final String systemId;
@Nullable private final String apiKey;

/** Creates headers containing 'System-Id' only. */
public Map<String, String> createHeaders() {
final Map<String, String> headerMap = new HashMap<>();
headerMap.put(VERSION_HEADER, applicationVersion);
headerMap.put(SYSTEM_ID_HEADER, systemId);
Optional.ofNullable(apiKey)
.ifPresent(apiKey -> headerMap.put("Authorization", "Bearer " + apiKey));
return headerMap;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import feign.RequestLine;
import java.net.URI;
import org.triplea.http.client.HttpClient;
import org.triplea.http.client.lib.HttpClientHeaders;
import org.triplea.http.client.lib.ClientIdentifiers;

/** Http client to upload error reports to the http lobby server. */
public interface ErrorReportClient {
Expand All @@ -13,11 +13,8 @@ public interface ErrorReportClient {
int MAX_REPORTS_PER_DAY = 5;

/** Creates an error report uploader clients, sends error reports and gets a response back. */
static ErrorReportClient newClient(URI uri, String clientVersion) {
return HttpClient.newClient(
ErrorReportClient.class,
uri,
HttpClientHeaders.defaultHeadersWithClientVersion(clientVersion));
static ErrorReportClient newClient(URI uri, ClientIdentifiers clientIdentifiers) {
return HttpClient.newClient(ErrorReportClient.class, uri, clientIdentifiers.createHeaders());
}

/**
Expand Down
2 changes: 0 additions & 2 deletions servers/game-support/server/configuration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@ githubApiToken: ${GITHUB_API_TOKEN:-}
githubWebServiceUrl: https://api.github.com
githubGameOrg: triplea-game
githubGameRepo: triplea
githubMapsOrgName: triplea-maps

# When disabled, API calls to github to create error reports will not
# be made and instead a hardcoded value returned.
errorReportToGithubEnabled: ${ERROR_REPORT_TO_GITHUB_ENABLED:-false}



database:
driverClass: org.postgresql.Driver
user: ${DATABASE_USER:-error_report_user}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import org.triplea.http.client.error.report.ErrorReportRequest;
import org.triplea.http.client.error.report.ErrorReportResponse;
import org.triplea.http.client.github.GithubApiClient;
import org.triplea.http.client.lib.HttpClientHeaders;
import org.triplea.http.client.lib.ClientIdentifiers;
import org.triplea.server.error.reporting.upload.CanUploadErrorReportStrategy;
import org.triplea.server.error.reporting.upload.CreateIssueParams;
import org.triplea.server.error.reporting.upload.ErrorReportModule;
Expand Down Expand Up @@ -71,7 +71,7 @@ public ErrorReportResponse uploadErrorReport(
return errorReportIngestion.createErrorReport(
CreateIssueParams.builder()
.ip(IpAddressExtractor.extractIpAddress(request))
.systemId(request.getHeader(HttpClientHeaders.VERSION_HEADER))
.systemId(request.getHeader(ClientIdentifiers.VERSION_HEADER))
.errorReportRequest(errorReport)
.build());
}
Expand Down
Loading

0 comments on commit c740a17

Please sign in to comment.