def list_all_session_videos(self, session_id):
        """

        :param session_id:
        :return:
        """
        LOGGER.info(
            "Listing all session videos. [session_id={}]".format(session_id))
        GenericValidator.validate_id(session_id)
        session = SessionManager.get_instance().get_session(
            session_id=session_id)
        videos = Video.objects(session=session['id'])
        session_videos = DataTransformer.generate_video_list_view(
            session=session, db_videos=videos)
        for session_video in session_videos:
            try:
                session_video['ts'] = VideoEditorHelper.get_initial_ts(
                    video_id=session_video['video_id'])
            except Exception:
                LOGGER.warn(
                    "Could not retrieve timestmap of video. Skipping it...")
                session_video['ts'] = -1
        ordered_list = sorted(session_videos, key=lambda x: float(x['ts']))
        LOGGER.info("Retrieved {} videos for session {}".format(
            len(ordered_list), session_id))
        return ordered_list
Beispiel #2
0
    def create_video_directory(self, session_folder, user_id, video_name):
        """
        Cretes the folder in the FS for a new video.

        :param user_id: Id of the user.
        :param video_name: Name of the video.
        :return: Absolute path of the video folder.
        :rtype: str
        :raises: ValueError: If the provided parameters has no valid formats.
        """
        LOGGER.info(
            "Creating directory for video [video_name={}]".format(video_name))

        if video_name is None or type(video_name) != str or not video_name:
            raise ValueError("Expected a valid video name.")
        if session_folder is None or type(
                session_folder) != str or not session_folder:
            raise ValueError("Expected a valid session folder.")
        GenericValidator.validate_id(user_id)
        try:
            if session_folder[-1] != "/":
                session_folder = session_folder + "/"
            video_path = session_folder + user_id + "/" + video_name
            LOGGER.debug(
                "Built path for new video: [path={}]".format(video_path))
            makedirs(video_path, exist_ok=True)
            LOGGER.info(
                "Successfully created directory for video [path={}]".format(
                    video_path))
            return video_path
        except Exception as ex:
            LOGGER.exception("Error creating video directory: ")
            raise ex
    def add_thumbs_thread(self, t_thread, video_id):
        """
        This method adds an already started t_thumbs thread to the list of managed threads in
        order to monitor it.

        The t_thumbs parameter represents a ThumbsCreatorThread that has been created and
        started by an external entity. This method is responsible of adding the thread to the
        VideoThreadsRepository  and also to update the thumbs_status field of the related video
        in the Database.

        :param t_thumbs: Running instance of a ThumbsCreatorThread.
        :param video_id: Id of the video which  thumbs are being created by the t_thumbs thread.
        """
        LOGGER.info("Adding thumbs creator thread to VideoThreadsManager: [video_id={}]".
                    format(video_id))
        try:
            if t_thread is None or type(t_thread) != ThumbsCreatorThread:
                raise ValueError("parameter is not instance of ThumbsCreatorThread")
            GenericValidator.validate_id(video_id)
            video = Video.objects(id=video_id).first()
            if video is None:
                raise NotExistingResource("No video with such id")
            VideoThreadsRepository.get_instance().add_thumbs_thread(t_thread=t_thread,
                                                                    video_id=video_id)
            video.update(set__thumbs_status=ProcessStatus.IN_PROGRESS.value)
            LOGGER.info(
                "ThumbsCreatorThread sucessfully added to VideoThreadsManager: [video_id={}]".
                format(video_id))
        except Exception as ex:
            LOGGER.exception("Error adding ThumbsCreatorThread: ")
            raise ex
