Search in sources :

Example 21 with StatedImage

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

the class LoggingAgentAutoRestartPatchServiceTest method testIsAffectedByDate.

@Test
public void testIsAffectedByDate() throws Exception {
    // GIVEN
    Stack stack = createStack();
    Image image = mock(Image.class);
    ImageCatalog imageCatalog = mock(ImageCatalog.class);
    StatedImage statedImageMock = mock(StatedImage.class);
    com.sequenceiq.cloudbreak.cloud.model.catalog.Image imageFromStated = mock(com.sequenceiq.cloudbreak.cloud.model.catalog.Image.class);
    given(image.getPackageVersions()).willReturn(new HashMap<>());
    given(stackImageService.getCurrentImage(stack)).willReturn(image);
    given(stackImageService.getImageCatalogFromStackAndImage(any(), any())).willReturn(imageCatalog);
    given(stackImageService.getStatedImageInternal(any(Stack.class), any(Image.class), any(ImageCatalog.class))).willReturn(Optional.of(statedImageMock));
    given(statedImageMock.getImage()).willReturn(imageFromStated);
    long sampleTimestamp = underTest.dateStringToTimestampForImage("2022-01-10");
    given(imageFromStated.getCreated()).willReturn(sampleTimestamp);
    initIsAffectedMocks();
    // WHEN
    underTest.init();
    boolean result = underTest.isAffected(stack);
    // THEN
    assertTrue(result);
}
Also used : Image(com.sequenceiq.cloudbreak.cloud.model.Image) StatedImage(com.sequenceiq.cloudbreak.service.image.StatedImage) ImageCatalog(com.sequenceiq.cloudbreak.domain.ImageCatalog) StatedImage(com.sequenceiq.cloudbreak.service.image.StatedImage) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.jupiter.api.Test)

Example 22 with StatedImage

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

the class MeteringAzureMetadataPatchServiceTest method testIsNotAffectedByDate.

@Test
public void testIsNotAffectedByDate() 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("2022-02-02");
    given(imageFromStated.getCreated()).willReturn(sampleTimestamp);
    // WHEN
    boolean result = underTest.isAffected(stack);
    // THEN
    assertFalse(result);
}
Also used : StatedImage(com.sequenceiq.cloudbreak.service.image.StatedImage) Image(com.sequenceiq.cloudbreak.cloud.model.catalog.Image) StatedImage(com.sequenceiq.cloudbreak.service.image.StatedImage) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.jupiter.api.Test)

Example 23 with StatedImage

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

the class UpgradeImageInfoFactory method create.

public UpgradeImageInfo create(String targetImageId, Long stackId) throws CloudbreakImageNotFoundException, CloudbreakImageCatalogException {
    Image currentImage = componentConfigProviderService.getImage(stackId);
    StatedImage currentStatedImage = imageCatalogService.getImage(currentImage.getImageCatalogUrl(), currentImage.getImageCatalogName(), currentImage.getImageId());
    StatedImage targetStatedImage = imageCatalogService.getImage(currentImage.getImageCatalogUrl(), currentImage.getImageCatalogName(), targetImageId);
    UpgradeImageInfo upgradeImageInfo = new UpgradeImageInfo(currentImage, currentStatedImage, targetStatedImage);
    LOGGER.debug("Provided upgradeImageInfo values to create UpgradeImageInfo: {}", upgradeImageInfo);
    return upgradeImageInfo;
}
Also used : StatedImage(com.sequenceiq.cloudbreak.service.image.StatedImage) Image(com.sequenceiq.cloudbreak.cloud.model.Image) StatedImage(com.sequenceiq.cloudbreak.service.image.StatedImage)

Example 24 with StatedImage

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

the class MaintenanceModeValidationService method validateImageCatalog.

public List<Warning> validateImageCatalog(Stack stack) {
    List<Warning> warnings = new ArrayList<>();
    try {
        Image image = componentConfigProviderService.getImage(stack.getId());
        StatedImage statedImage = imageCatalogService.getImage(image.getImageCatalogUrl(), image.getImageCatalogName(), image.getImageId());
        if (!image.getPackageVersions().isEmpty()) {
            CheckResult checkResult = stackImageUpdateService.checkPackageVersions(stack, statedImage);
            if (checkResult.getStatus().equals(EventStatus.FAILED)) {
                warnings.add(new Warning(WarningType.IMAGE_INCOMPATIBILITY_WARNING, checkResult.getMessage()));
            }
        }
    } catch (CloudbreakImageNotFoundException | CloudbreakImageCatalogException e) {
        throw new CloudbreakServiceException("Image info could not be validated!", e);
    }
    return warnings;
}
Also used : CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) CheckResult(com.sequenceiq.cloudbreak.core.flow2.CheckResult) ArrayList(java.util.ArrayList) CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) Image(com.sequenceiq.cloudbreak.cloud.model.Image) StatedImage(com.sequenceiq.cloudbreak.service.image.StatedImage) StatedImage(com.sequenceiq.cloudbreak.service.image.StatedImage) CloudbreakImageCatalogException(com.sequenceiq.cloudbreak.core.CloudbreakImageCatalogException)

Example 25 with StatedImage

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

the class ClusterUpgradeActions method clusterUpgradeFinished.

@Bean(name = "CLUSTER_UPGRADE_FINISHED_STATE")
public Action<?, ?> clusterUpgradeFinished() {
    return new AbstractClusterUpgradeAction<>(ClusterUpgradeSuccess.class) {

        @Inject
        private StackImageService stackImageService;

        @Override
        protected ClusterUpgradeContext createFlowContext(FlowParameters flowParameters, StateContext<FlowState, FlowEvent> stateContext, ClusterUpgradeSuccess payload) {
            return ClusterUpgradeContext.from(flowParameters, payload);
        }

        @Override
        protected void doExecute(ClusterUpgradeContext context, ClusterUpgradeSuccess payload, Map<Object, Object> variables) {
            StatedImage currentImage = getCurrentImage(variables);
            StatedImage targetImage = getTargetImage(variables);
            clusterUpgradeService.clusterUpgradeFinished(context.getStackId(), currentImage, targetImage);
            stackImageService.removeImageByComponentName(context.getStackId(), TARGET_IMAGE);
            sendEvent(context);
        }

        @Override
        protected Selectable createRequest(ClusterUpgradeContext context) {
            return new StackEvent(ClusterUpgradeEvent.CLUSTER_UPGRADE_FINALIZED_EVENT.event(), context.getStackId());
        }

        @Override
        protected Object getFailurePayload(ClusterUpgradeSuccess payload, Optional<ClusterUpgradeContext> flowContext, Exception ex) {
            return null;
        }
    };
}
Also used : FlowParameters(com.sequenceiq.flow.core.FlowParameters) StackEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackEvent) Optional(java.util.Optional) StateContext(org.springframework.statemachine.StateContext) StackImageService(com.sequenceiq.cloudbreak.service.stack.StackImageService) ClusterUpgradeSuccess(com.sequenceiq.cloudbreak.reactor.api.event.cluster.upgrade.ClusterUpgradeSuccess) Map(java.util.Map) StatedImage(com.sequenceiq.cloudbreak.service.image.StatedImage) Bean(org.springframework.context.annotation.Bean)

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