@Test public void testUpscaleThenThereAreNewInstancesRequired() { CloudContext cloudContext = createCloudContext(); AuthenticatedContext ac = new AuthenticatedContext(cloudContext, null); CloudResource template = createCloudResource(TEMPLATE, ResourceType.ARM_TEMPLATE); List<CloudResource> resources = List.of(createCloudResource("volumes", ResourceType.AZURE_VOLUMESET), template); List<Group> scaledGroups = createScaledGroups(); when(cloudResourceHelper.getScaledGroups(stack)).thenReturn(scaledGroups); when(azureTemplateDeploymentService.getTemplateDeployment(client, stack, ac, azureStackView, AzureInstanceTemplateOperation.UPSCALE)) .thenReturn(templateDeployment); when(templateDeployment.exportTemplate()).thenReturn(mock(DeploymentExportResult.class)); CloudResource newInstance = CloudResource.builder().instanceId("instanceid").type(ResourceType.AZURE_INSTANCE).status(CommonStatus.CREATED) .name("instance").params(Map.of()).build(); List<CloudResource> newInstances = List.of(newInstance); when(azureCloudResourceService.getDeploymentCloudResources(templateDeployment)).thenReturn(newInstances); when(azureCloudResourceService.getInstanceCloudResources(STACK_NAME, newInstances, scaledGroups, RESOURCE_GROUP)).thenReturn(newInstances); when(azureCloudResourceService.getNetworkResources(resources)).thenReturn(NETWORK_RESOURCES); List<CloudResourceStatus> actual = underTest.upscale(ac, stack, resources, azureStackView, client); assertFalse(actual.isEmpty()); assertEquals(template, actual.get(0).getCloudResource()); assertEquals(ResourceStatus.IN_PROGRESS, actual.get(0).getStatus()); verify(cloudResourceHelper).getScaledGroups(stack); verify(azureTemplateDeploymentService).getTemplateDeployment(client, stack, ac, azureStackView, AzureInstanceTemplateOperation.UPSCALE); verify(templateDeployment).exportTemplate(); verify(azureCloudResourceService).getInstanceCloudResources(STACK_NAME, newInstances, scaledGroups, RESOURCE_GROUP); verify(azureCloudResourceService).getNetworkResources(resources); verify(azureUtils).getStackName(any(CloudContext.class)); verify(azureResourceGroupMetadataProvider).getResourceGroupName(any(CloudContext.class), eq(stack)); verify(azureComputeResourceService).buildComputeResourcesForUpscale(ac, stack, scaledGroups, newInstances, List.of(), NETWORK_RESOURCES); }
public List<CloudResourceStatus> upscale(AuthenticatedContext ac, CloudStack stack, List<CloudResource> resources, AzureStackView azureStackView, AzureClient client) { CloudContext cloudContext = ac.getCloudContext(); String stackName = azureUtils.getStackName(cloudContext); String resourceGroupName = azureResourceGroupMetadataProvider.getResourceGroupName(cloudContext, stack); try { List<Group> scaledGroups = cloudResourceHelper.getScaledGroups(stack); CloudResource armTemplate = getArmTemplate(resources, stackName); purgeExistingInstances(azureStackView); Deployment templateDeployment = azureTemplateDeploymentService.getTemplateDeployment(client, stack, ac, azureStackView, AzureInstanceTemplateOperation.UPSCALE); LOGGER.info("Created template deployment for upscale: {}", templateDeployment.exportTemplate().template()); List<CloudResource> templateResources = azureCloudResourceService.getDeploymentCloudResources(templateDeployment); List<CloudResource> newInstances = azureCloudResourceService.getInstanceCloudResources(stackName, templateResources, scaledGroups, resourceGroupName); List<CloudResource> osDiskResources = azureCloudResourceService.getAttachedOsDiskResources(ac, newInstances, resourceGroupName); azureCloudResourceService.saveCloudResources(resourceNotifier, cloudContext, ListUtils.union(templateResources, osDiskResources)); List<CloudResource> reattachableVolumeSets = getReattachableVolumeSets(resources, newInstances); List<CloudResource> networkResources = azureCloudResourceService.getNetworkResources(resources); azureComputeResourceService.buildComputeResourcesForUpscale(ac, stack, scaledGroups, newInstances, reattachableVolumeSets, networkResources); return Collections.singletonList(new CloudResourceStatus(armTemplate, ResourceStatus.IN_PROGRESS)); } catch (CloudException e) { LOGGER.info("Upscale error, cloud exception happened: ", e); if (e.body() != null && e.body().details() != null) { String details = e.body().details().stream().map(CloudError::message).collect(Collectors.joining(", ")); throw new CloudConnectorException(String.format("Stack upscale failed, status code %s, error message: %s, details: %s", e.body().code(), e.body().message(), details)); } else { throw new CloudConnectorException(String.format("Stack upscale failed: '%s', please go to Azure Portal for detailed message", e)); } } catch (Exception e) { throw new CloudConnectorException(String.format("Could not upscale: %s ", stackName), e); } }
AzureUpscaleService { public List<CloudResourceStatus> upscale(AuthenticatedContext ac, CloudStack stack, List<CloudResource> resources, AzureStackView azureStackView, AzureClient client) { CloudContext cloudContext = ac.getCloudContext(); String stackName = azureUtils.getStackName(cloudContext); String resourceGroupName = azureResourceGroupMetadataProvider.getResourceGroupName(cloudContext, stack); try { List<Group> scaledGroups = cloudResourceHelper.getScaledGroups(stack); CloudResource armTemplate = getArmTemplate(resources, stackName); purgeExistingInstances(azureStackView); Deployment templateDeployment = azureTemplateDeploymentService.getTemplateDeployment(client, stack, ac, azureStackView, AzureInstanceTemplateOperation.UPSCALE); LOGGER.info("Created template deployment for upscale: {}", templateDeployment.exportTemplate().template()); List<CloudResource> templateResources = azureCloudResourceService.getDeploymentCloudResources(templateDeployment); List<CloudResource> newInstances = azureCloudResourceService.getInstanceCloudResources(stackName, templateResources, scaledGroups, resourceGroupName); List<CloudResource> osDiskResources = azureCloudResourceService.getAttachedOsDiskResources(ac, newInstances, resourceGroupName); azureCloudResourceService.saveCloudResources(resourceNotifier, cloudContext, ListUtils.union(templateResources, osDiskResources)); List<CloudResource> reattachableVolumeSets = getReattachableVolumeSets(resources, newInstances); List<CloudResource> networkResources = azureCloudResourceService.getNetworkResources(resources); azureComputeResourceService.buildComputeResourcesForUpscale(ac, stack, scaledGroups, newInstances, reattachableVolumeSets, networkResources); return Collections.singletonList(new CloudResourceStatus(armTemplate, ResourceStatus.IN_PROGRESS)); } catch (CloudException e) { LOGGER.info("Upscale error, cloud exception happened: ", e); if (e.body() != null && e.body().details() != null) { String details = e.body().details().stream().map(CloudError::message).collect(Collectors.joining(", ")); throw new CloudConnectorException(String.format("Stack upscale failed, status code %s, error message: %s, details: %s", e.body().code(), e.body().message(), details)); } else { throw new CloudConnectorException(String.format("Stack upscale failed: '%s', please go to Azure Portal for detailed message", e)); } } catch (Exception e) { throw new CloudConnectorException(String.format("Could not upscale: %s ", stackName), e); } } }
AzureUpscaleService { public List<CloudResourceStatus> upscale(AuthenticatedContext ac, CloudStack stack, List<CloudResource> resources, AzureStackView azureStackView, AzureClient client) { CloudContext cloudContext = ac.getCloudContext(); String stackName = azureUtils.getStackName(cloudContext); String resourceGroupName = azureResourceGroupMetadataProvider.getResourceGroupName(cloudContext, stack); try { List<Group> scaledGroups = cloudResourceHelper.getScaledGroups(stack); CloudResource armTemplate = getArmTemplate(resources, stackName); purgeExistingInstances(azureStackView); Deployment templateDeployment = azureTemplateDeploymentService.getTemplateDeployment(client, stack, ac, azureStackView, AzureInstanceTemplateOperation.UPSCALE); LOGGER.info("Created template deployment for upscale: {}", templateDeployment.exportTemplate().template()); List<CloudResource> templateResources = azureCloudResourceService.getDeploymentCloudResources(templateDeployment); List<CloudResource> newInstances = azureCloudResourceService.getInstanceCloudResources(stackName, templateResources, scaledGroups, resourceGroupName); List<CloudResource> osDiskResources = azureCloudResourceService.getAttachedOsDiskResources(ac, newInstances, resourceGroupName); azureCloudResourceService.saveCloudResources(resourceNotifier, cloudContext, ListUtils.union(templateResources, osDiskResources)); List<CloudResource> reattachableVolumeSets = getReattachableVolumeSets(resources, newInstances); List<CloudResource> networkResources = azureCloudResourceService.getNetworkResources(resources); azureComputeResourceService.buildComputeResourcesForUpscale(ac, stack, scaledGroups, newInstances, reattachableVolumeSets, networkResources); return Collections.singletonList(new CloudResourceStatus(armTemplate, ResourceStatus.IN_PROGRESS)); } catch (CloudException e) { LOGGER.info("Upscale error, cloud exception happened: ", e); if (e.body() != null && e.body().details() != null) { String details = e.body().details().stream().map(CloudError::message).collect(Collectors.joining(", ")); throw new CloudConnectorException(String.format("Stack upscale failed, status code %s, error message: %s, details: %s", e.body().code(), e.body().message(), details)); } else { throw new CloudConnectorException(String.format("Stack upscale failed: '%s', please go to Azure Portal for detailed message", e)); } } catch (Exception e) { throw new CloudConnectorException(String.format("Could not upscale: %s ", stackName), e); } }  }
AzureUpscaleService { public List<CloudResourceStatus> upscale(AuthenticatedContext ac, CloudStack stack, List<CloudResource> resources, AzureStackView azureStackView, AzureClient client) { CloudContext cloudContext = ac.getCloudContext(); String stackName = azureUtils.getStackName(cloudContext); String resourceGroupName = azureResourceGroupMetadataProvider.getResourceGroupName(cloudContext, stack); try { List<Group> scaledGroups = cloudResourceHelper.getScaledGroups(stack); CloudResource armTemplate = getArmTemplate(resources, stackName); purgeExistingInstances(azureStackView); Deployment templateDeployment = azureTemplateDeploymentService.getTemplateDeployment(client, stack, ac, azureStackView, AzureInstanceTemplateOperation.UPSCALE); LOGGER.info("Created template deployment for upscale: {}", templateDeployment.exportTemplate().template()); List<CloudResource> templateResources = azureCloudResourceService.getDeploymentCloudResources(templateDeployment); List<CloudResource> newInstances = azureCloudResourceService.getInstanceCloudResources(stackName, templateResources, scaledGroups, resourceGroupName); List<CloudResource> osDiskResources = azureCloudResourceService.getAttachedOsDiskResources(ac, newInstances, resourceGroupName); azureCloudResourceService.saveCloudResources(resourceNotifier, cloudContext, ListUtils.union(templateResources, osDiskResources)); List<CloudResource> reattachableVolumeSets = getReattachableVolumeSets(resources, newInstances); List<CloudResource> networkResources = azureCloudResourceService.getNetworkResources(resources); azureComputeResourceService.buildComputeResourcesForUpscale(ac, stack, scaledGroups, newInstances, reattachableVolumeSets, networkResources); return Collections.singletonList(new CloudResourceStatus(armTemplate, ResourceStatus.IN_PROGRESS)); } catch (CloudException e) { LOGGER.info("Upscale error, cloud exception happened: ", e); if (e.body() != null && e.body().details() != null) { String details = e.body().details().stream().map(CloudError::message).collect(Collectors.joining(", ")); throw new CloudConnectorException(String.format("Stack upscale failed, status code %s, error message: %s, details: %s", e.body().code(), e.body().message(), details)); } else { throw new CloudConnectorException(String.format("Stack upscale failed: '%s', please go to Azure Portal for detailed message", e)); } } catch (Exception e) { throw new CloudConnectorException(String.format("Could not upscale: %s ", stackName), e); } }  List<CloudResourceStatus> upscale(AuthenticatedContext ac, CloudStack stack, List<CloudResource> resources, AzureStackView azureStackView,
            AzureClient client); }
