Search in sources :

Example 1 with CreateFreeIpaRequest

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.create.CreateFreeIpaRequest in project cloudbreak by hortonworks.

the class FreeIpaCreationHandlerTest method testImageCatalogAndImageIdParemetersArePopulated.

@Test
public void testImageCatalogAndImageIdParemetersArePopulated() {
    EnvironmentDto environmentDto = someEnvironmentWithFreeIpaCreation();
    environmentDto.getFreeIpaCreation().setImageId(IMAGE_ID);
    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();
    assertEquals(IMAGE_CATALOG, freeIpaRequest.getImage().getCatalog());
    assertEquals(IMAGE_ID, freeIpaRequest.getImage().getId());
}
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 2 with CreateFreeIpaRequest

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.create.CreateFreeIpaRequest in project cloudbreak by hortonworks.

the class FreeIpaCreationHandlerTest method testFreeIpaInstanceTypeIsPopulatedIfProvided.

@Test
public void testFreeIpaInstanceTypeIsPopulatedIfProvided() {
    EnvironmentDto environmentDto = someEnvironmentWithFreeIpaCreation();
    environmentDto.getFreeIpaCreation().setInstanceType(INSTANCE_TYPE);
    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();
    assertThat(freeIpaRequest.getInstanceGroups()).extracting(ig -> ig.getInstanceTemplate().getInstanceType()).containsOnly(INSTANCE_TYPE);
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) Environment(com.sequenceiq.environment.environment.domain.Environment) AddDnsZoneForSubnetsRequest(com.sequenceiq.freeipa.api.v1.dns.model.AddDnsZoneForSubnetsRequest) EntitlementService(com.sequenceiq.cloudbreak.auth.altus.EntitlementService) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) LoggerFactory(org.slf4j.LoggerFactory) FreeIpaCreationDto(com.sequenceiq.environment.environment.dto.FreeIpaCreationDto) DnsV1Endpoint(com.sequenceiq.freeipa.api.v1.dns.DnsV1Endpoint) AttachChildEnvironmentRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.attachchildenv.AttachChildEnvironmentRequest) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) InstanceTemplateRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceTemplateRequest) Map(java.util.Map) Region(com.sequenceiq.environment.environment.domain.Region) InstanceGroupRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceGroupRequest) BackupConverter(com.sequenceiq.environment.environment.v1.converter.BackupConverter) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) EventSender(com.sequenceiq.flow.reactor.api.event.EventSender) Set(java.util.Set) ExtendedPollingResult(com.sequenceiq.cloudbreak.polling.ExtendedPollingResult) EventBus(reactor.bus.EventBus) FreeIpaService(com.sequenceiq.environment.environment.service.freeipa.FreeIpaService) Test(org.junit.jupiter.api.Test) PollingService(com.sequenceiq.cloudbreak.polling.PollingService) FreeIpaCreationAwsParametersDto(com.sequenceiq.environment.environment.dto.FreeIpaCreationAwsParametersDto) SupportedPlatforms(com.sequenceiq.environment.configuration.SupportedPlatforms) EnvironmentTags(com.sequenceiq.environment.environment.domain.EnvironmentTags) Optional(java.util.Optional) PollingResult(com.sequenceiq.cloudbreak.polling.PollingResult) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) CreateFreeIpaRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.create.CreateFreeIpaRequest) Mock(org.mockito.Mock) Credential(com.sequenceiq.environment.credential.domain.Credential) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) EnumSource(org.junit.jupiter.params.provider.EnumSource) AuthenticationDto(com.sequenceiq.environment.environment.dto.AuthenticationDto) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) CloudPlatform(com.sequenceiq.cloudbreak.common.mappable.CloudPlatform) ArgumentCaptor(org.mockito.ArgumentCaptor) Event(reactor.bus.Event) FreeIpaCreationAwsSpotParametersDto(com.sequenceiq.environment.environment.dto.FreeIpaCreationAwsSpotParametersDto) Mode(org.junit.jupiter.params.provider.EnumSource.Mode) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Headers(reactor.bus.Event.Headers) ArgumentMatchers.anyInt(org.mockito.ArgumentMatchers.anyInt) AwsInstanceTemplateParameters(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.aws.AwsInstanceTemplateParameters) TelemetryApiConverter(com.sequenceiq.environment.environment.v1.converter.TelemetryApiConverter) Collections.emptyMap(java.util.Collections.emptyMap) Logger(org.slf4j.Logger) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) EnvironmentService(com.sequenceiq.environment.environment.service.EnvironmentService) CloudConnector(com.sequenceiq.cloudbreak.cloud.CloudConnector) Mockito.verify(org.mockito.Mockito.verify) Mockito.never(org.mockito.Mockito.never) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) DescribeFreeIpaResponse(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.describe.DescribeFreeIpaResponse) NetworkDto(com.sequenceiq.environment.network.dto.NetworkDto) CloudPlatformConnectors(com.sequenceiq.cloudbreak.cloud.init.CloudPlatformConnectors) BaseNamedFlowEvent(com.sequenceiq.flow.reactor.api.event.BaseNamedFlowEvent) Collections(java.util.Collections) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) 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 3 with CreateFreeIpaRequest

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.create.CreateFreeIpaRequest in project cloudbreak by hortonworks.

