コード例 #1
0
    def test_add_experiment_instance_id_redundant(self):

        self.assertEquals([], self.resources_manager.list_resources())

        exp_id = ExperimentInstanceId("exp1", "ud-pld", "PLD Experiments")

        self.resources_manager.add_experiment_instance_id(
            "laboratory1:WL_SERVER1@WL_MACHINE1", exp_id,
            Resource("type", "instance"))

        # No problem in adding twice the same
        self.resources_manager.add_experiment_instance_id(
            "laboratory1:WL_SERVER1@WL_MACHINE1", exp_id,
            Resource("type", "instance"))

        # Everything is all right
        self._check_resource_added()
        self._check_experiment_instance_id_added()

        # However, we can't add another time the same experiment instance with a different laboratory id:
        self.assertRaises(CoordExc.InvalidExperimentConfigError,
                          self.resources_manager.add_experiment_instance_id,
                          "laboratory2:WL_SERVER1@WL_MACHINE1", exp_id,
                          Resource("type", "instance"))

        # Or the same experiment instance with a different resource instance:
        self.assertRaises(CoordExc.InvalidExperimentConfigError,
                          self.resources_manager.add_experiment_instance_id,
                          "laboratory1:WL_SERVER1@WL_MACHINE1", exp_id,
                          Resource("type", "instance2"))
コード例 #2
0
    def test_add_resource(self):
        session = self.session_maker()
        try:
            resource_types = session.query(CoordinatorModel.ResourceType).all()
            self.assertEquals(
                0, len(resource_types),
                "No resource expected in the beginning of the test")

            self.resources_manager.add_resource(session,
                                                Resource("type", "instance"))
            self._check_resource_added(session)
            session.commit()
        finally:
            session.close()

        # Can be executed twice without conflicts

        session = self.session_maker()
        try:
            self.resources_manager.add_resource(session,
                                                Resource("type", "instance"))
            self._check_resource_added(session)
            session.commit()
        finally:
            session.close()
コード例 #3
0
    def test_list_experiment_instance_ids_by_resource(self):
        session = self.session_maker()
        try:
            exp_id1 = ExperimentInstanceId("exp1", "ud-pld", "PLD Experiments")
            resource_instance1 = Resource("type1", "instance1")
            self.resources_manager.add_experiment_instance_id(
                "laboratory1:WL_SERVER1@WL_MACHINE1", exp_id1,
                resource_instance1)

            exp_id2 = ExperimentInstanceId("exp2", "ud-pld", "PLD Experiments")
            self.resources_manager.add_experiment_instance_id(
                "laboratory1:WL_SERVER1@WL_MACHINE1", exp_id2,
                resource_instance1)

            exp_id3 = ExperimentInstanceId("exp3", "ud-pld", "PLD Experiments")
            resource_instance2 = Resource("type1", "instance2")
            self.resources_manager.add_experiment_instance_id(
                "laboratory1:WL_SERVER1@WL_MACHINE1", exp_id3,
                resource_instance2)

            session.commit()
        finally:
            session.close()

        experiment_instance_ids = self.resources_manager.list_experiment_instance_ids_by_resource(
            resource_instance1)
        self.assertEquals(2, len(experiment_instance_ids))
        self.assertTrue(
            ExperimentInstanceId('exp1', 'ud-pld', 'PLD Experiments') in
            experiment_instance_ids)
        self.assertTrue(
            ExperimentInstanceId('exp2', 'ud-pld', 'PLD Experiments') in
            experiment_instance_ids)
コード例 #4
0
    def test_add_resource(self):
        self.assertEquals([], self.resources_manager.list_resources())
        self.resources_manager.add_resource(Resource("type", "instance"))
        self._check_resource_added()

        # Can be executed twice without conflicts

        self.resources_manager.add_resource(Resource("type", "instance"))
        self._check_resource_added()
コード例 #5
0
    def test_get_resource_instance_by_experiment_instance_id(self):
        exp_id = ExperimentInstanceId("exp1", "ud-pld", "PLD Experiments")
        self.resources_manager.add_experiment_instance_id(
            "laboratory1:WL_SERVER1@WL_MACHINE1", exp_id,
            Resource("type", "instance"))

        resource = self.resources_manager.get_resource_instance_by_experiment_instance_id(
            exp_id)
        expected_resource = Resource("type", "instance")
        self.assertEquals(expected_resource, resource)
コード例 #6
0
    def test_eq_other(self):
        res1 = Resource("foo", "bar")
        res2 = Resource("foo", "bar2")
        self.assertNotEquals(res1, res2)

        res2 = Resource("foo2", "bar")
        self.assertNotEquals(res1, res2)

        res2 = "foobar"
        self.assertNotEquals(res1, res2)
