use of com.sequenceiq.cloudbreak.cloud.notification.ResourceNotifier in project cloudbreak by hortonworks.
the class AzureUpscaleService method upscale.
public List<CloudResourceStatus> upscale(AuthenticatedContext ac, CloudStack stack, List<CloudResource> resources, AzureStackView azureStackView, AzureClient client, AdjustmentTypeWithThreshold adjustmentTypeWithThreshold) throws QuotaExceededException {
CloudContext cloudContext = ac.getCloudContext();
String stackName = azureUtils.getStackName(cloudContext);
String resourceGroupName = azureResourceGroupMetadataProvider.getResourceGroupName(cloudContext, stack);
List<CloudResource> newInstances = new ArrayList<>();
List<CloudResource> templateResources = new ArrayList<>();
List<CloudResource> osDiskResources = new ArrayList<>();
DateTime preDeploymentTime = DateTime.now();
filterExistingInstances(azureStackView);
try {
List<Group> scaledGroups = cloudResourceHelper.getScaledGroups(stack);
CloudResource armTemplate = getArmTemplate(resources, stackName);
Deployment templateDeployment = azureTemplateDeploymentService.getTemplateDeployment(client, stack, ac, azureStackView, AzureInstanceTemplateOperation.UPSCALE);
LOGGER.info("Created template deployment for upscale: {}", templateDeployment.exportTemplate().template());
templateResources.addAll(azureCloudResourceService.getDeploymentCloudResources(templateDeployment));
newInstances.addAll(azureCloudResourceService.getInstanceCloudResources(stackName, templateResources, scaledGroups, resourceGroupName));
if (!newInstances.isEmpty()) {
osDiskResources.addAll(azureCloudResourceService.getAttachedOsDiskResources(newInstances, resourceGroupName, client));
} else {
LOGGER.warn("Skipping OS disk collection as there was no VM instance found amongst cloud resources for {}!", stackName);
}
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, adjustmentTypeWithThreshold);
List<CloudResourceStatus> successfulInstances = newInstances.stream().map(cloudResource -> new CloudResourceStatus(cloudResource, ResourceStatus.CREATED, cloudResource.getParameter(CloudResource.PRIVATE_ID, Long.class))).collect(Collectors.toList());
return ListUtils.union(Collections.singletonList(new CloudResourceStatus(armTemplate, ResourceStatus.IN_PROGRESS)), successfulInstances);
} catch (Retry.ActionFailedException e) {
LOGGER.error("Retry.ActionFailedException happened", e);
rollbackResources(ac, client, stack, cloudContext, resources, preDeploymentTime);
throw azureUtils.convertToCloudConnectorException(e.getCause(), "Stack upscale");
} catch (CloudException e) {
LOGGER.error("CloudException happened", e);
rollbackResources(ac, client, stack, cloudContext, resources, preDeploymentTime);
checkIfQuotaLimitIssued(e);
throw azureUtils.convertToCloudConnectorException(e, "Stack upscale");
} catch (RolledbackResourcesException e) {
LOGGER.error("RolledbackResourcesException happened", e);
rollbackResources(ac, client, stack, cloudContext, resources, preDeploymentTime);
throw new CloudConnectorException(String.format("Could not upscale Azure infrastructure, infrastructure was rolled back with resources: %s, %s", stackName, e.getMessage()), e);
} catch (Exception e) {
LOGGER.error("Exception happened", e);
rollbackResources(ac, client, stack, cloudContext, resources, preDeploymentTime);
throw new CloudConnectorException(String.format("Could not upscale Azure infrastructure, infrastructure was rolled back: %s, %s", stackName, e.getMessage()), e);
}
}
use of com.sequenceiq.cloudbreak.cloud.notification.ResourceNotifier in project cloudbreak by hortonworks.
the class AwsRepairTest method upscaleStack.
private void upscaleStack() throws Exception {
AuthenticatedContext authenticatedContext = componentTestUtil.getAuthenticatedContext();
CloudStack stack = componentTestUtil.getStack(InstanceStatus.CREATE_REQUESTED, InstanceStatus.STARTED);
List<CloudResource> cloudResources = List.of(CloudResource.builder().name(AWS_SUBNET_ID).type(ResourceType.AWS_SUBNET).build(), createVolumeResource(VOLUME_ID_1, INSTANCE_ID_1, SIZE_DISK_1, FSTAB_1, CommonStatus.DETACHED), createVolumeResource(VOLUME_ID_2, INSTANCE_ID_2, SIZE_DISK_2, FSTAB_2, CommonStatus.DETACHED), createVolumeResource(VOLUME_ID_3, INSTANCE_ID_3, SIZE_DISK_2, FSTAB_2, CommonStatus.CREATED));
InMemoryStateStore.putStack(1L, PollGroup.POLLABLE);
when(amazonCloudFormationClient.describeStackResource(any())).thenReturn(new DescribeStackResourceResult().withStackResourceDetail(new StackResourceDetail().withPhysicalResourceId(AUTOSCALING_GROUP_NAME)));
when(amazonAutoScalingClient.describeAutoScalingGroups(any())).thenReturn(new DescribeAutoScalingGroupsResult().withAutoScalingGroups(new AutoScalingGroup().withAutoScalingGroupName(AUTOSCALING_GROUP_NAME).withInstances(List.of(new Instance().withInstanceId(INSTANCE_ID_1).withLifecycleState(LifecycleState.InService), new Instance().withInstanceId(INSTANCE_ID_2).withLifecycleState(LifecycleState.InService)))));
when(amazonEC2Client.describeVolumes(any())).thenReturn(new DescribeVolumesResult().withVolumes(new com.amazonaws.services.ec2.model.Volume().withVolumeId(VOLUME_ID_1).withState(VolumeState.Available), new com.amazonaws.services.ec2.model.Volume().withVolumeId(VOLUME_ID_2).withState(VolumeState.Available), new com.amazonaws.services.ec2.model.Volume().withVolumeId(VOLUME_ID_3).withState(VolumeState.InUse)));
when(amazonEC2Client.describeInstances(any())).thenReturn(new DescribeInstancesResult().withReservations(new Reservation().withInstances(new com.amazonaws.services.ec2.model.Instance().withInstanceId("i-instance"))));
DescribeScalingActivitiesResult result = new DescribeScalingActivitiesResult();
result.setActivities(List.of());
when(amazonAutoScalingClient.describeScalingActivities(any(DescribeScalingActivitiesRequest.class))).thenReturn(result);
AmazonEC2Waiters waiters = mock(AmazonEC2Waiters.class);
when(amazonEC2Client.waiters()).thenReturn(waiters);
Waiter<DescribeInstancesRequest> instanceWaiter = mock(Waiter.class);
when(waiters.instanceRunning()).thenReturn(instanceWaiter);
when(amazonAutoScalingClient.waiters()).thenReturn(asWaiters);
when(asWaiters.groupInService()).thenReturn(describeAutoScalingGroupsRequestWaiter);
underTest.upscale(authenticatedContext, stack, cloudResources, new AdjustmentTypeWithThreshold(AdjustmentType.EXACT, 0L));
verify(amazonAutoScalingClient).resumeProcesses(argThat(argument -> AUTOSCALING_GROUP_NAME.equals(argument.getAutoScalingGroupName()) && argument.getScalingProcesses().contains("Launch")));
verify(amazonAutoScalingClient).updateAutoScalingGroup(argThat(argument -> {
Group workerGroup = stack.getGroups().get(1);
return AUTOSCALING_GROUP_NAME.equals(argument.getAutoScalingGroupName()) && workerGroup.getInstancesSize().equals(argument.getMaxSize()) && workerGroup.getInstancesSize().equals(argument.getDesiredCapacity());
}));
verify(amazonAutoScalingClient, times(stack.getGroups().size())).suspendProcesses(argThat(argument -> AUTOSCALING_GROUP_NAME.equals(argument.getAutoScalingGroupName()) && SUSPENDED_PROCESSES.equals(argument.getScalingProcesses())));
ArgumentCaptor<CloudResource> updatedCloudResourceArgumentCaptor = ArgumentCaptor.forClass(CloudResource.class);
verify(resourceNotifier, times(2)).notifyUpdate(updatedCloudResourceArgumentCaptor.capture(), any());
assertVolumeResource(updatedCloudResourceArgumentCaptor.getAllValues(), INSTANCE_ID_1, SIZE_DISK_1, FSTAB_1);
assertVolumeResource(updatedCloudResourceArgumentCaptor.getAllValues(), INSTANCE_ID_2, SIZE_DISK_2, FSTAB_2);
}
Aggregations