Search in sources :

Example 26 with AdjustmentTypeWithThreshold

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);
}
Also used : CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) AdjustmentTypeWithThreshold(com.sequenceiq.common.api.adjustment.AdjustmentTypeWithThreshold) StackScalingFlowContext(com.sequenceiq.cloudbreak.core.flow2.stack.downscale.StackScalingFlowContext) UpdateDomainDnsResolverResult(com.sequenceiq.cloudbreak.reactor.api.event.stack.UpdateDomainDnsResolverResult) Test(org.junit.jupiter.api.Test)

Example 27 with AdjustmentTypeWithThreshold

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));
}
Also used : QuotaExceededException(com.sequenceiq.cloudbreak.cloud.exception.QuotaExceededException) Group(com.sequenceiq.cloudbreak.cloud.model.Group) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) InstanceAuthentication(com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication) CloudConnector(com.sequenceiq.cloudbreak.cloud.CloudConnector) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) ArrayList(java.util.ArrayList) AdjustmentTypeWithThreshold(com.sequenceiq.common.api.adjustment.AdjustmentTypeWithThreshold) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) SpiFileSystem(com.sequenceiq.cloudbreak.cloud.model.SpiFileSystem) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) Image(com.sequenceiq.cloudbreak.cloud.model.Image) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) QuotaExceededException(com.sequenceiq.cloudbreak.cloud.exception.QuotaExceededException) UpscaleStackResult(com.sequenceiq.cloudbreak.reactor.api.event.stack.UpscaleStackResult) Network(com.sequenceiq.cloudbreak.cloud.model.Network) ResourceConnector(com.sequenceiq.cloudbreak.cloud.ResourceConnector) UpscaleStackRequest(com.sequenceiq.cloudbreak.reactor.api.event.stack.UpscaleStackRequest) Test(org.junit.jupiter.api.Test)

Example 28 with 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());
}
Also used : CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) TestUtil(com.sequenceiq.cloudbreak.TestUtil) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) CloudbreakFlowMessageService(com.sequenceiq.cloudbreak.core.flow2.stack.CloudbreakFlowMessageService) Map(java.util.Map) UpscaleStackRequest(com.sequenceiq.cloudbreak.reactor.api.event.stack.UpscaleStackRequest) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) InstanceStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus) Set(java.util.Set) TestUtil.instanceMetaData(com.sequenceiq.cloudbreak.TestUtil.instanceMetaData) Collectors(java.util.stream.Collectors) TemporaryStorage(com.sequenceiq.cloudbreak.common.type.TemporaryStorage) Test(org.junit.jupiter.api.Test) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) AdjustmentType(com.sequenceiq.common.api.type.AdjustmentType) List(java.util.List) Group(com.sequenceiq.cloudbreak.cloud.model.Group) Optional(java.util.Optional) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Mock(org.mockito.Mock) SpiFileSystem(com.sequenceiq.cloudbreak.cloud.model.SpiFileSystem) Image(com.sequenceiq.cloudbreak.cloud.model.Image) ArrayList(java.util.ArrayList) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) ArgumentCaptor(org.mockito.ArgumentCaptor) UPDATE_IN_PROGRESS(com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status.UPDATE_IN_PROGRESS) UpscaleStackResult(com.sequenceiq.cloudbreak.reactor.api.event.stack.UpscaleStackResult) InstanceMetaDataService(com.sequenceiq.cloudbreak.service.stack.InstanceMetaDataService) InstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Network(com.sequenceiq.cloudbreak.cloud.model.Network) InjectMocks(org.mockito.InjectMocks) Security(com.sequenceiq.cloudbreak.cloud.model.Security) Collections.emptyMap(java.util.Collections.emptyMap) ResourceConnector(com.sequenceiq.cloudbreak.cloud.ResourceConnector) AdjustmentTypeWithThreshold(com.sequenceiq.common.api.adjustment.AdjustmentTypeWithThreshold) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) QuotaExceededException(com.sequenceiq.cloudbreak.cloud.exception.QuotaExceededException) CloudConnector(com.sequenceiq.cloudbreak.cloud.CloudConnector) Mockito.verify(org.mockito.Mockito.verify) InstanceGroupType(com.sequenceiq.common.api.type.InstanceGroupType) STACK_UPSCALE_QUOTA_ISSUE(com.sequenceiq.cloudbreak.event.ResourceEvent.STACK_UPSCALE_QUOTA_ISSUE) CloudPlatformConnectors(com.sequenceiq.cloudbreak.cloud.init.CloudPlatformConnectors) Assertions(org.junit.jupiter.api.Assertions) InstanceAuthentication(com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication) Collections(java.util.Collections) Group(com.sequenceiq.cloudbreak.cloud.model.Group) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) CloudConnector(com.sequenceiq.cloudbreak.cloud.CloudConnector) ArrayList(java.util.ArrayList) SpiFileSystem(com.sequenceiq.cloudbreak.cloud.model.SpiFileSystem) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) Image(com.sequenceiq.cloudbreak.cloud.model.Image) Network(com.sequenceiq.cloudbreak.cloud.model.Network) UpscaleStackRequest(com.sequenceiq.cloudbreak.reactor.api.event.stack.UpscaleStackRequest) QuotaExceededException(com.sequenceiq.cloudbreak.cloud.exception.QuotaExceededException) InstanceAuthentication(com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) AdjustmentTypeWithThreshold(com.sequenceiq.common.api.adjustment.AdjustmentTypeWithThreshold) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) QuotaExceededException(com.sequenceiq.cloudbreak.cloud.exception.QuotaExceededException) UpscaleStackResult(com.sequenceiq.cloudbreak.reactor.api.event.stack.UpscaleStackResult) ResourceConnector(com.sequenceiq.cloudbreak.cloud.ResourceConnector) Test(org.junit.jupiter.api.Test)