コード例 #7
0
    def test_list_experiments(self):
        exp_id1 = ExperimentInstanceId("exp1", "ud-pld", "PLD Experiments")
        resource_instance1 = Resource("type1", "instance1")
        self.resources_manager.add_experiment_instance_id(
            "laboratory1:WL_SERVER1@WL_MACHINE1", exp_id1, resource_instance1)

        exp_id2 = ExperimentInstanceId("exp2", "ud-pld", "PLD Experiments")
        resource_instance2 = Resource("type2", "instance1")
        self.resources_manager.add_experiment_instance_id(
            "laboratory1:WL_SERVER1@WL_MACHINE1", exp_id2, resource_instance2)

        resources = self.resources_manager.list_experiments()
        self.assertEquals(1, len(resources))
        self.assertTrue(ExperimentId('ud-pld', 'PLD Experiments') in resources)
コード例 #8
0
    def test_list_laboratories_addresses(self):
        session = self.session_maker()
        try:
            exp_id1 = ExperimentInstanceId("exp1", "ud-pld", "PLD Experiments")
            resource_instance1 = Resource("type1", "instance1")
            self.resources_manager.add_experiment_instance_id(
                "laboratory1:WL_SERVER1@WL_MACHINE1", exp_id1,
                resource_instance1)

            # Repeating laboratory1, but a set is returned so no problem
            exp_id2 = ExperimentInstanceId("exp2", "ud-pld", "PLD Experiments")
            resource_instance2 = Resource("type2", "instance1")
            self.resources_manager.add_experiment_instance_id(
                "laboratory1:WL_SERVER1@WL_MACHINE1", exp_id2,
                resource_instance2)

            exp_id3 = ExperimentInstanceId("exp3", "ud-pld", "PLD Experiments")
            resource_instance3 = Resource("type2", "instance2")
            self.resources_manager.add_experiment_instance_id(
                "laboratory2:WL_SERVER1@WL_MACHINE1", exp_id3,
                resource_instance3)

            session.commit()
        finally:
            session.close()

        addresses = self.resources_manager.list_laboratories_addresses()
        self.assertEquals(2, len(addresses))
        self.assertTrue("laboratory1:WL_SERVER1@WL_MACHINE1" in addresses)
        self.assertEquals(2,
                          len(addresses["laboratory1:WL_SERVER1@WL_MACHINE1"]))
        self.assertTrue(
            exp_id1 in addresses["laboratory1:WL_SERVER1@WL_MACHINE1"])
        self.assertTrue(
            exp_id2 in addresses["laboratory1:WL_SERVER1@WL_MACHINE1"])
        self.assertTrue("laboratory2:WL_SERVER1@WL_MACHINE1" in addresses)
        self.assertEquals(1,
                          len(addresses["laboratory2:WL_SERVER1@WL_MACHINE1"]))
        self.assertTrue(
            exp_id3 in addresses["laboratory2:WL_SERVER1@WL_MACHINE1"])

        self.assertEquals(
            resource_instance1,
            addresses["laboratory1:WL_SERVER1@WL_MACHINE1"][exp_id1])
        self.assertEquals(
            resource_instance2,
            addresses["laboratory1:WL_SERVER1@WL_MACHINE1"][exp_id2])
        self.assertEquals(
            resource_instance3,
            addresses["laboratory2:WL_SERVER1@WL_MACHINE1"][exp_id3])
コード例 #9
0
    def test_get_resource_instance_by_experiment_instance_id(self):
        session = self.session_maker()
        try:
            exp_id = ExperimentInstanceId("exp1", "ud-pld", "PLD Experiments")
            self.resources_manager.add_experiment_instance_id(
                "laboratory1:WL_SERVER1@WL_MACHINE1", exp_id,
                Resource("type", "instance"))
            session.commit()
        finally:
            session.close()

        resource = self.resources_manager.get_resource_instance_by_experiment_instance_id(
            exp_id)
        expected_resource = Resource("type", "instance")
        self.assertEquals(expected_resource, resource)
