Search in sources :

Example 1 with AdjustmentTypeWithThreshold

use of com.sequenceiq.common.api.adjustment.AdjustmentTypeWithThreshold in project cloudbreak by hortonworks.

the class StackUpscaleActions method addInstances.

@Bean(name = "ADD_INSTANCES_STATE")
public Action<?, ?> addInstances() {
    return new AbstractStackUpscaleAction<>(UpscaleStackValidationResult.class) {

        @Override
        protected void doExecute(StackScalingFlowContext context, UpscaleStackValidationResult payload, Map<Object, Object> variables) {
            sendEvent(context);
        }

        @Override
        protected Selectable createRequest(StackScalingFlowContext context) {
            Map<String, Integer> hostGroupWithInstanceCountToCreate = getHostGroupsWithInstanceCountToCreate(context);
            Stack updatedStack = instanceMetaDataService.saveInstanceAndGetUpdatedStack(context.getStack(), hostGroupWithInstanceCountToCreate, context.getHostgroupWithHostnames(), true, context.isRepair(), context.getStackNetworkScaleDetails());
            List<CloudResource> resources = context.getStack().getResources().stream().map(r -> cloudResourceConverter.convert(r)).collect(Collectors.toList());
            CloudStack updatedCloudStack = cloudStackConverter.convert(updatedStack);
            AdjustmentTypeWithThreshold adjustmentTypeWithThreshold = context.getAdjustmentTypeWithThreshold();
            if (adjustmentTypeWithThreshold == null) {
                Integer exactNumber = hostGroupWithInstanceCountToCreate.values().stream().reduce(0, Integer::sum);
                adjustmentTypeWithThreshold = new AdjustmentTypeWithThreshold(AdjustmentType.EXACT, exactNumber.longValue());
            }
            LOGGER.info("Adjustment type with threshold for upscale request: {}", adjustmentTypeWithThreshold);
            return new UpscaleStackRequest<UpscaleStackResult>(context.getCloudContext(), context.getCloudCredential(), updatedCloudStack, resources, adjustmentTypeWithThreshold);
        }
    };
}
Also used : Action(org.springframework.statemachine.action.Action) StackScaleTriggerEvent(com.sequenceiq.cloudbreak.core.flow2.event.StackScaleTriggerEvent) LoggerFactory(org.slf4j.LoggerFactory) StackToCloudStackConverter(com.sequenceiq.cloudbreak.converter.spi.StackToCloudStackConverter) EventSelectorUtil(com.sequenceiq.flow.event.EventSelectorUtil) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) InstanceGroupService(com.sequenceiq.cloudbreak.service.stack.InstanceGroupService) InstanceMetaDataToCloudInstanceConverter(com.sequenceiq.cloudbreak.converter.spi.InstanceMetaDataToCloudInstanceConverter) Map(java.util.Map) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) StackScalingFlowContext(com.sequenceiq.cloudbreak.core.flow2.stack.downscale.StackScalingFlowContext) BootstrapNewNodesResult(com.sequenceiq.cloudbreak.reactor.api.event.resource.BootstrapNewNodesResult) UpscaleStackRequest(com.sequenceiq.cloudbreak.reactor.api.event.stack.UpscaleStackRequest) AbstractStackFailureAction(com.sequenceiq.cloudbreak.core.flow2.stack.AbstractStackFailureAction) UpscaleStackValidationRequest(com.sequenceiq.cloudbreak.cloud.event.resource.UpscaleStackValidationRequest) Collection(java.util.Collection) StackFailureContext(com.sequenceiq.cloudbreak.core.flow2.stack.StackFailureContext) Set(java.util.Set) HOST_GROUP_WITH_HOSTNAMES(com.sequenceiq.cloudbreak.core.flow2.stack.upscale.AbstractStackUpscaleAction.HOST_GROUP_WITH_HOSTNAMES) Collectors(java.util.stream.Collectors) UpscaleStackValidationResult(com.sequenceiq.cloudbreak.cloud.event.resource.UpscaleStackValidationResult) Configuration(org.springframework.context.annotation.Configuration) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) AdjustmentType(com.sequenceiq.common.api.type.AdjustmentType) List(java.util.List) UpdateDomainDnsResolverResult(com.sequenceiq.cloudbreak.reactor.api.event.stack.UpdateDomainDnsResolverResult) TransactionExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException) ExtendHostMetadataRequest(com.sequenceiq.cloudbreak.reactor.api.event.resource.ExtendHostMetadataRequest) Optional(java.util.Optional) StackCreationEvent(com.sequenceiq.cloudbreak.core.flow2.stack.provision.StackCreationEvent) BootstrapNewNodesRequest(com.sequenceiq.cloudbreak.reactor.api.event.resource.BootstrapNewNodesRequest) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) StackService(com.sequenceiq.cloudbreak.service.stack.StackService) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) HashMap(java.util.HashMap) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) StackFailureEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackFailureEvent) ClusterPublicEndpointManagementService(com.sequenceiq.cloudbreak.service.publicendpoint.ClusterPublicEndpointManagementService) HOST_GROUP_WITH_ADJUSTMENT(com.sequenceiq.cloudbreak.core.flow2.stack.upscale.AbstractStackUpscaleAction.HOST_GROUP_WITH_ADJUSTMENT) StackEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackEvent) CleanupFreeIpaEvent(com.sequenceiq.cloudbreak.reactor.api.event.stack.CleanupFreeIpaEvent) HashSet(java.util.HashSet) Inject(javax.inject.Inject) ResourceToCloudResourceConverter(com.sequenceiq.cloudbreak.converter.spi.ResourceToCloudResourceConverter) ExtendHostMetadataResult(com.sequenceiq.cloudbreak.reactor.api.event.resource.ExtendHostMetadataResult) UpscaleStackResult(com.sequenceiq.cloudbreak.reactor.api.event.stack.UpscaleStackResult) InstanceMetaDataService(com.sequenceiq.cloudbreak.service.stack.InstanceMetaDataService) GetSSHFingerprintsResult(com.sequenceiq.cloudbreak.cloud.event.instance.GetSSHFingerprintsResult) UpdateDomainDnsResolverRequest(com.sequenceiq.cloudbreak.reactor.api.event.stack.UpdateDomainDnsResolverRequest) Logger(org.slf4j.Logger) GetSSHFingerprintsRequest(com.sequenceiq.cloudbreak.cloud.event.instance.GetSSHFingerprintsRequest) CollectMetadataResult(com.sequenceiq.cloudbreak.cloud.event.instance.CollectMetadataResult) CollectMetadataRequest(com.sequenceiq.cloudbreak.cloud.event.instance.CollectMetadataRequest) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) AdjustmentTypeWithThreshold(com.sequenceiq.common.api.adjustment.AdjustmentTypeWithThreshold) EnvironmentClientService(com.sequenceiq.cloudbreak.service.environment.EnvironmentClientService) ClusterProxyEnablementService(com.sequenceiq.cloudbreak.clusterproxy.ClusterProxyEnablementService) ClusterProxyReRegistrationRequest(com.sequenceiq.cloudbreak.reactor.api.event.orchestration.ClusterProxyReRegistrationRequest) InstanceGroupType(com.sequenceiq.common.api.type.InstanceGroupType) InstanceStatus(com.sequenceiq.cloudbreak.cloud.model.InstanceStatus) MetricType(com.sequenceiq.cloudbreak.service.metrics.MetricType) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) Bean(org.springframework.context.annotation.Bean) AdjustmentTypeWithThreshold(com.sequenceiq.common.api.adjustment.AdjustmentTypeWithThreshold) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) StackScalingFlowContext(com.sequenceiq.cloudbreak.core.flow2.stack.downscale.StackScalingFlowContext) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) UpscaleStackRequest(com.sequenceiq.cloudbreak.reactor.api.event.stack.UpscaleStackRequest) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) UpscaleStackValidationResult(com.sequenceiq.cloudbreak.cloud.event.resource.UpscaleStackValidationResult) Map(java.util.Map) HashMap(java.util.HashMap) Bean(org.springframework.context.annotation.Bean)

