Search in sources :

Example 11 with StatedImage

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

the class PackageVersionCheckerTest method compareImageAndInstancesMandatoryPackageVersionMissingPackageInImage.

@Test
public void compareImageAndInstancesMandatoryPackageVersionMissingPackageInImage() throws JsonProcessingException {
    String packageName = "package";
    Map<String, String> packageVersions = Collections.singletonMap(packageName, "1");
    when(statedImage.getImage()).thenReturn(image);
    when(image.isPrewarmed()).thenReturn(true);
    when(image.getPackageVersions()).thenReturn(Collections.emptyMap());
    Package aPackage = new Package();
    aPackage.setName(packageName);
    aPackage.setPrewarmed(true);
    when(instanceMetadataUpdater.getPackages()).thenReturn(Collections.singletonList(aPackage));
    InstanceMetaData instanceMetaData = new InstanceMetaData();
    instanceMetaData.setImage(new Json(new com.sequenceiq.cloudbreak.cloud.model.Image("image", Collections.emptyMap(), "os", "ostype", "catalogn", "catalogu", "id", packageVersions)));
    Set<InstanceMetaData> instanceMetaDataSet = Collections.singleton(instanceMetaData);
    CheckResult result = underTest.compareImageAndInstancesMandatoryPackageVersion(statedImage, instanceMetaDataSet);
    assertEquals(EventStatus.FAILED, result.getStatus());
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) CheckResult(com.sequenceiq.cloudbreak.core.flow2.CheckResult) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Package(com.sequenceiq.cloudbreak.service.cluster.Package) Json(com.sequenceiq.cloudbreak.common.json.Json) Image(com.sequenceiq.cloudbreak.cloud.model.catalog.Image) StatedImage(com.sequenceiq.cloudbreak.service.image.StatedImage) Test(org.junit.Test)

Example 12 with StatedImage

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

the class StackImageUpdateActionsTest method checkPackageVersions.

@Test
public void checkPackageVersions() {
    FlowEvent flowEvent = Mockito.mock(FlowEvent.class);
    when(stateContext.getEvent()).thenReturn(flowEvent);
    when(flowEvent.name()).thenReturn(EVENT_NAME);
    ImageUpdateEvent payload = new ImageUpdateEvent(StackImageUpdateEvent.STACK_IMAGE_UPDATE_EVENT.event(), 1L, statedImage);
    when(stateContext.getMessageHeader(HEADERS.DATA.name())).thenReturn(payload);
    when(state.getId()).thenReturn(StackImageUpdateState.CHECK_IMAGE_VERSIONS_STATE);
    when(stackImageUpdateService.checkPackageVersions(any(Stack.class), any(StatedImage.class))).thenReturn(CheckResult.ok());
    checkPackageVersionsAction.execute(stateContext);
    verify(stackImageUpdateService, times(1)).checkPackageVersions(any(Stack.class), any(StatedImage.class));
    verify(eventBus, times(1)).notify(eq(StackImageUpdateEvent.CHECK_PACKAGE_VERSIONS_FINISHED_EVENT.event()), any(Event.class));
}
Also used : FlowEvent(com.sequenceiq.flow.core.FlowEvent) FlowEvent(com.sequenceiq.flow.core.FlowEvent) StackFailureEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackFailureEvent) StackEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackEvent) Event(reactor.bus.Event) ResourceEvent(com.sequenceiq.cloudbreak.event.ResourceEvent) ImageUpdateEvent(com.sequenceiq.cloudbreak.reactor.api.event.stack.ImageUpdateEvent) StackImageUpdateTriggerEvent(com.sequenceiq.cloudbreak.core.flow2.event.StackImageUpdateTriggerEvent) StatedImage(com.sequenceiq.cloudbreak.service.image.StatedImage) ImageUpdateEvent(com.sequenceiq.cloudbreak.reactor.api.event.stack.ImageUpdateEvent) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.Test)

Example 13 with StatedImage

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

the class StackImageUpdateActionsTest method updateImage.

