bug5677: added button for multi-selection auto-scaling replica scale up/down

This commit is contained in:
Axel Uhl committed 2022-02-08 00:21:01 +01:00
1 parent f34b15366c
commit cb4d3eb871
10 files changed
+123 -32

No files matched your search

@@ -22,6 +22,7 @@ public class ApplicationReplicaSetsImagesBarCell extends ImagesBarCell {
public static final String ACTION_SWITCH_TO_AUTO_SCALING_REPLICAS_ONLY = "ACTION_SWITCH_TO_AUTO_SCALING_REPLICAS_ONLY";
public static final String ACTION_SWITCH_TO_REPLICA_ON_SHARED_INSTANCE = "ACTION_SWITCH_TO_REPLICA_ON_SHARED_INSTANCE";
public static final String ACTION_MOVE_MASTER_TO_OTHER_INSTANCE = "ACTION_MOVE_MASTER_TO_OTHER_INSTANCE";
public static final String ACTION_SCALE_AUTO_SCALING_REPLICAS_UP_DOWN = "ACTION_SCALE_AUTO_SCALING_REPLICAS_UP_DOWN";
private final StringMessages stringMessages;
@@ -59,6 +60,7 @@ public class ApplicationReplicaSetsImagesBarCell extends ImagesBarCell {
}
result.add(new ImageSpec(ACTION_SWITCH_TO_REPLICA_ON_SHARED_INSTANCE, stringMessages.switchToReplicaOnSharedInstance(), IconResources.INSTANCE.scaleDownIcon()));
result.add(new ImageSpec(ACTION_MOVE_MASTER_TO_OTHER_INSTANCE, stringMessages.moveMasterToOtherInstance(), IconResources.INSTANCE.moveIcon()));
result.add(new ImageSpec(ACTION_SCALE_AUTO_SCALING_REPLICAS_UP_DOWN, stringMessages.scaleAutoScalingReplicasUpOrDown(), IconResources.INSTANCE.scaleIcon()));
return result;
}
}
@@ -358,6 +358,9 @@ public class LandscapeManagementPanel extends SimplePanel {
applicationReplicaSetsActionColumn.addAction(ApplicationReplicaSetsImagesBarCell.ACTION_SWITCH_TO_AUTO_SCALING_REPLICAS_ONLY,
applicationReplicaSetToUpgrade -> switchToAutoScalingReplicasOnly(stringMessages,
regionsTable.getSelectionModel().getSelectedObject(), Collections.singleton(applicationReplicaSetToUpgrade)));
applicationReplicaSetsActionColumn.addAction(ApplicationReplicaSetsImagesBarCell.ACTION_SCALE_AUTO_SCALING_REPLICAS_UP_DOWN,
applicationReplicaSetToUpgrade -> scaleAutoScalingReplicasUpDown(stringMessages,
regionsTable.getSelectionModel().getSelectedObject(), Collections.singleton(applicationReplicaSetToUpgrade)));
// see below for the finalization o the applicationRelicaSetsActionColumn; we need to have the machineImagesTable ready for the last action...
final CaptionPanel applicationReplicaSetsCaptionPanel = new CaptionPanel(stringMessages.applicationReplicaSets());
final VerticalPanel applicationReplicaSetsVerticalPanel = new VerticalPanel();
@@ -394,6 +397,11 @@ public class LandscapeManagementPanel extends SimplePanel {
e->switchToReplicaOnSharedInstance(stringMessages, regionsTable.getSelectionModel().getSelectedObject(),
applicationReplicaSetsTable.getSelectionModel().getSelectedSet()));
applicationReplicaSetsButtonPanel.add(useSharedInsteadOfDedicatedAutoScalingReplicasButton);
final SelectedElementsCountingButton<SailingApplicationReplicaSetDTO<String>> scaleAutoScalingReplicasUpDown = new SelectedElementsCountingButton<>(
stringMessages.scaleAutoScalingReplicasUpOrDown(), applicationReplicaSetsTable.getSelectionModel(),
e->scaleAutoScalingReplicasUpDown(stringMessages, regionsTable.getSelectionModel().getSelectedObject(),
applicationReplicaSetsTable.getSelectionModel().getSelectedSet()));
applicationReplicaSetsButtonPanel.add(scaleAutoScalingReplicasUpDown);
applicationReplicaSetsCaptionPanel.add(applicationReplicaSetsVerticalPanel);
applicationReplicaSetsVerticalPanel.add(applicationReplicaSetsTable);
applicationReplicaSetsBusy = new SimpleBusyIndicator();
@@ -553,11 +561,11 @@ public class LandscapeManagementPanel extends SimplePanel {
final Iterator<SailingApplicationReplicaSetDTO<String>> replicaSetIterator = selectedSet.iterator();
if (replicaSetIterator.hasNext()) {
applicationReplicaSetsBusy.setBusy(true);
useSingleSharedInsteadOfDedicatedAutoScalingReplica(instructions, replicaSetIterator, stringMessages);
scaleSingleAutoScalingReplicaSetUpDown(instructions, replicaSetIterator, stringMessages);
}
}
private void useSingleSharedInsteadOfDedicatedAutoScalingReplica(
private void scaleSingleAutoScalingReplicaSetUpDown(
SwitchToReplicaOnSharedInstanceDialog.SwitchToReplicaOnSharedInstanceDialogInstructions instructions,
final Iterator<SailingApplicationReplicaSetDTO<String>> replicaSetIterator, StringMessages stringMessages) {
assert replicaSetIterator.hasNext();
@@ -570,7 +578,7 @@ public class LandscapeManagementPanel extends SimplePanel {
instructions.getOptionalMemoryTotalSizeFactorOrNull(),
instructions.getOptionalSharedReplicaInstanceType(),
new ApplicationReplicaSetActionChainingCallback<SwitchToReplicaOnSharedInstanceDialogInstructions>(replicaSetIterator, replicaSet,
(i, rsi)->useSingleSharedInsteadOfDedicatedAutoScalingReplica(i, rsi, stringMessages), instructions,
(i, rsi)->scaleSingleAutoScalingReplicaSetUpDown(i, rsi, stringMessages), instructions,
replicaSetName->stringMessages.successfullyCreatedReplicaSet(replicaSetName)));
}
@@ -616,6 +624,39 @@ public class LandscapeManagementPanel extends SimplePanel {
}
}
private void scaleAutoScalingReplicasUpDown(StringMessages stringMessages, String selectedObject, Set<SailingApplicationReplicaSetDTO<String>> selectedSet) {
new ChangeAutoScalingReplicaInstanceTypeDialog(landscapeManagementService, stringMessages, errorReporter,
new DialogCallback<String>() {
@Override
public void ok(String instanceTypeName) {
final Iterator<SailingApplicationReplicaSetDTO<String>> replicaSetIterator = selectedSet.iterator();
if (replicaSetIterator.hasNext()) {
applicationReplicaSetsBusy.setBusy(true);
scaleSingleAutoScalingReplicaSetUpDown(instanceTypeName, replicaSetIterator, stringMessages);
}
}
private void scaleSingleAutoScalingReplicaSetUpDown(
String instanceTypeName,
final Iterator<SailingApplicationReplicaSetDTO<String>> replicaSetIterator, StringMessages stringMessages) {
assert replicaSetIterator.hasNext();
final SailingApplicationReplicaSetDTO<String> replicaSet = replicaSetIterator.next();
final String optionalKeyName = sshKeyManagementPanel.getSelectedKeyPair().getName();
final byte[] privateKeyEncryptionPassphrase = sshKeyManagementPanel.getPassphraseForPrivateKeyDecryption() != null
? sshKeyManagementPanel.getPassphraseForPrivateKeyDecryption().getBytes() : null;
landscapeManagementService.changeAutoScalingReplicasInstanceType(replicaSet,
instanceTypeName, optionalKeyName, privateKeyEncryptionPassphrase,
new ApplicationReplicaSetActionChainingCallback<String>(replicaSetIterator, replicaSet,
(itn, rsi)->scaleSingleAutoScalingReplicaSetUpDown(itn, rsi, stringMessages), instanceTypeName,
replicaSetName->stringMessages.successfullyScaledAutoScalingReplicasForReplicaSet(replicaSetName)));
}
@Override
public void cancel() {
}
}).show();
}
private Iterable<SailingApplicationReplicaSetDTO<String>> getApplicationReplicaSetsToUpgradeAutoScalingReplicaAmisFor(AmazonMachineImageDTO amiBeingUpdated) {
final Iterable<SailingApplicationReplicaSetDTO<String>> result;
final Set<SailingApplicationReplicaSetDTO<String>> selection = applicationReplicaSetsTable.getSelectionModel().getSelectedSet();
@@ -132,4 +132,8 @@ public interface LandscapeManagementWriteService extends RemoteService {
String optionalInstanceTypeOrNull, String optionalKeyName, byte[] privateKeyEncryptionPassphrase,
String optionalMasterReplicationBearerTokenOrNull, String optionalReplicaReplicationBearerTokenOrNull,
Integer optionalMemoryInMegabytesOrNull, Integer optionalMemoryTotalSizeFactorOrNull) throws Exception;
SailingApplicationReplicaSetDTO<String> changeAutoScalingReplicasInstanceType(
SailingApplicationReplicaSetDTO<String> replicaSet, String instanceTypeName,
String optionalKeyName, byte[] privateKeyEncryptionPassphrase) throws Exception;
}
@@ -246,4 +246,8 @@ public interface LandscapeManagementWriteServiceAsync {
String optionalReplicaReplicationBearerTokenOrNull, Integer optionalMemoryInMegabytesOrNull,
Integer optionalMemoryTotalSizeFactorOrNull,
AsyncCallback<SailingApplicationReplicaSetDTO<String>> callback);
void changeAutoScalingReplicasInstanceType(SailingApplicationReplicaSetDTO<String> replicaSet,
String instanceTypeName, String optionalKeyName, byte[] privateKeyEncryptionPassphrase,
AsyncCallback<SailingApplicationReplicaSetDTO<String>> callback);
}
@@ -134,4 +134,6 @@ com.sap.sse.gwt.adminconsole.StringMessages {
String moveMasterToOtherInstance();
String successfullyMovedMasterOfReplicaSet(String replicaSetName);
String successfullyRemovedApplicationReplicaSet(String replicaSetName);
String scaleAutoScalingReplicasUpOrDown();
String successfullyScaledAutoScalingReplicasForReplicaSet(String replicaSetName);
}
@@ -122,4 +122,6 @@ successfullySwitchedReplicaSetToAutoReplicasOnly=Successfully switched applicati
switchToReplicaOnSharedInstance=Switch to replica on shared instance
moveMasterToOtherInstance=Move master process to other instance
successfullyMovedMasterOfReplicaSet=Successfully moved master process of replica set {0}
successfullyRemovedApplicationReplicaSet=Successfully removed replica set {0}
successfullyRemovedApplicationReplicaSet=Successfully removed replica set {0}
scaleAutoScalingReplicasUpOrDown=Scale auto-scaling replicas up/down
successfullyScaledAutoScalingReplicasForReplicaSet=Successfully scaled auto-scaling replicas for replica set {0}
@@ -121,4 +121,6 @@ successfullySwitchedReplicaSetToAutoReplicasOnly=Anwendungs-Cluster {0} erfolgre
switchToReplicaOnSharedInstance=Geteilte Replika einrichten
moveMasterToOtherInstance=Master-Prozess auf andere Instanz verschieben
successfullyMovedMasterOfReplicaSet=Master-Prozess der Anwendungs-Clusters {0} erfolgreich verschoben
successfullyRemovedApplicationReplicaSet=Anwendungs-Cluster {0} erfolgreich gelöscht
successfullyRemovedApplicationReplicaSet=Anwendungs-Cluster {0} erfolgreich gelöscht
scaleAutoScalingReplicasUpOrDown=Auto-skalierende Replikas hoch/herunter skalieren
successfullyScaledAutoScalingReplicasForReplicaSet=Auto-skalierende Replikas für Anwendungs-Cluster {0} erfolgreich skaliert
@@ -41,7 +41,7 @@ import com.sap.sailing.landscape.impl.SailingAnalyticsProcessImpl;
import com.sap.sailing.landscape.procedures.DeployProcessOnMultiServer;
import com.sap.sailing.landscape.procedures.SailingAnalyticsHostSupplier;
import com.sap.sailing.landscape.procedures.SailingAnalyticsMasterConfiguration;
import com.sap.sailing.landscape.procedures.SailingProcessConfigurationVariables;
import com.sap.sailing.landscape.procedures.SailingAnalyticsProcessFactory;
import com.sap.sailing.landscape.procedures.UpgradeAmi;
import com.sap.sailing.landscape.ui.client.LandscapeManagementWriteService;
import com.sap.sailing.landscape.ui.impl.Activator;
@@ -394,7 +394,6 @@ public class LandscapeManagementWriteServiceImpl extends ResultCachingProxiedRem
checkLandscapeManageAwsPermission();
final AwsLandscape<String> landscape = getLandscape();
final AmazonMachineImage<String> ami = landscape.getImage(new AwsRegion(region, landscape), machineImageId);
// TODO bug5502: what about the auto-scaling groups still using this image? Should we figure this out before we allow removing it?
ami.delete();
}
@@ -610,24 +609,15 @@ public class LandscapeManagementWriteServiceImpl extends ResultCachingProxiedRem
private AwsApplicationReplicaSet<String, SailingAnalyticsMetrics, SailingAnalyticsProcess<String>> convertFromApplicationReplicaSetDTO(
final AwsRegion region, SailingApplicationReplicaSetDTO<String> applicationReplicaSetDTO)
throws UnknownHostException {
throws Exception {
final SailingAnalyticsProcess<String> master = getSailingAnalyticsProcessFromDTO(applicationReplicaSetDTO.getMaster());
final AwsApplicationReplicaSet<String, SailingAnalyticsMetrics, SailingAnalyticsProcess<String>> applicationReplicaSet =
getLandscape().getApplicationReplicaSet(region, applicationReplicaSetDTO.getReplicaSetName(),
getSailingAnalyticsProcessFromDTO(applicationReplicaSetDTO.getMaster()),
getSailingAnalyticsProcessesFromDTOs(applicationReplicaSetDTO.getReplicas()));
master, master.getReplicas(LandscapeService.WAIT_FOR_PROCESS_TIMEOUT, new SailingAnalyticsHostSupplier<String>(),
new SailingAnalyticsProcessFactory(this::getLandscape)));
return applicationReplicaSet;
}
private Iterable<SailingAnalyticsProcess<String>> getSailingAnalyticsProcessesFromDTOs(Iterable<SailingAnalyticsProcessDTO> processDTOs) {
return Util.map(processDTOs, processDTO->{
try {
return getSailingAnalyticsProcessFromDTO(processDTO);
} catch (UnknownHostException e) {
throw new RuntimeException(e);
}
});
}
private SailingAnalyticsProcess<String> getSailingAnalyticsProcessFromDTO(SailingAnalyticsProcessDTO processDTO) throws UnknownHostException {
return new SailingAnalyticsProcessImpl<String>(processDTO.getPort(),
getHostFromInstanceDTO(processDTO.getHost()), processDTO.getServerDirectory(),
@@ -638,14 +628,7 @@ public class LandscapeManagementWriteServiceImpl extends ResultCachingProxiedRem
return new SailingAnalyticsHostImpl<String, SailingAnalyticsHost<String>>(hostDTO.getInstanceId(),
new AwsAvailabilityZoneImpl(AvailabilityZone.builder().regionName(hostDTO.getRegion()).zoneId(hostDTO.getAvailabilityZoneId()).build(), getLandscape()),
InetAddress.getByName(hostDTO.getPrivateIpAddress()), hostDTO.getLaunchTimePoint(), getLandscape(),
(host, port, serverDirectory, telnetPort, serverName, additionalProperties)->{
try {
return new SailingAnalyticsProcessImpl<String>(port, host, serverDirectory, telnetPort, serverName,
((Number) additionalProperties.get(SailingProcessConfigurationVariables.EXPEDITION_PORT.name())).intValue(), getLandscape());
} catch (Exception e) {
throw new RuntimeException(e);
}
});
new SailingAnalyticsProcessFactory(this::getLandscape));
}
@Override
@@ -753,7 +736,7 @@ public class LandscapeManagementWriteServiceImpl extends ResultCachingProxiedRem
Util.map(applicationReplicaSetsToUpdate, rsDTO->{
try {
return convertFromApplicationReplicaSetDTO(region, rsDTO);
} catch (UnknownHostException e) {
} catch (Exception e) {
throw new RuntimeException(e);
}
});
@@ -812,4 +795,17 @@ public class LandscapeManagementWriteServiceImpl extends ResultCachingProxiedRem
privateKeyEncryptionPassphrase, optionalMasterReplicationBearerTokenOrNull, optionalReplicaReplicationBearerTokenOrNull,
optionalMemoryInMegabytesOrNull, optionalMemoryTotalSizeFactorOrNull), Optional.ofNullable(optionalKeyName), privateKeyEncryptionPassphrase);
}
@Override
public SailingApplicationReplicaSetDTO<String> changeAutoScalingReplicasInstanceType(
SailingApplicationReplicaSetDTO<String> applicationReplicaSetDTO, String instanceTypeName,
String optionalKeyName, byte[] privateKeyEncryptionPassphrase) throws Exception {
checkLandscapeManageAwsPermission();
final AwsRegion region = new AwsRegion(applicationReplicaSetDTO.getMaster().getHost().getRegion(), getLandscape());
final AwsApplicationReplicaSet<String, SailingAnalyticsMetrics, SailingAnalyticsProcess<String>> replicaSet =
convertFromApplicationReplicaSetDTO(region, applicationReplicaSetDTO);
return convertToSailingApplicationReplicaSetDTO(
getLandscapeService().changeAutoScalingReplicasInstanceType(replicaSet, InstanceType.valueOf(instanceTypeName)),
Optional.ofNullable(optionalKeyName), privateKeyEncryptionPassphrase);
}
}
@@ -1204,12 +1204,16 @@ public class LandscapeServiceImpl implements LandscapeService {
final AwsApplicationReplicaSet<String, SailingAnalyticsMetrics, SailingAnalyticsProcess<String>> result;
final AwsAutoScalingGroup autoScalingGroup = replicaSet.getAutoScalingGroup();
if (autoScalingGroup != null) {
final Iterable<SailingAnalyticsProcess<String>> oldReplicas = replicaSet.getMaster().getReplicas(
LandscapeService.WAIT_FOR_PROCESS_TIMEOUT, new SailingAnalyticsHostSupplier<String>(),
processFactoryFromHostAndServerDirectory);
getLandscape().updateInstanceTypeInAutoScalingGroup(replicaSet.getMaster().getHost().getRegion(), autoScalingGroup, replicaSet.getName(), instanceType);
final int oldMinSize = autoScalingGroup.getAutoScalingGroup().minSize();
final int newMinSize = autoScalingGroup.getAutoScalingGroup().instances().size() + 1;
final int newMinSize = autoScalingGroup.getAutoScalingGroup().desiredCapacity() + 1;
getLandscape().updateAutoScalingGroupMinSize(autoScalingGroup, newMinSize);
Iterable<SailingAnalyticsProcess<String>> newSetOfAllReplicas = replicaSet.getReplicas();
for (final SailingAnalyticsProcess<String> replica : replicaSet.getReplicas()) {
// Don't trust the replicas passed in by the client; it may be stale. Instead, obtain a new set of replicas from the master:
Iterable<SailingAnalyticsProcess<String>> newSetOfAllReplicas = oldReplicas;
for (final SailingAnalyticsProcess<String> replica : oldReplicas) {
final SailingAnalyticsHost<String> replicaHost = replica.getHost();
if (replicaHost.isManagedByAutoScalingGroup(autoScalingGroup)) {
logger.info("Replica "+replica+" is managed by auto-scaling group "+
@@ -0,0 +1,34 @@
package com.sap.sailing.landscape.procedures;
import java.util.Map;
import java.util.function.Supplier;
import com.sap.sailing.landscape.SailingAnalyticsHost;
import com.sap.sailing.landscape.SailingAnalyticsMetrics;
import com.sap.sailing.landscape.SailingAnalyticsProcess;
import com.sap.sailing.landscape.impl.SailingAnalyticsProcessImpl;
import com.sap.sse.landscape.application.ProcessFactory;
import com.sap.sse.landscape.aws.AwsLandscape;
public class SailingAnalyticsProcessFactory implements
ProcessFactory<String, SailingAnalyticsMetrics, SailingAnalyticsProcess<String>, SailingAnalyticsHost<String>> {
private final Supplier<AwsLandscape<String>> landscapeSupplier;
public SailingAnalyticsProcessFactory(Supplier<AwsLandscape<String>> landscapeSupplier) {
super();
this.landscapeSupplier = landscapeSupplier;
}
@Override
public SailingAnalyticsProcess<String> createProcess(SailingAnalyticsHost<String> host, int port,
String serverDirectory, Integer telnetPort, String serverName, Map<String, Object> additionalProperties) {
try {
final Number expeditionUdpPort = (Number) additionalProperties
.get(SailingProcessConfigurationVariables.EXPEDITION_PORT.name());
return new SailingAnalyticsProcessImpl<String>(port, host, serverDirectory, telnetPort, serverName,
expeditionUdpPort == null ? null : expeditionUdpPort.intValue(), landscapeSupplier.get());
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}