Search in sources :

Example 6 with ImageV4Response

use of com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.responses.ImageV4Response in project cloudbreak by hortonworks.

the class ImagesToImagesV4ResponseConverter method convert.

public ImagesV4Response convert(Images source) {
    ImagesV4Response res = new ImagesV4Response();
    List<BaseImageV4Response> baseImages = getBaseImageResponses(source);
    res.setBaseImages(baseImages);
    List<ImageV4Response> cdhImages = convertImages(source.getCdhImages(), StackType.CDH);
    res.setCdhImages(cdhImages);
    res.setSupportedVersions(source.getSuppertedVersions());
    res.setFreeipaImages(source.getFreeIpaImages().stream().map(image -> imageToImageV4ResponseConverter.convert(image)).collect(Collectors.toList()));
    return res;
}
Also used : BaseImageV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.responses.BaseImageV4Response) BaseImageV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.responses.BaseImageV4Response) ImageV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.responses.ImageV4Response) ImagesV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.responses.ImagesV4Response)

Example 7 with ImageV4Response

use of com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.responses.ImageV4Response in project cloudbreak by hortonworks.

the class SdxServiceTest method getImageResponse.

private ImageV4Response getImageResponse() {
    Map<String, Map<String, String>> imageSetsByProvider = new HashMap<>();
    imageSetsByProvider.put("aws", null);
    BaseStackDetailsV4Response stackDetails = new BaseStackDetailsV4Response();
    stackDetails.setVersion("7.2.7");
    ImageV4Response imageV4Response = new ImageV4Response();
    imageV4Response.setImageSetsByProvider(imageSetsByProvider);
    imageV4Response.setStackDetails(stackDetails);
    return imageV4Response;
}
Also used : LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) ImageV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.responses.ImageV4Response) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) BaseStackDetailsV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.responses.BaseStackDetailsV4Response)

Example 8 with ImageV4Response

use of com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.responses.ImageV4Response in project cloudbreak by hortonworks.

the class SdxServiceTest method testCreateSdxClusterWithCustomRequestContainsImageInfo.

@Test
void testCreateSdxClusterWithCustomRequestContainsImageInfo() throws Exception {
    ImageV4Response imageResponse = getImageResponse();
    when(transactionService.required(isA(Supplier.class))).thenAnswer(invocation -> invocation.getArgument(0, Supplier.class).get());
    String lightDutyJson = FileReaderUtils.readFileFromClasspath("/duties/7.2.7/aws/light_duty.json");
    when(cdpConfigService.getConfigForKey(any())).thenReturn(JsonUtil.readValue(lightDutyJson, StackV4Request.class));
    SdxCustomClusterRequest sdxClusterRequest = createSdxCustomClusterRequest(LIGHT_DUTY, "cdp-default", "imageId_1");
    setSpot(sdxClusterRequest);
    withCloudStorage(sdxClusterRequest);
    when(imageCatalogService.getImageResponseFromImageRequest(eq(sdxClusterRequest.getImageSettingsV4Request()), any())).thenReturn(imageResponse);
    long id = 10L;
    when(sdxClusterRepository.save(any(SdxCluster.class))).thenAnswer(invocation -> {
        SdxCluster sdxWithId = invocation.getArgument(0, SdxCluster.class);
        sdxWithId.setId(id);
        return sdxWithId;
    });
    mockEnvironmentCall(sdxClusterRequest, CloudPlatform.AWS, null);
    Pair<SdxCluster, FlowIdentifier> result = ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.createSdx(USER_CRN, CLUSTER_NAME, sdxClusterRequest));
    SdxCluster createdSdxCluster = result.getLeft();
    StackV4Request stackV4Request = JsonUtil.readValue(createdSdxCluster.getStackRequest(), StackV4Request.class);
    assertNotNull(stackV4Request.getImage());
    assertEquals("cdp-default", stackV4Request.getImage().getCatalog());
    assertEquals("imageId_1", stackV4Request.getImage().getId());
}
Also used : SdxCustomClusterRequest(com.sequenceiq.sdx.api.model.SdxCustomClusterRequest) StackV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request) ImageV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.responses.ImageV4Response) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) Supplier(java.util.function.Supplier) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Example 9 with ImageV4Response

