use of com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV2 in project cloudbreak by hortonworks.
the class ImageCatalogServiceTest method beforeTest.
@Before
public void beforeTest() throws Exception {
String catalogJson = FileReaderUtils.readFileFromClasspath("com/sequenceiq/cloudbreak/service/image/cb-image-catalog-v2.json");
CloudbreakImageCatalogV2 catalog = JsonUtil.readValue(catalogJson, CloudbreakImageCatalogV2.class);
when(imageCatalogProvider.getImageCatalogV2("")).thenReturn(catalog);
IdentityUser user = getIdentityUser();
when(authenticatedUserService.getCbUser()).thenReturn(user);
constants.addAll(Collections.singletonList(new CloudConstant() {
@Override
public Platform platform() {
return Platform.platform("AWS");
}
@Override
public Variant variant() {
return Variant.variant("AWS");
}
}));
ReflectionTestUtils.setField(underTest, ImageCatalogService.class, "defaultCatalogUrl", "http://localhost/imagecatalog-url", null);
ReflectionTestUtils.setField(underTest, ImageCatalogService.class, "cbVersion", "unspecified", null);
}
use of com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV2 in project cloudbreak by hortonworks.
the class ImageCatalogServiceDefaultNotFoundTest method beforeTest.
@Before
public void beforeTest() throws Exception {
String catalogJson = FileReaderUtils.readFileFromClasspath("com/sequenceiq/cloudbreak/service/image/no-default-imagecatalog.json");
CloudbreakImageCatalogV2 catalog = JsonUtil.readValue(catalogJson, CloudbreakImageCatalogV2.class);
when(imageCatalogProvider.getImageCatalogV2("")).thenReturn(catalog);
IdentityUser user = getIdentityUser();
when(authenticatedUserService.getCbUser()).thenReturn(user);
when(userProfileService.get(user.getAccount(), user.getUserId(), user.getUsername())).thenReturn(new UserProfile());
}
use of com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV2 in project cloudbreak by hortonworks.
the class ImageCatalogProviderTest method testReadImageCatalogFromFile.
@Test
public void testReadImageCatalogFromFile() throws Exception {
String path = getPath(CB_IMAGE_CATALOG_V2_JSON);
underTest.setEtcConfigDir(path);
CloudbreakImageCatalogV2 catalog = underTest.getImageCatalogV2(CB_IMAGE_CATALOG_V2_JSON);
Assert.assertNotNull("Check that the parsed ImageCatalog not null.", catalog);
Optional<CloudbreakVersion> ver = catalog.getVersions().getCloudbreakVersions().stream().filter(v -> v.getVersions().contains(CB_VERSION)).findFirst();
Assert.assertTrue("Check that the parsed ImageCatalog contains the desired version of Cloudbreak.", ver.isPresent());
List<String> imageIds = ver.get().getImageIds();
Assert.assertNotNull("Check that the parsed ImageCatalog contains the desired version of Cloudbreak with image id(s).", imageIds);
Optional<String> imageIdOptional = imageIds.stream().findFirst();
Assert.assertTrue("Check that the parsed ImageCatalog contains Ambari image reference for the Cloudbreak version.", imageIdOptional.isPresent());
String imageId = imageIdOptional.get();
boolean baseImageFound = false;
boolean hdpImageFound = false;
boolean hdfImageFoiund = false;
if (catalog.getImages().getBaseImages() != null) {
baseImageFound = catalog.getImages().getBaseImages().stream().anyMatch(i -> i.getUuid().equals(imageId));
}
if (catalog.getImages().getHdpImages() != null) {
hdpImageFound = catalog.getImages().getHdpImages().stream().anyMatch(i -> i.getUuid().equals(imageId));
}
if (catalog.getImages().getHdfImages() != null) {
hdfImageFoiund = catalog.getImages().getHdfImages().stream().anyMatch(i -> i.getUuid().equals(imageId));
}
boolean anyImageFoundForVersion = baseImageFound || hdpImageFound || hdfImageFoiund;
Assert.assertTrue("Check that the parsed ImageCatalog contains Ambari image for the Cloudbreak version.", anyImageFoundForVersion);
}
use of com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV2 in project cloudbreak by hortonworks.
the class ImageCatalogProviderTest method testImageCatalogWithoutHdpImages.
@Test
public void testImageCatalogWithoutHdpImages() throws CloudbreakImageCatalogException, IOException {
String path = getPath(CB_IMAGE_CATALOG_WITHOUT_HDP_IMAGES);
underTest.setEtcConfigDir(path);
CloudbreakImageCatalogV2 imageCatalogV2 = underTest.getImageCatalogV2(CB_IMAGE_CATALOG_WITHOUT_HDP_IMAGES);
Assert.assertNotNull(imageCatalogV2.getImages().getHdpImages());
}
use of com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV2 in project cloudbreak by hortonworks.
the class CachedImageCatalogProvider method getImageCatalogV2.
@Cacheable(cacheNames = "imageCatalogCache", key = "#catalogUrl")
public CloudbreakImageCatalogV2 getImageCatalogV2(String catalogUrl) throws CloudbreakImageCatalogException {
CloudbreakImageCatalogV2 catalog = null;
if (catalogUrl == null) {
LOGGER.warn("No image catalog was defined!");
return catalog;
}
try {
long started = System.currentTimeMillis();
if (catalogUrl.startsWith("http")) {
Client client = RestClientUtil.get();
WebTarget target = client.target(catalogUrl);
Response response = target.request().get();
catalog = checkResponse(target, response);
} else {
String content = readCatalogFromFile(catalogUrl);
catalog = JsonUtil.readValue(content, CloudbreakImageCatalogV2.class);
}
validateImageCatalogUuids(catalog);
validateCloudBreakVersions(catalog);
cleanAndValidateMaps(catalog);
long timeOfParse = System.currentTimeMillis() - started;
LOGGER.info("ImageCatalog has been get and parsed from '{}' and took '{}' ms.", catalogUrl, timeOfParse);
} catch (RuntimeException e) {
throw new CloudbreakImageCatalogException("Failed to get image catalog", 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);
}
return catalog;
}
Aggregations