Search in sources :

Example 1 with ClusterUpgradeDiskSpaceValidationEvent

use of com.sequenceiq.cloudbreak.core.flow2.cluster.datalake.upgrade.validation.event.ClusterUpgradeDiskSpaceValidationEvent in project cloudbreak by hortonworks.

the class ClusterUpgradeValidationEventToClusterUpgradeDiskSpaceValidationEventConverterTest method testConvertShouldCreateAClusterUpgradeDiskSpaceValidationEvent.

@Test
public void testConvertShouldCreateAClusterUpgradeDiskSpaceValidationEvent() {
    ClusterUpgradeValidationEvent sourceEvent = new ClusterUpgradeValidationEvent(VALIDATE_DISK_SPACE_EVENT.event(), RESOURCE_ID, "image-id");
    ClusterUpgradeDiskSpaceValidationEvent actual = underTest.convert(sourceEvent);
    assertEquals(RESOURCE_ID, actual.getResourceId());
    assertEquals(1L, actual.getRequiredFreeSpace());
}
Also used : ClusterUpgradeValidationEvent(com.sequenceiq.cloudbreak.core.flow2.cluster.datalake.upgrade.validation.event.ClusterUpgradeValidationEvent) ClusterUpgradeDiskSpaceValidationEvent(com.sequenceiq.cloudbreak.core.flow2.cluster.datalake.upgrade.validation.event.ClusterUpgradeDiskSpaceValidationEvent) Test(org.junit.jupiter.api.Test)

Example 2 with ClusterUpgradeDiskSpaceValidationEvent

use of com.sequenceiq.cloudbreak.core.flow2.cluster.datalake.upgrade.validation.event.ClusterUpgradeDiskSpaceValidationEvent in project cloudbreak by hortonworks.

the class ClusterUpgradeValidationActions method clusterUpgradeDiskSpaceValidation.

@Bean(name = "CLUSTER_UPGRADE_DISK_SPACE_VALIDATION_STATE")
public Action<?, ?> clusterUpgradeDiskSpaceValidation() {
    return new AbstractClusterUpgradeValidationAction<>(ClusterUpgradeDiskSpaceValidationEvent.class) {

        @Override
        protected void doExecute(StackContext context, ClusterUpgradeDiskSpaceValidationEvent payload, Map<Object, Object> variables) {
            LOGGER.info("Starting disk space validation.");
            ClusterUpgradeDiskSpaceValidationEvent event = new ClusterUpgradeDiskSpaceValidationEvent(VALIDATE_DISK_SPACE_EVENT.name(), payload.getResourceId(), payload.getRequiredFreeSpace());
            sendEvent(context, event.selector(), event);
        }

        @Override
        protected Object getFailurePayload(ClusterUpgradeDiskSpaceValidationEvent payload, Optional<StackContext> flowContext, Exception ex) {
            return new ClusterUpgradeDiskSpaceValidationFinishedEvent(payload.getResourceId());
        }

        @Override
        protected void initPayloadConverterMap(List<PayloadConverter<ClusterUpgradeDiskSpaceValidationEvent>> payloadConverters) {
            payloadConverters.add(new ClusterUpgradeValidationEventToClusterUpgradeDiskSpaceValidationEventConverter());
        }
    };
}
Also used : ClusterUpgradeDiskSpaceValidationEvent(com.sequenceiq.cloudbreak.core.flow2.cluster.datalake.upgrade.validation.event.ClusterUpgradeDiskSpaceValidationEvent) Optional(java.util.Optional) StackContext(com.sequenceiq.cloudbreak.core.flow2.stack.StackContext) List(java.util.List) ClusterUpgradeValidationEventToClusterUpgradeDiskSpaceValidationEventConverter(com.sequenceiq.cloudbreak.core.flow2.cluster.datalake.upgrade.validation.config.ClusterUpgradeValidationEventToClusterUpgradeDiskSpaceValidationEventConverter) ClusterUpgradeDiskSpaceValidationFinishedEvent(com.sequenceiq.cloudbreak.core.flow2.cluster.datalake.upgrade.validation.event.ClusterUpgradeDiskSpaceValidationFinishedEvent) Map(java.util.Map) CloudbreakImageCatalogException(com.sequenceiq.cloudbreak.core.CloudbreakImageCatalogException) CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) Bean(org.springframework.context.annotation.Bean)

