Esempio n. 1
0
    def _collateral(
        self,
        project_uuid: str,
        pipeline_uuid: str,
        pipeline_path: str,
        project_dir: str,
        host_userdir: str,
    ):
        session = InteractiveSession(docker_client, network=_config.DOCKER_NETWORK)
        session.launch(
            pipeline_uuid,
            project_uuid,
            pipeline_path,
            project_dir,
            host_userdir,
        )

        # Update the database entry with information to connect to the
        # launched resources.
        IP = session.get_containers_IP()
        status = {
            "status": "RUNNING",
            "container_ids": session.get_container_IDs(),
            "jupyter_server_ip": IP.jupyter_server,
            "notebook_server_info": session.notebook_server_info,
        }
        models.InteractiveSession.query.filter_by(
            project_uuid=project_uuid, pipeline_uuid=pipeline_uuid
        ).update(status)
        db.session.commit()
Esempio n. 2
0
    def _background_session_start(
        cls,
        app,
        project_uuid: str,
        pipeline_uuid: str,
        pipeline_path: str,
        project_dir: str,
        host_userdir: str,
    ):

        with app.app_context():
            try:
                session = InteractiveSession(docker_client,
                                             network=_config.DOCKER_NETWORK)
                session.launch(
                    pipeline_uuid,
                    project_uuid,
                    pipeline_path,
                    project_dir,
                    host_userdir,
                )

                # Update the database entry with information to connect
                # to the launched resources.
                IP = session.get_containers_IP()

                # with for update to avoid overwriting the state of a
                # STOPPING instance.
                session_entry = (
                    models.InteractiveSession.query.with_for_update(
                    ).populate_existing().filter_by(
                        project_uuid=project_uuid,
                        pipeline_uuid=pipeline_uuid).one_or_none())
                if session_entry is None:
                    return

                session_entry.container_ids = session.get_container_IDs()
                session_entry.jupyter_server_ip = IP.jupyter_server
                session_entry.notebook_server_info = session.notebook_server_info

                # Do not overwrite the STOPPING status if the session is
                # stopping.
                if session_entry.status == "LAUNCHING":
                    session_entry.status = "RUNNING"

                db.session.commit()
            except Exception as e:
                current_app.logger.error(e)

                # Error handling. If it does not succeed then the
                # initial entry has to be removed from the database as
                # otherwise no session can be started in the future due
                # to the uniqueness constraint.
                models.InteractiveSession.query.filter_by(
                    project_uuid=project_uuid,
                    pipeline_uuid=pipeline_uuid).delete()
                db.session.commit()
Esempio n. 3
0
    def post(self):
        """Launches an interactive session."""
        post_data = request.get_json()

        # TODO: error handling. If it does not succeed then the initial
        #       entry has to be removed from the database as otherwise
        #       no session can be started in the future due to unique
        #       constraint.

        # Add initial entry to database.
        pipeline_uuid = post_data["pipeline_uuid"]
        pipeline_path = post_data["pipeline_path"]
        project_uuid = post_data["project_uuid"]

        interactive_session = {
            "project_uuid": project_uuid,
            "pipeline_uuid": pipeline_uuid,
            "status": "LAUNCHING",
        }
        db.session.add(models.InteractiveSession(**interactive_session))
        db.session.commit()

        session = InteractiveSession(docker_client, network="orchest")
        session.launch(
            pipeline_uuid,
            project_uuid,
            pipeline_path,
            post_data["project_dir"],
            post_data["settings"]["data_passing_memory_size"],
            post_data["host_userdir"],
        )

        # Update the database entry with information to connect to the
        # launched resources.
        IP = session.get_containers_IP()
        interactive_session.update({
            "status":
            "RUNNING",
            "container_ids":
            session.get_container_IDs(),
            "jupyter_server_ip":
            IP.jupyter_server,
            "notebook_server_info":
            session.notebook_server_info,
        })
        models.InteractiveSession.query.filter_by(
            project_uuid=project_uuid,
            pipeline_uuid=pipeline_uuid).update(interactive_session)
        db.session.commit()

        return interactive_session, 201
Esempio n. 4
0
    def _background_session_start(
        cls,
        app,
        project_uuid: str,
        pipeline_uuid: str,
        pipeline_path: str,
        project_dir: str,
        host_userdir: str,
    ):

        with app.app_context():
            try:
                session = InteractiveSession(docker_client,
                                             network=_config.DOCKER_NETWORK)
                session.launch(
                    pipeline_uuid,
                    project_uuid,
                    pipeline_path,
                    project_dir,
                    host_userdir,
                )

                # Update the database entry with information to connect
                # to the launched resources.
                IP = session.get_containers_IP()
                status = {
                    "status": "RUNNING",
                    "container_ids": session.get_container_IDs(),
                    "jupyter_server_ip": IP.jupyter_server,
                    "notebook_server_info": session.notebook_server_info,
                }

                models.InteractiveSession.query.filter_by(
                    project_uuid=project_uuid,
                    pipeline_uuid=pipeline_uuid).update(status)
                db.session.commit()
            except Exception as e:
                current_app.logger.error(e)

                # Error handling. If it does not succeed then the
                # initial entry has to be removed from the database as
                # otherwise no session can be started in the future due
                # to the uniqueness constraint.
                models.InteractiveSession.query.filter_by(
                    project_uuid=project_uuid,
                    pipeline_uuid=pipeline_uuid).delete()
                db.session.commit()
Esempio n. 5
0
    def post(self):
        """Launches an interactive session."""
        post_data = request.get_json()

        # TODO: error handling. If it does not succeed then the initial
        #       entry has to be removed from the database as otherwise
        #       no session can be started in the future due to unique
        #       constraint.

        # Add initial entry to database.
        pipeline_uuid = post_data['pipeline_uuid']
        interactive_session = {
            'pipeline_uuid': pipeline_uuid,
            'status': 'LAUNCHING',
        }
        db.session.add(models.InteractiveSession(**interactive_session))
        db.session.commit()

        session = InteractiveSession(docker_client, network='orchest')
        session.launch(pipeline_uuid, post_data['pipeline_dir'],
                       post_data['host_userdir'])

        # Update the database entry with information to connect to the
        # launched resources.
        IP = session.get_containers_IP()
        interactive_session.update({
            'status':
            'RUNNING',
            'container_ids':
            session.get_container_IDs(),
            'jupyter_server_ip':
            IP.jupyter_server,
            'notebook_server_info':
            session.notebook_server_info,
        })
        models.InteractiveSession.query \
            .filter_by(pipeline_uuid=pipeline_uuid) \
            .update(interactive_session)
        db.session.commit()

        return interactive_session, 201