コード例 #1
0
    def get(self, request, ingest_job_id):
        """
        Get the status of an ingest_job and number of messages in the upload queue
        Args:
            request: Django Rest framework object
            ingest_job_id: Ingest job id

        Returns: Status of the job

        """
        try:
            ingest_mgmr = IngestManager()
            ingest_job = ingest_mgmr.get_ingest_job(ingest_job_id)

            # Check if user is the ingest job creator or the sys admin
            if not self.is_user_or_admin(request, ingest_job):
                return BossHTTPError(
                    "Only the creator or admin can check the status of an ingest job",
                    ErrorCodes.INGEST_NOT_CREATOR)

            if ingest_job.status == 3:
                # Deleted Job
                raise BossError(
                    "The job with id {} has been deleted".format(
                        ingest_job_id), ErrorCodes.INVALID_REQUEST)
            else:
                if ingest_job.status == 2:
                    # Job is Complete so queues are gone
                    num_messages_in_queue = 0
                else:
                    upload_queue = ingest_mgmr.get_ingest_job_upload_queue(
                        ingest_job)
                    num_messages_in_queue = int(
                        upload_queue.queue.
                        attributes['ApproximateNumberOfMessages'])
                    if num_messages_in_queue < ingest_job.tile_count:
                        for n in range(9):
                            num_messages_in_queue += int(
                                upload_queue.queue.
                                attributes['ApproximateNumberOfMessages'])
                        num_messages_in_queue /= 10

                data = {
                    "id": ingest_job.id,
                    "status": ingest_job.status,
                    "total_message_count": ingest_job.tile_count,
                    "current_message_count": int(num_messages_in_queue)
                }

            return Response(data, status=status.HTTP_200_OK)
        except BossError as err:
            return err.to_http()
        except Exception as err:
            return BossError("{}".format(err),
                             ErrorCodes.BOSS_SYSTEM_ERROR).to_http()
コード例 #2
0
ファイル: views.py プロジェクト: ndrenkow/boss
    def get(self, request, ingest_job_id):
        """

        Args:
            job_id:

        Returns:

        """
        try:
            ingest_mgmr = IngestManager()
            ingest_job = ingest_mgmr.get_ingest_job(ingest_job_id)
            serializer = IngestJobListSerializer(ingest_job)
            print(serializer.data)

            # Start setting up output
            data = {}
            data['ingest_job'] = serializer.data
            if ingest_job.status == 3 or ingest_job.status == 2:
                # Return the information for the deleted job/completed job
                return Response(data, status=status.HTTP_200_OK)
            elif ingest_job.status == 0:
                # check if all message are in the upload queue
                upload_queue = ingest_mgmr.get_ingest_job_upload_queue(
                    ingest_job)
                if int(upload_queue.queue.
                       attributes['ApproximateNumberOfMessages']) == int(
                           ingest_job.tile_count):
                    #generate credentials
                    ingest_job.status = 1
                    ingest_job.save()
                elif int(upload_queue.queue.
                         attributes['ApproximateNumberOfMessages']) > int(
                             ingest_job.tile_count):
                    # This indicates an error in the lambda
                    raise BossError(
                        "Error generating ingest job messages due to resources timing out ."
                        " Delete the ingest job with id {} and try again.".
                        format(ingest_job_id), ErrorCodes.BOSS_SYSTEM_ERROR)

            if ingest_job.status == 1:
                data['ingest_job']['status'] = 1
                ingest_creds = IngestCredentials()
                data['credentials'] = ingest_creds.get_credentials(
                    ingest_job.id)
            else:
                data['credentials'] = None

            data['tile_bucket_name'] = ingest_mgmr.get_tile_bucket()
            data['KVIO_SETTINGS'] = settings.KVIO_SETTINGS
            data['STATEIO_CONFIG'] = settings.STATEIO_CONFIG
            data['OBJECTIO_CONFIG'] = settings.OBJECTIO_CONFIG

            # add the lambda - Possibly remove this later
            config = bossutils.configuration.BossConfig()
            data['ingest_lambda'] = config["lambda"]["page_in_function"]

            # Generate a "resource" for the ingest lambda function to be able to use SPDB cleanly
            collection = Collection.objects.get(
                name=data['ingest_job']["collection"])
            experiment = Experiment.objects.get(
                name=data['ingest_job']["experiment"], collection=collection)
            channel = Channel.objects.get(name=data['ingest_job']["channel"],
                                          experiment=experiment)

            resource = {}
            resource['boss_key'] = '{}&{}&{}'.format(
                data['ingest_job']["collection"],
                data['ingest_job']["experiment"],
                data['ingest_job']["channel"])
            resource['lookup_key'] = '{}&{}&{}'.format(collection.id,
                                                       experiment.id,
                                                       channel.id)
            resource['channel'] = {}
            resource['channel']['name'] = channel.name
            resource['channel']['description'] = ""
            resource['channel']['type'] = channel.type
            resource['channel']['datatype'] = channel.datatype
            resource['channel']['base_resolution'] = channel.base_resolution
            resource['channel']['sources'] = [
                x.name for x in channel.sources.all()
            ]
            resource['channel']['related'] = [
                x.name for x in channel.related.all()
            ]
            resource['channel'][
                'default_time_sample'] = channel.default_time_sample

            # Set resource
            data['resource'] = resource

            return Response(data, status=status.HTTP_200_OK)
        except BossError as err:
            return err.to_http()
        except Exception as err:
            return BossError("{}".format(err),
                             ErrorCodes.BOSS_SYSTEM_ERROR).to_http()