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