Search in sources :

Example 11 with CreateFreeIpaRequest

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);
}
Also used : CreateFreeIpaRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.create.CreateFreeIpaRequest) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) Test(org.junit.jupiter.api.Test)

Example 12 with CreateFreeIpaRequest

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());
}
Also used : Credential(com.sequenceiq.environment.credential.domain.Credential) CloudConnector(com.sequenceiq.cloudbreak.cloud.CloudConnector) CreateFreeIpaRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.create.CreateFreeIpaRequest) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) Environment(com.sequenceiq.environment.environment.domain.Environment) ExtendedPollingResult(com.sequenceiq.cloudbreak.polling.ExtendedPollingResult) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 13 with CreateFreeIpaRequest

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());
    });
}
Also used : Credential(com.sequenceiq.environment.credential.domain.Credential) CloudConnector(com.sequenceiq.cloudbreak.cloud.CloudConnector) CreateFreeIpaRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.create.CreateFreeIpaRequest) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) DnsV1Endpoint(com.sequenceiq.freeipa.api.v1.dns.DnsV1Endpoint) InstanceTemplateRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceTemplateRequest) Environment(com.sequenceiq.environment.environment.domain.Environment) ExtendedPollingResult(com.sequenceiq.cloudbreak.polling.ExtendedPollingResult) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 14 with CreateFreeIpaRequest

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;
}
Also used : CreateFreeIpaRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.create.CreateFreeIpaRequest) SecurityGroupRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.security.SecurityGroupRequest) FreeIpaServerRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.FreeIpaServerRequest)

Example 15 with 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);
}
Also used : StackAuthenticationRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.security.StackAuthenticationRequest)

Aggregations

CreateFreeIpaRequest (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.create.CreateFreeIpaRequest)23 Test (org.junit.jupiter.api.Test)18 InstanceGroupRequest (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceGroupRequest)10 ValidationResult (com.sequenceiq.cloudbreak.validation.ValidationResult)6 Stack (com.sequenceiq.freeipa.entity.Stack)6 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)6 CloudConnector (com.sequenceiq.cloudbreak.cloud.CloudConnector)5 ExtendedPollingResult (com.sequenceiq.cloudbreak.polling.ExtendedPollingResult)5 Telemetry (com.sequenceiq.common.api.telemetry.model.Telemetry)5 Credential (com.sequenceiq.environment.credential.domain.Credential)5 Environment (com.sequenceiq.environment.environment.domain.Environment)5 EnvironmentDto (com.sequenceiq.environment.environment.dto.EnvironmentDto)5 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)5 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)4 Backup (com.sequenceiq.freeipa.api.model.Backup)4 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)3 TelemetryRequest (com.sequenceiq.common.api.telemetry.request.TelemetryRequest)3 FreeIpaServerRequest (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.FreeIpaServerRequest)3 ImageSettingsRequest (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.image.ImageSettingsRequest)3 InstanceTemplateRequest (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceTemplateRequest)3