Search in sources :

Example 6 with CredentialResponse

use of com.sequenceiq.environment.api.v1.credential.model.response.CredentialResponse in project cloudbreak by hortonworks.

the class EnvironmentResponseConverterTest method testDtoToDetailedResponse.

@ParameterizedTest
@EnumSource(value = CloudPlatform.class, names = { "AWS", "AZURE", "GCP" })
void testDtoToDetailedResponse(CloudPlatform cloudPlatform) {
    EnvironmentDto environment = createEnvironmentDto(cloudPlatform);
    CredentialResponse credentialResponse = mock(CredentialResponse.class);
    FreeIpaResponse freeIpaResponse = mock(FreeIpaResponse.class);
    CompactRegionResponse compactRegionResponse = mock(CompactRegionResponse.class);
    TelemetryResponse telemetryResponse = mock(TelemetryResponse.class);
    BackupResponse backupResponse = mock(BackupResponse.class);
    ProxyResponse proxyResponse = mock(ProxyResponse.class);
    EnvironmentNetworkResponse environmentNetworkResponse = mock(EnvironmentNetworkResponse.class);
    when(credentialConverter.convert(environment.getCredential())).thenReturn(credentialResponse);
    when(freeIpaConverter.convert(environment.getFreeIpaCreation())).thenReturn(freeIpaResponse);
    when(regionConverter.convertRegions(environment.getRegions())).thenReturn(compactRegionResponse);
    when(telemetryApiConverter.convert(environment.getTelemetry())).thenReturn(telemetryResponse);
    when(backupConverter.convert(environment.getBackup())).thenReturn(backupResponse);
    when(proxyConfigToProxyResponseConverter.convert((ProxyConfig) environment.getProxyConfig())).thenReturn(proxyResponse);
    when(networkDtoToResponseConverter.convert(environment.getNetwork(), environment.getExperimentalFeatures().getTunnel(), true)).thenReturn(environmentNetworkResponse);
    DetailedEnvironmentResponse actual = underTest.dtoToDetailedResponse(environment);
    assertEquals(environment.getResourceCrn(), actual.getCrn());
    assertEquals(environment.getName(), actual.getName());
    assertEquals(environment.getOriginalName(), actual.getOriginalName());
    assertEquals(environment.getDescription(), actual.getDescription());
    assertEquals(environment.getCloudPlatform(), actual.getCloudPlatform());
    assertEquals(credentialResponse, actual.getCredential());
    assertEquals(environment.getStatus().getResponseStatus(), actual.getEnvironmentStatus());
    assertLocation(environment.getLocation(), actual.getLocation());
    assertTrue(actual.getCreateFreeIpa());
    assertEquals(freeIpaResponse, actual.getFreeIpa());
    assertEquals(compactRegionResponse, actual.getRegions());
    assertEquals(environment.getCreator(), actual.getCreator());
    assertAuthentication(environment.getAuthentication(), actual.getAuthentication());
    assertEquals(environment.getStatusReason(), actual.getStatusReason());
    assertEquals(environment.getCreated(), actual.getCreated());
    assertEquals(environment.getTags().getUserDefinedTags(), actual.getTags().getUserDefined());
    assertEquals(environment.getTags().getDefaultTags(), actual.getTags().getDefaults());
    assertEquals(telemetryResponse, actual.getTelemetry());
    assertEquals(environment.getExperimentalFeatures().getTunnel(), actual.getTunnel());
    assertEquals(environment.getExperimentalFeatures().getIdBrokerMappingSource(), actual.getIdBrokerMappingSource());
    assertEquals(environment.getExperimentalFeatures().getCloudStorageValidation(), actual.getCloudStorageValidation());
    assertEquals(environment.getExperimentalFeatures().getCcmV2TlsType(), actual.getCcmV2TlsType());
    assertEquals(environment.getAdminGroupName(), actual.getAdminGroupName());
    assertParameters(environment, actual, cloudPlatform);
    assertEquals(environment.getParentEnvironmentCrn(), actual.getParentEnvironmentCrn());
    assertEquals(environment.getParentEnvironmentName(), actual.getParentEnvironmentName());
    assertEquals(environment.getParentEnvironmentCloudPlatform(), actual.getParentEnvironmentCloudPlatform());
    assertEquals(proxyResponse, actual.getProxyConfig());
    assertEquals(environmentNetworkResponse, actual.getNetwork());
    assertSecurityAccess(environment.getSecurityAccess(), actual.getSecurityAccess());
    verify(credentialConverter).convert(environment.getCredential());
    verify(freeIpaConverter).convert(environment.getFreeIpaCreation());
    verify(regionConverter).convertRegions(environment.getRegions());
    verify(telemetryApiConverter).convert(environment.getTelemetry());
    verify(proxyConfigToProxyResponseConverter).convert(environment.getProxyConfig());
    verify(networkDtoToResponseConverter).convert(environment.getNetwork(), environment.getExperimentalFeatures().getTunnel(), true);
}
Also used : TelemetryResponse(com.sequenceiq.common.api.telemetry.response.TelemetryResponse) CompactRegionResponse(com.sequenceiq.environment.api.v1.environment.model.response.CompactRegionResponse) ProxyResponse(com.sequenceiq.environment.api.v1.proxy.model.response.ProxyResponse) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) EnvironmentNetworkResponse(com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentNetworkResponse) CredentialResponse(com.sequenceiq.environment.api.v1.credential.model.response.CredentialResponse) BackupResponse(com.sequenceiq.common.api.backup.response.BackupResponse) FreeIpaResponse(com.sequenceiq.environment.api.v1.environment.model.response.FreeIpaResponse) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 7 with CredentialResponse

