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