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