use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.create.CreateFreeIpaRequest in project cloudbreak by hortonworks.
the class FreeIpaV1ControllerTest method createValidationError.
@Test
void createValidationError() {
CreateFreeIpaRequest freeIpaRequest = new CreateFreeIpaRequest();
when(createFreeIpaRequestValidator.validate(freeIpaRequest)).thenReturn(ValidationResult.builder().error("error").build());
BadRequestException badRequestException = assertThrows(BadRequestException.class, () -> underTest.create(freeIpaRequest));
assertEquals("error", badRequestException.getMessage());
verify(creationService, never()).launchFreeIpa(freeIpaRequest, ACCOUNT_ID);
}
use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.create.CreateFreeIpaRequest in project cloudbreak by hortonworks.
the class FreeIpaCreationHandlerTest method testFreeIpaImageIsNullInCaseOfMissingImageId.
@Test
public void testFreeIpaImageIsNullInCaseOfMissingImageId() {
EnvironmentDto environmentDto = someEnvironmentWithFreeIpaCreation();
environmentDto.getFreeIpaCreation().setImageId(null);
environmentDto.getFreeIpaCreation().setImageCatalog(IMAGE_CATALOG);
environmentDto.setCredential(new Credential());
Environment environment = new Environment();
environment.setCreateFreeIpa(true);
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();
assertNull(freeIpaRequest.getImage());
}
use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.create.CreateFreeIpaRequest 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.create.CreateFreeIpaRequest in project cloudbreak by hortonworks.
the class FreeIpaCreationHandler method createFreeIpaRequest.
private CreateFreeIpaRequest createFreeIpaRequest(EnvironmentDto environment) {
boolean multiAzRequired = environment.getFreeIpaCreation().isEnableMultiAz();
CreateFreeIpaRequest createFreeIpaRequest = new CreateFreeIpaRequest();
createFreeIpaRequest.setEnvironmentCrn(environment.getResourceCrn());
createFreeIpaRequest.setName(environment.getName() + "-freeipa");
FreeIpaServerRequest freeIpaServerRequest = freeIpaServerRequestProvider.create(environment);
createFreeIpaRequest.setFreeIpa(freeIpaServerRequest);
setPlacementAndNetwork(environment, createFreeIpaRequest, multiAzRequired);
setAuthentication(environment.getAuthentication(), createFreeIpaRequest);
setTelemetry(environment, createFreeIpaRequest);
setBackup(environment, createFreeIpaRequest);
setTags(environment, createFreeIpaRequest);
setImage(environment, createFreeIpaRequest);
SecurityGroupRequest securityGroupRequest = null;
if (environment.getSecurityAccess() != null) {
securityGroupRequest = createSecurityGroupRequest(environment.getSecurityAccess());
}
createFreeIpaRequest.setInstanceGroups(createInstanceGroupRequests(createFreeIpaRequest, securityGroupRequest, environment, multiAzRequired));
setVariant(environment, createFreeIpaRequest, multiAzRequired);
setUseCcm(environment.getExperimentalFeatures().getTunnel(), createFreeIpaRequest);
return createFreeIpaRequest;
}
use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.create.CreateFreeIpaRequest in project cloudbreak by hortonworks.
the class FreeIpaCreationHandler method setAuthentication.
private void setAuthentication(AuthenticationDto authentication, CreateFreeIpaRequest createFreeIpaRequest) {
StackAuthenticationRequest stackAuthenticationRequest = new StackAuthenticationRequest();
stackAuthenticationRequest.setLoginUserName(authentication.getLoginUserName());
stackAuthenticationRequest.setPublicKey(authentication.getPublicKey());
stackAuthenticationRequest.setPublicKeyId(authentication.getPublicKeyId());
createFreeIpaRequest.setAuthentication(stackAuthenticationRequest);
}
Aggregations