Search in sources :

Example 16 with ImageCatalogPlatform

use of com.sequenceiq.cloudbreak.service.image.catalog.model.ImageCatalogPlatform in project cloudbreak by hortonworks.

the class CmSyncImageCollectorServiceTest method testCollectImagesWhenNoImageUuidThenAllImagesCollected.

@Test
void testCollectImagesWhenNoImageUuidThenAllImagesCollected() throws CloudbreakImageNotFoundException, CloudbreakImageCatalogException {
    ImageCatalogPlatform imageCatalogPlatform = imageCatalogPlatform(CURRENT_CLOUD_PLATFORM);
    setupStack(true, true);
    Set<String> candidateImageUuids = Set.of();
    List<Image> allCdhImages = List.of(getImage(IMAGE_UUID_1));
    when(imageService.getCurrentImageCatalogName(STACK_ID)).thenReturn(CURRENT_IMAGE_CATALOG_NAME);
    when(imageCatalogService.getAllCdhImages(anyString(), anyLong(), anyString(), anySet())).thenReturn(allCdhImages);
    when(platformStringTransformer.getPlatformStringForImageCatalogSet(anyObject(), anyString())).thenReturn(Set.of(imageCatalogPlatform));
    Set<Image> collectedImages = underTest.collectImages(USER_CRN, stack, candidateImageUuids);
    assertThat(collectedImages, hasSize(1));
    assertThat(collectedImages, containsInAnyOrder(hasProperty("uuid", is(IMAGE_UUID_1))));
    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());
}
Also used : ImageCatalogPlatform(com.sequenceiq.cloudbreak.service.image.catalog.model.ImageCatalogPlatform) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) StatedImage(com.sequenceiq.cloudbreak.service.image.StatedImage) Image(com.sequenceiq.cloudbreak.cloud.model.catalog.Image) Test(org.junit.jupiter.api.Test)

Example 17 with ImageCatalogPlatform

use of com.sequenceiq.cloudbreak.service.image.catalog.model.ImageCatalogPlatform in project cloudbreak by hortonworks.

the class UpgradeOptionsResponseFactoryTest method testCreateV4ResponseShouldReturnTheUpgradeOptionsFromTheGivenParameters.

@Test
public void testCreateV4ResponseShouldReturnTheUpgradeOptionsFromTheGivenParameters() throws CloudbreakImageNotFoundException {
    ImageCatalogPlatform imageCatalogPlatform = imageCatalogPlatform(CLOUD_PLATFORM);
    Map<String, String> packageVersions = createPackageVersions();
    ImageComponentVersions expectedPackageVersions = creatExpectedPackageVersions();
    Image currentImage = createImage(packageVersions);
    ImageFilterResult availableImages = createAvailableImages(packageVersions);
    when(platformStringTransformer.getPlatformStringForImageCatalogByRegion(anyString(), anyString())).thenReturn(imageCatalogPlatform);
    when(imageService.determineImageName(CLOUD_PLATFORM, imageCatalogPlatform, REGION, currentImage)).thenReturn(IMAGE_NAME);
    when(imageService.determineImageName(CLOUD_PLATFORM, imageCatalogPlatform, REGION, availableImages.getImages().get(0))).thenReturn(IMAGE_NAME);
    when(componentVersionProvider.getComponentVersions(eq(packageVersions), any(), any())).thenReturn(expectedPackageVersions);
    UpgradeV4Response actual = underTest.createV4Response(currentImage, availableImages, CLOUD_PLATFORM, REGION, IMAGE_CATALOG_NAME);
    assertEquals(IMAGE_ID, actual.getCurrent().getImageId());
    assertEquals(IMAGE_CATALOG_NAME, actual.getCurrent().getImageCatalogName());
    assertEquals(IMAGE_NAME, actual.getCurrent().getImageName());
    assertEquals(expectedPackageVersions, actual.getCurrent().getComponentVersions());
    assertEquals(CREATION_DATE, actual.getCurrent().getCreated());
    assertEquals(IMAGE_ID, actual.getUpgradeCandidates().get(0).getImageId());
    assertEquals(IMAGE_CATALOG_NAME, actual.getUpgradeCandidates().get(0).getImageCatalogName());
    assertEquals(IMAGE_NAME, actual.getUpgradeCandidates().get(0).getImageName());
    assertEquals(expectedPackageVersions, actual.getUpgradeCandidates().get(0).getComponentVersions());
    assertEquals(CREATION_DATE, actual.getUpgradeCandidates().get(0).getCreated());
}
Also used : UpgradeV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeV4Response) ImageCatalogPlatform(com.sequenceiq.cloudbreak.service.image.catalog.model.ImageCatalogPlatform) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ImageFilterResult(com.sequenceiq.cloudbreak.service.upgrade.image.ImageFilterResult) Image(com.sequenceiq.cloudbreak.cloud.model.catalog.Image) ImageComponentVersions(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.ImageComponentVersions) Test(org.junit.Test)

