Search in sources :

Example 6 with ClusterTemplateView

use of com.sequenceiq.cloudbreak.domain.view.ClusterTemplateView in project cloudbreak by hortonworks.

the class ClusterTemplateViewServiceTest method testWhenFindAllAvailableViewInWorkspaceIsCalledThenItsResultSetShouldBeReturnedWithoutFiltering.

@Test
public void testWhenFindAllAvailableViewInWorkspaceIsCalledThenItsResultSetShouldBeReturnedWithoutFiltering() {
    ClusterTemplateView repositoryResult = new ClusterTemplateView();
    Set<ClusterTemplateView> resultSetFromRepository = Set.of(repositoryResult);
    when(repository.findAllActive(WORKSPACE_ID)).thenReturn(resultSetFromRepository);
    when(internalClusterTemplateValidator.shouldPopulate(repositoryResult, false)).thenReturn(true);
    Set<ClusterTemplateView> result = underTest.findAllActive(WORKSPACE_ID, false);
    assertNotNull(result);
    assertEquals(resultSetFromRepository.size(), result.size());
    assertTrue(resultSetFromRepository.containsAll(result));
    verify(repository, times(1)).findAllActive(anyLong());
    verify(repository, times(1)).findAllActive(WORKSPACE_ID);
}
Also used : ClusterTemplateView(com.sequenceiq.cloudbreak.domain.view.ClusterTemplateView) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 7 with ClusterTemplateView

use of com.sequenceiq.cloudbreak.domain.view.ClusterTemplateView in project cloudbreak by hortonworks.

the class InternalClusterTemplateValidatorTest method internalClusterTemplateValidatorDataWithClusterTemplateViewObject.

@ParameterizedTest(name = "state = {0} internalTenant = {1} expectedShouldPopulate = {2}")
@MethodSource("internalClusterTemplateValidatorData")
public void internalClusterTemplateValidatorDataWithClusterTemplateViewObject(FeatureState state, boolean internalTenant, boolean expectedShouldPopulate) {
    ClusterTemplateView clusterTemplate = new ClusterTemplateView();
    clusterTemplate.setFeatureState(state);
    boolean shouldPopulate = underTest.shouldPopulate(clusterTemplate, internalTenant);
    Assert.assertEquals(expectedShouldPopulate, shouldPopulate);
}
Also used : ClusterTemplateView(com.sequenceiq.cloudbreak.domain.view.ClusterTemplateView) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 8 with ClusterTemplateView

use of com.sequenceiq.cloudbreak.domain.view.ClusterTemplateView in project cloudbreak by hortonworks.

the class BlueprintServiceTest method testPrepareDeletionWhenHasOneClusterDefinitionAndOneCluster.

@Test
public void testPrepareDeletionWhenHasOneClusterDefinitionAndOneCluster() {
    Blueprint blueprint = new Blueprint();
    blueprint.setName("TemplateName");
    Cluster templateCluster = getCluster("Stack Template Name", 0L, blueprint, DetailedStackStatus.AVAILABLE);
    templateCluster.getStack().setType(StackType.TEMPLATE);
    ClusterTemplateView clusterTemplateView = new ClusterTemplateView();
    clusterTemplateView.setName("ClusterDefinition");
    Cluster workloadCluster = getCluster("Workload Name", 1L, blueprint, DetailedStackStatus.AVAILABLE);
    when(clusterTemplateViewService.findAllByStackIds(List.of(0L))).thenReturn(Set.of(clusterTemplateView));
    when(clusterService.findByBlueprint(blueprint)).thenReturn(Set.of(workloadCluster, templateCluster));
    BadRequestException actual = Assertions.assertThrows(BadRequestException.class, () -> underTest.prepareDeletion(blueprint));
    Assertions.assertEquals("There are clusters or cluster definitions associated with cluster template 'TemplateName'. " + "The cluster template used by 1 cluster(s) (Workload Name) and 1 cluster definitions (ClusterDefinition). " + "Please remove these before deleting the cluster template.", actual.getMessage());
}
Also used : Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) ClusterTemplateView(com.sequenceiq.cloudbreak.domain.view.ClusterTemplateView) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) Test(org.junit.jupiter.api.Test)

