Beispiel #1
0
 def archivedNotebooks():
     """
     Get archived notebooks
     """
     res = ApiResponse(message="Error retrieving archived notebooks")
     notebooks = Zeppelin.getAllNotebooks("~Trash")
     if notebooks:
         res.update(True, "Archived notebooks retrieved successfully",
                    notebooks)
     return res
 def getNotebooks(offset: int = 0):
     """
     Service to fetch and serialize NotebookJob objects
     Number of NotebookJobs fetched is stored as the constant GET_NOTEBOOKJOBS_LIMIT
     :param offset: Offset for fetching NotebookJob objects
     """
     res = ApiResponse(message="Error retrieving notebooks")
     notebooks = Zeppelin.getAllNotebooks()
     if notebooks:
         notebookCount = len(notebooks)
         notebooks = notebooks[offset:offset + GET_NOTEBOOKJOBS_LIMIT]
         notebookIds = [notebook["id"] for notebook in notebooks]
         notebookJobs = NotebookJob.objects.filter(
             notebookId__in=notebookIds)
         for notebook in notebooks:
             notebook["name"] = notebook["path"]
             notebookJob = next((notebookJob for notebookJob in notebookJobs
                                 if notebookJob.name == notebook["id"]),
                                False)
             if notebookJob:
                 notebook["isScheduled"] = True
                 notebook["schedule"] = str(notebookJob.crontab)
                 notebook["isActive"] = notebookJob.enabled
                 notebook["notebookJobId"] = notebookJob.id
             else:
                 notebook["isScheduled"] = False
             notebookRunStatus = RunStatus.objects.filter(
                 notebookId=notebook["id"]).order_by(
                     "-startTimestamp").first()
             if notebookRunStatus:
                 notebook["lastRun"] = RunStatusSerializer(
                     notebookRunStatus).data
         res.update(True, "NotebookJobs retrieved successfully", {
             "notebooks": notebooks,
             "count": notebookCount
         })
     return res
Beispiel #3
0
 def getNotebooksLight():
     """ Gets concise notebook data"""
     res = ApiResponse(message="Error retrieving notebooks")
     notebooks = Zeppelin.getAllNotebooks()
     res.update(True, "Notebooks retrieved successfully", notebooks)
     return res
Beispiel #4
0
    def getNotebooks(offset: int = 0,
                     limit: int = None,
                     searchQuery: str = None,
                     sorter: dict = None,
                     _filter: dict = None):
        """
        Service to fetch and serialize NotebookJob objects
        Number of NotebookObjects fetched is stored as the constant GET_NOTEBOOKOJECTS_LIMIT
        :param offset: Offset for fetching NotebookJob objects
        """
        res = ApiResponse(message="Error retrieving notebooks")
        notebooks = Zeppelin.getAllNotebooks()
        if searchQuery:
            notebooks = NotebookJobServices.search(notebooks, "path",
                                                   searchQuery)
        if sorter.get('order', False):
            notebooks = NotebookJobServices.sortingOnNotebook(
                notebooks, sorter, _filter)
        if notebooks:
            notebookCount = len(notebooks)
            notebooks = notebooks[offset:offset + GET_NOTEBOOKOJECTS_LIMIT]
            notebookIds = [notebook["id"] for notebook in notebooks]
            notebookObjects = NotebookObject.objects.filter(
                notebookZeppelinId__in=notebookIds)
            notebookJobs = NotebookJob.objects.filter(
                notebookId__in=notebookIds)
            for notebook in notebooks:
                notebook["name"] = notebook["path"]
                notebookObj = next(
                    (notebookObj for notebookObj in notebookObjects
                     if notebookObj.notebookZeppelinId == notebook["id"]),
                    False)
                if notebookObj:
                    notebook["notebookObjId"] = notebookObj.id
                notebookJob = next(
                    (notebookJob for notebookJob in notebookJobs
                     if notebookJob.notebookId == notebook["id"]), False)
                if notebookJob:
                    notebook["isScheduled"] = True
                    notebook["schedule"] = str(
                        notebookJob.crontab.customschedule.name)
                    notebook["isActive"] = notebookJob.enabled
                    notebook["notebookJobId"] = notebookJob.id
                else:
                    notebook["isScheduled"] = False

                assignedWorkflowId = WorkflowNotebookMap.objects.filter(
                    notebookId=notebook["id"]).values_list("workflow_id",
                                                           flat=True)
                names = Workflow.objects.filter(
                    id__in=assignedWorkflowId).values_list('name', flat=True)
                workflowNames = []
                for name in names:
                    workflowNames.append(name)
                notebook["assignedWorkflow"] = workflowNames
                notebookRunLogs = NotebookRunLogs.objects.filter(
                    notebookId=notebook["id"]).order_by(
                        "-startTimestamp").first()
                if notebookRunLogs:
                    notebook[
                        "notebookStatus"] = notebookRunLogs.status if notebookRunLogs.status else None
                    notebook["lastRun"] = NotebookRunLogsSerializer(
                        notebookRunLogs).data
            res.update(True, "NotebookObjects retrieved successfully", {
                "notebooks": notebooks,
                "count": notebookCount
            })
        else:
            res.update(True, "NotebookObjects retrieved successfully", [])
        return res