Search in sources :

Example 41 with Environment

use of com.sequenceiq.environment.environment.domain.Environment in project cloudbreak by hortonworks.

the class PemBasedEnvironmentDomainProviderTest method testGenerateShouldThrowServiceExceptionWhenPemReturnsWithEmptyStringAsManagedDomainName.

@Test
void testGenerateShouldThrowServiceExceptionWhenPemReturnsWithEmptyStringAsManagedDomainName() {
    Environment environment = new Environment();
    String anEnvName = "anEnvName";
    environment.setName(anEnvName);
    when(dnsManagementService.generateManagedDomain(anyString(), eq(anEnvName))).thenReturn("");
    ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> Assertions.assertThrows(EnvironmentServiceException.class, () -> underTest.generate(environment)));
    verify(dnsManagementService, times(1)).generateManagedDomain(anyString(), eq(anEnvName));
}
Also used : Environment(com.sequenceiq.environment.environment.domain.Environment) EnvironmentServiceException(com.sequenceiq.environment.exception.EnvironmentServiceException) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Example 42 with Environment

use of com.sequenceiq.environment.environment.domain.Environment in project cloudbreak by hortonworks.

the class NetworkMetadataValidationServiceTest method testWithEndpointGatewayRemovePrivateSubnetsValidationEnabled.

@Test
public void testWithEndpointGatewayRemovePrivateSubnetsValidationEnabled() {
    EnvironmentDto environmentDto = createEnvironmentDto();
    Environment environment = createEnvironment(createNetwork());
    Map<String, CloudSubnet> subnets = createDefaultPrivateSubnets();
    Map<String, CloudSubnet> endpointGatewaySubnets = createDefaultPublicSubnets();
    endpointGatewaySubnets.putAll(createDefaultPrivateSubnets());
    when(cloudNetworkService.retrieveSubnetMetadata(any(EnvironmentDto.class), any())).thenReturn(subnets);
    when(cloudNetworkService.retrieveEndpointGatewaySubnetMetadata(any(EnvironmentDto.class), any())).thenReturn(endpointGatewaySubnets);
    Map<String, CloudSubnet> subnetResult = ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.getEndpointGatewaySubnetMetadata(environment, environmentDto));
    assertEquals(2, subnetResult.size());
    assertEquals(Set.of(PUBLIC_ID_1, PUBLIC_ID_2), subnetResult.keySet());
}
Also used : EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) Environment(com.sequenceiq.environment.environment.domain.Environment) CloudSubnet(com.sequenceiq.cloudbreak.cloud.model.CloudSubnet) Test(org.junit.jupiter.api.Test)

Example 43 with Environment

use of com.sequenceiq.environment.environment.domain.Environment in project cloudbreak by hortonworks.

the class NetworkMetadataValidationServiceTest method testWithEndpointGatewayWithMissingPublicSubnets.

@Test
public void testWithEndpointGatewayWithMissingPublicSubnets() {
    Map<String, CloudSubnet> subnets = createDefaultPrivateSubnets();
    subnets.put("id3", createPrivateSubnet("id3", "AZ-3"));
    Map<String, CloudSubnet> endpointGatewaySubnets = createDefaultPublicSubnets();
    EnvironmentDto environmentDto = createEnvironmentDto();
    environmentDto.getNetwork().setSubnetMetas(subnets);
    Environment environment = createEnvironment(createNetwork());
    when(cloudNetworkService.retrieveSubnetMetadata(any(EnvironmentDto.class), any())).thenReturn(subnets);
    when(cloudNetworkService.retrieveEndpointGatewaySubnetMetadata(any(EnvironmentDto.class), any())).thenReturn(endpointGatewaySubnets);
    BadRequestException exception = assertThrows(BadRequestException.class, () -> ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.getEndpointGatewaySubnetMetadata(environment, environmentDto)));
    assertTrue(exception.getMessage().startsWith(UNMATCHED_AZ_MSG));
}
Also used : EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) Environment(com.sequenceiq.environment.environment.domain.Environment) BadRequestException(javax.ws.rs.BadRequestException) CloudSubnet(com.sequenceiq.cloudbreak.cloud.model.CloudSubnet) Test(org.junit.jupiter.api.Test)

Example 44 with Environment

use of com.sequenceiq.environment.environment.domain.Environment in project cloudbreak by hortonworks.

the class NetworkMetadataValidationServiceTest method testWithEndpointGatewayAndProvidedSubnets.