コード例 #10
0
    def _clean_current_reservation(self, reservation_id):
        client = self.redis_maker()

        enqueue_free_experiment_args = None
        if reservation_id is not None:
            weblab_reservation_pqueue = WEBLAB_RESOURCE_RESERVATION_PQUEUE % (self.resource_type_name, reservation_id)
            reservation_data_str = client.get(weblab_reservation_pqueue)
            if reservation_data_str is not None:
                downgraded = self.reservations_manager.downgrade_confirmation(reservation_id)
                if downgraded:
                    reservation_data      = json.loads(reservation_data_str)
                    resource_instance_str = reservation_data.get(RESOURCE_INSTANCE)
                    if resource_instance_str is not None:
                        resource_instance       = Resource.parse(resource_instance_str)
                        weblab_resource_pqueue_instance_reservations = WEBLAB_RESOURCE_PQUEUE_INSTANCE_RESERVATIONS % (resource_instance.resource_type, resource_instance.resource_instance)
                        client.srem(weblab_resource_pqueue_instance_reservations, reservation_id)
                        self.resources_manager.release_resource(resource_instance)
                        lab_session_id          = reservation_data.get(LAB_SESSION_ID)
                        experiment_instance_str = reservation_data.get(EXPERIMENT_INSTANCE)
                        experiment_instance_id  = ExperimentInstanceId.parse(experiment_instance_str)
                        if experiment_instance_id is not None: 
                            # If the experiment instance doesn't exist, there is no need to call the free_experiment method
                            lab_coord_address  = reservation_data.get(LAB_COORD)
                            enqueue_free_experiment_args = (lab_coord_address, reservation_id, lab_session_id, experiment_instance_id)
                # otherwise the student has been removed
        return enqueue_free_experiment_args
コード例 #11
0
    def list_laboratories_addresses(self):
        client = self._redis_maker()

        laboratory_addresses = {
            # laboratory_coord_address : {
            #         experiment_instance_id : resource_instance
            # }
        }

        for experiment_type in client.smembers(WEBLAB_EXPERIMENT_TYPES):
            experiment_id = ExperimentId.parse(experiment_type)
            experiment_instance_names = client.smembers(
                WEBLAB_EXPERIMENT_INSTANCES % experiment_type)
            for experiment_instance_name in experiment_instance_names:
                experiment_instance_id = ExperimentInstanceId(
                    experiment_instance_name, experiment_id.exp_name,
                    experiment_id.cat_name)
                weblab_experiment_instance = WEBLAB_EXPERIMENT_INSTANCE % (
                    experiment_type, experiment_instance_name)
                laboratory_address = client.hget(weblab_experiment_instance,
                                                 LAB_COORD)
                resource_str = client.hget(weblab_experiment_instance,
                                           RESOURCE_INST)
                resource = Resource.parse(resource_str)
                current = laboratory_addresses.get(laboratory_address, {})
                current[experiment_instance_id] = resource
                laboratory_addresses[laboratory_address] = current

        return laboratory_addresses
コード例 #12
0
    def setUp(self):
        self.mocker = mocker.Mocker()
        self.lab_mock = self.mocker.mock()

        self.locator = FakeLocator(lab=self.lab_mock)
        self.db = FakeDatabase()

        self.cfg_manager = ConfigurationManager.ConfigurationManager()
        self.cfg_manager.append_module(configuration_module)
        self.cfg_manager._set_value(
            COORDINATOR_LABORATORY_SERVERS, {
                'server:laboratoryserver@labmachine': {
                    'inst1|ud-dummy|Dummy experiments': 'res_inst@res_type'
                }
            })

        self.commands_store = TemporalInformationStore.CommandsTemporalInformationStore(
        )

        self.coordinator = coordinator_create(SQLALCHEMY,
                                              self.locator,
                                              self.cfg_manager,
                                              ConfirmerClass=FakeConfirmer)
        self.coordinator._clean()
        self.coordinator.add_experiment_instance_id(
            "server:laboratoryserver@labmachine",
            ExperimentInstanceId('inst', 'ud-dummy', 'Dummy experiments'),
            Resource("res_type", "res_inst"))

        self.processor = UserProcessor.UserProcessor(
            self.locator,
            {'db_session_id': ValidDatabaseSessionId('my_db_session_id')},
            self.cfg_manager, self.coordinator, self.db, self.commands_store)
コード例 #13
0
    def confirm_experiment(self, reservation_id, lab_session_id, initial_configuration, exp_info):
        self._remove_expired_reservations()

        weblab_reservation_pqueue = WEBLAB_RESOURCE_RESERVATION_PQUEUE % (self.resource_type_name, reservation_id)

        client = self.redis_maker()
        pqueue_reservation_data_str = client.get(weblab_reservation_pqueue)
        if pqueue_reservation_data_str is None:
            return

        pqueue_reservation_data = json.loads(pqueue_reservation_data_str)
        resource_instance_str = pqueue_reservation_data.get(RESOURCE_INSTANCE)
        if resource_instance_str is not None:
            resource_instance = Resource.parse(resource_instance_str)
            if not self.resources_manager.check_working(resource_instance):
                # TODO: if the experiment is broken and the student is ACTIVE_STATUS, something should be done
                # 
                return

        pqueue_reservation_data[LAB_SESSION_ID]        = lab_session_id.id
        pqueue_reservation_data[INITIAL_CONFIGURATION] = initial_configuration
        pqueue_reservation_data[TIMESTAMP_AFTER]       = self.time_provider.get_time()
        pqueue_reservation_data[ACTIVE_STATUS]         = STATUS_RESERVED
        pqueue_reservation_data[EXP_INFO]              = json.dumps(exp_info)

        pqueue_reservation_data_str = json.dumps(pqueue_reservation_data)
        client.set(weblab_reservation_pqueue, pqueue_reservation_data_str)