Example 9 with ClusterTemplateView

use of com.sequenceiq.cloudbreak.domain.view.ClusterTemplateView in project cloudbreak by hortonworks.

the class BlueprintServiceTest method testPrepareDeletionWhenHasOneClusterDefinition.

@Test
public void testPrepareDeletionWhenHasOneClusterDefinition() {
    Blueprint blueprint = new Blueprint();
    blueprint.setName("TemplateName");
    Cluster templateCluster = getCluster("Cluster Name", 0L, blueprint, DetailedStackStatus.AVAILABLE);
    templateCluster.getStack().setType(StackType.TEMPLATE);
    ClusterTemplateView clusterTemplateView = new ClusterTemplateView();
    clusterTemplateView.setName("ClusterDefinition");
    when(clusterService.findByBlueprint(blueprint)).thenReturn(Set.of(templateCluster));
    when(clusterTemplateViewService.findAllByStackIds(any())).thenReturn(Set.of(clusterTemplateView));
    BadRequestException actual = Assertions.assertThrows(BadRequestException.class, () -> underTest.prepareDeletion(blueprint));
    Assertions.assertEquals("There is a cluster definition ['ClusterDefinition'] which uses cluster template 'TemplateName'. " + "Please remove this cluster before deleting the cluster template.", actual.getMessage());
}
Also used : Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) ClusterTemplateView(com.sequenceiq.cloudbreak.domain.view.ClusterTemplateView) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) Test(org.junit.jupiter.api.Test)

Example 10 with ClusterTemplateView

use of com.sequenceiq.cloudbreak.domain.view.ClusterTemplateView in project cloudbreak by hortonworks.

the class ClusterTemplateService method listInWorkspaceAndCleanUpInvalids.

public Set<ClusterTemplateViewV4Response> listInWorkspaceAndCleanUpInvalids(Long workspaceId, String accountId) {
    try {
        boolean internalTenant = entitlementService.internalTenant(accountId);
        Set<ClusterTemplateView> views = transactionService.required(() -> clusterTemplateViewService.findAllActive(workspaceId, internalTenant));
        Set<ClusterTemplateViewV4Response> responses = transactionService.required(() -> views.stream().map(v -> clusterTemplateViewToClusterTemplateViewV4ResponseConverter.convert(v)).collect(toSet()));
        environmentServiceDecorator.prepareEnvironments(responses);
        cleanUpInvalidClusterDefinitions(workspaceId, responses);
        return responses.stream().filter(this::isUsableClusterTemplate).filter(this::isClusterTemplateHasValidCloudPlatform).collect(toSet());
    } catch (TransactionExecutionException e) {
        LOGGER.warn("Unable to find cluster definitions due to {}", e.getMessage());
        LOGGER.warn("Unable to find cluster definitions", e);
        throw new CloudbreakServiceException("Unable to obtain cluster definitions!");
    }
}
Also used : TransactionExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) ClusterTemplateView(com.sequenceiq.cloudbreak.domain.view.ClusterTemplateView) ClusterTemplateViewV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.clustertemplate.responses.ClusterTemplateViewV4Response)

Aggregations

ClusterTemplateView (com.sequenceiq.cloudbreak.domain.view.ClusterTemplateView)14 Test (org.junit.jupiter.api.Test)10 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)8 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)7 Blueprint (com.sequenceiq.cloudbreak.domain.Blueprint)6 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)6 ClusterTemplateViewV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.clustertemplate.responses.ClusterTemplateViewV4Response)2 HashSet (java.util.HashSet)2 MethodSource (org.junit.jupiter.params.provider.MethodSource)2 CloudbreakServiceException (com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException)1 TransactionExecutionException (com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException)1 Supplier (java.util.function.Supplier)1 EnumSource (org.junit.jupiter.params.provider.EnumSource)1