Beispiel #4
0
    def stop_session(self, session_id):
        """
        Stops an active session.

        Stopping a session means that no more users would be able to stream video to the server.
        Of course, only active sessions could be stopped.
        :param session_id: Id of the session to stop.
        :raises:
            - ValueError, if the specified id is not valid.
            - IllegalSessionStateException: If the session was not active.
        """
        LOGGER.info("Stopping session: [id={}]".format(session_id))
        GenericValidator.validate_id(session_id)
        session = self.get_session(session_id)
        valid_states = [
            SessionStatus.CREATED.value, SessionStatus.ACTIVE.value
        ]
        if session['state'] not in valid_states:
            raise IllegalSessionStateException(
                "Only active and initialized sessions can be stopped.")
        db_session = RumbaSession.objects(id=session_id).first()
        if session['state'] == SessionStatus.ACTIVE.value:
            LOGGER.info("Stopping audio recording.")
            AudioManager.get_instance().stop_audio()
        db_session.update(set__state=SessionStatus.FINISHED.value)
        LOGGER.info("Session successfully stopped: [id={}]".format(session_id))
    def add_dasher_splitter_thread(self, d_thread, video_id):
        """
        Method for adding a DashetSplitter thread to the list of managed threads.

        :param d_thread: DasherSplitter thread to be added.
        :param video_id: Id of the video that is being splitted by the DasherSplitter thread.
        :raises:
            - ValueError, if the provided thread is not a valid DasherSplitter thread or
            the id of the video is not valid.
            - IllegalResourceState, if there's already a thread splitting the video.
        """
        LOGGER.info("Adding DasherSplitter thread: [video_id={}]".format(video_id))
        if d_thread is None or type(d_thread) != DasherSplitterThread:
            raise ValueError("Parameter is not insfance of DasherSplitterThread")
        GenericValidator.validate_id(video_id)
        try:
            LOGGER.info("Locking DasherSplitter mutex.")
            self.dasher_spliter_mutex.acquire()
            d_thread_list = list(filter(lambda x: x['video_id'] == video_id, self.dasher_spliter_threads))
            if len(d_thread_list) > 0:
                raise IllegalResourceState("There's already a thread splitting the video.")
            self.dasher_spliter_threads.append({'thread': d_thread, 'video_id': video_id})
            LOGGER.info("DasherSplitterThread thread sucessfully added: [video_id={}]".format(video_id))
        finally:
            LOGGER.debug("Unlocking DasherSplitter mutex.")
            self.dasher_spliter_mutex.release()
Beispiel #6
0
    def initialize_session(self, session_id):
        """
        Initialize a created session.

        A session can only be initialized from the "Created" state. When a session is initialized,
        it starts to record the audio and its state is modified to "Active" state.

        :param session_id: Session to be created
        :raises:
        - IllegalSessionStateException, if the session is no in the "Created" state.
        - NotExistingResource, if there's no session with such id.
        """
        LOGGER.info("Initializing session. [session_id={}]".format(session_id))
        GenericValidator.validate_id(session_id)
        session = RumbaSession.objects(id=session_id).first()
        if session is None:
            raise NotExistingResource("There's no session with such id.")
        if session['state'] != SessionStatus.CREATED.value:
            raise IllegalSessionStateException(
                "Session can only be initialized from 'Created' state")
        LOGGER.debug("Initializing audio record.")
        initial_timestmap = AudioManager.get_instance().record_audio(
            session['folder_url'])
        try:
            LOGGER.debug("Updating session state.")
            session.update(set__state=SessionStatus.ACTIVE.value,
                           set__audio_timestamp=str(initial_timestmap))
        except Exception as ex:
            LOGGER.exception(
                "Could not update session state. Stopping audio recording...")
            AudioManager.get_instance().stop_audio()
            raise ex
    def add_thumbs_thread(self, t_thread, video_id):
        """
        Method for adding ThumbsCreator threads to the list of managed threads.

        :param t_thread: ThumbsCreator thread to be added.
        :param video_id: Id of the video which thumbs are being created by the thread.
        :raises
            - ValueError, If the provided thread is not a valid ThumbsCreator thread or
            the id of the video is not valid.
            - IllegalResourceState: If there's already a thread creating thumbs for this video.
        """
        LOGGER.info("Adding ThumbsCreator thread: [video_id={}]".format(video_id))
        if t_thread is None or type(t_thread) != ThumbsCreatorThread:
            raise ValueError("parameter is not instance of ThumbsCreatorThread")
        GenericValidator.validate_id(video_id)
        try:
            LOGGER.info("Locking Thumbs mutex.")
            self.thumbs_mutex.acquire()
            t_thread_list = list(filter(lambda x: x['video_id'] == video_id, self.thumbs_threads))
            if len(t_thread_list) > 0:
                raise IllegalResourceState("There's already a thread creating thumbs for this video.")
            self.thumbs_threads.append({'thread': t_thread, 'video_id': video_id})
            LOGGER.info("ThumbsCreator thread sucessfully added: [video_id={}]".format(video_id))
        finally:
            LOGGER.debug("Unlocking Thumbs mutex.")
            self.thumbs_mutex.release()
    def add_dasher_splitter_thread(self, d_thread, video_id):
        """
        This method adds an already started d_thumbs thread to the list of managed threads in
        order to monitor it.

        The d_thumbs parameter represents a DasherSplitterThread that has been crearted and started
        by an external entity. This method is responsible of adding the thread to the
        VideoThreadsRepository and also to update the splitter_status field of the related
        vie Database.

        :param d_thread: Runnig instance of a DasherSplitterThread.
        :param video_id: Id of the video which is being splitted.
        :raises:
            - NotExistingResource, if there's no video with such id.
            - ValueError, if the provided thread is not a valid DasherSplitterThread or if
            the video id has a wrong format.
        """
        LOGGER.info("Adding dasher splitter thread to VideoThreadsManager: [video_id={}]".format(
            video_id))
        try:
            if d_thread is None or type(d_thread) != DasherSplitterThread:
                raise ValueError("parameter is not instance of VideoThreadsManager")
            GenericValidator.validate_id(video_id)
            video = Video.objects(id=video_id).first()
            if video is None:
                raise NotExistingResource("No video with such id")
            VideoThreadsRepository.get_instance().add_dasher_splitter_thread(d_thread=d_thread,
                                                                             video_id=video_id)
            video.update(set__splitter_status=ProcessStatus.IN_PROGRESS.value)
            LOGGER.info(
                "DasherSplitterThread sucessfully added to VideoThreadsManager: [video_id={}]".
                format(video_id))
        except Exception as ex:
            LOGGER.exception("Error adding DasherSplitterThread: ")
            raise ex
 def list_user_videos(self, user_id):
     LOGGER.info(
         "Listing all videos of the user. [user_id={}]".format(user_id))
     GenericValidator.validate_id(user_id)
     videos = Video.objects(user_id=user_id)
     user_videos = DataTransformer.generate_user_video_list(
         db_videos=videos)
     LOGGER.info("Retrieved {} videos for user {}".format(
         len(user_videos), user_id))
     return user_videos
    def get_audio_init_ts(session_id):
        """

        :return:
        """
        GenericValidator.validate_id(session_id)
        session = RumbaSession.objects(id=session_id).first()
        if session is None:
            raise NotExistingResource("No session with such id.")
        ts = session['audio_timestamp']
        return ts
