Search in sources :

Example 46 with Credential

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

the class CredentialToCredentialV1ResponseConverter method convert.

public Credential convert(ExtendedCloudCredential source) {
    if (source == null) {
        return null;
    }
    Credential credential = new Credential();
    credential.setName(source.getName());
    credential.setDescription(source.getDescription());
    credential.setCloudPlatform(source.getCloudPlatform());
    credential.setCreator(source.getUserCrn());
    credential.setAccountId(source.getAccountId());
    Map<String, Object> attributes = source.getParameters() == null ? new HashMap<>() : source.getParameters();
    credential.setAttributes(new Json(attributes).getValue());
    return credential;
}
Also used : ExtendedCloudCredential(com.sequenceiq.cloudbreak.cloud.model.ExtendedCloudCredential) Credential(com.sequenceiq.environment.credential.domain.Credential) Json(com.sequenceiq.cloudbreak.common.json.Json)

Example 47 with Credential

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

the class CredentialToCredentialV1ResponseConverter method convert.

public Credential convert(CredentialRequest source) {
    if (source == null) {
        return null;
    }
    Credential credential = new Credential();
    credential.setName(Strings.isNullOrEmpty(source.getName()) ? UUID.randomUUID().toString() : source.getName());
    credential.setDescription(source.getDescription());
    credential.setCloudPlatform(source.getCloudPlatform());
    credential.setVerificationStatusText(source.getVerificationStatusText());
    credential.setVerifyPermissions(source.isVerifyPermissions());
    convertAttributes(source, credential);
    if (source.getAws() != null) {
        credential.setGovCloud(source.getAws().getGovCloud());
    }
    return credential;
}
Also used : ExtendedCloudCredential(com.sequenceiq.cloudbreak.cloud.model.ExtendedCloudCredential) Credential(com.sequenceiq.environment.credential.domain.Credential)

Example 48 with Credential

use of com.sequenceiq.environment.credential.domain.Credential 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 49 with Credential

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

the class PlatformParameterServiceTest method getPlatformResourceRequestSetPlatformFromCredential.

@Test
void getPlatformResourceRequestSetPlatformFromCredential() {
    final Credential credential = new Credential();
    String platformFromCredential = "anotherVariant";
    credential.setCloudPlatform(platformFromCredential);
    when(credentialService.getOptionalByCrnForAccountId(eq(CREDENTIAL_CRN), eq(ACCOUNT_ID), eq(ENVIRONMENT))).thenReturn(Optional.of(credential));
    when(credentialService.extractCredential(any(), any())).thenReturn(credential);
    PlatformResourceRequest result = platformParameterServiceUnderTest.getPlatformResourceRequest(ACCOUNT_ID, null, CREDENTIAL_CRN, null, EMPTY, null);
    assertEquals(platformFromCredential, result.getCloudPlatform());
    assertEquals(platformFromCredential, result.getPlatformVariant());
    assertEquals(null, result.getRegion());
    assertEquals(null, result.getAvailabilityZone());
}
Also used : Credential(com.sequenceiq.environment.credential.domain.Credential) Test(org.junit.jupiter.api.Test)

Example 50 with Credential

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

the class PlatformParameterServiceTest method getPlatformResourceRequestSetPlatformFromArgument.

@Test
void getPlatformResourceRequestSetPlatformFromArgument() {
    final Credential credential = new Credential();
    String platformFromCredential = "anotherVariant";
    credential.setCloudPlatform(platformFromCredential);
    when(credentialService.getOptionalByCrnForAccountId(eq(CREDENTIAL_CRN), eq(ACCOUNT_ID), eq(ENVIRONMENT))).thenReturn(Optional.of(credential));
    when(credentialService.extractCredential(any(), any())).thenReturn(credential);
    PlatformResourceRequest result = platformParameterServiceUnderTest.getPlatformResourceRequest(ACCOUNT_ID, null, CREDENTIAL_CRN, REGION, PLATFORM_VARIANT, AVAILIBILTY_ZONE);
    assertEquals(platformFromCredential, result.getCloudPlatform());
    assertEquals(null, result.getPlatformVariant());
    assertEquals(REGION, result.getRegion());
    assertEquals(AVAILIBILTY_ZONE, result.getAvailabilityZone());
}
Also used : Credential(com.sequenceiq.environment.credential.domain.Credential) Test(org.junit.jupiter.api.Test)

Aggregations

Credential (com.sequenceiq.environment.credential.domain.Credential)102 Test (org.junit.jupiter.api.Test)49 Environment (com.sequenceiq.environment.environment.domain.Environment)27 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)23 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)13 EnvironmentDto (com.sequenceiq.environment.environment.dto.EnvironmentDto)10 ValidationResultBuilder (com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder)9 EnvironmentAuthentication (com.sequenceiq.environment.environment.domain.EnvironmentAuthentication)9 EnvironmentCreationDto (com.sequenceiq.environment.environment.dto.EnvironmentCreationDto)9 BadRequestException (javax.ws.rs.BadRequestException)9 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)9 CheckPermissionByAccount (com.sequenceiq.authorization.annotation.CheckPermissionByAccount)8 ParametersDto (com.sequenceiq.environment.parameter.dto.ParametersDto)8 Set (java.util.Set)8 CloudConnector (com.sequenceiq.cloudbreak.cloud.CloudConnector)7 ValidationResult (com.sequenceiq.cloudbreak.validation.ValidationResult)7 AwsNetwork (com.sequenceiq.environment.network.dao.domain.AwsNetwork)7 Map (java.util.Map)7 ExtendedPollingResult (com.sequenceiq.cloudbreak.polling.ExtendedPollingResult)6 BaseNetwork (com.sequenceiq.environment.network.dao.domain.BaseNetwork)6