Example 2 with AdjustmentTypeWithThreshold

use of com.sequenceiq.common.api.adjustment.AdjustmentTypeWithThreshold in project cloudbreak by hortonworks.

the class StackUpscaleService method upscale.

public List<CloudResourceStatus> upscale(AuthenticatedContext ac, UpscaleStackRequest<UpscaleStackResult> request, CloudConnector<?> connector) throws QuotaExceededException {
    CloudStack cloudStack = request.getCloudStack();
    AdjustmentTypeWithThreshold adjustmentTypeWithThreshold = request.getAdjustmentWithThreshold();
    try {
        return connector.resources().upscale(ac, cloudStack, request.getResourceList(), adjustmentTypeWithThreshold);
    } catch (QuotaExceededException quotaExceededException) {
        return handleQuotaExceptionAndRetryUpscale(request, connector, ac, cloudStack, adjustmentTypeWithThreshold, quotaExceededException);
    }
}
Also used : QuotaExceededException(com.sequenceiq.cloudbreak.cloud.exception.QuotaExceededException) AdjustmentTypeWithThreshold(com.sequenceiq.common.api.adjustment.AdjustmentTypeWithThreshold) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack)

Example 3 with AdjustmentTypeWithThreshold

use of com.sequenceiq.common.api.adjustment.AdjustmentTypeWithThreshold in project cloudbreak by hortonworks.

