Search in sources :

Example 1 with CloudStorageCdpService

use of com.sequenceiq.common.model.CloudStorageCdpService in project cloudbreak by hortonworks.

the class CloudStorageDecoratorTest method testUpdateCloudStorageLocationsWhenRequestContainsTemplatedLocationThenItShouldBeReplaced.

@Test
void testUpdateCloudStorageLocationsWhenRequestContainsTemplatedLocationThenItShouldBeReplaced() {
    CloudStorageCdpService storageLocationType = CloudStorageCdpService.DEFAULT_FS;
    String eStorageLocationValue = "s3a://some-dir/some-other-dir/{{{clusterName}}}";
    StorageLocationBase storageLocationBase = new StorageLocationBase();
    storageLocationBase.setType(storageLocationType);
    storageLocationBase.setValue(eStorageLocationValue);
    List<StorageLocationBase> storageLocations = new ArrayList<>(1);
    storageLocations.add(storageLocationBase);
    CloudStorageRequest request = new CloudStorageRequest();
    request.setLocations(storageLocations);
    SdxClusterResponse sdxResponse = new SdxClusterResponse();
    String storageLocationValue = "s3a://some-dir/some-other-dir/" + CLUSTER_NAME;
    sdxResponse.setCloudStorageBaseLocation(storageLocationValue);
    sdxResponse.setCloudStorageFileSystemType(FileSystemType.S3);
    ConfigQueryEntry cqe = new ConfigQueryEntry();
    cqe.setType(CloudStorageCdpService.DEFAULT_FS);
    cqe.setDefaultPath(storageLocationValue);
    Set<ConfigQueryEntry> cqes = new LinkedHashSet<>(1);
    cqes.add(cqe);
    when(blueprintService.queryFileSystemParameters(BLUEPRINT_NAME, CLUSTER_NAME, storageLocationValue, FileSystemType.S3.name(), "", true, false, 0L)).thenReturn(cqes);
    Pair<Blueprint, String> mockBt = mock(Pair.class);
    when(blueprintService.getBlueprintAndText(BLUEPRINT_NAME, 0L)).thenReturn(mockBt);
    FileSystemConfigQueryObject mockfscqo = mock(FileSystemConfigQueryObject.class);
    when(blueprintService.createFileSystemConfigQueryObject(mockBt, CLUSTER_NAME, sdxResponse.getCloudStorageBaseLocation(), sdxResponse.getCloudStorageFileSystemType().name(), "", true, false)).thenReturn(mockfscqo);
    when(cmCloudStorageConfigProvider.queryParameters(any(), eq(mockfscqo))).thenReturn(cqes);
    CloudStorageRequest result = underTest.updateCloudStorageLocations(BLUEPRINT_NAME, CLUSTER_NAME, request, List.of(sdxResponse));
    assertNotNull(result);
    assertEquals(0, result.getLocations().stream().filter(slb -> slb.getValue().contains("{{{") && slb.getValue().contains("}}}")).count());
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ConfigQueryEntry(com.sequenceiq.common.api.cloudstorage.query.ConfigQueryEntry) CloudStorageCdpService(com.sequenceiq.common.model.CloudStorageCdpService) CloudStorageRequest(com.sequenceiq.common.api.cloudstorage.CloudStorageRequest) Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) ArrayList(java.util.ArrayList) FileSystemConfigQueryObject(com.sequenceiq.cloudbreak.template.filesystem.FileSystemConfigQueryObject) SdxClusterResponse(com.sequenceiq.sdx.api.model.SdxClusterResponse) StorageLocationBase(com.sequenceiq.common.api.cloudstorage.StorageLocationBase) Test(org.junit.jupiter.api.Test)

Example 2 with CloudStorageCdpService

use of com.sequenceiq.common.model.CloudStorageCdpService in project cloudbreak by hortonworks.

the class CloudStorageDecorator method updateCloudStorageLocations.

