mirror of
https://github.com/floci-io/floci.git
synced 2026-11-24 06:20:24 -05:00
fix(elasticache): roll back proxy port and container on failed provisioning (#1618)
* fix(elasticache): roll back proxy port and container on failed provisioning * fix(elasticache): stop container even if proxy rollback fails * fix(elasticache): guard proxy stop and isolate rollback steps * test(elasticache): cover rollback when container start fails * fix: remove accidentally committed browse audit file Signed-off-by: Ahmed khaled <125749397+ahmedk20@users.noreply.github.com> * fix: remove accidentally committed browse audit file Signed-off-by: Ahmed khaled <125749397+ahmedk20@users.noreply.github.com> --------- Signed-off-by: Ahmed khaled <125749397+ahmedk20@users.noreply.github.com>
This commit is contained in:
1 parent
6c5f533f34
commit
8ba1e92713
2 files changed
+104
-18
No files matched your search
+42
-16
@@ -67,25 +67,51 @@ public class ElastiCacheService {
|
||||
LOG.infov("Creating replication group {0} with authMode={1} on proxy port {2}",
|
||||
groupId, authMode, String.valueOf(proxyPort));
|
||||
|
||||
ElastiCacheContainerHandle handle = containerManager.start(groupId, image);
|
||||
ElastiCacheContainerHandle handle = null;
|
||||
try {
|
||||
handle = containerManager.start(groupId, image);
|
||||
|
||||
String endpointHost = resolveEndpointHost();
|
||||
Endpoint endpoint = new Endpoint(endpointHost, proxyPort);
|
||||
ReplicationGroup group = new ReplicationGroup(
|
||||
groupId, description, ReplicationGroupStatus.AVAILABLE,
|
||||
authMode, endpoint, Instant.now(), proxyPort);
|
||||
group.setContainerId(handle.getContainerId());
|
||||
group.setContainerHost(handle.getHost());
|
||||
group.setContainerPort(handle.getPort());
|
||||
group.setAuthToken(authToken);
|
||||
String endpointHost = resolveEndpointHost();
|
||||
Endpoint endpoint = new Endpoint(endpointHost, proxyPort);
|
||||
ReplicationGroup group = new ReplicationGroup(
|
||||
groupId, description, ReplicationGroupStatus.AVAILABLE,
|
||||
authMode, endpoint, Instant.now(), proxyPort);
|
||||
group.setContainerId(handle.getContainerId());
|
||||
group.setContainerHost(handle.getHost());
|
||||
group.setContainerPort(handle.getPort());
|
||||
group.setAuthToken(authToken);
|
||||
|
||||
proxyManager.startProxy(groupId, authMode, proxyPort,
|
||||
handle.getHost(), handle.getPort(),
|
||||
(username, password) -> validatePassword(groupId, username, password));
|
||||
proxyManager.startProxy(groupId, authMode, proxyPort,
|
||||
handle.getHost(), handle.getPort(),
|
||||
(username, password) -> validatePassword(groupId, username, password));
|
||||
|
||||
groups.put(groupId, group);
|
||||
LOG.infov("Replication group {0} created, endpoint={1}:{2}", groupId, endpointHost, String.valueOf(proxyPort));
|
||||
return group;
|
||||
groups.put(groupId, group);
|
||||
LOG.infov("Replication group {0} created, endpoint={1}:{2}", groupId, endpointHost, String.valueOf(proxyPort));
|
||||
return group;
|
||||
} catch (RuntimeException e) {
|
||||
LOG.warnv("Replication group {0} provisioning failed, rolling back: {1}", groupId, e.getMessage());
|
||||
rollbackReplicationGroup(groupId, handle, proxyPort);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
private void rollbackReplicationGroup(String groupId, ElastiCacheContainerHandle handle, int proxyPort) {
|
||||
try {
|
||||
if (handle != null) {
|
||||
proxyManager.stopProxy(groupId);
|
||||
}
|
||||
} catch (RuntimeException e) {
|
||||
LOG.warnv("Error stopping proxy for replication group {0}: {1}", groupId, e.getMessage());
|
||||
}
|
||||
try {
|
||||
if (handle != null) {
|
||||
containerManager.stop(handle);
|
||||
}
|
||||
} catch (RuntimeException e) {
|
||||
LOG.warnv("Error stopping container for replication group {0}: {1}", groupId, e.getMessage());
|
||||
} finally {
|
||||
releaseProxyPort(proxyPort);
|
||||
}
|
||||
}
|
||||
|
||||
public ReplicationGroup getReplicationGroup(String groupId) {
|
||||
|
||||
Reference in new issue
Block a user