@Test public void testGetNetworkCidrWithoutResult() { String networkId = "vnet-1"; String resourceGroupName = "resourceGroupName"; Network network = new Network(null, Map.of(AzureUtils.NETWORK_ID, networkId)); CloudCredential credential = new CloudCredential(); com.microsoft.azure.management.network.Network azureNetwork = mock(com.microsoft.azure.management.network.Network.class); when(azureClientService.getClient(credential)).thenReturn(azureClient); when(azureUtils.getCustomResourceGroupName(network)).thenReturn(resourceGroupName); when(azureUtils.getCustomNetworkId(network)).thenReturn(networkId); when(azureClient.getNetworkByResourceGroup(resourceGroupName, networkId)).thenReturn(azureNetwork); when(azureNetwork.addressSpaces()).thenReturn(List.of()); thrown.expect(BadRequestException.class); thrown.expectMessage(String.format("Network could not be fetch from Azure with resource group name: %s and network id: %s", resourceGroupName, networkId)); underTest.getNetworkCidr(network, credential); }
@Override public NetworkCidr getNetworkCidr(Network network, CloudCredential credential) { AzureClient azureClient = azureClientService.getClient(credential); String resourceGroupName = azureUtils.getCustomResourceGroupName(network); String networkId = azureUtils.getCustomNetworkId(network); com.microsoft.azure.management.network.Network networkByResourceGroup = azureClient.getNetworkByResourceGroup(resourceGroupName, networkId); if (networkByResourceGroup == null || networkByResourceGroup.addressSpaces().isEmpty()) { throw new BadRequestException(String.format("Network could not be fetch from Azure with resource group name: %s and network id: %s", resourceGroupName, networkId)); } List<String> networkCidrs = networkByResourceGroup.addressSpaces(); if (networkCidrs.size() > 1) { LOGGER.info("More than one network cidrs for resource group name: {} and network id: {}. We will use the first one: {}", resourceGroupName, networkId, networkCidrs.get(0)); } return new NetworkCidr(networkCidrs.get(0), networkCidrs); }
AzureNetworkConnector implements NetworkConnector { @Override public NetworkCidr getNetworkCidr(Network network, CloudCredential credential) { AzureClient azureClient = azureClientService.getClient(credential); String resourceGroupName = azureUtils.getCustomResourceGroupName(network); String networkId = azureUtils.getCustomNetworkId(network); com.microsoft.azure.management.network.Network networkByResourceGroup = azureClient.getNetworkByResourceGroup(resourceGroupName, networkId); if (networkByResourceGroup == null || networkByResourceGroup.addressSpaces().isEmpty()) { throw new BadRequestException(String.format("Network could not be fetch from Azure with resource group name: %s and network id: %s", resourceGroupName, networkId)); } List<String> networkCidrs = networkByResourceGroup.addressSpaces(); if (networkCidrs.size() > 1) { LOGGER.info("More than one network cidrs for resource group name: {} and network id: {}. We will use the first one: {}", resourceGroupName, networkId, networkCidrs.get(0)); } return new NetworkCidr(networkCidrs.get(0), networkCidrs); } }
AzureNetworkConnector implements NetworkConnector { @Override public NetworkCidr getNetworkCidr(Network network, CloudCredential credential) { AzureClient azureClient = azureClientService.getClient(credential); String resourceGroupName = azureUtils.getCustomResourceGroupName(network); String networkId = azureUtils.getCustomNetworkId(network); com.microsoft.azure.management.network.Network networkByResourceGroup = azureClient.getNetworkByResourceGroup(resourceGroupName, networkId); if (networkByResourceGroup == null || networkByResourceGroup.addressSpaces().isEmpty()) { throw new BadRequestException(String.format("Network could not be fetch from Azure with resource group name: %s and network id: %s", resourceGroupName, networkId)); } List<String> networkCidrs = networkByResourceGroup.addressSpaces(); if (networkCidrs.size() > 1) { LOGGER.info("More than one network cidrs for resource group name: {} and network id: {}. We will use the first one: {}", resourceGroupName, networkId, networkCidrs.get(0)); } return new NetworkCidr(networkCidrs.get(0), networkCidrs); }  }
AzureNetworkConnector implements NetworkConnector { @Override public NetworkCidr getNetworkCidr(Network network, CloudCredential credential) { AzureClient azureClient = azureClientService.getClient(credential); String resourceGroupName = azureUtils.getCustomResourceGroupName(network); String networkId = azureUtils.getCustomNetworkId(network); com.microsoft.azure.management.network.Network networkByResourceGroup = azureClient.getNetworkByResourceGroup(resourceGroupName, networkId); if (networkByResourceGroup == null || networkByResourceGroup.addressSpaces().isEmpty()) { throw new BadRequestException(String.format("Network could not be fetch from Azure with resource group name: %s and network id: %s", resourceGroupName, networkId)); } List<String> networkCidrs = networkByResourceGroup.addressSpaces(); if (networkCidrs.size() > 1) { LOGGER.info("More than one network cidrs for resource group name: {} and network id: {}. We will use the first one: {}", resourceGroupName, networkId, networkCidrs.get(0)); } return new NetworkCidr(networkCidrs.get(0), networkCidrs); }  @Override CreatedCloudNetwork createNetworkWithSubnets(NetworkCreationRequest networkRequest); @Override void deleteNetworkWithSubnets(NetworkDeletionRequest networkDeletionRequest); @Override NetworkCidr getNetworkCidr(Network network, CloudCredential credential); @Override SubnetSelectionResult chooseSubnets(Collection<CloudSubnet> subnetMetas, SubnetSelectionParameters subnetSelectionParameters); @Override Platform platform(); @Override Variant variant(); }
AzureNetworkConnector implements NetworkConnector { @Override public NetworkCidr getNetworkCidr(Network network, CloudCredential credential) { AzureClient azureClient = azureClientService.getClient(credential); String resourceGroupName = azureUtils.getCustomResourceGroupName(network); String networkId = azureUtils.getCustomNetworkId(network); com.microsoft.azure.management.network.Network networkByResourceGroup = azureClient.getNetworkByResourceGroup(resourceGroupName, networkId); if (networkByResourceGroup == null || networkByResourceGroup.addressSpaces().isEmpty()) { throw new BadRequestException(String.format("Network could not be fetch from Azure with resource group name: %s and network id: %s", resourceGroupName, networkId)); } List<String> networkCidrs = networkByResourceGroup.addressSpaces(); if (networkCidrs.size() > 1) { LOGGER.info("More than one network cidrs for resource group name: {} and network id: {}. We will use the first one: {}", resourceGroupName, networkId, networkCidrs.get(0)); } return new NetworkCidr(networkCidrs.get(0), networkCidrs); }  @Override CreatedCloudNetwork createNetworkWithSubnets(NetworkCreationRequest networkRequest); @Override void deleteNetworkWithSubnets(NetworkDeletionRequest networkDeletionRequest); @Override NetworkCidr getNetworkCidr(Network network, CloudCredential credential); @Override SubnetSelectionResult chooseSubnets(Collection<CloudSubnet> subnetMetas, SubnetSelectionParameters subnetSelectionParameters); @Override Platform platform(); @Override Variant variant();  }