Search in sources :

Example 1 with ImageStatusResult

use of com.sequenceiq.cloudbreak.common.type.ImageStatusResult in project cloudbreak by hortonworks.

the class GcpProvisionSetup method checkImageStatus.

@Override
public ImageStatusResult checkImageStatus(AuthenticatedContext authenticatedContext, CloudStack stack, com.sequenceiq.cloudbreak.cloud.model.Image image) {
    CloudCredential credential = authenticatedContext.getCloudCredential();
    String projectId = getProjectId(credential);
    String imageName = image.getImageName();
    try {
        Image gcpApiImage = new Image();
        gcpApiImage.setName(getImageName(imageName));
        Compute compute = buildCompute(credential);
        Get getImages = compute.images().get(projectId, gcpApiImage.getName());
        String status = getImages.execute().getStatus();
        LOGGER.info("Status of image {} copy: {}", gcpApiImage.getName(), status);
        if (READY.equals(status)) {
            return new ImageStatusResult(ImageStatus.CREATE_FINISHED, ImageStatusResult.COMPLETED);
        }
    } catch (IOException e) {
        LOGGER.warn("Failed to retrieve image copy status", e);
        return new ImageStatusResult(ImageStatus.CREATE_FAILED, 0);
    }
    return new ImageStatusResult(ImageStatus.IN_PROGRESS, ImageStatusResult.HALF);
}
Also used : CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) GcpStackUtil.buildCompute(com.sequenceiq.cloudbreak.cloud.gcp.util.GcpStackUtil.buildCompute) Compute(com.google.api.services.compute.Compute) Get(com.google.api.services.compute.Compute.Images.Get) IOException(java.io.IOException) Image(com.google.api.services.compute.model.Image) ImageStatusResult(com.sequenceiq.cloudbreak.common.type.ImageStatusResult)

Example 2 with ImageStatusResult

use of com.sequenceiq.cloudbreak.common.type.ImageStatusResult 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 3 with ImageStatusResult

use of com.sequenceiq.cloudbreak.common.type.ImageStatusResult in project cloudbreak by hortonworks.

the class OpenStackSetup method checkImageStatus.

@Override
public ImageStatusResult checkImageStatus(AuthenticatedContext authenticatedContext, CloudStack stack, com.sequenceiq.cloudbreak.cloud.model.Image image) {
    String imageName = image.getImageName();
    OSClient osClient = openStackClient.createOSClient(authenticatedContext);
    Image.ImageStatus imageStatus = openStackImageVerifier.getStatus(osClient, imageName);
    ImageStatusResult imageStatusResult;
    switch(imageStatus) {
        case ACTIVE:
            imageStatusResult = new ImageStatusResult(ImageStatus.CREATE_FINISHED, ImageStatusResult.COMPLETED);
            break;
        case QUEUED:
        case SAVING:
            imageStatusResult = new ImageStatusResult(ImageStatus.IN_PROGRESS, ImageStatusResult.HALF);
            break;
        default:
            imageStatusResult = new ImageStatusResult(ImageStatus.CREATE_FAILED, ImageStatusResult.COMPLETED);
            break;
    }
    LOGGER.info("OpenStack image result. name: {}, imageStatus: {}, imageStatusResult: {}", imageName, imageStatus, imageStatusResult);
    return imageStatusResult;
}
Also used : OSClient(org.openstack4j.api.OSClient) Image(org.openstack4j.model.image.v2.Image) ImageStatusResult(com.sequenceiq.cloudbreak.common.type.ImageStatusResult)

Example 4 with ImageStatusResult

use of com.sequenceiq.cloudbreak.common.type.ImageStatusResult 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)

Example 5 with ImageStatusResult

use of com.sequenceiq.cloudbreak.common.type.ImageStatusResult in project cloudbreak by hortonworks.

the class AzureSetup method checkImageStatus.

@Override
public ImageStatusResult checkImageStatus(AuthenticatedContext ac, CloudStack stack, Image image) {
    String imageResourceGroupName = armStorage.getImageResourceGroupName(ac.getCloudContext(), stack);
    AzureClient client = ac.getParameter(AzureClient.class);
    AzureCredentialView acv = new AzureCredentialView(ac.getCloudCredential());
    String imageStorageName = armStorage.getImageStorageName(acv, ac.getCloudContext(), stack);
    try {
        CopyState copyState = client.getCopyStatus(imageResourceGroupName, imageStorageName, IMAGES_CONTAINER, image.getImageName());
        if (CopyStatus.SUCCESS.equals(copyState.getStatus())) {
            if (AzureUtils.hasManagedDisk(stack)) {
                String customImageId = armStorage.getCustomImageId(client, ac, stack);
                if (customImageId == null) {
                    return new ImageStatusResult(ImageStatus.CREATE_FAILED, ImageStatusResult.COMPLETED);
                }
            }
            return new ImageStatusResult(ImageStatus.CREATE_FINISHED, ImageStatusResult.COMPLETED);
        } else if (CopyStatus.ABORTED.equals(copyState.getStatus()) || CopyStatus.INVALID.equals(copyState.getStatus())) {
            return new ImageStatusResult(ImageStatus.CREATE_FAILED, 0);
        } else {
            int percentage = (int) (((double) copyState.getBytesCopied() * ImageStatusResult.COMPLETED) / copyState.getTotalBytes());
            LOGGER.info(String.format("CopyStatus Pending %s byte/%s byte: %.4s %%", copyState.getTotalBytes(), copyState.getBytesCopied(), percentage));
            return new ImageStatusResult(ImageStatus.IN_PROGRESS, percentage);
        }
    } catch (RuntimeException ignored) {
        return new ImageStatusResult(ImageStatus.IN_PROGRESS, ImageStatusResult.HALF);
    }
}
Also used : AzureClient(com.sequenceiq.cloudbreak.cloud.azure.client.AzureClient) AzureCredentialView(com.sequenceiq.cloudbreak.cloud.azure.view.AzureCredentialView) CopyState(com.microsoft.azure.storage.blob.CopyState) ImageStatusResult(com.sequenceiq.cloudbreak.common.type.ImageStatusResult)

Aggregations

ImageStatusResult (com.sequenceiq.cloudbreak.common.type.ImageStatusResult)5 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)2 CheckImageRequest (com.sequenceiq.cloudbreak.cloud.event.setup.CheckImageRequest)2 CheckImageResult (com.sequenceiq.cloudbreak.cloud.event.setup.CheckImageResult)2 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)2 Image (com.sequenceiq.cloudbreak.cloud.model.Image)2 Compute (com.google.api.services.compute.Compute)1 Get (com.google.api.services.compute.Compute.Images.Get)1 Image (com.google.api.services.compute.model.Image)1 CopyState (com.microsoft.azure.storage.blob.CopyState)1 CloudConnector (com.sequenceiq.cloudbreak.cloud.CloudConnector)1 AzureClient (com.sequenceiq.cloudbreak.cloud.azure.client.AzureClient)1 AzureCredentialView (com.sequenceiq.cloudbreak.cloud.azure.view.AzureCredentialView)1 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)1 GcpStackUtil.buildCompute (com.sequenceiq.cloudbreak.cloud.gcp.util.GcpStackUtil.buildCompute)1 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)1 Location (com.sequenceiq.cloudbreak.cloud.model.Location)1 OperationException (com.sequenceiq.cloudbreak.service.stack.connector.OperationException)1 IOException (java.io.IOException)1 OSClient (org.openstack4j.api.OSClient)1