@Test
public void testWithEndpointGatewayAndProvidedSubnets() {
    EnvironmentDto environmentDto = createEnvironmentDto();
    Environment environment = createEnvironment(createNetwork());
    Map<String, CloudSubnet> subnets = createDefaultPrivateSubnets();
    Map<String, CloudSubnet> endpointGatewaySubnets = createDefaultPublicSubnets();
    when(cloudNetworkService.retrieveSubnetMetadata(any(EnvironmentDto.class), any())).thenReturn(subnets);
    when(cloudNetworkService.retrieveEndpointGatewaySubnetMetadata(any(EnvironmentDto.class), any())).thenReturn(endpointGatewaySubnets);
    Map<String, CloudSubnet> subnetResult = ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.getEndpointGatewaySubnetMetadata(environment, environmentDto));
    assertEquals(2, subnetResult.size());
    assertEquals(Set.of(PUBLIC_ID_1, PUBLIC_ID_2), subnetResult.keySet());
}
Also used : EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) Environment(com.sequenceiq.environment.environment.domain.Environment) CloudSubnet(com.sequenceiq.cloudbreak.cloud.model.CloudSubnet) Test(org.junit.jupiter.api.Test)

Example 45 with Environment

use of com.sequenceiq.environment.environment.domain.Environment in project cloudbreak by hortonworks.

the class EnvironmentStructuredFlowEventFactory method createStructuredFlowEvent.

@Override
public CDPStructuredFlowEvent createStructuredFlowEvent(Long resourceId, FlowDetails flowDetails, Exception exception) {
    Environment environment = environmentService.findEnvironmentByIdOrThrow(resourceId);
    String resourceType = CloudbreakEventService.ENVIRONMENT_RESOURCE_TYPE;
    CDPOperationDetails operationDetails = new CDPOperationDetails(clock.getCurrentTimeMillis(), FLOW, resourceType, environment.getId(), environment.getName(), nodeConfig.getId(), serviceVersion, environment.getAccountId(), environment.getResourceCrn(), environment.getCreator(), environment.getResourceCrn(), null);
    EnvironmentDetails environmentDetails = environmentDtoConverter.environmentToDto(environment);
    CDPEnvironmentStructuredFlowEvent event = new CDPEnvironmentStructuredFlowEvent(operationDetails, flowDetails, environmentDetails, environment.getStatus().name(), getReason(environment));
    if (exception != null) {
        event.setException(ExceptionUtils.getStackTrace(exception));
    }
    return event;
}
Also used : CDPEnvironmentStructuredFlowEvent(com.sequenceiq.cloudbreak.structuredevent.event.cdp.environment.CDPEnvironmentStructuredFlowEvent) EnvironmentDetails(com.sequenceiq.cloudbreak.structuredevent.event.cdp.environment.EnvironmentDetails) Environment(com.sequenceiq.environment.environment.domain.Environment) CDPOperationDetails(com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPOperationDetails)

Aggregations

Environment (com.sequenceiq.environment.environment.domain.Environment)187 Test (org.junit.jupiter.api.Test)145 EnvironmentDto (com.sequenceiq.environment.environment.dto.EnvironmentDto)48 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)42 EnvironmentEditDto (com.sequenceiq.environment.environment.dto.EnvironmentEditDto)29 Credential (com.sequenceiq.environment.credential.domain.Credential)26 EnvironmentAuthentication (com.sequenceiq.environment.environment.domain.EnvironmentAuthentication)24 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)23 ValidationResult (com.sequenceiq.cloudbreak.validation.ValidationResult)21 ParametersDto (com.sequenceiq.environment.parameter.dto.ParametersDto)16 AwsNetwork (com.sequenceiq.environment.network.dao.domain.AwsNetwork)15 NetworkDto (com.sequenceiq.environment.network.dto.NetworkDto)14 ExtendedPollingResult (com.sequenceiq.cloudbreak.polling.ExtendedPollingResult)13 SecurityAccessDto (com.sequenceiq.environment.environment.dto.SecurityAccessDto)12 CloudConnector (com.sequenceiq.cloudbreak.cloud.CloudConnector)11 AwsParametersDto (com.sequenceiq.environment.parameter.dto.AwsParametersDto)11 AzureResourceEncryptionParametersDto (com.sequenceiq.environment.parameter.dto.AzureResourceEncryptionParametersDto)11 Headers (reactor.bus.Event.Headers)11 CloudSubnet (com.sequenceiq.cloudbreak.cloud.model.CloudSubnet)10 AuthenticationDto (com.sequenceiq.environment.environment.dto.AuthenticationDto)10