Search in sources :

Example 66 with Credential

use of com.sequenceiq.environment.credential.domain.Credential in project cloudbreak by hortonworks.

the class FreeIpaCreationHandlerTest method testIfFreeIpaPollingServiceReturnsWithUnsuccessfulResultThenCreationFailedEventShouldBeSent.

@ParameterizedTest
@EnumSource(value = PollingResult.class, names = "SUCCESS", mode = Mode.EXCLUDE)
public void testIfFreeIpaPollingServiceReturnsWithUnsuccessfulResultThenCreationFailedEventShouldBeSent(PollingResult pollingResult) {
    EnvironmentDto environmentDto = someEnvironmentWithFreeIpaCreation();
    environmentDto.setCredential(new Credential());
    Environment environment = mock(Environment.class);
    when(environment.getCloudPlatform()).thenReturn(environmentDto.getCloudPlatform());
    when(environment.isCreateFreeIpa()).thenReturn(environmentDto.getFreeIpaCreation().getCreate());
    ExtendedPollingResult result = mock(ExtendedPollingResult.class);
    when(result.getPollingResult()).thenReturn(pollingResult);
    when(environmentService.findEnvironmentById(environmentDto.getId())).thenReturn(Optional.of(environment));
    when(supportedPlatforms.supportedPlatformForFreeIpa(environmentDto.getCloudPlatform())).thenReturn(true);
    when(connectors.getDefault(any())).thenReturn(mock(CloudConnector.class));
    when(freeIpaPollingService.pollWithTimeout(any(FreeIpaCreationRetrievalTask.class), any(FreeIpaPollerObject.class), anyLong(), anyInt(), anyInt())).thenReturn(result);
    victim.accept(new Event<>(environmentDto));
    verify(eventBus).notify(anyString(), any(Event.class));
    verify(environmentService, times(1)).findEnvironmentById(anyLong());
    verify(environmentService, times(1)).findEnvironmentById(environmentDto.getId());
    verify(supportedPlatforms, times(1)).supportedPlatformForFreeIpa(anyString());
    verify(supportedPlatforms, times(1)).supportedPlatformForFreeIpa(environmentDto.getCloudPlatform());
    verify(freeIpaPollingService, times(1)).pollWithTimeout(any(FreeIpaCreationRetrievalTask.class), any(FreeIpaPollerObject.class), anyLong(), anyInt(), anyInt());
}
Also used : Credential(com.sequenceiq.environment.credential.domain.Credential) CloudConnector(com.sequenceiq.cloudbreak.cloud.CloudConnector) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) Environment(com.sequenceiq.environment.environment.domain.Environment) Event(reactor.bus.Event) BaseNamedFlowEvent(com.sequenceiq.flow.reactor.api.event.BaseNamedFlowEvent) ExtendedPollingResult(com.sequenceiq.cloudbreak.polling.ExtendedPollingResult) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 67 with Credential

use of com.sequenceiq.environment.credential.domain.Credential 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 68 with Credential

use of com.sequenceiq.environment.credential.domain.Credential 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 69 with Credential

use of com.sequenceiq.environment.credential.domain.Credential in project cloudbreak by hortonworks.

the class EnvironmentEncryptionServiceTest method testCreateEncryptionResourcesDeletionRequestShouldReturnWithANewDeletionRequest.

