@Test void testDeleteDnsEntryShouldCallDnsManagementServiceWithGatewayInstanceShortHostnameAsEndpointNameWhenEnvNameIsNotSpecified() { Cluster cluster = TestUtil.cluster(); Stack stack = cluster.getStack(); stack.setCluster(cluster); InstanceMetaData primaryGatewayInstance = stack.getPrimaryGatewayInstance(); String endpointName = primaryGatewayInstance.getShortHostname(); String gatewayIp = primaryGatewayInstance.getPublicIpWrapper(); String envName = "anEnvName"; DetailedEnvironmentResponse environment = DetailedEnvironmentResponse.Builder .builder() .withName(envName) .build(); when(environmentClientService.getByCrn(Mockito.anyString())).thenReturn(environment); when(dnsManagementService.deleteDnsEntryWithIp(eq(USER_CRN), eq("123"), eq(endpointName), eq(envName), eq(Boolean.FALSE), eq(List.of(gatewayIp)))).thenReturn(Boolean.TRUE); String result = ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.deleteDnsEntry(stack, null)); Assertions.assertNotNull(result); Assertions.assertEquals(gatewayIp, result); verify(dnsManagementService, times(1)) .deleteDnsEntryWithIp(eq(USER_CRN), eq("123"), eq(endpointName), eq(envName), eq(Boolean.FALSE), eq(List.of(gatewayIp))); }
public String deleteDnsEntry(Stack stack, String environmentName) { String actorCrn = ThreadBasedUserCrnProvider.getUserCrn(); String accountId = ThreadBasedUserCrnProvider.getAccountId(); if (StringUtils.isEmpty(environmentName)) { DetailedEnvironmentResponse environment = environmentClientService.getByCrn(stack.getEnvironmentCrn()); environmentName = environment.getName(); } Optional<InstanceMetaData> gateway = Optional.ofNullable(stack.getPrimaryGatewayInstance()); if (!gateway.isPresent()) { LOGGER.info("No running gateway or all node is terminated, we skip the dns entry deletion."); return null; } String ip = gateway.get().getPublicIpWrapper(); if (ip == null) { return null; } String endpointName = getEndpointNameForStack(stack); LOGGER.info("Deleting DNS entry with endpoint name: '{}', environment name: '{}' and gateway IP: '{}'", endpointName, environmentName, ip); getDnsManagementService().deleteDnsEntryWithIp(actorCrn, accountId, endpointName, environmentName, false, List.of(ip)); return ip; }
GatewayPublicEndpointManagementService extends BasePublicEndpointManagementService { public String deleteDnsEntry(Stack stack, String environmentName) { String actorCrn = ThreadBasedUserCrnProvider.getUserCrn(); String accountId = ThreadBasedUserCrnProvider.getAccountId(); if (StringUtils.isEmpty(environmentName)) { DetailedEnvironmentResponse environment = environmentClientService.getByCrn(stack.getEnvironmentCrn()); environmentName = environment.getName(); } Optional<InstanceMetaData> gateway = Optional.ofNullable(stack.getPrimaryGatewayInstance()); if (!gateway.isPresent()) { LOGGER.info("No running gateway or all node is terminated, we skip the dns entry deletion."); return null; } String ip = gateway.get().getPublicIpWrapper(); if (ip == null) { return null; } String endpointName = getEndpointNameForStack(stack); LOGGER.info("Deleting DNS entry with endpoint name: '{}', environment name: '{}' and gateway IP: '{}'", endpointName, environmentName, ip); getDnsManagementService().deleteDnsEntryWithIp(actorCrn, accountId, endpointName, environmentName, false, List.of(ip)); return ip; } }
GatewayPublicEndpointManagementService extends BasePublicEndpointManagementService { public String deleteDnsEntry(Stack stack, String environmentName) { String actorCrn = ThreadBasedUserCrnProvider.getUserCrn(); String accountId = ThreadBasedUserCrnProvider.getAccountId(); if (StringUtils.isEmpty(environmentName)) { DetailedEnvironmentResponse environment = environmentClientService.getByCrn(stack.getEnvironmentCrn()); environmentName = environment.getName(); } Optional<InstanceMetaData> gateway = Optional.ofNullable(stack.getPrimaryGatewayInstance()); if (!gateway.isPresent()) { LOGGER.info("No running gateway or all node is terminated, we skip the dns entry deletion."); return null; } String ip = gateway.get().getPublicIpWrapper(); if (ip == null) { return null; } String endpointName = getEndpointNameForStack(stack); LOGGER.info("Deleting DNS entry with endpoint name: '{}', environment name: '{}' and gateway IP: '{}'", endpointName, environmentName, ip); getDnsManagementService().deleteDnsEntryWithIp(actorCrn, accountId, endpointName, environmentName, false, List.of(ip)); return ip; }  }
GatewayPublicEndpointManagementService extends BasePublicEndpointManagementService { public String deleteDnsEntry(Stack stack, String environmentName) { String actorCrn = ThreadBasedUserCrnProvider.getUserCrn(); String accountId = ThreadBasedUserCrnProvider.getAccountId(); if (StringUtils.isEmpty(environmentName)) { DetailedEnvironmentResponse environment = environmentClientService.getByCrn(stack.getEnvironmentCrn()); environmentName = environment.getName(); } Optional<InstanceMetaData> gateway = Optional.ofNullable(stack.getPrimaryGatewayInstance()); if (!gateway.isPresent()) { LOGGER.info("No running gateway or all node is terminated, we skip the dns entry deletion."); return null; } String ip = gateway.get().getPublicIpWrapper(); if (ip == null) { return null; } String endpointName = getEndpointNameForStack(stack); LOGGER.info("Deleting DNS entry with endpoint name: '{}', environment name: '{}' and gateway IP: '{}'", endpointName, environmentName, ip); getDnsManagementService().deleteDnsEntryWithIp(actorCrn, accountId, endpointName, environmentName, false, List.of(ip)); return ip; }  boolean isCertRenewalTriggerable(Stack stack); boolean generateCertAndSaveForStackAndUpdateDnsEntry(Stack stack); String updateDnsEntry(Stack stack, String gatewayIp); String deleteDnsEntry(Stack stack, String environmentName); boolean renewCertificate(Stack stack); }
GatewayPublicEndpointManagementService extends BasePublicEndpointManagementService { public String deleteDnsEntry(Stack stack, String environmentName) { String actorCrn = ThreadBasedUserCrnProvider.getUserCrn(); String accountId = ThreadBasedUserCrnProvider.getAccountId(); if (StringUtils.isEmpty(environmentName)) { DetailedEnvironmentResponse environment = environmentClientService.getByCrn(stack.getEnvironmentCrn()); environmentName = environment.getName(); } Optional<InstanceMetaData> gateway = Optional.ofNullable(stack.getPrimaryGatewayInstance()); if (!gateway.isPresent()) { LOGGER.info("No running gateway or all node is terminated, we skip the dns entry deletion."); return null; } String ip = gateway.get().getPublicIpWrapper(); if (ip == null) { return null; } String endpointName = getEndpointNameForStack(stack); LOGGER.info("Deleting DNS entry with endpoint name: '{}', environment name: '{}' and gateway IP: '{}'", endpointName, environmentName, ip); getDnsManagementService().deleteDnsEntryWithIp(actorCrn, accountId, endpointName, environmentName, false, List.of(ip)); return ip; }  boolean isCertRenewalTriggerable(Stack stack); boolean generateCertAndSaveForStackAndUpdateDnsEntry(Stack stack); String updateDnsEntry(Stack stack, String gatewayIp); String deleteDnsEntry(Stack stack, String environmentName); boolean renewCertificate(Stack stack);  }