the class GcpResourceConnectorTest method testUpscaleWhenEverythingIsFine.

@Test
public void testUpscaleWhenEverythingIsFine() throws QuotaExceededException {
    AuthenticatedContext authenticatedContext = mock(AuthenticatedContext.class);
    CloudStack cloudStack = mock(CloudStack.class);
    Network network = mock(Network.class);
    CloudContext cloudContext = mock(CloudContext.class);
    ResourceBuilderContext resourceBuilderContext = mock(ResourceBuilderContext.class);
    ResourceContextBuilder resourceContextBuilder = mock(ResourceContextBuilder.class);
    List<CloudResource> cloudResourceList = List.of(cloudResource("test-5", GCP_ATTACHED_DISKSET));
    when(authenticatedContext.getCloudContext()).thenReturn(cloudContext);
    when(cloudStack.getNetwork()).thenReturn(network);
    when(cloudContext.getPlatform()).thenReturn(platform("GCP"));
    when(cloudContext.getVariant()).thenReturn(GcpConstants.GCP_VARIANT);
    when(contextBuilders.get(any(Platform.class))).thenReturn(resourceContextBuilder);
    when(resourceContextBuilder.contextInit(any(CloudContext.class), any(AuthenticatedContext.class), any(Network.class), anyList(), anyBoolean())).thenReturn(resourceBuilderContext);
    when(networkResourceService.getNetworkResources(any(Variant.class), anyList())).thenReturn(new ArrayList<>());
    doNothing().when(resourceBuilderContext).addNetworkResources(anyCollection());
    when(groupResourceService.getGroupResources(any(Variant.class), anyCollection())).thenReturn(List.of(cloudResource("test-1", GCP_INSTANCE)));
    Group master = group("master");
    master.getInstances().get(0).putParameter(CloudInstance.FQDN, "fqdn");
    when(cloudStack.getGroups()).thenReturn(List.of(master));
    doNothing().when(resourceBuilderContext).addComputeResources(anyLong(), anyList());
    when(computeResourceService.buildResourcesForUpscale(any(ResourceBuilderContext.class), any(AuthenticatedContext.class), any(CloudStack.class), anyCollection(), any())).thenReturn(List.of());
    underTest.upscale(authenticatedContext, cloudStack, cloudResourceList, new AdjustmentTypeWithThreshold(AdjustmentType.EXACT, 0L));
    verify(contextBuilders, times(1)).get(any(Platform.class));
    verify(networkResourceService, times(1)).getNetworkResources(any(Variant.class), anyList());
    verify(groupResourceService, times(1)).getGroupResources(any(Variant.class), anyList());
    verify(resourceBuilderContext, times(1)).addComputeResources(anyLong(), anyList());
    verify(computeResourceService, times(1)).buildResourcesForUpscale(any(ResourceBuilderContext.class), any(AuthenticatedContext.class), any(CloudStack.class), anyCollection(), any());
}
Also used : Group(com.sequenceiq.cloudbreak.cloud.model.Group) Platform(com.sequenceiq.cloudbreak.cloud.model.Platform) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) AdjustmentTypeWithThreshold(com.sequenceiq.common.api.adjustment.AdjustmentTypeWithThreshold) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) ResourceContextBuilder(com.sequenceiq.cloudbreak.cloud.template.ResourceContextBuilder) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) Variant(com.sequenceiq.cloudbreak.cloud.model.Variant) GroupNetwork(com.sequenceiq.cloudbreak.cloud.model.GroupNetwork) Network(com.sequenceiq.cloudbreak.cloud.model.Network) ResourceBuilderContext(com.sequenceiq.cloudbreak.cloud.template.context.ResourceBuilderContext) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) Test(org.junit.jupiter.api.Test)

Example 4 with AdjustmentTypeWithThreshold

use of com.sequenceiq.common.api.adjustment.AdjustmentTypeWithThreshold in project cloudbreak by hortonworks.

the class StackUpscaleActionsTest method prevalidateTestDoExecuteWhenScalingNeededAndAllowed.

