Search in sources :

Example 16 with PlatformResourceRequest

use of com.sequenceiq.environment.platformresource.PlatformResourceRequest in project cloudbreak by hortonworks.

the class CloudNetworkService method fetchCloudNetwork.

private Map<String, CloudSubnet> fetchCloudNetwork(Set<Region> regions, Credential credential, String cloudPlatform, NetworkDto network, Map<String, String> filter, Set<String> subnetIds) {
    String regionName = regions.iterator().next().getName();
    PlatformResourceRequest platformResourceRequest = new PlatformResourceRequest();
    platformResourceRequest.setCredential(credential);
    platformResourceRequest.setCloudPlatform(cloudPlatform);
    platformResourceRequest.setRegion(regionName);
    platformResourceRequest.setFilters(filter);
    LOGGER.debug("About to fetch networks from cloud provider ({})...", cloudPlatform);
    CloudNetworks cloudNetworks = platformParameterService.getCloudNetworks(platformResourceRequest);
    Set<CloudNetwork> cloudNetworkSet = cloudNetworks.getCloudNetworkResponses().get(regionName);
    return cloudNetworkSet.stream().flatMap(it -> it.getSubnetsMeta().stream()).filter(sn -> isNetworkIdMatches(subnetIds, sn, cloudPlatform) || isNetworkNameMatches(subnetIds, sn, cloudPlatform)).collect(toMap(getNetworkIdentifier(cloudPlatform), Function.identity()));
}
Also used : Environment(com.sequenceiq.environment.environment.domain.Environment) CloudSubnet(com.sequenceiq.cloudbreak.cloud.model.CloudSubnet) Logger(org.slf4j.Logger) PlatformParameterService(com.sequenceiq.environment.platformresource.PlatformParameterService) Credential(com.sequenceiq.environment.credential.domain.Credential) LoggerFactory(org.slf4j.LoggerFactory) Strings.isNullOrEmpty(com.google.common.base.Strings.isNullOrEmpty) Set(java.util.Set) HashMap(java.util.HashMap) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) Function(java.util.function.Function) CloudPlatform(com.sequenceiq.cloudbreak.common.mappable.CloudPlatform) CloudNetworks(com.sequenceiq.cloudbreak.cloud.model.CloudNetworks) AwsParams(com.sequenceiq.environment.network.dto.AwsParams) Collectors.toMap(java.util.stream.Collectors.toMap) NetworkDto(com.sequenceiq.environment.network.dto.NetworkDto) Service(org.springframework.stereotype.Service) Map(java.util.Map) PlatformResourceRequest(com.sequenceiq.environment.platformresource.PlatformResourceRequest) Optional(java.util.Optional) Region(com.sequenceiq.environment.environment.domain.Region) CloudNetwork(com.sequenceiq.cloudbreak.cloud.model.CloudNetwork) GcpStackUtil(com.sequenceiq.cloudbreak.cloud.gcp.util.GcpStackUtil) CloudNetworks(com.sequenceiq.cloudbreak.cloud.model.CloudNetworks) PlatformResourceRequest(com.sequenceiq.environment.platformresource.PlatformResourceRequest) CloudNetwork(com.sequenceiq.cloudbreak.cloud.model.CloudNetwork)

Example 17 with PlatformResourceRequest

use of com.sequenceiq.environment.platformresource.PlatformResourceRequest in project cloudbreak by hortonworks.

the class EnvironmentService method getRegionsByEnvironment.

public CloudRegions getRegionsByEnvironment(Environment environment) {
    PlatformResourceRequest platformResourceRequest = new PlatformResourceRequest();
    platformResourceRequest.setCredential(environment.getCredential());
    platformResourceRequest.setCloudPlatform(environment.getCloudPlatform());
    return platformParameterService.getRegionsByCredential(platformResourceRequest, false);
}
Also used : PlatformResourceRequest(com.sequenceiq.environment.platformresource.PlatformResourceRequest)

Example 18 with PlatformResourceRequest

use of com.sequenceiq.environment.platformresource.PlatformResourceRequest in project cloudbreak by hortonworks.

the class CredentialPlatformResourceControllerTest method getNoSqlTables.

@Test
void getNoSqlTables() {
    CloudNoSqlTables noSqlTables = new CloudNoSqlTables();
    PlatformResourceRequest platformResourceRequest = new PlatformResourceRequest();
    PlatformNoSqlTablesResponse response = new PlatformNoSqlTablesResponse();
    when(platformParameterService.getPlatformResourceRequest(any(), any(), any(), any(), any(), any())).thenReturn(platformResourceRequest);
    when(platformParameterService.getNoSqlTables(any(PlatformResourceRequest.class))).thenReturn(noSqlTables);
    when(cloudNoSqlTablesToPlatformNoSqlTablesV1ResponseConverter.convert(noSqlTables)).thenReturn(response);
    doNothing().when(commonPermissionCheckingUtils).checkPermissionForUserOnResource(any(), any(), any());
    PlatformNoSqlTablesResponse result = ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.getNoSqlTables(null, CREDENTIAL_CRN, "region", "aws", "az"));
    verify(platformParameterService).getNoSqlTables(platformResourceRequest);
    verify(cloudNoSqlTablesToPlatformNoSqlTablesV1ResponseConverter).convert(noSqlTables);
    assertEquals(response, result);
}
Also used : CloudNoSqlTables(com.sequenceiq.cloudbreak.cloud.model.nosql.CloudNoSqlTables) PlatformResourceRequest(com.sequenceiq.environment.platformresource.PlatformResourceRequest) PlatformNoSqlTablesResponse(com.sequenceiq.environment.api.v1.platformresource.model.PlatformNoSqlTablesResponse) Test(org.junit.jupiter.api.Test)