Example 3 with ClusterUpgradeDiskSpaceValidationEvent

use of com.sequenceiq.cloudbreak.core.flow2.cluster.datalake.upgrade.validation.event.ClusterUpgradeDiskSpaceValidationEvent in project cloudbreak by hortonworks.

the class ClusterUpgradeDiskSpaceValidationHandler method doAccept.

@Override
protected Selectable doAccept(HandlerEvent<ClusterUpgradeDiskSpaceValidationEvent> event) {
    LOGGER.debug("Accepting Cluster upgrade validation event.");
    ClusterUpgradeDiskSpaceValidationEvent request = event.getData();
    Long stackId = request.getResourceId();
    try {
        diskSpaceValidationService.validateFreeSpaceForUpgrade(getStack(stackId), request.getRequiredFreeSpace());
        return new ClusterUpgradeDiskSpaceValidationFinishedEvent(request.getResourceId());
    } catch (UpgradeValidationFailedException e) {
        LOGGER.warn("Cluster upgrade validation failed", e);
        return new ClusterUpgradeValidationFailureEvent(stackId, e);
    } catch (Exception e) {
        LOGGER.error("Cluster upgrade validation was unsuccessful due to an internal error", e);
        return new ClusterUpgradeDiskSpaceValidationFinishedEvent(request.getResourceId());
    }
}
Also used : ClusterUpgradeDiskSpaceValidationEvent(com.sequenceiq.cloudbreak.core.flow2.cluster.datalake.upgrade.validation.event.ClusterUpgradeDiskSpaceValidationEvent) ClusterUpgradeDiskSpaceValidationFinishedEvent(com.sequenceiq.cloudbreak.core.flow2.cluster.datalake.upgrade.validation.event.ClusterUpgradeDiskSpaceValidationFinishedEvent) UpgradeValidationFailedException(com.sequenceiq.cloudbreak.common.exception.UpgradeValidationFailedException) UpgradeValidationFailedException(com.sequenceiq.cloudbreak.common.exception.UpgradeValidationFailedException) ClusterUpgradeValidationFailureEvent(com.sequenceiq.cloudbreak.core.flow2.cluster.datalake.upgrade.validation.event.ClusterUpgradeValidationFailureEvent)

Example 4 with ClusterUpgradeDiskSpaceValidationEvent

use of com.sequenceiq.cloudbreak.core.flow2.cluster.datalake.upgrade.validation.event.ClusterUpgradeDiskSpaceValidationEvent in project cloudbreak by hortonworks.

the class ClusterUpgradeImageValidationHandler method doAccept.

@Override
protected Selectable doAccept(HandlerEvent<ClusterUpgradeImageValidationEvent> event) {
    LOGGER.debug("Accepting cluster upgrade image validation event.");
    ClusterUpgradeImageValidationEvent request = event.getData();
    CloudContext cloudContext = request.getCloudContext();
    try {
        Set<Response> parcelsResponses = parcelAvailabilityService.validateAvailability(request.getTargetImage(), request.getResourceId());
        long requiredDiskSpaceForUpgrade = parcelSizeService.getRequiredFreeSpace(parcelsResponses);
        executePlatformSpecificValidations(request, cloudContext);
        LOGGER.debug("Cluster upgrade image validation succeeded.");
        return new ClusterUpgradeDiskSpaceValidationEvent(START_CLUSTER_UPGRADE_DISK_SPACE_VALIDATION_EVENT.selector(), request.getResourceId(), requiredDiskSpaceForUpgrade);
    } catch (RuntimeException e) {
        LOGGER.warn("Cluster upgrade image validation failed: ", e);
        return new ClusterUpgradeValidationFailureEvent(request.getResourceId(), e);
    }
}
Also used : Response(javax.ws.rs.core.Response) ClusterUpgradeDiskSpaceValidationEvent(com.sequenceiq.cloudbreak.core.flow2.cluster.datalake.upgrade.validation.event.ClusterUpgradeDiskSpaceValidationEvent) ClusterUpgradeImageValidationEvent(com.sequenceiq.cloudbreak.core.flow2.cluster.datalake.upgrade.validation.ClusterUpgradeImageValidationEvent) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) ClusterUpgradeValidationFailureEvent(com.sequenceiq.cloudbreak.core.flow2.cluster.datalake.upgrade.validation.event.ClusterUpgradeValidationFailureEvent)

