Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mbloch1986 committed Jul 28, 2023
1 parent 8e9dc8a commit e98b334
Show file tree
Hide file tree
Showing 12 changed files with 139 additions and 56 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ pom.xml.releaseBackup
release.properties
.idea/
aem-orchestrator.iml
core
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Added
- Add Preview-Publish & Preview-Publish-Dispatcher orchestration logic #RS-161

## [3.0.1] - 2020-12-02
### Fixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public boolean execute(String instanceId) {
String authorAemBaseUrl = aemHelperService.getAemUrlForAuthorElb();

try {
replicationAgentManager.deleteReplicationAgent(instanceId, authorAemBaseUrl, AgentRunMode.AUTHOR);
replicationAgentManager.deletePreviewReplicationAgent(instanceId, authorAemBaseUrl, AgentRunMode.AUTHOR);
} catch (ApiException e) {
logger.warn("Failed to delete replication agent on author for previewPublish id: " + instanceId +
". It may already be deleted.");
Expand All @@ -59,7 +59,7 @@ public boolean execute(String instanceId) {
if (reverseReplicationEnabled) {
logger.debug("Reverse replication is enabled");
try {
replicationAgentManager.deleteReverseReplicationAgent(instanceId, authorAemBaseUrl,
replicationAgentManager.deletePreviewReverseReplicationAgent(instanceId, authorAemBaseUrl,
AgentRunMode.AUTHOR);

} catch (ApiException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ private boolean performSnapshot(String instanceId, String activePreviewPublishId
}

} catch (Exception e) {
logger.error("Error while pausing and attempting to snapshot an active previewPublish instance", e);
logger.error("Error while pausing and attempting to snapshot an active preview Publish instance", e);
success = false;
} finally {
// Always need to resume active previewPublish instance replication queue
Expand All @@ -157,10 +157,10 @@ private boolean pairAndTagWithDispatcher(String instanceId, String authorAemBase

try {
// Find unpaired previewPublish dispatcher and pair it with tags
logger.debug("Attempting to find unpaired previewPublish dispatcher instance");
logger.debug("Attempting to find unpaired Preview Publish dispatcher instance");
String unpairedDispatcherId = aemHelperService.findUnpairedPreviewPublishDispatcher(instanceId);

logger.debug("Pairing previewPublish instance (" + instanceId + ") with pubish dispatcher ("
logger.debug("Pairing previewPublish instance (" + instanceId + ") with preview publish dispatcher ("
+ unpairedDispatcherId + ") via tags");
aemHelperService.pairPreviewPublishWithDispatcher(instanceId, unpairedDispatcherId);

Expand All @@ -182,7 +182,7 @@ private void attachContentHealthCheckAlarm(String instanceId) {
logger.info("Creating content health check alarm");
aemHelperService.createContentHealthAlarmForPreviewPublisher(instanceId);
} catch (Exception e) {
logger.warn("Failed to create content health check alarm for previewPublish instance " + instanceId, e);
logger.warn("Failed to create content health check alarm for Preview Publish instance " + instanceId, e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ private boolean pairAndTagWithDispatcher(String instanceId, String authorAemBase
logger.debug("Attempting to find unpaired publish dispatcher instance");
String unpairedDispatcherId = aemHelperService.findUnpairedPublishDispatcher(instanceId);

logger.debug("Pairing publish instance (" + instanceId + ") with pubish dispatcher ("
logger.debug("Pairing publish instance (" + instanceId + ") with preview publish dispatcher ("
+ unpairedDispatcherId + ") via tags");
aemHelperService.pairPublishWithDispatcher(instanceId, unpairedDispatcherId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,23 +118,27 @@ public EnvironmentValues envValues(final AwsHelperService awsHelper) {
logger.debug("Resolved auto scaling group name for publish dispatcher to: " +
envValues.getAutoScaleGroupNameForPublishDispatcher());

envValues.setAutoScaleGroupNameForPreviewPublishDispatcher(
awsHelper.getStackPhysicalResourceId(awsPreviewPublishDispatcherStackName, awsPreviewPublishDispatcherAutoScaleGroupLogicalId));
logger.debug("Resolved auto scaling group name for previewPublish dispatcher to: " +
envValues.getAutoScaleGroupNameForPreviewPublishDispatcher());

if (awsPreviewPublishDispatcherStackName != null && !awsPreviewPublishDispatcherStackName.equals("")) {
envValues.setAutoScaleGroupNameForPreviewPublishDispatcher(
awsHelper.getStackPhysicalResourceId(awsPreviewPublishDispatcherStackName, awsPreviewPublishDispatcherAutoScaleGroupLogicalId)
);

logger.debug("Resolved auto scaling group name for previewPublish dispatcher to: " +
envValues.getAutoScaleGroupNameForPreviewPublishDispatcher());

envValues.setAutoScaleGroupNameForPreviewPublish(
awsHelper.getStackPhysicalResourceId(awsPreviewPublishStackName, awsPreviewPublishAutoScaleGroupLogicalId));

logger.debug("Resolved auto scaling group name for previewPublish to: " +
envValues.getAutoScaleGroupNameForPreviewPublish());
}

envValues.setAutoScaleGroupNameForPublish(
awsHelper.getStackPhysicalResourceId(awsPublishStackName, awsPublishAutoScaleGroupLogicalId));

logger.debug("Resolved auto scaling group name for publish to: " +
envValues.getAutoScaleGroupNameForPublish());

envValues.setAutoScaleGroupNameForPreviewPublish(
awsHelper.getStackPhysicalResourceId(awsPreviewPublishStackName, awsPreviewPublishAutoScaleGroupLogicalId));

logger.debug("Resolved auto scaling group name for previewPublish to: " +
envValues.getAutoScaleGroupNameForPreviewPublish());

envValues.setAutoScaleGroupNameForAuthorDispatcher(
awsHelper.getStackPhysicalResourceId(awsAuthorDispatcherStackName, awsAuthorDispatcherAutoScaleGroupLogicalId));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
public enum InstanceTags {

PAIR_INSTANCE_ID("PairInstanceId"),
PREVIEW_PAIR_INSTANCE_ID("PreviewPairInstanceId"),
INSTANCE_ID("InstanceId"),
AEM_PUBLISH_HOST("PublishHost"),
AEM_PUBLISH_DISPATCHER_HOST("PublishDispatcherHost"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ public String getPreviewPublishIdForPairedDispatcher(String dispatcherInstanceId
envValues.getAutoScaleGroupNameForPreviewPublish());

return previewPublishIds.stream().filter(p -> dispatcherInstanceId.equals(
awsHelperService.getTags(p).get(PAIR_INSTANCE_ID.getTagName()))).findFirst().orElse(null);
awsHelperService.getTags(p).get(PREVIEW_PAIR_INSTANCE_ID.getTagName()))).findFirst().orElse(null);
}

/**
Expand Down Expand Up @@ -299,7 +299,7 @@ public String getDispatcherIdForPairedPreviewPublish(String previewPublishInstan
envValues.getAutoScaleGroupNameForPreviewPublishDispatcher());

return dispatcherIds.stream().filter(d -> previewPublishInstanceId.equals(
awsHelperService.getTags(d).get(PAIR_INSTANCE_ID.getTagName()))).findFirst().orElse(null);
awsHelperService.getTags(d).get(PREVIEW_PAIR_INSTANCE_ID.getTagName()))).findFirst().orElse(null);
}

/**
Expand Down Expand Up @@ -533,14 +533,14 @@ public void pairPublishWithDispatcher(String publishId, String dispatcherId) {
*/
public void pairPreviewPublishWithDispatcher(String previewPublishId, String dispatcherId) {
Map<String, String> previewPublishTags = new HashMap<String, String>();
previewPublishTags.put(AEM_PUBLISH_DISPATCHER_HOST.getTagName(), awsHelperService.getPrivateIp(dispatcherId));
previewPublishTags.put(PAIR_INSTANCE_ID.getTagName(), dispatcherId);
previewPublishTags.put(AEM_PREVIEW_PUBLISH_DISPATCHER_HOST.getTagName(), awsHelperService.getPrivateIp(dispatcherId));
previewPublishTags.put(PREVIEW_PAIR_INSTANCE_ID.getTagName(), dispatcherId);
awsHelperService.addTags(previewPublishId, previewPublishTags);

Map<String, String> dispatcherTags = new HashMap<String, String>();
dispatcherTags.put(AEM_PUBLISH_HOST.getTagName(), awsHelperService.getPrivateIp(previewPublishId));
dispatcherTags.put(PAIR_INSTANCE_ID.getTagName(), previewPublishId);
awsHelperService.addTags(dispatcherId, dispatcherTags);
Map<String, String> previewDispatcherTags = new HashMap<String, String>();
previewDispatcherTags.put(AEM_PREVIEW_PUBLISH_HOST.getTagName(), awsHelperService.getPrivateIp(previewPublishId));
previewDispatcherTags.put(PREVIEW_PAIR_INSTANCE_ID.getTagName(), previewPublishId);
awsHelperService.addTags(dispatcherId, previewDispatcherTags);
}

/**
Expand Down Expand Up @@ -590,7 +590,7 @@ public String findUnpairedPreviewPublishDispatcher(String instanceId) throws NoP
envValues.getAutoScaleGroupNameForPreviewPublishDispatcher());
//Filter the list to get all possible eligible candidates
dispatcherIds = dispatcherIds.stream().filter(d ->
isViablePair(instanceId, d.getInstanceId())).collect(Collectors.toList());
isViablePreviewPair(instanceId, d.getInstanceId())).collect(Collectors.toList());

if(dispatcherIds.size() > 1) {
String previewPublishAZ = awsHelperService.getAvailabilityZone(instanceId);
Expand All @@ -613,6 +613,12 @@ private boolean isViablePair(String instanceId, String dispatcherInstanceId) {
tags.get(PAIR_INSTANCE_ID.getTagName()).equals(instanceId); //Or it's already paired to the instance
}

private boolean isViablePreviewPair(String instanceId, String previewDispatcherInstanceId) {
Map<String, String> tags = awsHelperService.getTags(previewDispatcherInstanceId);
return !tags.containsKey(PREVIEW_PAIR_INSTANCE_ID.getTagName()) || //Either it's missing a pairing tag
tags.get(PREVIEW_PAIR_INSTANCE_ID.getTagName()).equals(instanceId); //Or it's already paired to the instance
}

/**
* Creates a CloudWatch content health alarm for a given publish instance
* @param instanceId of the publish instance
Expand All @@ -633,7 +639,7 @@ public void createContentHealthAlarmForPublisher(String instanceId) {
public void createContentHealthAlarmForPreviewPublisher(String instanceId) {
awsHelperService.createContentHealthCheckAlarm(
getContentHealthCheckAlarmName(instanceId),
"Content Health Alarm for PreviewPublish Instance " + instanceId,
"Content Health Alarm for Preview Publish Instance " + instanceId,
instanceId,
awsPreviewPublishDispatcherStackName,
envValues.getTopicArn());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,18 @@ public void setUp() throws Exception {
}

@Test
public void testTerminatePairedDispatcherAndDeleteReplicationAgent() throws Exception {
public void testTerminatePairedPreviewDispatcherAndDeleteReplicationAgent() throws Exception {
when(aemHelperService.getDispatcherIdForPairedPreviewPublish(instanceId)).thenReturn(pairedDispatcherId);

boolean success = action.execute(instanceId);

verify(awsHelperService, times(1)).terminateInstance(pairedDispatcherId);

verify(replicationAgentManager, times(1)).deleteReplicationAgent(instanceId, authorAemBaseUrl,
verify(replicationAgentManager, times(1)).deletePreviewReplicationAgent(instanceId, authorAemBaseUrl,
AgentRunMode.AUTHOR);

//Ensure reverse replication queue removal not called unless enabled
verify(replicationAgentManager, times(0)).deleteReverseReplicationAgent(instanceId, authorAemBaseUrl,
verify(replicationAgentManager, times(0)).deletePreviewReverseReplicationAgent(instanceId, authorAemBaseUrl,
AgentRunMode.AUTHOR);

assertThat(success, equalTo(true));
Expand All @@ -75,7 +75,7 @@ public void testCantFindPairedDispatcher() throws Exception {

verify(awsHelperService, times(0)).terminateInstance(pairedDispatcherId);

verify(replicationAgentManager, times(1)).deleteReplicationAgent(instanceId, authorAemBaseUrl,
verify(replicationAgentManager, times(1)).deletePreviewReplicationAgent(instanceId, authorAemBaseUrl,
AgentRunMode.AUTHOR);

assertThat(success, equalTo(true));
Expand All @@ -85,7 +85,7 @@ public void testCantFindPairedDispatcher() throws Exception {
public void testHandlesExceptionWhenDeletingReplicationAgent() throws Exception {
when(aemHelperService.getDispatcherIdForPairedPreviewPublish(instanceId)).thenReturn(pairedDispatcherId);

doThrow(new ApiException()).when(replicationAgentManager).deleteReplicationAgent(instanceId, authorAemBaseUrl,
doThrow(new ApiException()).when(replicationAgentManager).deletePreviewReplicationAgent(instanceId, authorAemBaseUrl,
AgentRunMode.AUTHOR);

boolean success = action.execute(instanceId);
Expand All @@ -105,10 +105,10 @@ public void testDeletesReverseReplicationQueueIfEnabled() throws Exception {

verify(awsHelperService, times(1)).terminateInstance(pairedDispatcherId);

verify(replicationAgentManager, times(1)).deleteReplicationAgent(instanceId, authorAemBaseUrl,
verify(replicationAgentManager, times(1)).deletePreviewReplicationAgent(instanceId, authorAemBaseUrl,
AgentRunMode.AUTHOR);

verify(replicationAgentManager, times(1)).deleteReverseReplicationAgent(instanceId, authorAemBaseUrl,
verify(replicationAgentManager, times(1)).deletePreviewReverseReplicationAgent(instanceId, authorAemBaseUrl,
AgentRunMode.AUTHOR);

assertThat(success, equalTo(true));
Expand All @@ -118,7 +118,7 @@ public void testDeletesReverseReplicationQueueIfEnabled() throws Exception {
public void testDeletesReverseReplicationWithException() throws Exception {
when(aemHelperService.getDispatcherIdForPairedPreviewPublish(instanceId)).thenReturn(pairedDispatcherId);

doThrow(new ApiException()).when(replicationAgentManager).deleteReverseReplicationAgent(instanceId, authorAemBaseUrl,
doThrow(new ApiException()).when(replicationAgentManager).deletePreviewReverseReplicationAgent(instanceId, authorAemBaseUrl,
AgentRunMode.AUTHOR);

setField(action, "reverseReplicationEnabled", true);
Expand All @@ -127,7 +127,7 @@ public void testDeletesReverseReplicationWithException() throws Exception {

verify(awsHelperService, times(1)).terminateInstance(pairedDispatcherId);

verify(replicationAgentManager, times(1)).deleteReplicationAgent(instanceId, authorAemBaseUrl,
verify(replicationAgentManager, times(1)).deletePreviewReplicationAgent(instanceId, authorAemBaseUrl,
AgentRunMode.AUTHOR);

assertThat(success, equalTo(true));
Expand Down
Loading

0 comments on commit e98b334

Please sign in to comment.