Beispiel #11
0
    def get_initial_ts(video_id):
        """

        :param video_id:
        :return:
        """
        GenericValidator.validate_id(video_id)
        video = Video.objects(id=video_id).first()
        if video is None:
            raise NotExistingResource("No video with such id.")
        video_path = video['video_path']
        ts_filename = "{}/ts.txt".format(video_path)
        file = open(ts_filename, "r")
        if not os.path.exists(ts_filename):
            raise NotExistingResource(
                "Video is still being recorded or it failed.")
        ts = file.read().rstrip("\n")
        return ts
 def __validate_video_edition_input__(self, session_id, edit_info):
     """
     Helper method for checking that the information provided by the editor to mouna video
     has valid data.
     :param session_id: Id of the rumba session.
     :param edit_info: The informtion provided by the editor containing the list of video slices.
     :raises: ValueError, if the information provided by the editor is not valid or has a wrong
     format.
     """
     LOGGER.info(
         "Starting video edition: [session_id={}]".format(session_id))
     try:
         LOGGER.debug("Validating user input")
         GenericValidator.validate_id(session_id)
         VideoValidator.validate_video_edit_info(edit_info)
         ## TODO check if all videos belong to the session.
     except ValueError as ex:
         LOGGER.exception("Error validating user input - ")
         raise ex