コード例 #14
0
    def _clean_current_reservation(self, reservation_id):
        client = self.redis_maker()

        enqueue_free_experiment_args = None
        if reservation_id is not None:
            weblab_reservation_pqueue = WEBLAB_RESOURCE_RESERVATION_PQUEUE % (self.resource_type_name, reservation_id)
            reservation_data_str = client.get(weblab_reservation_pqueue)
            if reservation_data_str is not None:
                downgraded = self.reservations_manager.downgrade_confirmation(reservation_id)
                if downgraded:
                    reservation_data      = json.loads(reservation_data_str)
                    resource_instance_str = reservation_data.get(RESOURCE_INSTANCE)
                    if resource_instance_str is not None:
                        resource_instance       = Resource.parse(resource_instance_str)
                        weblab_resource_pqueue_instance_reservations = WEBLAB_RESOURCE_PQUEUE_INSTANCE_RESERVATIONS % (resource_instance.resource_type, resource_instance.resource_instance)
                        client.srem(weblab_resource_pqueue_instance_reservations, reservation_id)
                        # print "RELEASING AT _clean_current_reservation. SHOULD NEVER HAPPEN."
                        # self.resources_manager.release_resource(resource_instance)
                        lab_session_id          = reservation_data.get(LAB_SESSION_ID)
                        experiment_instance_str = reservation_data.get(EXPERIMENT_INSTANCE)
                        experiment_instance_id  = ExperimentInstanceId.parse(experiment_instance_str)
                        if experiment_instance_id is not None: 
                            # If the experiment instance doesn't exist, there is no need to call the free_experiment method
                            lab_coord_address  = reservation_data.get(LAB_COORD)
                            enqueue_free_experiment_args = (lab_coord_address, reservation_id, lab_session_id, experiment_instance_id)
                # otherwise the student has been removed
        return enqueue_free_experiment_args
コード例 #15
0
    def test_remove_resource_instance(self):
        session = self.session_maker()
        try:
            exp_id = ExperimentInstanceId("exp1", "ud-pld", "PLD Experiments")
            resource_instance = Resource("type", "instance")
            self.resources_manager.add_experiment_instance_id(
                "laboratory1:WL_SERVER1@WL_MACHINE1", exp_id,
                resource_instance)

            # Checking that the resources are there
            experiment_instances = session.query(
                CoordinatorModel.ExperimentInstance).all()
            self.assertEquals(1, len(experiment_instances))
            resource_instances = session.query(
                CoordinatorModel.ResourceInstance).all()
            self.assertEquals(1, len(resource_instances))

            # Removing resource instance
            self.resources_manager.remove_resource_instance(
                session, resource_instance)

            # Checking that the resources are not there, neither the experiment instances
            resource_instances = session.query(
                CoordinatorModel.ResourceInstance).all()
            self.assertEquals(0, len(resource_instances))
            experiment_instances = session.query(
                CoordinatorModel.ExperimentInstance).all()
            self.assertEquals(0, len(experiment_instances))

            session.commit()
        finally:
            session.close()
コード例 #16
0
    def confirm_experiment(self, reservation_id, lab_session_id,
                           initial_configuration, exp_info):
        self._remove_expired_reservations()

        weblab_reservation_pqueue = WEBLAB_RESOURCE_RESERVATION_PQUEUE % (
            self.resource_type_name, reservation_id)

        client = self.redis_maker()
        pqueue_reservation_data_str = client.get(weblab_reservation_pqueue)
        if pqueue_reservation_data_str is None:
            return

        pqueue_reservation_data = json.loads(pqueue_reservation_data_str)
        resource_instance_str = pqueue_reservation_data.get(RESOURCE_INSTANCE)
        if resource_instance_str is not None:
            resource_instance = Resource.parse(resource_instance_str)
            if not self.resources_manager.check_working(resource_instance):
                # TODO: if the experiment is broken and the student is ACTIVE_STATUS, something should be done
                #
                return

        pqueue_reservation_data[LAB_SESSION_ID] = lab_session_id.id
        pqueue_reservation_data[INITIAL_CONFIGURATION] = initial_configuration
        pqueue_reservation_data[TIMESTAMP_AFTER] = self.time_provider.get_time(
        )
        pqueue_reservation_data[ACTIVE_STATUS] = STATUS_RESERVED
        pqueue_reservation_data[EXP_INFO] = json.dumps(exp_info)

        pqueue_reservation_data_str = json.dumps(pqueue_reservation_data)
        client.set(weblab_reservation_pqueue, pqueue_reservation_data_str)
