Search in sources :

Example 1 with InstanceTemplateRequest

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceTemplateRequest in project cloudbreak by hortonworks.

the class StackToCreateFreeIpaRequestConverter method getInstanceTemplateRequest.

private InstanceTemplateRequest getInstanceTemplateRequest(Template template) {
    InstanceTemplateRequest request = null;
    if (template != null) {
        request = new InstanceTemplateRequest();
        request.setInstanceType(template.getInstanceType());
        Integer spotPercentage = template.getAttributes().getValue(AwsInstanceTemplate.EC2_SPOT_PERCENTAGE);
        Double maxPrice = template.getAttributes().getValue(AwsInstanceTemplate.EC2_SPOT_MAX_PRICE);
        if (spotPercentage != null) {
            LOGGER.debug("EC2 spot percentage found in the instances template attributes");
            AwsInstanceTemplateParameters aws = new AwsInstanceTemplateParameters();
            AwsInstanceTemplateSpotParameters spot = new AwsInstanceTemplateSpotParameters();
            spot.setPercentage(spotPercentage);
            if (maxPrice != null) {
                LOGGER.debug("EC2 max price found in the instances template attributes");
                spot.setMaxPrice(maxPrice);
            }
            aws.setSpot(spot);
            request.setAws(aws);
        }
        VolumeRequest volumeRequest = new VolumeRequest();
        volumeRequest.setType(template.getVolumeType());
        volumeRequest.setCount(template.getVolumeCount());
        volumeRequest.setSize(template.getVolumeSize());
        request.setAttachedVolumes(Optional.of(volumeRequest).filter(v -> v.getCount() != null && v.getCount() > 0 && v.getSize() != null && v.getSize() > 0).stream().collect(Collectors.toSet()));
    }
    LOGGER.debug("Created instance template request {} from instance template {}", request, template);
    return request;
}
Also used : InstanceGroupNetwork(com.sequenceiq.freeipa.entity.InstanceGroupNetwork) Arrays(java.util.Arrays) URISyntaxException(java.net.URISyntaxException) Template(com.sequenceiq.freeipa.entity.Template) LoggerFactory(org.slf4j.LoggerFactory) FeaturesRequest(com.sequenceiq.common.api.telemetry.request.FeaturesRequest) StringUtils(org.apache.commons.lang3.StringUtils) TelemetryRequest(com.sequenceiq.common.api.telemetry.request.TelemetryRequest) InstanceTemplateRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceTemplateRequest) StackAuthenticationRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.security.StackAuthenticationRequest) Map(java.util.Map) Telemetry(com.sequenceiq.common.api.telemetry.model.Telemetry) URI(java.net.URI) InstanceGroupRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceGroupRequest) FreeIpaServerRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.FreeIpaServerRequest) InstanceGroupNetworkRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceGroupNetworkRequest) FreeIpa(com.sequenceiq.freeipa.entity.FreeIpa) Network(com.sequenceiq.freeipa.entity.Network) StackTags(com.sequenceiq.cloudbreak.cloud.model.StackTags) Logging(com.sequenceiq.common.api.telemetry.model.Logging) Collectors(java.util.stream.Collectors) Json(com.sequenceiq.cloudbreak.common.json.Json) List(java.util.List) FreeIpaService(com.sequenceiq.freeipa.service.freeipa.FreeIpaService) AwsInstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.instance.AwsInstanceTemplate) Optional(java.util.Optional) NetworkConstants(com.sequenceiq.cloudbreak.common.network.NetworkConstants) StackAuthentication(com.sequenceiq.freeipa.entity.StackAuthentication) Features(com.sequenceiq.common.api.telemetry.model.Features) PlacementRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.region.PlacementRequest) SecurityGroup(com.sequenceiq.freeipa.entity.SecurityGroup) CreateFreeIpaRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.create.CreateFreeIpaRequest) BackupRequest(com.sequenceiq.common.api.backup.request.BackupRequest) ImageEntity(com.sequenceiq.freeipa.entity.ImageEntity) CloudPlatform(com.sequenceiq.cloudbreak.common.mappable.CloudPlatform) Inject(javax.inject.Inject) Backup(com.sequenceiq.freeipa.api.model.Backup) WorkloadAnalyticsRequest(com.sequenceiq.common.api.telemetry.request.WorkloadAnalyticsRequest) Monitoring(com.sequenceiq.common.api.telemetry.model.Monitoring) AwsInstanceTemplateParameters(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.aws.AwsInstanceTemplateParameters) Stack(com.sequenceiq.freeipa.entity.Stack) ImageSettingsRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.image.ImageSettingsRequest) Converter(org.springframework.core.convert.converter.Converter) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) Logger(org.slf4j.Logger) WorkloadAnalytics(com.sequenceiq.common.api.telemetry.model.WorkloadAnalytics) SecurityRule(com.sequenceiq.freeipa.entity.SecurityRule) SecurityGroupRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.security.SecurityGroupRequest) IOException(java.io.IOException) Maps(com.google.common.collect.Maps) NetworkRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.network.NetworkRequest) LoggingRequest(com.sequenceiq.common.api.telemetry.request.LoggingRequest) SecurityRuleRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.security.SecurityRuleRequest) Component(org.springframework.stereotype.Component) VolumeRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.VolumeRequest) InstanceGroup(com.sequenceiq.freeipa.entity.InstanceGroup) AwsInstanceTemplateSpotParameters(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.aws.AwsInstanceTemplateSpotParameters) InstanceGroupAwsNetworkParameters(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.aws.InstanceGroupAwsNetworkParameters) MonitoringRequest(com.sequenceiq.common.api.telemetry.request.MonitoringRequest) AwsInstanceTemplateSpotParameters(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.aws.AwsInstanceTemplateSpotParameters) InstanceTemplateRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceTemplateRequest) AwsInstanceTemplateParameters(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.aws.AwsInstanceTemplateParameters) VolumeRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.VolumeRequest)