Beispiel #13
0
    def set_session_logo(self, session_id, image_file):
        """

        :param session_id:
        :param image_file:
        :return:
        """
        LOGGER.info("Setting session logo: [session_id={}]".format(session_id))
        try:
            GenericValidator.validate_id(session_id)
            FilesValidator.validate_image_format(image_file)
            session = self.get_session(session_id=session_id)
            FileSystemService.get_instance().save_session_logo(
                band=session['band'], logo=image_file)
            LOGGER.info(
                "Session logo successfully stored: [session_id={}]".format(
                    session_id))
        except Exception as ex:
            LOGGER.exception("Error setting session logo: ")
            raise ex
    def list_session_videos(self, session_id, user_id):
        """

        :param session_id:
        :param user_id:
        :return:
        """
        LOGGER.info(
            "Listing all session videos of the user. [session_id={}, user_id={}]"
            .format(session_id, user_id))
        GenericValidator.validate_id(session_id)
        GenericValidator.validate_id(user_id)
        session = SessionManager.get_instance().get_session(
            session_id=session_id)
        videos = Video.objects(session=session['id'], user_id=user_id)
        session_videos = DataTransformer.generate_video_list_view(
            session=session, db_videos=videos)
        LOGGER.info("Retrieved {} videos for session {} and user {}".format(
            len(session_videos), session_id, user_id))
        return session_videos
    def get_thumbs_thread(self, video_id):
        """
        Method for retrieving the ThumbsCreator thread that is creating threads for the video
        identified with the given id.

        :param video_id: Id of the video.
        :rtype: ThumbsCreatorThread
        """
        LOGGER.info("Getting ThumbsCreator thread: [video_id={}]".format(video_id))
        GenericValidator.validate_id(video_id)
        try:
            LOGGER.info("Locking Thumbs mutex.")
            self.thumbs_mutex.acquire()
            t_thread = list(filter(lambda x: x['video_id'] == video_id, self.thumbs_threads))
            if len(t_thread) == 0:
                raise NotExistingResource("There's no ThumbsCreator thread for this video.")
            LOGGER.info("ThumbsCreator thread sucessfully retrieved: [video_id={}]".format(video_id))
            return t_thread[0]['thread']
        finally:
            LOGGER.debug("Unlocking Thumbs mutex.")
            self.thumbs_mutex.release()
