Search in sources :

Example 41 with StatedImage

use of com.sequenceiq.cloudbreak.service.image.StatedImage in project cloudbreak by hortonworks.

the class CmSyncImageCollectorServiceTest method testCollectImagesWhenImageUuidPresentThenCurrentImageAdded.

@Test
void testCollectImagesWhenImageUuidPresentThenCurrentImageAdded() throws CloudbreakImageNotFoundException, CloudbreakImageCatalogException {
    setupStack(true, false);
    Set<String> candidateImageUuids = Set.of(IMAGE_UUID_1);
    StatedImage currentStatedImage = getCurrentStatedImage();
    StatedImage anotherStatedImage = getStatedImage(IMAGE_UUID_1);
    when(imageService.getCurrentImageCatalogName(STACK_ID)).thenReturn(CURRENT_IMAGE_CATALOG_NAME);
    when(imageService.getCurrentImage(STACK_ID)).thenReturn(currentStatedImage);
    when(imageCatalogService.getImageByCatalogName(WORKSPCE_ID, IMAGE_UUID_1, CURRENT_IMAGE_CATALOG_NAME)).thenReturn(anotherStatedImage);
    Set<Image> collectedImages = underTest.collectImages(USER_CRN, stack, candidateImageUuids);
    assertThat(collectedImages, hasSize(2));
    assertThat(collectedImages, containsInAnyOrder(hasProperty("uuid", is(IMAGE_UUID_1)), hasProperty("uuid", is(CURRENT_IMAGE_UUID))));
    verify(imageService).getCurrentImageCatalogName(STACK_ID);
    verify(imageCatalogService).getImageByCatalogName(WORKSPCE_ID, IMAGE_UUID_1, CURRENT_IMAGE_CATALOG_NAME);
    verify(imageService).getCurrentImage(STACK_ID);
    verify(imageCatalogService, never()).getAllCdhImages(anyString(), anyLong(), anyString(), anySet());
}
Also used : ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) StatedImage(com.sequenceiq.cloudbreak.service.image.StatedImage) Image(com.sequenceiq.cloudbreak.cloud.model.catalog.Image) StatedImage(com.sequenceiq.cloudbreak.service.image.StatedImage) Test(org.junit.jupiter.api.Test)

Example 42 with StatedImage

use of com.sequenceiq.cloudbreak.service.image.StatedImage in project cloudbreak by hortonworks.

the class StackComponentUpdaterTest method testUpdateImageComponents.

