Search in sources :

Example 16 with StatedImage

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");
}
Also used : StatedImage(com.sequenceiq.cloudbreak.service.image.StatedImage) Image(com.sequenceiq.cloudbreak.cloud.model.catalog.Image) StatedImage(com.sequenceiq.cloudbreak.service.image.StatedImage) Workspace(com.sequenceiq.cloudbreak.workspace.model.Workspace) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Before(org.junit.Before)

Example 17 with StatedImage

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);
}
Also used : StatedImage(com.sequenceiq.cloudbreak.service.image.StatedImage)

Example 18 with StatedImage

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;
}
Also used : StatedImage(com.sequenceiq.cloudbreak.service.image.StatedImage)

Example 19 with 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");
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) RepairValidation(com.sequenceiq.cloudbreak.service.cluster.model.RepairValidation) UpgradeOptionV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeOptionV4Response) Image(com.sequenceiq.cloudbreak.cloud.model.Image) StatedImage(com.sequenceiq.cloudbreak.service.image.StatedImage) StatedImage(com.sequenceiq.cloudbreak.service.image.StatedImage) Map(java.util.Map) HashMap(java.util.HashMap) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.jupiter.api.Test)

Example 20 with StatedImage

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());
}
Also used : ImageCatalogPlatform(com.sequenceiq.cloudbreak.service.image.catalog.model.ImageCatalogPlatform) StatedImage(com.sequenceiq.cloudbreak.service.image.StatedImage) Image(com.sequenceiq.cloudbreak.cloud.model.catalog.Image) 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