Search in sources :

Example 1 with VirtualNetworkLinkInner

use of com.microsoft.azure.management.privatedns.v2018_09_01.implementation.VirtualNetworkLinkInner in project cloudbreak by hortonworks.

the class AzureClient method checkIfNetworkLinksDeployed.

public boolean checkIfNetworkLinksDeployed(String resourceGroupName, String networkId, List<AzurePrivateDnsZoneServiceEnum> services) {
    LOGGER.debug("Checking Network link between network and services {} and network link {}", networkId, services.stream().map(AzurePrivateDnsZoneServiceEnum::getDnsZoneName).collect(Collectors.toList()));
    for (AzurePrivateDnsZoneServiceEnum service : services) {
        String dnsZoneName = service.getDnsZoneName();
        PagedList<VirtualNetworkLinkInner> virtualNetworkLinks = listNetworkLinksByPrivateDnsZoneName(resourceGroupName, dnsZoneName);
        if (virtualNetworkLinks.isEmpty()) {
            LOGGER.info("Network link for network {} not found for DNS zone {}!", networkId, dnsZoneName);
            return false;
        } else if (!isNetworkLinkCreated(networkId, virtualNetworkLinks)) {
            LOGGER.info("Network link for network {} and DNS Zone {} is not provisioned successfully yet!", networkId, dnsZoneName);
            return false;
        }
    }
    return true;
}
Also used : AzurePrivateDnsZoneServiceEnum(com.sequenceiq.cloudbreak.cloud.azure.AzurePrivateDnsZoneServiceEnum) VirtualNetworkLinkInner(com.microsoft.azure.management.privatedns.v2018_09_01.implementation.VirtualNetworkLinkInner)

Example 2 with VirtualNetworkLinkInner

use of com.microsoft.azure.management.privatedns.v2018_09_01.implementation.VirtualNetworkLinkInner in project cloudbreak by hortonworks.

the class AzureClient method listNetworkLinksByPrivateDnsZoneName.

public PagedList<VirtualNetworkLinkInner> listNetworkLinksByPrivateDnsZoneName(String subscriptionId, String resourceGroupName, String dnsZoneName) {
    privatednsManager dnsManager = azureClientCredentials.getPrivateDnsManagerWithAnotherSubscription(subscriptionId);
    PagedList<VirtualNetworkLinkInner> virtualNetworkLinks = dnsManager.virtualNetworkLinks().inner().list(resourceGroupName, dnsZoneName);
    virtualNetworkLinks.loadAll();
    return virtualNetworkLinks;
}
Also used : com.microsoft.azure.management.privatedns.v2018_09_01.implementation.privatednsManager(com.microsoft.azure.management.privatedns.v2018_09_01.implementation.privatednsManager) VirtualNetworkLinkInner(com.microsoft.azure.management.privatedns.v2018_09_01.implementation.VirtualNetworkLinkInner)

Example 3 with VirtualNetworkLinkInner

use of com.microsoft.azure.management.privatedns.v2018_09_01.implementation.VirtualNetworkLinkInner 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!"));
}
Also used : ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult) VirtualNetworkLinkInner(com.microsoft.azure.management.privatedns.v2018_09_01.implementation.VirtualNetworkLinkInner) PrivateZone(com.microsoft.azure.management.privatedns.v2018_09_01.PrivateZone) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with VirtualNetworkLinkInner

use of com.microsoft.azure.management.privatedns.v2018_09_01.implementation.VirtualNetworkLinkInner in project cloudbreak by hortonworks.

the class AzurePrivateDnsZoneValidatorServiceTest method getNetworkLinks.

