use of com.sequenceiq.environment.platformresource.PlatformResourceRequest 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()));
}
}
use of com.sequenceiq.environment.platformresource.PlatformResourceRequest in project cloudbreak by hortonworks.
the class CredentialPlatformResourceController method getCloudSshKeys.
@Override
@CustomPermissionCheck
public PlatformSshKeysResponse getCloudSshKeys(String credentialName, String credentialCrn, String region, String platformVariant, String availabilityZone) {
customCheckUtil.run(() -> permissionCheckByCredential(credentialName, credentialCrn));
String accountId = getAccountId();
PlatformResourceRequest request = platformParameterService.getPlatformResourceRequest(accountId, credentialName, credentialCrn, region, platformVariant, availabilityZone);
LOGGER.info("Get /platform_resources/ssh_keys, request: {}", request);
CloudSshKeys sshKeys = platformParameterService.getCloudSshKeys(request);
PlatformSshKeysResponse response = cloudSshKeysToPlatformSshKeysV1ResponseConverter.convert(sshKeys);
LOGGER.info("Resp /platform_resources/ssh_keys, request: {}, sshKeys: {}", request, sshKeys);
return response;
}
use of com.sequenceiq.environment.platformresource.PlatformResourceRequest in project cloudbreak by hortonworks.
the class CredentialPlatformResourceController method getRegionsByCredential.
@Override
@CustomPermissionCheck
public RegionResponse getRegionsByCredential(String credentialName, String credentialCrn, String region, String platformVariant, String availabilityZone, boolean availabilityZonesNeeded) {
customCheckUtil.run(() -> permissionCheckByCredential(credentialName, credentialCrn));
String accountId = getAccountId();
PlatformResourceRequest request = platformParameterService.getPlatformResourceRequest(accountId, credentialName, credentialCrn, region, platformVariant, availabilityZone);
LOGGER.info("Get /platform_resources/regions, request: {}", request);
CloudRegions regions = platformParameterService.getRegionsByCredential(request, availabilityZonesNeeded);
RegionResponse response = platformRegionsToRegionV1ResponseConverter.convert(regions);
LOGGER.info("Resp /platform_resources/regions, request: {}, regions: {}, response: {}", request, regions, response);
return response;
}
use of com.sequenceiq.environment.platformresource.PlatformResourceRequest in project cloudbreak by hortonworks.
the class CredentialPlatformResourceController method getAccessConfigs.
@Override
@CustomPermissionCheck
public PlatformAccessConfigsResponse getAccessConfigs(String credentialName, String credentialCrn, String region, String platformVariant, String availabilityZone, AccessConfigTypeQueryParam accessConfigType) {
customCheckUtil.run(() -> permissionCheckByCredential(credentialName, credentialCrn));
String accountId = getAccountId();
PlatformResourceRequest request = platformParameterService.getPlatformResourceRequest(accountId, credentialName, credentialCrn, region, platformVariant, availabilityZone, null, accessConfigType);
LOGGER.info("Get /platform_resources/access_configs, request: {}", request);
CloudAccessConfigs accessConfigs = platformParameterService.getAccessConfigs(request);
PlatformAccessConfigsResponse response = cloudAccessConfigsToPlatformAccessConfigsV1ResponseConverter.convert(accessConfigs);
LOGGER.info("Resp /platform_resources/access_configs, request: {}, accessConfigs: {}, response: {}", request, accessConfigs, response);
return response;
}
use of com.sequenceiq.environment.platformresource.PlatformResourceRequest in project cloudbreak by hortonworks.
the class CredentialPlatformResourceController method getCloudNetworks.
@Override
@CustomPermissionCheck
public PlatformNetworksResponse getCloudNetworks(String credentialName, String credentialCrn, String region, String platformVariant, String availabilityZone, String networkId, String subnetIds, String sharedProjectId) {
customCheckUtil.run(() -> permissionCheckByCredential(credentialName, credentialCrn));
String accountId = getAccountId();
Map<String, String> filter = new HashMap<>();
if (!Strings.isNullOrEmpty(subnetIds)) {
filter.put(NetworkConstants.SUBNET_IDS, subnetIds);
}
if (!Strings.isNullOrEmpty(networkId)) {
filter.put("networkId", networkId);
}
PlatformResourceRequest request = platformParameterService.getPlatformResourceRequest(accountId, credentialName, credentialCrn, region, platformVariant, availabilityZone, sharedProjectId, filter, null, CdpResourceType.DEFAULT);
LOGGER.info("Get /platform_resources/networks, request: {}", request);
CloudNetworks networks = platformParameterService.getCloudNetworks(request);
PlatformNetworksResponse response = cloudNetworksToPlatformNetworksV1ResponseConverter.convert(networks);
LOGGER.info("Resp /platform_resources/networks, request: {}, networks: {}, response: {}", request, networks, response);
return response;
}
Aggregations