From e98b334fceabe73d14c0f345ea447bb374be0268 Mon Sep 17 00:00:00 2001 From: Michael Bloch Date: Fri, 28 Jul 2023 11:35:02 +1000 Subject: [PATCH] Fixes --- .gitignore | 1 + CHANGELOG.md | 2 + .../ScaleDownPreviewPublishAction.java | 4 +- .../actions/ScaleUpPreviewPublishAction.java | 8 +- .../actions/ScaleUpPublishAction.java | 2 +- .../aemorchestrator/config/AemConfig.java | 26 ++++--- .../aemorchestrator/model/InstanceTags.java | 1 + .../service/AemInstanceHelperService.java | 26 ++++--- .../ScaleDownPreviewPublishActionTest.java | 18 ++--- .../aemorchestrator/config/AemConfigTest.java | 76 ++++++++++++++++++- .../service/AemInstanceHelperServiceTest.java | 28 +++---- .../service/ResourceReadyCheckerTest.java | 3 - 12 files changed, 139 insertions(+), 56 deletions(-) diff --git a/.gitignore b/.gitignore index 1c6fe78..79a1b1f 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ pom.xml.releaseBackup release.properties .idea/ aem-orchestrator.iml +core diff --git a/CHANGELOG.md b/CHANGELOG.md index 8062f45..095d0ff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/main/java/com/shinesolutions/aemorchestrator/actions/ScaleDownPreviewPublishAction.java b/src/main/java/com/shinesolutions/aemorchestrator/actions/ScaleDownPreviewPublishAction.java index fe36945..fc989e4 100644 --- a/src/main/java/com/shinesolutions/aemorchestrator/actions/ScaleDownPreviewPublishAction.java +++ b/src/main/java/com/shinesolutions/aemorchestrator/actions/ScaleDownPreviewPublishAction.java @@ -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."); @@ -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) { diff --git a/src/main/java/com/shinesolutions/aemorchestrator/actions/ScaleUpPreviewPublishAction.java b/src/main/java/com/shinesolutions/aemorchestrator/actions/ScaleUpPreviewPublishAction.java index bab65cd..5344ad8 100644 --- a/src/main/java/com/shinesolutions/aemorchestrator/actions/ScaleUpPreviewPublishAction.java +++ b/src/main/java/com/shinesolutions/aemorchestrator/actions/ScaleUpPreviewPublishAction.java @@ -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 @@ -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); @@ -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); } } diff --git a/src/main/java/com/shinesolutions/aemorchestrator/actions/ScaleUpPublishAction.java b/src/main/java/com/shinesolutions/aemorchestrator/actions/ScaleUpPublishAction.java index f4b790b..d25e15f 100644 --- a/src/main/java/com/shinesolutions/aemorchestrator/actions/ScaleUpPublishAction.java +++ b/src/main/java/com/shinesolutions/aemorchestrator/actions/ScaleUpPublishAction.java @@ -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); diff --git a/src/main/java/com/shinesolutions/aemorchestrator/config/AemConfig.java b/src/main/java/com/shinesolutions/aemorchestrator/config/AemConfig.java index ad92dc9..02923cd 100644 --- a/src/main/java/com/shinesolutions/aemorchestrator/config/AemConfig.java +++ b/src/main/java/com/shinesolutions/aemorchestrator/config/AemConfig.java @@ -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)); diff --git a/src/main/java/com/shinesolutions/aemorchestrator/model/InstanceTags.java b/src/main/java/com/shinesolutions/aemorchestrator/model/InstanceTags.java index 6a8a5d7..593ddb2 100644 --- a/src/main/java/com/shinesolutions/aemorchestrator/model/InstanceTags.java +++ b/src/main/java/com/shinesolutions/aemorchestrator/model/InstanceTags.java @@ -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"), diff --git a/src/main/java/com/shinesolutions/aemorchestrator/service/AemInstanceHelperService.java b/src/main/java/com/shinesolutions/aemorchestrator/service/AemInstanceHelperService.java index 129d30d..b7d8ee2 100644 --- a/src/main/java/com/shinesolutions/aemorchestrator/service/AemInstanceHelperService.java +++ b/src/main/java/com/shinesolutions/aemorchestrator/service/AemInstanceHelperService.java @@ -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); } /** @@ -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); } /** @@ -533,14 +533,14 @@ public void pairPublishWithDispatcher(String publishId, String dispatcherId) { */ public void pairPreviewPublishWithDispatcher(String previewPublishId, String dispatcherId) { Map previewPublishTags = new HashMap(); - 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 dispatcherTags = new HashMap(); - dispatcherTags.put(AEM_PUBLISH_HOST.getTagName(), awsHelperService.getPrivateIp(previewPublishId)); - dispatcherTags.put(PAIR_INSTANCE_ID.getTagName(), previewPublishId); - awsHelperService.addTags(dispatcherId, dispatcherTags); + Map previewDispatcherTags = new HashMap(); + previewDispatcherTags.put(AEM_PREVIEW_PUBLISH_HOST.getTagName(), awsHelperService.getPrivateIp(previewPublishId)); + previewDispatcherTags.put(PREVIEW_PAIR_INSTANCE_ID.getTagName(), previewPublishId); + awsHelperService.addTags(dispatcherId, previewDispatcherTags); } /** @@ -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); @@ -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 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 @@ -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()); diff --git a/src/test/java/com/shinesolutions/aemorchestrator/actions/ScaleDownPreviewPublishActionTest.java b/src/test/java/com/shinesolutions/aemorchestrator/actions/ScaleDownPreviewPublishActionTest.java index 68a281c..1796742 100644 --- a/src/test/java/com/shinesolutions/aemorchestrator/actions/ScaleDownPreviewPublishActionTest.java +++ b/src/test/java/com/shinesolutions/aemorchestrator/actions/ScaleDownPreviewPublishActionTest.java @@ -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)); @@ -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)); @@ -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); @@ -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)); @@ -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); @@ -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)); diff --git a/src/test/java/com/shinesolutions/aemorchestrator/config/AemConfigTest.java b/src/test/java/com/shinesolutions/aemorchestrator/config/AemConfigTest.java index 31aae36..5f18faa 100644 --- a/src/test/java/com/shinesolutions/aemorchestrator/config/AemConfigTest.java +++ b/src/test/java/com/shinesolutions/aemorchestrator/config/AemConfigTest.java @@ -56,7 +56,80 @@ public void testAemCredentials_ReadingThrowsException() throws Exception { } @Test - public void testEnvValue() { + public void testEnvValueStandardArchitecture() { + AwsHelperService awsHelperService = mock(AwsHelperService.class); + + // Set autoScaleGroupNameForPublishDispatcher + String awsPublishDispatcherStackName = "awsPublishDispatcherStackName"; + String awsPublishDispatcherAutoScaleGroupLogicalId = "awsPublishDispatcherAutoScaleGroupLogicalId"; + String autoScaleGroupNameForPublishDispatcher = "autoScaleGroupNameForPublishDispatcher"; + setField(aemConfig, "awsPublishDispatcherStackName", awsPublishDispatcherStackName); + setField(aemConfig, "awsPublishDispatcherAutoScaleGroupLogicalId", awsPublishDispatcherAutoScaleGroupLogicalId); + when(awsHelperService.getStackPhysicalResourceId( + awsPublishDispatcherStackName, + awsPublishDispatcherAutoScaleGroupLogicalId)) + .thenReturn(autoScaleGroupNameForPublishDispatcher); + + // Set autoScaleGroupNameForPublish + String awsPublishStackName = "awsPublishStackName"; + String awsPublishAutoScaleGroupLogicalId = "awsPublishAutoScaleGroupLogicalId"; + String autoScaleGroupNameForPublish = "autoScaleGroupNameForPublish"; + setField(aemConfig, "awsPublishStackName", awsPublishStackName); + setField(aemConfig, "awsPublishAutoScaleGroupLogicalId", awsPublishAutoScaleGroupLogicalId); + when(awsHelperService.getStackPhysicalResourceId( + awsPublishStackName, + awsPublishAutoScaleGroupLogicalId)) + .thenReturn(autoScaleGroupNameForPublish); + + // Set autoScaleGroupNameForAuthorDispatcher + String awsAuthorDispatcherStackName = "awsAuthorDispatcherStackName"; + String awsAuthorDispatcherAutoScaleGroupLogicalId = "awsAuthorDispatcherAutoScaleGroupLogicalId"; + String autoScaleGroupNameForAuthorDispatcher = "autoScaleGroupNameForAuthorDispatcher"; + setField(aemConfig, "awsAuthorDispatcherStackName", awsAuthorDispatcherStackName); + setField(aemConfig, "awsAuthorDispatcherAutoScaleGroupLogicalId", awsAuthorDispatcherAutoScaleGroupLogicalId); + when(awsHelperService.getStackPhysicalResourceId( + awsAuthorDispatcherStackName, + awsAuthorDispatcherAutoScaleGroupLogicalId)) + .thenReturn(autoScaleGroupNameForAuthorDispatcher); + + // Set elasticLoadBalancerNameForAuthor + String awsAuthorStackName = "awsAuthorStackName"; + String awsAuthorLoadBalancerLogicalId = "awsAuthorLoadBalancerLogicalId"; + String elasticLoadBalancerNameForAuthor = "elasticLoadBalancerNameForAuthor"; + setField(aemConfig, "awsAuthorStackName", awsAuthorStackName); + setField(aemConfig, "awsAuthorLoadBalancerLogicalId", awsAuthorLoadBalancerLogicalId); + when(awsHelperService.getElbName( + awsHelperService.getStackPhysicalResourceId( + awsAuthorStackName, + awsAuthorLoadBalancerLogicalId + ))).thenReturn(elasticLoadBalancerNameForAuthor); + + // Set elasticLoadBalancerAuthorDns + String elasticLoadBalancerAuthorDns = "elasticLoadBalancerAuthorDns"; + when(awsHelperService.getElbDnsName(elasticLoadBalancerNameForAuthor)).thenReturn(elasticLoadBalancerAuthorDns); + + // Set topicArn + String awsMessagingStackName = "awsMessagingStackName"; + String awsSnsTopicLogicalId = "awsSnsTopicLogicalId"; + String topicArn = "topicArn"; + setField(aemConfig, "awsMessagingStackName", awsMessagingStackName); + setField(aemConfig, "awsSnsTopicLogicalId", awsSnsTopicLogicalId); + when(awsHelperService.getStackPhysicalResourceId(awsMessagingStackName, awsSnsTopicLogicalId)).thenReturn(topicArn); + + EnvironmentValues envValues = aemConfig.envValues(awsHelperService); + + assertThat(envValues.getAutoScaleGroupNameForPublishDispatcher(), equalTo(autoScaleGroupNameForPublishDispatcher)); + assertThat(envValues.getAutoScaleGroupNameForPublish(), equalTo(autoScaleGroupNameForPublish)); + assertThat(envValues.getAutoScaleGroupNameForPreviewPublishDispatcher(), equalTo(null)); + assertThat(envValues.getAutoScaleGroupNameForPreviewPublish(), equalTo(null)); + assertThat(envValues.getAutoScaleGroupNameForAuthorDispatcher(), equalTo(autoScaleGroupNameForAuthorDispatcher)); + assertThat(envValues.getElasticLoadBalancerNameForAuthor(), equalTo(elasticLoadBalancerNameForAuthor)); + assertThat(envValues.getElasticLoadBalancerAuthorDns(), equalTo(elasticLoadBalancerAuthorDns)); + assertThat(envValues.getTopicArn(), equalTo(topicArn)); + } + + @Test + public void testEnvValuePreviewArchitecture() { AwsHelperService awsHelperService = mock(AwsHelperService.class); // Set autoScaleGroupNameForPublishDispatcher @@ -118,7 +191,6 @@ public void testEnvValue() { String awsAuthorStackName = "awsAuthorStackName"; String awsAuthorLoadBalancerLogicalId = "awsAuthorLoadBalancerLogicalId"; String elasticLoadBalancerNameForAuthor = "elasticLoadBalancerNameForAuthor"; - String elasticLoadBalancerArnForAuthor = "arn:aws:elasticloadbalancing:ap-southeast-2:918473058104:loadbalancer/app/bloch-Autho-1GWRY37R2O1GQ/809dd96ac8ee4083"; setField(aemConfig, "awsAuthorStackName", awsAuthorStackName); setField(aemConfig, "awsAuthorLoadBalancerLogicalId", awsAuthorLoadBalancerLogicalId); when(awsHelperService.getElbName( diff --git a/src/test/java/com/shinesolutions/aemorchestrator/service/AemInstanceHelperServiceTest.java b/src/test/java/com/shinesolutions/aemorchestrator/service/AemInstanceHelperServiceTest.java index 87072b9..c8161e0 100644 --- a/src/test/java/com/shinesolutions/aemorchestrator/service/AemInstanceHelperServiceTest.java +++ b/src/test/java/com/shinesolutions/aemorchestrator/service/AemInstanceHelperServiceTest.java @@ -520,7 +520,7 @@ public void testFindUnpairedPreviewPublishDispatcher() throws Exception { EC2Instance instance3 = new EC2Instance().withInstanceId("3rd-222983").withAvailabilityZone(previewPublishAZ); Map tagsWithPairName = new HashMap<>(); - tagsWithPairName.put(PAIR_INSTANCE_ID.getTagName(), "testPair"); + tagsWithPairName.put(PREVIEW_PAIR_INSTANCE_ID.getTagName(), "testPair"); Map tagsWithoutPairName = new HashMap<>(); @@ -579,7 +579,7 @@ public void testFindUnpairedPreviewPublishDispatcherDiffAvailablityZone() throws EC2Instance instance3 = new EC2Instance().withInstanceId("3rd-222983").withAvailabilityZone(previewPublishAZ); Map tagsWithPairName = new HashMap<>(); - tagsWithPairName.put(PAIR_INSTANCE_ID.getTagName(), "testPair"); + tagsWithPairName.put(PREVIEW_PAIR_INSTANCE_ID.getTagName(), "testPair"); Map tagsWithoutPairName = new HashMap<>(); @@ -639,7 +639,7 @@ public void testFindUnpairedPreviewPublishDispatcherSameAvailablityZone() throws EC2Instance instance3 = new EC2Instance().withInstanceId("3rd-222983").withAvailabilityZone(previewPublishAZ); Map tagsWithPairName = new HashMap<>(); - tagsWithPairName.put(PAIR_INSTANCE_ID.getTagName(), "testPair"); + tagsWithPairName.put(PREVIEW_PAIR_INSTANCE_ID.getTagName(), "testPair"); Map tagsWithoutPairName = new HashMap<>(); @@ -699,7 +699,7 @@ public void testFindUnpairedPreviewPublishDispatcherNoSameAvailablityZone() thro EC2Instance instance3 = new EC2Instance().withInstanceId("3rd-222983").withAvailabilityZone("B"); Map tagsWithPairName = new HashMap<>(); - tagsWithPairName.put(PAIR_INSTANCE_ID.getTagName(), "testPair"); + tagsWithPairName.put(PREVIEW_PAIR_INSTANCE_ID.getTagName(), "testPair"); Map tagsWithoutPairName = new HashMap<>(); @@ -775,7 +775,7 @@ public void testFindUnpairedPreviewPublishDispatcherAlreadyPaired() throws Excep EC2Instance instance2 = new EC2Instance().withInstanceId("2nd-111982").withAvailabilityZone(previewPublishAZ); Map tagsWithPairName = new HashMap<>(); - tagsWithPairName.put(PAIR_INSTANCE_ID.getTagName(), "testPair"); + tagsWithPairName.put(PREVIEW_PAIR_INSTANCE_ID.getTagName(), "testPair"); Map tagsWithAlreadyPairedId = new HashMap<>(); tagsWithAlreadyPairedId.put(PAIR_INSTANCE_ID.getTagName(), instanceId); @@ -842,10 +842,10 @@ public void testGetPreviewPublishIdForPairedDispatcherWithFoundPair() { String dispatcherId = "dis-4385974"; Map tagsWithPair = new HashMap<>(); - tagsWithPair.put(PAIR_INSTANCE_ID.getTagName(), dispatcherId); + tagsWithPair.put(PREVIEW_PAIR_INSTANCE_ID.getTagName(), dispatcherId); Map tagsWithoutPair = new HashMap<>(); - tagsWithoutPair.put(PAIR_INSTANCE_ID.getTagName(), "abc-35734685"); + tagsWithoutPair.put(PREVIEW_PAIR_INSTANCE_ID.getTagName(), "abc-35734685"); Map tagsMissingPair = new HashMap<>(); @@ -946,10 +946,10 @@ public void testGetDispatcherIdForPairedPreviewPublishWithFoundPair() { String previewPublishId = "dis-4385974"; Map tagsWithPair = new HashMap<>(); - tagsWithPair.put(PAIR_INSTANCE_ID.getTagName(), previewPublishId); + tagsWithPair.put(PREVIEW_PAIR_INSTANCE_ID.getTagName(), previewPublishId); Map tagsWithoutPair = new HashMap<>(); - tagsWithoutPair.put(PAIR_INSTANCE_ID.getTagName(), "abc-35734685"); + tagsWithoutPair.put(PREVIEW_PAIR_INSTANCE_ID.getTagName(), "abc-35734685"); Map tagsMissingPair = new HashMap<>(); @@ -1123,14 +1123,14 @@ public void testPairPreviewPublishWithDispatcher() { Map previewPublishTags = mapCaptor.getAllValues().get(0); //Confirm that the correct tags and their values are set for previewPublish instance - assertThat(previewPublishTags.get(AEM_PUBLISH_DISPATCHER_HOST.getTagName()), equalTo(dispatcherHost)); - assertThat(previewPublishTags.get(PAIR_INSTANCE_ID.getTagName()), equalTo(dispatcherId)); + assertThat(previewPublishTags.get(AEM_PREVIEW_PUBLISH_DISPATCHER_HOST.getTagName()), equalTo(dispatcherHost)); + assertThat(previewPublishTags.get(PREVIEW_PAIR_INSTANCE_ID.getTagName()), equalTo(dispatcherId)); - Map dispatcherTags = mapCaptor.getAllValues().get(1); + Map previewDispatcherTags = mapCaptor.getAllValues().get(1); //Confirm that the correct tags and their values are set for previewPublish dispatcher - assertThat(dispatcherTags.get(AEM_PUBLISH_HOST.getTagName()), equalTo(previewPublishHost)); - assertThat(dispatcherTags.get(PAIR_INSTANCE_ID.getTagName()), equalTo(previewPublishId)); + assertThat(previewDispatcherTags.get(AEM_PREVIEW_PUBLISH_HOST.getTagName()), equalTo(previewPublishHost)); + assertThat(previewDispatcherTags.get(PREVIEW_PAIR_INSTANCE_ID.getTagName()), equalTo(previewPublishId)); } @Test diff --git a/src/test/java/com/shinesolutions/aemorchestrator/service/ResourceReadyCheckerTest.java b/src/test/java/com/shinesolutions/aemorchestrator/service/ResourceReadyCheckerTest.java index bcc2773..1d08d43 100644 --- a/src/test/java/com/shinesolutions/aemorchestrator/service/ResourceReadyCheckerTest.java +++ b/src/test/java/com/shinesolutions/aemorchestrator/service/ResourceReadyCheckerTest.java @@ -17,9 +17,6 @@ import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; -import com.shinesolutions.aemorchestrator.service.AemInstanceHelperService; -import com.shinesolutions.aemorchestrator.service.ResourceReadyChecker; - @RunWith(MockitoJUnitRunner.class) public class ResourceReadyCheckerTest {