Search in sources :

Example 26 with Template

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

the class StackToCloudStackConverter method buildInstance.

private CloudInstance buildInstance(Stack stack, InstanceMetaData instanceMetaData, InstanceGroup instanceGroup, StackAuthentication stackAuthentication, Long privateId, InstanceStatus status, String imageName) {
    LOGGER.debug("Instance metadata is {}", instanceMetaData);
    String id = instanceMetaData == null ? null : instanceMetaData.getInstanceId();
    String name = instanceGroup.getGroupName();
    Template template = instanceGroup.getTemplate();
    InstanceTemplate instanceTemplate = buildInstanceTemplate(template, name, privateId, status, imageName);
    InstanceAuthentication instanceAuthentication = buildInstanceAuthentication(stackAuthentication);
    Map<String, Object> parameters = buildCloudInstanceParameters(stack.getEnvironmentCrn(), instanceMetaData);
    return new CloudInstance(id, instanceTemplate, instanceAuthentication, instanceMetaData != null ? instanceMetaData.getSubnetId() : null, instanceMetaData != null ? instanceMetaData.getAvailabilityZone() : null, parameters);
}
Also used : InstanceAuthentication(com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) Template(com.sequenceiq.freeipa.entity.Template) InstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate) InstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate)

Example 27 with Template

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

the class StackToCloudStackConverter method buildInstanceGroups.

private List<Group> buildInstanceGroups(Stack stack, List<InstanceGroup> instanceGroups, Collection<String> deleteRequests, String imageName, Optional<CloudFileSystemView> fileSystemView) {
    String cloudPlatform = stack.getCloudPlatform();
    // sort by name to avoid shuffling the different instance groups
    Collections.sort(instanceGroups);
    List<Group> groups = new ArrayList<>();
    InstanceAuthentication instanceAuthentication = buildInstanceAuthentication(stack.getStackAuthentication());
    for (InstanceGroup instanceGroup : instanceGroups) {
        if (instanceGroup.getTemplate() != null) {
            CloudInstance skeleton = null;
            List<CloudInstance> instances = new ArrayList<>();
            Template template = instanceGroup.getTemplate();
            // existing instances
            for (InstanceMetaData metaData : instanceGroup.getNotDeletedInstanceMetaDataSet()) {
                InstanceStatus status = getInstanceStatus(metaData, deleteRequests);
                instances.add(buildInstance(stack, metaData, instanceGroup, stack.getStackAuthentication(), metaData.getPrivateId(), status, imageName));
            }
            if (instanceGroup.getNodeCount() == 0) {
                skeleton = buildInstance(stack, null, instanceGroup, stack.getStackAuthentication(), 0L, CREATE_REQUESTED, imageName);
            }
            Json attributes = instanceGroup.getAttributes();
            Map<String, Object> fields = attributes == null ? Collections.emptyMap() : attributes.getMap();
            Integer rootVolumeSize = instanceGroup.getTemplate().getRootVolumeSize();
            if (Objects.isNull(rootVolumeSize)) {
                rootVolumeSize = defaultRootVolumeSizeProvider.getForPlatform(cloudPlatform);
            }
            GroupNetwork groupNetwork = buildGroupNetwork(stack.getNetwork(), instanceGroup);
            groups.add(new Group(instanceGroup.getGroupName(), InstanceGroupType.GATEWAY, instances, buildSecurity(instanceGroup), skeleton, fields, instanceAuthentication, instanceAuthentication.getLoginUserName(), instanceAuthentication.getPublicKey(), rootVolumeSize, fileSystemView, groupNetwork, getUserDefinedTags(stack)));
        }
    }
    return groups;
}
Also used : Group(com.sequenceiq.cloudbreak.cloud.model.Group) AzureResourceGroup(com.sequenceiq.environment.api.v1.environment.model.request.azure.AzureResourceGroup) InstanceGroup(com.sequenceiq.freeipa.entity.InstanceGroup) InstanceAuthentication(com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication) ArrayList(java.util.ArrayList) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) Json(com.sequenceiq.cloudbreak.common.json.Json) InstanceGroup(com.sequenceiq.freeipa.entity.InstanceGroup) Template(com.sequenceiq.freeipa.entity.Template) InstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate) InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) InstanceStatus(com.sequenceiq.cloudbreak.cloud.model.InstanceStatus) InstanceGroupNetwork(com.sequenceiq.freeipa.entity.InstanceGroupNetwork) GroupNetwork(com.sequenceiq.cloudbreak.cloud.model.GroupNetwork)

Example 28 with Template

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

the class StackToCloudStackConverterTest method testBuildInstance.

