Search in sources :

Example 16 with CustomImage

use of com.sequenceiq.cloudbreak.domain.CustomImage in project cloudbreak by hortonworks.

the class CustomImageProviderTest method testMergeSourceImageAndCustomImagePropertiesInCaseOfFreeipaImage.

@Test
public void testMergeSourceImageAndCustomImagePropertiesInCaseOfFreeipaImage() throws Exception {
    StatedImage statedImage = getStatedImageFromCatalog(V3_FREEIPA_CATALOG_FILE, "3b6ae396-df40-4e2b-7c2b-54b15822614c");
    CustomImage customImage = getCustomImage(ImageType.FREEIPA, CUSTOM_IMAGE_ID, CUSTOM_BASE_PARCEL_URL);
    VmImage vmImage1 = new VmImage();
    vmImage1.setRegion("europe-west1");
    vmImage1.setImageReference("cloudera-freeipa-images/freeipa-cdh--2103081304.tar.gz");
    customImage.setVmImage(Set.of(vmImage1));
    StatedImage image = underTest.mergeSourceImageAndCustomImageProperties(statedImage, customImage, CUSTOM_IMAGE_CATALOG_URL, CUSTOM_CATALOG_NAME);
    assertEquals(customImage.getCreated(), image.getImage().getCreated());
    assertEquals(customImage.getDescription(), image.getImage().getDescription());
    assertEquals(CUSTOM_IMAGE_ID, image.getImage().getUuid());
    assertTrue(image.getImage().getRepo().isEmpty());
    assertTrue(image.getImage().getPreWarmParcels().isEmpty());
    assertTrue(image.getImage().getPreWarmCsd().isEmpty());
    Map<String, Map<String, String>> imageSetsByProvider = image.getImage().getImageSetsByProvider();
    assertTrue(imageSetsByProvider.containsKey("aws"));
    assertEquals(1, imageSetsByProvider.get("aws").size());
    assertTrue(imageSetsByProvider.get("aws").containsKey("europe-west1"));
    assertEquals("cloudera-freeipa-images/freeipa-cdh--2103081304.tar.gz", image.getImage().getImageSetsByProvider().get("aws").get("europe-west1"));
}
Also used : CustomImage(com.sequenceiq.cloudbreak.domain.CustomImage) VmImage(com.sequenceiq.cloudbreak.domain.VmImage) Map(java.util.Map) Test(org.junit.Test)

Example 17 with CustomImage

use of com.sequenceiq.cloudbreak.domain.CustomImage in project cloudbreak by hortonworks.

the class CustomImageCatalogServiceTest method testCreateCustomImageShouldFailInCaseOfNonCustomImageCatalog.

@Test
public void testCreateCustomImageShouldFailInCaseOfNonCustomImageCatalog() throws TransactionService.TransactionExecutionException, CloudbreakImageNotFoundException, CloudbreakImageCatalogException {
    CrnTestUtil.mockCrnGenerator(regionAwareCrnGenerator);
    ImageCatalog imageCatalog = new ImageCatalog();
    CustomImage customImage = aCustomImage();
    doAnswer(invocation -> ((Supplier<CustomImage>) invocation.getArgument(0)).get()).when(transactionService).required(any(Supplier.class));
    when(imageCatalogService.getImageCatalogByName(WORKSPACE_ID, IMAGE_CATALOG_NAME)).thenReturn(imageCatalog);
    when(imageCatalogService.getSourceImageByImageType(customImage)).thenThrow(new CloudbreakImageCatalogException(""));
    assertThrows(NotFoundException.class, () -> victim.createCustomImage(WORKSPACE_ID, ACCOUNT_ID, CREATOR, IMAGE_CATALOG_NAME, customImage));
}
Also used : CustomImage(com.sequenceiq.cloudbreak.domain.CustomImage) Supplier(java.util.function.Supplier) ImageCatalog(com.sequenceiq.cloudbreak.domain.ImageCatalog) CloudbreakImageCatalogException(com.sequenceiq.cloudbreak.core.CloudbreakImageCatalogException) Test(org.junit.jupiter.api.Test)

Example 18 with CustomImage

use of com.sequenceiq.cloudbreak.domain.CustomImage in project cloudbreak by hortonworks.

the class CustomImageCatalogServiceTest method testDeleteCustomImageShouldFailInCaseOfNonCustomImageCatalog.

@Test
public void testDeleteCustomImageShouldFailInCaseOfNonCustomImageCatalog() throws TransactionService.TransactionExecutionException {
    ImageCatalog imageCatalog = new ImageCatalog();
    imageCatalog.setImageCatalogUrl(IMAGE_CATALOG_URL);
    doAnswer(invocation -> ((Supplier<CustomImage>) invocation.getArgument(0)).get()).when(transactionService).required(any(Supplier.class));
    when(imageCatalogService.getImageCatalogByName(WORKSPACE_ID, IMAGE_CATALOG_NAME)).thenReturn(imageCatalog);
    assertThrows(BadRequestException.class, () -> victim.deleteCustomImage(WORKSPACE_ID, IMAGE_CATALOG_NAME, IMAGE_NAME));
}
Also used : CustomImage(com.sequenceiq.cloudbreak.domain.CustomImage) Supplier(java.util.function.Supplier) ImageCatalog(com.sequenceiq.cloudbreak.domain.ImageCatalog) Test(org.junit.jupiter.api.Test)

Example 19 with CustomImage

use of com.sequenceiq.cloudbreak.domain.CustomImage in project cloudbreak by hortonworks.

the class CustomImageCatalogServiceTest method testDeleteCustomImage.