the class FreeIpaCreationHandlerTest method testFreeIpaImageIdIsPopulatedInCaseOfMissingImageCatalog.

@Test
public void testFreeIpaImageIdIsPopulatedInCaseOfMissingImageCatalog() {
    EnvironmentDto environmentDto = someEnvironmentWithFreeIpaCreation();
    environmentDto.getFreeIpaCreation().setImageId(IMAGE_ID);
    environmentDto.getFreeIpaCreation().setImageCatalog(null);
    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().getCatalog());
    assertEquals(IMAGE_ID, freeIpaRequest.getImage().getId());
}
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 4 with CreateFreeIpaRequest

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.create.CreateFreeIpaRequest in project cloudbreak by hortonworks.

the class RepairInstancesServiceTest method testRebuild.

@Test
public void testRebuild() throws Exception {
    Stack stack = createStack(Status.DELETE_COMPLETED, List.of(InstanceStatus.TERMINATED, InstanceStatus.TERMINATED), 2);
    CreateFreeIpaRequest createFreeIpaRequest = new CreateFreeIpaRequest();
    DescribeFreeIpaResponse response = new DescribeFreeIpaResponse();
    when(stackService.getByCrnAndAccountIdEvenIfTerminated(ENVIRONMENT_ID1, ACCOUNT_ID, FREEIPA_CRN)).thenReturn(stack);
    when(stackService.findByEnvironmentCrnAndAccountId(ENVIRONMENT_ID1, ACCOUNT_ID)).thenReturn(Optional.empty());
    when(stackToCreateFreeIpaRequestConverter.convert(eq(stack))).thenReturn(createFreeIpaRequest);
    when(freeIpaCreationService.launchFreeIpa(eq(createFreeIpaRequest), eq(ACCOUNT_ID))).thenReturn(response);
    when(entitlementService.isFreeIpaRebuildEnabled(eq(ACCOUNT_ID))).thenReturn(true);
    RebuildRequest rebuildRequest = new RebuildRequest();
    rebuildRequest.setEnvironmentCrn(ENVIRONMENT_ID1);
    rebuildRequest.setSourceCrn(FREEIPA_CRN);
    assertEquals(response, underTest.rebuild(ACCOUNT_ID, rebuildRequest));
}
Also used : DescribeFreeIpaResponse(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.describe.DescribeFreeIpaResponse) CreateFreeIpaRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.create.CreateFreeIpaRequest) RebuildRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.rebuild.RebuildRequest) Stack(com.sequenceiq.freeipa.entity.Stack) Test(org.junit.jupiter.api.Test)

Example 5 with CreateFreeIpaRequest

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.create.CreateFreeIpaRequest in project cloudbreak by hortonworks.

the class FreeIpaCreationHandler method setImage.

private void setImage(EnvironmentDto environment, CreateFreeIpaRequest createFreeIpaRequest) {
    if (environment.getFreeIpaCreation() != null) {
        String imageCatalog = environment.getFreeIpaCreation().getImageCatalog();
        String imageId = environment.getFreeIpaCreation().getImageId();
        if (!Strings.isNullOrEmpty(imageId)) {
            LOGGER.info("FreeIPA creation with a pre-defined image catalog and image id: '{}', '{}'", imageCatalog, imageId);
            ImageSettingsRequest imageSettings = new ImageSettingsRequest();
            imageSettings.setCatalog(imageCatalog);
            imageSettings.setId(imageId);
            createFreeIpaRequest.setImage(imageSettings);
        } else {
            LOGGER.info("FreeIPA creation without pre-defined image settings. FreeIpa serivce is going to handle default settings.");
        }
    }
}
Also used : ImageSettingsRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.image.ImageSettingsRequest)

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