Federico Simoncelli has uploaded a new change for review. Change subject: backend,frontend: add more specific glance errors ......................................................................
backend,frontend: add more specific glance errors Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=1003902 Change-Id: Iecba90adfc2be50fb1471ac93908fde176696404 Signed-off-by: Federico Simoncelli <fsimo...@redhat.com> --- M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ImportRepoImageCommand.java A backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/provider/OpenStackImageException.java M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/provider/OpenStackImageProviderProxy.java M backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java M frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java M frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties 6 files changed, 85 insertions(+), 17 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/70/19370/1 diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ImportRepoImageCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ImportRepoImageCommand.java index 0945b97..7dcd102 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ImportRepoImageCommand.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ImportRepoImageCommand.java @@ -1,5 +1,6 @@ package org.ovirt.engine.core.bll; +import org.ovirt.engine.core.bll.provider.OpenStackImageException; import org.ovirt.engine.core.bll.provider.OpenStackImageProviderProxy; import org.ovirt.engine.core.bll.provider.ProviderProxyFactory; import org.ovirt.engine.core.bll.quota.QuotaConsumptionParameter; @@ -186,8 +187,17 @@ try { diskImage = getDiskImage(); - } catch (Exception e) { - log.error("Unable to get the disk image from the provider proxy", e); + } catch (OpenStackImageException e) { + log.errorFormat("Unable to get the disk image from the provider proxy: {0}", e.getMessage()); + switch (e.getErrorType()) { + case UNSUPPORTED_CONTAINER_FORMAT: + case UNSUPPORTED_DISK_FORMAT: + return failCanDoAction(VdcBllMessages.ACTION_TYPE_FAILED_IMAGE_NOT_SUPPORTED); + case UNABLE_TO_DOWNLOAD_IMAGE: + return failCanDoAction(VdcBllMessages.ACTION_TYPE_FAILED_IMAGE_DOWNLOAD_ERROR); + case UNRECOGNIZED_IMAGE_FORMAT: + return failCanDoAction(VdcBllMessages.ACTION_TYPE_FAILED_IMAGE_UNRECOGNIZED); + } } if (diskImage == null) { diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/provider/OpenStackImageException.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/provider/OpenStackImageException.java new file mode 100644 index 0000000..06586fb --- /dev/null +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/provider/OpenStackImageException.java @@ -0,0 +1,27 @@ +package org.ovirt.engine.core.bll.provider; + +public class OpenStackImageException extends RuntimeException { + + public static enum ErrorType { + UNSUPPORTED_CONTAINER_FORMAT, + UNSUPPORTED_DISK_FORMAT, + UNABLE_TO_DOWNLOAD_IMAGE, + UNRECOGNIZED_IMAGE_FORMAT + } + + ErrorType errorType; + + public OpenStackImageException(ErrorType errorType) { + this.errorType = errorType; + } + + public OpenStackImageException(ErrorType errorType, String message) { + super(message); + this.errorType = errorType; + } + + public ErrorType getErrorType() { + return errorType; + } + +} diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/provider/OpenStackImageProviderProxy.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/provider/OpenStackImageProviderProxy.java index e79e995..33f747e 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/provider/OpenStackImageProviderProxy.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/provider/OpenStackImageProviderProxy.java @@ -182,7 +182,9 @@ protected void validateContainerFormat(Image glanceImage) { if (!glanceImage.getContainerFormat().equals(GlanceImageContainer.BARE.getValue())) { - throw new RuntimeException("Unsupported container format"); + throw new OpenStackImageException( + OpenStackImageException.ErrorType.UNSUPPORTED_CONTAINER_FORMAT, + "Unsupported container format: " + glanceImage.getContainerFormat()); } } @@ -255,7 +257,9 @@ } else if (glanceImage.getDiskFormat().equals(GlanceImageFormat.COW.getValue())) { diskImage.setvolumeFormat(VolumeFormat.COW); } else { - throw new RuntimeException("Unknown disk format: " + glanceImage.getDiskFormat()); + throw new OpenStackImageException( + OpenStackImageException.ErrorType.UNSUPPORTED_DISK_FORMAT, + "Unknown disk format: " + glanceImage.getDiskFormat()); } return diskImage; @@ -271,7 +275,9 @@ } else if (diskImage.getVolumeFormat() == VolumeFormat.COW) { glanceImage.setDiskFormat(GlanceImageFormat.COW.getValue()); } else { - throw new RuntimeException("Unknown disk format: " + diskImage.getVolumeFormat()); + throw new OpenStackImageException( + OpenStackImageException.ErrorType.UNSUPPORTED_DISK_FORMAT, + "Unknown disk format: " + diskImage.getVolumeFormat()); } glanceImage.setContainerFormat(GlanceImageContainer.BARE.getValue()); @@ -281,7 +287,7 @@ return retGlanceImage.getId(); } - private long getCowVirtualSize(String id) throws IOException { + private long getCowVirtualSize(String id) { // For the qcow2 format we need to download the image header and read the virtual size from there byte[] imgContent = new byte[72]; ImageDownload downloadImage = getClient().images().download(id).execute(); @@ -289,11 +295,20 @@ try { int bytesRead = downloadImage.getInputStream().read(imgContent, 0, imgContent.length); if (bytesRead != imgContent.length) { - throw new RuntimeException("Unable to read image header: " + bytesRead); + throw new OpenStackImageException( + OpenStackImageException.ErrorType.UNABLE_TO_DOWNLOAD_IMAGE, + "Unable to read image header: " + bytesRead); } - } - finally { - downloadImage.getInputStream().close(); + } catch (IOException e) { + throw new OpenStackImageException( + OpenStackImageException.ErrorType.UNABLE_TO_DOWNLOAD_IMAGE, + "Unable to download image"); + } finally { + try { + downloadImage.getInputStream().close(); + } catch (IOException e) { + // Silently skip errors on close + } } ByteBuffer b = ByteBuffer.wrap(imgContent); @@ -303,7 +318,9 @@ return b.getLong(); } - throw new RuntimeException("Unable to recognize QCOW2 format"); + throw new OpenStackImageException( + OpenStackImageException.ErrorType.UNRECOGNIZED_IMAGE_FORMAT, + "Unable to recognize QCOW2 format"); } protected long getImageVirtualSize(Image glanceImage) { @@ -313,14 +330,12 @@ || glanceImage.getDiskFormat().equals(GlanceImageFormat.ISO.getValue())) { return glanceImage.getSize(); } else if (glanceImage.getDiskFormat().equals(GlanceImageFormat.COW.getValue())) { - try { - return getCowVirtualSize(glanceImage.getId()); - } catch (IOException e) { - throw new RuntimeException("Unsupported image format"); - } + return getCowVirtualSize(glanceImage.getId()); } - throw new RuntimeException("Unsupported image format"); + throw new OpenStackImageException( + OpenStackImageException.ErrorType.UNSUPPORTED_DISK_FORMAT, + "Unknown disk format: " + glanceImage.getDiskFormat()); } public long getImageVirtualSize(String id) { diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java index 72c0ba3..2ce81c7 100644 --- a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java @@ -767,6 +767,10 @@ ACTION_TYPE_FAILED_CLUSTERID_AND_SERVERID_BOTH_NULL(ErrorType.BAD_PARAMETERS), ACTION_TYPE_FAILED_NO_SERVERS_FOR_CLUSTER(ErrorType.BAD_PARAMETERS), ACTION_TYPE_FAILED_VOLUME_OPERATION_IN_PROGRESS(ErrorType.CONFLICT), + // OpenStack Glance + ACTION_TYPE_FAILED_IMAGE_DOWNLOAD_ERROR(ErrorType.BAD_PARAMETERS), + ACTION_TYPE_FAILED_IMAGE_NOT_SUPPORTED(ErrorType.BAD_PARAMETERS), + ACTION_TYPE_FAILED_IMAGE_UNRECOGNIZED(ErrorType.BAD_PARAMETERS), VM_INTERFACE_NOT_EXIST(ErrorType.BAD_PARAMETERS), ACTION_TYPE_FAILED_CANNOT_REMOVE_ACTIVE_DEVICE(ErrorType.CONFLICT), diff --git a/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java b/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java index 6d2c058..8ead807 100644 --- a/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java +++ b/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java @@ -2525,6 +2525,15 @@ @DefaultStringValue("Cannot ${action} ${type}. A task is in progress on the volume ${volumeName} in cluster ${vdsGroup}.") String ACTION_TYPE_FAILED_VOLUME_OPERATION_IN_PROGRESS(); + @DefaultStringValue("Cannot ${action} ${type}. An unexpected error occurred trying to inspect the image content.") + String ACTION_TYPE_FAILED_IMAGE_DOWNLOAD_ERROR(); + + @DefaultStringValue("Cannot ${action} ${type}. The image format is not supported.") + String ACTION_TYPE_FAILED_IMAGE_NOT_SUPPORTED(); + + @DefaultStringValue("Cannot ${action} ${type}. The image is missing or its format is corrupted or unrecognizable") + String ACTION_TYPE_FAILED_IMAGE_UNRECOGNIZED(); + @DefaultStringValue("Cannot ${action} ${type}. Rebalance is not running on the volume ${volumeName} in cluster ${vdsGroup}.") String ACTION_TYPE_FAILED_GLUSTER_VOLUME_REBALANCE_NOT_STARTED(); diff --git a/frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties b/frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties index c1589d6..65348f0 100644 --- a/frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties +++ b/frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties @@ -947,6 +947,9 @@ ACTION_TYEPE_FAILED_SERVICE_ALREADY_STOPPED=Cannot ${action} ${type}. Service ${service} already stopped on Server ${server}. CLUSTER_ALL_SERVERS_NOT_UP=One or more servers in the cluster is down ACTION_TYPE_FAILED_VOLUME_OPERATION_IN_PROGRESS=Cannot ${action} ${type}. A task is in progress on the volume ${volumeName} in cluster ${vdsGroup}. +ACTION_TYPE_FAILED_IMAGE_DOWNLOAD_ERROR=Cannot ${action} ${type}. An unexpected error occurred trying to inspect the image content. +ACTION_TYPE_FAILED_IMAGE_NOT_SUPPORTED=Cannot ${action} ${type}. The image format is not supported. +ACTION_TYPE_FAILED_IMAGE_UNRECOGNIZED=Cannot ${action} ${type}. The image is missing or its format is corrupted or unrecognizable ACTION_TYPE_FAILED_GLUSTER_VOLUME_REBALANCE_NOT_STARTED=Cannot ${action} ${type}. Rebalance is not running on the volume ${volumeName} in cluster ${vdsGroup}. ACTION_TYPE_FAILED_NETWORK_QOS_MISSING_VALUES=Cannot ${action} ${type}. All three values are needed in order to define QoS on each network directions. ACTION_TYPE_FAILED_NETWORK_QOS_NEGATIVE_VALUES=Cannot ${action} ${type}. Negative values are not allowed. -- To view, visit http://gerrit.ovirt.org/19370 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Iecba90adfc2be50fb1471ac93908fde176696404 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Federico Simoncelli <fsimo...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches