use of com.sequenceiq.cloudbreak.common.exception.BadRequestException 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());
}
use of com.sequenceiq.cloudbreak.common.exception.BadRequestException 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());
}
use of com.sequenceiq.cloudbreak.common.exception.BadRequestException 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());
}
use of com.sequenceiq.cloudbreak.common.exception.BadRequestException in project cloudbreak by hortonworks.
the class EnvironmentLoadBalancerServiceTest method testNoEntitlements.
@Test
public void testNoEntitlements() {
EnvironmentLoadBalancerDto environmentLbDto = EnvironmentLoadBalancerDto.builder().withEndpointAccessGateway(PublicEndpointAccessGateway.DISABLED).build();
EnvironmentDto environmentDto = EnvironmentDto.builder().withResourceCrn(ENV_CRN).build();
String expectedError = "Neither Endpoint Gateway nor Data Lake load balancer is enabled. Nothing to do.";
when(entitlementService.datalakeLoadBalancerEnabled(anyString())).thenReturn(false);
final BadRequestException[] exception = new BadRequestException[1];
ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> {
exception[0] = assertThrows(BadRequestException.class, () -> underTest.updateLoadBalancerInEnvironmentAndStacks(environmentDto, environmentLbDto));
});
assertEquals(expectedError, exception[0].getMessage());
}
use of com.sequenceiq.cloudbreak.common.exception.BadRequestException in project cloudbreak by hortonworks.
the class DistroXV1RequestToStackV4RequestConverter method convert.
public StackV4Request convert(DistroXV1Request source) {
DetailedEnvironmentResponse environment = Optional.ofNullable(environmentClientService.getByName(source.getEnvironmentName())).orElseThrow(() -> new BadRequestException("No environment name provided hence unable to obtain some important data"));
StackV4Request request = new StackV4Request();
SdxClusterResponse sdxClusterResponse = getSdxClusterResponse(environment);
request.setName(source.getName());
request.setType(StackType.WORKLOAD);
request.setCloudPlatform(getCloudPlatform(environment));
request.setEnvironmentCrn(environment.getCrn());
request.setAuthentication(getIfNotNull(environment.getAuthentication(), authenticationConverter::convert));
request.setImage(getIfNotNull(source.getImage(), imageConverter::convert));
request.setCluster(getIfNotNull(source, environment, clusterConverter::convert));
NetworkV4Request network = getNetwork(source.getNetwork(), environment, source.getInstanceGroups());
request.setNetwork(network);
request.setInstanceGroups(getIfNotNull(source.getInstanceGroups(), igs -> instanceGroupConverter.convertTo(network, igs, environment)));
request.setAws(getIfNotNull(source.getAws(), stackParameterConverter::convert));
request.setAzure(getIfNotNull(source.getAzure(), stackParameterConverter::convert));
request.setGcp(getIfNotNull(source.getGcp(), stackParameterConverter::convert));
request.setYarn(getYarnProperties(source, environment));
request.setInputs(source.getInputs());
request.setTags(getIfNotNull(source.getTags(), this::getTags));
request.setPlacement(preparePlacement(environment));
request.setSharedService(sdxConverter.getSharedService(sdxClusterResponse));
request.setCustomDomain(null);
request.setTimeToLive(source.getTimeToLive());
request.setTelemetry(getTelemetryRequest(environment, sdxClusterResponse));
request.setGatewayPort(source.getGatewayPort());
request.setExternalDatabase(getIfNotNull(source.getExternalDatabase(), databaseRequestConverter::convert));
request.setEnableLoadBalancer(source.isEnableLoadBalancer());
request.setVariant(source.getVariant());
checkMultipleGatewayNodes(source);
return request;
}
Aggregations