Search in sources :

Example 1 with ClusterTemplateView

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

the class BlueprintServiceTest method testDeletionWithTerminatedClustersNonTerminatedStacks.

@Test
public void testDeletionWithTerminatedClustersNonTerminatedStacks() {
    Blueprint blueprint = getBlueprint("name", USER_MANAGED);
    Set<Cluster> clusters = new HashSet<>();
    clusters.add(getCluster("c1", 1L, blueprint, DetailedStackStatus.PRE_DELETE_IN_PROGRESS));
    clusters.add(getCluster("c2", 1L, blueprint, DetailedStackStatus.DELETE_IN_PROGRESS));
    clusters.add(getCluster("c3", 1L, blueprint, DetailedStackStatus.DELETE_COMPLETED));
    ClusterTemplateView clusterTemplateView = new ClusterTemplateView();
    clusterTemplateView.setName("ClusterDefinition");
    when(clusterTemplateViewService.findAllByStackIds(any())).thenReturn(Set.of(clusterTemplateView));
    when(clusterService.findByBlueprint(any())).thenReturn(clusters);
    BadRequestException exception = Assertions.assertThrows(BadRequestException.class, () -> underTest.delete(blueprint));
    assertEquals("There is a cluster ['ClusterDefinition'] which uses cluster template 'name'. " + "Please remove this cluster before deleting the cluster template.", exception.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) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 2 with ClusterTemplateView

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

the class BlueprintServiceTest method testDeletionWithTerminatedAndNonTerminatedClusters.

@Test
public void testDeletionWithTerminatedAndNonTerminatedClusters() {
    Blueprint blueprint = getBlueprint("name", USER_MANAGED);
    Set<Cluster> clusters = new HashSet<>();
    clusters.add(getCluster("c1", 1L, blueprint, DetailedStackStatus.PRE_DELETE_IN_PROGRESS));
    clusters.add(getCluster("c2", 1L, blueprint, DetailedStackStatus.DELETE_COMPLETED));
    ClusterTemplateView clusterTemplateView = new ClusterTemplateView();
    clusterTemplateView.setName("ClusterDefinition1");
    ClusterTemplateView clusterTemplateView2 = new ClusterTemplateView();
    clusterTemplateView2.setName("ClusterDefinition2");
    when(clusterTemplateViewService.findAllByStackIds(any())).thenReturn(Set.of(clusterTemplateView, clusterTemplateView2));
    when(clusterService.findByBlueprint(any())).thenReturn(clusters);
    try {
        underTest.delete(blueprint);
    } catch (BadRequestException e) {
        assertTrue(e.getMessage().contains("ClusterDefinition1"));
        assertFalse(e.getMessage().contains("ClusterDefinition2"));
    }
    verify(clusterService, times(1)).saveAll(anyCollection());
}
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) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 3 with ClusterTemplateView

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

the class BlueprintServiceTest method testDeletionWithNonTerminatedClusterAndStack.

@Test
public void testDeletionWithNonTerminatedClusterAndStack() {
    Blueprint blueprint = getBlueprint("name", USER_MANAGED);
    Cluster cluster = getCluster("c1", 1L, blueprint, DetailedStackStatus.AVAILABLE);
    ClusterTemplateView clusterTemplateView = new ClusterTemplateView();
    clusterTemplateView.setName("ClusterDefinition");
    when(clusterTemplateViewService.findAllByStackIds(any())).thenReturn(Set.of(clusterTemplateView));
    when(clusterService.findByBlueprint(any())).thenReturn(Set.of(cluster));
    BadRequestException exception = Assertions.assertThrows(BadRequestException.class, () -> underTest.delete(blueprint));
    assertEquals("There is a cluster ['ClusterDefinition'] which uses cluster template 'name'. " + "Please remove this cluster before deleting the cluster template.", exception.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 4 with ClusterTemplateView

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

the class BlueprintServiceTest method testPrepareDeletionWhenHasOneCluster.

@Test
public void testPrepareDeletionWhenHasOneCluster() {
    Blueprint blueprint = new Blueprint();
    blueprint.setName("TemplateName");
    Cluster templateCluster = getCluster("Cluster Name", 0L, blueprint, DetailedStackStatus.AVAILABLE);
    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 ['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 5 with ClusterTemplateView

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

the class ClusterTemplateViewServiceTest method testPrepareCreation.

@Test
public void testPrepareCreation() {
    BadRequestException expectedException = assertThrows(BadRequestException.class, () -> underTest.prepareCreation(new ClusterTemplateView()));
    assertEquals("Cluster template creation is not supported from ClusterTemplateViewService", expectedException.getMessage());
}
Also used : ClusterTemplateView(com.sequenceiq.cloudbreak.domain.view.ClusterTemplateView) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

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