예제 #1
0
    def get_resource_instance_by_experiment_instance_id(self, experiment_instance_id):
        session = self._session_maker()
        try:
            experiment_type = session.query(ExperimentType).filter_by(cat_name = experiment_instance_id.cat_name, exp_name = experiment_instance_id.exp_name).first()
            if experiment_type is None:
                raise CoordExc.ExperimentNotFoundError("Experiment not found: %s" % experiment_instance_id)

            experiment_instance = session.query(ExperimentInstance).filter_by(experiment_type = experiment_type, experiment_instance_id = experiment_instance_id.inst_name).first()
            if experiment_instance is None:
                raise CoordExc.ExperimentNotFoundError("Experiment not found: %s" % experiment_instance_id)
            return experiment_instance.resource_instance.to_resource()
        finally:
            session.close()
예제 #2
0
 def _get_scheduler_aggregator(self, experiment_id):
     experiment_id_str = experiment_id.to_weblab_str()
     aggregator = self.aggregators.get(experiment_id_str)
     if aggregator is None:
         raise CoordExc.ExperimentNotFoundError(
             "Could not find scheduler aggregator associated to experiment id %s."
             % (experiment_id_str))
     return aggregator
예제 #3
0
    def get_resource_types_by_experiment_id(self, experiment_id):
        client = self._redis_maker()

        weblab_experiment_resources = WEBLAB_EXPERIMENT_RESOURCES % experiment_id.to_weblab_str()
        experiment_types = client.smembers(weblab_experiment_resources)
        if not client.exists(weblab_experiment_resources):
            raise CoordExc.ExperimentNotFoundError("Experiment not found: %s" % experiment_id)
        return set(experiment_types)
예제 #4
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)
예제 #5
0
    def list_sessions(self, experiment_id):
        """ list_sessions( experiment_id ) -> [ session_id ] """
        client = self._redis_maker()

        if not client.sismember(WEBLAB_EXPERIMENT_TYPES,
                                experiment_id.to_weblab_str()):
            raise CoordExc.ExperimentNotFoundError("Experiment %s not found" %
                                                   experiment_id)

        weblab_resource_reservations = WEBLAB_RESOURCE_RESERVATIONS % experiment_id.to_weblab_str(
        )
        return list(client.smembers(weblab_resource_reservations))
예제 #6
0
    def get_resource_types_by_experiment_id(self, experiment_id):
        session = self._session_maker()
        try:
            experiment_type = session.query(ExperimentType).filter_by(cat_name = experiment_id.cat_name, exp_name = experiment_id.exp_name).first()
            if experiment_type is None:
                raise CoordExc.ExperimentNotFoundError("Experiment not found: %s" % experiment_id)

            resource_types = set()
            for resource_type in experiment_type.resource_types:
                resource_types.add(resource_type.name)
            return resource_types
        finally:
            session.close()
    def list_sessions(self, experiment_id):
        """ list_sessions( experiment_id ) -> [ session_id ] """
        session = self._session_maker()
        try:
            experiment_type = session.query(ExperimentType).filter_by(
                exp_name=experiment_id.exp_name,
                cat_name=experiment_id.cat_name).first()
            if experiment_type is None:
                raise CoordExc.ExperimentNotFoundError(
                    "Experiment %s not found" % experiment_id)

            reservation_ids = []

            for reservation in experiment_type.reservations:
                reservation_ids.append(reservation.id)

        finally:
            session.close()

        return reservation_ids
예제 #8
0
    def create(session_maker, experiment_id, client_initial_data, server_initial_data, request_info, now = None):
        MAX_TRIES = 10
        counter = 0
        while True:
            session = session_maker()
            try:
                id = str(uuid.uuid4())
                experiment_type = session.query(ExperimentType).filter_by(exp_name = experiment_id.exp_name, cat_name = experiment_id.cat_name).first()
                if experiment_type is None:
                    raise CoordExc.ExperimentNotFoundError("Couldn't find experiment_type %s when creating Reservation" % experiment_id)

                reservation = Reservation(id, client_initial_data, server_initial_data, request_info, now)
                reservation.experiment_type = experiment_type
                session.add(reservation)
                try:
                    session.commit()
                    return reservation.id
                except sqlalchemy.exceptions.IntegrityError:
                    counter += 1
                    if counter == MAX_TRIES:
                        raise Exception("Couldn't create a session after %s tries" % MAX_TRIES)
            finally:
                session.close()