@Test
public void testBuildInstance() throws Exception {
    InstanceMetaData instanceMetaData = mock(InstanceMetaData.class);
    InstanceGroup instanceGroup = mock(InstanceGroup.class);
    ImageEntity imageEntity = mock(ImageEntity.class);
    when(imageService.getByStack(any())).thenReturn(imageEntity);
    when(imageEntity.getImageName()).thenReturn(IMAGE_NAME);
    when(instanceMetaData.getInstanceId()).thenReturn(INSTANCE_ID);
    when(instanceGroup.getGroupName()).thenReturn(GROUP_NAME);
    Template template = mock(Template.class);
    when(instanceGroup.getTemplate()).thenReturn(template);
    when(template.getVolumeCount()).thenReturn(VOLUME_COUNT);
    CloudInstance cloudInstance = underTest.buildInstance(stack, instanceMetaData, instanceGroup, stackAuthentication, 0L, InstanceStatus.CREATED);
    assertEquals(INSTANCE_ID, cloudInstance.getInstanceId());
}
Also used : InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) ImageEntity(com.sequenceiq.freeipa.entity.ImageEntity) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) InstanceGroup(com.sequenceiq.freeipa.entity.InstanceGroup) Template(com.sequenceiq.freeipa.entity.Template) Test(org.junit.Test)

Example 29 with Template

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

the class InstanceGroupRequestToInstanceGroupConverterTest method testConvertWithNullTemplate.

@Test
public void testConvertWithNullTemplate() {
    int nodeCount = 2;
    InstanceGroupRequest request = new InstanceGroupRequest();
    request.setName(NAME);
    request.setType(InstanceGroupType.MASTER);
    request.setNodeCount(nodeCount);
    Template template = mock(Template.class);
    SecurityGroupRequest securityGroupRequest = mock(SecurityGroupRequest.class);
    SecurityGroup securityGroup = mock(SecurityGroup.class);
    request.setSecurityGroup(securityGroupRequest);
    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();
    // GIVEN
    given(defaultInstanceGroupProvider.createDefaultTemplate(eq(MOCK), eq(ACCOUNT_ID), eq(null), eq(null), eq(null))).willReturn(template);
    given(securityGroupConverter.convert(eq(securityGroupRequest))).willReturn(securityGroup);
    // WHEN
    InstanceGroup result = underTest.convert(request, networkRequest, ACCOUNT_ID, stack, freeIpaServerRequest, detailedEnvironmentResponse, createAndGetCloudArgsForIgCoverterMap(null, null, null));
    // THEN
    assertThat(result).isNotNull();
    assertThat(result.getGroupName()).isEqualTo(NAME);
    assertThat(result.getInstanceGroupType()).isEqualTo(InstanceGroupType.MASTER);
    assertThat(result.getSecurityGroup()).isEqualTo(securityGroup);
    assertThat(result.getNodeCount()).isEqualTo(nodeCount);
    assertThat(result.getInstanceMetaData().size()).isEqualTo(nodeCount);
    int i = 0;
    for (InstanceMetaData instanceMetaData : result.getInstanceMetaData()) {
        assertThat(instanceMetaData.getInstanceGroup()).isEqualTo(result);
        assertThat(instanceMetaData.getDiscoveryFQDN()).startsWith(HOSTNAME + i);
        i++;
    }
}
Also used : InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) InstanceGroupRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceGroupRequest) SecurityGroupRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.security.SecurityGroupRequest) NetworkRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.network.NetworkRequest) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) SecurityGroup(com.sequenceiq.freeipa.entity.SecurityGroup) 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 30 with Template

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

the class InstanceGroupRequestToInstanceGroupConverterTest method convertTestTemplateConversion.

@Test
void convertTestTemplateConversion() {
    InstanceGroupRequest request = new InstanceGroupRequest();
    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();
    InstanceTemplateRequest instanceTemplateRequest = mock(InstanceTemplateRequest.class);
    request.setInstanceTemplateRequest(instanceTemplateRequest);
    Template template = mock(Template.class);
    when(templateConverter.convert(instanceTemplateRequest, MOCK, ACCOUNT_ID, "dummyDiskEncryptionSetId", "encryptionKey", "awsEncryptionKeyArn")).thenReturn(template);
    InstanceGroup result = underTest.convert(request, networkRequest, ACCOUNT_ID, stack, freeIpaServerRequest, detailedEnvironmentResponse, createAndGetCloudArgsForIgCoverterMap("dummyDiskEncryptionSetId", "encryptionKey", "awsEncryptionKeyArn"));
    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) 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) 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