use of com.sequenceiq.environment.environment.domain.Region in project cloudbreak by hortonworks.
the class AwsEnvironmentSecurityGroupValidatorTest method testValidationWhenOnlyOneGroupDefinedReturnInValid.
@Test
public void testValidationWhenOnlyOneGroupDefinedReturnInValid() {
Region region = getRegion();
String sec1 = null;
String sec2 = "sec-2";
String vpcId = "vpc-123";
when(platformParameterService.getSecurityGroups(any(PlatformResourceRequest.class))).thenReturn(cloudSecurityGroups(region.getName(), vpcId, sec1, sec2));
EnvironmentDto environmentDto = EnvironmentDto.builder().withRegions(Set.of(region)).withSecurityAccess(getSecurityAccessDto(sec1, sec2)).withNetwork(getNetworkDto(vpcId)).withCredential(getCredential()).build();
EnvironmentValidationDto environmentValidationDto = EnvironmentValidationDto.builder().withEnvironmentDto(environmentDto).build();
ValidationResultBuilder builder = ValidationResult.builder();
underTest.validate(environmentValidationDto, builder);
requestIsInvalid(builder);
}
use of com.sequenceiq.environment.environment.domain.Region in project cloudbreak by hortonworks.
the class AwsEnvironmentSecurityGroupValidatorTest method testValidationWhenGroupsInDifferentVpcReturnInValid.
@Test
public void testValidationWhenGroupsInDifferentVpcReturnInValid() {
Region region = getRegion();
String sec1 = "sec-1,sec-2";
String sec2 = "sec-2";
String vpcId = "vpc-123";
String requestVpcId = "vpc-124";
when(platformParameterService.getSecurityGroups(any(PlatformResourceRequest.class))).thenReturn(cloudSecurityGroups(region.getName(), vpcId, "sec-1", "sec-2"));
EnvironmentDto environmentDto = EnvironmentDto.builder().withRegions(Set.of(region)).withSecurityAccess(getSecurityAccessDto(sec1, sec2)).withNetwork(getNetworkDto(requestVpcId)).withCredential(getCredential()).build();
EnvironmentValidationDto environmentValidationDto = EnvironmentValidationDto.builder().withEnvironmentDto(environmentDto).build();
ValidationResultBuilder builder = ValidationResult.builder();
underTest.validate(environmentValidationDto, builder);
requestIsInvalid(builder);
}
use of com.sequenceiq.environment.environment.domain.Region in project cloudbreak by hortonworks.
the class AwsEnvironmentSecurityGroupValidatorTest method testValidationWhenGroupsWhenGroupHasMoreGroupIdInTheSameVpcReturnIsValid.
@Test
public void testValidationWhenGroupsWhenGroupHasMoreGroupIdInTheSameVpcReturnIsValid() {
Region region = getRegion();
String sec1 = "sec-1,sec-2";
String sec2 = "sec-2,sec-1";
String requestVpcId = "vpc-124";
when(platformParameterService.getSecurityGroups(any(PlatformResourceRequest.class))).thenReturn(cloudSecurityGroups(region.getName(), requestVpcId, "sec-1", "sec-2"));
EnvironmentDto environmentDto = EnvironmentDto.builder().withRegions(Set.of(region)).withSecurityAccess(getSecurityAccessDto(sec1, sec2)).withNetwork(getNetworkDto(requestVpcId)).withCredential(getCredential()).build();
EnvironmentValidationDto environmentValidationDto = EnvironmentValidationDto.builder().withEnvironmentDto(environmentDto).build();
ValidationResultBuilder builder = ValidationResult.builder();
underTest.validate(environmentValidationDto, builder);
requestIsValid(builder);
}
use of com.sequenceiq.environment.environment.domain.Region in project cloudbreak by hortonworks.
the class AzureEnvironmentSecurityGroupValidatorTest method testValidationWhenGroupsInTheSameRegionReturnValid.
@Test
public void testValidationWhenGroupsInTheSameRegionReturnValid() {
Region region = getRegion();
when(platformParameterService.getSecurityGroups(any(PlatformResourceRequest.class))).thenReturn(cloudSecurityGroups(REGION, SECURITY_GROUP_1, SECURITY_GROUP_2));
EnvironmentDto environmentDto = EnvironmentDto.builder().withRegions(Set.of(region)).withSecurityAccess(getSecurityAccessDto(SECURITY_GROUP_1, SECURITY_GROUP_2)).withCredential(getCredential()).build();
EnvironmentValidationDto environmentValidationDto = EnvironmentValidationDto.builder().withEnvironmentDto(environmentDto).build();
ValidationResultBuilder builder = ValidationResult.builder();
underTest.validate(environmentValidationDto, builder);
requestIsValid(builder);
}
use of com.sequenceiq.environment.environment.domain.Region in project cloudbreak by hortonworks.
the class GcpEnvironmentSecurityGroupValidator method validateSecurityGroup.
private void validateSecurityGroup(EnvironmentDto environmentDto, ValidationResult.ValidationResultBuilder resultBuilder, String securityGroupIds) {
Region region = environmentDto.getRegions().iterator().next();
PlatformResourceRequest request = platformParameterService.getPlatformResourceRequest(environmentDto.getAccountId(), environmentDto.getCredential().getName(), null, region.getName(), getCloudPlatform().name(), null, CdpResourceType.DEFAULT);
Map<String, String> filters = new HashMap<>();
if (!Strings.isNullOrEmpty(environmentDto.getNetwork().getGcp().getSharedProjectId())) {
filters.put(GcpStackUtil.SHARED_PROJECT_ID, environmentDto.getNetwork().getGcp().getSharedProjectId());
}
request.setFilters(filters);
CloudSecurityGroups securityGroups = platformParameterService.getSecurityGroups(request);
boolean securityGroupFoundInRegion = false;
Map<String, Set<CloudSecurityGroup>> cloudSecurityGroupsResponses = securityGroups.getCloudSecurityGroupsResponses();
if (Objects.nonNull(cloudSecurityGroupsResponses)) {
Set<CloudSecurityGroup> cloudSecurityGroups = cloudSecurityGroupsResponses.get(region.getName());
for (String securityGroupId : getSecurityGroupIds(securityGroupIds)) {
securityGroupFoundInRegion = false;
if (Objects.nonNull(cloudSecurityGroups)) {
for (CloudSecurityGroup cloudSecurityGroup : cloudSecurityGroups) {
String groupId = cloudSecurityGroup.getGroupId();
if (!Strings.isNullOrEmpty(groupId) && groupId.equalsIgnoreCase(securityGroupId)) {
securityGroupFoundInRegion = true;
break;
}
}
}
if (!securityGroupFoundInRegion) {
break;
}
}
}
if (!securityGroupFoundInRegion) {
LOGGER.info("The security groups {} are not presented in the region {}", securityGroupIds, region.getName());
resultBuilder.error(securityGroupNotInTheSameRegion(securityGroupIds, region.getName()));
}
}
Aggregations