Example #1
0
    def _process_use(self, use, reservation_id):
        """Given a reservation_id not present in the usage db, check if it is still running or waiting, or it did never enter the system"""
        if use is not None:
            if use == self._db_manager.forbidden_access:
                return ForbiddenReservationResult()
            if use.end_date is None:
                log.log(
                    UserProcessor, log.level.Debug,
                    "Reservation %s is running since end_time is None" %
                    reservation_id)
                return RunningReservationResult()
            storage_path = self._cfg_manager.get_value(
                'core_store_students_programs_path')
            use.load_files(storage_path)
            return FinishedReservationResult(use)

        try:
            # We don't actually care about the result. The question is: has it expired or is it running?
            status = self._coordinator.get_reservation_status(
                reservation_id.id)
            if status.status in WebLabSchedulingStatus.NOT_USED_YET_EXPERIMENT_STATUS:
                return WaitingReservationResult()
            else:
                log.log(
                    UserProcessor, log.level.Debug,
                    "Reservation %s is running due to status %r" %
                    (reservation_id, status))
                return RunningReservationResult()
        except coord_exc.ExpiredSessionError, ese:
            log.log(
                UserProcessor, log.level.Debug,
                "Reservation %s is cancelled due to expired session: %s" %
                (reservation_id, ese))
            return CancelledReservationResult()
    def test_return_get_experiment_use_by_id(self):
        expected_sess_id = SessionId.SessionId("whatever")

        expected_alive_result = WaitingReservationResult()
        self.mock_ups.return_values[
            'get_experiment_use_by_id'] = expected_alive_result

        alive_result = self.rfm.get_experiment_use_by_id(
            expected_sess_id, SessionId.SessionId('reservation'))
        self.assertEquals(expected_alive_result.status, alive_result.status)
    def test_return_get_experiment_uses_by_id(self):
        expected_sess_id = SessionId.SessionId("whatever")

        expected_usage = ExperimentUsage(10, time.time(),
                                         time.time(), '127.0.0.1',
                                         ExperimentId("exp", "cat"))

        command_sent = CommandSent(Command.Command("request"), time.time(),
                                   Command.Command("response"), time.time())
        expected_usage.append_command(command_sent)

        loaded_file_sent = LoadedFileSent('content-of-the-file', time.time(),
                                          Command.Command("response"),
                                          time.time(), 'program')
        expected_usage.append_file(loaded_file_sent)

        expected_finished_result = FinishedReservationResult(expected_usage)
        expected_alive_result = WaitingReservationResult()
        expected_cancelled_result = CancelledReservationResult()

        self.mock_ups.return_values['get_experiment_uses_by_id'] = (
            expected_finished_result, expected_alive_result,
            expected_cancelled_result)

        results = self.rfm.get_experiment_uses_by_id(
            expected_sess_id, (SessionId.SessionId('reservation'),
                               SessionId.SessionId('reservation2'),
                               SessionId.SessionId('reservation3')))

        self.assertEquals(3, len(results))
        self.assertEquals(expected_finished_result.status, results[0].status)
        self.assertEquals(expected_alive_result.status, results[1].status)
        self.assertEquals(expected_cancelled_result.status, results[2].status)

        self.assertEquals(expected_usage,
                          expected_finished_result.experiment_use)
Example #4
0
    def _parse_experiment_result(self, experiment_result):
        if experiment_result['status'] == ReservationResult.ALIVE:
            if experiment_result['running']:
                return RunningReservationResult()
            else:
                return WaitingReservationResult()
        elif experiment_result['status'] == ReservationResult.CANCELLED:
            return CancelledReservationResult()
        elif experiment_result['status'] == ReservationResult.FORBIDDEN:
            return ForbiddenReservationResult()

        experiment_use = experiment_result['experiment_use']

        experiment_id = ExperimentId(
            experiment_use['experiment_id']['exp_name'],
            experiment_use['experiment_id']['cat_name'])

        addr = experiment_use['coord_address']
        if 'machine_id' in addr:
            coord_address = CoordAddress(addr['machine_id'],
                                         addr['instance_id'],
                                         addr['server_id'])
        else:
            coord_address = CoordAddress(addr['host'], addr['process'],
                                         addr['component'])

        use = ExperimentUsage(experiment_use['experiment_use_id'],
                              experiment_use['start_date'],
                              experiment_use['end_date'],
                              experiment_use['from_ip'], experiment_id,
                              experiment_use['reservation_id'], coord_address,
                              experiment_use['request_info'])
        for sent_file in experiment_use['sent_files']:
            response = Command(
                sent_file['response']['commandstring']
            ) if 'commandstring' in sent_file['response'] and sent_file[
                'response'] is not None else NullCommand
            if sent_file['file_info'] == {}:
                file_info = None
            else:
                file_info = sent_file['file_info']
            unserialized_sent_file = LoadedFileSent(
                sent_file['file_content'], sent_file['timestamp_before'],
                response, sent_file['timestamp_after'], file_info)
            use.append_file(unserialized_sent_file)

        for command in experiment_use['commands']:
            request = Command(
                command['command']['commandstring']
            ) if 'commandstring' in command['command'] and command[
                'command'] is not None else NullCommand
            response_command = command['response'][
                'commandstring'] if 'commandstring' in command[
                    'response'] and command['response'] is not None else None
            if response_command is None or response_command == {}:
                response = NullCommand()
            else:
                response = Command(response_command)

            if command['timestamp_after'] is None or command[
                    'timestamp_after'] == {}:
                timestamp_after = None
            else:
                timestamp_after = command['timestamp_after']
            unserialized_command = CommandSent(request,
                                               command['timestamp_before'],
                                               response, timestamp_after)
            use.append_command(unserialized_command)
        return FinishedReservationResult(use)