Search in sources :

Example 21 with Template

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

the class InstanceGroupRequestToInstanceGroupConverterTest method convertTestTemplateConversionWithDiskEncryptionSetId.

@Test
void convertTestTemplateConversionWithDiskEncryptionSetId() {
    InstanceGroupRequest request = new InstanceGroupRequest();
    Stack stack = new Stack();
    stack.setAccountId(ACCOUNT_ID);
    stack.setCloudPlatform(AZURE.name());
    stack.setName(NAME);
    FreeIpaServerRequest freeIpaServerRequest = new FreeIpaServerRequest();
    freeIpaServerRequest.setHostname(HOSTNAME);
    freeIpaServerRequest.setDomain(DOMAINNAME);
    NetworkRequest networkRequest = new NetworkRequest();
    DetailedEnvironmentResponse detailedEnvironmentResponse = new DetailedEnvironmentResponse();
    InstanceTemplateRequest instanceTemplateRequest = mock(InstanceTemplateRequest.class);
    request.setInstanceTemplateRequest(instanceTemplateRequest);
    Template template = new Template();
    Map<String, Object> json = new HashMap<>();
    json.put(AzureInstanceTemplate.DISK_ENCRYPTION_SET_ID, "dummyDiskEncryptionSetId");
    json.put(AzureInstanceTemplate.MANAGED_DISK_ENCRYPTION_WITH_CUSTOM_KEY_ENABLED, Boolean.TRUE);
    template.setAttributes(new Json(json));
    when(templateConverter.convert(instanceTemplateRequest, AZURE, ACCOUNT_ID, "dummyDiskEncryptionSetId", null, null)).thenReturn(template);
    InstanceGroup result = underTest.convert(request, networkRequest, ACCOUNT_ID, stack, freeIpaServerRequest, detailedEnvironmentResponse, createAndGetCloudArgsForIgCoverterMap("dummyDiskEncryptionSetId", null, null));
    assertThat(result).isNotNull();
    assertThat(result.getTemplate()).isSameAs(template);
}
Also used : InstanceGroupRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceGroupRequest) HashMap(java.util.HashMap) NetworkRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.network.NetworkRequest) Json(com.sequenceiq.cloudbreak.common.json.Json) Stack(com.sequenceiq.freeipa.entity.Stack) Template(com.sequenceiq.freeipa.entity.Template) AzureInstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.instance.AzureInstanceTemplate) AwsInstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.instance.AwsInstanceTemplate) InstanceGroup(com.sequenceiq.freeipa.entity.InstanceGroup) InstanceTemplateRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceTemplateRequest) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) FreeIpaServerRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.FreeIpaServerRequest) Test(org.junit.jupiter.api.Test)

Example 22 with Template

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

the class InstanceGroupRequestToInstanceGroupConverterTest method convertTestDefaultTemplateConversionWithGcpEncryptionKey.

@Test
void convertTestDefaultTemplateConversionWithGcpEncryptionKey() {
    InstanceGroupRequest request = new InstanceGroupRequest();
    InstanceTemplateRequest instanceTemplateRequest = mock(InstanceTemplateRequest.class);
    request.setInstanceTemplateRequest(instanceTemplateRequest);
    Template template = mock(Template.class);
    Stack stack = new Stack();
    stack.setAccountId(ACCOUNT_ID);
    stack.setCloudPlatform(MOCK.name());
    stack.setName(NAME);
    FreeIpaServerRequest freeIpaServerRequest = new FreeIpaServerRequest();
    freeIpaServerRequest.setHostname(HOSTNAME);
    freeIpaServerRequest.setDomain(DOMAINNAME);
    NetworkRequest networkRequest = new NetworkRequest();
    DetailedEnvironmentResponse detailedEnvironmentResponse = new DetailedEnvironmentResponse();
    when(templateConverter.convert(instanceTemplateRequest, MOCK, ACCOUNT_ID, null, "dummyEncryptionKey", null)).thenReturn(template);
    InstanceGroup result = underTest.convert(request, networkRequest, ACCOUNT_ID, stack, freeIpaServerRequest, detailedEnvironmentResponse, createAndGetCloudArgsForIgCoverterMap(null, "dummyEncryptionKey", null));
    assertThat(result).isNotNull();
    assertThat(result.getTemplate()).isSameAs(template);
}
Also used : InstanceGroupRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceGroupRequest) InstanceTemplateRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceTemplateRequest) NetworkRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.network.NetworkRequest) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) FreeIpaServerRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.FreeIpaServerRequest) Template(com.sequenceiq.freeipa.entity.Template) AzureInstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.instance.AzureInstanceTemplate) AwsInstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.instance.AwsInstanceTemplate) Stack(com.sequenceiq.freeipa.entity.Stack) InstanceGroup(com.sequenceiq.freeipa.entity.InstanceGroup) Test(org.junit.jupiter.api.Test)

Example 23 with Template

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

the class DefaultInstanceGroupProvider method createDefaultTemplate.