use of com.sequenceiq.environment.api.v1.credential.model.response.CredentialResponse in project cloudbreak by hortonworks.

the class EnvironmentResponseConverterTest method testDtoToSimpleResponse.

@ParameterizedTest
@EnumSource(value = CloudPlatform.class, names = { "AWS", "AZURE" })
void testDtoToSimpleResponse(CloudPlatform cloudPlatform) {
    EnvironmentDto environmentDto = createEnvironmentDto(cloudPlatform);
    CredentialViewResponse credentialResponse = mock(CredentialViewResponse.class);
    FreeIpaResponse freeIpaResponse = mock(FreeIpaResponse.class);
    CompactRegionResponse compactRegionResponse = mock(CompactRegionResponse.class);
    TelemetryResponse telemetryResponse = mock(TelemetryResponse.class);
    ProxyViewResponse proxyResponse = mock(ProxyViewResponse.class);
    EnvironmentNetworkResponse environmentNetworkResponse = mock(EnvironmentNetworkResponse.class);
    when(credentialViewConverter.convertResponse(environmentDto.getCredential())).thenReturn(credentialResponse);
    when(freeIpaConverter.convert(environmentDto.getFreeIpaCreation())).thenReturn(freeIpaResponse);
    when(regionConverter.convertRegions(environmentDto.getRegions())).thenReturn(compactRegionResponse);
    when(telemetryApiConverter.convert(environmentDto.getTelemetry())).thenReturn(telemetryResponse);
    when(proxyConfigToProxyResponseConverter.convertToView(environmentDto.getProxyConfig())).thenReturn(proxyResponse);
    when(networkDtoToResponseConverter.convert(environmentDto.getNetwork(), environmentDto.getExperimentalFeatures().getTunnel(), false)).thenReturn(environmentNetworkResponse);
    SimpleEnvironmentResponse actual = underTest.dtoToSimpleResponse(environmentDto, true, true);
    assertEquals(environmentDto.getResourceCrn(), actual.getCrn());
    assertEquals(environmentDto.getName(), actual.getName());
    assertEquals(environmentDto.getOriginalName(), actual.getOriginalName());
    assertEquals(environmentDto.getDescription(), actual.getDescription());
    assertEquals(environmentDto.getCloudPlatform(), actual.getCloudPlatform());
    assertEquals(credentialResponse, actual.getCredential());
    assertEquals(environmentDto.getStatus().getResponseStatus(), actual.getEnvironmentStatus());
    assertEquals(environmentDto.getCreator(), actual.getCreator());
    assertLocation(environmentDto.getLocation(), actual.getLocation());
    assertTrue(actual.getCreateFreeIpa());
    assertEquals(freeIpaResponse, actual.getFreeIpa());
    assertEquals(environmentDto.getStatusReason(), actual.getStatusReason());
    assertEquals(environmentDto.getCreated(), actual.getCreated());
    assertEquals(environmentDto.getExperimentalFeatures().getTunnel(), actual.getTunnel());
    assertEquals(environmentDto.getExperimentalFeatures().getCcmV2TlsType(), actual.getCcmV2TlsType());
    assertEquals(environmentDto.getAdminGroupName(), actual.getAdminGroupName());
    assertEquals(environmentDto.getTags().getUserDefinedTags(), actual.getTags().getUserDefined());
    assertEquals(environmentDto.getTags().getDefaultTags(), actual.getTags().getDefaults());
    assertEquals(telemetryResponse, actual.getTelemetry());
    assertEquals(compactRegionResponse, actual.getRegions());
    assertParameters(environmentDto, actual, cloudPlatform);
    assertEquals(environmentDto.getParentEnvironmentName(), actual.getParentEnvironmentName());
    assertEquals(proxyResponse, actual.getProxyConfig());
    assertEquals(environmentNetworkResponse, actual.getNetwork());
    verify(credentialViewConverter).convertResponse(environmentDto.getCredential());
    verify(freeIpaConverter).convert(environmentDto.getFreeIpaCreation());
    verify(regionConverter).convertRegions(environmentDto.getRegions());
    verify(telemetryApiConverter).convert(environmentDto.getTelemetry());
    verify(proxyConfigToProxyResponseConverter).convertToView(environmentDto.getProxyConfig());
    verify(networkDtoToResponseConverter).convert(environmentDto.getNetwork(), environmentDto.getExperimentalFeatures().getTunnel(), false);
}
Also used : CredentialViewResponse(com.sequenceiq.environment.api.v1.credential.model.response.CredentialViewResponse) TelemetryResponse(com.sequenceiq.common.api.telemetry.response.TelemetryResponse) CompactRegionResponse(com.sequenceiq.environment.api.v1.environment.model.response.CompactRegionResponse) ProxyViewResponse(com.sequenceiq.environment.api.v1.proxy.model.response.ProxyViewResponse) SimpleEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.SimpleEnvironmentResponse) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) EnvironmentNetworkResponse(com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentNetworkResponse) FreeIpaResponse(com.sequenceiq.environment.api.v1.environment.model.response.FreeIpaResponse) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 8 with CredentialResponse

