@Test public void testWhenComputeResourceIsNullThenNullReturns() { when(context.getComputeResources(anyLong())).thenReturn(null); List<CloudResource> result = underTest.create(context, PRIVATE_ID, auth, group, image); Assert.assertNull(result); }
@Override public List<CloudResource> create(AzureContext context, long privateId, AuthenticatedContext auth, Group group, Image image) { LOGGER.info("Creating volume resources"); List<CloudResource> computeResources = context.getComputeResources(privateId); if (Objects.isNull(computeResources) || computeResources.isEmpty()) { return null; } CloudResource vm = context.getComputeResources(privateId) .stream() .filter(cloudResource -> ResourceType.AZURE_INSTANCE.equals(cloudResource.getType())) .findFirst() .get(); Optional<CloudResource> reattachableVolumeSet = computeResources.stream() .filter(resource -> ResourceType.AZURE_VOLUMESET.equals(resource.getType())) .filter(cloudResource -> CommonStatus.DETACHED.equals(cloudResource.getStatus()) || vm.getInstanceId().equals(cloudResource.getInstanceId())) .findFirst(); LOGGER.debug("Reattachable volume set {}", reattachableVolumeSet.map(cloudResource -> "is present with name:" + cloudResource.getName()) .orElse("is not present")); return List.of(reattachableVolumeSet.orElseGet(createVolumeSet(privateId, auth, group, vm, context.getStringParameter(PlatformParametersConsts.RESOURCE_CRN_PARAMETER)))); }
AzureVolumeResourceBuilder extends AbstractAzureComputeBuilder { @Override public List<CloudResource> create(AzureContext context, long privateId, AuthenticatedContext auth, Group group, Image image) { LOGGER.info("Creating volume resources"); List<CloudResource> computeResources = context.getComputeResources(privateId); if (Objects.isNull(computeResources) || computeResources.isEmpty()) { return null; } CloudResource vm = context.getComputeResources(privateId) .stream() .filter(cloudResource -> ResourceType.AZURE_INSTANCE.equals(cloudResource.getType())) .findFirst() .get(); Optional<CloudResource> reattachableVolumeSet = computeResources.stream() .filter(resource -> ResourceType.AZURE_VOLUMESET.equals(resource.getType())) .filter(cloudResource -> CommonStatus.DETACHED.equals(cloudResource.getStatus()) || vm.getInstanceId().equals(cloudResource.getInstanceId())) .findFirst(); LOGGER.debug("Reattachable volume set {}", reattachableVolumeSet.map(cloudResource -> "is present with name:" + cloudResource.getName()) .orElse("is not present")); return List.of(reattachableVolumeSet.orElseGet(createVolumeSet(privateId, auth, group, vm, context.getStringParameter(PlatformParametersConsts.RESOURCE_CRN_PARAMETER)))); } }
AzureVolumeResourceBuilder extends AbstractAzureComputeBuilder { @Override public List<CloudResource> create(AzureContext context, long privateId, AuthenticatedContext auth, Group group, Image image) { LOGGER.info("Creating volume resources"); List<CloudResource> computeResources = context.getComputeResources(privateId); if (Objects.isNull(computeResources) || computeResources.isEmpty()) { return null; } CloudResource vm = context.getComputeResources(privateId) .stream() .filter(cloudResource -> ResourceType.AZURE_INSTANCE.equals(cloudResource.getType())) .findFirst() .get(); Optional<CloudResource> reattachableVolumeSet = computeResources.stream() .filter(resource -> ResourceType.AZURE_VOLUMESET.equals(resource.getType())) .filter(cloudResource -> CommonStatus.DETACHED.equals(cloudResource.getStatus()) || vm.getInstanceId().equals(cloudResource.getInstanceId())) .findFirst(); LOGGER.debug("Reattachable volume set {}", reattachableVolumeSet.map(cloudResource -> "is present with name:" + cloudResource.getName()) .orElse("is not present")); return List.of(reattachableVolumeSet.orElseGet(createVolumeSet(privateId, auth, group, vm, context.getStringParameter(PlatformParametersConsts.RESOURCE_CRN_PARAMETER)))); }  }
AzureVolumeResourceBuilder extends AbstractAzureComputeBuilder { @Override public List<CloudResource> create(AzureContext context, long privateId, AuthenticatedContext auth, Group group, Image image) { LOGGER.info("Creating volume resources"); List<CloudResource> computeResources = context.getComputeResources(privateId); if (Objects.isNull(computeResources) || computeResources.isEmpty()) { return null; } CloudResource vm = context.getComputeResources(privateId) .stream() .filter(cloudResource -> ResourceType.AZURE_INSTANCE.equals(cloudResource.getType())) .findFirst() .get(); Optional<CloudResource> reattachableVolumeSet = computeResources.stream() .filter(resource -> ResourceType.AZURE_VOLUMESET.equals(resource.getType())) .filter(cloudResource -> CommonStatus.DETACHED.equals(cloudResource.getStatus()) || vm.getInstanceId().equals(cloudResource.getInstanceId())) .findFirst(); LOGGER.debug("Reattachable volume set {}", reattachableVolumeSet.map(cloudResource -> "is present with name:" + cloudResource.getName()) .orElse("is not present")); return List.of(reattachableVolumeSet.orElseGet(createVolumeSet(privateId, auth, group, vm, context.getStringParameter(PlatformParametersConsts.RESOURCE_CRN_PARAMETER)))); }  @Override List<CloudResource> create(AzureContext context, long privateId, AuthenticatedContext auth, Group group, Image image); @Override List<CloudResource> build(AzureContext context, long privateId, AuthenticatedContext auth, Group group,
            List<CloudResource> buildableResource, CloudStack cloudStack); @Override CloudResource delete(AzureContext context, AuthenticatedContext auth, CloudResource resource); @Override ResourceType resourceType(); @Override int order(); }
AzureVolumeResourceBuilder extends AbstractAzureComputeBuilder { @Override public List<CloudResource> create(AzureContext context, long privateId, AuthenticatedContext auth, Group group, Image image) { LOGGER.info("Creating volume resources"); List<CloudResource> computeResources = context.getComputeResources(privateId); if (Objects.isNull(computeResources) || computeResources.isEmpty()) { return null; } CloudResource vm = context.getComputeResources(privateId) .stream() .filter(cloudResource -> ResourceType.AZURE_INSTANCE.equals(cloudResource.getType())) .findFirst() .get(); Optional<CloudResource> reattachableVolumeSet = computeResources.stream() .filter(resource -> ResourceType.AZURE_VOLUMESET.equals(resource.getType())) .filter(cloudResource -> CommonStatus.DETACHED.equals(cloudResource.getStatus()) || vm.getInstanceId().equals(cloudResource.getInstanceId())) .findFirst(); LOGGER.debug("Reattachable volume set {}", reattachableVolumeSet.map(cloudResource -> "is present with name:" + cloudResource.getName()) .orElse("is not present")); return List.of(reattachableVolumeSet.orElseGet(createVolumeSet(privateId, auth, group, vm, context.getStringParameter(PlatformParametersConsts.RESOURCE_CRN_PARAMETER)))); }  @Override List<CloudResource> create(AzureContext context, long privateId, AuthenticatedContext auth, Group group, Image image); @Override List<CloudResource> build(AzureContext context, long privateId, AuthenticatedContext auth, Group group,
            List<CloudResource> buildableResource, CloudStack cloudStack); @Override CloudResource delete(AzureContext context, AuthenticatedContext auth, CloudResource resource); @Override ResourceType resourceType(); @Override int order();  }