@Test public void getAttachedOsDiskResourcesFound() { CloudResource vm1 = createCloudResource(INSTANCE_1, ResourceType.AZURE_INSTANCE); CloudResource vm2 = createCloudResource(INSTANCE_2, ResourceType.AZURE_INSTANCE); CloudResource vm3 = createCloudResource(INSTANCE_3, ResourceType.AZURE_INSTANCE); PagedList<VirtualMachine> virtualMachines = Mockito.spy(PagedList.class); VirtualMachine vm = Mockito.mock(VirtualMachine.class); StorageProfile storageProfile = Mockito.mock(StorageProfile.class); OSDisk osDisk = Mockito.mock(OSDisk.class); ManagedDiskParameters managedDiskParameters = Mockito.mock(ManagedDiskParameters.class); virtualMachines.add(vm); when(vm.name()).thenReturn(INSTANCE_1); when(vm.storageProfile()).thenReturn(storageProfile); when(vm.storageProfile().osDisk()).thenReturn(osDisk); when(osDisk.managedDisk()).thenReturn(managedDiskParameters); when(managedDiskParameters.id()).thenReturn("diskId1"); when(osDisk.name()).thenReturn("diskName1"); when(ac.getParameter(AzureClient.class)).thenReturn(azureClient); when(azureClient.getVirtualMachines("resourceGroupName")).thenReturn(virtualMachines); List<CloudResource> osDiskResources = underTest.getAttachedOsDiskResources(ac, List.of(vm1, vm2, vm3), "resourceGroupName"); assertEquals(1, osDiskResources.size()); CloudResource diskResource = osDiskResources.get(0); assertEquals("diskName1", diskResource.getName()); assertEquals("diskId1", diskResource.getReference()); }
public List<CloudResource> getAttachedOsDiskResources(AuthenticatedContext authenticatedContext, List<CloudResource> instanceList, String resourceGroupName) { List<CloudResource> osDiskList = new ArrayList<>(); AzureClient client = authenticatedContext.getParameter(AzureClient.class); PagedList<VirtualMachine> virtualMachines = client.getVirtualMachines(resourceGroupName); virtualMachines.loadAll(); instanceList.forEach(vm -> { Optional<VirtualMachine> matchingAzureVmOptional = virtualMachines .stream() .filter(azureVirtualMachine -> vm.getName().equals(azureVirtualMachine.name())) .findFirst(); matchingAzureVmOptional.ifPresentOrElse( matchingAzureVm -> osDiskList.add(collectOsDisk(vm.getInstanceId(), matchingAzureVm)), () -> LOGGER.warn("No Azure VM metadata found for the VM: " + vm.getInstanceId())); } ); return osDiskList; }
AzureCloudResourceService { public List<CloudResource> getAttachedOsDiskResources(AuthenticatedContext authenticatedContext, List<CloudResource> instanceList, String resourceGroupName) { List<CloudResource> osDiskList = new ArrayList<>(); AzureClient client = authenticatedContext.getParameter(AzureClient.class); PagedList<VirtualMachine> virtualMachines = client.getVirtualMachines(resourceGroupName); virtualMachines.loadAll(); instanceList.forEach(vm -> { Optional<VirtualMachine> matchingAzureVmOptional = virtualMachines .stream() .filter(azureVirtualMachine -> vm.getName().equals(azureVirtualMachine.name())) .findFirst(); matchingAzureVmOptional.ifPresentOrElse( matchingAzureVm -> osDiskList.add(collectOsDisk(vm.getInstanceId(), matchingAzureVm)), () -> LOGGER.warn("No Azure VM metadata found for the VM: " + vm.getInstanceId())); } ); return osDiskList; } }
AzureCloudResourceService { public List<CloudResource> getAttachedOsDiskResources(AuthenticatedContext authenticatedContext, List<CloudResource> instanceList, String resourceGroupName) { List<CloudResource> osDiskList = new ArrayList<>(); AzureClient client = authenticatedContext.getParameter(AzureClient.class); PagedList<VirtualMachine> virtualMachines = client.getVirtualMachines(resourceGroupName); virtualMachines.loadAll(); instanceList.forEach(vm -> { Optional<VirtualMachine> matchingAzureVmOptional = virtualMachines .stream() .filter(azureVirtualMachine -> vm.getName().equals(azureVirtualMachine.name())) .findFirst(); matchingAzureVmOptional.ifPresentOrElse( matchingAzureVm -> osDiskList.add(collectOsDisk(vm.getInstanceId(), matchingAzureVm)), () -> LOGGER.warn("No Azure VM metadata found for the VM: " + vm.getInstanceId())); } ); return osDiskList; }  }
AzureCloudResourceService { public List<CloudResource> getAttachedOsDiskResources(AuthenticatedContext authenticatedContext, List<CloudResource> instanceList, String resourceGroupName) { List<CloudResource> osDiskList = new ArrayList<>(); AzureClient client = authenticatedContext.getParameter(AzureClient.class); PagedList<VirtualMachine> virtualMachines = client.getVirtualMachines(resourceGroupName); virtualMachines.loadAll(); instanceList.forEach(vm -> { Optional<VirtualMachine> matchingAzureVmOptional = virtualMachines .stream() .filter(azureVirtualMachine -> vm.getName().equals(azureVirtualMachine.name())) .findFirst(); matchingAzureVmOptional.ifPresentOrElse( matchingAzureVm -> osDiskList.add(collectOsDisk(vm.getInstanceId(), matchingAzureVm)), () -> LOGGER.warn("No Azure VM metadata found for the VM: " + vm.getInstanceId())); } ); return osDiskList; }  List<CloudResource> getNetworkResources(List<CloudResource> resources); List<CloudResource> getDeploymentCloudResources(Deployment templateDeployment); List<CloudResource> getInstanceCloudResources(String stackName, List<CloudResource> cloudResourceList, List<Group> groups,
            String resourceGroupName); CloudResource buildCloudResource(String name, String id, ResourceType type); List<CloudResource> getAttachedOsDiskResources(AuthenticatedContext authenticatedContext, List<CloudResource> instanceList,
            String resourceGroupName); void saveCloudResources(PersistenceNotifier notifier, CloudContext cloudContext, List<CloudResource> cloudResources); void deleteCloudResources(PersistenceNotifier notifier, CloudContext cloudContext, List<CloudResource> cloudResources); List<CloudResource> collectAndSaveNetworkAndSubnet(String resourceGroupName, String virtualNetwork, PersistenceNotifier notifier,
            CloudContext cloudContext, List<String> subnetNameList, String networkName, AzureClient client); }
