use of com.sequenceiq.cloudbreak.service.image.catalog.model.ImageCatalogPlatform in project cloudbreak by hortonworks.
the class ImageService method create.
@Measure(ImageService.class)
public Set<Component> create(Stack stack, StatedImage imgFromCatalog) throws CloudbreakImageNotFoundException, CloudbreakImageCatalogException {
String region = stack.getRegion();
String cloudPlatform = stack.getCloudPlatform();
ImageCatalogPlatform platformString = platformStringTransformer.getPlatformStringForImageCatalog(cloudPlatform, stack.getPlatformVariant());
LOGGER.debug("Determined image from catalog: {}", imgFromCatalog);
String imageName = determineImageName(cloudPlatform, platformString, region, imgFromCatalog.getImage());
LOGGER.debug("Selected VM image for CloudPlatform '{}' and region '{}' is: {} from: {} image catalog", platformString, region, imageName, imgFromCatalog.getImageCatalogUrl());
Set<Component> components = getComponents(stack, Map.of(), imgFromCatalog, EnumSet.of(IMAGE, CDH_PRODUCT_DETAILS, CM_REPO_DETAILS));
componentConfigProviderService.store(components);
return components;
}
use of com.sequenceiq.cloudbreak.service.image.catalog.model.ImageCatalogPlatform in project cloudbreak by hortonworks.
the class ImageService method determineImageFromCatalog.
// CHECKSTYLE:OFF
@Measure(ImageService.class)
public StatedImage determineImageFromCatalog(Long workspaceId, ImageSettingsV4Request imageSettings, String platformString, String variant, Blueprint blueprint, boolean useBaseImage, boolean baseImageEnabled, User user, Predicate<com.sequenceiq.cloudbreak.cloud.model.catalog.Image> imagePredicate) throws CloudbreakImageNotFoundException, CloudbreakImageCatalogException {
ImageCatalogPlatform platform = platformStringTransformer.getPlatformStringForImageCatalog(platformString, variant);
if (imageSettings != null && StringUtils.isNotEmpty(imageSettings.getId())) {
LOGGER.debug("Image id {} is specified for the stack.", imageSettings.getId());
if (imageSettings.getCatalog() == null) {
imageSettings.setCatalog(CDP_DEFAULT_CATALOG_NAME);
}
StatedImage image = imageCatalogService.getImageByCatalogName(workspaceId, imageSettings.getId(), imageSettings.getCatalog());
return checkIfBasePermitted(image, baseImageEnabled);
} else if (useBaseImage && !baseImageEnabled) {
throw new CloudbreakImageCatalogException("Inconsistent request, base images are disabled but custom repo information is submitted!");
}
String clusterVersion = getClusterVersion(blueprint);
Set<String> operatingSystems;
try {
operatingSystems = getSupportedOperatingSystems(workspaceId, imageSettings, clusterVersion, platform);
} catch (Exception ex) {
throw new CloudbreakImageCatalogException(ex);
}
ImageCatalog imageCatalog = getImageCatalogFromRequestOrDefault(workspaceId, imageSettings, user);
ImageFilter imageFilter = new ImageFilter(imageCatalog, Set.of(platform), null, baseImageEnabled, operatingSystems, clusterVersion);
LOGGER.info("Image id is not specified for the stack.");
if (baseImageEnabled && useBaseImage) {
LOGGER.info("Trying to select a base image.");
return imageCatalogService.getLatestBaseImageDefaultPreferred(imageFilter, imagePredicate);
}
LOGGER.info("Trying to select a prewarmed image.");
return imageCatalogService.getImagePrewarmedDefaultPreferred(imageFilter, imagePredicate);
}
use of com.sequenceiq.cloudbreak.service.image.catalog.model.ImageCatalogPlatform in project cloudbreak by hortonworks.
the class DefaultImageCatalogService method getImageFromDefaultCatalog.
public StatedImage getImageFromDefaultCatalog(String type, ImageCatalogPlatform provider, String runtime) throws CloudbreakImageCatalogException, CloudbreakImageNotFoundException {
ImageType imageType = ImageType.valueOf(type);
StatedImage statedImage;
switch(imageType) {
case FREEIPA:
throw new BadRequestException(String.format("Runtime is not supported in case of '%s' image type", imageType));
case RUNTIME:
ImageCatalog imageCatalog = getCloudbreakDefaultImageCatalog();
ImageFilter imageFilter = new ImageFilter(imageCatalog, Set.of(provider), null, false, null, runtime);
statedImage = imageCatalogService.getImagePrewarmedDefaultPreferred(imageFilter, i -> true);
break;
default:
throw new BadRequestException(String.format("Image type '%s' is not supported.", type));
}
return statedImage;
}
use of com.sequenceiq.cloudbreak.service.image.catalog.model.ImageCatalogPlatform in project cloudbreak by hortonworks.
the class UpgradeOptionsResponseFactory method getImageName.
private String getImageName(Image image, String cloudPlatform, String region) {
String imageName;
try {
ImageCatalogPlatform platformString = platformStringTransformer.getPlatformStringForImageCatalogByRegion(cloudPlatform, region);
imageName = imageService.determineImageName(cloudPlatform, platformString, region, image);
} catch (CloudbreakImageNotFoundException e) {
throw new NotFoundException(String.format("Image (%s) name not found", image.getUuid()), e);
}
return imageName;
}
use of com.sequenceiq.cloudbreak.service.image.catalog.model.ImageCatalogPlatform in project cloudbreak by hortonworks.
the class CmSyncImageCollectorServiceTest method testCollectImagesWhenNoImageUuidAndImageCatalogExceptionThenReturnsEmpty.
@Test
void testCollectImagesWhenNoImageUuidAndImageCatalogExceptionThenReturnsEmpty() throws CloudbreakImageNotFoundException, CloudbreakImageCatalogException {
ImageCatalogPlatform imageCatalogPlatform = imageCatalogPlatform(CURRENT_CLOUD_PLATFORM);
setupStack(true, true);
Set<String> candidateImageUuids = Set.of();
when(imageCatalogService.getAllCdhImages(USER_CRN, WORKSPCE_ID, CURRENT_IMAGE_CATALOG_NAME, Set.of(imageCatalogPlatform(CURRENT_CLOUD_PLATFORM)))).thenThrow(new CloudbreakImageCatalogException("My custom image catalog exception"));
when(imageService.getCurrentImageCatalogName(STACK_ID)).thenReturn(CURRENT_IMAGE_CATALOG_NAME);
when(platformStringTransformer.getPlatformStringForImageCatalogSet(anyObject(), anyString())).thenReturn(Set.of(imageCatalogPlatform));
Set<Image> collectedImages = underTest.collectImages(USER_CRN, stack, candidateImageUuids);
assertThat(collectedImages, emptyCollectionOf(Image.class));
verify(imageService).getCurrentImageCatalogName(STACK_ID);
verify(imageCatalogService).getAllCdhImages(USER_CRN, WORKSPCE_ID, CURRENT_IMAGE_CATALOG_NAME, Set.of(imageCatalogPlatform));
verify(imageService, never()).getCurrentImage(anyLong());
verify(imageCatalogService, never()).getImageByCatalogName(anyLong(), anyString(), anyString());
}
Aggregations