use of com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.responses.ImageV4Response in project cloudbreak by hortonworks.

the class ImageCatalogServiceTest method testImageLookupByImageCatalogNameAndImageID.

@Test
public void testImageLookupByImageCatalogNameAndImageID() throws Exception {
    ImageV4Response imageResponse = getImageResponse();
    ImagesV4Response imagesV4Response = new ImagesV4Response();
    imagesV4Response.setCdhImages(List.of(imageResponse));
    ImageSettingsV4Request imageSettingsV4Request = new ImageSettingsV4Request();
    imageSettingsV4Request.setCatalog(IMAGE_CATALOG_NAME);
    imageSettingsV4Request.setId(IMAGE_ID);
    when(cloudbreakInternalCrnClient.withInternalCrn()).thenReturn(cloudbreakServiceCrnEndpoints);
    when(cloudbreakServiceCrnEndpoints.imageCatalogV4Endpoint()).thenReturn(imageCatalogV4Endpoint);
    when(imageCatalogV4Endpoint.getImageByCatalogNameAndImageId(any(), eq(IMAGE_CATALOG_NAME), eq(IMAGE_ID), any())).thenReturn(imagesV4Response);
    ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> {
        ImageV4Response actual = victim.getImageResponseFromImageRequest(imageSettingsV4Request, CloudPlatform.AWS);
        assertEquals(imageResponse, actual);
    });
}
Also used : ImageSettingsV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.image.ImageSettingsV4Request) ImageV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.responses.ImageV4Response) ImagesV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.responses.ImagesV4Response) Test(org.junit.jupiter.api.Test)

Example 10 with ImageV4Response

use of com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.responses.ImageV4Response in project cloudbreak by hortonworks.

the class SdxService method createSdx.

