Search in sources :

Example 6 with CloudbreakImageCatalogV2

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);
}
Also used : IdentityUser(com.sequenceiq.cloudbreak.common.model.user.IdentityUser) CloudbreakImageCatalogV2(com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV2) CloudConstant(com.sequenceiq.cloudbreak.cloud.CloudConstant) Before(org.junit.Before)

Example 7 with CloudbreakImageCatalogV2

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());
}
Also used : IdentityUser(com.sequenceiq.cloudbreak.common.model.user.IdentityUser) UserProfile(com.sequenceiq.cloudbreak.domain.UserProfile) CloudbreakImageCatalogV2(com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV2) Before(org.junit.Before)

Example 8 with CloudbreakImageCatalogV2

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);
}
Also used : InjectMocks(org.mockito.InjectMocks) List(java.util.List) MockitoJUnitRunner(org.mockito.runners.MockitoJUnitRunner) CloudbreakVersion(com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakVersion) RunWith(org.junit.runner.RunWith) Optional(java.util.Optional) TestUtil(com.sequenceiq.cloudbreak.TestUtil) IOException(java.io.IOException) Test(org.junit.Test) CloudbreakImageCatalogException(com.sequenceiq.cloudbreak.core.CloudbreakImageCatalogException) Assert(org.junit.Assert) CloudbreakImageCatalogV2(com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV2) CloudbreakVersion(com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakVersion) CloudbreakImageCatalogV2(com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV2) Test(org.junit.Test)

Example 9 with CloudbreakImageCatalogV2

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());
}
Also used : CloudbreakImageCatalogV2(com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV2) Test(org.junit.Test)

Example 10 with CloudbreakImageCatalogV2

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;
}
Also used : Response(javax.ws.rs.core.Response) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) CloudbreakImageCatalogV2(com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV2) WebTarget(javax.ws.rs.client.WebTarget) IOException(java.io.IOException) Client(javax.ws.rs.client.Client) CloudbreakImageCatalogException(com.sequenceiq.cloudbreak.core.CloudbreakImageCatalogException) Cacheable(org.springframework.cache.annotation.Cacheable)

Aggregations

CloudbreakImageCatalogV2 (com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV2)10 Test (org.junit.Test)5 IdentityUser (com.sequenceiq.cloudbreak.common.model.user.IdentityUser)4 CloudbreakImageCatalogException (com.sequenceiq.cloudbreak.core.CloudbreakImageCatalogException)3 UserProfile (com.sequenceiq.cloudbreak.domain.UserProfile)3 Before (org.junit.Before)3 CloudbreakVersion (com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakVersion)2 IOException (java.io.IOException)2 List (java.util.List)2 Optional (java.util.Optional)2 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 TestUtil (com.sequenceiq.cloudbreak.TestUtil)1 CloudConstant (com.sequenceiq.cloudbreak.cloud.CloudConstant)1 Versioned (com.sequenceiq.cloudbreak.cloud.model.Versioned)1 Image (com.sequenceiq.cloudbreak.cloud.model.catalog.Image)1 Images (com.sequenceiq.cloudbreak.cloud.model.catalog.Images)1 APIResourceType (com.sequenceiq.cloudbreak.common.type.APIResourceType)1 AuthenticatedUserService (com.sequenceiq.cloudbreak.controller.AuthenticatedUserService)1 BadRequestException (com.sequenceiq.cloudbreak.controller.BadRequestException)1