Example 5 with ClusterUpgradeDiskSpaceValidationEvent

use of com.sequenceiq.cloudbreak.core.flow2.cluster.datalake.upgrade.validation.event.ClusterUpgradeDiskSpaceValidationEvent in project cloudbreak by hortonworks.

the class ClusterUpgradeImageValidationHandlerTest method testDoAcceptWhenImageTermsAreSignedThenSuccess.

@Test
void testDoAcceptWhenImageTermsAreSignedThenSuccess() {
    setupCloudContext();
    setupCloudConnector(cloudContext, cloudCredential);
    Validator imageValidator = new ValidatorBuilder(cloudConnector).withSucceedingImageValidator().build().get();
    HandlerEvent<ClusterUpgradeImageValidationEvent> event = getHandlerEvent();
    ClusterUpgradeImageValidationEvent request = event.getData();
    Set<Response> responses = Collections.emptySet();
    when(parcelAvailabilityService.validateAvailability(request.getTargetImage(), request.getResourceId())).thenReturn(responses);
    when(parcelSizeService.getRequiredFreeSpace(responses)).thenReturn(REQUIRED_FREE_SPACE);
    Selectable nextFlowStepSelector = underTest.doAccept(event);
    assertEquals(START_CLUSTER_UPGRADE_DISK_SPACE_VALIDATION_EVENT.selector(), nextFlowStepSelector.selector());
    assertEquals(REQUIRED_FREE_SPACE, ((ClusterUpgradeDiskSpaceValidationEvent) nextFlowStepSelector).getRequiredFreeSpace());
    verify(parcelAvailabilityService).validateAvailability(request.getTargetImage(), request.getResourceId());
    verify(parcelSizeService).getRequiredFreeSpace(responses);
    verify(cloudContext).getPlatformVariant();
    verify(cloudPlatformConnectors).get(CLOUD_PLATFORM_VARIANT);
    verify(imageValidator).validate(authenticatedContext, cloudStack);
}
Also used : Response(javax.ws.rs.core.Response) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) ClusterUpgradeImageValidationEvent(com.sequenceiq.cloudbreak.core.flow2.cluster.datalake.upgrade.validation.ClusterUpgradeImageValidationEvent) Validator(com.sequenceiq.cloudbreak.cloud.Validator) Test(org.junit.jupiter.api.Test)

Aggregations

ClusterUpgradeDiskSpaceValidationEvent (com.sequenceiq.cloudbreak.core.flow2.cluster.datalake.upgrade.validation.event.ClusterUpgradeDiskSpaceValidationEvent)4 ClusterUpgradeImageValidationEvent (com.sequenceiq.cloudbreak.core.flow2.cluster.datalake.upgrade.validation.ClusterUpgradeImageValidationEvent)2 ClusterUpgradeDiskSpaceValidationFinishedEvent (com.sequenceiq.cloudbreak.core.flow2.cluster.datalake.upgrade.validation.event.ClusterUpgradeDiskSpaceValidationFinishedEvent)2 ClusterUpgradeValidationFailureEvent (com.sequenceiq.cloudbreak.core.flow2.cluster.datalake.upgrade.validation.event.ClusterUpgradeValidationFailureEvent)2 Response (javax.ws.rs.core.Response)2 Test (org.junit.jupiter.api.Test)2 Validator (com.sequenceiq.cloudbreak.cloud.Validator)1 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)1 Selectable (com.sequenceiq.cloudbreak.common.event.Selectable)1 UpgradeValidationFailedException (com.sequenceiq.cloudbreak.common.exception.UpgradeValidationFailedException)1 CloudbreakImageCatalogException (com.sequenceiq.cloudbreak.core.CloudbreakImageCatalogException)1 CloudbreakImageNotFoundException (com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException)1 ClusterUpgradeValidationEventToClusterUpgradeDiskSpaceValidationEventConverter (com.sequenceiq.cloudbreak.core.flow2.cluster.datalake.upgrade.validation.config.ClusterUpgradeValidationEventToClusterUpgradeDiskSpaceValidationEventConverter)1 ClusterUpgradeValidationEvent (com.sequenceiq.cloudbreak.core.flow2.cluster.datalake.upgrade.validation.event.ClusterUpgradeValidationEvent)1 StackContext (com.sequenceiq.cloudbreak.core.flow2.stack.StackContext)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Bean (org.springframework.context.annotation.Bean)1