@Test
public void updateImage() {
    FlowEvent flowEvent = Mockito.mock(FlowEvent.class);
    when(stateContext.getEvent()).thenReturn(flowEvent);
    when(flowEvent.name()).thenReturn(EVENT_NAME);
    ImageUpdateEvent payload = new ImageUpdateEvent(StackImageUpdateEvent.CHECK_PACKAGE_VERSIONS_FINISHED_EVENT.event(), 1L, statedImage);
    when(stateContext.getMessageHeader(HEADERS.DATA.name())).thenReturn(payload);
    when(state.getId()).thenReturn(StackImageUpdateState.UPDATE_IMAGE_STATE);
    updateImageAction.execute(stateContext);
    verify(stackImageService, times(1)).storeNewImageComponent(any(Stack.class), any(StatedImage.class));
    verify(eventBus, times(1)).notify(eq(StackImageUpdateEvent.UPDATE_IMAGE_FINESHED_EVENT.event()), any(Event.class));
    assertTrue(variables.containsKey(AbstractStackImageUpdateAction.ORIGINAL_IMAGE));
}
Also used : FlowEvent(com.sequenceiq.flow.core.FlowEvent) FlowEvent(com.sequenceiq.flow.core.FlowEvent) StackFailureEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackFailureEvent) StackEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackEvent) Event(reactor.bus.Event) ResourceEvent(com.sequenceiq.cloudbreak.event.ResourceEvent) ImageUpdateEvent(com.sequenceiq.cloudbreak.reactor.api.event.stack.ImageUpdateEvent) StackImageUpdateTriggerEvent(com.sequenceiq.cloudbreak.core.flow2.event.StackImageUpdateTriggerEvent) StatedImage(com.sequenceiq.cloudbreak.service.image.StatedImage) ImageUpdateEvent(com.sequenceiq.cloudbreak.reactor.api.event.stack.ImageUpdateEvent) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.Test)

Example 14 with StatedImage

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

the class StackImageUpdateServiceTest method testGetNewImageIfVersionsMatch.

@Test
public void testGetNewImageIfVersionsMatch() throws CloudbreakImageNotFoundException, CloudbreakImageCatalogException {
    com.sequenceiq.cloudbreak.cloud.model.Image imageInComponent = new com.sequenceiq.cloudbreak.cloud.model.Image("imageOldName", Collections.emptyMap(), "centos7", "centos", statedImage.getImageCatalogUrl(), statedImage.getImageCatalogName(), "uuid2", packageVersions);
    when(restRequestThreadLocalService.getRequestedWorkspaceId()).thenReturn(null);
    when(stackImageService.getCurrentImage(stack)).thenReturn(imageInComponent);
    when(imageCatalogService.getImage(anyString(), anyString(), anyString())).thenReturn(statedImage);
    StatedImage newImageIfVersionsMatch = underTest.getNewImageIfVersionsMatch(stack, "newimageid", "imagecatalogname", "imagecatalogurl");
    assertNotNull(newImageIfVersionsMatch);
    verify(restRequestThreadLocalService).setWorkspace(stack.getWorkspace());
}
Also used : 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.Test)

Example 15 with StatedImage

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

the class StackImageUpdateServiceTest method testIsValidImage.

@Test
public void testIsValidImage() throws CloudbreakImageNotFoundException, CloudbreakImageCatalogException {
    com.sequenceiq.cloudbreak.cloud.model.Image imageInComponent = new com.sequenceiq.cloudbreak.cloud.model.Image("imageOldName", Collections.emptyMap(), "centos7", "centos", statedImage.getImageCatalogUrl(), statedImage.getImageCatalogName(), "uuid2", packageVersions);
    when(stackImageService.getCurrentImage(stack)).thenReturn(imageInComponent);
    when(imageCatalogService.getImage(anyString(), anyString(), anyString())).thenReturn(statedImage);
    CloudbreakDetails cloudbreakDetails = new CloudbreakDetails();
    cloudbreakDetails.setVersion(StackImageUpdateService.MIN_VERSION);
    when(componentConfigProviderService.getCloudbreakDetails(stack.getId())).thenReturn(cloudbreakDetails);
    boolean validImage = underTest.isValidImage(stack, "imageId", "imageCatalogName", "imageCatalogUrl");
    assertTrue(validImage);
}
Also used : CloudbreakDetails(com.sequenceiq.cloudbreak.cloud.model.CloudbreakDetails) StatedImage(com.sequenceiq.cloudbreak.service.image.StatedImage) Image(com.sequenceiq.cloudbreak.cloud.model.catalog.Image) Test(org.junit.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