def start_interactive_session(self, interactive_session_type, **kwargs):
        """Start an interactive workflow run.

        :param interactive_session_type: One of the available interactive
            session types.
        :return: Relative path to access the interactive session.
        """
        action_completed = True
        try:
            if (interactive_session_type not in INTERACTIVE_SESSION_TYPES):
                raise REANAInteractiveSessionError(
                    "Interactive type {} does not exist.".format(
                        interactive_session_type))
            access_path = self._generate_interactive_workflow_path()
            self.workflow.interactive_session_type = interactive_session_type
            self.workflow.interactive_session = access_path
            workflow_run_name = \
                self._workflow_run_name_generator(
                    'interactive', type=interactive_session_type)
            self.workflow.interactive_session_name = workflow_run_name
            kubernetes_objects = \
                build_interactive_k8s_objects[interactive_session_type](
                    workflow_run_name, self.workflow.workspace_path,
                    access_path,
                    access_token=self.workflow.get_owner_access_token(),
                    cvmfs_repos=self.retrieve_required_cvmfs_repos(),
                    **kwargs)

            instantiate_chained_k8s_objects(
                kubernetes_objects,
                KubernetesWorkflowRunManager.default_namespace)
            return access_path

        except KeyError:
            action_completed = False
            raise REANAInteractiveSessionError(
                "Unsupported interactive session type {}.".format(
                    interactive_session_type))
        except ApiException as api_exception:
            action_completed = False
            raise REANAInteractiveSessionError(
                "Connection to Kubernetes has failed:\n{}".format(
                    api_exception))
        except Exception as e:
            action_completed = False
            raise REANAInteractiveSessionError(
                "Unkown error while starting interactive workflow run:\n{}".
                format(e))
        finally:
            if not action_completed:
                self.workflow.interactive_session = None
                if kubernetes_objects:
                    delete_k8s_objects_if_exist(
                        kubernetes_objects,
                        KubernetesWorkflowRunManager.default_namespace)

            current_db_sessions = Session.object_session(self.workflow)
            current_db_sessions.add(self.workflow)
            current_db_sessions.commit()
Esempio n. 2
0
    def start_interactive_session(self, interactive_session_type, **kwargs):
        """Start an interactive workflow run.

        :param interactive_session_type: One of the available interactive
            session types.
        :return: Relative path to access the interactive session.
        """
        action_completed = True
        try:
            if interactive_session_type not in InteractiveSessionType.__members__:
                raise REANAInteractiveSessionError(
                    "Interactive type {} does not exist.".format(
                        interactive_session_type))
            access_path = self._generate_interactive_workflow_path()
            workflow_run_name = self._workflow_run_name_generator("session")
            kubernetes_objects = build_interactive_k8s_objects[
                interactive_session_type](
                    workflow_run_name,
                    self.workflow.workspace_path,
                    access_path,
                    access_token=self.workflow.get_owner_access_token(),
                    cvmfs_repos=self.retrieve_required_cvmfs_repos(),
                    **kwargs,
                )

            instantiate_chained_k8s_objects(
                kubernetes_objects, REANA_RUNTIME_KUBERNETES_NAMESPACE)

            # Save interactive session to the database
            int_session = InteractiveSession(
                name=workflow_run_name,
                path=access_path,
                type_=interactive_session_type,
                owner_id=self.workflow.owner_id,
            )
            self.workflow.sessions.append(int_session)
            current_db_sessions = Session.object_session(self.workflow)
            current_db_sessions.add(self.workflow)
            current_db_sessions.commit()

            return access_path

        except KeyError:
            action_completed = False
            raise REANAInteractiveSessionError(
                "Unsupported interactive session type {}.".format(
                    interactive_session_type))
        except ApiException as api_exception:
            action_completed = False
            raise REANAInteractiveSessionError(
                "Connection to Kubernetes has failed:\n{}".format(
                    api_exception))
        except Exception as e:
            action_completed = False
            raise REANAInteractiveSessionError(
                "Unkown error while starting interactive workflow run:\n{}".
                format(e))
        finally:
            if not action_completed and kubernetes_objects:
                delete_k8s_objects_if_exist(
                    kubernetes_objects, REANA_RUNTIME_KUBERNETES_NAMESPACE)