コード例 #17
0
 def list_resource_instances_by_type(self, resource_type_name):
     client = self._redis_maker()
     return [
         Resource(resource_type_name, resource_instance)
         for resource_instance in client.smembers(WEBLAB_RESOURCE %
                                                  resource_type_name)
     ]
コード例 #18
0
    def list_resource_instances(self):
        client = self._redis_maker()
        resource_instances = []
        for resource_type in client.smembers(WEBLAB_RESOURCES):
            for resource_instance in client.smembers(WEBLAB_RESOURCE % resource_type):
                resource_instances.append(Resource(resource_type, resource_instance))

        return resource_instances
コード例 #19
0
    def test_get_resource_types_by_experiment_id_error(self):
        exp_id = ExperimentInstanceId("exp1", "ud-pld", "PLD Experiments")
        self.resources_manager.add_experiment_instance_id(
            "laboratory1:WL_SERVER1@WL_MACHINE1", exp_id,
            Resource("type", "instance"))

        self.assertRaises(
            CoordExc.ExperimentNotFoundError,
            self.resources_manager.get_resource_types_by_experiment_id,
            ExperimentId("foo", "bar"))
コード例 #20
0
    def test_add_experiment_instance_id_redundant(self):
        session = self.session_maker()
        try:
            resource_types = session.query(CoordinatorModel.ResourceType).all()
            self.assertEquals(
                0, len(resource_types),
                "No resource expected in the beginning of the test")
        finally:
            session.close()

        exp_id = ExperimentInstanceId("exp1", "ud-pld", "PLD Experiments")
        self.resources_manager.add_experiment_instance_id(
            "laboratory1:WL_SERVER1@WL_MACHINE1", exp_id,
            Resource("type", "instance"))

        # No problem in adding twice the same
        self.resources_manager.add_experiment_instance_id(
            "laboratory1:WL_SERVER1@WL_MACHINE1", exp_id,
            Resource("type", "instance"))

        session = self.session_maker()
        try:
            # Everything is all right
            self._check_resource_added(session)
            self._check_experiment_instance_id_added(session)

            # However, we can't add another time the same experiment instance with a different laboratory id:
            self.assertRaises(
                CoordExc.InvalidExperimentConfigError,
                self.resources_manager.add_experiment_instance_id,
                "laboratory2:WL_SERVER1@WL_MACHINE1", exp_id,
                Resource("type", "instance"))

            # Or the same experiment instance with a different resource instance:
            self.assertRaises(
                CoordExc.InvalidExperimentConfigError,
                self.resources_manager.add_experiment_instance_id,
                "laboratory1:WL_SERVER1@WL_MACHINE1", exp_id,
                Resource("type", "instance2"))

            session.commit()
        finally:
            session.close()
コード例 #21
0
    def get_resource_instance_by_experiment_instance_id(self, experiment_instance_id):
        experiment_id = experiment_instance_id.to_experiment_id()
        weblab_experiment_instance = WEBLAB_EXPERIMENT_INSTANCE % (experiment_id.to_weblab_str(), experiment_instance_id.inst_name)

        client = self._redis_maker()
        resource_instance = client.hget(weblab_experiment_instance, RESOURCE_INST)
        if resource_instance is None:
            raise CoordExc.ExperimentNotFoundError("Experiment not found: %s" % experiment_instance_id)

        return Resource.parse(resource_instance)
コード例 #22
0
    def get_resource_instance_by_experiment_instance_id(self, experiment_instance_id):
        experiment_id = experiment_instance_id.to_experiment_id()
        weblab_experiment_instance = WEBLAB_EXPERIMENT_INSTANCE % (experiment_id.to_weblab_str(), experiment_instance_id.inst_name)

        client = self._redis_maker()
        resource_instance = client.hget(weblab_experiment_instance, RESOURCE_INST)
        if resource_instance is None:
            raise CoordExc.ExperimentNotFoundError("Experiment not found: %s" % experiment_instance_id)

        return Resource.parse(resource_instance)
コード例 #23
0
    def test_get_resource_types_by_experiment_id(self):
        exp_id = ExperimentInstanceId("exp1", "ud-pld", "PLD Experiments")
        self.resources_manager.add_experiment_instance_id(
            "laboratory1:WL_SERVER1@WL_MACHINE1", exp_id,
            Resource("type", "instance"))

        exp_type_id = ExperimentId("ud-pld", "PLD Experiments")
        resource_types = self.resources_manager.get_resource_types_by_experiment_id(
            exp_type_id)
        self.assertEquals(1, len(resource_types))
        self.assertTrue(u"type" in resource_types)
