VirtualBox

Changeset 78749 in vbox for trunk/src


Ignore:
Timestamp:
May 25, 2019 5:18:05 PM (6 years ago)
Author:
vboxsync
Message:

Main/Appliance::i_importImpl: Ditto (bugref:9416). Untested.

Location:
trunk/src/VBox/Main/src-server
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/src-server/ApplianceImpl.cpp

    r78428 r78749  
    10191019
    10201020    /* Create the progress object */
    1021     pProgress.createObject();
     1021    try
     1022    {
     1023        rc = pProgress.createObject();
     1024        if (FAILED(rc))
     1025            return rc;
     1026    }
     1027    catch (std::bad_alloc &)
     1028    {
     1029        return E_OUTOFMEMORY;
     1030    }
    10221031
    10231032    // compute the disks weight (this sets ulTotalDisksMB and cDisks in the instance data)
     
    10261035    m->ulWeightForManifestOperation = 0;
    10271036
    1028     ULONG cOperations;
     1037    ULONG cOperations = 1               // one for XML setup
     1038                      + m->cDisks;      // plus one per disk
    10291039    ULONG ulTotalOperationsWeight;
    1030 
    1031     cOperations =   1               // one for XML setup
    1032                   + m->cDisks;      // plus one per disk
    10331040    if (m->ulTotalDisksMB)
    10341041    {
     
    10641071        case ImportS3:
    10651072        {
    1066             cOperations += 1 + 1;     // another one for the manifest file & another one for the import
     1073            cOperations += 1 + 1;       // another one for the manifest file & another one for the import
    10671074            ulTotalOperationsWeight = m->ulTotalDisksMB;
    10681075            if (!m->ulTotalDisksMB)
     
    10811088        case WriteS3:
    10821089        {
    1083             cOperations += 1 + 1;     // another one for the mf & another one for temporary creation
     1090            cOperations += 1 + 1;       // another one for the mf & another one for temporary creation
    10841091
    10851092            if (m->ulTotalDisksMB)
     
    11101117         m->ulTotalDisksMB, m->cDisks, cOperations, ulTotalOperationsWeight, m->ulWeightForXmlOperation));
    11111118
    1112     rc = pProgress->init(mVirtualBox, static_cast<IAppliance*>(this),
    1113                          Bstr(strDescription).raw(),
    1114                          TRUE /* aCancelable */,
    1115                          cOperations, // ULONG cOperations,
    1116                          ulTotalOperationsWeight, // ULONG ulTotalOperationsWeight,
    1117                          Bstr(strDescription).raw(), // CBSTR bstrFirstOperationDescription,
    1118                          m->ulWeightForXmlOperation); // ULONG ulFirstOperationWeight,
    1119     return rc;
     1119    return pProgress->init(mVirtualBox, static_cast<IAppliance*>(this),
     1120                           strDescription,
     1121                           TRUE /* aCancelable */,
     1122                           cOperations, // ULONG cOperations,
     1123                           ulTotalOperationsWeight, // ULONG ulTotalOperationsWeight,
     1124                           strDescription, // CBSTR bstrFirstOperationDescription,
     1125                           m->ulWeightForXmlOperation); // ULONG ulFirstOperationWeight,
    11201126}
    11211127
  • trunk/src/VBox/Main/src-server/ApplianceImplImport.cpp

    r78748 r78749  
    782782    if (aOptions.size())
    783783    {
    784         m->optListImport.setCapacity(aOptions.size());
    785         for (size_t i = 0; i < aOptions.size(); ++i)
    786         {
    787             m->optListImport.insert(i, aOptions[i]);
     784        try
     785        {
     786            m->optListImport.setCapacity(aOptions.size());
     787            for (size_t i = 0; i < aOptions.size(); ++i)
     788                m->optListImport.insert(i, aOptions[i]);
     789        }
     790        catch (std::bad_alloc &)
     791        {
     792            return E_OUTOFMEMORY;
    788793        }
    789794    }
     
    803808
    804809    ComObjPtr<Progress> progress;
    805     HRESULT rc = S_OK;
    806     try
    807     {
    808         rc = i_importImpl(m->locInfo, progress);
    809     }
    810     catch (HRESULT aRC)
    811     {
    812         rc = aRC;
    813     }
    814 
    815     if (SUCCEEDED(rc))
    816         /* Return progress to the caller */
     810    HRESULT hrc = i_importImpl(m->locInfo, progress);
     811    if (SUCCEEDED(hrc))
    817812        progress.queryInterfaceTo(aProgress.asOutParam());
    818813
    819     return rc;
     814    return hrc;
    820815}
    821816
     
    28182813                                ComObjPtr<Progress> &progress)
    28192814{
    2820     HRESULT rc = S_OK;
    2821 
    2822     SetUpProgressMode mode;
    2823     if (locInfo.storageType == VFSType_File)
    2824         mode = ImportFile;
    2825     else if (locInfo.storageType == VFSType_Cloud)
    2826         mode = ImportCloud;
     2815    HRESULT rc;
     2816
     2817    /* Initialize our worker task */
     2818    ThreadTask *pTask;
     2819    if (locInfo.storageType != VFSType_Cloud)
     2820    {
     2821        rc = i_setUpProgress(progress, Utf8StrFmt(tr("Importing appliance '%s'"), locInfo.strPath.c_str()),
     2822                             locInfo.storageType == VFSType_File ? ImportFile : ImportS3);
     2823        if (FAILED(rc))
     2824            return setError(rc, tr("Failed to create task for importing appliance into VirtualBox"));
     2825        try
     2826        {
     2827            pTask = new TaskOVF(this, TaskOVF::Import, locInfo, progress);
     2828        }
     2829        catch (std::bad_alloc &)
     2830        {
     2831            return E_OUTOFMEMORY;
     2832        }
     2833    }
    28272834    else
    2828         mode = ImportS3;
    2829 
    2830     /* Initialize our worker task */
    2831     TaskOVF* ovfTask = NULL;
    2832     TaskCloud* cloudTask = NULL;
    2833     try
    2834     {
    2835         if (mode == ImportFile)
    2836         {
    2837             rc = i_setUpProgress(progress,
    2838                                  BstrFmt(tr("Importing appliance '%s'"), locInfo.strPath.c_str()),
    2839                                  mode);
    2840             if (FAILED(rc)) throw rc;
    2841 
    2842             ovfTask = new TaskOVF(this, TaskOVF::Import, locInfo, progress);
    2843             rc = ovfTask->createThread();
    2844         }
    2845         else if (mode == ImportCloud)
    2846         {
    2847             progress.createObject();
    2848             if (locInfo.strProvider.equals("OCI"))
    2849             {
    2850                 /*
    2851                  * 1. Create a custom image from the instance
    2852                  *  - 2 operations (starting and waiting)
    2853                  * 2. Import the custom image into the Object Storage (OCI format - TAR file with QCOW2 image and JSON file)
    2854                  *  - 2 operations (starting and waiting)
    2855                  * 3. Download the object from the Object Storage
    2856                  *  - 2 operations (starting and waiting)
    2857                  * 4. Open the object, extract QCOW2 image and convert one QCOW2->VDI
    2858                  *  - 1 operation (extracting and conversion are piped)
    2859                  * 5. Create VM with user settings and attach the converted image to VM
    2860                  *  - 1 operation.
    2861                  *  sum up = 2+2+2+1+1 = 8 op
    2862                 */
    2863 
    2864                 /*
    2865                  * See src/VBox/ExtPacks/Puel/OCI/OCICloudClient.h.
    2866                  * Weight of cloud import operations (1-3 items from above):
    2867                  * Total = 750 = 10+40+50+50+200x2+200.
    2868                  *
    2869                  * Weight of local import operations (4-5 items from above):
    2870                  * Total = 250 = 200 (extract and convert) + 50 (create VM, attach disks)
    2871                  */
    2872                 progress->init(mVirtualBox, static_cast<IAppliance*>(this),
    2873                              Bstr("Importing VM from Cloud...").raw(),
    2874                              TRUE /* aCancelable */,
    2875                              8, // ULONG cOperations,
    2876                              1000, // ULONG ulTotalOperationsWeight,
    2877                              Bstr("Importing VM from Cloud...").raw(), // aFirstOperationDescription
    2878                              10); // ULONG ulFirstOperationWeight
    2879             }
    2880             else
    2881                 return setErrorVrc(VBOX_E_NOT_SUPPORTED,
    2882                                    tr("Only \"OCI\" cloud provider is supported for now. \"%s\" isn't supported."),
    2883                                    locInfo.strProvider.c_str());
    2884 
    2885             cloudTask = new TaskCloud(this, TaskCloud::Import, locInfo, progress);
    2886             rc = cloudTask->createThread();
    2887             if (FAILED(rc)) throw rc;
    2888         }
    2889     }
    2890     catch (HRESULT aRc)
    2891     {
    2892         rc = aRc;
    2893     }
    2894     catch (...)
    2895     {
    2896         rc = setError(VBOX_E_OBJECT_NOT_FOUND,
    2897                             tr("Could not create a task object for importing appliance into VirtualBox"));
    2898     }
    2899 
    2900     if (FAILED(rc))
    2901     {
    2902         if (ovfTask)
    2903             delete ovfTask;
    2904         if (cloudTask)
    2905             delete cloudTask;
    2906         throw rc;
    2907     }
    2908 
    2909     return rc;
     2835    {
     2836        if (locInfo.strProvider.equals("OCI"))
     2837        {
     2838            /*
     2839             * 1. Create a custom image from the instance:
     2840             *    - 2 operations (starting and waiting)
     2841             * 2. Import the custom image into the Object Storage (OCI format - TAR file with QCOW2 image and JSON file):
     2842             *    - 2 operations (starting and waiting)
     2843             * 3. Download the object from the Object Storage:
     2844             *    - 2 operations (starting and waiting)
     2845             * 4. Open the object, extract QCOW2 image and convert one QCOW2->VDI:
     2846             *    - 1 operation (extracting and conversion are piped)
     2847             * 5. Create VM with user settings and attach the converted image to VM:
     2848             *    - 1 operation.
     2849             *
     2850             * Total: 2+2+2+1+1 = 8 operations
     2851             *
     2852             * See src/VBox/ExtPacks/Puel/OCI/OCICloudClient.h.
     2853             * Weight of cloud import operations (1-3 items from above):
     2854             * Total = 750 = 10+40+50+50+200x2+200.
     2855             *
     2856             * Weight of local import operations (4-5 items from above):
     2857             * Total = 250 = 200 (extract and convert) + 50 (create VM, attach disks)
     2858             */
     2859            try
     2860            {
     2861                rc = progress.createObject();
     2862                if (SUCCEEDED(rc))
     2863                    rc = progress->init(mVirtualBox, static_cast<IAppliance *>(this),
     2864                                        Utf8Str(tr("Importing VM from Cloud...")),
     2865                                        TRUE /* aCancelable */,
     2866                                        8, // ULONG cOperations,
     2867                                        1000, // ULONG ulTotalOperationsWeight,
     2868                                        Utf8Str(tr("Importing VM from Cloud...")), // aFirstOperationDescription
     2869                                        10); // ULONG ulFirstOperationWeight
     2870                if (SUCCEEDED(rc))
     2871                    pTask = new TaskCloud(this, TaskCloud::Import, locInfo, progress);
     2872                else
     2873                    pTask = NULL; /* shut up vcc */
     2874            }
     2875            catch (std::bad_alloc &)
     2876            {
     2877                return E_OUTOFMEMORY;
     2878            }
     2879            if (FAILED(rc))
     2880                return setError(rc, tr("Failed to create task for importing appliance into VirtualBox"));
     2881        }
     2882        else
     2883            return setError(E_NOTIMPL, tr("Only \"OCI\" cloud provider is supported for now. \"%s\" isn't supported."),
     2884                            locInfo.strProvider.c_str());
     2885    }
     2886
     2887    /*
     2888     * Start the task thread.
     2889     */
     2890    rc = pTask->createThread();
     2891    pTask = NULL;
     2892    if (SUCCEEDED(rc))
     2893        return rc;
     2894    return setError(rc, tr("Failed to start thread for importing appliance into VirtualBox"));
    29102895}
    29112896
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette