use of com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV3 in project cloudbreak by hortonworks.
the class SdxControllerTest method generateImageCatalogTest.
@Test
void generateImageCatalogTest() {
CloudbreakImageCatalogV3 imageCatalog = mock(CloudbreakImageCatalogV3.class);
when(sdxImageCatalogService.generateImageCatalog(SDX_CLUSTER_NAME)).thenReturn(imageCatalog);
SdxGenerateImageCatalogResponse actual = sdxController.generateImageCatalog(SDX_CLUSTER_NAME);
assertEquals(imageCatalog, actual.getImageCatalog());
}
use of com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV3 in project cloudbreak by hortonworks.
the class CachedImageCatalogWrapperProvider method filterImagesByOsType.
private CloudbreakImageCatalogV3 filterImagesByOsType(CloudbreakImageCatalogV3 catalog) {
LOGGER.debug("Filtering images by OS type {}", getEnabledLinuxTypes());
if (CollectionUtils.isEmpty(getEnabledLinuxTypes())) {
return catalog;
}
Images catalogImages = catalog.getImages();
List<Image> filteredBaseImages = filterImages(catalogImages.getBaseImages(), enabledOsPredicate());
List<Image> filteredCdhImages = filterImages(catalogImages.getCdhImages(), enabledOsPredicate());
List<Image> filteredFreeipaImages = filterImages(catalogImages.getFreeIpaImages(), enabledOsPredicate());
Images images = new Images(filteredBaseImages, filteredCdhImages, filteredFreeipaImages, catalogImages.getSuppertedVersions());
return new CloudbreakImageCatalogV3(images, catalog.getVersions());
}
use of com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV3 in project cloudbreak by hortonworks.
the class CachedImageCatalogWrapperProvider method getImageCatalogWrapper.
@Cacheable(cacheNames = "imageCatalogCache", key = "#catalogUrl")
public ImageCatalogWrapper getImageCatalogWrapper(String catalogUrl) throws CloudbreakImageCatalogException {
try {
if (Objects.nonNull(catalogUrl)) {
long started = System.currentTimeMillis();
String content;
if (catalogUrl.startsWith("http")) {
Client client = restClientFactory.getOrCreateDefault();
WebTarget target = client.target(catalogUrl);
Response response = target.request().get();
content = readResponse(target, response);
} else {
content = readCatalogFromFile(catalogUrl);
}
CloudbreakImageCatalogV3 catalog = objectMapper.readValue(content, CloudbreakImageCatalogV3.class);
if (Objects.nonNull(catalog)) {
imageCatalogServiceProxy.validate(catalog);
cleanAndValidateMaps(catalog);
catalog = filterImagesByOsType(catalog);
ImageCatalogMetaData metaData = imageCatalogServiceProxy.getImageCatalogMetaData(catalog);
long timeOfParse = System.currentTimeMillis() - started;
LOGGER.debug("ImageCatalog has been get and parsed from '{}' and took '{}' ms.", catalogUrl, timeOfParse);
return new ImageCatalogWrapper(catalog, metaData);
}
throw new CloudbreakImageCatalogException(String.format("Failed to read the content of '%s' as an image catalog.", catalogUrl));
}
throw new CloudbreakImageCatalogException("Unable to fetch image catalog. The catalogUrl is null.");
} catch (CloudbreakImageCatalogException e) {
throw e;
} catch (RuntimeException e) {
throw new CloudbreakImageCatalogException(String.format("Failed to get image catalog: %s from %s", e.getMessage(), catalogUrl), e);
} catch (JsonMappingException e) {
throw new CloudbreakImageCatalogException(e.getMessage(), e);
} catch (IOException e) {
throw new CloudbreakImageCatalogException(String.format("Failed to read image catalog from file: '%s'", catalogUrl), e);
}
}
use of com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV3 in project cloudbreak by hortonworks.
the class ImageCatalogService method getImageCatalogMetaData.
default ImageCatalogMetaData getImageCatalogMetaData(CloudbreakImageCatalogV3 imageCatalogV3) {
ImageFilterResult imageFilterResult = getImageFilterResult(imageCatalogV3);
List<String> runtimes = imageFilterResult.getImages().stream().map(Image::getVersion).distinct().map(version -> (Versioned) () -> version).sorted(VERSION_COMPARATOR.reversed()).map(Versioned::getVersion).collect(toList());
return new ImageCatalogMetaData(runtimes);
}
use of com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV3 in project cloudbreak by hortonworks.
the class SdxImageCatalogServiceTest method shouldCallGenererateImageCatalog.
@Test
void shouldCallGenererateImageCatalog() {
CloudbreakImageCatalogV3 imageCatalogV3 = mock(CloudbreakImageCatalogV3.class);
GenerateImageCatalogV4Response response = new GenerateImageCatalogV4Response(imageCatalogV3);
when(stackV4Endpoint.generateImageCatalogInternal(WORKSPACE_ID_DEFAULT, CLUSTER_NAME, USER_CRN)).thenReturn(response);
when(regionAwareInternalCrnGenerator.getInternalCrnForServiceAsString()).thenReturn("crn");
when(regionAwareInternalCrnGeneratorFactory.iam()).thenReturn(regionAwareInternalCrnGenerator);
when(regionAwareInternalCrnGenerator.getInternalCrnForServiceAsString()).thenReturn("crn");
when(regionAwareInternalCrnGeneratorFactory.iam()).thenReturn(regionAwareInternalCrnGenerator);
CloudbreakImageCatalogV3 actual = ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.generateImageCatalog(CLUSTER_NAME));
assertEquals(imageCatalogV3, actual);
}
Aggregations