Search in sources :

Example 1 with EnvironmentLoadBalancerDto

use of com.sequenceiq.environment.environment.dto.EnvironmentLoadBalancerDto in project cloudbreak by hortonworks.

the class EnvironmentLoadBalancerServiceTest method testNoEnvironmentFound.

@Test
public void testNoEnvironmentFound() {
    EnvironmentLoadBalancerDto environmentLbDto = EnvironmentLoadBalancerDto.builder().withEndpointAccessGateway(PublicEndpointAccessGateway.ENABLED).build();
    EnvironmentDto environmentDto = EnvironmentDto.builder().withName(ENV_NAME).withResourceCrn(ENV_CRN).build();
    String expectedError = String.format("Could not find environment '%s' using crn '%s'", ENV_NAME, ENV_CRN);
    when(environmentService.findByResourceCrnAndAccountIdAndArchivedIsFalse(anyString(), anyString())).thenReturn(Optional.empty());
    doNothing().when(loadBalancerEntitlementService).validateNetworkForEndpointGateway(any(), any(), any());
    final NotFoundException[] exception = new NotFoundException[1];
    ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> {
        exception[0] = assertThrows(NotFoundException.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) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Example 2 with EnvironmentLoadBalancerDto

use of com.sequenceiq.environment.environment.dto.EnvironmentLoadBalancerDto 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 3 with EnvironmentLoadBalancerDto

use of com.sequenceiq.environment.environment.dto.EnvironmentLoadBalancerDto in project cloudbreak by hortonworks.

the class EnvironmentApiConverterTest method testInitLoadBalancerDto.

@Test
void testInitLoadBalancerDto() {
    Set<String> subnetIds = Set.of("id1, id2");
    EnvironmentLoadBalancerUpdateRequest request = new EnvironmentLoadBalancerUpdateRequest();
    request.setPublicEndpointAccessGateway(PublicEndpointAccessGateway.ENABLED);
    request.setSubnetIds(subnetIds);
    EnvironmentLoadBalancerDto environmentLbDto = underTest.initLoadBalancerDto(request);
    assertEquals(PublicEndpointAccessGateway.ENABLED, environmentLbDto.getEndpointAccessGateway());
    assertEquals(subnetIds, environmentLbDto.getEndpointGatewaySubnetIds());
}
Also used : EnvironmentLoadBalancerDto(com.sequenceiq.environment.environment.dto.EnvironmentLoadBalancerDto) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) EnvironmentLoadBalancerUpdateRequest(com.sequenceiq.environment.api.v1.environment.model.request.EnvironmentLoadBalancerUpdateRequest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with EnvironmentLoadBalancerDto

use of com.sequenceiq.environment.environment.dto.EnvironmentLoadBalancerDto in project cloudbreak by hortonworks.

the class EnvironmentLoadBalancerServiceTest method testDataLakeLoadBalancerEnabled.

@Test
public void testDataLakeLoadBalancerEnabled() {
    EnvironmentLoadBalancerDto environmentLbDto = EnvironmentLoadBalancerDto.builder().withEndpointAccessGateway(PublicEndpointAccessGateway.DISABLED).build();
    EnvironmentDto environmentDto = EnvironmentDto.builder().withResourceCrn(ENV_CRN).build();
    when(entitlementService.datalakeLoadBalancerEnabled(anyString())).thenReturn(true);
    when(environmentService.findByResourceCrnAndAccountIdAndArchivedIsFalse(anyString(), anyString())).thenReturn(Optional.of(new Environment()));
    doNothing().when(loadBalancerEntitlementService).validateNetworkForEndpointGateway(any(), any(), any());
    ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> {
        underTest.updateLoadBalancerInEnvironmentAndStacks(environmentDto, environmentLbDto);
    });
    verify(reactorFlowManager, times(1)).triggerLoadBalancerUpdateFlow(any(), any(), any(), any(), any(), any(), anyString());
}
Also used : EnvironmentLoadBalancerDto(com.sequenceiq.environment.environment.dto.EnvironmentLoadBalancerDto) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) Environment(com.sequenceiq.environment.environment.domain.Environment) Test(org.junit.jupiter.api.Test)

Example 5 with EnvironmentLoadBalancerDto

use of com.sequenceiq.environment.environment.dto.EnvironmentLoadBalancerDto in project cloudbreak by hortonworks.

the class EnvironmentLoadBalancerServiceTest method testEndpointGatewayEnabled.

@Test
public void testEndpointGatewayEnabled() {
    EnvironmentLoadBalancerDto environmentLbDto = EnvironmentLoadBalancerDto.builder().withEndpointAccessGateway(PublicEndpointAccessGateway.ENABLED).build();
    EnvironmentDto environmentDto = EnvironmentDto.builder().withResourceCrn(ENV_CRN).build();
    when(environmentService.findByResourceCrnAndAccountIdAndArchivedIsFalse(anyString(), anyString())).thenReturn(Optional.of(new Environment()));
    doNothing().when(loadBalancerEntitlementService).validateNetworkForEndpointGateway(any(), any(), any());
    ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> {
        underTest.updateLoadBalancerInEnvironmentAndStacks(environmentDto, environmentLbDto);
    });
    verify(reactorFlowManager, times(1)).triggerLoadBalancerUpdateFlow(any(), any(), any(), any(), any(), any(), anyString());
}
Also used : EnvironmentLoadBalancerDto(com.sequenceiq.environment.environment.dto.EnvironmentLoadBalancerDto) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) Environment(com.sequenceiq.environment.environment.domain.Environment) Test(org.junit.jupiter.api.Test)

Aggregations

EnvironmentLoadBalancerDto (com.sequenceiq.environment.environment.dto.EnvironmentLoadBalancerDto)11 EnvironmentDto (com.sequenceiq.environment.environment.dto.EnvironmentDto)10 Test (org.junit.jupiter.api.Test)5 LoadBalancerUpdateEvent (com.sequenceiq.environment.environment.flow.loadbalancer.event.LoadBalancerUpdateEvent)4 EnvironmentStatus (com.sequenceiq.environment.environment.EnvironmentStatus)3 Environment (com.sequenceiq.environment.environment.domain.Environment)3 Map (java.util.Map)3 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)3 ResourceEvent (com.sequenceiq.cloudbreak.event.ResourceEvent)2 LoadBalancerUpdateFailedEvent (com.sequenceiq.environment.environment.flow.loadbalancer.event.LoadBalancerUpdateFailedEvent)2 CommonContext (com.sequenceiq.flow.core.CommonContext)2 Bean (org.springframework.context.annotation.Bean)2 CheckPermissionByResourceCrn (com.sequenceiq.authorization.annotation.CheckPermissionByResourceCrn)1 CheckPermissionByResourceName (com.sequenceiq.authorization.annotation.CheckPermissionByResourceName)1 CloudSubnet (com.sequenceiq.cloudbreak.cloud.model.CloudSubnet)1 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)1 NotFoundException (com.sequenceiq.cloudbreak.common.exception.NotFoundException)1 PublicEndpointAccessGateway (com.sequenceiq.common.api.type.PublicEndpointAccessGateway)1 EnvironmentLoadBalancerUpdateRequest (com.sequenceiq.environment.api.v1.environment.model.request.EnvironmentLoadBalancerUpdateRequest)1 LoadBalancerUpdateHandlerSelectors (com.sequenceiq.environment.environment.flow.loadbalancer.event.LoadBalancerUpdateHandlerSelectors)1