Search in sources :

Example 1 with ShowTerminatedClustersAfterConfig

use of com.sequenceiq.cloudbreak.service.stack.ShowTerminatedClusterConfigService.ShowTerminatedClustersAfterConfig in project cloudbreak by hortonworks.

the class StackService method getByNameInWorkspaceWithEntries.

public StackV4Response getByNameInWorkspaceWithEntries(String name, Long workspaceId, Set<String> entries, User user, StackType stackType) {
    try {
        return transactionService.required(() -> {
            Workspace workspace = workspaceService.get(workspaceId, user);
            ShowTerminatedClustersAfterConfig showTerminatedClustersAfterConfig = showTerminatedClusterConfigService.get();
            Optional<Stack> stack = findByNameAndWorkspaceIdWithLists(name, workspace.getId(), stackType, showTerminatedClustersAfterConfig);
            if (stack.isEmpty()) {
                throw new NotFoundException(format(STACK_NOT_FOUND_BY_NAME_EXCEPTION_MESSAGE, name));
            }
            StackV4Response stackResponse = stackToStackV4ResponseConverter.convert(stack.get());
            stackResponse = stackResponseDecorator.decorate(stackResponse, stack.get(), entries);
            return stackResponse;
        });
    } catch (TransactionExecutionException e) {
        throw new TransactionRuntimeExecutionException(e);
    }
}
Also used : ShowTerminatedClustersAfterConfig(com.sequenceiq.cloudbreak.service.stack.ShowTerminatedClusterConfigService.ShowTerminatedClustersAfterConfig) StackV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackV4Response) AutoscaleStackV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.AutoscaleStackV4Response) TransactionExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) Workspace(com.sequenceiq.cloudbreak.workspace.model.Workspace) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) AutoscaleStack(com.sequenceiq.cloudbreak.domain.projection.AutoscaleStack) TransactionRuntimeExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionRuntimeExecutionException)

Example 2 with ShowTerminatedClustersAfterConfig

use of com.sequenceiq.cloudbreak.service.stack.ShowTerminatedClusterConfigService.ShowTerminatedClustersAfterConfig in project cloudbreak by hortonworks.

the class StackService method getStackRequestByNameOrCrnInWorkspaceId.

public StackV4Request getStackRequestByNameOrCrnInWorkspaceId(NameOrCrn nameOrCrn, Long workspaceId) {
    try {
        return transactionService.required(() -> {
            ShowTerminatedClustersAfterConfig showTerminatedClustersAfterConfig = showTerminatedClusterConfigService.get();
            Optional<Stack> stack = findByNameOrCrnAndWorkspaceIdWithLists(nameOrCrn, workspaceId);
            if (stack.isEmpty()) {
                throw new NotFoundException(format(STACK_NOT_FOUND_BY_NAME_OR_CRN_EXCEPTION_MESSAGE, nameOrCrn));
            }
            StackV4Request request = stackToStackV4RequestConverter.convert(stack.get());
            request.getCluster().setName(null);
            request.setName(stack.get().getName());
            return request;
        });
    } catch (TransactionExecutionException e) {
        throw new TransactionRuntimeExecutionException(e);
    }
}
Also used : ShowTerminatedClustersAfterConfig(com.sequenceiq.cloudbreak.service.stack.ShowTerminatedClusterConfigService.ShowTerminatedClustersAfterConfig) StackV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request) TransactionExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) AutoscaleStack(com.sequenceiq.cloudbreak.domain.projection.AutoscaleStack) TransactionRuntimeExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionRuntimeExecutionException)

Example 3 with ShowTerminatedClustersAfterConfig

use of com.sequenceiq.cloudbreak.service.stack.ShowTerminatedClusterConfigService.ShowTerminatedClustersAfterConfig in project cloudbreak by hortonworks.

the class ShowTerminatedClustersConfigServiceTest method testGetWhenUserHasPreference.

@Test
public void testGetWhenUserHasPreference() {
    init(false);
    when(clock.nowMinus(DEFAULT_DURATION)).thenReturn(Instant.ofEpochSecond(0));
    ShowTerminatedClustersAfterConfig showTerminatedClustersConfig = underTest.get();
    assertFalse(showTerminatedClustersConfig.isActive());
    assertEquals(Long.valueOf(0), showTerminatedClustersConfig.showAfterMillisecs());
    verify(userProfileService, times(0)).getOrCreateForLoggedInUser();
}
Also used : ShowTerminatedClustersAfterConfig(com.sequenceiq.cloudbreak.service.stack.ShowTerminatedClusterConfigService.ShowTerminatedClustersAfterConfig) Test(org.junit.Test)

