Search in sources :

Example 1 with CheckImageResult

use of com.sequenceiq.cloudbreak.cloud.event.setup.CheckImageResult in project cloudbreak by hortonworks.

the class ServiceProviderSetupAdapter method checkImage.

public ImageStatusResult checkImage(Stack stack) throws Exception {
    Location location = location(region(stack.getRegion()), availabilityZone(stack.getAvailabilityZone()));
    CloudContext cloudContext = new CloudContext(stack.getId(), stack.getName(), stack.cloudPlatform(), stack.getOwner(), stack.getPlatformVariant(), location);
    CloudCredential cloudCredential = credentialConverter.convert(stack.getCredential());
    Image image = imageService.getImage(stack.getId());
    CheckImageRequest<CheckImageResult> checkImageRequest = new CheckImageRequest<>(cloudContext, cloudCredential, cloudStackConverter.convert(stack), image);
    LOGGER.info("Triggering event: {}", checkImageRequest);
    eventBus.notify(checkImageRequest.selector(), eventFactory.createEvent(checkImageRequest));
    try {
        CheckImageResult res = checkImageRequest.await();
        LOGGER.info("Result: {}", res);
        if (res.getErrorDetails() != null) {
            LOGGER.error("Failed to check image state", res.getErrorDetails());
            throw new OperationException(res.getErrorDetails());
        }
        return new ImageStatusResult(res.getImageStatus(), res.getStatusProgressValue());
    } catch (InterruptedException e) {
        LOGGER.error("Error while executing check image", e);
        throw new OperationException(e);
    }
}
Also used : CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) CheckImageResult(com.sequenceiq.cloudbreak.cloud.event.setup.CheckImageResult) Image(com.sequenceiq.cloudbreak.cloud.model.Image) OperationException(com.sequenceiq.cloudbreak.service.stack.connector.OperationException) Location(com.sequenceiq.cloudbreak.cloud.model.Location) CheckImageRequest(com.sequenceiq.cloudbreak.cloud.event.setup.CheckImageRequest) ImageStatusResult(com.sequenceiq.cloudbreak.common.type.ImageStatusResult)

Example 2 with CheckImageResult

use of com.sequenceiq.cloudbreak.cloud.event.setup.CheckImageResult in project cloudbreak by hortonworks.

the class CheckImageAction method doExecute.

@Override
protected void doExecute(StackContext context, StackEvent payload, Map<Object, Object> variables) {
    CheckImageResult checkImageResult = stackCreationService.checkImage(context);
    switch(checkImageResult.getImageStatus()) {
        case IN_PROGRESS:
            repeat(context);
            break;
        case CREATE_FINISHED:
            sendEvent(context);
            break;
        case CREATE_FAILED:
            LOGGER.error("Error during image status check: {}", payload);
            int faultNum = getFaultNum(variables) + 1;
            if (faultNum == FAULT_TOLERANCE) {
                removeFaultNum(variables);
                throw new CloudbreakServiceException("Image copy failed.");
            } else {
                setFaultNum(variables, faultNum);
                repeat(context);
            }
            break;
        default:
            LOGGER.error("Unknown imagestatus: {}", checkImageResult.getImageStatus());
            break;
    }
}
Also used : CloudbreakServiceException(com.sequenceiq.cloudbreak.service.CloudbreakServiceException) CheckImageResult(com.sequenceiq.cloudbreak.cloud.event.setup.CheckImageResult)

Example 3 with CheckImageResult

use of com.sequenceiq.cloudbreak.cloud.event.setup.CheckImageResult in project cloudbreak by hortonworks.

the class StackCreationService method checkImage.

public CheckImageResult checkImage(StackContext context) {
    try {
        Stack stack = context.getStack();
        Image image = imageService.getImage(stack.getId());
        CheckImageRequest<CheckImageResult> checkImageRequest = new CheckImageRequest<>(context.getCloudContext(), context.getCloudCredential(), cloudStackConverter.convert(stack), image);
        LOGGER.info("Triggering event: {}", checkImageRequest);
        eventBus.notify(checkImageRequest.selector(), eventFactory.createEvent(checkImageRequest));
        CheckImageResult result = checkImageRequest.await();
        sendNotification(result, stack);
        LOGGER.info("Result: {}", result);
        return result;
    } catch (InterruptedException e) {
        LOGGER.error("Error while executing check image", e);
        throw new OperationException(e);
    } catch (CloudbreakImageNotFoundException e) {
        throw new CloudbreakServiceException(e);
    }
}
Also used : CloudbreakServiceException(com.sequenceiq.cloudbreak.service.CloudbreakServiceException) CheckImageResult(com.sequenceiq.cloudbreak.cloud.event.setup.CheckImageResult) CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) Image(com.sequenceiq.cloudbreak.cloud.model.Image) OperationException(com.sequenceiq.cloudbreak.service.stack.connector.OperationException) Stack(com.sequenceiq.cloudbreak.domain.Stack) CheckImageRequest(com.sequenceiq.cloudbreak.cloud.event.setup.CheckImageRequest)

Example 4 with CheckImageResult

use of com.sequenceiq.cloudbreak.cloud.event.setup.CheckImageResult in project cloudbreak by hortonworks.

the class CheckImageHandler method accept.

@Override
public void accept(Event<CheckImageRequest> event) {
    LOGGER.info("Received event: {}", event);
    CheckImageRequest request = event.getData();
    CloudContext cloudContext = request.getCloudContext();
    try {
        CloudConnector connector = cloudPlatformConnectors.get(request.getCloudContext().getPlatformVariant());
        AuthenticatedContext auth = connector.authentication().authenticate(cloudContext, request.getCloudCredential());
        Image image = request.getImage();
        CloudStack stack = request.getStack();
        ImageStatusResult progress = connector.setup().checkImageStatus(auth, stack, image);
        CheckImageResult imageResult = new CheckImageResult(request, progress.getImageStatus(), progress.getStatusProgressValue());
        request.getResult().onNext(imageResult);
        LOGGER.info("Provision setup finished for {}", cloudContext);
    } catch (RuntimeException e) {
        CheckImageResult failure = new CheckImageResult(e, request, ImageStatus.CREATE_FAILED);
        request.getResult().onNext(failure);
    }
}
Also used : CloudConnector(com.sequenceiq.cloudbreak.cloud.CloudConnector) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) CheckImageResult(com.sequenceiq.cloudbreak.cloud.event.setup.CheckImageResult) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) Image(com.sequenceiq.cloudbreak.cloud.model.Image) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) CheckImageRequest(com.sequenceiq.cloudbreak.cloud.event.setup.CheckImageRequest) ImageStatusResult(com.sequenceiq.cloudbreak.common.type.ImageStatusResult)

Aggregations

CheckImageResult (com.sequenceiq.cloudbreak.cloud.event.setup.CheckImageResult)4 CheckImageRequest (com.sequenceiq.cloudbreak.cloud.event.setup.CheckImageRequest)3 Image (com.sequenceiq.cloudbreak.cloud.model.Image)3 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)2 ImageStatusResult (com.sequenceiq.cloudbreak.common.type.ImageStatusResult)2 CloudbreakServiceException (com.sequenceiq.cloudbreak.service.CloudbreakServiceException)2 OperationException (com.sequenceiq.cloudbreak.service.stack.connector.OperationException)2 CloudConnector (com.sequenceiq.cloudbreak.cloud.CloudConnector)1 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)1 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)1 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)1 Location (com.sequenceiq.cloudbreak.cloud.model.Location)1 CloudbreakImageNotFoundException (com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException)1 Stack (com.sequenceiq.cloudbreak.domain.Stack)1