@Test public void getInstanceCloudResourcesInstancesFound() { List<Group> groupList = new ArrayList<>(); Group group = Mockito.mock(Group.class); CloudInstance instance = Mockito.mock(CloudInstance.class); InstanceTemplate instanceTemplate = Mockito.mock(InstanceTemplate.class); CloudResource vm1 = createCloudResource(INSTANCE_1, ResourceType.AZURE_INSTANCE); CloudResource vm2 = createCloudResource(INSTANCE_2, ResourceType.AZURE_INSTANCE); CloudResource vm3 = createCloudResource(INSTANCE_3, ResourceType.AZURE_INSTANCE); CloudResource storage1 = createCloudResource(STORAGE_1, ResourceType.AZURE_STORAGE); CloudResource ip1 = createCloudResource(IP_1, ResourceType.AZURE_PUBLIC_IP); List<CloudResource> cloudResourceList = List.of(vm1, vm2, vm3, storage1, ip1); when(instance.getTemplate()).thenReturn(instanceTemplate); when(instance.getTemplate().getPrivateId()).thenReturn(1L); when(instance.getTemplate().getStatus()).thenReturn(InstanceStatus.CREATE_REQUESTED); when(azureUtils.getPrivateInstanceId(any(), any(), any())) .thenReturn(INSTANCE_1) .thenReturn(INSTANCE_2) .thenReturn(INSTANCE_3); when(group.getInstances()).thenReturn(List.of(instance)); groupList.add(group); List<CloudResource> resourceList = underTest.getInstanceCloudResources(STACK_NAME, cloudResourceList, groupList, "resourceGroupName"); assertEquals(3, resourceList.size()); assertEquals(INSTANCE_1, resourceList.get(0).getName()); assertEquals(INSTANCE_2, resourceList.get(1).getName()); assertEquals(INSTANCE_3, resourceList.get(2).getName()); }
public List<CloudResource> getInstanceCloudResources(String stackName, List<CloudResource> cloudResourceList, List<Group> groups, String resourceGroupName) { List<CloudResource> vmResourceList = new ArrayList<>(); cloudResourceList .stream() .filter(cloudResource -> cloudResource.getType().equals(ResourceType.AZURE_INSTANCE)) .forEach(instance -> groups .stream() .map(Group::getInstances) .forEach(cloudInstances -> cloudInstances .stream() .filter(cloudInstance -> cloudInstance.getTemplate().getStatus().equals(InstanceStatus.CREATE_REQUESTED)) .filter(cloudInstance -> instance.getName().equalsIgnoreCase( azureUtils.getPrivateInstanceId(stackName, cloudInstance.getTemplate().getGroupName(), Long.toString(cloudInstance.getTemplate().getPrivateId())))) .peek(cloudInstance -> LOGGER.debug("The following resource is categorized as VM instance {}", cloudInstance.toString())) .forEach(filteredInstance -> vmResourceList.add(buildVm(instance, filteredInstance.getTemplate().getGroupName(), resourceGroupName)) ) ) ); if (vmResourceList.size() == 0) { String message = String.format("No VM resource found amongst cloud resources: %s", cloudResourceList.toString()); LOGGER.warn(message); throw new CloudbreakServiceException(message); } return vmResourceList; }
AzureCloudResourceService { public List<CloudResource> getInstanceCloudResources(String stackName, List<CloudResource> cloudResourceList, List<Group> groups, String resourceGroupName) { List<CloudResource> vmResourceList = new ArrayList<>(); cloudResourceList .stream() .filter(cloudResource -> cloudResource.getType().equals(ResourceType.AZURE_INSTANCE)) .forEach(instance -> groups .stream() .map(Group::getInstances) .forEach(cloudInstances -> cloudInstances .stream() .filter(cloudInstance -> cloudInstance.getTemplate().getStatus().equals(InstanceStatus.CREATE_REQUESTED)) .filter(cloudInstance -> instance.getName().equalsIgnoreCase( azureUtils.getPrivateInstanceId(stackName, cloudInstance.getTemplate().getGroupName(), Long.toString(cloudInstance.getTemplate().getPrivateId())))) .peek(cloudInstance -> LOGGER.debug("The following resource is categorized as VM instance {}", cloudInstance.toString())) .forEach(filteredInstance -> vmResourceList.add(buildVm(instance, filteredInstance.getTemplate().getGroupName(), resourceGroupName)) ) ) ); if (vmResourceList.size() == 0) { String message = String.format("No VM resource found amongst cloud resources: %s", cloudResourceList.toString()); LOGGER.warn(message); throw new CloudbreakServiceException(message); } return vmResourceList; } }
AzureCloudResourceService { public List<CloudResource> getInstanceCloudResources(String stackName, List<CloudResource> cloudResourceList, List<Group> groups, String resourceGroupName) { List<CloudResource> vmResourceList = new ArrayList<>(); cloudResourceList .stream() .filter(cloudResource -> cloudResource.getType().equals(ResourceType.AZURE_INSTANCE)) .forEach(instance -> groups .stream() .map(Group::getInstances) .forEach(cloudInstances -> cloudInstances .stream() .filter(cloudInstance -> cloudInstance.getTemplate().getStatus().equals(InstanceStatus.CREATE_REQUESTED)) .filter(cloudInstance -> instance.getName().equalsIgnoreCase( azureUtils.getPrivateInstanceId(stackName, cloudInstance.getTemplate().getGroupName(), Long.toString(cloudInstance.getTemplate().getPrivateId())))) .peek(cloudInstance -> LOGGER.debug("The following resource is categorized as VM instance {}", cloudInstance.toString())) .forEach(filteredInstance -> vmResourceList.add(buildVm(instance, filteredInstance.getTemplate().getGroupName(), resourceGroupName)) ) ) ); if (vmResourceList.size() == 0) { String message = String.format("No VM resource found amongst cloud resources: %s", cloudResourceList.toString()); LOGGER.warn(message); throw new CloudbreakServiceException(message); } return vmResourceList; }  }
AzureCloudResourceService { public List<CloudResource> getInstanceCloudResources(String stackName, List<CloudResource> cloudResourceList, List<Group> groups, String resourceGroupName) { List<CloudResource> vmResourceList = new ArrayList<>(); cloudResourceList .stream() .filter(cloudResource -> cloudResource.getType().equals(ResourceType.AZURE_INSTANCE)) .forEach(instance -> groups .stream() .map(Group::getInstances) .forEach(cloudInstances -> cloudInstances .stream() .filter(cloudInstance -> cloudInstance.getTemplate().getStatus().equals(InstanceStatus.CREATE_REQUESTED)) .filter(cloudInstance -> instance.getName().equalsIgnoreCase( azureUtils.getPrivateInstanceId(stackName, cloudInstance.getTemplate().getGroupName(), Long.toString(cloudInstance.getTemplate().getPrivateId())))) .peek(cloudInstance -> LOGGER.debug("The following resource is categorized as VM instance {}", cloudInstance.toString())) .forEach(filteredInstance -> vmResourceList.add(buildVm(instance, filteredInstance.getTemplate().getGroupName(), resourceGroupName)) ) ) ); if (vmResourceList.size() == 0) { String message = String.format("No VM resource found amongst cloud resources: %s", cloudResourceList.toString()); LOGGER.warn(message); throw new CloudbreakServiceException(message); } return vmResourceList; }  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> getInstanceCloudResources(String stackName, List<CloudResource> cloudResourceList, List<Group> groups, String resourceGroupName) { List<CloudResource> vmResourceList = new ArrayList<>(); cloudResourceList .stream() .filter(cloudResource -> cloudResource.getType().equals(ResourceType.AZURE_INSTANCE)) .forEach(instance -> groups .stream() .map(Group::getInstances) .forEach(cloudInstances -> cloudInstances .stream() .filter(cloudInstance -> cloudInstance.getTemplate().getStatus().equals(InstanceStatus.CREATE_REQUESTED)) .filter(cloudInstance -> instance.getName().equalsIgnoreCase( azureUtils.getPrivateInstanceId(stackName, cloudInstance.getTemplate().getGroupName(), Long.toString(cloudInstance.getTemplate().getPrivateId())))) .peek(cloudInstance -> LOGGER.debug("The following resource is categorized as VM instance {}", cloudInstance.toString())) .forEach(filteredInstance -> vmResourceList.add(buildVm(instance, filteredInstance.getTemplate().getGroupName(), resourceGroupName)) ) ) ); if (vmResourceList.size() == 0) { String message = String.format("No VM resource found amongst cloud resources: %s", cloudResourceList.toString()); LOGGER.warn(message); throw new CloudbreakServiceException(message); } return vmResourceList; }  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);  }