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