Search in sources :

Example 46 with InstanceGroup

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

Example 47 with InstanceGroup

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

the class LdapConfigRegisterServiceTest method testRegister.

@Test
void testRegister() {
    Stack stack = new Stack();
    stack.setEnvironmentCrn("env");
    stack.setAccountId("acc");
    stack.setName("name");
    stack.setAppVersion("2.20.0");
    InstanceGroup instanceGroup = new InstanceGroup();
    instanceGroup.setInstanceGroupType(InstanceGroupType.MASTER);
    InstanceMetaData instanceMetaData = new InstanceMetaData();
    instanceMetaData.setDiscoveryFQDN("fqdn");
    instanceMetaData.setPrivateIp("1.1.1.1");
    instanceGroup.setInstanceMetaData(Collections.singleton(instanceMetaData));
    stack.setInstanceGroups(Collections.singleton(instanceGroup));
    when(stackService.getByIdWithListsInTransaction(anyLong())).thenReturn(stack);
    FreeIpa freeIpa = new FreeIpa();
    freeIpa.setDomain("testdomain.local");
    freeIpa.setAdminPassword("asdf");
    when(freeIpaService.findByStackId(anyLong())).thenReturn(freeIpa);
    when(balancedDnsAvailabilityChecker.isBalancedDnsAvailable(stack)).thenReturn(true);
    underTest.register(1L);
    ArgumentCaptor<LdapConfig> ldapConfigArgumentCaptor = ArgumentCaptor.forClass(LdapConfig.class);
    ArgumentCaptor<String> accountIdArgumentCaptor = ArgumentCaptor.forClass(String.class);
    verify(ldapConfigService).createLdapConfig(ldapConfigArgumentCaptor.capture(), accountIdArgumentCaptor.capture());
    assertEquals(stack.getAccountId(), accountIdArgumentCaptor.getValue());
    LdapConfig ldapConfig = ldapConfigArgumentCaptor.getValue();
    assertEquals(ldapConfig.getName(), stack.getName());
    assertEquals(ldapConfig.getEnvironmentCrn(), stack.getEnvironmentCrn());
    String domainComponent = ",dc=testdomain,dc=local";
    assertEquals(ldapConfig.getBindDn(), BIND_DN + domainComponent);
    assertEquals(ldapConfig.getUserSearchBase(), USER_SEARCH_BASE + domainComponent);
    assertEquals(ldapConfig.getGroupSearchBase(), GROUP_SEARCH_BASE + domainComponent);
    assertEquals(ldapConfig.getUserDnPattern(), USER_DN_PATTERN + domainComponent);
    assertEquals(ldapConfig.getServerHost(), "ldap.testdomain.local");
    assertEquals(ldapConfig.getProtocol(), PROTOCOL);
    assertEquals(ldapConfig.getServerPort(), SERVER_PORT);
    assertEquals(ldapConfig.getDomain(), freeIpa.getDomain());
    assertEquals(ldapConfig.getBindPassword(), freeIpa.getAdminPassword());
    assertEquals(ldapConfig.getDirectoryType(), DirectoryType.LDAP);
    assertEquals(ldapConfig.getUserNameAttribute(), USER_NAME_ATTRIBUTE);
    assertEquals(ldapConfig.getUserObjectClass(), USER_OBJECT_CLASS);
    assertEquals(ldapConfig.getGroupMemberAttribute(), GROUP_MEMBER_ATTRIBUTE);
    assertEquals(ldapConfig.getGroupNameAttribute(), GROUP_NAME_ATTRIBUTE);
    assertEquals(ldapConfig.getGroupObjectClass(), GROUP_OBJECT_CLASS);
}
Also used : InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) LdapConfig(com.sequenceiq.freeipa.ldap.LdapConfig) FreeIpa(com.sequenceiq.freeipa.entity.FreeIpa) Stack(com.sequenceiq.freeipa.entity.Stack) InstanceGroup(com.sequenceiq.freeipa.entity.InstanceGroup) Test(org.junit.jupiter.api.Test)

Example 48 with InstanceGroup

use of com.sequenceiq.freeipa.entity.InstanceGroup 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 49 with InstanceGroup

use of com.sequenceiq.freeipa.entity.InstanceGroup 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 50 with InstanceGroup

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

Aggregations

InstanceGroup (com.sequenceiq.freeipa.entity.InstanceGroup)60 Stack (com.sequenceiq.freeipa.entity.Stack)32 InstanceMetaData (com.sequenceiq.freeipa.entity.InstanceMetaData)31 Test (org.junit.jupiter.api.Test)30 Template (com.sequenceiq.freeipa.entity.Template)18 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)16 FreeIpaServerRequest (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.FreeIpaServerRequest)11 Json (com.sequenceiq.cloudbreak.common.json.Json)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 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)9 AwsInstanceTemplate (com.sequenceiq.cloudbreak.cloud.model.instance.AwsInstanceTemplate)9 InstanceGroupNetwork (com.sequenceiq.freeipa.entity.InstanceGroupNetwork)9 HashSet (java.util.HashSet)9 AzureInstanceTemplate (com.sequenceiq.cloudbreak.cloud.model.instance.AzureInstanceTemplate)8 FreeIpa (com.sequenceiq.freeipa.entity.FreeIpa)7 InstanceTemplate (com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate)6 InstanceTemplateRequest (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceTemplateRequest)6 HashMap (java.util.HashMap)6 CreateFreeIpaRequest (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.create.CreateFreeIpaRequest)5