Search in sources :

Example 1 with Template

use of com.sequenceiq.freeipa.entity.Template 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 Template

use of com.sequenceiq.freeipa.entity.Template in project cloudbreak by hortonworks.

the class InstanceTemplateRequestToTemplateConverter method convert.

public Template convert(InstanceTemplateRequest source, CloudPlatform cloudPlatform, String accountId, String diskEncryptionSetId, String gcpKmsEncryptionKey, String awsKmsEncryptionKey) {
    Template template = new Template();
    template.setAccountId(accountId);
    template.setName(missingResourceNameGenerator.generateName(APIResourceType.TEMPLATE));
    template.setStatus(ResourceStatus.USER_MANAGED);
    setVolumesProperty(source.getAttachedVolumes(), template, cloudPlatform);
    template.setInstanceType(Objects.requireNonNullElse(source.getInstanceType(), defaultInstanceTypeProvider.getForPlatform(cloudPlatform.name())));
    Map<String, Object> attributes = new HashMap<>();
    if (cloudPlatform == CloudPlatform.AWS) {
        if (awsKmsEncryptionKey != null) {
            attributes.put(AwsInstanceTemplate.EBS_ENCRYPTION_ENABLED, Boolean.TRUE);
            attributes.put(InstanceTemplate.VOLUME_ENCRYPTION_KEY_TYPE, EncryptionType.CUSTOM.name());
            attributes.put(InstanceTemplate.VOLUME_ENCRYPTION_KEY_ID, awsKmsEncryptionKey);
        } else {
            attributes.put(AwsInstanceTemplate.EBS_ENCRYPTION_ENABLED, Boolean.TRUE);
            attributes.put(InstanceTemplate.VOLUME_ENCRYPTION_KEY_TYPE, EncryptionType.DEFAULT.name());
        }
    }
    Optional.ofNullable(source.getAws()).map(AwsInstanceTemplateParameters::getSpot).ifPresent(spotParameters -> {
        attributes.put(AwsInstanceTemplate.EC2_SPOT_PERCENTAGE, spotParameters.getPercentage());
        if (Objects.nonNull(spotParameters.getMaxPrice())) {
            attributes.put(AwsInstanceTemplate.EC2_SPOT_MAX_PRICE, spotParameters.getMaxPrice());
        }
    });
    if (cloudPlatform == CloudPlatform.AZURE) {
        if (diskEncryptionSetId != null) {
            attributes.put(AzureInstanceTemplate.DISK_ENCRYPTION_SET_ID, diskEncryptionSetId);
            attributes.put(AzureInstanceTemplate.MANAGED_DISK_ENCRYPTION_WITH_CUSTOM_KEY_ENABLED, true);
        }
        if (entitlementService.isAzureEncryptionAtHostEnabled(accountId)) {
            attributes.put(AzureInstanceTemplate.ENCRYPTION_AT_HOST_ENABLED, true);
        }
    }
    if (gcpKmsEncryptionKey != null && cloudPlatform == CloudPlatform.GCP) {
        attributes.put(GcpInstanceTemplate.VOLUME_ENCRYPTION_KEY_ID, gcpKmsEncryptionKey);
        attributes.put(GcpInstanceTemplate.VOLUME_ENCRYPTION_KEY_TYPE, EncryptionType.CUSTOM);
        attributes.put(GcpInstanceTemplate.KEY_ENCRYPTION_METHOD, KeyEncryptionMethod.KMS);
    }
    template.setAttributes(new Json(attributes));
    return template;
}
Also used : HashMap(java.util.HashMap) Json(com.sequenceiq.cloudbreak.common.json.Json) Template(com.sequenceiq.freeipa.entity.Template) InstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate) AzureInstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.instance.AzureInstanceTemplate) AwsInstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.instance.AwsInstanceTemplate) GcpInstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.instance.GcpInstanceTemplate)

Example 3 with Template

use of com.sequenceiq.freeipa.entity.Template in project cloudbreak by hortonworks.

the class InstanceMetaDataToCloudInstanceConverter method convert.