Example 29 with AdjustmentTypeWithThreshold

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);
    }
}
Also used : AzureClient(com.sequenceiq.cloudbreak.cloud.azure.client.AzureClient) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) CloudError(com.microsoft.azure.CloudError) RolledbackResourcesException(com.sequenceiq.cloudbreak.cloud.exception.RolledbackResourcesException) LoggerFactory(org.slf4j.LoggerFactory) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) AzureComputeResourceService(com.sequenceiq.cloudbreak.cloud.azure.connector.resource.AzureComputeResourceService) ArrayList(java.util.ArrayList) ResourceNotifier(com.sequenceiq.cloudbreak.cloud.notification.ResourceNotifier) Inject(javax.inject.Inject) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) Matcher(java.util.regex.Matcher) AzureStackView(com.sequenceiq.cloudbreak.cloud.azure.view.AzureStackView) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) ListUtils(org.apache.commons.collections4.ListUtils) AzureInstanceView(com.sequenceiq.cloudbreak.cloud.azure.view.AzureInstanceView) AzureUtils(com.sequenceiq.cloudbreak.cloud.azure.AzureUtils) CommonStatus(com.sequenceiq.common.api.type.CommonStatus) ResourceStatus(com.sequenceiq.cloudbreak.cloud.model.ResourceStatus) CloudResourceHelper(com.sequenceiq.cloudbreak.cloud.transform.CloudResourceHelper) ResourceType(com.sequenceiq.common.api.type.ResourceType) Deployment(com.microsoft.azure.management.resources.Deployment) Logger(org.slf4j.Logger) AzureResourceGroupMetadataProvider(com.sequenceiq.cloudbreak.cloud.azure.AzureResourceGroupMetadataProvider) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) AdjustmentTypeWithThreshold(com.sequenceiq.common.api.adjustment.AdjustmentTypeWithThreshold) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) DateTime(org.joda.time.DateTime) Retry(com.sequenceiq.cloudbreak.service.Retry) Collectors(java.util.stream.Collectors) QuotaExceededException(com.sequenceiq.cloudbreak.cloud.exception.QuotaExceededException) AzureCloudResourceService(com.sequenceiq.cloudbreak.cloud.azure.AzureCloudResourceService) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) AzureTerminationHelperService(com.sequenceiq.cloudbreak.cloud.azure.AzureTerminationHelperService) List(java.util.List) Component(org.springframework.stereotype.Component) AzureTemplateDeploymentService(com.sequenceiq.cloudbreak.cloud.azure.template.AzureTemplateDeploymentService) Group(com.sequenceiq.cloudbreak.cloud.model.Group) CloudException(com.microsoft.azure.CloudException) Pattern(java.util.regex.Pattern) AzureInstanceTemplateOperation(com.sequenceiq.cloudbreak.cloud.azure.AzureInstanceTemplateOperation) Collections(java.util.Collections) Group(com.sequenceiq.cloudbreak.cloud.model.Group) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) ArrayList(java.util.ArrayList) Deployment(com.microsoft.azure.management.resources.Deployment) CloudException(com.microsoft.azure.CloudException) RolledbackResourcesException(com.sequenceiq.cloudbreak.cloud.exception.RolledbackResourcesException) DateTime(org.joda.time.DateTime) RolledbackResourcesException(com.sequenceiq.cloudbreak.cloud.exception.RolledbackResourcesException) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) QuotaExceededException(com.sequenceiq.cloudbreak.cloud.exception.QuotaExceededException) CloudException(com.microsoft.azure.CloudException) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) Retry(com.sequenceiq.cloudbreak.service.Retry)