コード例 #24
0
    def test_coordination_configuration_parser(self):
        self.cfg_manager._set_value(CoordinationConfigurationParser.COORDINATOR_LABORATORY_SERVERS, {
                        'laboratory1:WL_SERVER1@WL_MACHINE1' : {
                                'exp1|ud-fpga|FPGA experiments' : 'fpga1@fpga boards',
                                'exp1|ud-pld|PLD experiments' : 'pld1@pld boards',
                            },
                    })

        configuration = self.coordination_configuration_parser.parse_configuration()
        self.assertEquals(1, len(configuration))
        lab_config = configuration['laboratory1:WL_SERVER1@WL_MACHINE1']
        self.assertEquals(2, len(lab_config))
        exp_fpga = ExperimentInstanceId("exp1","ud-fpga","FPGA experiments")
        exp_pld  = ExperimentInstanceId("exp1","ud-pld","PLD experiments")

        fpga_resource = lab_config[exp_fpga]
        self.assertEquals(Resource("fpga boards", "fpga1"), fpga_resource)

        pld_resource = lab_config[exp_pld]
        self.assertEquals(Resource("pld boards", "pld1"), pld_resource)
コード例 #25
0
    def setUp(self):

        locator_mock = None

        self.cfg_manager = ConfigurationManager.ConfigurationManager()
        self.cfg_manager.append_module(configuration_module)

        self.coordinator = WrappedSqlCoordinator(locator_mock,
                                                 self.cfg_manager,
                                                 ConfirmerClass=ConfirmerMock)
        self.coordinator._clean()

        self.coordinator.add_experiment_instance_id(
            "lab1:inst@machine", ExperimentInstanceId('inst1', 'exp1', 'cat1'),
            Resource("res_type", "res_inst1"))
        self.coordinator.add_experiment_instance_id(
            "lab2:inst@machine", ExperimentInstanceId('inst2', 'exp2', 'cat1'),
            Resource("res_type", "res_inst2"))

        self.reservations_manager = self.coordinator.reservations_manager
コード例 #26
0
    def test_add_experiment_instance_id(self):

        self.assertEquals([], self.resources_manager.list_resources())

        exp_id = ExperimentInstanceId("exp1", "ud-pld", "PLD Experiments")

        self.resources_manager.add_experiment_instance_id(
            "laboratory1:WL_SERVER1@WL_MACHINE1", exp_id,
            Resource("type", "instance"))

        self._check_resource_added()
        self._check_experiment_instance_id_added()
コード例 #27
0
    def test_list_resources(self):
        session = self.session_maker()
        try:
            exp_id1 = ExperimentInstanceId("exp1", "ud-pld", "PLD Experiments")
            resource_instance1 = Resource("type1", "instance1")
            self.resources_manager.add_experiment_instance_id(
                "laboratory1:WL_SERVER1@WL_MACHINE1", exp_id1,
                resource_instance1)

            exp_id2 = ExperimentInstanceId("exp2", "ud-pld", "PLD Experiments")
            resource_instance2 = Resource("type2", "instance1")
            self.resources_manager.add_experiment_instance_id(
                "laboratory1:WL_SERVER1@WL_MACHINE1", exp_id2,
                resource_instance2)
            session.commit()
        finally:
            session.close()

        resources = self.resources_manager.list_resources()
        self.assertEquals(2, len(resources))
        self.assertTrue('type1' in resources)
        self.assertTrue('type2' in resources)
コード例 #28
0
    def parse_configuration(self):
        #
        # configuration = {
        #      "laboratory1:WL_SERVER1@WL_MACHINE1" : {
        #                 ExperimentInstanceId("exp1", "ud-pld", "PLD Experiments") : ("pld1", "ud-pld-boards")
        #      }
        # }
        #
        configuration = {}

        laboratory_servers = self._cfg_manager.get_value(
            COORDINATOR_LABORATORY_SERVERS)
        for laboratory_server_coord_address_str in laboratory_servers:
            experiment_instances = laboratory_servers[
                laboratory_server_coord_address_str]

            laboratory_configuration = {}
            configuration[
                laboratory_server_coord_address_str] = laboratory_configuration

            for experiment_instance in experiment_instances:
                resource_instance = experiment_instances[experiment_instance]
                mo_experiment_instance = re.match(
                    self.EXPERIMENT_INSTANCE_REGEX, experiment_instance)
                if mo_experiment_instance is None:
                    raise coreExc.CoordinationConfigurationParsingError(
                        "Error in coordination parsing: %s doesn't match the regular expression %s"
                        %
                        (experiment_instance, self.EXPERIMENT_INSTANCE_REGEX))

                mo_resource_instance = re.match(self.RESOURCE_INSTANCE_REGEX,
                                                resource_instance)
                if mo_resource_instance is None:
                    raise coreExc.CoordinationConfigurationParsingError(
                        "Error in coordination parsing: %s doesn't match the regular expression %s"
                        % (resource_instance, self.RESOURCE_INSTANCE_REGEX))

                (inst_name, exp_name,
                 exp_cat_name) = mo_experiment_instance.groups()

                experiment_instance_id = ExperimentInstanceId(
                    inst_name, exp_name, exp_cat_name)

                (resource_instance,
                 resource_type) = mo_resource_instance.groups()

                resource = Resource(resource_type, resource_instance)

                laboratory_configuration[experiment_instance_id] = resource

        return configuration