public CloudInstance convert(InstanceMetaData metaDataEntity) {
    InstanceGroup group = metaDataEntity.getInstanceGroup();
    Optional<StackAuthenticationView> stackAuthenticationView = instanceMetaDataService.getStackAuthenticationViewByInstanceMetaDataId(metaDataEntity.getId());
    Template template = metaDataEntity.getInstanceGroup().getTemplate();
    Optional<StackAuthentication> stackAuthentication = stackAuthenticationView.map(StackAuthenticationView::getStackAuthentication);
    InstanceStatus status = getInstanceStatus(metaDataEntity);
    String imageId = stackAuthenticationView.map(StackAuthenticationView::getStackId).map(stackId -> imageService.getByStackId(stackId)).map(ImageEntity::getImageName).orElse(null);
    InstanceTemplate instanceTemplate = stackToCloudStackConverter.buildInstanceTemplate(template, group.getGroupName(), metaDataEntity.getPrivateId(), status, imageId);
    InstanceAuthentication instanceAuthentication = new InstanceAuthentication(stackAuthentication.map(StackAuthentication::getPublicKey).orElse(null), stackAuthentication.map(StackAuthentication::getPublicKeyId).orElse(null), stackAuthentication.map(StackAuthentication::getLoginUserName).orElse(null));
    Map<String, Object> params = new HashMap<>();
    params.put(SUBNET_ID, metaDataEntity.getSubnetId());
    params.put(CloudInstance.INSTANCE_NAME, metaDataEntity.getInstanceName());
    Stack stack = stackAuthenticationView.map(StackAuthenticationView::getStackId).map(stackService::getStackById).orElseThrow(NotFoundException::new);
    Map<String, Object> cloudInstanceParameters = stackToCloudStackConverter.buildCloudInstanceParameters(stack.getEnvironmentCrn(), metaDataEntity);
    params.putAll(cloudInstanceParameters);
    return new CloudInstance(metaDataEntity.getInstanceId(), instanceTemplate, instanceAuthentication, metaDataEntity.getSubnetId(), stack.getAvailabilityZone(), params);
}
Also used : StackAuthentication(com.sequenceiq.freeipa.entity.StackAuthentication) InstanceAuthentication(com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication) HashMap(java.util.HashMap) NotFoundException(javax.ws.rs.NotFoundException) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) InstanceGroup(com.sequenceiq.freeipa.entity.InstanceGroup) Template(com.sequenceiq.freeipa.entity.Template) InstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate) Stack(com.sequenceiq.freeipa.entity.Stack) InstanceStatus(com.sequenceiq.cloudbreak.cloud.model.InstanceStatus) StackAuthenticationView(com.sequenceiq.freeipa.entity.projection.StackAuthenticationView) InstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate)

Example 4 with Template

use of com.sequenceiq.freeipa.entity.Template in project cloudbreak by hortonworks.

the class FreeIpaRecommendationServiceTest method createStack.

private Stack createStack(String instanceType) {
    Stack stack = new Stack();
    stack.setCloudPlatform("AWS");
    stack.setRegion("eu-central-1");
    InstanceGroup instanceGroup = new InstanceGroup();
    instanceGroup.setGroupName("master");
    Template template = new Template();
    template.setInstanceType(instanceType);
    instanceGroup.setTemplate(template);
    stack.getInstanceGroups().add(instanceGroup);
    return stack;
}
Also used : Stack(com.sequenceiq.freeipa.entity.Stack) InstanceGroup(com.sequenceiq.freeipa.entity.InstanceGroup) Template(com.sequenceiq.freeipa.entity.Template)

Example 5 with Template

use of com.sequenceiq.freeipa.entity.Template in project cloudbreak by hortonworks.

the class DefaultInstanceGroupProviderTest method createDefaultTemplateTestVolumeEncryptionAddedWhenAzureAndNoDESAndEncryptionAtHostEnabled.

@Test
void createDefaultTemplateTestVolumeEncryptionAddedWhenAzureAndNoDESAndEncryptionAtHostEnabled() {
    when(entitlementService.isAzureEncryptionAtHostEnabled(ACCOUNT_ID)).thenReturn(Boolean.TRUE);
    Template result = underTest.createDefaultTemplate(CloudPlatform.AZURE, ACCOUNT_ID, null, null, null);
    assertThat(result).isNotNull();
    Json attributes = result.getAttributes();
    assertThat(attributes).isNotNull();
    assertThat(attributes.<Object>getValue(AzureInstanceTemplate.ENCRYPTION_AT_HOST_ENABLED)).isEqualTo(Boolean.TRUE);
}
Also used : JSONObject(net.sf.json.JSONObject) Json(com.sequenceiq.cloudbreak.common.json.Json) Template(com.sequenceiq.freeipa.entity.Template) InstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate) AzureInstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.instance.AzureInstanceTemplate) AwsInstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.instance.AwsInstanceTemplate) Test(org.junit.jupiter.api.Test)

Aggregations

Template (com.sequenceiq.freeipa.entity.Template)44 AwsInstanceTemplate (com.sequenceiq.cloudbreak.cloud.model.instance.AwsInstanceTemplate)33 AzureInstanceTemplate (com.sequenceiq.cloudbreak.cloud.model.instance.AzureInstanceTemplate)31 Test (org.junit.jupiter.api.Test)31 Json (com.sequenceiq.cloudbreak.common.json.Json)27 InstanceTemplate (com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate)26 InstanceTemplateRequest (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceTemplateRequest)21 InstanceGroup (com.sequenceiq.freeipa.entity.InstanceGroup)19 GcpInstanceTemplate (com.sequenceiq.cloudbreak.cloud.model.instance.GcpInstanceTemplate)16 Stack (com.sequenceiq.freeipa.entity.Stack)13 FreeIpaServerRequest (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.FreeIpaServerRequest)10 InstanceGroupRequest (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceGroupRequest)10 NetworkRequest (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.network.NetworkRequest)10 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)8 InstanceMetaData (com.sequenceiq.freeipa.entity.InstanceMetaData)7 HashMap (java.util.HashMap)6 JSONObject (net.sf.json.JSONObject)6 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)4 ImageEntity (com.sequenceiq.freeipa.entity.ImageEntity)3 InstanceGroupNetwork (com.sequenceiq.freeipa.entity.InstanceGroupNetwork)3