Search in sources :

Example 1 with AutoscaleStack

use of com.sequenceiq.cloudbreak.domain.projection.AutoscaleStack in project cloudbreak by hortonworks.

the class StackService method getAllForAutoscale.

public Set<AutoscaleStackV4Response> getAllForAutoscale() {
    try {
        return transactionService.required(() -> {
            Set<AutoscaleStack> aliveOnes = stackRepository.findAliveOnesWithClusterManager();
            Set<AutoscaleStack> aliveNotUnderDeletion = Optional.ofNullable(aliveOnes).orElse(Set.of()).stream().filter(stack -> !DELETE_IN_PROGRESS.equals(stack.getStackStatus())).collect(Collectors.toSet());
            return aliveNotUnderDeletion.stream().map(a -> autoscaleStackToAutoscaleStackResponseJsonConverter.convert(a)).collect(Collectors.toSet());
        });
    } catch (TransactionExecutionException e) {
        throw new TransactionRuntimeExecutionException(e);
    }
}
Also used : CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) FluentClusterType(com.sequenceiq.cloudbreak.telemetry.fluent.FluentClusterType) StackToStackV4RequestConverter(com.sequenceiq.cloudbreak.converter.v4.stacks.cli.StackToStackV4RequestConverter) GetPlatformTemplateRequest(com.sequenceiq.cloudbreak.cloud.event.platform.GetPlatformTemplateRequest) ComponentConfigProviderService(com.sequenceiq.cloudbreak.service.ComponentConfigProviderService) Measure(com.sequenceiq.cloudbreak.aspect.Measure) TransactionRuntimeExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionRuntimeExecutionException) StringUtils(org.apache.commons.lang3.StringUtils) Orchestrator(com.sequenceiq.cloudbreak.domain.Orchestrator) ThreadBasedUserCrnProvider(com.sequenceiq.cloudbreak.auth.ThreadBasedUserCrnProvider) StackClusterStatusView(com.sequenceiq.cloudbreak.domain.projection.StackClusterStatusView) Duration(java.time.Duration) Map(java.util.Map) EnumSet(java.util.EnumSet) Component(com.sequenceiq.cloudbreak.domain.stack.Component) AccountTagClientService(com.sequenceiq.cloudbreak.service.environment.tag.AccountTagClientService) StackIdViewToStackResponseConverter(com.sequenceiq.cloudbreak.converter.stack.StackIdViewToStackResponseConverter) Set(java.util.Set) JobResource(com.sequenceiq.cloudbreak.quartz.model.JobResource) Crn(com.sequenceiq.cloudbreak.auth.crn.Crn) CloudbreakOrchestratorException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorException) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) StackRepository(com.sequenceiq.cloudbreak.repository.StackRepository) LocalDateTime(java.time.LocalDateTime) Supplier(java.util.function.Supplier) Value(org.springframework.beans.factory.annotation.Value) Strings(com.google.common.base.Strings) CrnResourceDescriptor(com.sequenceiq.cloudbreak.auth.crn.CrnResourceDescriptor) AccountTagValidationFailed(com.sequenceiq.cloudbreak.tag.AccountTagValidationFailed) StatedImage(com.sequenceiq.cloudbreak.service.image.StatedImage) Service(org.springframework.stereotype.Service) OrchestrationCredential(com.sequenceiq.cloudbreak.orchestrator.model.OrchestrationCredential) StackResponseDecorator(com.sequenceiq.cloudbreak.service.decorator.StackResponseDecorator) CDH_PRODUCT_DETAILS(com.sequenceiq.cloudbreak.common.type.ComponentType.CDH_PRODUCT_DETAILS) CloudConstants(com.sequenceiq.cloudbreak.common.type.CloudConstants) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) AutoscaleStack(com.sequenceiq.cloudbreak.domain.projection.AutoscaleStack) StackTtlView(com.sequenceiq.cloudbreak.domain.projection.StackTtlView) IOException(java.io.IOException) Workspace(com.sequenceiq.cloudbreak.workspace.model.Workspace) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) SdxClientService(com.sequenceiq.cloudbreak.service.datalake.SdxClientService) CostTagging(com.sequenceiq.cloudbreak.tag.CostTagging) NetworkConfigurationValidator(com.sequenceiq.cloudbreak.controller.validation.network.NetworkConfigurationValidator) StackToStackV4ResponseConverter(com.sequenceiq.cloudbreak.converter.v4.stacks.StackToStackV4ResponseConverter) StackIdView(com.sequenceiq.cloudbreak.domain.projection.StackIdView) CloudPlatformVariant(com.sequenceiq.cloudbreak.cloud.model.CloudPlatformVariant) StackStatus(com.sequenceiq.cloudbreak.domain.stack.StackStatus) StackView(com.sequenceiq.cloudbreak.domain.view.StackView) ComponentType(com.sequenceiq.cloudbreak.common.type.ComponentType) EntitlementService(com.sequenceiq.cloudbreak.auth.altus.EntitlementService) CDPTagGenerationRequest(com.sequenceiq.cloudbreak.tag.request.CDPTagGenerationRequest) AutoscaleStackToAutoscaleStackResponseJsonConverter(com.sequenceiq.cloudbreak.converter.stack.AutoscaleStackToAutoscaleStackResponseJsonConverter) LoggerFactory(org.slf4j.LoggerFactory) AccountTelemetryClientService(com.sequenceiq.cloudbreak.service.environment.telemetry.AccountTelemetryClientService) ServiceProviderConnectorAdapter(com.sequenceiq.cloudbreak.service.stack.connector.adapter.ServiceProviderConnectorAdapter) PlatformParametersConsts(com.sequenceiq.cloudbreak.cloud.PlatformParametersConsts) ImageService(com.sequenceiq.cloudbreak.service.image.ImageService) ClouderaManagerProduct(com.sequenceiq.cloudbreak.cloud.model.ClouderaManagerProduct) TransactionService(com.sequenceiq.cloudbreak.common.service.TransactionService) CloudbreakImageCatalogException(com.sequenceiq.cloudbreak.core.CloudbreakImageCatalogException) OpenSshPublicKeyValidator(com.sequenceiq.cloudbreak.service.environment.credential.OpenSshPublicKeyValidator) Telemetry(com.sequenceiq.common.api.telemetry.model.Telemetry) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) StackV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackV4Response) Tunnel(com.sequenceiq.common.api.type.Tunnel) ResourceWithId(com.sequenceiq.authorization.service.list.ResourceWithId) PayloadContext(com.sequenceiq.cloudbreak.common.event.PayloadContext) StackStatusView(com.sequenceiq.cloudbreak.domain.projection.StackStatusView) Timestamp(java.sql.Timestamp) Collection(java.util.Collection) StackTemplate(com.sequenceiq.cloudbreak.cloud.model.StackTemplate) InstanceStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus) StackTags(com.sequenceiq.cloudbreak.cloud.model.StackTags) Status(com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status) WorkspaceService(com.sequenceiq.cloudbreak.service.workspace.WorkspaceService) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) StackCrnView(com.sequenceiq.cloudbreak.domain.projection.StackCrnView) Objects(java.util.Objects) Json(com.sequenceiq.cloudbreak.common.json.Json) List(java.util.List) TransactionExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException) Optional(java.util.Optional) OrchestratorService(com.sequenceiq.cloudbreak.service.orchestrator.OrchestratorService) Network(com.sequenceiq.cloudbreak.domain.Network) ContainerOrchestratorResolver(com.sequenceiq.cloudbreak.core.bootstrap.service.container.ContainerOrchestratorResolver) AutoscaleStackV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.AutoscaleStackV4Response) MDCBuilder(com.sequenceiq.cloudbreak.logger.MDCBuilder) HashMap(java.util.HashMap) Image(com.sequenceiq.cloudbreak.cloud.model.Image) StackPlatformVariantView(com.sequenceiq.cloudbreak.domain.projection.StackPlatformVariantView) StackStatusService(com.sequenceiq.cloudbreak.service.stackstatus.StackStatusService) HashSet(java.util.HashSet) Inject(javax.inject.Inject) ResourceService(com.sequenceiq.cloudbreak.service.resource.ResourceService) AuthorizationResourceNamesProvider(com.sequenceiq.authorization.service.AuthorizationResourceNamesProvider) CloudStorageFolderResolverService(com.sequenceiq.cloudbreak.telemetry.fluent.cloud.CloudStorageFolderResolverService) CloudbreakApiException(com.sequenceiq.cloudbreak.exception.CloudbreakApiException) NotFoundException.notFound(com.sequenceiq.cloudbreak.common.exception.NotFoundException.notFound) Logger(org.slf4j.Logger) ContainerOrchestrator(com.sequenceiq.cloudbreak.orchestrator.container.ContainerOrchestrator) CloudbreakDetails(com.sequenceiq.cloudbreak.cloud.model.CloudbreakDetails) Benchmark.measure(com.sequenceiq.cloudbreak.util.Benchmark.measure) PayloadContextProvider(com.sequenceiq.flow.core.PayloadContextProvider) RegionAwareCrnGenerator(com.sequenceiq.cloudbreak.auth.crn.RegionAwareCrnGenerator) StackValidation(com.sequenceiq.cloudbreak.domain.stack.StackValidation) ShowTerminatedClustersAfterConfig(com.sequenceiq.cloudbreak.service.stack.ShowTerminatedClusterConfigService.ShowTerminatedClustersAfterConfig) NameOrCrn(com.sequenceiq.cloudbreak.api.endpoint.v4.dto.NameOrCrn) CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) User(com.sequenceiq.cloudbreak.workspace.model.User) StackV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request) ResourceBasicView(com.sequenceiq.cloudbreak.common.dal.ResourceBasicView) DELETE_IN_PROGRESS(com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status.DELETE_IN_PROGRESS) ResourceIdProvider(com.sequenceiq.flow.core.ResourceIdProvider) StackType(com.sequenceiq.cloudbreak.api.endpoint.v4.common.StackType) VisibleForTesting(com.google.common.annotations.VisibleForTesting) StringUtils.substringBefore(org.apache.commons.lang3.StringUtils.substringBefore) Collections(java.util.Collections) StackListItem(com.sequenceiq.cloudbreak.domain.projection.StackListItem) TransactionExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException) AutoscaleStack(com.sequenceiq.cloudbreak.domain.projection.AutoscaleStack) TransactionRuntimeExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionRuntimeExecutionException)

