|
| 1 | +from azure import batch |
| 2 | +from aztk.models import ClusterConfiguration, SchedulingTarget |
| 3 | +from core import config, log |
| 4 | + |
| 5 | +def disable_scheduling(batch_client: batch.BatchServiceClient): |
| 6 | + """ |
| 7 | + Disable scheduling for the current node |
| 8 | + """ |
| 9 | + pool_id = config.pool_id |
| 10 | + node_id = config.node_id |
| 11 | + |
| 12 | + node = batch_client.compute_node.get(pool_id, node_id) |
| 13 | + if node.scheduling_state == batch.models.SchedulingState.enabled: |
| 14 | + batch_client.compute_node.disable_scheduling(pool_id, node_id) |
| 15 | + log.info("Disabled task scheduling for this node") |
| 16 | + else: |
| 17 | + log.info("Task scheduling is already disabled for this node") |
| 18 | + |
| 19 | +def enable_scheduling(batch_client: batch.BatchServiceClient): |
| 20 | + """ |
| 21 | + Disable scheduling for the current node |
| 22 | + """ |
| 23 | + pool_id = config.pool_id |
| 24 | + node_id = config.node_id |
| 25 | + |
| 26 | + node = batch_client.compute_node.get(pool_id, node_id) |
| 27 | + if node.scheduling_state == batch.models.SchedulingState.disabled: |
| 28 | + batch_client.compute_node.disable_scheduling(pool_id, node_id) |
| 29 | + log.info("Enabled task scheduling for this node") |
| 30 | + else: |
| 31 | + log.info("Task scheduling is already enabled for this node") |
| 32 | + |
| 33 | + |
| 34 | +def setup_node_scheduling( |
| 35 | + batch_client: batch.BatchServiceClient, |
| 36 | + cluster_config: ClusterConfiguration, |
| 37 | + is_master: bool): |
| 38 | + |
| 39 | + is_dedicated = config.is_dedicated |
| 40 | + enable = False |
| 41 | + log.info("Resolving scheduling for this node") |
| 42 | + log.info(" Scheduling target: %s", cluster_config.scheduling_target and cluster_config.scheduling_target.value) |
| 43 | + log.info(" Is node dedicated: %s", str(is_dedicated)) |
| 44 | + log.info(" Is node master: %s", str(is_master)) |
| 45 | + |
| 46 | + if cluster_config.scheduling_target == SchedulingTarget.Any or cluster_config.scheduling_target is None: |
| 47 | + enable = True |
| 48 | + elif cluster_config.scheduling_target == SchedulingTarget.Dedicated and is_dedicated: |
| 49 | + enable = True |
| 50 | + elif cluster_config.scheduling_target == SchedulingTarget.Master and is_master: |
| 51 | + enable = True |
| 52 | + |
| 53 | + if enable: |
| 54 | + log.info("Scheduling will be enabled on this node as it satifies the right conditions") |
| 55 | + enable_scheduling(batch_client) |
| 56 | + else: |
| 57 | + log.info("Scheduling will be disabled on this node as it does NOT satifies the right conditions") |
| 58 | + disable_scheduling(batch_client) |
0 commit comments