use of com.sequenceiq.environment.api.v1.credential.model.response.CredentialResponse in project cloudbreak by hortonworks.

the class CredentialServiceTest method testAzureCredential.

@Test
public void testAzureCredential() {
    CredentialResponse credentialResponse = new CredentialResponse();
    credentialResponse.setCrn(CRN);
    credentialResponse.setName(NAME);
    credentialResponse.setAttributes(secretResponse);
    AzureCredentialResponseParameters azureResponse = new AzureCredentialResponseParameters();
    azureResponse.setSubscriptionId(SUBSCRIPTION_ID);
    credentialResponse.setAzure(azureResponse);
    when(credentialEndpoint.getByEnvironmentCrn(ENVIRONMENT_CRN)).thenReturn(credentialResponse);
    Credential credential = underTest.getCredentialByEnvCrn(ENVIRONMENT_CRN);
    assertEquals(CRN, credential.getCrn());
    assertEquals(NAME, credential.getName());
    assertEquals(ATTRIBUTES, credential.getAttributes());
    assertTrue(credential.getAzure().isPresent());
    assertEquals(SUBSCRIPTION_ID, credential.getAzure().get().getSubscriptionId());
}
Also used : Credential(com.sequenceiq.redbeams.dto.Credential) CredentialResponse(com.sequenceiq.environment.api.v1.credential.model.response.CredentialResponse) AzureCredentialResponseParameters(com.sequenceiq.environment.api.v1.credential.model.parameters.azure.AzureCredentialResponseParameters) Test(org.junit.Test)

Example 9 with CredentialResponse

use of com.sequenceiq.environment.api.v1.credential.model.response.CredentialResponse in project cloudbreak by hortonworks.

the class StackToTemplatePreparationObjectConverterTest method testConvertWhenEnvironmentBackupLocationDefinedThenBaseFileSystemConfigurationsViewShouldAddIt.

