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());
}
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;
}
}));
}
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();
}
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);
}
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());
}
Aggregations