AzureUpscaleService { public List<CloudResourceStatus> upscale(AuthenticatedContext ac, CloudStack stack, List<CloudResource> resources, AzureStackView azureStackView, AzureClient client) { CloudContext cloudContext = ac.getCloudContext(); String stackName = azureUtils.getStackName(cloudContext); String resourceGroupName = azureResourceGroupMetadataProvider.getResourceGroupName(cloudContext, stack); try { List<Group> scaledGroups = cloudResourceHelper.getScaledGroups(stack); CloudResource armTemplate = getArmTemplate(resources, stackName); purgeExistingInstances(azureStackView); Deployment templateDeployment = azureTemplateDeploymentService.getTemplateDeployment(client, stack, ac, azureStackView, AzureInstanceTemplateOperation.UPSCALE); LOGGER.info("Created template deployment for upscale: {}", templateDeployment.exportTemplate().template()); List<CloudResource> templateResources = azureCloudResourceService.getDeploymentCloudResources(templateDeployment); List<CloudResource> newInstances = azureCloudResourceService.getInstanceCloudResources(stackName, templateResources, scaledGroups, resourceGroupName); List<CloudResource> osDiskResources = azureCloudResourceService.getAttachedOsDiskResources(ac, newInstances, resourceGroupName); azureCloudResourceService.saveCloudResources(resourceNotifier, cloudContext, ListUtils.union(templateResources, osDiskResources)); List<CloudResource> reattachableVolumeSets = getReattachableVolumeSets(resources, newInstances); List<CloudResource> networkResources = azureCloudResourceService.getNetworkResources(resources); azureComputeResourceService.buildComputeResourcesForUpscale(ac, stack, scaledGroups, newInstances, reattachableVolumeSets, networkResources); return Collections.singletonList(new CloudResourceStatus(armTemplate, ResourceStatus.IN_PROGRESS)); } catch (CloudException e) { LOGGER.info("Upscale error, cloud exception happened: ", e); if (e.body() != null && e.body().details() != null) { String details = e.body().details().stream().map(CloudError::message).collect(Collectors.joining(", ")); throw new CloudConnectorException(String.format("Stack upscale failed, status code %s, error message: %s, details: %s", e.body().code(), e.body().message(), details)); } else { throw new CloudConnectorException(String.format("Stack upscale failed: '%s', please go to Azure Portal for detailed message", e)); } } catch (Exception e) { throw new CloudConnectorException(String.format("Could not upscale: %s ", stackName), e); } }  List<CloudResourceStatus> upscale(AuthenticatedContext ac, CloudStack stack, List<CloudResource> resources, AzureStackView azureStackView,
            AzureClient client);  }