private PagedList<VirtualNetworkLinkInner> getNetworkLinks(List<String> foundNetworkIds) {
    PagedList<VirtualNetworkLinkInner> virtualNetworkLinks = new TestPagedList<>();
    foundNetworkIds.stream().map(id -> new VirtualNetworkLinkInner().withVirtualNetwork(new SubResource().withId(id))).forEach(virtualNetworkLinks::add);
    return virtualNetworkLinks;
}
Also used : SubResource(com.microsoft.azure.SubResource) AzureClient(com.sequenceiq.cloudbreak.cloud.azure.client.AzureClient) Mock(org.mockito.Mock) StringUtils(org.apache.commons.lang3.StringUtils) PrivateZone(com.microsoft.azure.management.privatedns.v2018_09_01.PrivateZone) SUBSCRIPTION_ID(com.sequenceiq.cloudbreak.cloud.model.filesystem.CloudAdlsView.SUBSCRIPTION_ID) Network(com.microsoft.azure.management.network.Network) VirtualNetworkLinkInner(com.microsoft.azure.management.privatedns.v2018_09_01.implementation.VirtualNetworkLinkInner) TestPagedList(com.sequenceiq.cloudbreak.cloud.azure.validator.privatedns.PrivateDnsZoneValidationTestConstants.TestPagedList) ZONE_NAME_POSTGRES(com.sequenceiq.cloudbreak.cloud.azure.validator.privatedns.PrivateDnsZoneValidationTestConstants.ZONE_NAME_POSTGRES) PrivateDnsZoneValidationTestConstants.getPrivateDnsZoneResourceId(com.sequenceiq.cloudbreak.cloud.azure.validator.privatedns.PrivateDnsZoneValidationTestConstants.getPrivateDnsZoneResourceId) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) PagedList(com.microsoft.azure.PagedList) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult) A_RESOURCE_GROUP_NAME(com.sequenceiq.cloudbreak.cloud.azure.validator.privatedns.PrivateDnsZoneValidationTestConstants.A_RESOURCE_GROUP_NAME) SINGLE_RESOURCE_GROUP_NAME(com.sequenceiq.cloudbreak.cloud.azure.validator.privatedns.PrivateDnsZoneValidationTestConstants.SINGLE_RESOURCE_GROUP_NAME) MethodSource(org.junit.jupiter.params.provider.MethodSource) ProvisioningState(com.microsoft.azure.management.privatedns.v2018_09_01.ProvisioningState) InjectMocks(org.mockito.InjectMocks) NETWORK_RESOURCE_ID(com.sequenceiq.cloudbreak.cloud.azure.validator.privatedns.PrivateDnsZoneValidationTestConstants.NETWORK_RESOURCE_ID) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) Mockito.when(org.mockito.Mockito.when) Collectors(java.util.stream.Collectors) NETWORK_NAME(com.sequenceiq.cloudbreak.cloud.azure.validator.privatedns.PrivateDnsZoneValidationTestConstants.NETWORK_NAME) Mockito.verify(org.mockito.Mockito.verify) NETWORK_RESOURCE_GROUP_NAME(com.sequenceiq.cloudbreak.cloud.azure.validator.privatedns.PrivateDnsZoneValidationTestConstants.NETWORK_RESOURCE_GROUP_NAME) Test(org.junit.jupiter.api.Test) Mockito.never(org.mockito.Mockito.never) List(java.util.List) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) ValidationTestUtil(com.sequenceiq.cloudbreak.cloud.azure.validator.ValidationTestUtil) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Mockito.mock(org.mockito.Mockito.mock) AzurePrivateDnsZoneServiceEnum(com.sequenceiq.cloudbreak.cloud.azure.AzurePrivateDnsZoneServiceEnum) SubResource(com.microsoft.azure.SubResource) TestPagedList(com.sequenceiq.cloudbreak.cloud.azure.validator.privatedns.PrivateDnsZoneValidationTestConstants.TestPagedList) VirtualNetworkLinkInner(com.microsoft.azure.management.privatedns.v2018_09_01.implementation.VirtualNetworkLinkInner)

Example 5 with VirtualNetworkLinkInner

use of com.microsoft.azure.management.privatedns.v2018_09_01.implementation.VirtualNetworkLinkInner in project cloudbreak by hortonworks.

the class AzurePrivateDnsZoneValidatorServiceTest method testPrivateDnsZoneConnectedToNetworkWhenConnectedToEnvironmentNetwork.