Example 30 with AdjustmentTypeWithThreshold

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();
}
Also used : StackView(com.sequenceiq.cloudbreak.domain.view.StackView) EntitlementService(com.sequenceiq.cloudbreak.auth.altus.EntitlementService) InstanceGroupService(com.sequenceiq.cloudbreak.service.stack.InstanceGroupService) KerberosConfigService(com.sequenceiq.cloudbreak.kerberos.KerberosConfigService) HashMultimap(com.google.common.collect.HashMultimap) ClusterDownscaleDetails(com.sequenceiq.cloudbreak.core.flow2.event.ClusterDownscaleDetails) RescheduleStatusCheckTriggerEvent(com.sequenceiq.cloudbreak.reactor.api.event.orchestration.RescheduleStatusCheckTriggerEvent) Map(java.util.Map) LinkedListMultimap(com.google.common.collect.LinkedListMultimap) AwsVariantMigrationTriggerEvent(com.sequenceiq.cloudbreak.core.flow2.event.AwsVariantMigrationTriggerEvent) AwsConstants(com.sequenceiq.cloudbreak.cloud.aws.common.AwsConstants) FlowChainFinalizePayload(com.sequenceiq.flow.core.chain.finalize.flowevents.FlowChainFinalizePayload) Collection(java.util.Collection) ClusterAndStackDownscaleTriggerEvent(com.sequenceiq.cloudbreak.core.flow2.event.ClusterAndStackDownscaleTriggerEvent) StackDownscaleTriggerEvent(com.sequenceiq.cloudbreak.core.flow2.event.StackDownscaleTriggerEvent) Set(java.util.Set) Crn(com.sequenceiq.cloudbreak.auth.crn.Crn) Collectors(java.util.stream.Collectors) AdjustmentType(com.sequenceiq.common.api.type.AdjustmentType) List(java.util.List) Entry(java.util.Map.Entry) Optional(java.util.Optional) Queue(java.util.Queue) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) StackService(com.sequenceiq.cloudbreak.service.stack.StackService) AwsVariantMigrationEvent(com.sequenceiq.cloudbreak.core.flow2.stack.migration.AwsVariantMigrationEvent) StackAndClusterUpscaleTriggerEvent(com.sequenceiq.cloudbreak.core.flow2.event.StackAndClusterUpscaleTriggerEvent) InstanceGroupView(com.sequenceiq.cloudbreak.domain.view.InstanceGroupView) HashMap(java.util.HashMap) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) HostGroupService(com.sequenceiq.cloudbreak.service.hostgroup.HostGroupService) ClusterRepairTriggerEvent(com.sequenceiq.cloudbreak.reactor.api.event.orchestration.ClusterRepairTriggerEvent) Multimap(com.google.common.collect.Multimap) StackEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackEvent) ArrayList(java.util.ArrayList) Multimaps(com.google.common.collect.Multimaps) HashSet(java.util.HashSet) Inject(javax.inject.Inject) FlowChainInitPayload(com.sequenceiq.flow.core.chain.init.flowevents.FlowChainInitPayload) ClusterManagerType(com.sequenceiq.cloudbreak.common.type.ClusterManagerType) FlowTriggerEventQueue(com.sequenceiq.flow.core.chain.config.FlowTriggerEventQueue) InstanceMetaDataService(com.sequenceiq.cloudbreak.service.stack.InstanceMetaDataService) NotFoundException.notFound(com.sequenceiq.cloudbreak.common.exception.NotFoundException.notFound) Logger(org.slf4j.Logger) StackViewService(com.sequenceiq.cloudbreak.service.stack.StackViewService) AdjustmentTypeWithThreshold(com.sequenceiq.common.api.adjustment.AdjustmentTypeWithThreshold) FlowEventChainFactory(com.sequenceiq.flow.core.chain.FlowEventChainFactory) ConcurrentLinkedDeque(java.util.concurrent.ConcurrentLinkedDeque) InstanceGroupType(com.sequenceiq.common.api.type.InstanceGroupType) Component(org.springframework.stereotype.Component) ScalingType(com.sequenceiq.cloudbreak.common.type.ScalingType) HostGroup(com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) Comparator(java.util.Comparator) Collections(java.util.Collections) STACK_DOWNSCALE_EVENT(com.sequenceiq.cloudbreak.core.flow2.stack.downscale.StackDownscaleEvent.STACK_DOWNSCALE_EVENT) StackAndClusterUpscaleTriggerEvent(com.sequenceiq.cloudbreak.core.flow2.event.StackAndClusterUpscaleTriggerEvent) AdjustmentTypeWithThreshold(com.sequenceiq.common.api.adjustment.AdjustmentTypeWithThreshold) InstanceGroupView(com.sequenceiq.cloudbreak.domain.view.InstanceGroupView)

Aggregations

AdjustmentTypeWithThreshold (com.sequenceiq.common.api.adjustment.AdjustmentTypeWithThreshold)41 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)22 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)20 Group (com.sequenceiq.cloudbreak.cloud.model.Group)20 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)18 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)15 ArrayList (java.util.ArrayList)15 Test (org.junit.Test)14 Test (org.junit.jupiter.api.Test)14 CloudConnectorException (com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException)12 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)12 List (java.util.List)12 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)11 InstanceAuthentication (com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication)11 Set (java.util.Set)10 Collectors (java.util.stream.Collectors)10 QuotaExceededException (com.sequenceiq.cloudbreak.cloud.exception.QuotaExceededException)9 CloudResourceStatus (com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus)9 AdjustmentType (com.sequenceiq.common.api.type.AdjustmentType)9 Inject (javax.inject.Inject)9