Azure Batch refuses to run docker tasks on docker supporting nodes - azure

I have an Azure Batch pool with nodes supporting Docker.
That is, the OS offer is MicrosoftWindowsServer WindowsServer 2016-Datacenter-with-Containers.
I create a task as recommended:
private static CloudTask CreateTask(string id, string commandLine)
{
var autoUserSpec = new AutoUserSpecification(elevationLevel: ElevationLevel.Admin);
var containerSettings = new TaskContainerSettings(_imageName);
var task = new CloudTask(id, commandLine)
{
UserIdentity = new UserIdentity(autoUserSpec),
ContainerSettings = containerSettings,
};
return task;
}
When the task is run, it completes with the error ContainerPoolNotSupported, The compute node does not support container feature.
This does not make sense. When I connect to the node, I see docker there, the image is preinstalled so I can even run the container right away. The task finishes nearly immediately so likely Azure Batch just notices the container settings and for some reason throws.
Are there any workarounds? Google offers 0 references for the error name.

Without the context of how you created the pool, this answer is not definitive. But most likely you did not specify the ContainerConfiguration on VirtualMachineConfiguration of the CloudPool object.
Please see this guide for a tutorial on running container workloads on Azure Batch.

What helped was to disregard TaskContainerSettings altogether, that is to imitate an ordinary CloudTask yet to have docker run in the task command line:
private static CloudTask CreateTask(string id, string commandLine)
{
var autoUserSpec = new AutoUserSpecification(elevationLevel: ElevationLevel.Admin);
var task = new CloudTask(id, $"docker run {_imageName} {commandLine}")
{
UserIdentity = new UserIdentity(autoUserSpec),
};
return task;
}
So this is truly a workaround until the support of containers becomes more stable in Azure.

Related

Submitting data from Xamarin iOS when backgrounded

