From f063036f139170ebfa093907fbe55cc1a263263d Mon Sep 17 00:00:00 2001 From: Manish Sharma Date: Wed, 27 Feb 2019 12:55:22 +0530 Subject: [PATCH 01/22] adding preptask sample --- Python/Batch/sample4_preparationtask.cfg | 4 + Python/Batch/sample4_preparationtask.py | 129 +++++++++++++++++++++++ 2 files changed, 133 insertions(+) create mode 100644 Python/Batch/sample4_preparationtask.cfg create mode 100644 Python/Batch/sample4_preparationtask.py diff --git a/Python/Batch/sample4_preparationtask.cfg b/Python/Batch/sample4_preparationtask.cfg new file mode 100644 index 00000000..538e6a8b --- /dev/null +++ b/Python/Batch/sample4_preparationtask.cfg @@ -0,0 +1,4 @@ +[DEFAULT] +shoulddeletejob=true +poolvmsize=small +poolvmcount=1 \ No newline at end of file diff --git a/Python/Batch/sample4_preparationtask.py b/Python/Batch/sample4_preparationtask.py new file mode 100644 index 00000000..ca85f7a2 --- /dev/null +++ b/Python/Batch/sample4_preparationtask.py @@ -0,0 +1,129 @@ +# sample5_preparationtask.py Code Sample + +from __future__ import print_function +try: + import configparser +except ImportError: + import ConfigParser as configparser +import datetime +import os + +import azure.batch.batch_service_client as batch +import azure.batch.batch_auth as batchauth +import azure.batch.models as batchmodels + +import common.helpers + + + + +preptaskcommand = 'cmd /c set' + + +def submit_job_and_add_task(batch_client, job_id, vm_size, vm_count): + """Submits a job to the Azure Batch service and adds a simple task with preparation task + + :param batch_client: The batch client to use. + :type batch_client: `batchserviceclient.BatchServiceClient` + :param str job_id: The id of the job to create. + """ + + pool_info = batchmodels.PoolInformation( + auto_pool_specification=batchmodels.AutoPoolSpecification( + auto_pool_id_prefix="Helloworld_jobprep", + pool=batchmodels.PoolSpecification( + vm_size=vm_size, + target_dedicated_nodes=vm_count, + cloud_service_configuration={'os_family': "4"}), + keep_alive=False, + pool_lifetime_option=batchmodels.PoolLifetimeOption.job)) + + job = batchmodels.JobAddParameter( + id=job_id, + pool_info=pool_info, + job_preparation_task=batch.models.JobPreparationTask( + command_line= preptaskcommand, + wait_for_success=True + ) + ) + + batch_client.job.add(job) + + task = batchmodels.TaskAddParameter( + id="HelloWorld_Task", + command_line=common.helpers.wrap_commands_in_shell( + 'windows', ['echo Hello world from the Batch Hello world sample!']) + ) + + batch_client.task.add(job_id=job.id, task=task) + + +def execute_sample(global_config, sample_config): + """Executes the sample with the specified configurations. + + :param global_config: The global configuration to use. + :type global_config: `configparser.ConfigParser` + :param sample_config: The sample specific configuration to use. + :type sample_config: `configparser.ConfigParser` + """ + # Set up the configuration + batch_account_key = global_config.get('Batch', 'batchaccountkey') + batch_account_name = global_config.get('Batch', 'batchaccountname') + batch_service_url = global_config.get('Batch', 'batchserviceurl') + + should_delete_job = sample_config.getboolean( + 'DEFAULT', + 'shoulddeletejob') + pool_vm_size = sample_config.get( + 'DEFAULT', + 'poolvmsize') + pool_vm_count = sample_config.getint( + 'DEFAULT', + 'poolvmcount') + + # Print the settings we are running with + common.helpers.print_configuration(global_config) + common.helpers.print_configuration(sample_config) + + credentials = batchauth.SharedKeyCredentials( + batch_account_name, + batch_account_key) + + batch_client = batch.BatchServiceClient( + credentials, + base_url=batch_service_url) + + # Retry 5 times -- default is 3 + batch_client.config.retry_policy.retries = 5 + job_id = common.helpers.generate_unique_resource_name("HelloWorldwithJobpreparationtask") + + try: + submit_job_and_add_task( + batch_client, + job_id, + pool_vm_size, + pool_vm_count) + + common.helpers.wait_for_tasks_to_complete( + batch_client, + job_id, + datetime.timedelta(minutes=25)) + + tasks = batch_client.task.list(job_id) + task_ids = [task.id for task in tasks] + + common.helpers.print_task_output(batch_client, job_id, task_ids) + finally: + if should_delete_job: + print("Deleting job: ", job_id) + batch_client.job.delete(job_id) + + +if __name__ == '__main__': + global_config = configparser.ConfigParser() + global_config.read(common.helpers._SAMPLES_CONFIG_FILE_NAME) + + sample_config = configparser.ConfigParser() + sample_config.read(os.path.splitext(os.path.basename(__file__))[0] + '.cfg') + + execute_sample(global_config, sample_config) From 4158e9a1be4209a805071333b16819adbb1bb5ee Mon Sep 17 00:00:00 2001 From: Manish Sharma Date: Wed, 27 Feb 2019 13:07:01 +0530 Subject: [PATCH 02/22] adding preptask sample --- Python/Batch/sample4_preparationtask.py | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/Python/Batch/sample4_preparationtask.py b/Python/Batch/sample4_preparationtask.py index ca85f7a2..25d3fd3e 100644 --- a/Python/Batch/sample4_preparationtask.py +++ b/Python/Batch/sample4_preparationtask.py @@ -14,15 +14,11 @@ import common.helpers - - - preptaskcommand = 'cmd /c set' - def submit_job_and_add_task(batch_client, job_id, vm_size, vm_count): - """Submits a job to the Azure Batch service and adds a simple task with preparation task - + """Submits a job to the Azure Batch service + and adds a simple task with preparation task :param batch_client: The batch client to use. :type batch_client: `batchserviceclient.BatchServiceClient` :param str job_id: The id of the job to create. @@ -41,10 +37,7 @@ def submit_job_and_add_task(batch_client, job_id, vm_size, vm_count): job = batchmodels.JobAddParameter( id=job_id, pool_info=pool_info, - job_preparation_task=batch.models.JobPreparationTask( - command_line= preptaskcommand, - wait_for_success=True - ) + job_preparation_task=batch.models.JobPreparationTask(command_line= preptaskcommand, wait_for_success=True ) ) batch_client.job.add(job) From 709d3015c86767b2e64b06afdd623fd237b74063 Mon Sep 17 00:00:00 2001 From: Manish Sharma Date: Wed, 27 Feb 2019 13:13:35 +0530 Subject: [PATCH 03/22] adding preptask sample --- Python/Batch/sample4_preparationtask.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Python/Batch/sample4_preparationtask.py b/Python/Batch/sample4_preparationtask.py index 25d3fd3e..445af39f 100644 --- a/Python/Batch/sample4_preparationtask.py +++ b/Python/Batch/sample4_preparationtask.py @@ -37,8 +37,10 @@ def submit_job_and_add_task(batch_client, job_id, vm_size, vm_count): job = batchmodels.JobAddParameter( id=job_id, pool_info=pool_info, - job_preparation_task=batch.models.JobPreparationTask(command_line= preptaskcommand, wait_for_success=True ) - ) + job_preparation_task=batch.models.JobPreparationTask( + command_line= preptaskcommand, + wait_for_success=True) + ) batch_client.job.add(job) @@ -88,7 +90,7 @@ def execute_sample(global_config, sample_config): # Retry 5 times -- default is 3 batch_client.config.retry_policy.retries = 5 - job_id = common.helpers.generate_unique_resource_name("HelloWorldwithJobpreparationtask") + job_id = common.helpers.generate_unique_resource_name("samplePrepJob") try: submit_job_and_add_task( From 0742d87872638ad9b61b208063dd1c2e8b27b939 Mon Sep 17 00:00:00 2001 From: Manish Sharma Date: Wed, 27 Feb 2019 13:27:06 +0530 Subject: [PATCH 04/22] adding preptask sample --- Python/Batch/sample4_preparationtask.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/Python/Batch/sample4_preparationtask.py b/Python/Batch/sample4_preparationtask.py index 445af39f..e42027ce 100644 --- a/Python/Batch/sample4_preparationtask.py +++ b/Python/Batch/sample4_preparationtask.py @@ -16,8 +16,9 @@ preptaskcommand = 'cmd /c set' + def submit_job_and_add_task(batch_client, job_id, vm_size, vm_count): - """Submits a job to the Azure Batch service + """Submits a job to the Azure Batch service and adds a simple task with preparation task :param batch_client: The batch client to use. :type batch_client: `batchserviceclient.BatchServiceClient` @@ -34,10 +35,7 @@ def submit_job_and_add_task(batch_client, job_id, vm_size, vm_count): keep_alive=False, pool_lifetime_option=batchmodels.PoolLifetimeOption.job)) - job = batchmodels.JobAddParameter( - id=job_id, - pool_info=pool_info, - job_preparation_task=batch.models.JobPreparationTask( + job = batchmodels.JobAddParameter(id=job_id, pool_info=pool_info, job_preparation_task=batch.models.JobPreparationTask( command_line= preptaskcommand, wait_for_success=True) ) From 4aa8c4d6f64ab5b47681e3a7ff163811054d1703 Mon Sep 17 00:00:00 2001 From: Manish Sharma Date: Wed, 27 Feb 2019 14:51:04 +0530 Subject: [PATCH 05/22] adding preptask sample --- Python/Batch/configuration.cfg | 10 +++++----- Python/Batch/sample4_preparationtask.py | 7 ++++--- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/Python/Batch/configuration.cfg b/Python/Batch/configuration.cfg index 0596775f..c852c43a 100644 --- a/Python/Batch/configuration.cfg +++ b/Python/Batch/configuration.cfg @@ -1,9 +1,9 @@ [Batch] -batchaccountname= -batchaccountkey= -batchserviceurl= +batchaccountname=batchwz2xljmm53wrq +batchaccountkey=CM3GV1oj+KFcM2EGHUdHC7zB0Z8Y70342PluVQknzrrPQUHkecodhWC8lErSaEMn3DYGb6pTn8jOAtlVNqBPwg== +batchserviceurl=https://batchwz2xljmm53wrq.southeastasia.batch.azure.com [Storage] -storageaccountname= -storageaccountkey= +storageaccountname=storagewz2xljmm53wrq +storageaccountkey=KoZrUsp+4jxIfvecohbXs/JJh3/dsGa1Ea8Fd+io9aPpynboasJNvQzdMYX2Hb9Ho3p6prcS7q4lwJAdJycK1A== storageaccountsuffix=core.windows.net diff --git a/Python/Batch/sample4_preparationtask.py b/Python/Batch/sample4_preparationtask.py index e42027ce..b79de63d 100644 --- a/Python/Batch/sample4_preparationtask.py +++ b/Python/Batch/sample4_preparationtask.py @@ -14,8 +14,6 @@ import common.helpers -preptaskcommand = 'cmd /c set' - def submit_job_and_add_task(batch_client, job_id, vm_size, vm_count): """Submits a job to the Azure Batch service @@ -35,6 +33,8 @@ def submit_job_and_add_task(batch_client, job_id, vm_size, vm_count): keep_alive=False, pool_lifetime_option=batchmodels.PoolLifetimeOption.job)) + preptaskcommand = 'cmd /c set' + job = batchmodels.JobAddParameter(id=job_id, pool_info=pool_info, job_preparation_task=batch.models.JobPreparationTask( command_line= preptaskcommand, wait_for_success=True) @@ -117,6 +117,7 @@ def execute_sample(global_config, sample_config): global_config.read(common.helpers._SAMPLES_CONFIG_FILE_NAME) sample_config = configparser.ConfigParser() - sample_config.read(os.path.splitext(os.path.basename(__file__))[0] + '.cfg') + sample_config.read( + os.path.splitext(os.path.basename(__file__))[0] + '.cfg') execute_sample(global_config, sample_config) From 845e70b45c3c9f5615e9d5bb2990e6a0847fdebf Mon Sep 17 00:00:00 2001 From: Manish Sharma Date: Wed, 27 Feb 2019 14:55:08 +0530 Subject: [PATCH 06/22] removing config changes --- Python/Batch/configuration.cfg | 10 +++++----- Python/Batch/sample4_preparationtask.py | 7 +++---- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/Python/Batch/configuration.cfg b/Python/Batch/configuration.cfg index c852c43a..0596775f 100644 --- a/Python/Batch/configuration.cfg +++ b/Python/Batch/configuration.cfg @@ -1,9 +1,9 @@ [Batch] -batchaccountname=batchwz2xljmm53wrq -batchaccountkey=CM3GV1oj+KFcM2EGHUdHC7zB0Z8Y70342PluVQknzrrPQUHkecodhWC8lErSaEMn3DYGb6pTn8jOAtlVNqBPwg== -batchserviceurl=https://batchwz2xljmm53wrq.southeastasia.batch.azure.com +batchaccountname= +batchaccountkey= +batchserviceurl= [Storage] -storageaccountname=storagewz2xljmm53wrq -storageaccountkey=KoZrUsp+4jxIfvecohbXs/JJh3/dsGa1Ea8Fd+io9aPpynboasJNvQzdMYX2Hb9Ho3p6prcS7q4lwJAdJycK1A== +storageaccountname= +storageaccountkey= storageaccountsuffix=core.windows.net diff --git a/Python/Batch/sample4_preparationtask.py b/Python/Batch/sample4_preparationtask.py index b79de63d..e42027ce 100644 --- a/Python/Batch/sample4_preparationtask.py +++ b/Python/Batch/sample4_preparationtask.py @@ -14,6 +14,8 @@ import common.helpers +preptaskcommand = 'cmd /c set' + def submit_job_and_add_task(batch_client, job_id, vm_size, vm_count): """Submits a job to the Azure Batch service @@ -33,8 +35,6 @@ def submit_job_and_add_task(batch_client, job_id, vm_size, vm_count): keep_alive=False, pool_lifetime_option=batchmodels.PoolLifetimeOption.job)) - preptaskcommand = 'cmd /c set' - job = batchmodels.JobAddParameter(id=job_id, pool_info=pool_info, job_preparation_task=batch.models.JobPreparationTask( command_line= preptaskcommand, wait_for_success=True) @@ -117,7 +117,6 @@ def execute_sample(global_config, sample_config): global_config.read(common.helpers._SAMPLES_CONFIG_FILE_NAME) sample_config = configparser.ConfigParser() - sample_config.read( - os.path.splitext(os.path.basename(__file__))[0] + '.cfg') + sample_config.read(os.path.splitext(os.path.basename(__file__))[0] + '.cfg') execute_sample(global_config, sample_config) From 01d0e1d7a11a77c4dbeb9299e440799730120270 Mon Sep 17 00:00:00 2001 From: Manish Sharma Date: Wed, 27 Feb 2019 15:03:17 +0530 Subject: [PATCH 07/22] removing config changes --- Python/Batch/sample4_preparationtask.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Python/Batch/sample4_preparationtask.py b/Python/Batch/sample4_preparationtask.py index e42027ce..4a5487e9 100644 --- a/Python/Batch/sample4_preparationtask.py +++ b/Python/Batch/sample4_preparationtask.py @@ -35,7 +35,8 @@ def submit_job_and_add_task(batch_client, job_id, vm_size, vm_count): keep_alive=False, pool_lifetime_option=batchmodels.PoolLifetimeOption.job)) - job = batchmodels.JobAddParameter(id=job_id, pool_info=pool_info, job_preparation_task=batch.models.JobPreparationTask( + job = batchmodels.JobAddParameter(id=job_id, pool_info=pool_info, + job_preparation_task=batch.models.JobPreparationTask( command_line= preptaskcommand, wait_for_success=True) ) From 38fe86ef8951976942ab9d4f0cf7095881945efc Mon Sep 17 00:00:00 2001 From: Manish Sharma Date: Wed, 27 Feb 2019 15:07:37 +0530 Subject: [PATCH 08/22] removing config changes --- Python/Batch/sample4_preparationtask.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Python/Batch/sample4_preparationtask.py b/Python/Batch/sample4_preparationtask.py index 4a5487e9..a19c24e2 100644 --- a/Python/Batch/sample4_preparationtask.py +++ b/Python/Batch/sample4_preparationtask.py @@ -35,10 +35,10 @@ def submit_job_and_add_task(batch_client, job_id, vm_size, vm_count): keep_alive=False, pool_lifetime_option=batchmodels.PoolLifetimeOption.job)) - job = batchmodels.JobAddParameter(id=job_id, pool_info=pool_info, + job = batchmodels.JobAddParameter(id=job_id, pool_info=pool_info, job_preparation_task=batch.models.JobPreparationTask( - command_line= preptaskcommand, - wait_for_success=True) + command_line= preptaskcommand, + wait_for_success=True) ) batch_client.job.add(job) From 90e96f47a789dbf83708c573907e270505f55661 Mon Sep 17 00:00:00 2001 From: Manish Sharma Date: Wed, 27 Feb 2019 15:13:20 +0530 Subject: [PATCH 09/22] removing config changes --- Python/Batch/sample4_preparationtask.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Python/Batch/sample4_preparationtask.py b/Python/Batch/sample4_preparationtask.py index a19c24e2..6459a127 100644 --- a/Python/Batch/sample4_preparationtask.py +++ b/Python/Batch/sample4_preparationtask.py @@ -36,9 +36,9 @@ def submit_job_and_add_task(batch_client, job_id, vm_size, vm_count): pool_lifetime_option=batchmodels.PoolLifetimeOption.job)) job = batchmodels.JobAddParameter(id=job_id, pool_info=pool_info, - job_preparation_task=batch.models.JobPreparationTask( - command_line= preptaskcommand, - wait_for_success=True) + job_preparation_task=batch.models.JobPreparationTask( + command_line= preptaskcommand, + wait_for_success=True) ) batch_client.job.add(job) @@ -118,6 +118,7 @@ def execute_sample(global_config, sample_config): global_config.read(common.helpers._SAMPLES_CONFIG_FILE_NAME) sample_config = configparser.ConfigParser() - sample_config.read(os.path.splitext(os.path.basename(__file__))[0] + '.cfg') + sample_config.read( + os.path.splitext(os.path.basename(__file__))[0] + '.cfg') execute_sample(global_config, sample_config) From d2cbff625827e0421be5391e60c7e0b0205e0a70 Mon Sep 17 00:00:00 2001 From: Manish Sharma Date: Wed, 27 Feb 2019 15:19:02 +0530 Subject: [PATCH 10/22] removing config changes --- Python/Batch/sample4_preparationtask.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Python/Batch/sample4_preparationtask.py b/Python/Batch/sample4_preparationtask.py index 6459a127..1a42c17b 100644 --- a/Python/Batch/sample4_preparationtask.py +++ b/Python/Batch/sample4_preparationtask.py @@ -37,7 +37,7 @@ def submit_job_and_add_task(batch_client, job_id, vm_size, vm_count): job = batchmodels.JobAddParameter(id=job_id, pool_info=pool_info, job_preparation_task=batch.models.JobPreparationTask( - command_line= preptaskcommand, + command_line=preptaskcommand, wait_for_success=True) ) From 2a23022f5b9ea77496c9b2f1a21985871365ebae Mon Sep 17 00:00:00 2001 From: Manish Sharma Date: Wed, 27 Feb 2019 16:10:15 +0530 Subject: [PATCH 11/22] removing config changes --- Python/Batch/sample4_preparationtask.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Python/Batch/sample4_preparationtask.py b/Python/Batch/sample4_preparationtask.py index 1a42c17b..417f25b1 100644 --- a/Python/Batch/sample4_preparationtask.py +++ b/Python/Batch/sample4_preparationtask.py @@ -37,7 +37,7 @@ def submit_job_and_add_task(batch_client, job_id, vm_size, vm_count): job = batchmodels.JobAddParameter(id=job_id, pool_info=pool_info, job_preparation_task=batch.models.JobPreparationTask( - command_line=preptaskcommand, + command_line=preptaskcommand, wait_for_success=True) ) From 6f02b877f2888f4715a7f5eb4fcddfe8baef12d0 Mon Sep 17 00:00:00 2001 From: Manish Sharma Date: Wed, 27 Feb 2019 16:23:21 +0530 Subject: [PATCH 12/22] removing config changes --- Python/Batch/sample4_preparationtask.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Python/Batch/sample4_preparationtask.py b/Python/Batch/sample4_preparationtask.py index 417f25b1..bd108865 100644 --- a/Python/Batch/sample4_preparationtask.py +++ b/Python/Batch/sample4_preparationtask.py @@ -37,8 +37,8 @@ def submit_job_and_add_task(batch_client, job_id, vm_size, vm_count): job = batchmodels.JobAddParameter(id=job_id, pool_info=pool_info, job_preparation_task=batch.models.JobPreparationTask( - command_line=preptaskcommand, - wait_for_success=True) + command_line=preptaskcommand, + wait_for_success=True) ) batch_client.job.add(job) From 7bb41012a5e40b1483909b1d961071ce1a1be850 Mon Sep 17 00:00:00 2001 From: Manish Sharma Date: Wed, 27 Feb 2019 16:35:23 +0530 Subject: [PATCH 13/22] removing config changes --- Python/Batch/sample4_preparationtask.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Python/Batch/sample4_preparationtask.py b/Python/Batch/sample4_preparationtask.py index bd108865..1a42c17b 100644 --- a/Python/Batch/sample4_preparationtask.py +++ b/Python/Batch/sample4_preparationtask.py @@ -37,8 +37,8 @@ def submit_job_and_add_task(batch_client, job_id, vm_size, vm_count): job = batchmodels.JobAddParameter(id=job_id, pool_info=pool_info, job_preparation_task=batch.models.JobPreparationTask( - command_line=preptaskcommand, - wait_for_success=True) + command_line=preptaskcommand, + wait_for_success=True) ) batch_client.job.add(job) From 9411e8c19cf229c446ede09b9421515472562cd6 Mon Sep 17 00:00:00 2001 From: Manish Sharma Date: Wed, 27 Feb 2019 17:09:14 +0530 Subject: [PATCH 14/22] removing config changes --- Python/Batch/configuration.cfg | 10 +++++----- Python/Batch/sample4_preparationtask.py | 3 ++- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/Python/Batch/configuration.cfg b/Python/Batch/configuration.cfg index 0596775f..c852c43a 100644 --- a/Python/Batch/configuration.cfg +++ b/Python/Batch/configuration.cfg @@ -1,9 +1,9 @@ [Batch] -batchaccountname= -batchaccountkey= -batchserviceurl= +batchaccountname=batchwz2xljmm53wrq +batchaccountkey=CM3GV1oj+KFcM2EGHUdHC7zB0Z8Y70342PluVQknzrrPQUHkecodhWC8lErSaEMn3DYGb6pTn8jOAtlVNqBPwg== +batchserviceurl=https://batchwz2xljmm53wrq.southeastasia.batch.azure.com [Storage] -storageaccountname= -storageaccountkey= +storageaccountname=storagewz2xljmm53wrq +storageaccountkey=KoZrUsp+4jxIfvecohbXs/JJh3/dsGa1Ea8Fd+io9aPpynboasJNvQzdMYX2Hb9Ho3p6prcS7q4lwJAdJycK1A== storageaccountsuffix=core.windows.net diff --git a/Python/Batch/sample4_preparationtask.py b/Python/Batch/sample4_preparationtask.py index 1a42c17b..17803331 100644 --- a/Python/Batch/sample4_preparationtask.py +++ b/Python/Batch/sample4_preparationtask.py @@ -37,7 +37,8 @@ def submit_job_and_add_task(batch_client, job_id, vm_size, vm_count): job = batchmodels.JobAddParameter(id=job_id, pool_info=pool_info, job_preparation_task=batch.models.JobPreparationTask( - command_line=preptaskcommand, + command_line=common.helpers.wrap_commands_in_shell( + 'windows', [preptaskcommand]), wait_for_success=True) ) From 8247409f4b0c2479a7f26b653a9501afa03a29ff Mon Sep 17 00:00:00 2001 From: Manish Sharma Date: Wed, 27 Feb 2019 17:24:50 +0530 Subject: [PATCH 15/22] removing config changes --- Python/Batch/sample4_preparationtask.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Python/Batch/sample4_preparationtask.py b/Python/Batch/sample4_preparationtask.py index 17803331..19fc8866 100644 --- a/Python/Batch/sample4_preparationtask.py +++ b/Python/Batch/sample4_preparationtask.py @@ -35,10 +35,11 @@ def submit_job_and_add_task(batch_client, job_id, vm_size, vm_count): keep_alive=False, pool_lifetime_option=batchmodels.PoolLifetimeOption.job)) - job = batchmodels.JobAddParameter(id=job_id, pool_info=pool_info, + job = batchmodels.JobAddParameter( + id=job_id, + pool_info=pool_info, job_preparation_task=batch.models.JobPreparationTask( - command_line=common.helpers.wrap_commands_in_shell( - 'windows', [preptaskcommand]), + command_line=preptaskcommand, wait_for_success=True) ) From 526f17cc2510ee6f329f205008a8c59f147e7be1 Mon Sep 17 00:00:00 2001 From: Manish Sharma Date: Thu, 28 Feb 2019 08:38:14 +0530 Subject: [PATCH 16/22] removing config changes --- Python/Batch/configuration.cfg | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Python/Batch/configuration.cfg b/Python/Batch/configuration.cfg index c852c43a..0596775f 100644 --- a/Python/Batch/configuration.cfg +++ b/Python/Batch/configuration.cfg @@ -1,9 +1,9 @@ [Batch] -batchaccountname=batchwz2xljmm53wrq -batchaccountkey=CM3GV1oj+KFcM2EGHUdHC7zB0Z8Y70342PluVQknzrrPQUHkecodhWC8lErSaEMn3DYGb6pTn8jOAtlVNqBPwg== -batchserviceurl=https://batchwz2xljmm53wrq.southeastasia.batch.azure.com +batchaccountname= +batchaccountkey= +batchserviceurl= [Storage] -storageaccountname=storagewz2xljmm53wrq -storageaccountkey=KoZrUsp+4jxIfvecohbXs/JJh3/dsGa1Ea8Fd+io9aPpynboasJNvQzdMYX2Hb9Ho3p6prcS7q4lwJAdJycK1A== +storageaccountname= +storageaccountkey= storageaccountsuffix=core.windows.net From 024151aa9cefda89f8c5809dd57faf6785c16f43 Mon Sep 17 00:00:00 2001 From: Manish Sharma Date: Mon, 4 Mar 2019 16:54:11 +0530 Subject: [PATCH 17/22] adding change in README.md --- Python/Batch/README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Python/Batch/README.md b/Python/Batch/README.md index 95a5e049..23d7287d 100644 --- a/Python/Batch/README.md +++ b/Python/Batch/README.md @@ -49,6 +49,12 @@ path invocation. This sample can be run on Windows with an appropriate openssl binary and modified openssl invocations (i.e., `openssl.exe` instead of `openssl`). +#### [sample4\_preparationtask.py](./sample4_preparationtask.py) +This sample demostrates preparation task with batch job to show environment +variables using command line as an example before executing normal batch +task on each nodes. It spin-up a fixed pool of windows paas cloud service +and submits a simple python script as the only task of the job. + ## Azure Batch on Linux Best Practices Although some of the Python samples are not specific to Linux, the Azure Batch From c3977b4653b0f93d94bd05148f7b20f65fa3393c Mon Sep 17 00:00:00 2001 From: Manish Sharma Date: Mon, 4 Mar 2019 16:56:39 +0530 Subject: [PATCH 18/22] correcting comments --- Python/Batch/sample4_preparationtask.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Python/Batch/sample4_preparationtask.py b/Python/Batch/sample4_preparationtask.py index 19fc8866..e5caa03d 100644 --- a/Python/Batch/sample4_preparationtask.py +++ b/Python/Batch/sample4_preparationtask.py @@ -1,4 +1,4 @@ -# sample5_preparationtask.py Code Sample +# sample5_preparationtask.py code sample from __future__ import print_function try: From c68f2ebc62ec430fc4014c4aa24885d8c4d7ff84 Mon Sep 17 00:00:00 2001 From: Manish Sharma Date: Mon, 4 Mar 2019 16:58:07 +0530 Subject: [PATCH 19/22] correcting comments --- Python/Batch/sample4_preparationtask.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Python/Batch/sample4_preparationtask.py b/Python/Batch/sample4_preparationtask.py index e5caa03d..7d5f8a5f 100644 --- a/Python/Batch/sample4_preparationtask.py +++ b/Python/Batch/sample4_preparationtask.py @@ -1,4 +1,4 @@ -# sample5_preparationtask.py code sample +# Sample4_preparationtask.py Code Sample from __future__ import print_function try: From 60f4906c42b5b22b875d3f71dbf88518f622abdb Mon Sep 17 00:00:00 2001 From: Manish Sharma Date: Tue, 23 Apr 2019 19:14:36 +0530 Subject: [PATCH 20/22] adding suggested changes --- Python/Batch/README.md | 7 +++---- Python/Batch/sample4_preparationtask.py | 4 ++-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/Python/Batch/README.md b/Python/Batch/README.md index 23d7287d..01b327c4 100644 --- a/Python/Batch/README.md +++ b/Python/Batch/README.md @@ -50,10 +50,9 @@ binary and modified openssl invocations (i.e., `openssl.exe` instead of `openssl`). #### [sample4\_preparationtask.py](./sample4_preparationtask.py) -This sample demostrates preparation task with batch job to show environment -variables using command line as an example before executing normal batch -task on each nodes. It spin-up a fixed pool of windows paas cloud service -and submits a simple python script as the only task of the job. +This sample demonstrates using a `JobPreparationTask` to list environment +variables. This sample is geared towards Windows with the deployment of +a Windows pool. ## Azure Batch on Linux Best Practices diff --git a/Python/Batch/sample4_preparationtask.py b/Python/Batch/sample4_preparationtask.py index 7d5f8a5f..def918e0 100644 --- a/Python/Batch/sample4_preparationtask.py +++ b/Python/Batch/sample4_preparationtask.py @@ -14,7 +14,7 @@ import common.helpers -preptaskcommand = 'cmd /c set' +prep_task_command = 'cmd /c set' def submit_job_and_add_task(batch_client, job_id, vm_size, vm_count): @@ -39,7 +39,7 @@ def submit_job_and_add_task(batch_client, job_id, vm_size, vm_count): id=job_id, pool_info=pool_info, job_preparation_task=batch.models.JobPreparationTask( - command_line=preptaskcommand, + command_line=prep_task_command, wait_for_success=True) ) From d2082100012b6277ee5186599e672681e502f71d Mon Sep 17 00:00:00 2001 From: Manish Sharma Date: Tue, 23 Apr 2019 19:25:29 +0530 Subject: [PATCH 21/22] adding suggested from review --- Python/Batch/sample4_preparationtask.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Python/Batch/sample4_preparationtask.py b/Python/Batch/sample4_preparationtask.py index def918e0..ffa3ea45 100644 --- a/Python/Batch/sample4_preparationtask.py +++ b/Python/Batch/sample4_preparationtask.py @@ -1,4 +1,4 @@ -# Sample4_preparationtask.py Code Sample +# Sample4_preparationtask.py Code sample from __future__ import print_function try: From cfe19e66d0200829c5003ff37b35afb97140c10c Mon Sep 17 00:00:00 2001 From: Manish Sharma Date: Tue, 23 Apr 2019 19:37:55 +0530 Subject: [PATCH 22/22] adding suggested from review --- Python/Batch/sample4_preparationtask.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Python/Batch/sample4_preparationtask.cfg b/Python/Batch/sample4_preparationtask.cfg index 538e6a8b..5e24a9ec 100644 --- a/Python/Batch/sample4_preparationtask.cfg +++ b/Python/Batch/sample4_preparationtask.cfg @@ -1,4 +1,4 @@ [DEFAULT] shoulddeletejob=true poolvmsize=small -poolvmcount=1 \ No newline at end of file +poolvmcount=1