private Pair<SdxCluster, FlowIdentifier> createSdx(final String userCrn, final String name, final SdxClusterRequest sdxClusterRequest, final StackV4Request internalStackV4Request, final ImageSettingsV4Request imageSettingsV4Request) {
    LOGGER.info("Creating SDX cluster with name {}", name);
    String accountId = getAccountIdFromCrn(userCrn);
    validateSdxRequest(name, sdxClusterRequest.getEnvironment(), accountId);
    DetailedEnvironmentResponse environment = validateAndGetEnvironment(sdxClusterRequest.getEnvironment());
    CloudPlatform cloudPlatform = CloudPlatform.valueOf(environment.getCloudPlatform());
    ImageV4Response imageV4Response = imageCatalogService.getImageResponseFromImageRequest(imageSettingsV4Request, cloudPlatform);
    validateInternalSdxRequest(internalStackV4Request, sdxClusterRequest);
    validateRuntimeAndImage(sdxClusterRequest, environment, imageSettingsV4Request, imageV4Response);
    String runtimeVersion = getRuntime(sdxClusterRequest, internalStackV4Request, imageV4Response);
    validateCcmV2Requirement(environment, runtimeVersion);
    SdxCluster sdxCluster = validateAndCreateNewSdxCluster(userCrn, name, runtimeVersion, sdxClusterRequest.getClusterShape(), sdxClusterRequest.isEnableRangerRaz(), sdxClusterRequest.isEnableMultiAz(), environment);
    setTagsSafe(sdxClusterRequest, sdxCluster);
    if (isCloudStorageConfigured(sdxClusterRequest)) {
        validateCloudStorageRequest(sdxClusterRequest.getCloudStorage(), environment);
        String trimmedBaseLocation = StringUtils.stripEnd(sdxClusterRequest.getCloudStorage().getBaseLocation(), "/");
        sdxCluster.setCloudStorageBaseLocation(trimmedBaseLocation);
        sdxCluster.setCloudStorageFileSystemType(sdxClusterRequest.getCloudStorage().getFileSystemType());
        sdxClusterRequest.getCloudStorage().setBaseLocation(trimmedBaseLocation);
    } else if (!CloudPlatform.YARN.equalsIgnoreCase(cloudPlatform.name()) && !CloudPlatform.GCP.equalsIgnoreCase(cloudPlatform.name()) && !CloudPlatform.MOCK.equalsIgnoreCase(cloudPlatform.name()) && internalStackV4Request == null) {
        throw new BadRequestException("Cloud storage parameter is required.");
    }
    externalDatabaseConfigurer.configure(cloudPlatform, sdxClusterRequest.getExternalDatabase(), sdxCluster);
    updateStackV4RequestWithEnvironmentCrnIfNotExistsOnIt(internalStackV4Request, environment.getCrn());
    StackV4Request stackRequest = getStackRequest(sdxClusterRequest.getClusterShape(), sdxClusterRequest.isEnableRangerRaz(), internalStackV4Request, cloudPlatform, runtimeVersion, imageSettingsV4Request);
    overrideDefaultTemplateValues(stackRequest, sdxClusterRequest.getCustomInstanceGroups(), accountId);
    validateRecipes(sdxClusterRequest, stackRequest, userCrn);
    prepareCloudStorageForStack(sdxClusterRequest, stackRequest, sdxCluster, environment);
    prepareDefaultSecurityConfigs(internalStackV4Request, stackRequest, cloudPlatform);
    prepareProviderSpecificParameters(stackRequest, sdxClusterRequest, cloudPlatform);
    updateStackV4RequestWithRecipes(sdxClusterRequest, stackRequest);
    stackRequest.setResourceCrn(sdxCluster.getCrn());
    sdxCluster.setStackRequest(stackRequest);
    MDCBuilder.buildMdcContext(sdxCluster);
    SdxCluster savedSdxCluster;
    try {
        savedSdxCluster = transactionService.required(() -> {
            SdxCluster created = sdxClusterRepository.save(sdxCluster);
            ownerAssignmentService.assignResourceOwnerRoleIfEntitled(created.getInitiatorUserCrn(), created.getCrn(), created.getAccountId());
            sdxStatusService.setStatusForDatalakeAndNotify(DatalakeStatusEnum.REQUESTED, "Datalake requested", created);
            return created;
        });
    } catch (TransactionExecutionException e) {
        throw new TransactionRuntimeExecutionException(e);
    }
    FlowIdentifier flowIdentifier = sdxReactorFlowManager.triggerSdxCreation(savedSdxCluster);
    return Pair.of(savedSdxCluster, flowIdentifier);
}
Also used : CloudPlatform(com.sequenceiq.cloudbreak.common.mappable.CloudPlatform) StackV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request) TransactionExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException) ImageV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.responses.ImageV4Response) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) TransactionRuntimeExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionRuntimeExecutionException)

Aggregations

ImageV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.responses.ImageV4Response)16 TestFailException (com.sequenceiq.it.cloudbreak.exception.TestFailException)4 BaseStackDetailsV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.responses.BaseStackDetailsV4Response)3 ImagesV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.responses.ImagesV4Response)3 NotImplementedException (org.apache.commons.lang3.NotImplementedException)3 StackV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request)2 AbstractEntityConverterTest (com.sequenceiq.cloudbreak.converter.AbstractEntityConverterTest)2 SdxCluster (com.sequenceiq.datalake.entity.SdxCluster)2 FlowIdentifier (com.sequenceiq.flow.api.model.FlowIdentifier)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Test (org.junit.Test)2 Test (org.junit.jupiter.api.Test)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 ImageCatalogV4Endpoint (com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.ImageCatalogV4Endpoint)1 BaseImageV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.responses.BaseImageV4Response)1 ImageSettingsV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.image.ImageSettingsV4Request)1 ImageStackDetails (com.sequenceiq.cloudbreak.cloud.model.catalog.ImageStackDetails)1 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)1 CloudbreakServiceException (com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException)1