public CloudStorageRequest updateCloudStorageLocations(String blueprintName, String clusterName, CloudStorageRequest request, List<SdxClusterResponse> datalakes) {
    if (hasDatalake(datalakes)) {
        Pair<String, FileSystemType> sdxBaseLocationFileSystemType = getBaseLocationWithFileSystemTypeFromSdx(datalakes.get(0));
        Set<ConfigQueryEntry> recommendations = getRecommendations(blueprintName, clusterName, sdxBaseLocationFileSystemType);
        if (storageLocationsNotDefined(request)) {
            if (request == null) {
                request = new CloudStorageRequest();
            }
            if (request.getLocations() == null) {
                request.setLocations(new ArrayList<>());
            }
            for (ConfigQueryEntry recommendation : recommendations) {
                request.getLocations().add(createStorageLocationBaseByTypeAndDefaultPath(recommendation.getType(), recommendation.getDefaultPath()));
            }
        } else {
            Map<CloudStorageCdpService, String> templatedLocations = findLocationsThatContainsTemplatedValue(request);
            if (!templatedLocations.isEmpty()) {
                LOGGER.info("Cloud storage location(s) has found with template placeholder(s). About to replace them with the recommended one(s).");
                Set<ConfigQueryEntry> filtered = filterConfigsWithTemplatePlaceholder(request, recommendations);
                Set<ConfigQueryEntry> replaced = queryParameters(filtered, blueprintName, clusterName, sdxBaseLocationFileSystemType);
                replaceTemplatedLocationValuesWithFilledValues(request, replaced, templatedLocations);
            }
        }
    }
    return request;
}
Also used : ConfigQueryEntry(com.sequenceiq.common.api.cloudstorage.query.ConfigQueryEntry) CloudStorageCdpService(com.sequenceiq.common.model.CloudStorageCdpService) CloudStorageRequest(com.sequenceiq.common.api.cloudstorage.CloudStorageRequest) FileSystemType(com.sequenceiq.common.model.FileSystemType)

Example 3 with CloudStorageCdpService

use of com.sequenceiq.common.model.CloudStorageCdpService in project cloudbreak by hortonworks.

the class AzureIDBrokerObjectStorageValidatorTest method getStorageLocation.

private List<StorageLocationBase> getStorageLocation() {
    CloudStorageCdpService eStorageLocationType = CloudStorageCdpService.RANGER_AUDIT;
    StorageLocationBase storageLocationBase = new StorageLocationBase();
    storageLocationBase.setType(eStorageLocationType);
    storageLocationBase.setValue(STORAGE_LOCATION_RANGER);
    return List.of(storageLocationBase);
}
Also used : CloudStorageCdpService(com.sequenceiq.common.model.CloudStorageCdpService) StorageLocationBase(com.sequenceiq.common.api.cloudstorage.StorageLocationBase)

Example 4 with CloudStorageCdpService

use of com.sequenceiq.common.model.CloudStorageCdpService in project cloudbreak by hortonworks.

the class CloudStorageDecoratorTest method testConvertWhenRequestHasNotCloudStorageLocationsAndSdxHasShouldTheSdxOnesBeUsed.

