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
Beispiel #2
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
    def list_experiment_instance_ids_by_resource(self, resource):
        client = self._redis_maker()

        experiment_instance_ids = []

        weblab_resource_instance_experiments = WEBLAB_RESOURCE_INSTANCE_EXPERIMENTS % (resource.resource_type, resource.resource_instance)
        current_members = client.smembers(weblab_resource_instance_experiments) or []
        for member in current_members:
            experiment_instance_id = ExperimentInstanceId.parse(member)
            experiment_instance_ids.append(experiment_instance_id)

        return experiment_instance_ids
    def remove_resource_instance(self, resource):
        client = self._redis_maker()

        weblab_resource = WEBLAB_RESOURCE % resource.resource_type
        if client.srem(weblab_resource, resource.resource_instance):
            # else it did not exist
            weblab_resource_instance_experiments = WEBLAB_RESOURCE_INSTANCE_EXPERIMENTS % (resource.resource_type, resource.resource_instance)
            experiment_instances = client.smembers(weblab_resource_instance_experiments) or []
            client.delete(weblab_resource_instance_experiments)
            for experiment_instance in experiment_instances:
                experiment_instance_id = ExperimentInstanceId.parse(experiment_instance)
                self.remove_resource_instance_id(experiment_instance_id)
    def list_experiment_instance_ids_by_resource(self, resource):
        client = self._redis_maker()

        experiment_instance_ids = []

        weblab_resource_instance_experiments = WEBLAB_RESOURCE_INSTANCE_EXPERIMENTS % (resource.resource_type, resource.resource_instance)
        current_members = client.smembers(weblab_resource_instance_experiments) or []
        for member in current_members:
            experiment_instance_id = ExperimentInstanceId.parse(member)
            experiment_instance_ids.append(experiment_instance_id)

        return experiment_instance_ids
    def remove_resource_instance(self, resource):
        client = self._redis_maker()

        weblab_resource = WEBLAB_RESOURCE % resource.resource_type
        if client.srem(weblab_resource, resource.resource_instance):
            # else it did not exist
            weblab_resource_instance_experiments = WEBLAB_RESOURCE_INSTANCE_EXPERIMENTS % (resource.resource_type, resource.resource_instance)
            experiment_instances = client.smembers(weblab_resource_instance_experiments) or []
            client.delete(weblab_resource_instance_experiments)
            for experiment_instance in experiment_instances:
                experiment_instance_id = ExperimentInstanceId.parse(experiment_instance)
                self.remove_resource_instance_id(experiment_instance_id)