Example 2 with InstanceTemplateRequest

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceTemplateRequest in project cloudbreak by hortonworks.

the class FreeIpaTestDto method mapInstanceTemplateRequest.

private InstanceTemplateRequest mapInstanceTemplateRequest(InstanceGroupV4Request request) {
    InstanceTemplateRequest template = new InstanceTemplateRequest();
    template.setInstanceType(request.getTemplate().getInstanceType());
    template.setAttachedVolumes(request.getTemplate().getAttachedVolumes().stream().map(volreq -> {
        VolumeRequest volumeRequest = new VolumeRequest();
        volumeRequest.setCount(volreq.getCount());
        volumeRequest.setSize(volreq.getSize());
        volumeRequest.setType(volreq.getType());
        return volumeRequest;
    }).collect(Collectors.toSet()));
    Optional.ofNullable(request.getTemplate().getAws()).map(AwsInstanceTemplateV4Parameters::getSpot).map(AwsInstanceTemplateV4SpotParameters::getPercentage).ifPresent(spotPercentage -> {
        AwsInstanceTemplateParameters awsInstanceTemplateParameters = new AwsInstanceTemplateParameters();
        AwsInstanceTemplateSpotParameters awsInstanceTemplateSpotParameters = new AwsInstanceTemplateSpotParameters();
        awsInstanceTemplateSpotParameters.setPercentage(spotPercentage);
        awsInstanceTemplateParameters.setSpot(awsInstanceTemplateSpotParameters);
        template.setAws(awsInstanceTemplateParameters);
    });
    return template;
}
Also used : AwsInstanceTemplateSpotParameters(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.aws.AwsInstanceTemplateSpotParameters) InstanceTemplateRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceTemplateRequest) AwsInstanceTemplateV4Parameters(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.parameter.template.AwsInstanceTemplateV4Parameters) AwsInstanceTemplateParameters(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.aws.AwsInstanceTemplateParameters) VolumeRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.VolumeRequest)

Example 3 with InstanceTemplateRequest

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceTemplateRequest in project cloudbreak by hortonworks.

the class InstanceTemplateRequestToTemplateConverterTest method shouldSetEncryptionKeyAndEncryptionMethodPropertyWhenGcpEncryptionKeyPresent.

@Test
void shouldSetEncryptionKeyAndEncryptionMethodPropertyWhenGcpEncryptionKeyPresent() {
    InstanceTemplateRequest source = new InstanceTemplateRequest();
    source.setInstanceType(INSTANCE_TYPE);
    Template result = underTest.convert(source, CloudPlatform.GCP, ACCOUNT_ID, null, "dummyEncryptionKey", null);
    Json attributes = result.getAttributes();
    assertThat(attributes).isNotNull();
    assertThat(attributes.<Object>getValue(GcpInstanceTemplate.VOLUME_ENCRYPTION_KEY_ID)).isEqualTo("dummyEncryptionKey");
    assertThat(attributes.<Object>getValue("keyEncryptionMethod")).isEqualTo("KMS");
}
Also used : InstanceTemplateRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceTemplateRequest) Json(com.sequenceiq.cloudbreak.common.json.Json) AzureInstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.instance.AzureInstanceTemplate) Template(com.sequenceiq.freeipa.entity.Template) AwsInstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.instance.AwsInstanceTemplate) GcpInstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.instance.GcpInstanceTemplate) InstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate) Test(org.junit.jupiter.api.Test)