@Test
void testPrivateDnsZoneConnectedToNetworkWhenConnectedToEnvironmentNetwork() {
    ValidationResult.ValidationResultBuilder resultBuilder = ValidationResult.builder();
    Network network = getNetwork();
    when(azureClient.getNetworkByResourceGroup(NETWORK_RESOURCE_GROUP_NAME, NETWORK_NAME)).thenReturn(network);
    PagedList<VirtualNetworkLinkInner> virtualNetworkLinks = getNetworkLinks(List.of(NETWORK_RESOURCE_ID));
    when(azureClient.listNetworkLinksByPrivateDnsZoneName(SUBSCRIPTION_ID, A_RESOURCE_GROUP_NAME, ZONE_NAME_POSTGRES)).thenReturn(virtualNetworkLinks);
    resultBuilder = underTest.privateDnsZoneConnectedToNetwork(azureClient, NETWORK_RESOURCE_GROUP_NAME, NETWORK_NAME, getPrivateDnsZoneResourceId(A_RESOURCE_GROUP_NAME), resultBuilder);
    assertFalse(resultBuilder.build().hasError());
}
Also used : Network(com.microsoft.azure.management.network.Network) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult) VirtualNetworkLinkInner(com.microsoft.azure.management.privatedns.v2018_09_01.implementation.VirtualNetworkLinkInner) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

VirtualNetworkLinkInner (com.microsoft.azure.management.privatedns.v2018_09_01.implementation.VirtualNetworkLinkInner)7 ValidationResult (com.sequenceiq.cloudbreak.validation.ValidationResult)4 Test (org.junit.jupiter.api.Test)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 Network (com.microsoft.azure.management.network.Network)3 PrivateZone (com.microsoft.azure.management.privatedns.v2018_09_01.PrivateZone)2 AzurePrivateDnsZoneServiceEnum (com.sequenceiq.cloudbreak.cloud.azure.AzurePrivateDnsZoneServiceEnum)2 PagedList (com.microsoft.azure.PagedList)1 SubResource (com.microsoft.azure.SubResource)1 ProvisioningState (com.microsoft.azure.management.privatedns.v2018_09_01.ProvisioningState)1 com.microsoft.azure.management.privatedns.v2018_09_01.implementation.privatednsManager (com.microsoft.azure.management.privatedns.v2018_09_01.implementation.privatednsManager)1 AzureClient (com.sequenceiq.cloudbreak.cloud.azure.client.AzureClient)1 AzureDnsZoneDeploymentParameters (com.sequenceiq.cloudbreak.cloud.azure.connector.resource.AzureDnsZoneDeploymentParameters)1 ValidationTestUtil (com.sequenceiq.cloudbreak.cloud.azure.validator.ValidationTestUtil)1 A_RESOURCE_GROUP_NAME (com.sequenceiq.cloudbreak.cloud.azure.validator.privatedns.PrivateDnsZoneValidationTestConstants.A_RESOURCE_GROUP_NAME)1 NETWORK_NAME (com.sequenceiq.cloudbreak.cloud.azure.validator.privatedns.PrivateDnsZoneValidationTestConstants.NETWORK_NAME)1 NETWORK_RESOURCE_GROUP_NAME (com.sequenceiq.cloudbreak.cloud.azure.validator.privatedns.PrivateDnsZoneValidationTestConstants.NETWORK_RESOURCE_GROUP_NAME)1 NETWORK_RESOURCE_ID (com.sequenceiq.cloudbreak.cloud.azure.validator.privatedns.PrivateDnsZoneValidationTestConstants.NETWORK_RESOURCE_ID)1 SINGLE_RESOURCE_GROUP_NAME (com.sequenceiq.cloudbreak.cloud.azure.validator.privatedns.PrivateDnsZoneValidationTestConstants.SINGLE_RESOURCE_GROUP_NAME)1 TestPagedList (com.sequenceiq.cloudbreak.cloud.azure.validator.privatedns.PrivateDnsZoneValidationTestConstants.TestPagedList)1