Daniel Erez has uploaded a new change for review. Change subject: core: add CinderDisksValidator ......................................................................
core: add CinderDisksValidator Introducing CinderDisksValidator and a generic error (ACTION_TYPE_FAILED_CINDER) for handling an OpenStackResponseException. Change-Id: I763c0467bb144a450ba68de2128cb7cea13ee983 Bug-Url: https://bugzilla.redhat.com/1185826 Signed-off-by: Daniel Erez <[email protected]> --- A backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/validator/storage/CinderDisksValidator.java M backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties M frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java M frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties M frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties 5 files changed, 72 insertions(+), 1 deletion(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/22/39022/1 diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/validator/storage/CinderDisksValidator.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/validator/storage/CinderDisksValidator.java new file mode 100644 index 0000000..5491ced --- /dev/null +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/validator/storage/CinderDisksValidator.java @@ -0,0 +1,65 @@ +package org.ovirt.engine.core.bll.validator.storage; + +import com.woorea.openstack.base.client.OpenStackResponseException; +import org.ovirt.engine.core.bll.ValidationResult; +import org.ovirt.engine.core.bll.provider.storage.OpenStackVolumeProviderProxy; +import org.ovirt.engine.core.common.businessentities.storage.CinderDisk; +import org.ovirt.engine.core.common.errors.VdcBllMessages; +import org.ovirt.engine.core.compat.Guid; +import org.ovirt.engine.core.dal.dbbroker.DbFacade; +import org.ovirt.engine.core.dao.DiskDao; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.Callable; + +public class CinderDisksValidator { + + private Iterable<CinderDisk> cinderDisks; + + private Map<Guid, OpenStackVolumeProviderProxy> diskProxyMap; + + public CinderDisksValidator(Iterable<CinderDisk> cinderDisks) { + this.cinderDisks = cinderDisks; + this.diskProxyMap = getVolumeProviderProxyMap(); + } + + public CinderDisksValidator(CinderDisk cinderDisk) { + this(Collections.singleton(cinderDisk)); + } + + private ValidationResult validate(Callable<ValidationResult> callable) { + try { + return callable.call(); + } catch (OpenStackResponseException e) { + return new ValidationResult(VdcBllMessages.ACTION_TYPE_FAILED_CINDER, + String.format("$cinderException %1$s", e.getMessage())); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + private Map<Guid, OpenStackVolumeProviderProxy> getVolumeProviderProxyMap() { + if (diskProxyMap == null) { + diskProxyMap = new HashMap<>(); + for (CinderDisk cinderDisk : cinderDisks) { + OpenStackVolumeProviderProxy volumeProviderProxy = getVolumeProviderProxy(cinderDisk); + diskProxyMap.put(cinderDisk.getId(), volumeProviderProxy); + } + + } + return diskProxyMap; + } + + private OpenStackVolumeProviderProxy getVolumeProviderProxy(CinderDisk cinderDisk) { + if (cinderDisk == null || cinderDisk.getStorageIds().isEmpty()) { + return null; + } + return OpenStackVolumeProviderProxy.getFromStorageDomainId(cinderDisk.getStorageIds().get(0)); + } + + protected DiskDao getDiskDao() { + return DbFacade.getInstance().getDiskDao(); + } +} diff --git a/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties b/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties index 82389f8..858ea8e 100644 --- a/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties +++ b/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties @@ -1376,3 +1376,4 @@ # Cinder ACTION_TYPE_FAILED_PROVIDER_NOT_SUPPORTED=Cannot ${action} ${type}. The current type ${providerType} is not supported. +ACTION_TYPE_FAILED_CINDER=Cannot ${action} ${type}. An error occurred on Cinder - '${cinderException}'. 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 d723849..972bee1 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 @@ -3666,4 +3666,7 @@ @DefaultStringValue("Cannot ${action} ${type}. The current type ${providerType} is not supported.") String ACTION_TYPE_FAILED_PROVIDER_NOT_SUPPORTED(); + + @DefaultStringValue("Cannot ${action} ${type}. An error occurred on Cinder - '${cinderException}'") + String ACTION_TYPE_FAILED_CINDER(); } diff --git a/frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties b/frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties index 85101be..a0cfcc9 100644 --- a/frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties +++ b/frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties @@ -1091,4 +1091,5 @@ ACTION_TYPE_REMOVE_GRAPHICS_DEV_INVALID_PARAMS=Cannot ${action} ${type}. Graphics device ID or VM/Template ID is null. # Cinder -ACTION_TYPE_FAILED_PROVIDER_NOT_SUPPORTED=Cannot ${action} ${type}. The current type ${providerType} is not supported. \ No newline at end of file +ACTION_TYPE_FAILED_PROVIDER_NOT_SUPPORTED=Cannot ${action} ${type}. The current type ${providerType} is not supported. +ACTION_TYPE_FAILED_CINDER=Cannot ${action} ${type}. An error occurred on Cinder - '${cinderException}'. 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 ed2fbb6..ad4df61 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 @@ -1329,3 +1329,4 @@ # Cinder ACTION_TYPE_FAILED_PROVIDER_NOT_SUPPORTED=Cannot ${action} ${type}. The current type ${providerType} is not supported. +ACTION_TYPE_FAILED_CINDER=Cannot ${action} ${type}. An error occurred on Cinder - '${cinderException}'. -- To view, visit https://gerrit.ovirt.org/39022 To unsubscribe, visit https://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I763c0467bb144a450ba68de2128cb7cea13ee983 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Daniel Erez <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
