preparatory refactoring for bug5676, extracting method for replica config builder

This commit is contained in:
Axel Uhl
2022-01-13 13:26:31 +01:00
parent f4834764f6
commit 4aa9783289
3 changed files with 41 additions and 34 deletions
@@ -510,6 +510,25 @@ public class LandscapeServiceImpl implements LandscapeService {
return masterConfigurationBuilder;
}
private Builder<?, String> createReplicaConfigurationBuilder(final AwsLandscape<String> landscape,
final AwsRegion region, String replicaSetName, final int masterPort,
final Release release, final String bearerTokenUsedByReplicas, final String masterHostname) {
final Builder<?, String> replicaConfigurationBuilder = SailingAnalyticsReplicaConfiguration.replicaBuilder();
// no specific memory configuration is made here; replicas are currently launched on a dedicated host and hence can
// grab as much memory as they can get on that host
replicaConfigurationBuilder
.setLandscape(landscape)
.setRegion(region)
.setServerName(replicaSetName)
.setRelease(release)
.setPort(masterPort) // replicas need to run on the same port for target group "interoperability"
.setInboundReplicationConfiguration(InboundReplicationConfiguration.builder()
.setMasterHostname(masterHostname) // don't set the master port; the replica set talks to "itself" through the load balancer using HTTPS
.setCredentials(new BearerTokenReplicationCredentials(bearerTokenUsedByReplicas))
.build());
return replicaConfigurationBuilder;
}
private void applyMemoryConfigurationToApplicationConfigurationBuilder(
final AwsApplicationConfiguration.Builder<?, ?, ?, ?, ?> applicationConfigurationBuilder,
Integer optionalMemoryInMegabytesOrNull, Integer optionalMemoryTotalSizeFactorOrNull) {
@@ -546,19 +565,7 @@ public class LandscapeServiceImpl implements LandscapeService {
.build();
createLoadBalancerMapping.run();
// construct a replica configuration which is used to produce the user data for the launch configuration used in an auto-scaling group
final Builder<?, String> replicaConfigurationBuilder = SailingAnalyticsReplicaConfiguration.replicaBuilder();
// no specific memory configuration is made here; replicas are currently launched on a dedicated host and hence can
// grab as much memory as they can get on that host
replicaConfigurationBuilder
.setLandscape(landscape)
.setRegion(region)
.setServerName(replicaSetName)
.setRelease(release)
.setPort(master.getPort()) // replicas need to run on the same port for target group "interoperability"
.setInboundReplicationConfiguration(InboundReplicationConfiguration.builder()
.setMasterHostname(masterHostname) // don't set the master port; the replica set talks to "itself" through the load balancer using HTTPS
.setCredentials(new BearerTokenReplicationCredentials(bearerTokenUsedByReplicas))
.build());
final Builder<?, String> replicaConfigurationBuilder = createReplicaConfigurationBuilder(landscape, region, replicaSetName, master.getPort(), release, bearerTokenUsedByReplicas, masterHostname);
final CompletableFuture<Iterable<ApplicationLoadBalancer<String>>> allLoadBalancersInRegion = landscape.getLoadBalancersAsync(region);
final CompletableFuture<Map<TargetGroup<String>, Iterable<TargetHealthDescription>>> allTargetGroupsInRegion = landscape.getTargetGroupsAsync(region);
final CompletableFuture<Map<Listener, Iterable<Rule>>> allLoadBalancerRulesInRegion = landscape.getLoadBalancerListenerRulesAsync(region, allLoadBalancersInRegion);
@@ -596,7 +603,7 @@ public class LandscapeServiceImpl implements LandscapeService {
allLoadBalancersInRegion, allTargetGroupsInRegion, allLoadBalancerRulesInRegion, autoScalingGroups, launchConfigurations, dnsCache);
return applicationReplicaSet;
}
@Override
public Release upgradeApplicationReplicaSet(AwsRegion region,
AwsApplicationReplicaSet<String, SailingAnalyticsMetrics, SailingAnalyticsProcess<String>> replicaSet,
@@ -717,19 +724,11 @@ public class LandscapeServiceImpl implements LandscapeService {
private SailingAnalyticsProcess<String> spinUpReplicaAndRegisterInPublicTargetGroup(
AwsApplicationReplicaSet<String, SailingAnalyticsMetrics, SailingAnalyticsProcess<String>> replicaSet,
Optional<String> optionalKeyName, byte[] privateKeyEncryptionPassphrase, String replicationBearerToken) throws Exception {
final com.sap.sailing.landscape.procedures.SailingAnalyticsReplicaConfiguration.Builder<?, String> replicaConfigurationBuilder = SailingAnalyticsReplicaConfiguration.replicaBuilder();
final AwsRegion region = replicaSet.getMaster().getHost().getRegion();
final InstanceType masterInstanceType = getLandscape().getInstance(replicaSet.getMaster().getHost().getInstanceId(), region).instanceType();
final Release release = replicaSet.getVersion(LandscapeService.WAIT_FOR_PROCESS_TIMEOUT, optionalKeyName, privateKeyEncryptionPassphrase);
replicaConfigurationBuilder
.setLandscape(getLandscape())
.setRegion(region)
.setPort(replicaSet.getMaster().getPort())
.setServerName(replicaSet.getServerName())
.setRelease(release)
.setInboundReplicationConfiguration(InboundReplicationConfiguration.builder()
.setMasterHostname(replicaSet.getHostname()) // see bug5571: don't rely on hostname being {server-name}.sapsailing.com but take from load balancer config
.setCredentials(new BearerTokenReplicationCredentials(replicationBearerToken)).build());
final com.sap.sailing.landscape.procedures.SailingAnalyticsReplicaConfiguration.Builder<?, String> replicaConfigurationBuilder =
createReplicaConfigurationBuilder(getLandscape(), region, replicaSet.getServerName(), replicaSet.getMaster().getPort(), release, replicationBearerToken, replicaSet.getHostname());
final InstanceType masterInstanceType = getLandscape().getInstance(replicaSet.getMaster().getHost().getInstanceId(), region).instanceType();
final com.sap.sailing.landscape.procedures.StartSailingAnalyticsReplicaHost.Builder<?, String> replicaHostBuilder = StartSailingAnalyticsReplicaHost.replicaHostBuilder(replicaConfigurationBuilder);
replicaHostBuilder
.setInstanceType(masterInstanceType)
@@ -14,9 +14,9 @@ import com.sap.sailing.domain.common.DataImportProgress;
import com.sap.sse.shared.json.JsonDeserializationException;
/**
* Represents a remote instance of a server process running the Sailing Analytics and exposes various methods as a
* convenient Java API which are implemented using the remote server's REST API. In short, this is a Java facade for a
* REST API.
* Represents a remote instance of a server process or an entire application replica set with a master and zero or more
* replicas, running the Sailing Analytics, and exposes various methods as a convenient Java API which are implemented
* using the remote server's REST API. In short, this is a Java facade for a REST API.
* <p>
*
* Objects of this type manage authentication information required for executing its methods as part of their immutable
@@ -27,6 +27,8 @@ import com.sap.sse.shared.json.JsonDeserializationException;
* this object shares its security service with the server where this object is constructed.
* <p>
*
* Constructs objects whose type conforms with this interface by using {@link SailingServerFactory}.
*
* @author Axel Uhl (d043530)
*/
public interface SailingServer {
@@ -58,6 +60,12 @@ public interface SailingServer {
*/
CompareServersResult compareServers(Optional<SailingServer> a, SailingServer b, Optional<Iterable<UUID>> leaderboardGroupIds) throws Exception;
/**
* Obtains the {@link RemoteSailingServerReference}s established in this server. These references point to
* other servers / application replica sets and make those other servers' content visible in the events list
* on this server. As users navigate to those other servers' events they leave the scope of this server. The
* remote references can optionally specify a set of events to include / exclude.
*/
Iterable<RemoteSailingServerReference> getRemoteServerReferences() throws JsonDeserializationException,
MalformedURLException, ClientProtocolException, IOException, ParseException;
@@ -72,14 +80,14 @@ public interface SailingServer {
*
* @return the reference added or the existing reference found
*/
RemoteSailingServerReference addRemoteServerReference(SailingServer referencedServer,
boolean includeSpecifiedEvents)
RemoteSailingServerReference addRemoteServerReference(SailingServer referencedServer, boolean includeSpecifiedEvents)
throws JsonDeserializationException, ClientProtocolException, IOException, ParseException;
/**
* @return the reference removed, or {@code null} if no such reference was found
*/
RemoteSailingServerReference removeRemoteServerReference(SailingServer referencedServer) throws JsonDeserializationException, ClientProtocolException, IOException, ParseException;
RemoteSailingServerReference removeRemoteServerReference(SailingServer referencedServer)
throws JsonDeserializationException, ClientProtocolException, IOException, ParseException;
/**
* Ensures that a remote sailing server reference to {@code referencedServer} exists and includes the events
@@ -3,9 +3,9 @@ package com.sap.sailing.server.gateway.interfaces;
import java.net.URL;
/**
* A factory service that obtains {@link SailingServer} instances which represent (usually remote) server processes,
* identified by a {@link URL} that is used as the base to construct the REST API URLs, plus the authentication
* information necessary to authenticate calls.
* A factory service that obtains {@link SailingServer} instances which represent (usually remote) server processes or
* entire application replica sets, identified by a {@link URL} that is used as the base to construct the REST API URLs,
* plus the authentication information necessary to authenticate calls.
* <p>
*
* Using {@link #getSailingServer(URL)} may be used to try authentication with the bearer token of the current local