Beispiel #16
0
 def get_session_logo_url(self, session_id):
     """
     Method for retrieving the path where the session logo is stored.
     :param session_id: Id of the session.
     :return: URL containing the FS path where the logo is located.
     :rtype: str
     :raises:
         - SessionValidationException, if the session has no stored logo.
         - ValueError, if provided parameter is not a valid session name.
     """
     LOGGER.info("Getting session logo: [session_id={}]".format(session_id))
     try:
         GenericValidator.validate_id(session_id)
         session = self.get_session(session_id=session_id)
         url = FileSystemService.get_instance().get_session_logo_url(
             band=session['band'])
         LOGGER.info("Session logo URL successfully retrieved.")
         return url
     except Exception as ex:
         LOGGER.exception("Error getting session logo: ")
         raise ex
    def get_dasher_splitter_thread(self, video_id):
        """
        Method for retrieving the DasherSplitter thread that is using the dasher-basic to
        split the video in portions of 1 second.

        :param video_id: Id of the video.
        :rtype: DasherSplitterThread
        """
        LOGGER.info("Getting DasherSplitter thread: [video_id={}]".format(video_id))
        GenericValidator.validate_id(video_id)
        try:
            LOGGER.info("Locking DasherSplitter mutex.")
            self.dasher_spliter_mutex.acquire()
            d_thread = list(filter(lambda x: x['video_id'] == video_id, self.dasher_spliter_threads))
            if len(d_thread) == 0:
                raise NotExistingResource("There's no DasherSplitter thread for this video.")
            LOGGER.info("DasherSplitter thread sucessfully retrieved: [video_id={}]".format(video_id))
            return d_thread[0]['thread']
        finally:
            LOGGER.debug("Unlocking DasherSplitter mutex.")
            self.dasher_spliter_mutex.release()
    def cut_audio_for_user_video(session_id, video_id, video_init_ts,
                                 video_length):
        """

        :param session_id:
        :param video_id:
        :return:
        """
        GenericValidator.validate_id(session_id)
        GenericValidator.validate_id(video_id)
        session = RumbaSession.objects(id=session_id).first()
        if session is None:
            raise NotExistingResource("There's no session with such id.")
        video = Video.objects(id=video_id).first()
        if video is None:
            raise NotExistingResource("There's no video with such id.")
        audio_path = "{}/audio.wav".format(session['folder_url'])
        audio_output = "{}/audio-{}.wav".format(session['folder_url'],
                                                uuid.uuid4().hex)
        audio_init_ts = AudioManager.get_instance().get_audio_init_ts(
            session_id=session_id)
        audio_init_offset = VideoEditorHelper.calculate_audio_init_offset(
            audio_init_ts=audio_init_ts, video_init_ts=video_init_ts)
        ffmpeg_audio_init_offset = DataTransformer.transform_seconds_to_ffmpeg_offset(
            float(audio_init_offset))
        audio_end_offset = 12
        print("Video_id: {}".format(video_id))
        print("Video init ts: {}".format(video_init_ts))
        print("Audio init ts: {}".format(audio_init_ts))
        print("Audio init offset: {}".format(audio_init_offset))
        audio_thread = AudioSplitterThread(
            inputFile=audio_path,
            outputFile=audio_output,
            initial_offset=ffmpeg_audio_init_offset,
            end_offset=video_length)
        audio_thread.start()
        audio_thread.join()
        if audio_thread.code != 0:
            raise Exception("FFMpeg command failed.")
        return audio_output
    def stop_and_remove_thumbs_thread(self, video_id):
        """
        Stops and removes the ThumbsCreatorThread of a specific video.

        This method check if there's a ThumbsCreatorThread running for a specific video, which is
        is given as parameter. If the thread is still running, this method stops it and updates
        the database information, marking the thread as Failure. If the thread is not running, then
        this method checks the return code of the thread to mark the state in the DB as
        "Failure" or "Finished" depending on its value.

        :param video_id: Id of the video.
        :raises:
            - ValueError, if the given id os not a valid.
            - NotExistingResource, if there's no video with such id.
        """
        LOGGER.info("Removing thumbs creator thread from VideoThreadsManager: [video_id={}]".
                    format(video_id))
        try:
            GenericValidator.validate_id(video_id)
            t_thread = VideoThreadsRepository.get_instance().get_thumbs_thread(video_id=video_id)
            video = Video.objects(id=video_id).first()
            if video is None:
                raise NotExistingResource("No video with such id")
            # 1) If the thread is running,we stop it and mark it as failure in the db.
            if t_thread['thread'].is_alive():
                t_thread['thread'].exit()
                video.update(set__thumbs_status=ProcessStatus.FAILURE.value)
            # 2) If the thread finished, we check the return code and update the db.
            elif t_thread['thread'].code != 0:
                video.update(set__thumbs_status=ProcessStatus.FAILURE.value)
            else:
                video.update(set__thumbs_status=ProcessStatus.FINISHED.value)
            # 3) Finally we remove it from the REPOSITORY.
            VideoThreadsRepository.get_instance().remove_thumbs_thread(video_id=video_id)
            LOGGER.info(
                "Sucessfully removed thumbs creator thread from VideoThreadsManager: [video_id={}]".
                format(video_id))
        except Exception as ex:
            LOGGER.error("Error removing ThumbsCreatorThread: ")
            raise ex
    def merge_user_video(self, video_id):
        """
        Given the id of a video recorded by a user, it merges the video identified with such id
        with the audio of the session.

        A video can only be merged with the session audio if the record proces of the video
        is already finished.

        :param video_id: Id of the video.
        """
        GenericValidator.validate_id(video_id)
        video = Video.objects(id=video_id).first()
        if video is None:
            raise NotExistingResource("There's no video with such id.")
        video_init_ts = VideoEditorHelper.get_initial_ts(video_id=video_id)
        original_video = "{}/dasher-output/video.mp4".format(
            video['video_path'])
        t_video_length = VideoLengthThread(video_file=original_video)
        t_video_length.start()
        t_video_length.join()
        if (t_video_length.code != 0):
            raise Exception("Error merging audio and video of the user.")
        audio_path = AudioManager.cut_audio_for_user_video(
            session_id=str(video['session']['id']),
            video_id=video_id,
            video_init_ts=video_init_ts,
            video_length=t_video_length.output)
        output_file = "{}/dasher-output/video-mixed.mp4".format(
            video['video_path'])
        mixer = AudioVideoMixerThread(video_file=original_video,
                                      audio_file=audio_path,
                                      output_file=output_file)
        mixer.start()
        mixer.join()
        if mixer.code != 0:
            raise Exception(
                "Error merging user video with audio. FFmpeg command failed.")
        video.update(set__mixed=True)
        video.update(set__mixed_video_path=output_file)
 def stop_video(self, video_id):
     """
     
     :param video_id:
     :return:
     """
     LOGGER.info("Stopping video: [id={}]".format(video_id))
     try:
         GenericValidator.validate_id(video_id)
         video = Video.objects(id=video_id).first()
         if video is None:
             raise NotExistingResource("No video with such id")
         if video['finished']:
             raise IllegalResourceState("The video is already stopped.")
         video.update(set__finished=True)
         LOGGER.info("Video stopped: [id={}]".format(video_id))
     except ValueError as ve:
         LOGGER.exception("Error validating video id: ")
         raise ve
     except Exception as ex:
         LOGGER.exception("Error trying to stop video: ")
         raise ex
    def remove_thumbs_thread(self, video_id):
        """
        Method for removing ThumbsCreator thread  from the list of managed threads.

        :param video_id: Id of the video to remove.
        :raises
            - ValueError, if the video id is not a valid id.
            - NotExistingResource: If there's no thread creating thumbs for this video.
        """
        LOGGER.info("Removing ThumbsCreator thread: [video_id={}]".format(video_id))
        GenericValidator.validate_id(video_id)
        try:
            LOGGER.info("Locking Thumbs mutex.")
            self.thumbs_mutex.acquire()
            t_thread = list(filter(lambda x: x['video_id'] == video_id, self.thumbs_threads))
            if len(t_thread) == 0:
                raise NotExistingResource("There's no ThumbsCreator thread for this video.")
            self.thumbs_threads.remove(t_thread[0])
            LOGGER.info("ThumbsCreator thread sucessfully removed: [video_id={}]".format(video_id))
        finally:
            LOGGER.debug("Unlocking Thumbs mutex.")
            self.thumbs_mutex.release()