Example 4 with ShowTerminatedClustersAfterConfig

use of com.sequenceiq.cloudbreak.service.stack.ShowTerminatedClusterConfigService.ShowTerminatedClustersAfterConfig in project cloudbreak by hortonworks.

the class ShowTerminatedClustersConfigServiceTest method testGetWhenUserHasNoPreference.

@Test
public void testGetWhenUserHasNoPreference() {
    init(false);
    when(userProfileService.getOrCreateForLoggedInUser()).thenReturn(new UserProfileBuilder().withNullClusterPrefs().build());
    when(clock.nowMinus(any())).thenReturn(Instant.ofEpochSecond(0));
    ShowTerminatedClustersAfterConfig showTerminatedClustersAfterConfig = underTest.get();
    assertFalse(showTerminatedClustersAfterConfig.isActive());
    assertEquals(0L, showTerminatedClustersAfterConfig.showAfterMillisecs().longValue());
    verify(clock).nowMinus(any());
    verify(userProfileService, times(0)).getOrCreateForLoggedInUser();
}
Also used : ShowTerminatedClustersAfterConfig(com.sequenceiq.cloudbreak.service.stack.ShowTerminatedClusterConfigService.ShowTerminatedClustersAfterConfig) Test(org.junit.Test)

Example 5 with ShowTerminatedClustersAfterConfig

use of com.sequenceiq.cloudbreak.service.stack.ShowTerminatedClusterConfigService.ShowTerminatedClustersAfterConfig in project cloudbreak by hortonworks.

the class StackService method getByCrnInWorkspaceWithEntries.

public StackV4Response getByCrnInWorkspaceWithEntries(String crn, Long workspaceId, Set<String> entries, User user, StackType stackType) {
    try {
        return transactionService.required(() -> {
            Workspace workspace = workspaceService.get(workspaceId, user);
            ShowTerminatedClustersAfterConfig showTerminatedClustersAfterConfig = showTerminatedClusterConfigService.get();
            Optional<Stack> stack = findByCrnAndWorkspaceIdWithLists(crn, workspace.getId(), stackType, showTerminatedClustersAfterConfig);
            if (stack.isEmpty()) {
                throw new NotFoundException(format("Stack not found by crn '%s'", crn));
            }
            StackV4Response stackResponse = stackToStackV4ResponseConverter.convert(stack.get());
            stackResponse = stackResponseDecorator.decorate(stackResponse, stack.get(), entries);
            return stackResponse;
        });
    } catch (TransactionExecutionException e) {
        throw new TransactionRuntimeExecutionException(e);
    }
}
Also used : ShowTerminatedClustersAfterConfig(com.sequenceiq.cloudbreak.service.stack.ShowTerminatedClusterConfigService.ShowTerminatedClustersAfterConfig) StackV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackV4Response) AutoscaleStackV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.AutoscaleStackV4Response) TransactionExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) Workspace(com.sequenceiq.cloudbreak.workspace.model.Workspace) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) AutoscaleStack(com.sequenceiq.cloudbreak.domain.projection.AutoscaleStack) TransactionRuntimeExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionRuntimeExecutionException)

Aggregations

ShowTerminatedClustersAfterConfig (com.sequenceiq.cloudbreak.service.stack.ShowTerminatedClusterConfigService.ShowTerminatedClustersAfterConfig)5 NotFoundException (com.sequenceiq.cloudbreak.common.exception.NotFoundException)3 TransactionExecutionException (com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException)3 TransactionRuntimeExecutionException (com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionRuntimeExecutionException)3 CloudbreakImageNotFoundException (com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException)3 AutoscaleStack (com.sequenceiq.cloudbreak.domain.projection.AutoscaleStack)3 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)3 AutoscaleStackV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.AutoscaleStackV4Response)2 StackV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackV4Response)2 Workspace (com.sequenceiq.cloudbreak.workspace.model.Workspace)2 Test (org.junit.Test)2 StackV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request)1