@Test
void testCreateEncryptionResourcesDeletionRequestShouldReturnWithANewDeletionRequest() {
    EnvironmentDto environmentDto = EnvironmentDto.builder().withResourceCrn(ENVIRONMENT_CRN).withId(ENVIRONMENT_ID).withName(ENVIRONMENT_NAME).withCloudPlatform(CLOUD_PLATFORM).withCredential(credential).withLocationDto(LocationDto.builder().withName(REGION).build()).withParameters(ParametersDto.builder().withAzureParameters(AzureParametersDto.builder().withEncryptionParameters(AzureResourceEncryptionParametersDto.builder().withDiskEncryptionSetId(DISK_ENCRYPTION_SET_ID).withEncryptionKeyUrl(KEY_URL).build()).build()).build()).withCreator(USER_NAME).withAccountId(ACCOUNT_ID).build();
    CloudResource desCloudResource = CloudResource.builder().name(DISK_ENCRYPTION_SET_NAME).type(ResourceType.AZURE_DISK_ENCRYPTION_SET).reference(DISK_ENCRYPTION_SET_ID).status(CommonStatus.CREATED).build();
    when(resourceRetriever.findByEnvironmentIdAndType(ENVIRONMENT_ID, ResourceType.AZURE_DISK_ENCRYPTION_SET)).thenReturn(Optional.of(desCloudResource));
    when(credentialToCloudCredentialConverter.convert(credential)).thenReturn(cloudCredential);
    DiskEncryptionSetDeletionRequest deletionRequest = underTest.createEncryptionResourcesDeletionRequest(environmentDto);
    Optional<CloudResource> dummyResourceOptional = deletionRequest.getCloudResources().stream().filter(r -> r.getType() == ResourceType.AZURE_DISK_ENCRYPTION_SET).findFirst();
    assertNotNull(dummyResourceOptional);
    assertThat(dummyResourceOptional).isNotEmpty();
    assertEquals(dummyResourceOptional.get().getReference(), DISK_ENCRYPTION_SET_ID);
    verifyCloudContext(deletionRequest.getCloudContext());
    assertThat(deletionRequest.getCloudCredential()).isSameAs(cloudCredential);
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Variant(com.sequenceiq.cloudbreak.cloud.model.Variant) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) AzureResourceGroupDto(com.sequenceiq.environment.parameter.dto.AzureResourceGroupDto) Region(com.sequenceiq.cloudbreak.cloud.model.Region) Mock(org.mockito.Mock) Credential(com.sequenceiq.environment.credential.domain.Credential) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) EncryptionResources(com.sequenceiq.cloudbreak.cloud.EncryptionResources) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) Captor(org.mockito.Captor) DiskEncryptionSetDeletionRequest(com.sequenceiq.cloudbreak.cloud.model.encryption.DiskEncryptionSetDeletionRequest) CloudResourceRetrieverService(com.sequenceiq.environment.resourcepersister.CloudResourceRetrieverService) ResourceGroupUsagePattern(com.sequenceiq.environment.parameter.dto.ResourceGroupUsagePattern) ArgumentCaptor(org.mockito.ArgumentCaptor) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) DiskEncryptionSetCreationRequest(com.sequenceiq.cloudbreak.cloud.model.encryption.DiskEncryptionSetCreationRequest) Map(java.util.Map) Location(com.sequenceiq.cloudbreak.cloud.model.Location) Map.entry(java.util.Map.entry) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) CommonStatus(com.sequenceiq.common.api.type.CommonStatus) InjectMocks(org.mockito.InjectMocks) ResourceType(com.sequenceiq.common.api.type.ResourceType) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) CreatedDiskEncryptionSet(com.sequenceiq.cloudbreak.cloud.model.encryption.CreatedDiskEncryptionSet) ParametersDto(com.sequenceiq.environment.parameter.dto.ParametersDto) EnvironmentTagProvider(com.sequenceiq.environment.environment.service.EnvironmentTagProvider) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) Platform(com.sequenceiq.cloudbreak.cloud.model.Platform) Mockito.when(org.mockito.Mockito.when) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) CloudConnector(com.sequenceiq.cloudbreak.cloud.CloudConnector) AzureParametersDto(com.sequenceiq.environment.parameter.dto.AzureParametersDto) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) List(java.util.List) CloudPlatformConnectors(com.sequenceiq.cloudbreak.cloud.init.CloudPlatformConnectors) LocationDto(com.sequenceiq.environment.environment.dto.LocationDto) Optional(java.util.Optional) AzureResourceEncryptionParametersDto(com.sequenceiq.environment.parameter.dto.AzureResourceEncryptionParametersDto) CredentialToCloudCredentialConverter(com.sequenceiq.environment.credential.v1.converter.CredentialToCloudCredentialConverter) CloudPlatformVariant(com.sequenceiq.cloudbreak.cloud.model.CloudPlatformVariant) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) DiskEncryptionSetDeletionRequest(com.sequenceiq.cloudbreak.cloud.model.encryption.DiskEncryptionSetDeletionRequest) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) Test(org.junit.jupiter.api.Test)

