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);
}
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);
}
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());
}
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());
}
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!");
}
}
Aggregations