@Test void testUpdateDnsEntryShouldReturnWithFqdnInCaseOfSuccessAndSetEntryToGatewayIpWhenGatewayIpIsSpecified() { String gatewayIp = "10.191.192.193"; Cluster cluster = TestUtil.cluster(); Stack stack = cluster.getStack(); stack.setCluster(cluster); InstanceMetaData primaryGatewayInstance = stack.getPrimaryGatewayInstance(); String endpointName = primaryGatewayInstance.getShortHostname(); String envName = "anEnvName"; DetailedEnvironmentResponse environment = DetailedEnvironmentResponse.Builder .builder() .withName(envName) .build(); when(environmentClientService.getByCrn(Mockito.anyString())).thenReturn(environment); when(dnsManagementService.createOrUpdateDnsEntryWithIp(eq(USER_CRN), eq("123"), eq(endpointName), eq(envName), eq(Boolean.FALSE), eq(List.of(gatewayIp)))).thenReturn(Boolean.TRUE); String accountWorkloadSubdomain = "aWorkloadSubdomain"; UserManagementProto.Account umsAccount = UserManagementProto.Account.newBuilder() .setWorkloadSubdomain(accountWorkloadSubdomain) .build(); when(grpcUmsClient.getAccountDetails(USER_CRN, "123", Optional.empty())).thenReturn(umsAccount); String fqdn = endpointName + ".anenvname.xcu2-8y8x.dev.cldr.work"; when(domainNameProvider.getFullyQualifiedEndpointName(endpointName, envName, accountWorkloadSubdomain)).thenReturn(fqdn); String result = ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.updateDnsEntry(stack, gatewayIp)); Assertions.assertNotNull(result); Assertions.assertEquals(fqdn, result); verify(dnsManagementService, times(1)) .createOrUpdateDnsEntryWithIp(eq(USER_CRN), eq("123"), eq(endpointName), eq(envName), eq(Boolean.FALSE), eq(List.of(gatewayIp))); }
public String updateDnsEntry(Stack stack, String gatewayIp) { LOGGER.info("Update dns entry"); String userCrn = ThreadBasedUserCrnProvider.getUserCrn(); String accountId = ThreadBasedUserCrnProvider.getAccountId(); DetailedEnvironmentResponse environment = environmentClientService.getByCrn(stack.getEnvironmentCrn()); if (StringUtils.isEmpty(gatewayIp)) { Optional<InstanceMetaData> gateway = Optional.ofNullable(stack.getPrimaryGatewayInstance()); if (gateway.isEmpty()) { LOGGER.info("No running gateway or all node is terminated, we skip the dns entry deletion."); return null; } else { gatewayIp = gateway.get().getPublicIpWrapper(); } } String endpointName = getEndpointNameForStack(stack); LOGGER.info("Creating DNS entry with endpoint name: '{}', environment name: '{}' and gateway IP: '{}'", endpointName, environment.getName(), gatewayIp); List<String> ips = List.of(gatewayIp); boolean success = getDnsManagementService().createOrUpdateDnsEntryWithIp(userCrn, accountId, endpointName, environment.getName(), false, ips); if (success) { try { String fullQualifiedDomainName = getDomainNameProvider() .getFullyQualifiedEndpointName(endpointName, environment.getName(), getWorkloadSubdomain(userCrn)); if (fullQualifiedDomainName != null) { LOGGER.info("Dns entry updated: ip: {}, FQDN: {}", gatewayIp, fullQualifiedDomainName); return fullQualifiedDomainName; } } catch (Exception e) { LOGGER.info("Cannot generate fqdn: {}", e.getMessage(), e); } } return null; }
GatewayPublicEndpointManagementService extends BasePublicEndpointManagementService { public String updateDnsEntry(Stack stack, String gatewayIp) { LOGGER.info("Update dns entry"); String userCrn = ThreadBasedUserCrnProvider.getUserCrn(); String accountId = ThreadBasedUserCrnProvider.getAccountId(); DetailedEnvironmentResponse environment = environmentClientService.getByCrn(stack.getEnvironmentCrn()); if (StringUtils.isEmpty(gatewayIp)) { Optional<InstanceMetaData> gateway = Optional.ofNullable(stack.getPrimaryGatewayInstance()); if (gateway.isEmpty()) { LOGGER.info("No running gateway or all node is terminated, we skip the dns entry deletion."); return null; } else { gatewayIp = gateway.get().getPublicIpWrapper(); } } String endpointName = getEndpointNameForStack(stack); LOGGER.info("Creating DNS entry with endpoint name: '{}', environment name: '{}' and gateway IP: '{}'", endpointName, environment.getName(), gatewayIp); List<String> ips = List.of(gatewayIp); boolean success = getDnsManagementService().createOrUpdateDnsEntryWithIp(userCrn, accountId, endpointName, environment.getName(), false, ips); if (success) { try { String fullQualifiedDomainName = getDomainNameProvider() .getFullyQualifiedEndpointName(endpointName, environment.getName(), getWorkloadSubdomain(userCrn)); if (fullQualifiedDomainName != null) { LOGGER.info("Dns entry updated: ip: {}, FQDN: {}", gatewayIp, fullQualifiedDomainName); return fullQualifiedDomainName; } } catch (Exception e) { LOGGER.info("Cannot generate fqdn: {}", e.getMessage(), e); } } return null; } }
GatewayPublicEndpointManagementService extends BasePublicEndpointManagementService { public String updateDnsEntry(Stack stack, String gatewayIp) { LOGGER.info("Update dns entry"); String userCrn = ThreadBasedUserCrnProvider.getUserCrn(); String accountId = ThreadBasedUserCrnProvider.getAccountId(); DetailedEnvironmentResponse environment = environmentClientService.getByCrn(stack.getEnvironmentCrn()); if (StringUtils.isEmpty(gatewayIp)) { Optional<InstanceMetaData> gateway = Optional.ofNullable(stack.getPrimaryGatewayInstance()); if (gateway.isEmpty()) { LOGGER.info("No running gateway or all node is terminated, we skip the dns entry deletion."); return null; } else { gatewayIp = gateway.get().getPublicIpWrapper(); } } String endpointName = getEndpointNameForStack(stack); LOGGER.info("Creating DNS entry with endpoint name: '{}', environment name: '{}' and gateway IP: '{}'", endpointName, environment.getName(), gatewayIp); List<String> ips = List.of(gatewayIp); boolean success = getDnsManagementService().createOrUpdateDnsEntryWithIp(userCrn, accountId, endpointName, environment.getName(), false, ips); if (success) { try { String fullQualifiedDomainName = getDomainNameProvider() .getFullyQualifiedEndpointName(endpointName, environment.getName(), getWorkloadSubdomain(userCrn)); if (fullQualifiedDomainName != null) { LOGGER.info("Dns entry updated: ip: {}, FQDN: {}", gatewayIp, fullQualifiedDomainName); return fullQualifiedDomainName; } } catch (Exception e) { LOGGER.info("Cannot generate fqdn: {}", e.getMessage(), e); } } return null; }  }
GatewayPublicEndpointManagementService extends BasePublicEndpointManagementService { public String updateDnsEntry(Stack stack, String gatewayIp) { LOGGER.info("Update dns entry"); String userCrn = ThreadBasedUserCrnProvider.getUserCrn(); String accountId = ThreadBasedUserCrnProvider.getAccountId(); DetailedEnvironmentResponse environment = environmentClientService.getByCrn(stack.getEnvironmentCrn()); if (StringUtils.isEmpty(gatewayIp)) { Optional<InstanceMetaData> gateway = Optional.ofNullable(stack.getPrimaryGatewayInstance()); if (gateway.isEmpty()) { LOGGER.info("No running gateway or all node is terminated, we skip the dns entry deletion."); return null; } else { gatewayIp = gateway.get().getPublicIpWrapper(); } } String endpointName = getEndpointNameForStack(stack); LOGGER.info("Creating DNS entry with endpoint name: '{}', environment name: '{}' and gateway IP: '{}'", endpointName, environment.getName(), gatewayIp); List<String> ips = List.of(gatewayIp); boolean success = getDnsManagementService().createOrUpdateDnsEntryWithIp(userCrn, accountId, endpointName, environment.getName(), false, ips); if (success) { try { String fullQualifiedDomainName = getDomainNameProvider() .getFullyQualifiedEndpointName(endpointName, environment.getName(), getWorkloadSubdomain(userCrn)); if (fullQualifiedDomainName != null) { LOGGER.info("Dns entry updated: ip: {}, FQDN: {}", gatewayIp, fullQualifiedDomainName); return fullQualifiedDomainName; } } catch (Exception e) { LOGGER.info("Cannot generate fqdn: {}", e.getMessage(), e); } } return null; }  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 updateDnsEntry(Stack stack, String gatewayIp) { LOGGER.info("Update dns entry"); String userCrn = ThreadBasedUserCrnProvider.getUserCrn(); String accountId = ThreadBasedUserCrnProvider.getAccountId(); DetailedEnvironmentResponse environment = environmentClientService.getByCrn(stack.getEnvironmentCrn()); if (StringUtils.isEmpty(gatewayIp)) { Optional<InstanceMetaData> gateway = Optional.ofNullable(stack.getPrimaryGatewayInstance()); if (gateway.isEmpty()) { LOGGER.info("No running gateway or all node is terminated, we skip the dns entry deletion."); return null; } else { gatewayIp = gateway.get().getPublicIpWrapper(); } } String endpointName = getEndpointNameForStack(stack); LOGGER.info("Creating DNS entry with endpoint name: '{}', environment name: '{}' and gateway IP: '{}'", endpointName, environment.getName(), gatewayIp); List<String> ips = List.of(gatewayIp); boolean success = getDnsManagementService().createOrUpdateDnsEntryWithIp(userCrn, accountId, endpointName, environment.getName(), false, ips); if (success) { try { String fullQualifiedDomainName = getDomainNameProvider() .getFullyQualifiedEndpointName(endpointName, environment.getName(), getWorkloadSubdomain(userCrn)); if (fullQualifiedDomainName != null) { LOGGER.info("Dns entry updated: ip: {}, FQDN: {}", gatewayIp, fullQualifiedDomainName); return fullQualifiedDomainName; } } catch (Exception e) { LOGGER.info("Cannot generate fqdn: {}", e.getMessage(), e); } } return null; }  boolean isCertRenewalTriggerable(Stack stack); boolean generateCertAndSaveForStackAndUpdateDnsEntry(Stack stack); String updateDnsEntry(Stack stack, String gatewayIp); String deleteDnsEntry(Stack stack, String environmentName); boolean renewCertificate(Stack stack);  }