Example 2 with AutoscaleStack

use of com.sequenceiq.cloudbreak.domain.projection.AutoscaleStack in project cloudbreak by hortonworks.

the class StackServiceTest method testGetAllForAutoscaleWithDeleteInProgressStack.

@Test
public void testGetAllForAutoscaleWithDeleteInProgressStack() throws TransactionExecutionException {
    when(transactionService.required(any(Supplier.class))).thenAnswer(invocation -> {
        Supplier<AutoscaleStackV4Response> callback = invocation.getArgument(0);
        return callback.get();
    });
    AutoscaleStack availableStack = mock(AutoscaleStack.class);
    when(availableStack.getStackStatus()).thenReturn(Status.AVAILABLE);
    AutoscaleStack deleteInProgressStack = mock(AutoscaleStack.class);
    when(deleteInProgressStack.getStackStatus()).thenReturn(Status.AVAILABLE);
    when(stackRepository.findAliveOnesWithClusterManager()).thenReturn(Set.of(availableStack, deleteInProgressStack));
    ArgumentCaptor<AutoscaleStack> aliveStackCaptor = ArgumentCaptor.forClass(AutoscaleStack.class);
    AutoscaleStackV4Response autoscaleStackResponse = new AutoscaleStackV4Response();
    when(autoscaleStackToAutoscaleStackResponseJsonConverter.convert(aliveStackCaptor.capture())).thenReturn(autoscaleStackResponse);
    Set<AutoscaleStackV4Response> allForAutoscale = underTest.getAllForAutoscale();
    assertNotNull(allForAutoscale);
    assertEquals(autoscaleStackResponse, allForAutoscale.iterator().next());
    AutoscaleStack stackSet = aliveStackCaptor.getValue();
    assertNotNull(stackSet);
    assertEquals(availableStack.getStackStatus(), stackSet.getStackStatus());
}
Also used : AutoscaleStackV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.AutoscaleStackV4Response) Supplier(java.util.function.Supplier) AutoscaleStack(com.sequenceiq.cloudbreak.domain.projection.AutoscaleStack) Test(org.junit.Test)