@Test
public void testConvertWhenEnvironmentBackupLocationDefinedThenBaseFileSystemConfigurationsViewShouldAddIt() throws IOException {
    String backupLocation = "s3a://test";
    FileSystem sourceFileSystem = new FileSystem();
    FileSystem clusterServiceFileSystem = new FileSystem();
    ConfigQueryEntries configQueryEntries = new ConfigQueryEntries();
    BaseFileSystemConfigurationsView expected = mock(BaseFileSystemConfigurationsView.class);
    List<StorageLocationView> storageLocationViews = mock(List.class);
    BackupResponse backupResponse = new BackupResponse();
    backupResponse.setStorageLocation(backupLocation);
    DetailedEnvironmentResponse environmentResponse = DetailedEnvironmentResponse.builder().withIdBrokerMappingSource(IdBrokerMappingSource.MOCK).withCredential(new CredentialResponse()).withAdminGroupName(ADMIN_GROUP_NAME).withCrn(TestConstants.CRN).withBackup(backupResponse).build();
    StorageLocation storageLocation = new StorageLocation();
    storageLocation.setValue(backupLocation);
    storageLocation.setProperty(RangerCloudStorageServiceConfigProvider.DEFAULT_BACKUP_DIR);
    StorageLocationView backupLocationView = new StorageLocationView(storageLocation);
    when(sourceCluster.getFileSystem()).thenReturn(sourceFileSystem);
    when(cluster.getFileSystem()).thenReturn(clusterServiceFileSystem);
    when(fileSystemConfigurationProvider.fileSystemConfiguration(eq(clusterServiceFileSystem), eq(stackMock), any(), eq(new Json("")), eq(configQueryEntries))).thenReturn(expected);
    when(cmCloudStorageConfigProvider.getConfigQueryEntries()).thenReturn(configQueryEntries);
    when(environmentClientService.getByCrn(anyString())).thenReturn(environmentResponse);
    when(blueprintViewProvider.getBlueprintView(any())).thenReturn(getBlueprintView());
    when(expected.getLocations()).thenReturn(storageLocationViews);
    TemplatePreparationObject result = underTest.convert(stackMock);
    assertThat(result.getFileSystemConfigurationView().isPresent()).isTrue();
    assertThat(result.getFileSystemConfigurationView().get()).isEqualTo(expected);
    verify(fileSystemConfigurationProvider, times(1)).fileSystemConfiguration(eq(clusterServiceFileSystem), eq(stackMock), any(), eq(new Json("")), eq(configQueryEntries));
    verify(expected, times(1)).getLocations();
    verify(storageLocationViews, times(1)).add(eq(backupLocationView));
}
Also used : TemplatePreparationObject(com.sequenceiq.cloudbreak.template.TemplatePreparationObject) StorageLocationView(com.sequenceiq.cloudbreak.template.filesystem.StorageLocationView) BaseFileSystemConfigurationsView(com.sequenceiq.cloudbreak.template.filesystem.BaseFileSystemConfigurationsView) FileSystem(com.sequenceiq.cloudbreak.domain.FileSystem) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) CredentialResponse(com.sequenceiq.environment.api.v1.credential.model.response.CredentialResponse) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Json(com.sequenceiq.cloudbreak.common.json.Json) BackupResponse(com.sequenceiq.common.api.backup.response.BackupResponse) StorageLocation(com.sequenceiq.cloudbreak.domain.StorageLocation) ConfigQueryEntries(com.sequenceiq.common.api.cloudstorage.query.ConfigQueryEntries) Test(org.junit.jupiter.api.Test)

Example 10 with CredentialResponse

use of com.sequenceiq.environment.api.v1.credential.model.response.CredentialResponse in project cloudbreak by hortonworks.

the class CredentialService method getCredentialByEnvCrn.

/**
 * Gets the credential for an environment.
 *
 * @param envCrn environment CRN
 * @return environment credential
 */
public Credential getCredentialByEnvCrn(String envCrn) {
    CredentialResponse credentialResponse = credentialEndpoint.getByEnvironmentCrn(envCrn);
    SecretResponse secretResponse = credentialResponse.getAttributes();
    String attributes = secretService.getByResponse(secretResponse);
    if (credentialResponse.getAzure() != null) {
        return new Credential(credentialResponse.getCrn(), credentialResponse.getName(), attributes, new Credential.AzureParameters(credentialResponse.getAzure().getSubscriptionId()), credentialResponse.getAccountId());
    } else {
        return new Credential(credentialResponse.getCrn(), credentialResponse.getName(), attributes, credentialResponse.getAccountId());
    }
}
Also used : SecretResponse(com.sequenceiq.cloudbreak.service.secret.model.SecretResponse) Credential(com.sequenceiq.redbeams.dto.Credential) CredentialResponse(com.sequenceiq.environment.api.v1.credential.model.response.CredentialResponse)

Aggregations

CredentialResponse (com.sequenceiq.environment.api.v1.credential.model.response.CredentialResponse)29 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)12 Test (org.junit.jupiter.api.Test)10 InteractiveCredentialResponse (com.sequenceiq.environment.api.v1.credential.model.response.InteractiveCredentialResponse)6 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)6 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)5 CompactRegionResponse (com.sequenceiq.environment.api.v1.environment.model.response.CompactRegionResponse)5 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)4 EnvironmentNetworkResponse (com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentNetworkResponse)4 BadRequestException (javax.ws.rs.BadRequestException)4 NameOrCrn (com.sequenceiq.cloudbreak.api.endpoint.v4.dto.NameOrCrn)3 StackViewV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackViewV4Response)3 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)3 Before (org.junit.Before)3 BeforeEach (org.junit.jupiter.api.BeforeEach)3 StackV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request)2 Json (com.sequenceiq.cloudbreak.common.json.Json)2 Credential (com.sequenceiq.cloudbreak.dto.credential.Credential)2 SecretResponse (com.sequenceiq.cloudbreak.service.secret.model.SecretResponse)2 BackupResponse (com.sequenceiq.common.api.backup.response.BackupResponse)2