I have a weird problem in our current Xamarin project. As the app sends a larger chunk of data to the server, to protect it when app gets backgrounded, we're starting a long-running task (using the UIApplication.SharedApplication.BeginBackgroundTask / UIApplication.SharedApplication.EndBackgroundTask API). What's weird is that this works great when I build and run from my machine but several of my colleagues get a timeout error when running the exact same scenario when the app was build/deployed from their machines.
As far as I understand it running stuff in a long-running task like this should work. I should not have to specify backgrounding capabilities in info.plist. Also, as the HttpClient employ NSUrlSession for sending/receiving it should be protected from interruptions when the app gets backgrounded, right?
I can't figure out why the same code yields different behavior on the same device when built with different Macs. Could there be some setting somewhere in VS that could be local to the machine that would affect this behavior?
I'm out of ideas now so any hints would be greatly appreciated.
This is an example of code that works/fails depending on the Mac that built/deployed it:
public async Task Submit()
{
// ... some irrelevant code
BackgroundTask.Run(async () => await submitAsync()); // Form-level encapsulation of the UIApplication.SharedApplication.BeginBackgroundTask API
// ... more irrelevant code
}
private async Task submitAsync()
{
if (!IsSubmitAllowed)
return;
IsBusy = true;
IsGoBackAllowed = IsGoNextAllowed = false;
var statusIndicator = new StatusIndicator();
await PopupNavigation.Instance.PushAsync(statusIndicator);
try
{
statusIndicator.Status = "Saving TI";
statusIndicator.Progress = 0.1;
var submitted = await _service.SubmitAsync(Model); // ERROR! causes timeout exception for some
var submittedId = submitted.BackendId;
// ... etc.
Both of your assumptions seem to be wrong.
First, beginBackgroundTaskWithExpirationHandler: doesn't grant unlimited background activity. Most notably:
https://developer.apple.com/documentation/uikit/uiapplication/1623031-beginbackgroundtaskwithexpiratio?language=objc
Apps running background tasks have a finite amount of time in which to
run them
Second, NSURLSession isn't enabled by default in the HttpClient, and overal NSURLSession is not something that handles transfers in the background by default, that is just possibility and it would be natural that HttpClient doesn't use this mode. Again check the documentation: https://developer.apple.com/documentation/foundation/nsurlsession

Task failure and Exit code -532462766 in Azure Batch

I am trying to run a Console Application in Azure Batch. I have created the Client Application having responsibility of creating and running Job & Tasks in the Azure Batch so far. My ClientApplication successfully creates a Job, a Task within the Job but when the application code uploaded on the AzureStorage get executed in Azure the Pool, the Task fails and exits with an Exit code -532462766. I could not find any information for this exit code. Please help me to fix this.
Here is my code for creating the task and it's configuration
private static async Task<List<CloudTask>> AddTasksAsync(BatchClient batchClient, string jobId)
{
Console.WriteLine("Adding {0} tasks to job [{1}]...", 1, jobId);
List<CloudTask> tasks = new List<CloudTask>();
string taskId = "topNtask";
string taskCommandLine = String.Format("cmd /c %AZ_BATCH_NODE_SHARED_DIR%\\SelfHostedWebAPI.exe {0} {1} {2}", 11109, "MSS_F_MST_______", "Normal");
//string taskCommandLine = String.Format("cmd /c %AZ_BATCH_NODE_SHARED_DIR%\\SelfHostedWebAPI.exe");
CloudTask task = new CloudTask(taskId, taskCommandLine);
tasks.Add(task);
await batchClient.JobOperations.AddTaskAsync(jobId, tasks);
return tasks;
}
And the task failure report from my Azure Portal
Corresponding hex value for -532462766 is 0xE0434352; more information about this error code/exception can be found on this SO post. Common culprits are missing assemblies (see the Assembly Binding Log Viewer). Additionally, the Windows Event Viewer might be able to provide you with more information prior to having to resort to WinDbg and SOS.
Finally I got the solution of this problem and to save one's precious time here is the solution.
We need to upload each and every .dll files and dependencies of our code that run in Azure Pool to the linked AzureStorage account. In addition, when the pool is being created and it's StartTask is initialized, a ResourceFile with SAS(Shared Access Signature, for the target .dll that it points) for every .dll file or any other type, should be given to it as a parameter.

Azure Batch microtask parallel processing (Modify Task Queue)

I am trying to parallelise micro-tasks that will be fired off on one of the VMs and should get parallelised on all the VMs. How can I modify the Azure Batch queue. Is there any way to add a task to the queue through the API?
Is there any way to add a task to the queue through the API?
If you use Azure Batch .NET Library, you could add a task to a job using following code.
private static async Task<List<CloudTask>> AddTasksAsync(
BatchClient batchClient,
string jobId,
string taskId,
List<ResourceFile> inputFiles,
string taskCommand)
{
// Create a collection to hold the tasks that we'll be adding to the job
List<CloudTask> tasks = new List<CloudTask>();
CloudTask task = new CloudTask(taskId, taskCommand);
task.ResourceFiles = inputFiles;
tasks.Add(task);
await batchClient.JobOperations.AddTaskAsync(jobId, tasks);
return tasks;
}
If you want to use REST API, link below is for your reference.
Add a task to a job
If you encounter any problem when using the APIs above, please feel free to let me know.

Why does my continuous azure webjob run the function twice?

I have created my first azure webjob that runs continously;
I'm not so sure this is a code issue, but for the sake of completeness here is my code:
static void Main()
{
var host = new JobHost();
host.CallAsync(typeof(Functions).GetMethod("ProcessMethod"));
host.RunAndBlock();
}
And for the function:
[NoAutomaticTrigger]
public static async Task ProcessMethod(TextWriter log)
{
log.WriteLine(DateTime.UtcNow.ToShortTimeString() + ": Started");
while (true)
{
Task.Run(() => RunAllAsync(log));
await Task.Delay(TimeSpan.FromSeconds(60));
}
log.WriteLine(DateTime.UtcNow.ToShortTimeString() + "Shutting down..");
}
Note that the async task fires off a task of its own. This was to ensure they were started quite accurately with the same interval. The job itself is to download an url, parse and input some data in a db, but that shouldnt be relevant for the multiple instance issue I am experiencing.
My problem is that once this has been running for roughly 5 minutes a second ProcessMethod is called which makes me have two sessions simoultaniously doing the same thing. The second method says it is "started from Dashboard" even though I am 100% confident I did not click anything to start it off myself.
Anyone experienced anything like it?
Change the instance count to 1 from Scale tab of WebApp in Azure portal. By default it is set to 2 instances which is causing it to run two times.
I can't explain why it's getting called twice, but I think you'd be better served with a triggered job using a CRON schedule (https://azure.microsoft.com/en-us/documentation/articles/web-sites-create-web-jobs/#CreateScheduledCRON), instead of a Continuous WebJob.
Also, it doesn't seem like you are using the WebJobs SDK, so you can completely skip that. Your WebJob can be as simple as a Main that directly does the work. No JobHost, no async, and generally easier to get right.

How to run webjobs in azure emulator

I have a console based application as WebJob. Now internally i am trying to map a CloudDrive using the storageconnectionstring UseDevelopmentStorage=true
It is throwing exception ERROR_AZURE_DRIVE_DEV_PATH_NOT_SET. I searched for this error and found that WebJobs do not run locally in Azure emulator. Is this information still valid?
Is there any plan to provide emulator (storage) support for webjobs in near future say in a week or so?
thanks
The information is still valid - we don't support the Azure emulator.
We have that work item on our backlog but I cannot give you any ETA.
Boo hoo Microsoft... This seems rather stupid given that you want us to start adopting the use of Azure Web Jobs!
There are new few lines of code in current version, which I believe solves this issue
static void Main()
{
var config = new JobHostConfiguration();
if (config.IsDevelopment)
{
config.UseDevelopmentSettings();
}
var host = new JobHost();
// The following code ensures that the WebJob will be running continuously
host.RunAndBlock();
}

Resources