def delete_pool(self, batch_service_client: batch.BatchExtensionsClient):
        """
        Deletes the pool the if the pool, if the pool has already been deleted or marked for deletion it
        should ignore the batch exception that is thrown. These errors come up due to multiple jobs using the same pool
        and when a the job cleans up after it's self it will call delete on the same pool since they are a shared resource.

        :param batch_service_client: A Batch service client.
        :type batch_service_client: `azure.batch.BatchExtensionsClient`
        """
        logger.info("Deleting pool: {}.".format(self.pool_id))
        try:
            batch_service_client.pool.delete(self.pool_id)
        except batchmodels.batch_error.BatchErrorException as batch_exception:
            if utils.expected_exception(
                    batch_exception, "The specified pool has been marked for deletion"):
                logger.warning(
                    "The specified pool [{}] has been marked for deletion.".format(
                        self.pool_id))
            elif utils.expected_exception(batch_exception, "The specified pool does not exist"):
                logger.warning(
                    "The specified pool [{}] has been deleted.".format(
                        self.pool_id))
            else:
                traceback.print_exc()
                utils.print_batch_exception(batch_exception)
    def delete_pool(self, batch_service_client: batch.BatchExtensionsClient):
        """
        Deletes the pool the if the pool, if the pool has already been deleted or marked for deletion it
        should ignore the batch exception that is thrown. These errors come up due to multiple jobs using the same pool
        and when a the job cleans up after it's self it will call delete on the same pool since they are a shared resource.

        :param batch_service_client: A Batch service client.
        :type batch_service_client: `azure.batch.BatchExtensionsClient`
        """
        logger.info("Deleting pool: {}.".format(self.pool_id))
        try:
            batch_service_client.pool.delete(self.pool_id)
        except batchmodels.batch_error.BatchErrorException as batch_exception:
            if utils.expected_exception(
                    batch_exception,
                    "The specified pool has been marked for deletion"):
                logger.warning(
                    "The specified pool [{}] has been marked for deletion.".
                    format(self.pool_id))
            elif utils.expected_exception(batch_exception,
                                          "The specified pool does not exist"):
                logger.warning(
                    "The specified pool [{}] has been deleted.".format(
                        self.pool_id))
            else:
                traceback.print_exc()
                utils.print_batch_exception(batch_exception)
    def submit_pool(self, batch_service_client: batch.BatchExtensionsClient,
                    template: str):
        """
        Submits a batch pool based on the template 

        :param batch_service_client: The batch client used for making batch operations
        :type batch_service_client: `azure.batch.BatchExtensionsClient`
        :param template: The in memory version of the template used to create a the job.
        :type template: str
        """
        parameters = ctm.load_file(self.parameters_file)

        #updates any placeholder parameter values with the values from keyVault, if required
        utils.update_params_with_values_from_keyvault(
            parameters, self.keyvault_client_with_url)
        pool_json = batch_service_client.pool.expand_template(
            template, parameters)
        ctm.set_template_pool_id(template, self.pool_id)
        pool = batch_service_client.pool.poolparameter_from_json(pool_json)
        logger.info('Creating pool [{}]...'.format(pool))
        try:
            batch_service_client.pool.add(pool)
        except batchmodels.BatchErrorException as err:
            if utils.expected_exception(err,
                                        "The specified pool already exists"):
                logger.warning("Pool [{}] is already being created.".format(
                    self.pool_id))
            else:
                logger.info("Create pool error: {}".format(err))
                traceback.print_exc()
                utils.print_batch_exception(err)
    def submit_pool(self, batch_service_client: batch.BatchExtensionsClient, template: str):
        """
        Submits a batch pool based on the template 

        :param batch_service_client: The batch client used for making batch operations
        :type batch_service_client: `azure.batch.BatchExtensionsClient`
        :param template: The in memory version of the template used to create a the job.
        :type template: str
        """
        parameters = ctm.load_file(self.parameters_file)
        pool_json = batch_service_client.pool.expand_template(template, parameters)
        ctm.set_template_pool_id(template, self.pool_id)
        pool = batch_service_client.pool.poolparameter_from_json(pool_json)
        logger.info('Creating pool [{}]...'.format(self.pool_id))
        try:
            batch_service_client.pool.add(pool)
        except batchmodels.batch_error.BatchErrorException as err:
            if utils.expected_exception(
                    err, "The specified pool already exists"):
                logger.warning(
                    "Pool [{}] is already being created.".format(
                        self.pool_id))
            else:
                logger.info("Create pool error: {}".format(err))
                traceback.print_exc()
                utils.print_batch_exception(err)
    def delete_resources(self,
                         batch_service_client: batch.BatchExtensionsClient,
                         blob_client: azureblob.BlockBlobService,
                         force_delete: bool = None):
        """
        Deletes the job, pool and the containers used for the job. If the job fails the output container will not be deleted.
        The non deleted container is used for debugging.

        :param batch_service_client: A Batch service client.
        :type batch_service_client: `azure.batch.BatchExtensionsClient`
        :param blob_client: A blob service client.
        :type blob_client: `azure.storage.blob.BlockBlobService`
        :param force_delete: Forces the deletion of all the containers related this job.
        :type force_delete: bool
        """
        # delete the job
        try:
            batch_service_client.job.delete(self.job_id)
        except batchmodels.batch_error.BatchErrorException as batch_exception:
            if utils.expected_exception(batch_exception,
                                        "The specified job does not exist"):
                logger.error("The specified Job [{}] was not created.".format(
                    self.job_id))
            else:
                traceback.print_exc()
                utils.print_batch_exception(batch_exception)

        if self.status.job_state in {
                utils.JobState.COMPLETE, utils.JobState.POOL_FAILED,
                utils.JobState.NOT_STARTED
        } or force_delete:
            logger.info('Deleting container [{}]...'.format(
                self.storage_info.input_container))
            blob_client.delete_container(self.storage_info.input_container)

            logger.info('Deleting container [{}]...'.format(
                self.storage_info.output_container))
            blob_client.delete_container(self.storage_info.output_container)
        else:
            logger.info("Did not delete the output container")
            logger.info(
                "Job: {}. did not complete successfully, Container {} was not deleted."
                .format(self.job_id, self.storage_info.output_container))
