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;
}
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);
}
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;
}
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());
}
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++;
}
}
Aggregations