Example 4 with InstanceTemplateRequest

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceTemplateRequest in project cloudbreak by hortonworks.

the class InstanceTemplateRequestToTemplateConverterTest method shouldSetInstanceTypeWhenProvided.

@Test
void shouldSetInstanceTypeWhenProvided() {
    InstanceTemplateRequest source = new InstanceTemplateRequest();
    source.setInstanceType(INSTANCE_TYPE);
    Template result = underTest.convert(source, CLOUD_PLATFORM, ACCOUNT_ID, null, null, null);
    assertThat(result.getInstanceType()).isEqualTo(source.getInstanceType());
}
Also used : InstanceTemplateRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceTemplateRequest) AzureInstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.instance.AzureInstanceTemplate) Template(com.sequenceiq.freeipa.entity.Template) AwsInstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.instance.AwsInstanceTemplate) GcpInstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.instance.GcpInstanceTemplate) InstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate) Test(org.junit.jupiter.api.Test)

Example 5 with InstanceTemplateRequest

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceTemplateRequest in project cloudbreak by hortonworks.

the class InstanceTemplateRequestToTemplateConverterTest method shouldNotSetDiskEncryptionSetIdPropertyWhenAzureAndDiskEncryptionSetIdIsNotPresent.

@Test
void shouldNotSetDiskEncryptionSetIdPropertyWhenAzureAndDiskEncryptionSetIdIsNotPresent() {
    InstanceTemplateRequest source = new InstanceTemplateRequest();
    source.setInstanceType(INSTANCE_TYPE);
    Template result = underTest.convert(source, CloudPlatform.AZURE, ACCOUNT_ID, null, null, null);
    Json attributes = result.getAttributes();
    assertThat(attributes).isNotNull();
    assertThat(attributes.<Object>getValue(AzureInstanceTemplate.DISK_ENCRYPTION_SET_ID)).isNull();
    assertThat(attributes.<Object>getValue(AzureInstanceTemplate.MANAGED_DISK_ENCRYPTION_WITH_CUSTOM_KEY_ENABLED)).isNull();
}
Also used : InstanceTemplateRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceTemplateRequest) Json(com.sequenceiq.cloudbreak.common.json.Json) AzureInstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.instance.AzureInstanceTemplate) Template(com.sequenceiq.freeipa.entity.Template) AwsInstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.instance.AwsInstanceTemplate) GcpInstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.instance.GcpInstanceTemplate) InstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate) Test(org.junit.jupiter.api.Test)

Aggregations

InstanceTemplateRequest (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceTemplateRequest)24 AwsInstanceTemplate (com.sequenceiq.cloudbreak.cloud.model.instance.AwsInstanceTemplate)21 Template (com.sequenceiq.freeipa.entity.Template)21 Test (org.junit.jupiter.api.Test)21 AzureInstanceTemplate (com.sequenceiq.cloudbreak.cloud.model.instance.AzureInstanceTemplate)19 Json (com.sequenceiq.cloudbreak.common.json.Json)15 InstanceTemplate (com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate)14 GcpInstanceTemplate (com.sequenceiq.cloudbreak.cloud.model.instance.GcpInstanceTemplate)14 FreeIpaServerRequest (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.FreeIpaServerRequest)7 InstanceGroupRequest (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceGroupRequest)7 NetworkRequest (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.network.NetworkRequest)7 InstanceGroup (com.sequenceiq.freeipa.entity.InstanceGroup)7 Stack (com.sequenceiq.freeipa.entity.Stack)7 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)5 VolumeRequest (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.VolumeRequest)3 AwsInstanceTemplateParameters (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.aws.AwsInstanceTemplateParameters)3 AwsInstanceTemplateSpotParameters (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.aws.AwsInstanceTemplateSpotParameters)3 CreateFreeIpaRequest (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.create.CreateFreeIpaRequest)3 StackTags (com.sequenceiq.cloudbreak.cloud.model.StackTags)2 BackupRequest (com.sequenceiq.common.api.backup.request.BackupRequest)2