Example 3 with AutoscaleStack

use of com.sequenceiq.cloudbreak.domain.projection.AutoscaleStack in project cloudbreak by hortonworks.

the class StackServiceTest method testGetAllForAutoscaleWithAvailableStack.

@Test
public void testGetAllForAutoscaleWithAvailableStack() throws TransactionExecutionException {
    when(transactionService.required(any(Supplier.class))).thenAnswer(invocation -> {
        Supplier<AutoscaleStackV4Response> callback = invocation.getArgument(0);
        return callback.get();
    });
    AutoscaleStack stack = mock(AutoscaleStack.class);
    when(stack.getStackStatus()).thenReturn(Status.AVAILABLE);
    when(stackRepository.findAliveOnesWithClusterManager()).thenReturn(Set.of(stack));
    ArgumentCaptor<AutoscaleStack> aliveStackCaptor = ArgumentCaptor.forClass(AutoscaleStack.class);
    AutoscaleStackV4Response autoscaleStackResponse = new AutoscaleStackV4Response();
    when(autoscaleStackToAutoscaleStackResponseJsonConverter.convert(aliveStackCaptor.capture())).thenReturn(autoscaleStackResponse);
    Set<AutoscaleStackV4Response> allForAutoscale = underTest.getAllForAutoscale();
    assertNotNull(allForAutoscale);
    assertEquals(autoscaleStackResponse, allForAutoscale.iterator().next());
    AutoscaleStack stackSet = aliveStackCaptor.getValue();
    assertNotNull(stackSet);
    assertEquals(stack.getStackStatus(), stackSet.getStackStatus());
}
Also used : AutoscaleStackV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.AutoscaleStackV4Response) Supplier(java.util.function.Supplier) AutoscaleStack(com.sequenceiq.cloudbreak.domain.projection.AutoscaleStack) Test(org.junit.Test)

