use of com.sequenceiq.common.api.adjustment.AdjustmentTypeWithThreshold in project cloudbreak by hortonworks.
the class StackUpscaleActionsTest method prevalidateTestDoExecuteWhenScalingNotNeeded.
@Test
void prevalidateTestDoExecuteWhenScalingNotNeeded() throws Exception {
AdjustmentTypeWithThreshold adjustmentTypeWithThreshold = new AdjustmentTypeWithThreshold(AdjustmentType.EXACT, ADJUSTMENT_ZERO.longValue());
context = new StackScalingFlowContext(flowParameters, stack, cloudContext, cloudCredential, cloudStack, Map.of(INSTANCE_GROUP_NAME, ADJUSTMENT_ZERO), Map.of(), Map.of(), false, adjustmentTypeWithThreshold);
UpdateDomainDnsResolverResult payload = new UpdateDomainDnsResolverResult(STACK_ID);
when(stackUpscaleService.getInstanceCountToCreate(stack, INSTANCE_GROUP_NAME, ADJUSTMENT_ZERO, false)).thenReturn(ADJUSTMENT_ZERO);
List<CloudResourceStatus> resourceStatuses = List.of(cloudResourceStatus);
when(reactorEventFactory.createEvent(anyMap(), isNotNull())).thenReturn(event);
new AbstractActionTestSupport<>(getPrevalidateAction()).doExecute(context, payload, createVariables(Map.of(INSTANCE_GROUP_NAME, ADJUSTMENT_ZERO), Map.of(), NetworkScaleDetails.getEmpty(), adjustmentTypeWithThreshold, VARIANT));
verify(stackUpscaleService).addInstanceFireEventAndLog(stack, Map.of(INSTANCE_GROUP_NAME, ADJUSTMENT_ZERO), adjustmentTypeWithThreshold);
verifyEventForExtendMetadata(resourceStatuses);
}
use of com.sequenceiq.common.api.adjustment.AdjustmentTypeWithThreshold in project cloudbreak by hortonworks.
the class StackUpscaleServiceTest method testExactButFailBecauseHigherThanProvisionable.
@Test
public void testExactButFailBecauseHigherThanProvisionable() throws QuotaExceededException {
CloudConnector connector = mock(CloudConnector.class);
ResourceConnector resourceConnector = mock(ResourceConnector.class);
when(connector.resources()).thenReturn(resourceConnector);
when(resourceConnector.upscale(any(), any(), any(), any())).thenThrow(new QuotaExceededException(40, 20, 40, "quota error", new Exception()));
AdjustmentTypeWithThreshold adjustmentTypeWithThreshold = new AdjustmentTypeWithThreshold(AdjustmentType.EXACT, 3L);
List<Group> groups = new ArrayList<>();
List<CloudInstance> workerInstances = new ArrayList<>();
workerInstances.add(new CloudInstance("W1", getInstanceTemplate(1L, "worker"), mock(InstanceAuthentication.class), "subnet-1", "az1", Map.of(CloudInstance.FQDN, "worker1.example.com")));
workerInstances.add(new CloudInstance(null, getInstanceTemplate(2L, "worker"), mock(InstanceAuthentication.class), "subnet-1", "az1", Map.of(CloudInstance.FQDN, "worker2.example.com")));
workerInstances.add(new CloudInstance(null, getInstanceTemplate(3L, "worker"), mock(InstanceAuthentication.class), "subnet-1", "az1", Map.of(CloudInstance.FQDN, "worker3.example.com")));
groups.add(new Group("worker", InstanceGroupType.CORE, workerInstances, mock(Security.class), mock(CloudInstance.class), mock(InstanceAuthentication.class), "admin", "ssh", 100, Optional.empty(), null, emptyMap()));
List<CloudInstance> computeInstances = new ArrayList<>();
computeInstances.add(new CloudInstance("C1", getInstanceTemplate(4L, "compute"), mock(InstanceAuthentication.class), "subnet-1", "az1", Map.of(CloudInstance.FQDN, "compute1.example.com")));
computeInstances.add(new CloudInstance(null, getInstanceTemplate(5L, "compute"), mock(InstanceAuthentication.class), "subnet-1", "az1", Map.of(CloudInstance.FQDN, "compute2.example.com")));
computeInstances.add(new CloudInstance(null, getInstanceTemplate(6L, "compute"), mock(InstanceAuthentication.class), "subnet-1", "az1", Map.of(CloudInstance.FQDN, "compute3.example.com")));
groups.add(new Group("compute", InstanceGroupType.CORE, computeInstances, mock(Security.class), mock(CloudInstance.class), mock(InstanceAuthentication.class), "admin", "ssh", 100, Optional.empty(), null, emptyMap()));
CloudStack cloudStack = new CloudStack(groups, mock(Network.class), mock(Image.class), Collections.emptyMap(), Collections.emptyMap(), "template", mock(InstanceAuthentication.class), "username", "publickey", mock(SpiFileSystem.class));
UpscaleStackRequest<UpscaleStackResult> upscaleStackRequest = new UpscaleStackRequest<>(mock(CloudContext.class), mock(CloudCredential.class), cloudStack, new ArrayList<>(), adjustmentTypeWithThreshold);
Assertions.assertThrows(CloudConnectorException.class, () -> stackUpscaleService.upscale(mock(AuthenticatedContext.class), upscaleStackRequest, connector));
verify(flowMessageService, times(1)).fireEventAndLog(upscaleStackRequest.getResourceId(), UPDATE_IN_PROGRESS.name(), STACK_UPSCALE_QUOTA_ISSUE, "quota error");
ArgumentCaptor<CloudStack> cloudStackArgumentCaptor = ArgumentCaptor.forClass(CloudStack.class);
verify(resourceConnector, times(1)).upscale(any(), cloudStackArgumentCaptor.capture(), any(), eq(adjustmentTypeWithThreshold));
}
use of com.sequenceiq.common.api.adjustment.AdjustmentTypeWithThreshold in project cloudbreak by hortonworks.
the class StackUpscaleServiceTest method testPercentageAndProvisionable.
@Test
public void testPercentageAndProvisionable() throws QuotaExceededException {
CloudConnector connector = mock(CloudConnector.class);
ResourceConnector resourceConnector = mock(ResourceConnector.class);
when(connector.resources()).thenReturn(resourceConnector);
when(resourceConnector.upscale(any(), any(), any(), any())).thenThrow(new QuotaExceededException(40, 20, 40, "quota error", new Exception())).thenReturn(Collections.emptyList());
AdjustmentTypeWithThreshold adjustmentTypeWithThreshold = new AdjustmentTypeWithThreshold(AdjustmentType.PERCENTAGE, 50L);
List<Group> groups = new ArrayList<>();
List<CloudInstance> workerInstances = new ArrayList<>();
workerInstances.add(new CloudInstance("W1", getInstanceTemplate(1L, "worker"), mock(InstanceAuthentication.class), "subnet-1", "az1", Map.of(CloudInstance.FQDN, "worker1.example.com")));
workerInstances.add(new CloudInstance(null, getInstanceTemplate(2L, "worker"), mock(InstanceAuthentication.class), "subnet-1", "az1", Map.of(CloudInstance.FQDN, "worker2.example.com")));
workerInstances.add(new CloudInstance(null, getInstanceTemplate(3L, "worker"), mock(InstanceAuthentication.class), "subnet-1", "az1", Map.of(CloudInstance.FQDN, "worker3.example.com")));
groups.add(new Group("worker", InstanceGroupType.CORE, workerInstances, mock(Security.class), mock(CloudInstance.class), mock(InstanceAuthentication.class), "admin", "ssh", 100, Optional.empty(), null, emptyMap()));
List<CloudInstance> computeInstances = new ArrayList<>();
computeInstances.add(new CloudInstance("C1", getInstanceTemplate(4L, "compute"), mock(InstanceAuthentication.class), "subnet-1", "az1", Map.of(CloudInstance.FQDN, "compute1.example.com")));
computeInstances.add(new CloudInstance(null, getInstanceTemplate(5L, "compute"), mock(InstanceAuthentication.class), "subnet-1", "az1", Map.of(CloudInstance.FQDN, "compute2.example.com")));
computeInstances.add(new CloudInstance(null, getInstanceTemplate(6L, "compute"), mock(InstanceAuthentication.class), "subnet-1", "az1", Map.of(CloudInstance.FQDN, "compute3.example.com")));
groups.add(new Group("compute", InstanceGroupType.CORE, computeInstances, mock(Security.class), mock(CloudInstance.class), mock(InstanceAuthentication.class), "admin", "ssh", 100, Optional.empty(), null, emptyMap()));
CloudStack cloudStack = new CloudStack(groups, mock(Network.class), mock(Image.class), Collections.emptyMap(), Collections.emptyMap(), "template", mock(InstanceAuthentication.class), "username", "publickey", mock(SpiFileSystem.class));
UpscaleStackRequest<UpscaleStackResult> upscaleStackRequest = new UpscaleStackRequest<>(mock(CloudContext.class), mock(CloudCredential.class), cloudStack, new ArrayList<>(), adjustmentTypeWithThreshold);
stackUpscaleService.upscale(mock(AuthenticatedContext.class), upscaleStackRequest, connector);
verify(flowMessageService, times(1)).fireEventAndLog(upscaleStackRequest.getResourceId(), UPDATE_IN_PROGRESS.name(), STACK_UPSCALE_QUOTA_ISSUE, "quota error");
ArgumentCaptor<CloudStack> cloudStackArgumentCaptor = ArgumentCaptor.forClass(CloudStack.class);
verify(resourceConnector, times(2)).upscale(any(), cloudStackArgumentCaptor.capture(), any(), eq(adjustmentTypeWithThreshold));
List<CloudStack> cloudStacks = cloudStackArgumentCaptor.getAllValues();
List<CloudInstance> cloudInstances = cloudStacks.get(1).getGroups().stream().flatMap(group -> group.getInstances().stream()).collect(Collectors.toList());
List<CloudInstance> cloudInstancesWithoutInstanceId = cloudInstances.stream().filter(cloudInstance -> cloudInstance.getInstanceId() == null).collect(Collectors.toList());
assertEquals(4, cloudInstances.size());
assertEquals(2, cloudInstancesWithoutInstanceId.size());
}
use of com.sequenceiq.common.api.adjustment.AdjustmentTypeWithThreshold 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.common.api.adjustment.AdjustmentTypeWithThreshold in project cloudbreak by hortonworks.
the class ClusterRepairFlowEventChainFactory method fullUpscaleEvent.
private StackAndClusterUpscaleTriggerEvent fullUpscaleEvent(ClusterRepairTriggerEvent event, Map<String, Set<String>> groupsWithHostNames, boolean singlePrimaryGateway, boolean restartServices, boolean kerberosSecured) {
Set<InstanceGroupView> instanceGroupViews = instanceGroupService.findViewByStackId(event.getStackId());
boolean singleNodeCluster = isSingleNode(instanceGroupViews);
Integer adjustmentSize = groupsWithHostNames.values().stream().map(Set::size).reduce(0, Integer::sum);
AdjustmentTypeWithThreshold adjustmentTypeWithThreshold = new AdjustmentTypeWithThreshold(AdjustmentType.EXACT, (long) adjustmentSize);
Map<String, Integer> hostGroupAdjustments = groupsWithHostNames.entrySet().stream().collect(Collectors.toMap(Entry::getKey, o -> o.getValue().size()));
LOGGER.info("Full upscale with host groups and adjustments: {}", hostGroupAdjustments);
LOGGER.info("Full upscale with host groups and host names: {}", groupsWithHostNames);
return new StackAndClusterUpscaleTriggerEvent(FlowChainTriggers.FULL_UPSCALE_TRIGGER_EVENT, event.getResourceId(), hostGroupAdjustments, null, groupsWithHostNames, ScalingType.UPSCALE_TOGETHER, singlePrimaryGateway, kerberosSecured, event.accepted(), singleNodeCluster, restartServices, ClusterManagerType.CLOUDERA_MANAGER, adjustmentTypeWithThreshold, event.getTriggeredStackVariant()).setRepair();
}
Aggregations