use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceGroupRequest in project cloudbreak by hortonworks.
the class InstanceGroupRequestToInstanceGroupConverterTest method convertTestDefaultTemplateConversionWithAwsEncryptionKey.
@Test
void convertTestDefaultTemplateConversionWithAwsEncryptionKey() {
InstanceGroupRequest request = new InstanceGroupRequest();
Stack stack = new Stack();
stack.setAccountId(ACCOUNT_ID);
stack.setCloudPlatform(AWS.name());
stack.setName(NAME);
FreeIpaServerRequest freeIpaServerRequest = new FreeIpaServerRequest();
freeIpaServerRequest.setHostname(HOSTNAME);
freeIpaServerRequest.setDomain(DOMAINNAME);
NetworkRequest networkRequest = new NetworkRequest();
DetailedEnvironmentResponse detailedEnvironmentResponse = new DetailedEnvironmentResponse();
Template template = new Template();
Map<String, Object> json = new HashMap<>();
json.put(AwsInstanceTemplate.VOLUME_ENCRYPTION_KEY_ID, "dummyAwsEncryptionKeyArn");
json.put(AwsInstanceTemplate.VOLUME_ENCRYPTION_KEY_TYPE, EncryptionType.CUSTOM);
template.setAttributes(new Json(json));
when(defaultInstanceGroupProvider.createDefaultTemplate(AWS, ACCOUNT_ID, null, null, "dummyAwsEncryptionKeyArn")).thenReturn(template);
InstanceGroup result = underTest.convert(request, networkRequest, ACCOUNT_ID, stack, freeIpaServerRequest, detailedEnvironmentResponse, createAndGetCloudArgsForIgCoverterMap(null, null, "dummyAwsEncryptionKeyArn"));
assertThat(result).isNotNull();
assertThat(result.getTemplate()).isSameAs(template);
}
use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceGroupRequest 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);
}
use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceGroupRequest 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);
}
use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceGroupRequest in project cloudbreak by hortonworks.
the class FreeIpaCreationHandlerTest method testSpotParameters.
@Test
public void testSpotParameters() {
EnvironmentDto environmentDto = someEnvironmentWithFreeIpaCreation();
Environment environment = new Environment();
environment.setCreateFreeIpa(true);
Credential credential = new Credential();
environment.setCredential(credential);
int spotPercentage = 100;
Double spotMaxPrice = 0.9;
environmentDto.getFreeIpaCreation().setAws(FreeIpaCreationAwsParametersDto.builder().withSpot(FreeIpaCreationAwsSpotParametersDto.builder().withMaxPrice(spotMaxPrice).withPercentage(spotPercentage).build()).build());
environmentDto.setCredential(new Credential());
ExtendedPollingResult extendedPollingResult = new ExtendedPollingResult.ExtendedPollingResultBuilder().success().build();
when(environmentService.findEnvironmentById(ENVIRONMENT_ID)).thenReturn(Optional.of(environment));
when(supportedPlatforms.supportedPlatformForFreeIpa(environment.getCloudPlatform())).thenReturn(true);
when(freeIpaService.describe(ENVIRONMENT_CRN)).thenReturn(Optional.empty());
when(connectors.getDefault(any())).thenReturn(mock(CloudConnector.class));
when(freeIpaPollingService.pollWithTimeout(any(FreeIpaCreationRetrievalTask.class), any(FreeIpaPollerObject.class), anyLong(), anyInt(), anyInt())).thenReturn(extendedPollingResult);
victim.accept(new Event<>(environmentDto));
ArgumentCaptor<CreateFreeIpaRequest> freeIpaRequestCaptor = ArgumentCaptor.forClass(CreateFreeIpaRequest.class);
verify(freeIpaService).create(freeIpaRequestCaptor.capture());
CreateFreeIpaRequest freeIpaRequest = freeIpaRequestCaptor.getValue();
freeIpaRequest.getInstanceGroups().stream().map(InstanceGroupRequest::getInstanceTemplate).map(InstanceTemplateRequest::getAws).map(AwsInstanceTemplateParameters::getSpot).forEach(spotParameters -> {
assertEquals(spotMaxPrice, spotParameters.getMaxPrice());
assertEquals(spotPercentage, spotParameters.getPercentage());
});
}
use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceGroupRequest in project cloudbreak by hortonworks.
the class FreeIpaCreationHandler method createInstanceGroupRequests.
private List<InstanceGroupRequest> createInstanceGroupRequests(CreateFreeIpaRequest createFreeIpaRequest, SecurityGroupRequest securityGroupRequest, EnvironmentDto environment, boolean multiAzRequired) {
List<InstanceGroupRequest> instanceGroupRequests = new LinkedList<>();
FreeIpaCreationDto freeIpaCreation = environment.getFreeIpaCreation();
InstanceGroupRequest instanceGroupRequest = new InstanceGroupRequest();
instanceGroupRequest.setName(MASTER_GROUP_NAME);
instanceGroupRequest.setNodeCount(freeIpaCreation.getInstanceCountByGroup());
instanceGroupRequest.setType(InstanceGroupType.MASTER);
instanceGroupRequest.setSecurityGroup(securityGroupRequest);
instanceGroupRequest.setInstanceTemplateRequest(createInstanceTemplate(freeIpaCreation));
if (multiAzRequired && multiAzValidator.suportedMultiAzForEnvironment(environment.getCloudPlatform())) {
FreeIpaNetworkProvider freeIpaNetworkProvider = freeIpaNetworkProviderMapByCloudPlatform.get(CloudPlatform.valueOf(environment.getCloudPlatform()));
if (freeIpaNetworkProvider != null) {
InstanceGroupNetworkRequest instanceGroupNetworkRequest = freeIpaNetworkProvider.networkByGroup(environment);
instanceGroupRequest.setNetwork(instanceGroupNetworkRequest);
createFreeIpaRequest.getPlacement().setAvailabilityZone(freeIpaNetworkProvider.availabilityZone(instanceGroupNetworkRequest, environment));
}
}
instanceGroupRequests.add(instanceGroupRequest);
return instanceGroupRequests;
}
Aggregations