@Test
public void testDeleteCustomImage() throws TransactionService.TransactionExecutionException {
    CustomImage expected = aCustomImage();
    ImageCatalog imageCatalog = new ImageCatalog();
    imageCatalog.getCustomImages().add(expected);
    doAnswer(invocation -> ((Supplier<CustomImage>) invocation.getArgument(0)).get()).when(transactionService).required(any(Supplier.class));
    when(imageCatalogService.getImageCatalogByName(WORKSPACE_ID, IMAGE_CATALOG_NAME)).thenReturn(imageCatalog);
    when(imageCatalogService.pureSave(imageCatalog)).thenReturn(imageCatalog);
    CustomImage actual = victim.deleteCustomImage(WORKSPACE_ID, IMAGE_CATALOG_NAME, IMAGE_NAME);
    assertTrue(imageCatalog.getCustomImages().isEmpty());
    assertEquals(expected, actual);
}
Also used : CustomImage(com.sequenceiq.cloudbreak.domain.CustomImage) Supplier(java.util.function.Supplier) ImageCatalog(com.sequenceiq.cloudbreak.domain.ImageCatalog) Test(org.junit.jupiter.api.Test)

Example 20 with CustomImage

use of com.sequenceiq.cloudbreak.domain.CustomImage in project cloudbreak by hortonworks.

the class CustomImageCatalogServiceTest method testUpdateCustomImageWithDeletedVmImage.

@Test
public void testUpdateCustomImageWithDeletedVmImage() throws TransactionService.TransactionExecutionException {
    CustomImage updatedCustomImage = aCustomImage();
    updatedCustomImage.setVmImage(Collections.emptySet());
    CustomImage savedCustomImage = new CustomImage();
    VmImage vmImage = new VmImage();
    vmImage.setRegion(REGION);
    savedCustomImage.getVmImage().add(vmImage);
    savedCustomImage.setName(IMAGE_NAME);
    ImageCatalog imageCatalog = new ImageCatalog();
    imageCatalog.getCustomImages().add(savedCustomImage);
    doAnswer(invocation -> ((Supplier<CustomImage>) invocation.getArgument(0)).get()).when(transactionService).required(any(Supplier.class));
    when(imageCatalogService.getImageCatalogByName(WORKSPACE_ID, IMAGE_CATALOG_NAME)).thenReturn(imageCatalog);
    when(imageCatalogService.pureSave(imageCatalog)).thenReturn(imageCatalog);
    CustomImage actual = victim.updateCustomImage(WORKSPACE_ID, CREATOR, IMAGE_CATALOG_NAME, updatedCustomImage);
    assertEquals(1, imageCatalog.getCustomImages().size());
    assertEquals(CUSTOMIZED_IMAGE_ID, actual.getCustomizedImageId());
    assertEquals(BASE_PARCEL_URL, actual.getBaseParcelUrl());
    assertEquals(ImageType.RUNTIME, actual.getImageType());
    assertEquals(0, actual.getVmImage().size());
}
Also used : CustomImage(com.sequenceiq.cloudbreak.domain.CustomImage) Supplier(java.util.function.Supplier) VmImage(com.sequenceiq.cloudbreak.domain.VmImage) ImageCatalog(com.sequenceiq.cloudbreak.domain.ImageCatalog) Test(org.junit.jupiter.api.Test)

Aggregations

CustomImage (com.sequenceiq.cloudbreak.domain.CustomImage)47 Test (org.junit.jupiter.api.Test)26 ImageCatalog (com.sequenceiq.cloudbreak.domain.ImageCatalog)18 VmImage (com.sequenceiq.cloudbreak.domain.VmImage)13 Supplier (java.util.function.Supplier)11 Image (com.sequenceiq.cloudbreak.cloud.model.catalog.Image)9 CustomImageCatalogV4GetImageResponse (com.sequenceiq.cloudbreak.api.endpoint.v4.customimage.response.CustomImageCatalogV4GetImageResponse)4 CheckPermissionByResourceName (com.sequenceiq.authorization.annotation.CheckPermissionByResourceName)3 CustomImageCatalogV4UpdateImageRequest (com.sequenceiq.cloudbreak.api.endpoint.v4.customimage.request.CustomImageCatalogV4UpdateImageRequest)3 CustomImageCatalogV4VmImageResponse (com.sequenceiq.cloudbreak.api.endpoint.v4.customimage.response.CustomImageCatalogV4VmImageResponse)3 CloudbreakImageCatalogException (com.sequenceiq.cloudbreak.core.CloudbreakImageCatalogException)3 Test (org.junit.Test)3 CustomImageCatalogV4CreateImageRequest (com.sequenceiq.cloudbreak.api.endpoint.v4.customimage.request.CustomImageCatalogV4CreateImageRequest)2 CustomImageCatalogV4CreateImageResponse (com.sequenceiq.cloudbreak.api.endpoint.v4.customimage.response.CustomImageCatalogV4CreateImageResponse)2 CustomImageCatalogV4DeleteImageResponse (com.sequenceiq.cloudbreak.api.endpoint.v4.customimage.response.CustomImageCatalogV4DeleteImageResponse)2 CustomImageCatalogV4ImageListItemResponse (com.sequenceiq.cloudbreak.api.endpoint.v4.customimage.response.CustomImageCatalogV4ImageListItemResponse)2 CustomImageCatalogV4UpdateImageResponse (com.sequenceiq.cloudbreak.api.endpoint.v4.customimage.response.CustomImageCatalogV4UpdateImageResponse)2 TransactionService (com.sequenceiq.cloudbreak.common.service.TransactionService)2 ConversionException (com.sequenceiq.cloudbreak.converter.ConversionException)2 StatedImage.statedImage (com.sequenceiq.cloudbreak.service.image.StatedImage.statedImage)2