2016-12-01 71 views
0

我是Azure的新手,我正在嘗試在此處構建一個簡單的Azure批處理案例。Azure Batch Pool啓動任務從Blob下載資源文件FileShare

我在批池堆放啓動任務...

我創作了一批賬戶,並在美國東部的存儲帳戶,然後我創建了一個通用 - 文件共享在存儲帳戶與容器。我手動更新了一個名爲Test.txt的文件。

我想要做的就是要求批量池下載此文件在啓動任務。

所以代碼老話:

string storageConnectionString = String.Format("DefaultEndpointsProtocol=https;AccountName={0};AccountKey={1}", StorageAccountName, StorageAccountKey); 

// Retrieve the storage account 
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(storageConnectionString); 
CloudFileClient fileClient = storageAccount.CreateCloudFileClient(); 
SharedAccessFilePolicy fileShareConstraint = new SharedAccessFilePolicy 
{ 
    SharedAccessExpiryTime = DateTime.UtcNow.AddHours(48), 
    Permissions = SharedAccessFilePermissions.Read, 
}; 
var fileShare = fileClient.GetShareReference(inputContainerName); 
var rootDir = fileShare.GetRootDirectoryReference(); 
var testFile = rootDir.GetFileReference("test.txt"); 
var sasUrl = fileShare.GetSharedAccessSignature(fileShareConstraint); 
var fileUrl = string.Format("{0}{1}", testFile.StorageUri.PrimaryUri, sasUrl); 

var list = new List<ResourceFile>(); 
var testResourceFile = new ResourceFile(fileUrl, "test.txt"); 

list.Add(testResourceFile); 
await CreatePoolAsync(batchClient, PoolId, list); 

然後CreatePoolAsync方法:

private static async Task CreatePoolAsync(BatchClient batchClient, string poolId, IList<ResourceFile> resourceFiles) 
{ 

    Console.WriteLine("Creating pool [{0}]...", poolId); 

    // Create the unbound pool. Until we call CloudPool.Commit() or CommitAsync(), no pool is actually created in the 
    // Batch service. This CloudPool instance is therefore considered "unbound," and we can modify its properties. 

    //if(await batchClient.PoolOperations.GetPoolAsync(poolId) == null) 
    //{ 

    CloudPool pool = batchClient.PoolOperations.CreatePool(
     poolId: poolId, 
     targetDedicated: 1,               // 3 compute nodes 
     virtualMachineSize: "small",            // single-core, 1.75 GB memory, 225 GB disk 
     cloudServiceConfiguration: new CloudServiceConfiguration(osFamily: "4")); // Windows Server 2012 R2 
    pool.MaxTasksPerComputeNode = 2; 

    // Create and assign the StartTask that will be executed when compute nodes join the pool. 
    // In this case, we copy the StartTask's resource files (that will be automatically downloaded 
    // to the node by the StartTask) into the shared directory that all tasks will have access to. 
    pool.StartTask = new StartTask 
    { 
     // Specify a command line for the StartTask that copies the task application files to the 
     // node's shared directory. Every compute node in a Batch pool is configured with a number 
     // of pre-defined environment variables that can be referenced by commands or applications 
     // run by tasks. 

     // Since a successful execution of robocopy can return a non-zero exit code (e.g. 1 when one or 
     // more files were successfully copied) we need to manually exit with a 0 for Batch to recognize 
     // StartTask execution success. 

     CommandLine = "cmd /c (robocopy %AZ_BATCH_TASK_WORKING_DIR% %AZ_BATCH_NODE_SHARED_DIR%) ^& IF %ERRORLEVEL% LEQ 1 exit 0", 
     //CommandLine = "cmd /c net use E: \\krisblob2.file.core.windows.net\\krisfilecontiner1 /u:krisblob2 aqTFKyPqcpeI3BrEnlx8RTBAmDaN5FK+mxpBtdgn3v6IT+IbPgDhVU4ojRA1wAmMpYPEHQ9Gzh/A1mAHtxNs+A==", 
     //CommandLine = [email protected]"cmd /c net use Z: \\{StorageAccountName}.file.core.windows.net\krisfilecontiner1 /u:{StorageAccountName} {StorageAccountKey}", 
     //CommandLine = "cmd /c %AZ_BATCH_TASK_WORKING_DIR%\\WinPcap_4_1_3.exe /passive", 
     ResourceFiles = resourceFiles, 
     WaitForSuccess = true 
    }; 
}  

的inputcontainer是我給的文件共享容器名稱。

當我運行的代碼,啓動任務總是失敗,出現錯誤:

BlobDownloadMiscError消息

Miscellaneous error encountered while downloading one of the specified Azure Blob(s) Details   The value for one of the HTTP headers is not in the correct format. RequestId:944807de-001a-00bb-73ae-4ac746000000 Time:2016-11-30T02:04:59.8679984Z

誰能幫我解決這個問題呢?

謝謝!

+0

剛試過你的代碼,沒有遇到這個問題......你能告訴我哪一行拋出錯誤嗎? – forester123

+0

實際上,在Azure門戶池啓動任務信息中發現錯誤。基本上當Compute節點加入池時,並試圖下載我指定的資源文件。 –

+0

就是這樣,在創建和啓動節點後,我的一面也出現同樣的錯誤。我會檢查並稍後再回來。 – forester123

回答

0

Azure的批量resource files只能從Azure的Blob存儲,而不是Azure的文件存儲採購。

您需要net use上的共享,並手動將文件複製的文件或移動到Azure的Blob存儲來代替。

+0

看起來這是正確的!映射驅動器後,計算節點可以訪問它中的文件!非常感謝! –