@Test
public void testUpdateImageComponents() throws CloudbreakImageCatalogException, CloudbreakImageNotFoundException {
    Stack stack = TestUtil.stack();
    Cluster cluster = TestUtil.cluster();
    stack.setCluster(cluster);
    StatedImage targetImage = ImageTestUtil.getImageFromCatalog(true, "targetImageUuid", TARGET_STACK_VERSION);
    Image originalImage = ImageTestUtil.getImage(true, "originalImageUuid", STACK_VERSION);
    Component originalImageComponent = new Component(ComponentType.IMAGE, ComponentType.IMAGE.name(), new Json(originalImage), stack);
    when(componentConfigProviderService.getComponentsByStackId(stack.getId())).thenReturn(Set.of(originalImageComponent));
    Set<Component> targetComponents = createComponents(stack, targetImage);
    underTest.updateComponentsByStackId(stack, targetComponents, true);
    ArgumentCaptor<Set<Component>> componentCatcher = ArgumentCaptor.forClass(Set.class);
    verify(componentConfigProviderService, times(1)).store(componentCatcher.capture());
    assertEquals(3, componentCatcher.getValue().size());
    assertTrue(componentCatcher.getValue().stream().anyMatch(component -> {
        Object version = component.getAttributes().getValue("version");
        if (Objects.nonNull(version)) {
            return ((String) version).contains(TARGET_STACK_VERSION);
        } else {
            return false;
        }
    }));
    assertTrue(componentCatcher.getValue().stream().anyMatch(component -> {
        Object userData = component.getAttributes().getValue("userdata");
        if (Objects.nonNull(userData)) {
            return ((Map<String, String>) userData).get(InstanceGroupType.GATEWAY.name()).contains("gw user data");
        } else {
            return false;
        }
    }));
}
Also used : Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) ComponentType(com.sequenceiq.cloudbreak.common.type.ComponentType) Mock(org.mockito.Mock) ImageTestUtil(com.sequenceiq.cloudbreak.service.image.ImageTestUtil) TestUtil(com.sequenceiq.cloudbreak.TestUtil) ComponentConfigProviderService(com.sequenceiq.cloudbreak.service.ComponentConfigProviderService) ImageService(com.sequenceiq.cloudbreak.service.image.ImageService) ArgumentCaptor(org.mockito.ArgumentCaptor) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) StatedImage(com.sequenceiq.cloudbreak.service.image.StatedImage) Map(java.util.Map) CloudbreakImageCatalogException(com.sequenceiq.cloudbreak.core.CloudbreakImageCatalogException) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Component(com.sequenceiq.cloudbreak.domain.stack.Component) InjectMocks(org.mockito.InjectMocks) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) Set(java.util.Set) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) ClouderaManagerRepo(com.sequenceiq.cloudbreak.cloud.model.ClouderaManagerRepo) Image(com.sequenceiq.cloudbreak.cloud.model.catalog.Image) Mockito.verify(org.mockito.Mockito.verify) CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) InstanceGroupType(com.sequenceiq.common.api.type.InstanceGroupType) Objects(java.util.Objects) Test(org.junit.jupiter.api.Test) Json(com.sequenceiq.cloudbreak.common.json.Json) ClusterComponent(com.sequenceiq.cloudbreak.domain.stack.cluster.ClusterComponent) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Set(java.util.Set) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) Json(com.sequenceiq.cloudbreak.common.json.Json) StatedImage(com.sequenceiq.cloudbreak.service.image.StatedImage) Image(com.sequenceiq.cloudbreak.cloud.model.catalog.Image) Component(com.sequenceiq.cloudbreak.domain.stack.Component) ClusterComponent(com.sequenceiq.cloudbreak.domain.stack.cluster.ClusterComponent) StatedImage(com.sequenceiq.cloudbreak.service.image.StatedImage) Map(java.util.Map) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.jupiter.api.Test)

Example 43 with StatedImage

use of com.sequenceiq.cloudbreak.service.image.StatedImage in project cloudbreak by hortonworks.

the class UpgradeImageInfoFactoryTest method testCreate.

@Test
void testCreate() throws CloudbreakImageNotFoundException, CloudbreakImageCatalogException {
    Image image = getImage();
    when(componentConfigProviderService.getImage(STACK_ID)).thenReturn(image);
    StatedImage currentStatedImage = StatedImage.statedImage(getCatalogImage(), IMAGE_CATALOG_NAME, CURRENT_IMAGE_ID);
    when(imageCatalogService.getImage(IMAGE_CATALOG_URL, IMAGE_CATALOG_NAME, CURRENT_IMAGE_ID)).thenReturn(currentStatedImage);
    StatedImage targetStatedImage = StatedImage.statedImage(getCatalogImage(), IMAGE_CATALOG_NAME, TARGET_IMAGE_ID);
    when(imageCatalogService.getImage(IMAGE_CATALOG_URL, IMAGE_CATALOG_NAME, TARGET_IMAGE_ID)).thenReturn(targetStatedImage);
    UpgradeImageInfo upgradeImageInfo = underTest.create(TARGET_IMAGE_ID, STACK_ID);
    assertEquals(image, upgradeImageInfo.getCurrentImage());
    assertEquals(currentStatedImage, upgradeImageInfo.getCurrentStatedImage());
    assertEquals(targetStatedImage, upgradeImageInfo.getTargetStatedImage());
    verify(image).getImageId();
    verify(image, times(2)).getImageCatalogName();
    verify(image, times(2)).getImageCatalogUrl();
}
Also used : Image(com.sequenceiq.cloudbreak.cloud.model.Image) StatedImage(com.sequenceiq.cloudbreak.service.image.StatedImage) StatedImage(com.sequenceiq.cloudbreak.service.image.StatedImage) Test(org.junit.jupiter.api.Test)

Example 44 with StatedImage

use of com.sequenceiq.cloudbreak.service.image.StatedImage in project cloudbreak by hortonworks.

the class MeteringAzureMetadataPatchServiceTest method testIsAffected.

@Test
public void testIsAffected() throws Exception {
    // GIVEN
    Stack stack = createStack();
    StatedImage statedImageMock = mock(StatedImage.class);
    Image imageFromStated = mock(Image.class);
    given(stackImageService.getStatedImageInternal(stack)).willReturn(Optional.of(statedImageMock));
    given(statedImageMock.getImage()).willReturn(imageFromStated);
    given(meteringAzureMetadataPatchConfig.getDateBefore()).willReturn(DATE_SAMPLE);
    long sampleTimestamp = underTest.dateStringToTimestampForImage("2021-12-24");
    given(imageFromStated.getCreated()).willReturn(sampleTimestamp);
    // WHEN
    boolean result = underTest.isAffected(stack);
    // THEN
    assertTrue(result);
}
Also used : StatedImage(com.sequenceiq.cloudbreak.service.image.StatedImage) Image(com.sequenceiq.cloudbreak.cloud.model.catalog.Image) StatedImage(com.sequenceiq.cloudbreak.service.image.StatedImage) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.jupiter.api.Test)

Example 45 with StatedImage

use of com.sequenceiq.cloudbreak.service.image.StatedImage in project cloudbreak by hortonworks.

the class StackImageServiceTest method testGetStatedImageForStackInternal.

@Test
public void testGetStatedImageForStackInternal() throws Exception {
    ImageCatalog imageCatalog = mock(ImageCatalog.class);
    com.sequenceiq.cloudbreak.cloud.model.Image imageComp = mock(com.sequenceiq.cloudbreak.cloud.model.Image.class);
    when(imageCatalog.getName()).thenReturn(TARGET_IMAGE_CATALOG);
    when(imageComp.getImageCatalogName()).thenReturn(TARGET_IMAGE_CATALOG);
    when(imageComp.getImageId()).thenReturn(IMAGE_ID);
    when(componentConfigProviderService.getImage(anyLong())).thenReturn(imageComp);
    when(internalCrnModifier.getInternalCrnWithAccountId(anyString())).thenReturn("accountId");
    when(imageCatalogService.getImageCatalogByName(anyLong(), anyString())).thenReturn(imageCatalog);
    when(imageCatalogService.getImageByCatalogName(anyLong(), anyString(), anyString())).thenReturn(statedImage);
    Optional<StatedImage> result = victim.getStatedImageInternal(stack);
    assertTrue(result.isPresent());
}
Also used : ImageCatalog(com.sequenceiq.cloudbreak.domain.ImageCatalog) StatedImage(com.sequenceiq.cloudbreak.service.image.StatedImage) Test(org.junit.jupiter.api.Test)

Aggregations

StatedImage (com.sequenceiq.cloudbreak.service.image.StatedImage)48 Image (com.sequenceiq.cloudbreak.cloud.model.catalog.Image)19 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)12 Test (org.junit.Test)12 Image (com.sequenceiq.cloudbreak.cloud.model.Image)11 Test (org.junit.jupiter.api.Test)10 CloudbreakImageNotFoundException (com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException)9 Json (com.sequenceiq.cloudbreak.common.json.Json)7 CloudbreakImageCatalogException (com.sequenceiq.cloudbreak.core.CloudbreakImageCatalogException)7 InstanceMetaData (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData)7 CheckResult (com.sequenceiq.cloudbreak.core.flow2.CheckResult)6 Map (java.util.Map)6 ImageCatalog (com.sequenceiq.cloudbreak.domain.ImageCatalog)5 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)5 CloudbreakDetails (com.sequenceiq.cloudbreak.cloud.model.CloudbreakDetails)4 CloudbreakServiceException (com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException)4 StackEvent (com.sequenceiq.cloudbreak.reactor.api.event.StackEvent)4 StackImageUpdateTriggerEvent (com.sequenceiq.cloudbreak.core.flow2.event.StackImageUpdateTriggerEvent)3 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)3 ImageUpdateEvent (com.sequenceiq.cloudbreak.reactor.api.event.stack.ImageUpdateEvent)3