Aggregations

AutoscaleStackV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.AutoscaleStackV4Response)3 AutoscaleStack (com.sequenceiq.cloudbreak.domain.projection.AutoscaleStack)2 Supplier (java.util.function.Supplier)2 Test (org.junit.Test)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Strings (com.google.common.base.Strings)1 AuthorizationResourceNamesProvider (com.sequenceiq.authorization.service.AuthorizationResourceNamesProvider)1 ResourceWithId (com.sequenceiq.authorization.service.list.ResourceWithId)1 StackType (com.sequenceiq.cloudbreak.api.endpoint.v4.common.StackType)1 Status (com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status)1 DELETE_IN_PROGRESS (com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status.DELETE_IN_PROGRESS)1 NameOrCrn (com.sequenceiq.cloudbreak.api.endpoint.v4.dto.NameOrCrn)1 InstanceStatus (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus)1 StackV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request)1 StackV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackV4Response)1 Measure (com.sequenceiq.cloudbreak.aspect.Measure)1 ThreadBasedUserCrnProvider (com.sequenceiq.cloudbreak.auth.ThreadBasedUserCrnProvider)1 EntitlementService (com.sequenceiq.cloudbreak.auth.altus.EntitlementService)1 Crn (com.sequenceiq.cloudbreak.auth.crn.Crn)1 CrnResourceDescriptor (com.sequenceiq.cloudbreak.auth.crn.CrnResourceDescriptor)1