Esempio n. 1
0
class TestClusterBatchScheduling(unittest.TestCase):
    def setUp(self) -> None:
        """
        Batch scheduling setup
        """
        self.env = simpy.Environment()
        config = Config(CONFIG)

        self.cluster = Cluster(env=self.env, config=config)
        self.telescope = Telescope(self.env,
                                   config,
                                   planner=None,
                                   scheduler=None)
        self.observation = self.telescope.observations[0]

    def test_provision_resources(self):
        """
        Test that resource provisioning occurs and the right number of
        resources exist in the right place

        Returns
        -------

        """
        provision_size = 5
        self.cluster.provision_batch_resources(provision_size,
                                               self.observation)
        self.assertEqual(5, len(self.cluster.get_available_resources()))
        self.assertEqual(
            5, len(self.cluster.get_idle_resources(self.observation)))
        self.assertListEqual(self.cluster._get_batch_observations(),
                             [self.observation])

    def test_batch_removal(self):
        provision_size = 5
        self.cluster.provision_batch_resources(provision_size,
                                               self.observation)
        self.cluster.release_batch_resources(self.observation)
        self.assertListEqual([],
                             self.cluster.get_idle_resources(self.observation))
        self.assertEqual(10, len(self.cluster.get_available_resources()))

    def tearDown(self) -> None:
        """
        TODO
        Batch scheduling tear down
        """
        pass
Esempio n. 2
0
class TestBatchSchedulerAllocation(unittest.TestCase):
    def setUp(self):
        self.algorithm = BatchProcessing
        self.env = simpy.Environment()
        config = Config(CONFIG)
        self.cluster = Cluster(self.env, config=config)
        self.buffer = Buffer(self.env, self.cluster, config)
        self.scheduler = Scheduler(self.env, self.buffer, self.cluster,
                                   DynamicAlgorithmFromPlan())
        self.algorithm = BatchProcessing()
        self.model = BatchPlanning('batch')
        self.planner = Planner(
            self.env,
            'heft',
            self.cluster,
            self.model,
        )

        self.telescope = Telescope(self.env, config, self.planner,
                                   self.scheduler)

    def test_resource_provision(self):
        """
        Given a max_resource_split of 2, and total machines of 10, we should
        provision a maximum of 5 machines within the cluster (
        max_resource_split being the number of parallel provision ings we can
        make).

        Returns
        -------

        """
        self.assertEqual(10, len(self.cluster.get_available_resources()))

    def test_max_resource_provision(self):
        obs = self.telescope.observations[0]
        self.env.process(self.cluster.provision_ingest_resources(5, obs))
        self.env.run(until=1)
        self.assertEqual(5, len(self.cluster.get_available_resources()))
        self.assertEqual(5,
                         self.algorithm._max_resource_provision(self.cluster))
        # TODO The algorithm must provision resources if they are not already
        #  provisioned.
        plan = self.planner.run(obs, self.buffer, self.telescope.max_ingest)
        self.algorithm._provision_resources(self.cluster, plan)
        self.assertEqual(5, len(self.cluster.get_idle_resources(obs.name)))
        self.assertEqual(0,
                         self.algorithm._max_resource_provision(self.cluster))
        # self.planner.run(obs, )

    def test_algorithm_allocation(self):
        obs = self.telescope.observations[0]
        obs.plan = self.planner.run(obs, self.buffer,
                                    self.telescope.max_ingest)
        # Replicate the Scheduler allocate_task() methods
        existing_schedule = {}
        existing_schedule, status = self.algorithm.run(self.cluster,
                                                       self.env.now, obs.plan,
                                                       existing_schedule)
        self.assertTrue(obs.plan.tasks[0] in existing_schedule)

    def test_observation_queue(self):
        """