@Test
void testConvertWhenRequestHasNotCloudStorageLocationsAndSdxHasShouldTheSdxOnesBeUsed() {
    CloudStorageCdpService storageLocationType = CloudStorageCdpService.RANGER_AUDIT;
    SdxClusterResponse sdxReponse = new SdxClusterResponse();
    String storageLocationValue = "MYBUCKET/CONTAINER2";
    sdxReponse.setCloudStorageBaseLocation(storageLocationValue);
    sdxReponse.setCloudStorageFileSystemType(FileSystemType.S3);
    when(sdxClientService.getByEnvironmentCrn(any())).thenReturn(List.of(sdxReponse));
    ConfigQueryEntry sdxConfigQueryEntry = new ConfigQueryEntry();
    sdxConfigQueryEntry.setType(storageLocationType);
    sdxConfigQueryEntry.setDefaultPath(storageLocationValue);
    when(blueprintService.queryFileSystemParameters(any(), any(), any(), any(), any(), eq(Boolean.TRUE), eq(Boolean.FALSE), eq(0L))).thenReturn(Set.of(sdxConfigQueryEntry));
    CloudStorageRequest result = underTest.decorate(BLUEPRINT_NAME, CLUSTER_NAME, null, new DetailedEnvironmentResponse());
    assertNotNull(result);
    assertTrue(result.getLocations().stream().anyMatch(loc -> storageLocationType.equals(loc.getType()) && storageLocationValue.equals(loc.getValue())));
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Mock(org.mockito.Mock) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) ArrayList(java.util.ArrayList) SdxClusterResponse(com.sequenceiq.sdx.api.model.SdxClusterResponse) Pair(org.apache.commons.lang3.tuple.Pair) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) FileSystemConfigQueryObject(com.sequenceiq.cloudbreak.template.filesystem.FileSystemConfigQueryObject) Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) TelemetryResponse(com.sequenceiq.common.api.telemetry.response.TelemetryResponse) LinkedHashSet(java.util.LinkedHashSet) InjectMocks(org.mockito.InjectMocks) LoggingResponse(com.sequenceiq.common.api.telemetry.response.LoggingResponse) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) CloudStorageCdpService(com.sequenceiq.common.model.CloudStorageCdpService) StorageLocationBase(com.sequenceiq.common.api.cloudstorage.StorageLocationBase) Set(java.util.Set) Mockito.when(org.mockito.Mockito.when) Test(org.junit.jupiter.api.Test) List(java.util.List) CmCloudStorageConfigProvider(com.sequenceiq.cloudbreak.cmtemplate.cloudstorage.CmCloudStorageConfigProvider) SdxClientService(com.sequenceiq.cloudbreak.service.datalake.SdxClientService) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) CloudStorageRequest(com.sequenceiq.common.api.cloudstorage.CloudStorageRequest) FileSystemType(com.sequenceiq.common.model.FileSystemType) ConfigQueryEntry(com.sequenceiq.common.api.cloudstorage.query.ConfigQueryEntry) BlueprintService(com.sequenceiq.cloudbreak.service.blueprint.BlueprintService) CloudIdentityType(com.sequenceiq.common.model.CloudIdentityType) Mockito.mock(org.mockito.Mockito.mock) ConfigQueryEntry(com.sequenceiq.common.api.cloudstorage.query.ConfigQueryEntry) CloudStorageCdpService(com.sequenceiq.common.model.CloudStorageCdpService) CloudStorageRequest(com.sequenceiq.common.api.cloudstorage.CloudStorageRequest) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) SdxClusterResponse(com.sequenceiq.sdx.api.model.SdxClusterResponse) Test(org.junit.jupiter.api.Test)

Example 5 with CloudStorageCdpService

use of com.sequenceiq.common.model.CloudStorageCdpService in project cloudbreak by hortonworks.

the class CloudStorageDecoratorTest method testConvertWhenEnvironmentHaveTelemetryAndStorageLocationsIsNotNullOrEmpty.