Beispiel #23
0
    def delete_session(self, session_id):
        """
        Removes a Rumba session.

        This method deletes from the database. Sessions can only be remoced if they have been
        stopped. In order to remove a live session, it is mandatory to remove it first.
        :param session_id: Id of the session to remove.
        :raises:
            - IllegalSessionStateException, if the session does not exist.
            - IlegalSessionStateException, if the session is active.
            - ValueError, if the provided id is not a valid id.
        """
        LOGGER.info("Removing session: [id={}]".format(session_id))
        GenericValidator.validate_id(session_id)
        session = self.get_session(session_id)
        if session['state'] == SessionStatus.ACTIVE.value:
            raise IllegalSessionStateException(
                "Session is active: it should be stopped first.")
        FileSystemService.get_instance().delete_session_directory(
            band=session['band'])
        RumbaSession.objects(id=session_id).delete()
        LOGGER.info("Session successfully removed: [id={}]".format(session_id))
    def split_video(self, video_id):
        """

        :param video_id:
        :return:
        """
        LOGGER.info("Splitting video in fragments: [id={}]".format(video_id))
        try:
            GenericValidator.validate_id(video_id)
            video = Video.objects(id=video_id).first()
            if video is None:
                raise NotExistingResource("No video with such id.")
            video_path = video['video_path']
            t_splitter = DasherSplitterThread(video_path=video_path)
            t_splitter.start()
            VideoThreadsManager.get_instance().add_dasher_splitter_thread(
                d_thread=t_splitter, video_id=video_id)
        except ValueError as ve:
            LOGGER.exception("Error validating video path: ")
            raise ve
        except Exception as ex:
            LOGGER.exception("Error trying to split video: ")
            raise ex
    def create_video_thumbs(self, video_id):
        """

        :param video_id:
        :return:
        """
        LOGGER.info("Creating thumbs for video: [id={}]".format(video_id))
        try:
            GenericValidator.validate_id(video_id)
            video = Video.objects(id=video_id).first()
            if video is None:
                raise NotExistingResource("No video with such id.")
            video_path = video['video_path']
            t_thumbs_creator = ThumbsCreatorThread(video_path=video_path)
            t_thumbs_creator.start()
            VideoThreadsManager.get_instance().add_thumbs_thread(
                t_thread=t_thumbs_creator, video_id=video_id)
        except ValueError as ve:
            LOGGER.exception("Error validating video path: ")
            raise ve
        except Exception as ex:
            LOGGER.exception("Error trying to create thumbs for video: ")
            raise ex
Beispiel #26
0
    def get_session(self, session_id):
        """
        Retrieves and returns the session identified with the given id.

        This method check if there's a session in the database with the provided id. If so, the
        information of the session is returned in a dictionary. If not, the method raises a
        IllegalSessionStateException.
        :return: Dictionary containing the information of the session identified with the id given
        as parameter.
        :raises:
        - NotExistingResource, if there's no session with such id.
        - ValueError, if the provided id is not a valid id.
        """
        LOGGER.info("Retrieveing session: [id={}].".format(session_id))
        GenericValidator.validate_id(session_id)
        session = RumbaSession.objects(id=session_id).first()
        if session is None:
            raise NotExistingResource("There's no session with such id.")
        LOGGER.info(
            "Session successfully retrieved: [id={}]".format(session_id))
        LOGGER.debug("Session information: {}".format(session))
        view_sess = MongoHelper.to_dict(session)
        view_sess.pop('folder_url')
        return view_sess