public Template createDefaultTemplate(CloudPlatform cloudPlatform, String accountId, String diskEncryptionSetId, String gcpKmsEncryptionKey, String awsKmsEncryptionKey) {
    Template template = new Template();
    template.setName(missingResourceNameGenerator.generateName(APIResourceType.TEMPLATE));
    template.setStatus(ResourceStatus.DEFAULT);
    template.setRootVolumeSize(defaultRootVolumeSizeProvider.getForPlatform(cloudPlatform.name()));
    template.setVolumeCount(0);
    template.setVolumeSize(0);
    template.setInstanceType(defaultInstanceTypeProvider.getForPlatform(cloudPlatform.name()));
    template.setAccountId(accountId);
    if (cloudPlatform == AWS) {
        if (awsKmsEncryptionKey != null) {
            template.setAttributes(new Json(Map.<String, Object>ofEntries(entry(AwsInstanceTemplate.EBS_ENCRYPTION_ENABLED, Boolean.TRUE), entry(InstanceTemplate.VOLUME_ENCRYPTION_KEY_TYPE, EncryptionType.CUSTOM.name()), entry(InstanceTemplate.VOLUME_ENCRYPTION_KEY_ID, awsKmsEncryptionKey))));
        } else {
            template.setAttributes(new Json(Map.<String, Object>ofEntries(entry(AwsInstanceTemplate.EBS_ENCRYPTION_ENABLED, Boolean.TRUE), entry(InstanceTemplate.VOLUME_ENCRYPTION_KEY_TYPE, EncryptionType.DEFAULT.name()))));
        }
    }
    if (cloudPlatform == AZURE) {
        if (diskEncryptionSetId != null) {
            template.setAttributes(new Json(Map.<String, Object>ofEntries(entry(AzureInstanceTemplate.DISK_ENCRYPTION_SET_ID, diskEncryptionSetId), entry(AzureInstanceTemplate.MANAGED_DISK_ENCRYPTION_WITH_CUSTOM_KEY_ENABLED, Boolean.TRUE))));
        }
        if (entitlementService.isAzureEncryptionAtHostEnabled(accountId)) {
            Map<String, Object> attributesJson;
            if (template.getAttributes() != null) {
                attributesJson = template.getAttributes().getMap();
            } else {
                attributesJson = new HashMap<>();
            }
            attributesJson.put(AzureInstanceTemplate.ENCRYPTION_AT_HOST_ENABLED, Boolean.TRUE);
            template.setAttributes(new Json(attributesJson));
        }
    }
    if (cloudPlatform == CloudPlatform.GCP && gcpKmsEncryptionKey != null) {
        template.setAttributes(new Json(Map.<String, Object>ofEntries(entry(GcpInstanceTemplate.VOLUME_ENCRYPTION_KEY_ID, gcpKmsEncryptionKey), entry(GcpInstanceTemplate.VOLUME_ENCRYPTION_KEY_TYPE, EncryptionType.CUSTOM), entry(GcpInstanceTemplate.KEY_ENCRYPTION_METHOD, KeyEncryptionMethod.KMS))));
    }
    return template;
}
Also used : 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 24 with Template

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

the class InstanceGroupToInstanceGroupDetailsConverter method convert.

public InstanceGroupDetails convert(InstanceGroup source) {
    InstanceGroupDetails instanceGroupDetails = new InstanceGroupDetails();
    instanceGroupDetails.setGroupName(source.getGroupName());
    instanceGroupDetails.setGroupType(source.getInstanceGroupType().name());
    instanceGroupDetails.setNodeCount(source.getNodeCount());
    Template template = source.getTemplate();
    if (template != null) {
        instanceGroupDetails.setInstanceType(template.getInstanceType());
        instanceGroupDetails.setAttributes(filterAttributes(template.getAttributes().getMap()));
        instanceGroupDetails.setRootVolumeSize(template.getRootVolumeSize());
        VolumeDetails volumeDetails = new VolumeDetails();
        volumeDetails.setVolumeType(template.getVolumeType());
        volumeDetails.setVolumeSize(template.getVolumeSize());
        volumeDetails.setVolumeCount(template.getVolumeCount());
        instanceGroupDetails.setVolumes(List.of(volumeDetails));
    }
    return instanceGroupDetails;
}
Also used : InstanceGroupDetails(com.sequenceiq.cloudbreak.structuredevent.event.InstanceGroupDetails) VolumeDetails(com.sequenceiq.cloudbreak.structuredevent.event.VolumeDetails) Template(com.sequenceiq.freeipa.entity.Template)

Example 25 with Template

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

the class BootstrapServiceTest method createInstance.

private InstanceMetaData createInstance(String instanceId, String fqdn) {
    InstanceMetaData im = new InstanceMetaData();
    im.setInstanceId(instanceId);
    im.setDiscoveryFQDN(fqdn);
    im.setPrivateId(1L);
    InstanceGroup instanceGroup = new InstanceGroup();
    Template template = new Template();
    template.setInstanceType("GW");
    instanceGroup.setTemplate(template);
    instanceGroup.setGroupName("TADA");
    im.setInstanceGroup(instanceGroup);
    return im;
}
Also used : InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) InstanceGroup(com.sequenceiq.freeipa.entity.InstanceGroup) Template(com.sequenceiq.freeipa.entity.Template)

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