Search in sources :

Example 1 with CopyState

use of com.microsoft.azure.storage.blob.CopyState 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

CopyState (com.microsoft.azure.storage.blob.CopyState)1 AzureClient (com.sequenceiq.cloudbreak.cloud.azure.client.AzureClient)1 AzureCredentialView (com.sequenceiq.cloudbreak.cloud.azure.view.AzureCredentialView)1 ImageStatusResult (com.sequenceiq.cloudbreak.common.type.ImageStatusResult)1