Example 18 with ImageCatalogPlatform

use of com.sequenceiq.cloudbreak.service.image.catalog.model.ImageCatalogPlatform in project cloudbreak by hortonworks.

the class StackImageService method getImageModelFromStatedImage.

public Image getImageModelFromStatedImage(Stack stack, Image currentImage, StatedImage targetImage) {
    try {
        ImageCatalogPlatform platformString = platformStringTransformer.getPlatformStringForImageCatalog(stack.getCloudPlatform(), stack.getPlatformVariant());
        String cloudPlatform = platform(stack.cloudPlatform()).value().toLowerCase();
        String newImageName = imageService.determineImageName(cloudPlatform, platformString, stack.getRegion(), targetImage.getImage());
        return new Image(newImageName, currentImage.getUserdata(), targetImage.getImage().getOs(), targetImage.getImage().getOsType(), targetImage.getImageCatalogUrl(), targetImage.getImageCatalogName(), targetImage.getImage().getUuid(), targetImage.getImage().getPackageVersions());
    } catch (CloudbreakImageNotFoundException e) {
        LOGGER.info("Could not find image", e);
        throw new CloudbreakServiceException("Could not find image", e);
    }
}
Also used : CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) ImageCatalogPlatform(com.sequenceiq.cloudbreak.service.image.catalog.model.ImageCatalogPlatform) CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) Image(com.sequenceiq.cloudbreak.cloud.model.Image) StatedImage(com.sequenceiq.cloudbreak.service.image.StatedImage)

Example 19 with ImageCatalogPlatform

use of com.sequenceiq.cloudbreak.service.image.catalog.model.ImageCatalogPlatform in project cloudbreak by hortonworks.

the class ImageCatalogServiceTest method testGetImagesWithPlatform.

@Test
public void testGetImagesWithPlatform() throws CloudbreakImageCatalogException, IOException {
    setupUserProfileService();
    setupImageCatalogProvider(DEFAULT_CATALOG_URL, V2_CB_CATALOG_FILE);
    ImageCatalog imageCatalog = new ImageCatalog();
    imageCatalog.setImageCatalogUrl(DEFAULT_CATALOG_URL);
    ImageCatalogPlatform imageCatalogPlatform = imageCatalogPlatform("AWS");
    when(platformStringTransformer.getPlatformStringForImageCatalog(any(String.class), anyBoolean())).thenReturn(imageCatalogPlatform);
    when(imageCatalogRepository.findByNameAndWorkspaceId(anyString(), anyLong())).thenReturn(Optional.of(imageCatalog));
    underTest.getImagesByCatalogName(ORG_ID, "catalog", null, imageCatalogPlatform, false);
    verify(entitlementService, times(1)).baseImageEnabled(Objects.requireNonNull(Crn.fromString(user.getUserCrn())).getAccountId());
    verify(entitlementService, never()).baseImageEnabled(user.getUserCrn());
    verify(stackImageFilterService, never()).getApplicableImages(anyLong(), anyString(), anyString());
    verify(stackImageFilterService, never()).getApplicableImages(anyLong(), anyString());
}
Also used : ImageCatalogPlatform(com.sequenceiq.cloudbreak.service.image.catalog.model.ImageCatalogPlatform) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ImageCatalog(com.sequenceiq.cloudbreak.domain.ImageCatalog) Test(org.junit.Test)

Aggregations

ImageCatalogPlatform (com.sequenceiq.cloudbreak.service.image.catalog.model.ImageCatalogPlatform)19 Image (com.sequenceiq.cloudbreak.cloud.model.catalog.Image)10 CloudbreakImageCatalogException (com.sequenceiq.cloudbreak.core.CloudbreakImageCatalogException)6 ImageCatalog (com.sequenceiq.cloudbreak.domain.ImageCatalog)6 CloudbreakImageNotFoundException (com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException)5 Test (org.junit.jupiter.api.Test)5 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)4 Optional (java.util.Optional)4 Inject (javax.inject.Inject)4 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)4 ClouderaManagerRepo (com.sequenceiq.cloudbreak.cloud.model.ClouderaManagerRepo)3 Images (com.sequenceiq.cloudbreak.cloud.model.catalog.Images)3 NotFoundException (com.sequenceiq.cloudbreak.common.exception.NotFoundException)3 StatedImage (com.sequenceiq.cloudbreak.service.image.StatedImage)3 StatedImages (com.sequenceiq.cloudbreak.service.image.StatedImages)3 ClouderaManagerStackDescriptorV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.util.responses.ClouderaManagerStackDescriptorV4Response)2 StackMatrixV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.util.responses.StackMatrixV4Response)2 Measure (com.sequenceiq.cloudbreak.aspect.Measure)2 Image (com.sequenceiq.cloudbreak.cloud.model.Image)2 StackType (com.sequenceiq.cloudbreak.cloud.model.component.StackType)2