Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Helloworld migration to net6 #303

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions CSharp/Common/Microsoft.Azure.Batch.Samples.Common.csproj
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net462</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Azure.Storage.Blobs" Version="12.10.0" />
<PackageReference Include="Microsoft.Azure.Batch" Version="14.0.0" />
<PackageReference Include="Microsoft.Azure.Batch.FileStaging" Version="8.3.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="2.1.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="2.1.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.1.0" />
<PackageReference Include="WindowsAzure.Storage" Version="9.3.3" />

</ItemGroup>
<ItemGroup>
<None Update="accountsettings.json">
Expand Down
1 change: 1 addition & 0 deletions CSharp/Common/SampleHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ public static string GetFailureInfoDetails(TaskFailureInformation failureInfo)
return builder.ToString();
}


public static AccountSettings LoadAccountSettings()
{
AccountSettings accountSettings = new ConfigurationBuilder()
Expand Down
9 changes: 1 addition & 8 deletions CSharp/Common/accountsettings.json
Original file line number Diff line number Diff line change
@@ -1,8 +1 @@
{
"batchAccountName": "",
"batchAccountKey": "",
"batchServiceUrl": "",
"storageAccountName": "",
"storageAccountKey": "",
"storageServiceUrl": "core.windows.net"
}

10 changes: 5 additions & 5 deletions CSharp/GettingStarted/01_HelloWorld/HelloWorld.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net462</TargetFramework>
<TargetFramework>net60</TargetFramework>
<RootNamespace>Microsoft.Azure.Batch.Samples.HelloWorld</RootNamespace>
</PropertyGroup>

Expand All @@ -11,10 +11,10 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Azure.Batch" Version="14.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="2.1.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.1.0" />
<PackageReference Include="WindowsAzure.Storage" Version="9.3.3" />
<PackageReference Include="Azure.Storage.Blobs" Version="12.10.0" />
<PackageReference Include="Microsoft.Azure.Batch" Version="15.1.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="6.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
6 changes: 3 additions & 3 deletions CSharp/GettingStarted/01_HelloWorld/settings.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"poolTargetNodeCount": 2,
"poolNodeVirtualMachineSize": "standard_d1_v2",
"poolTargetNodeCount": 1,
"poolNodeVirtualMachineSize": "Standard_A4_v2",
"poolOSFamily": "5",
"poolId": "HelloWorld-Pool",
"shouldDeleteJob": true
"shouldDeleteJob": true
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,14 @@ public class JobSubmitter
private readonly Settings poolsAndResourceFileSettings;
private readonly AccountSettings accountSettings;

private const string exeFile = "SampleExe.exe";

// The SimpleTask project is included via project-depedency, so the
// executable produced by that project will be in the same working
// directory as JobSubmitter at runtime.
private const string SimpleTaskExe = "SimpleTask.exe";
private string ExecutableFile = Path.Combine(@"C:\dev\git\azure-batch\azure-batch-samples\CSharp\GettingStarted\Shared\SimpleTask\bin\Release\net60\publish", exeFile);

private string TaskCommand = $"{exeFile} --arg 42";

public JobSubmitter()
{
Expand Down Expand Up @@ -139,7 +143,7 @@ private async Task CreatePoolIfNotExistAsync(BatchClient batchClient, CloudStora
// Create a new start task to facilitate pool-wide file management or installation.
// In this case, we just add a single dummy data file to the StartTask.
string localSampleFilePath = GettingStartedCommon.GenerateTemporaryFile("StartTask.txt", "hello from Batch PoolsAndResourceFiles sample!");
List<string> files = new List<string> { localSampleFilePath };
List<string> files = new List<string> { localSampleFilePath, ExecutableFile };

List<ResourceFile> resourceFiles = await SampleHelpers.UploadResourcesAndCreateResourceFileReferencesAsync(
cloudStorageAccount,
Expand Down Expand Up @@ -169,15 +173,15 @@ private async Task<HashSet<string>> SubmitJobAsync(BatchClient batchClient, Clou
CloudJob unboundJob = batchClient.JobOperations.CreateJob();
unboundJob.Id = jobId;
unboundJob.PoolInformation = new PoolInformation() { PoolId = this.poolsAndResourceFileSettings.PoolId };

// Commit Job to create it in the service
await unboundJob.CommitAsync();

List<CloudTask> tasksToRun = new List<CloudTask>();

// Create a task which requires some resource files
CloudTask taskWithFiles = new CloudTask("task_with_file1", SimpleTaskExe);

CloudTask taskWithFiles = new CloudTask("task_with_file1", TaskCommand);
// Set up a collection of files to be staged -- these files will be uploaded to Azure Storage
// when the tasks are submitted to the Azure Batch service.
taskWithFiles.FilesToStage = new List<IFileStagingProvider>();
Expand All @@ -194,7 +198,7 @@ private async Task<HashSet<string>> SubmitJobAsync(BatchClient batchClient, Clou
// add the files as a task dependency so they will be uploaded to storage before the task
// is submitted and downloaded to the node before the task starts execution.
FileToStage helloWorldFile = new FileToStage(localSampleFile, fileStagingStorageAccount);
FileToStage simpleTaskFile = new FileToStage(SimpleTaskExe, fileStagingStorageAccount);
FileToStage simpleTaskFile = new FileToStage(ExecutableFile, fileStagingStorageAccount);

// When this task is added via JobOperations.AddTaskAsync below, the FilesToStage are uploaded to storage once.
// The Batch service does not automatically delete content from your storage account, so files added in this
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net462</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<RootNamespace>Microsoft.Azure.Batch.Samples.PoolsAndResourceFiles</RootNamespace>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"poolTargetNodeCount": 2,
"poolNodeVirtualMachineSize": "standard_d1_v2",
"poolTargetNodeCount": 1,
"poolNodeVirtualMachineSize": "Standard_A4_v2",
"poolOSFamily": "5",
"poolId": "PoolsAndResourceFilesPool",
"shouldDeleteJob": true,
Expand Down
8 changes: 8 additions & 0 deletions CSharp/GettingStarted/Shared/SimpleTask/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ public static void Main(string[] args)
{
Console.WriteLine("Found a file: {0}", file);
}

foreach (var file in Directory.EnumerateDirectories("Z:\\"))
{
Console.WriteLine("Found a file: {0}", file);
}

Console.WriteLine($"Started with arg: {args[0]}");

}
}
}
6 changes: 5 additions & 1 deletion CSharp/GettingStarted/Shared/SimpleTask/SimpleTask.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net462</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<RootNamespace>Microsoft.Azure.Batch.Samples.SimpleTask</RootNamespace>
</PropertyGroup>

<ItemGroup>
<Folder Include="Properties\PublishProfiles\" />
</ItemGroup>

</Project>