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;
}
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;
}
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());
}
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);
});
}
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);
}
Aggregations