Omer Frenkel has uploaded a new change for review.

Change subject: webadmin: warn when exporting template version if base is 
missing
......................................................................

webadmin: warn when exporting template version if base is missing

added a warning to the user, if trying to export template version,
and the base template is missing on the export domain,
because on import the base template must exist, or clone is needed.

this is very similar for exporting thin vm when template is missing.

Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=1073035
Change-Id: I028f9e98a31cca391e05e2e02c535f5f1b2068cf
Signed-off-by: Omer Frenkel <[email protected]>
---
M 
frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/help/HelpTag.java
M 
frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/templates/TemplateListModel.java
M 
frontend/webadmin/modules/uicompat/src/main/java/org/ovirt/engine/ui/uicompat/UIConstants.java
3 files changed, 136 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/72/26072/1

diff --git 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/help/HelpTag.java
 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/help/HelpTag.java
index 5422557..b90258c 100644
--- 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/help/HelpTag.java
+++ 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/help/HelpTag.java
@@ -398,6 +398,8 @@
 
     template_not_found_on_export_domain("template_not_found_on_export_domain", 
HelpTagType.WEBADMIN, "VMs Tab > Export VM(s) > Confirm VM's Template not on 
Export Domain"), //$NON-NLS-1$ //$NON-NLS-2$
 
+    
base_template_not_found_on_export_domain("base_template_not_found_on_export_domain",
 HelpTagType.WEBADMIN, "Templates Tab > Export Template Version(s) > Confirm 
Base Template not on Export Domain"), //$NON-NLS-1$ //$NON-NLS-2$
+
     templates("templates", HelpTagType.UNKNOWN), //$NON-NLS-1$
 
     users("users", HelpTagType.UNKNOWN), //$NON-NLS-1$
diff --git 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/templates/TemplateListModel.java
 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/templates/TemplateListModel.java
index dde05d7..646f372 100644
--- 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/templates/TemplateListModel.java
+++ 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/templates/TemplateListModel.java
@@ -14,6 +14,8 @@
 import org.ovirt.engine.core.common.businessentities.DisplayType;
 import org.ovirt.engine.core.common.businessentities.StorageDomain;
 import org.ovirt.engine.core.common.businessentities.VDS;
+import org.ovirt.engine.core.common.businessentities.DiskImage;
+import org.ovirt.engine.core.common.businessentities.StoragePool;
 import org.ovirt.engine.core.common.businessentities.VmTemplate;
 import org.ovirt.engine.core.common.businessentities.VmTemplateStatus;
 import org.ovirt.engine.core.common.businessentities.VmWatchdog;
@@ -211,6 +213,113 @@
         {
             return;
         }
+
+        model.startProgress(null);
+
+        getTemplatesNotPresentOnExportDomain();
+    }
+
+    private void getTemplatesNotPresentOnExportDomain()
+    {
+        ExportVmModel model = (ExportVmModel) getWindow();
+        Guid storageDomainId = ((StorageDomain) 
model.getStorage().getSelectedItem()).getId();
+
+        AsyncDataProvider.getDataCentersByStorageDomain(new AsyncQuery(this,
+                new INewAsyncCallback() {
+                    @Override
+                    public void onSuccess(Object target, Object returnValue) {
+                        TemplateListModel templateListModel = 
(TemplateListModel) target;
+                        ArrayList<StoragePool> storagePools =
+                                (ArrayList<StoragePool>) returnValue;
+                        StoragePool storagePool = storagePools.size() > 0 ? 
storagePools.get(0) : null;
+
+                        
templateListModel.postGetTemplatesNotPresentOnExportDomain(storagePool);
+                    }
+                }), storageDomainId);
+    }
+
+    private void postGetTemplatesNotPresentOnExportDomain(StoragePool 
storagePool)
+    {
+        ExportVmModel model = (ExportVmModel) getWindow();
+        Guid storageDomainId = ((StorageDomain) 
model.getStorage().getSelectedItem()).getId();
+
+        if (storagePool != null)
+        {
+            AsyncDataProvider.getAllTemplatesFromExportDomain(new 
AsyncQuery(this,
+                    new INewAsyncCallback() {
+                        @Override
+                        public void onSuccess(Object target, Object 
returnValue) {
+                            TemplateListModel templateListModel = 
(TemplateListModel) target;
+                            HashMap<VmTemplate, ArrayList<DiskImage>> 
templatesDiskSet =
+                                    (HashMap<VmTemplate, 
ArrayList<DiskImage>>) returnValue;
+                            ArrayList<String> verTempMissingBase = new 
ArrayList<String>();
+
+                            // check if relevant templates are already there
+                            for (Object selectedItem : 
templateListModel.getSelectedItems()) {
+                                VmTemplate template = (VmTemplate) 
selectedItem;
+                                // only relevant for template versions
+                                if (!template.isBaseTemplate()) {
+                                    boolean hasMatch = false;
+                                    for (VmTemplate a : 
templatesDiskSet.keySet()) {
+                                        if 
(template.getBaseTemplateId().equals(a.getId())) {
+                                            hasMatch = true;
+                                            break;
+                                        }
+                                    }
+
+                                    if 
(!template.getBaseTemplateId().equals(Guid.Empty) && !hasMatch) {
+                                        
verTempMissingBase.add(template.getName());
+                                    }
+                                }
+                            }
+
+                            
templateListModel.postExportGetMissingTemplates(verTempMissingBase);
+                        }
+                    }),
+                    storagePool.getId(),
+                    storageDomainId);
+        }
+    }
+
+    private void postExportGetMissingTemplates(ArrayList<String> 
missingTemplatesFromVms)
+    {
+        ExportVmModel model = (ExportVmModel) getWindow();
+
+        if (!missingTemplatesFromVms.isEmpty())
+        {
+            model.stopProgress();
+
+            ConfirmationModel confirmModel = new ConfirmationModel();
+            setConfirmWindow(confirmModel);
+            confirmModel.setTitle(ConstantsManager.getInstance()
+                    .getConstants()
+                    .baseTemplatesNotFoundOnExportDomainTitle());
+            
confirmModel.setHelpTag(HelpTag.base_template_not_found_on_export_domain);
+            
confirmModel.setHashName("base_template_not_found_on_export_domain"); 
//$NON-NLS-1$
+
+            confirmModel.setMessage(ConstantsManager.getInstance()
+                            .getConstants()
+                            
.theFollowingTemplatesAreMissingOnTargetExportDomainForTemplateVersionsMsg());
+            confirmModel.setItems(missingTemplatesFromVms);
+
+            UICommand tempVar = new UICommand("OnExportNoTemplates", this); 
//$NON-NLS-1$
+            
tempVar.setTitle(ConstantsManager.getInstance().getConstants().ok());
+            tempVar.setIsDefault(true);
+            confirmModel.getCommands().add(tempVar);
+            UICommand tempVar2 = new UICommand("CancelConfirmation", this); 
//$NON-NLS-1$
+            
tempVar2.setTitle(ConstantsManager.getInstance().getConstants().cancel());
+            tempVar2.setIsCancel(true);
+            confirmModel.getCommands().add(tempVar2);
+        }
+        else
+        {
+            doExport();
+        }
+    }
+
+    private void doExport()
+    {
+        ExportVmModel model = (ExportVmModel) getWindow();
 
         ArrayList<VdcActionParametersBase> list = new 
ArrayList<VdcActionParametersBase>();
         for (Object item : getSelectedItems())
@@ -588,7 +697,16 @@
     {
         Frontend.getInstance().unsubscribe();
 
+        cancelConfirmation();
+
         setWindow(null);
+
+        updateActionAvailability();
+    }
+
+    private void cancelConfirmation()
+    {
+        setConfirmWindow(null);
     }
 
     @Override
@@ -734,6 +852,14 @@
         {
             onRemove();
         }
+        else if ("OnExportNoTemplates".equals(command.getName())) //$NON-NLS-1$
+        {
+            doExport();
+        }
+        else if ("CancelConfirmation".equals(command.getName())) //$NON-NLS-1$
+        {
+            cancelConfirmation();
+        }
     }
 
     @Override
diff --git 
a/frontend/webadmin/modules/uicompat/src/main/java/org/ovirt/engine/ui/uicompat/UIConstants.java
 
b/frontend/webadmin/modules/uicompat/src/main/java/org/ovirt/engine/ui/uicompat/UIConstants.java
index 67709c5..db18978 100644
--- 
a/frontend/webadmin/modules/uicompat/src/main/java/org/ovirt/engine/ui/uicompat/UIConstants.java
+++ 
b/frontend/webadmin/modules/uicompat/src/main/java/org/ovirt/engine/ui/uicompat/UIConstants.java
@@ -639,6 +639,9 @@
     @DefaultStringValue("Template(s) not Found on Export Domain")
     String templatesNotFoundOnExportDomainTitle();
 
+    @DefaultStringValue("Base Template(s) not Found on Export Domain")
+    String baseTemplatesNotFoundOnExportDomainTitle();
+
     @DefaultStringValue("Run Virtual Machine(s)")
     String runVirtualMachinesTitle();
 
@@ -1374,6 +1377,11 @@
     @DefaultStringValue("The following templates are missing on the target 
Export Domain:")
     String theFollowingTemplatesAreMissingOnTargetExportDomainMsg();
 
+    @DefaultStringValue("The following template versions are based on 
templates which do not exist on the export domain and are required for the 
template version to function.\n" +
+            "If you proceed you will not be able to import these template 
versions unless you already have the relevant templates on the target domains, 
or by using Clone.\n" +
+            "Do you wish to continue anyway?")
+    String 
theFollowingTemplatesAreMissingOnTargetExportDomainForTemplateVersionsMsg();
+
     @DefaultStringValue("There are no active Data-Centers in the system.")
     String noActiveDataCenters();
 


-- 
To view, visit http://gerrit.ovirt.org/26072
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I028f9e98a31cca391e05e2e02c535f5f1b2068cf
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: ovirt-engine-3.4
Gerrit-Owner: Omer Frenkel <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to