コード例 #29
0
    def remove_resource_instance_id(self, experiment_instance_id):
        client = self._redis_maker()

        experiment_id_str = experiment_instance_id.to_experiment_id().to_weblab_str()
        weblab_experiment_instances = WEBLAB_EXPERIMENT_INSTANCES % experiment_id_str
        weblab_experiment_instance  = WEBLAB_EXPERIMENT_INSTANCE % (experiment_id_str, experiment_instance_id.inst_name)

        resource_instance = client.hget(weblab_experiment_instance, RESOURCE_INST)
        if resource_instance is not None:
            # else it does not exist
            resource = Resource.parse(resource_instance)
            weblab_resource_experiment_instances = WEBLAB_RESOURCE_INSTANCE_EXPERIMENTS % (resource.resource_type, resource.resource_instance)
            client.srem(weblab_experiment_instances, experiment_instance_id.inst_name)
            client.delete(weblab_experiment_instance)
            client.srem(weblab_resource_experiment_instances, experiment_instance_id.to_weblab_str())
コード例 #30
0
    def test_remove_resource_instance_id(self):
        exp_id = ExperimentInstanceId("exp1", "ud-pld", "PLD Experiments")
        self.resources_manager.add_experiment_instance_id(
            "laboratory1:WL_SERVER1@WL_MACHINE1", exp_id,
            Resource("type", "instance"))

        experiment_instances = self.resources_manager.list_experiment_instances_by_type(
            exp_id.to_experiment_id())
        self.assertEquals(1, len(experiment_instances))

        self.resources_manager.remove_resource_instance_id(exp_id)

        experiment_instances = self.resources_manager.list_experiment_instances_by_type(
            exp_id.to_experiment_id())
        self.assertEquals(0, len(experiment_instances))
コード例 #31
0
    def test_scheduler_reservation_associations(self):
        exp_inst_id1 = ExperimentInstanceId("exp1", "ud-pld",
                                            "PLD experiments")
        exp_inst_id1b = ExperimentInstanceId("exp2", "ud-pld",
                                             "PLD experiments")
        exp_inst_id2 = ExperimentInstanceId("exp1", "ud-fpga",
                                            "FPGA experiments")

        exp_id1 = exp_inst_id1.to_experiment_id()
        exp_id2 = exp_inst_id2.to_experiment_id()

        self.resources_manager.add_resource(Resource("pld_local", "instance"))
        self.resources_manager.add_resource(Resource("pld_remote", "instance"))
        self.resources_manager.add_resource(Resource("fpga_remote",
                                                     "instance"))

        self.resources_manager.add_experiment_instance_id(
            "laboratory1:WL_SERVER1@WL_MACHINE1", exp_inst_id1,
            Resource("pld_local", "instance"))
        self.resources_manager.add_experiment_instance_id(
            "laboratory1:WL_SERVER1@WL_MACHINE1", exp_inst_id1b,
            Resource("pld_remote", "instance"))
        self.resources_manager.add_experiment_instance_id(
            "laboratory1:WL_SERVER1@WL_MACHINE1", exp_inst_id2,
            Resource("fpga_remote", "instance"))

        reservation1 = 'reservation1'
        reservation2 = 'reservation2'

        self.resources_manager.associate_scheduler_to_reservation(
            reservation1, exp_id1, 'pld_local')
        self.resources_manager.associate_scheduler_to_reservation(
            reservation1, exp_id1, 'pld_remote')
        self.resources_manager.associate_scheduler_to_reservation(
            reservation2, exp_id2, 'fpga_remote')

        resource_type_names = self.resources_manager.retrieve_schedulers_per_reservation(
            reservation1, exp_id1)
        self.assertEquals(set(('pld_local', 'pld_remote')),
                          set(resource_type_names))
        resource_type_names = self.resources_manager.retrieve_schedulers_per_reservation(
            reservation2, exp_id2)
        self.assertEquals(['fpga_remote'], list(resource_type_names))

        self.resources_manager.dissociate_scheduler_from_reservation(
            reservation1, exp_id1, 'pld_remote')
        resource_type_names = self.resources_manager.retrieve_schedulers_per_reservation(
            reservation1, exp_id1)
        self.assertEquals(['pld_local'], list(resource_type_names))

        self.resources_manager.clean_associations_for_reservation(
            reservation1, exp_id1)

        resource_type_names = self.resources_manager.retrieve_schedulers_per_reservation(
            reservation1, exp_id1)
        self.assertEquals(0, len(resource_type_names))