Example 19 with PlatformResourceRequest

use of com.sequenceiq.environment.platformresource.PlatformResourceRequest in project cloudbreak by hortonworks.

the class CredentialPlatformResourceController method getGatewaysCredentialId.

@Override
@CustomPermissionCheck
public PlatformGatewaysResponse getGatewaysCredentialId(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/gateways, request: {}", request);
    CloudGateWays gateways = platformParameterService.getGatewaysCredentialId(request);
    PlatformGatewaysResponse response = cloudGatewayssToPlatformGatewaysV1ResponseConverter.convert(gateways);
    LOGGER.info("Resp /platform_resources/gateways, request: {}, ipPools: {}, response: {}", request, gateways, response);
    return response;
}
Also used : PlatformGatewaysResponse(com.sequenceiq.environment.api.v1.platformresource.model.PlatformGatewaysResponse) CloudGateWays(com.sequenceiq.cloudbreak.cloud.model.CloudGateWays) PlatformResourceRequest(com.sequenceiq.environment.platformresource.PlatformResourceRequest) CustomPermissionCheck(com.sequenceiq.authorization.annotation.CustomPermissionCheck)

Example 20 with PlatformResourceRequest

use of com.sequenceiq.environment.platformresource.PlatformResourceRequest in project cloudbreak by hortonworks.

the class CredentialPlatformResourceController method getEncryptionKeys.

@Override
@CustomPermissionCheck
public PlatformEncryptionKeysResponse getEncryptionKeys(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/encryption_keys, request: {}", request);
    CloudEncryptionKeys encryptionKeys = platformParameterService.getEncryptionKeys(request);
    PlatformEncryptionKeysResponse response = cloudEncryptionKeysToPlatformEncryptionKeysV1ResponseConverter.convert(encryptionKeys);
    LOGGER.info("Resp /platform_resources/encryption_keys, request: {}, ipPools: {}, response: {}", request, encryptionKeys, response);
    return response;
}
Also used : PlatformEncryptionKeysResponse(com.sequenceiq.environment.api.v1.platformresource.model.PlatformEncryptionKeysResponse) PlatformResourceRequest(com.sequenceiq.environment.platformresource.PlatformResourceRequest) CloudEncryptionKeys(com.sequenceiq.cloudbreak.cloud.model.CloudEncryptionKeys) CustomPermissionCheck(com.sequenceiq.authorization.annotation.CustomPermissionCheck)

Aggregations

PlatformResourceRequest (com.sequenceiq.environment.platformresource.PlatformResourceRequest)31 CheckPermissionByResourceCrn (com.sequenceiq.authorization.annotation.CheckPermissionByResourceCrn)12 CustomPermissionCheck (com.sequenceiq.authorization.annotation.CustomPermissionCheck)12 CloudSecurityGroups (com.sequenceiq.cloudbreak.cloud.model.CloudSecurityGroups)9 CloudNetworks (com.sequenceiq.cloudbreak.cloud.model.CloudNetworks)7 CloudNoSqlTables (com.sequenceiq.cloudbreak.cloud.model.nosql.CloudNoSqlTables)7 PlatformNoSqlTablesResponse (com.sequenceiq.environment.api.v1.platformresource.model.PlatformNoSqlTablesResponse)7 CloudAccessConfigs (com.sequenceiq.cloudbreak.cloud.model.CloudAccessConfigs)6 CloudEncryptionKeys (com.sequenceiq.cloudbreak.cloud.model.CloudEncryptionKeys)6 CloudGateWays (com.sequenceiq.cloudbreak.cloud.model.CloudGateWays)6 CloudIpPools (com.sequenceiq.cloudbreak.cloud.model.CloudIpPools)6 CloudRegions (com.sequenceiq.cloudbreak.cloud.model.CloudRegions)6 CloudSshKeys (com.sequenceiq.cloudbreak.cloud.model.CloudSshKeys)6 CloudVmTypes (com.sequenceiq.cloudbreak.cloud.model.CloudVmTypes)6 PlatformAccessConfigsResponse (com.sequenceiq.environment.api.v1.platformresource.model.PlatformAccessConfigsResponse)6 PlatformEncryptionKeysResponse (com.sequenceiq.environment.api.v1.platformresource.model.PlatformEncryptionKeysResponse)6 PlatformGatewaysResponse (com.sequenceiq.environment.api.v1.platformresource.model.PlatformGatewaysResponse)6 PlatformIpPoolsResponse (com.sequenceiq.environment.api.v1.platformresource.model.PlatformIpPoolsResponse)6 PlatformNetworksResponse (com.sequenceiq.environment.api.v1.platformresource.model.PlatformNetworksResponse)6 PlatformSecurityGroupsResponse (com.sequenceiq.environment.api.v1.platformresource.model.PlatformSecurityGroupsResponse)6