// Note: this implicitly tests getPrevalidateAction().createRequest() as well.
@Test
void prevalidateTestDoExecuteWhenScalingNeededAndAllowed() throws Exception {
    when(cloudContext.getId()).thenReturn(STACK_ID);
    AdjustmentTypeWithThreshold adjustmentTypeWithThreshold = new AdjustmentTypeWithThreshold(AdjustmentType.EXACT, ADJUSTMENT.longValue());
    UpdateDomainDnsResolverResult payload = new UpdateDomainDnsResolverResult(STACK_ID);
    when(stackUpscaleService.getInstanceCountToCreate(stack, INSTANCE_GROUP_NAME, ADJUSTMENT, false)).thenReturn(ADJUSTMENT);
    Stack updatedStack = mock(Stack.class);
    when(instanceMetaDataService.saveInstanceAndGetUpdatedStack(stack, Map.of(INSTANCE_GROUP_NAME, 3), Map.of(), false, false, context.getStackNetworkScaleDetails())).thenReturn(updatedStack);
    CloudStack convertedCloudStack = mock(CloudStack.class);
    when(cloudStackConverter.convert(updatedStack)).thenReturn(convertedCloudStack);
    when(reactorEventFactory.createEvent(anyMap(), isNotNull())).thenReturn(event);
    new AbstractActionTestSupport<>(getPrevalidateAction()).doExecute(context, payload, createVariables(Map.of(INSTANCE_GROUP_NAME, ADJUSTMENT), Map.of(), NetworkScaleDetails.getEmpty(), adjustmentTypeWithThreshold, VARIANT));
    verify(stackUpscaleService).addInstanceFireEventAndLog(stack, Map.of(INSTANCE_GROUP_NAME, ADJUSTMENT), adjustmentTypeWithThreshold);
    verify(stackUpscaleService).startAddInstances(stack, Map.of(INSTANCE_GROUP_NAME, ADJUSTMENT));
    verify(reactorEventFactory).createEvent(anyMap(), payloadArgumentCaptor.capture());
    verify(eventBus).notify("UPSCALESTACKVALIDATIONREQUEST", event);
    Object responsePayload = payloadArgumentCaptor.getValue();
    assertThat(responsePayload).isInstanceOf(UpscaleStackValidationRequest.class);
    UpscaleStackValidationRequest<UpscaleStackValidationResult> upscaleStackValidationRequest = (UpscaleStackValidationRequest<UpscaleStackValidationResult>) responsePayload;
    assertThat(upscaleStackValidationRequest.getResourceId()).isEqualTo(STACK_ID);
    assertThat(upscaleStackValidationRequest.getCloudContext()).isSameAs(cloudContext);
    assertThat(upscaleStackValidationRequest.getCloudStack()).isSameAs(convertedCloudStack);
    assertThat(upscaleStackValidationRequest.getCloudCredential()).isSameAs(cloudCredential);
}
Also used : AdjustmentTypeWithThreshold(com.sequenceiq.common.api.adjustment.AdjustmentTypeWithThreshold) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) UpscaleStackValidationResult(com.sequenceiq.cloudbreak.cloud.event.resource.UpscaleStackValidationResult) UpdateDomainDnsResolverResult(com.sequenceiq.cloudbreak.reactor.api.event.stack.UpdateDomainDnsResolverResult) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) UpscaleStackValidationRequest(com.sequenceiq.cloudbreak.cloud.event.resource.UpscaleStackValidationRequest) Test(org.junit.jupiter.api.Test)

Example 5 with AdjustmentTypeWithThreshold

use of com.sequenceiq.common.api.adjustment.AdjustmentTypeWithThreshold in project cloudbreak by hortonworks.

the class StackUpscaleActionsTest method prevalidateTestDoExecuteWhenScalingNeededAndNotAllowed.

@Test
void prevalidateTestDoExecuteWhenScalingNeededAndNotAllowed() throws Exception {
    AdjustmentTypeWithThreshold adjustmentTypeWithThreshold = new AdjustmentTypeWithThreshold(AdjustmentType.EXACT, ADJUSTMENT.longValue());
    UpdateDomainDnsResolverResult payload = new UpdateDomainDnsResolverResult(STACK_ID);
    when(stackUpscaleService.getInstanceCountToCreate(stack, INSTANCE_GROUP_NAME, ADJUSTMENT, 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), Map.of(), NetworkScaleDetails.getEmpty(), adjustmentTypeWithThreshold, VARIANT));
    verify(stackUpscaleService).addInstanceFireEventAndLog(stack, Map.of(INSTANCE_GROUP_NAME, ADJUSTMENT), adjustmentTypeWithThreshold);
    verifyEventForExtendMetadata(resourceStatuses);
}
Also used : CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) AdjustmentTypeWithThreshold(com.sequenceiq.common.api.adjustment.AdjustmentTypeWithThreshold) UpdateDomainDnsResolverResult(com.sequenceiq.cloudbreak.reactor.api.event.stack.UpdateDomainDnsResolverResult) Test(org.junit.jupiter.api.Test)

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