コード例 #32
0
    def remove_resource_instance_id(self, experiment_instance_id):
        client = self._redis_maker()

        experiment_id_str = experiment_instance_id.to_experiment_id().to_weblab_str()
        weblab_experiment_instances = WEBLAB_EXPERIMENT_INSTANCES % experiment_id_str
        weblab_experiment_instance  = WEBLAB_EXPERIMENT_INSTANCE % (experiment_id_str, experiment_instance_id.inst_name)

        resource_instance = client.hget(weblab_experiment_instance, RESOURCE_INST)
        if resource_instance is not None:
            # else it does not exist
            resource = Resource.parse(resource_instance)
            weblab_resource_experiment_instances = WEBLAB_RESOURCE_INSTANCE_EXPERIMENTS % (resource.resource_type, resource.resource_instance)
            client.srem(weblab_experiment_instances, experiment_instance_id.inst_name)
            client.delete(weblab_experiment_instance)
            client.srem(weblab_resource_experiment_instances, experiment_instance_id.to_weblab_str())
コード例 #33
0
    def test_get_resource_instance_by_experiment_instance_id_failing(self):
        exp_id = ExperimentInstanceId("exp1", "ud-pld", "PLD Experiments")
        self.resources_manager.add_experiment_instance_id(
            "laboratory1:WL_SERVER1@WL_MACHINE1", exp_id,
            Resource("type", "instance"))

        exp_invalid_type = ExperimentInstanceId("exp1", "ud-pld.invalid",
                                                "PLD Experiments")

        self.assertRaises(
            CoordExc.ExperimentNotFoundError, self.resources_manager.
            get_resource_instance_by_experiment_instance_id, exp_invalid_type)

        exp_invalid_inst = ExperimentInstanceId("exp.invalid", "ud-pld",
                                                "PLD Experiments")
        self.assertRaises(
            CoordExc.ExperimentNotFoundError, self.resources_manager.
            get_resource_instance_by_experiment_instance_id, exp_invalid_inst)
コード例 #34
0
    def test_remove_resource_instance_id(self):
        session = self.session_maker()
        try:
            exp_id = ExperimentInstanceId("exp1", "ud-pld", "PLD Experiments")
            self.resources_manager.add_experiment_instance_id(
                "laboratory1:WL_SERVER1@WL_MACHINE1", exp_id,
                Resource("type", "instance"))

            experiment_instances = session.query(
                CoordinatorModel.ExperimentInstance).all()
            self.assertEquals(1, len(experiment_instances))

            self.resources_manager.remove_resource_instance_id(session, exp_id)

            experiment_instances = session.query(
                CoordinatorModel.ExperimentInstance).all()
            self.assertEquals(0, len(experiment_instances))

            session.commit()
        finally:
            session.close()
コード例 #35
0
    def list_laboratories_addresses(self):
        client = self._redis_maker()

        laboratory_addresses = {
            # laboratory_coord_address : {
            #         experiment_instance_id : resource_instance
            # }
        }

        for experiment_type in client.smembers(WEBLAB_EXPERIMENT_TYPES):
            experiment_id = ExperimentId.parse(experiment_type)
            experiment_instance_names = client.smembers(WEBLAB_EXPERIMENT_INSTANCES % experiment_type)
            for experiment_instance_name in experiment_instance_names:
                experiment_instance_id = ExperimentInstanceId(experiment_instance_name, experiment_id.exp_name, experiment_id.cat_name)
                weblab_experiment_instance = WEBLAB_EXPERIMENT_INSTANCE % (experiment_type, experiment_instance_name)
                laboratory_address = client.hget(weblab_experiment_instance, LAB_COORD)
                resource_str       = client.hget(weblab_experiment_instance, RESOURCE_INST)
                resource           = Resource.parse(resource_str)
                current            = laboratory_addresses.get(laboratory_address, {})
                current[experiment_instance_id] = resource
                laboratory_addresses[laboratory_address] = current

        return laboratory_addresses