Beispiel #6
0
    def submit_pool(self, batch_service_client: batch.BatchExtensionsClient, template: str, UseLowPriorityVMs: bool):
        """
        Submits a batch pool based on the template 

        :param batch_service_client: The batch client used for making batch operations
        :type batch_service_client: `azure.batch.BatchExtensionsClient`
        :param template: The in memory version of the template used to create a the job.
        :type template: str
        :param UseLowPriorityVMs: True: Use low priority nodes, False: will use the type in the template file
        :type UseLowPriorityVMs: bool
        """
        parameters = ctm.load_file(self.parameters_file)
        if UseLowPriorityVMs==True:
            #swap the dedicated vm count to low pri and zero out the dedicated count (to reduce testing COGS)
            ctm.set_low_priority_vm_count(template, str(self.min_required_vms))

            #some tests set the dedicated vm count in the test parameters file, and some use the default in the template, so override both to 0
            ctm.set_dedicated_vm_count(parameters, 0)
            ctm.set_dedicated_vm_count(template, 0)

        # updates any placeholder parameter values with the values from
        # keyVault, if required
        utils.update_params_with_values_from_keyvault(
            parameters, self.keyvault_client_with_url)
        pool_json = batch_service_client.pool.expand_template(
            template, parameters)
        ctm.set_template_pool_id(template, self.pool_id)
        pool = batch_service_client.pool.poolparameter_from_json(pool_json)
        logger.info('Creating pool [{}]...'.format(pool))
        try:
            utils.run_with_jitter_retry(batch_service_client.pool.add, pool)
        except batchmodels.BatchErrorException as err:
            if utils.expected_exception(
                    err, "The specified pool already exists"):
                logger.warning(
                    "Pool [{}] is already being created.".format(
                        self.pool_id))
            else:
                logger.info("Create pool error: {}".format(err))
                traceback.print_exc()
                utils.print_batch_exception(err)
    def delete_resources(self, batch_service_client: batch.BatchExtensionsClient,
                         blob_client: azureblob.BlockBlobService, force_delete: bool = None):
        """
        Deletes the job, pool and the containers used for the job. If the job fails the output container will not be deleted.
        The non deleted container is used for debugging.

        :param batch_service_client: A Batch service client.
        :type batch_service_client: `azure.batch.BatchExtensionsClient`
        :param blob_client: A blob service client.
        :type blob_client: `azure.storage.blob.BlockBlobService`
        :param force_delete: Forces the deletion of all the containers related this job.
        :type force_delete: bool
        """
        # delete the job
        try:
            batch_service_client.job.delete(self.job_id)
        except batchmodels.batch_error.BatchErrorException as batch_exception:
            if utils.expected_exception(
                    batch_exception, "The specified job does not exist"):
                logger.error(
                    "The specified Job [{}] was not created.".format(
                        self.job_id))
            else:
                traceback.print_exc()
                utils.print_batch_exception(batch_exception)

        if self.status.job_state in {
            utils.JobState.COMPLETE, utils.JobState.POOL_FAILED, utils.JobState.NOT_STARTED} or force_delete:
            logger.info('Deleting container [{}]...'.format(
                self.storage_info.input_container))
            blob_client.delete_container(self.storage_info.input_container)

            logger.info('Deleting container [{}]...'.format(
                self.storage_info.output_container))
            blob_client.delete_container(self.storage_info.output_container)
        else:
            logger.info("Did not delete the output container")
            logger.info(
                "Job: {}. did not complete successfully, Container {} was not deleted.".format(
                    self.job_id, self.storage_info.output_container))
    def submit_pool(self, batch_service_client: batch.BatchExtensionsClient,
                    template: str):
        """
        Submits a batch pool based on the template 

        :param batch_service_client: The batch client used for making batch operations
        :type batch_service_client: `azure.batch.BatchExtensionsClient`
        :param template: The in memory version of the template used to create a the job.
        :type template: str
        """
        pool_json = batch_service_client.pool.expand_template(template)
        pool = batch_service_client.pool.poolparameter_from_json(pool_json)
        logger.info('Creating pool [{}]...'.format(self.pool_id))
        try:
            batch_service_client.pool.add(pool)
        except batchmodels.batch_error.BatchErrorException as err:
            if utils.expected_exception(err,
                                        "The specified pool already exists"):
                logger.warning("Pool [{}] is already being created.".format(
                    self.pool_id))
            else:
                logger.info("Create pool error: {}".format(err))
                traceback.print_exc()
                utils.print_batch_exception(err)