use of com.sequenceiq.cloudbreak.service.image.StatedImage in project cloudbreak by hortonworks.
the class StackImageUpdateServiceTest method setUp.
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
Workspace workspace = new Workspace();
workspace.setId(WORKSPACE_ID);
stack = new Stack();
stack.setId(1L);
stack.setName("stackname");
stack.setRegion("region");
stack.setCloudPlatform("AWS");
stack.setWorkspace(workspace);
image = new Image("asdf", System.currentTimeMillis(), System.currentTimeMillis(), "asdf", "centos7", "uuid", "2.8.0", Collections.emptyMap(), Collections.singletonMap("AWS", Collections.emptyMap()), null, "centos", packageVersions, Collections.emptyList(), Collections.emptyList(), "1", true, null, null);
statedImage = StatedImage.statedImage(image, "url", "name");
when(packageVersionChecker.checkInstancesHaveAllMandatoryPackageVersion(anySet())).thenReturn(CheckResult.ok());
when(packageVersionChecker.checkInstancesHaveMultiplePackageVersions(anySet())).thenReturn(CheckResult.ok());
when(packageVersionChecker.compareImageAndInstancesMandatoryPackageVersion(any(StatedImage.class), anySet())).thenReturn(CheckResult.ok());
when(messagesService.getMessage(anyString(), anyCollection())).thenReturn("message");
}
use of com.sequenceiq.cloudbreak.service.image.StatedImage in project cloudbreak by hortonworks.
the class UpgradeServiceTest method setupImageCatalogMocks.
private void setupImageCatalogMocks(Image image, boolean prewarmedImage, String oldImage, String newImage) throws CloudbreakImageNotFoundException, CloudbreakImageCatalogException {
when(componentConfigProviderService.getImage(anyLong())).thenReturn(image);
StatedImage currentImageFromCatalog = imageFromCatalog(prewarmedImage, oldImage);
when(imageCatalogService.getImage(anyString(), anyString(), anyString())).thenReturn(currentImageFromCatalog);
StatedImage latestImage = imageFromCatalog(true, newImage);
when(imageService.determineImageFromCatalog(anyLong(), any(), anyString(), any(), any(), anyBoolean(), anyBoolean(), any(), any())).thenReturn(latestImage);
}
use of com.sequenceiq.cloudbreak.service.image.StatedImage in project cloudbreak by hortonworks.
the class UpgradeServiceTest method imageFromCatalog.
private StatedImage imageFromCatalog(boolean prewarmed, String imageName) {
com.sequenceiq.cloudbreak.cloud.model.catalog.Image image = mock(com.sequenceiq.cloudbreak.cloud.model.catalog.Image.class);
lenient().when(image.isPrewarmed()).thenReturn(prewarmed);
lenient().when(image.getUuid()).thenReturn("uuid");
lenient().when(image.getImageSetsByProvider()).thenReturn(Map.of("aws", Map.of("eu-central-1", imageName)));
StatedImage statedImage = StatedImage.statedImage(image, null, null);
return statedImage;
}
use of com.sequenceiq.cloudbreak.service.image.StatedImage in project cloudbreak by hortonworks.
the class UpgradeServiceTest method shouldNotAllowUpgradeIfDryRunFails.
@Test
public void shouldNotAllowUpgradeIfDryRunFails() throws CloudbreakImageNotFoundException, CloudbreakImageCatalogException {
Stack stack = getStack();
Image image = getImage("id-1");
when(stackService.getByNameOrCrnInWorkspace(eq(ofName), eq(WORKSPACE_ID))).thenReturn(stack);
when(componentConfigProviderService.getImage(anyLong())).thenReturn(image);
StatedImage currentImageFromCatalog = imageFromCatalog(true, image.getImageId());
when(imageCatalogService.getImage(anyString(), anyString(), anyString())).thenReturn(currentImageFromCatalog);
Result<Map<HostGroupName, Set<InstanceMetaData>>, RepairValidation> repairStartResult = Result.error(RepairValidation.of(List.of("Repair cannot be performed because there is an active flow running.", "No external Database")));
when(clusterRepairService.repairWithDryRun(1L)).thenReturn(repairStartResult);
UpgradeOptionV4Response result = underTest.getOsUpgradeOptionByStackNameOrCrn(WORKSPACE_ID, ofName, user);
verify(clusterRepairService).repairWithDryRun(eq(stack.getId()));
verifyNoMoreInteractions(distroXV1Endpoint);
verifyNoMoreInteractions(componentConfigProviderService);
verifyNoMoreInteractions(imageService);
assertThat(result.getUpgrade()).isEqualTo(null);
assertThat(result.getReason()).isEqualTo("Repair cannot be performed because there is an active flow running.; No external Database");
}
use of com.sequenceiq.cloudbreak.service.image.StatedImage in project cloudbreak by hortonworks.
the class StackImageServiceTest method testChangeImageCatalogOutOfFlow.
@Test
public void testChangeImageCatalogOutOfFlow() throws CloudbreakImageNotFoundException, CloudbreakImageCatalogException, IOException {
ImageCatalog imageCatalog = mock(ImageCatalog.class);
ImageCatalogPlatform imageCatalogPlatform = imageCatalogPlatform(stack.getCloudPlatform());
Image targetImage = anImage(IMAGE_ID);
StatedImage targetStatedImage = StatedImage.statedImage(targetImage, TARGET_IMAGE_CATALOG_URL, TARGET_IMAGE_CATALOG);
when(componentConfigProviderService.getImage(stack.getId())).thenReturn(anImageComponent());
when(imageCatalogService.getImageCatalogByName(stack.getWorkspace().getId(), TARGET_IMAGE_CATALOG)).thenReturn(imageCatalog);
when(imageCatalog.getName()).thenReturn(TARGET_IMAGE_CATALOG);
when(imageCatalog.getImageCatalogUrl()).thenReturn(TARGET_IMAGE_CATALOG_URL);
when(imageCatalogService.getImage(TARGET_IMAGE_CATALOG_URL, TARGET_IMAGE_CATALOG, IMAGE_ID)).thenReturn(targetStatedImage);
when(imageService.determineImageName(stack.getCloudPlatform().toLowerCase(), imageCatalogPlatform, stack.getRegion(), targetStatedImage.getImage())).thenReturn(IMAGE_NAME);
when(platformStringTransformer.getPlatformStringForImageCatalog(stack.getCloudPlatform(), stack.getPlatformVariant())).thenReturn(imageCatalogPlatform);
victim.changeImageCatalog(stack, TARGET_IMAGE_CATALOG);
verify(componentConfigProviderService).replaceImageComponentWithNew(componentArgumentCaptor.capture());
com.sequenceiq.cloudbreak.cloud.model.Image newImage = componentArgumentCaptor.getValue().getAttributes().get(com.sequenceiq.cloudbreak.cloud.model.Image.class);
assertEquals(TARGET_IMAGE_CATALOG, newImage.getImageCatalogName());
assertEquals(TARGET_IMAGE_CATALOG_URL, newImage.getImageCatalogUrl());
assertEquals(IMAGE_ID, newImage.getImageId());
}
Aggregations