@Test
void testConvertWhenEnvironmentHaveTelemetryAndStorageLocationsIsNotNullOrEmpty() {
    TelemetryResponse telemetry = new TelemetryResponse();
    telemetry.setLogging(new LoggingResponse());
    DetailedEnvironmentResponse environment = new DetailedEnvironmentResponse();
    environment.setTelemetry(telemetry);
    CloudStorageCdpService eStorageLocationType = CloudStorageCdpService.RANGER_AUDIT;
    String eStorageLocationValue = "MYBUCKET/CONTAINER";
    StorageLocationBase storageLocationBase = new StorageLocationBase();
    storageLocationBase.setType(eStorageLocationType);
    storageLocationBase.setValue(eStorageLocationValue);
    List<StorageLocationBase> storageLocations = List.of(storageLocationBase);
    CloudStorageRequest request = new CloudStorageRequest();
    request.setLocations(storageLocations);
    CloudStorageRequest result = underTest.decorate(BLUEPRINT_NAME, CLUSTER_NAME, request, environment);
    assertNotNull(result);
    assertTrue(result.getIdentities().stream().anyMatch(id -> CloudIdentityType.LOG.equals(id.getType())));
    assertTrue(result.getLocations().stream().anyMatch(loc -> eStorageLocationType.equals(loc.getType()) && eStorageLocationValue.equals(loc.getValue())));
}
Also used : TelemetryResponse(com.sequenceiq.common.api.telemetry.response.TelemetryResponse) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Mock(org.mockito.Mock) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) ArrayList(java.util.ArrayList) SdxClusterResponse(com.sequenceiq.sdx.api.model.SdxClusterResponse) Pair(org.apache.commons.lang3.tuple.Pair) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) FileSystemConfigQueryObject(com.sequenceiq.cloudbreak.template.filesystem.FileSystemConfigQueryObject) Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) TelemetryResponse(com.sequenceiq.common.api.telemetry.response.TelemetryResponse) LinkedHashSet(java.util.LinkedHashSet) InjectMocks(org.mockito.InjectMocks) LoggingResponse(com.sequenceiq.common.api.telemetry.response.LoggingResponse) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) CloudStorageCdpService(com.sequenceiq.common.model.CloudStorageCdpService) StorageLocationBase(com.sequenceiq.common.api.cloudstorage.StorageLocationBase) Set(java.util.Set) Mockito.when(org.mockito.Mockito.when) Test(org.junit.jupiter.api.Test) List(java.util.List) CmCloudStorageConfigProvider(com.sequenceiq.cloudbreak.cmtemplate.cloudstorage.CmCloudStorageConfigProvider) SdxClientService(com.sequenceiq.cloudbreak.service.datalake.SdxClientService) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) CloudStorageRequest(com.sequenceiq.common.api.cloudstorage.CloudStorageRequest) FileSystemType(com.sequenceiq.common.model.FileSystemType) ConfigQueryEntry(com.sequenceiq.common.api.cloudstorage.query.ConfigQueryEntry) BlueprintService(com.sequenceiq.cloudbreak.service.blueprint.BlueprintService) CloudIdentityType(com.sequenceiq.common.model.CloudIdentityType) Mockito.mock(org.mockito.Mockito.mock) CloudStorageCdpService(com.sequenceiq.common.model.CloudStorageCdpService) CloudStorageRequest(com.sequenceiq.common.api.cloudstorage.CloudStorageRequest) LoggingResponse(com.sequenceiq.common.api.telemetry.response.LoggingResponse) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) StorageLocationBase(com.sequenceiq.common.api.cloudstorage.StorageLocationBase) Test(org.junit.jupiter.api.Test)

Aggregations

CloudStorageCdpService (com.sequenceiq.common.model.CloudStorageCdpService)8 CloudStorageRequest (com.sequenceiq.common.api.cloudstorage.CloudStorageRequest)7 StorageLocationBase (com.sequenceiq.common.api.cloudstorage.StorageLocationBase)7 ConfigQueryEntry (com.sequenceiq.common.api.cloudstorage.query.ConfigQueryEntry)7 Blueprint (com.sequenceiq.cloudbreak.domain.Blueprint)6 FileSystemConfigQueryObject (com.sequenceiq.cloudbreak.template.filesystem.FileSystemConfigQueryObject)6 SdxClusterResponse (com.sequenceiq.sdx.api.model.SdxClusterResponse)6 ArrayList (java.util.ArrayList)6 LinkedHashSet (java.util.LinkedHashSet)6 Test (org.junit.jupiter.api.Test)6 FileSystemType (com.sequenceiq.common.model.FileSystemType)5 CmCloudStorageConfigProvider (com.sequenceiq.cloudbreak.cmtemplate.cloudstorage.CmCloudStorageConfigProvider)4 BlueprintService (com.sequenceiq.cloudbreak.service.blueprint.BlueprintService)4 SdxClientService (com.sequenceiq.cloudbreak.service.datalake.SdxClientService)4 LoggingResponse (com.sequenceiq.common.api.telemetry.response.LoggingResponse)4 TelemetryResponse (com.sequenceiq.common.api.telemetry.response.TelemetryResponse)4 CloudIdentityType (com.sequenceiq.common.model.CloudIdentityType)4 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)4 List (java.util.List)4 Set (java.util.Set)4