Search in sources :

Example 51 with BadRequestException

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());
}
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 52 with BadRequestException

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());
}
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 53 with BadRequestException

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());
}
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 54 with BadRequestException

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());
}
Also used : EnvironmentLoadBalancerDto(com.sequenceiq.environment.environment.dto.EnvironmentLoadBalancerDto) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Example 55 with BadRequestException

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;
}
Also used : PlacementSettingsV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.environment.placement.PlacementSettingsV4Request) InstanceGroupNetworkV1Base(com.sequenceiq.distrox.api.v1.distrox.model.network.InstanceGroupNetworkV1Base) InstanceGroupAwsNetworkV1Parameters(com.sequenceiq.distrox.api.v1.distrox.model.network.aws.InstanceGroupAwsNetworkV1Parameters) NullUtil.getIfNotNull(com.sequenceiq.cloudbreak.util.NullUtil.getIfNotNull) EnvironmentNetworkResponse(com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentNetworkResponse) TelemetryConverter(com.sequenceiq.cloudbreak.converter.v4.stacks.TelemetryConverter) LoggerFactory(org.slf4j.LoggerFactory) CloudPlatform(com.sequenceiq.cloudbreak.common.mappable.CloudPlatform) TagsV1Request(com.sequenceiq.distrox.api.v1.distrox.model.tags.TagsV1Request) ArrayList(java.util.ArrayList) TelemetryRequest(com.sequenceiq.common.api.telemetry.request.TelemetryRequest) HashSet(java.util.HashSet) Inject(javax.inject.Inject) SdxClusterResponse(com.sequenceiq.sdx.api.model.SdxClusterResponse) AwsNetworkV1Parameters(com.sequenceiq.distrox.api.v1.distrox.model.network.aws.AwsNetworkV1Parameters) Map(java.util.Map) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) TelemetryResponse(com.sequenceiq.common.api.telemetry.response.TelemetryResponse) NetworkV1Request(com.sequenceiq.distrox.api.v1.distrox.model.network.NetworkV1Request) DistroXV1Request(com.sequenceiq.distrox.api.v1.distrox.model.DistroXV1Request) InstanceGroupV1Request(com.sequenceiq.distrox.api.v1.distrox.model.instancegroup.InstanceGroupV1Request) TagsV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.tags.TagsV4Request) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) CloudSubnet(com.sequenceiq.cloudbreak.cloud.model.CloudSubnet) Logger(org.slf4j.Logger) Collection(java.util.Collection) Set(java.util.Set) NetworkV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.network.NetworkV4Request) EnvironmentClientService(com.sequenceiq.cloudbreak.service.environment.EnvironmentClientService) Collectors(java.util.stream.Collectors) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) InstanceGroupType(com.sequenceiq.common.api.type.InstanceGroupType) YarnStackV4Parameters(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.parameter.stack.YarnStackV4Parameters) Component(org.springframework.stereotype.Component) StackV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request) SdxClientService(com.sequenceiq.cloudbreak.service.datalake.SdxClientService) Optional(java.util.Optional) StackType(com.sequenceiq.cloudbreak.api.endpoint.v4.common.StackType) StackV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) SdxClusterResponse(com.sequenceiq.sdx.api.model.SdxClusterResponse) NetworkV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.network.NetworkV4Request)

Aggregations

BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)298 Test (org.junit.jupiter.api.Test)134 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)45 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)34 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)26 SdxCluster (com.sequenceiq.datalake.entity.SdxCluster)23 ValidationResult (com.sequenceiq.cloudbreak.validation.ValidationResult)22 StackV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request)21 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)21 Blueprint (com.sequenceiq.cloudbreak.domain.Blueprint)19 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)19 Stack (com.sequenceiq.freeipa.entity.Stack)18 BaseDiagnosticsCollectionRequest (com.sequenceiq.common.api.diagnostics.BaseDiagnosticsCollectionRequest)14 FlowIdentifier (com.sequenceiq.flow.api.model.FlowIdentifier)14 SdxClusterRequest (com.sequenceiq.sdx.api.model.SdxClusterRequest)14 Set (java.util.Set)14 NotFoundException (com.sequenceiq.cloudbreak.common.exception.NotFoundException)13 NameOrCrn (com.sequenceiq.cloudbreak.api.endpoint.v4.dto.NameOrCrn)12 Json (com.sequenceiq.cloudbreak.common.json.Json)12 TransactionExecutionException (com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException)12