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