Example 70 with Credential

use of com.sequenceiq.environment.credential.domain.Credential in project cloudbreak by hortonworks.

the class EnvironmentCreationServiceTest method testEncryptionKeyValidationError.

@Test
void testEncryptionKeyValidationError() {
    final EnvironmentCreationDto environmentCreationDto = EnvironmentCreationDto.builder().withName(ENVIRONMENT_NAME).withCloudPlatform("GCP").withCreator(CRN).withAccountId(ACCOUNT_ID).withAuthentication(AuthenticationDto.builder().build()).build();
    final Environment environment = new Environment();
    environment.setName(ENVIRONMENT_NAME);
    environment.setId(1L);
    environment.setAccountId(ACCOUNT_ID);
    Credential credential = new Credential();
    credential.setCloudPlatform("GCP");
    ValidationResultBuilder validationResultBuilder = new ValidationResultBuilder();
    validationResultBuilder.error("error");
    when(validatorService.validateEncryptionKeyUrl(any(), any())).thenReturn(validationResultBuilder.build());
    when(environmentService.isNameOccupied(eq(ENVIRONMENT_NAME), eq(ACCOUNT_ID))).thenReturn(false);
    when(environmentDtoConverter.creationDtoToEnvironment(eq(environmentCreationDto))).thenReturn(environment);
    when(environmentResourceService.getCredentialFromRequest(any(), any())).thenReturn(credential);
    when(validatorService.validateParentChildRelation(any(), any())).thenReturn(ValidationResult.builder().build());
    when(validatorService.validateNetworkCreation(any(), any())).thenReturn(ValidationResult.builder());
    when(validatorService.validateFreeIpaCreation(any())).thenReturn(ValidationResult.builder().build());
    when(authenticationDtoConverter.dtoToAuthentication(any())).thenReturn(new EnvironmentAuthentication());
    when(entitlementService.azureEnabled(eq(ACCOUNT_ID))).thenReturn(true);
    when(environmentService.save(any())).thenReturn(environment);
    assertThrows(BadRequestException.class, () -> environmentCreationServiceUnderTest.create(environmentCreationDto));
}
Also used : Credential(com.sequenceiq.environment.credential.domain.Credential) EnvironmentAuthentication(com.sequenceiq.environment.environment.domain.EnvironmentAuthentication) ValidationResultBuilder(com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder) Environment(com.sequenceiq.environment.environment.domain.Environment) EnvironmentCreationDto(com.sequenceiq.environment.environment.dto.EnvironmentCreationDto) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

Credential (com.sequenceiq.environment.credential.domain.Credential)102 Test (org.junit.jupiter.api.Test)49 Environment (com.sequenceiq.environment.environment.domain.Environment)27 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)23 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)13 EnvironmentDto (com.sequenceiq.environment.environment.dto.EnvironmentDto)10 ValidationResultBuilder (com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder)9 EnvironmentAuthentication (com.sequenceiq.environment.environment.domain.EnvironmentAuthentication)9 EnvironmentCreationDto (com.sequenceiq.environment.environment.dto.EnvironmentCreationDto)9 BadRequestException (javax.ws.rs.BadRequestException)9 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)9 CheckPermissionByAccount (com.sequenceiq.authorization.annotation.CheckPermissionByAccount)8 ParametersDto (com.sequenceiq.environment.parameter.dto.ParametersDto)8 Set (java.util.Set)8 CloudConnector (com.sequenceiq.cloudbreak.cloud.CloudConnector)7 ValidationResult (com.sequenceiq.cloudbreak.validation.ValidationResult)7 AwsNetwork (com.sequenceiq.environment.network.dao.domain.AwsNetwork)7 Map (java.util.Map)7 ExtendedPollingResult (com.sequenceiq.cloudbreak.polling.ExtendedPollingResult)6 BaseNetwork (com.sequenceiq.environment.network.dao.domain.BaseNetwork)6