AzureCloudResourceService { public List<CloudResource> getAttachedOsDiskResources(AuthenticatedContext authenticatedContext, List<CloudResource> instanceList, String resourceGroupName) { List<CloudResource> osDiskList = new ArrayList<>(); AzureClient client = authenticatedContext.getParameter(AzureClient.class); PagedList<VirtualMachine> virtualMachines = client.getVirtualMachines(resourceGroupName); virtualMachines.loadAll(); instanceList.forEach(vm -> { Optional<VirtualMachine> matchingAzureVmOptional = virtualMachines .stream() .filter(azureVirtualMachine -> vm.getName().equals(azureVirtualMachine.name())) .findFirst(); matchingAzureVmOptional.ifPresentOrElse( matchingAzureVm -> osDiskList.add(collectOsDisk(vm.getInstanceId(), matchingAzureVm)), () -> LOGGER.warn("No Azure VM metadata found for the VM: " + vm.getInstanceId())); } ); return osDiskList; }  List<CloudResource> getNetworkResources(List<CloudResource> resources); List<CloudResource> getDeploymentCloudResources(Deployment templateDeployment); List<CloudResource> getInstanceCloudResources(String stackName, List<CloudResource> cloudResourceList, List<Group> groups,
            String resourceGroupName); CloudResource buildCloudResource(String name, String id, ResourceType type); List<CloudResource> getAttachedOsDiskResources(AuthenticatedContext authenticatedContext, List<CloudResource> instanceList,
            String resourceGroupName); void saveCloudResources(PersistenceNotifier notifier, CloudContext cloudContext, List<CloudResource> cloudResources); void deleteCloudResources(PersistenceNotifier notifier, CloudContext cloudContext, List<CloudResource> cloudResources); List<CloudResource> collectAndSaveNetworkAndSubnet(String resourceGroupName, String virtualNetwork, PersistenceNotifier notifier,
            CloudContext cloudContext, List<String> subnetNameList, String networkName, AzureClient client);  }