use of com.microsoft.azure.management.privatedns.v2018_09_01.PrivateZone in project cloudbreak by hortonworks.
the class AzureClient method validateNetworkLinkExistenceForDnsZones.
public ValidationResult validateNetworkLinkExistenceForDnsZones(String networkLinkId, List<AzurePrivateDnsZoneServiceEnum> services, String resourceGroupName) {
ValidationResultBuilder resultBuilder = new ValidationResultBuilder();
PagedList<PrivateZone> privateDnsZoneList = getPrivateDnsZoneList();
for (AzurePrivateDnsZoneServiceEnum service : services) {
String dnsZoneName = service.getDnsZoneName();
Optional<PrivateZone> privateZoneWithNetworkLink = privateDnsZoneList.stream().filter(privateZone -> !privateZone.resourceGroupName().equalsIgnoreCase(resourceGroupName)).filter(privateZone -> privateZone.name().equalsIgnoreCase(dnsZoneName)).filter(privateZone -> privateZone.provisioningState().equals(SUCCEEDED)).filter(privateZone -> Objects.nonNull(getNetworkLinkByPrivateDnsZone(privateZone.resourceGroupName(), dnsZoneName, networkLinkId))).findFirst();
if (privateZoneWithNetworkLink.isPresent()) {
PrivateZone privateZone = privateZoneWithNetworkLink.get();
String validationMessage = String.format("Network link for the network %s already exists for Private DNS Zone %s in resource group %s. " + "Please ensure that there is no existing network link and try again!", networkLinkId, dnsZoneName, privateZone.resourceGroupName());
LOGGER.warn(validationMessage);
resultBuilder.error(validationMessage);
}
}
return resultBuilder.build();
}
use of com.microsoft.azure.management.privatedns.v2018_09_01.PrivateZone in project cloudbreak by hortonworks.
the class AzureClient method checkIfDnsZonesDeployed.
public boolean checkIfDnsZonesDeployed(String resourceGroupName, List<AzurePrivateDnsZoneServiceEnum> services) {
LOGGER.debug("Checking DNS Zones for services {}", services.stream().map(AzurePrivateDnsZoneServiceEnum::getDnsZoneName).collect(Collectors.toList()));
PagedList<PrivateZone> dnsZones = listPrivateDnsZonesByResourceGroup(resourceGroupName);
for (AzurePrivateDnsZoneServiceEnum service : services) {
String dnsZoneName = service.getDnsZoneName();
boolean dnsZoneFound = dnsZones.stream().filter(dnsZone -> dnsZone.name().equals(dnsZoneName)).anyMatch(dnsZone -> dnsZone.provisioningState().equals(SUCCEEDED));
if (!dnsZoneFound) {
LOGGER.info("DNS Zone {} is not provisioned successfully yet!", dnsZoneName);
return false;
}
}
return true;
}
use of com.microsoft.azure.management.privatedns.v2018_09_01.PrivateZone in project cloudbreak by hortonworks.
the class AzureClient method getPrivateDnsZonesByResourceGroup.
public PagedList<PrivateZone> getPrivateDnsZonesByResourceGroup(String subscriptionId, String resourceGroupName) {
privatednsManager dnsManager = azureClientCredentials.getPrivateDnsManagerWithAnotherSubscription(subscriptionId);
PagedList<PrivateZone> privateDnsZones = dnsManager.privateZones().listByResourceGroup(resourceGroupName);
privateDnsZones.loadAll();
return privateDnsZones;
}
use of com.microsoft.azure.management.privatedns.v2018_09_01.PrivateZone in project cloudbreak by hortonworks.
the class AzureNewPrivateDnsZoneValidatorService method zonesNotConnectedToNetwork.
public ValidationResult.ValidationResultBuilder zonesNotConnectedToNetwork(AzureClient azureClient, String networkId, String singleResourceGroupName, Set<AzurePrivateDnsZoneServiceEnum> servicesWithExistingDnsZones, ValidationResult.ValidationResultBuilder resultBuilder) {
List<AzurePrivateDnsZoneServiceEnum> cdpManagedPrivateEndpointServices = azurePrivateEndpointServicesProvider.getCdpManagedDnsZones(servicesWithExistingDnsZones);
if (cdpManagedPrivateEndpointServices.isEmpty()) {
LOGGER.debug("There are no private DNS zone services that CDP would manage on its own, skipping checking if DNS zones are already connected " + "to the network");
return resultBuilder;
}
PagedList<PrivateZone> privateDnsZoneList = azureClient.getPrivateDnsZoneList();
for (AzurePrivateDnsZoneServiceEnum service : cdpManagedPrivateEndpointServices) {
LOGGER.debug("Validating network that no private DNS zone with name {} is connected to it.", service.getDnsZoneName());
azurePrivateDnsZoneValidatorService.privateDnsZonesNotConnectedToNetwork(azureClient, networkId, singleResourceGroupName, service.getDnsZoneName(), resultBuilder, privateDnsZoneList);
}
return resultBuilder;
}
use of com.microsoft.azure.management.privatedns.v2018_09_01.PrivateZone in project cloudbreak by hortonworks.
the class AzurePrivateDnsZoneValidatorServiceTest method testPrivateDnsZonesNotConnectedToNetworkWhenZoneConnected.
@Test
void testPrivateDnsZonesNotConnectedToNetworkWhenZoneConnected() {
ValidationResult.ValidationResultBuilder resultBuilder = ValidationResult.builder();
PagedList<PrivateZone> privateDnsZoneList = getPrivateDnsZones(A_RESOURCE_GROUP_NAME, List.of(ZONE_NAME_POSTGRES), ProvisioningState.SUCCEEDED);
when(azureClient.getNetworkLinkByPrivateDnsZone(A_RESOURCE_GROUP_NAME, ZONE_NAME_POSTGRES, NETWORK_NAME)).thenReturn(new VirtualNetworkLinkInner());
ValidationResult result = underTest.privateDnsZonesNotConnectedToNetwork(azureClient, NETWORK_NAME, SINGLE_RESOURCE_GROUP_NAME, ZONE_NAME_POSTGRES, resultBuilder, privateDnsZoneList);
assertTrue(result.hasError());
ValidationTestUtil.checkErrorsPresent(resultBuilder, List.of("Network link for the network networkName already exists for Private DNS Zone " + "privatelink.postgres.database.azure.com in resource group a-resource-group-name. Please ensure that there is no existing network link and " + "try again!"));
}
Aggregations