Beispiel #1
0
def ingest_status(request, uuid=None):
    # Equivalent to: "SELECT SIPUUID, MAX(createdTime) AS latest FROM Jobs WHERE unitType='unitSIP' GROUP BY SIPUUID
    objects = models.Job.objects.filter(hidden=False, subjobof='').values('sipuuid').annotate(timestamp=Max('createdtime')).exclude(sipuuid__icontains = 'None').filter(unittype__exact = 'unitSIP')
    mcp_available = False
    try:
        client = MCPClient()
        mcp_status = etree.XML(client.list())
        mcp_available = True
    except Exception: pass
    def encoder(obj):
        items = []
        for item in obj:
            # Check if hidden (TODO: this method is slow)
            if models.SIP.objects.is_hidden(item['sipuuid']):
                continue
            jobs = helpers.get_jobs_by_sipuuid(item['sipuuid'])
            item['directory'] = utils.get_directory_name(jobs[0])
            item['timestamp'] = calendar.timegm(item['timestamp'].timetuple())
            item['uuid'] = item['sipuuid']
            item['id'] = item['sipuuid']
            del item['sipuuid']
            item['jobs'] = []
            for job in jobs:
                newJob = {}
                item['jobs'].append(newJob)

                # allow user to know name of file that has failed normalization
                if job.jobtype == 'Access normalization failed - copying' or job.jobtype == 'Preservation normalization failed - copying' or job.jobtype == 'thumbnail normalization failed - copying':
                    task = models.Task.objects.get(job=job)
                    newJob['filename'] = task.filename

                newJob['uuid'] = job.jobuuid
                newJob['type'] = job.jobtype
                newJob['microservicegroup'] = job.microservicegroup
                newJob['subjobof'] = job.subjobof
                newJob['currentstep'] = job.currentstep
                newJob['timestamp'] = '%d.%s' % (calendar.timegm(job.createdtime.timetuple()), str(job.createdtimedec).split('.')[-1])
                try: mcp_status
                except NameError: pass
                else:
                    xml_unit = mcp_status.xpath('choicesAvailableForUnit[UUID="%s"]' % job.jobuuid)
                    if xml_unit:
                        xml_unit_choices = xml_unit[0].findall('choices/choice')
                        choices = {}
                        for choice in xml_unit_choices:
                            choices[choice.find("chainAvailable").text] = choice.find("description").text
                        newJob['choices'] = choices
            items.append(item)
        return items

    response = {}
    response['objects'] = objects
    response['mcp'] = mcp_available

    return HttpResponse(
        simplejson.JSONEncoder(default=encoder).encode(response),
        mimetype='application/json'
    )
Beispiel #2
0
def ingest_status(request, uuid=None):
    # Equivalent to: "SELECT SIPUUID, MAX(createdTime) AS latest FROM Jobs WHERE unitType='unitSIP' GROUP BY SIPUUID
    objects = models.Job.objects.filter(hidden=False, subjobof='').values('sipuuid').annotate(timestamp=Max('createdtime')).exclude(sipuuid__icontains = 'None').filter(unittype__exact = 'unitSIP')
    mcp_available = False
    try:
        client = MCPClient()
        mcp_status = etree.XML(client.list())
        mcp_available = True
    except Exception: pass
    def encoder(obj):
        items = []
        for item in obj:
            # Check if hidden (TODO: this method is slow)
            if models.SIP.objects.is_hidden(item['sipuuid']):
                continue
            jobs = helpers.get_jobs_by_sipuuid(item['sipuuid'])
            item['directory'] = utils.get_directory_name_from_job(jobs[0])
            item['timestamp'] = calendar.timegm(item['timestamp'].timetuple())
            item['uuid'] = item['sipuuid']
            item['id'] = item['sipuuid']
            del item['sipuuid']
            item['jobs'] = []
            for job in jobs:
                newJob = {}
                item['jobs'].append(newJob)

                # allow user to know name of file that has failed normalization
                if job.jobtype == 'Access normalization failed - copying' or job.jobtype == 'Preservation normalization failed - copying' or job.jobtype == 'thumbnail normalization failed - copying':
                    task = models.Task.objects.get(job=job)
                    newJob['filename'] = task.filename

                newJob['uuid'] = job.jobuuid
                newJob['type'] = job.jobtype
                newJob['microservicegroup'] = job.microservicegroup
                newJob['subjobof'] = job.subjobof
                newJob['currentstep'] = job.currentstep
                newJob['timestamp'] = '%d.%s' % (calendar.timegm(job.createdtime.timetuple()), str(job.createdtimedec).split('.')[-1])
                try: mcp_status
                except NameError: pass
                else:
                    xml_unit = mcp_status.xpath('choicesAvailableForUnit[UUID="%s"]' % job.jobuuid)
                    if xml_unit:
                        xml_unit_choices = xml_unit[0].findall('choices/choice')
                        choices = {}
                        for choice in xml_unit_choices:
                            choices[choice.find("chainAvailable").text] = choice.find("description").text
                        newJob['choices'] = choices
            items.append(item)
        return items

    response = {}
    response['objects'] = objects
    response['mcp'] = mcp_available

    return HttpResponse(
        json.JSONEncoder(default=encoder).encode(response),
        content_type='application/json'
    )
def list(request):
    client = MCPClient()
    jobs = etree.XML(client.list())
    response = ''
    if 0 < len(jobs):
        for job in jobs:
            response += etree.tostring(job)
    response = '<MCP>%s</MCP>' % response
    return HttpResponse(response, mimetype = 'text/xml')
Beispiel #4
0
def list(request):
    client = MCPClient(request.user)
    jobs = etree.XML(client.list())
    response = ""
    if 0 < len(jobs):
        for job in jobs:
            response += etree.tostring(job)
    response = "<MCP>%s</MCP>" % response
    return HttpResponse(response, content_type="text/xml")
Beispiel #5
0
def list(request):
    client = MCPClient()
    jobs = etree.XML(client.list())
    response = ''
    if 0 < len(jobs):
        for job in jobs:
            response += etree.tostring(job)
    response = '<MCP>%s</MCP>' % response
    return HttpResponse(response, mimetype='text/xml')
Beispiel #6
0
def status(request):
    client = MCPClient()
    xml = etree.XML(client.list())

    sip_count = len(xml.xpath('//choicesAvailableForUnits/choicesAvailableForUnit/unit/type[text()="SIP"]'))
    transfer_count = len(xml.xpath('//choicesAvailableForUnits/choicesAvailableForUnit/unit/type[text()="Transfer"]'))
    dip_count = len(xml.xpath('//choicesAvailableForUnits/choicesAvailableForUnit/unit/type[text()="DIP"]'))

    response = {'sip': sip_count, 'transfer': transfer_count, 'dip': dip_count}

    return HttpResponse(simplejson.JSONEncoder().encode(response), mimetype='application/json')
Beispiel #7
0
def status(request):
    client = MCPClient()
    xml = etree.XML(client.list())

    sip_count = len(xml.xpath('//choicesAvailableForUnits/choicesAvailableForUnit/unit/type[text()="SIP"]'))
    transfer_count = len(xml.xpath('//choicesAvailableForUnits/choicesAvailableForUnit/unit/type[text()="Transfer"]'))
    dip_count = len(xml.xpath('//choicesAvailableForUnits/choicesAvailableForUnit/unit/type[text()="DIP"]'))

    response = {'sip': sip_count, 'transfer': transfer_count, 'dip': dip_count}

    return helpers.json_response(response)
Beispiel #8
0
def status(request):
    client = MCPClient()
    xml = etree.XML(client.list())

    sip_count = len(
        xml.xpath(
            '//choicesAvailableForUnits/choicesAvailableForUnit/unit/type[text()="SIP"]'
        ))
    transfer_count = len(
        xml.xpath(
            '//choicesAvailableForUnits/choicesAvailableForUnit/unit/type[text()="Transfer"]'
        ))
    dip_count = len(
        xml.xpath(
            '//choicesAvailableForUnits/choicesAvailableForUnit/unit/type[text()="DIP"]'
        ))

    response = {'sip': sip_count, 'transfer': transfer_count, 'dip': dip_count}

    return HttpResponse(simplejson.JSONEncoder().encode(response),
                        mimetype='application/json')
Beispiel #9
0
def status(request, uuid=None):
    # Equivalent to: "SELECT SIPUUID, MAX(createdTime) AS latest FROM Jobs GROUP BY SIPUUID
    objects = models.Job.objects.filter(
        hidden=False, subjobof='',
        unittype__exact='unitTransfer').values('sipuuid').annotate(
            timestamp=Max('createdtime')).exclude(
                sipuuid__icontains='None').order_by('-timestamp')
    mcp_available = False
    try:
        client = MCPClient()
        mcp_status = etree.XML(client.list())
        mcp_available = True
    except Exception:
        pass

    def encoder(obj):
        items = []
        for item in obj:
            # Check if hidden (TODO: this method is slow)
            if models.Transfer.objects.is_hidden(item['sipuuid']):
                continue
            jobs = models.Job.objects.filter(sipuuid=item['sipuuid'],
                                             subjobof='').order_by(
                                                 '-createdtime', 'subjobof')
            item['directory'] = os.path.basename(
                utils.get_directory_name_from_job(jobs))
            item['timestamp'] = calendar.timegm(item['timestamp'].timetuple())
            item['uuid'] = item['sipuuid']
            item['id'] = item['sipuuid']
            del item['sipuuid']
            item['jobs'] = []
            for job in jobs:
                newJob = {}
                item['jobs'].append(newJob)
                newJob['uuid'] = job.jobuuid
                newJob['type'] = job.jobtype
                newJob['link_id'] = job.microservicechainlink.pk
                newJob['microservicegroup'] = job.microservicegroup
                newJob['subjobof'] = job.subjobof
                newJob['currentstep'] = job.currentstep
                newJob['currentstep_label'] = job.get_currentstep_display()
                newJob['timestamp'] = '%d.%s' % (calendar.timegm(
                    job.createdtime.timetuple()), str(
                        job.createdtimedec).split('.')[-1])
                try:
                    mcp_status
                except NameError:
                    pass
                else:
                    xml_unit = mcp_status.xpath(
                        'choicesAvailableForUnit[UUID="%s"]' % job.jobuuid)
                    if xml_unit:
                        xml_unit_choices = xml_unit[0].findall(
                            'choices/choice')
                        choices = {}
                        for choice in xml_unit_choices:
                            choices[choice.find("chainAvailable").
                                    text] = choice.find("description").text
                        newJob['choices'] = choices
            items.append(item)
        return items

    response = {}
    response['objects'] = objects
    response['mcp'] = mcp_available
    return HttpResponse(json.JSONEncoder(default=encoder).encode(response),
                        content_type='application/json')
Beispiel #10
0
def ingest_status(request, uuid=None):
    """Returns the status of the SIPs in ingest as a JSON object with an
    ``objects`` attribute that is an array of objects, each of which represents
    a single SIP. Each SIP object has a ``jobs`` attribute whose value is an
    array of objects, each of which represents a Job of the SIP.
    """
    sql = """
        SELECT SIPUUID,
                MAX(UNIX_TIMESTAMP(createdTime) + createdTimeDec) AS timestamp
            FROM Jobs
            WHERE unitType='unitSIP' AND NOT SIPUUID LIKE '%%None%%'
            GROUP BY SIPUUID;"""
    with connection.cursor() as cursor:
        cursor.execute(sql)
        sipuuids_and_timestamps = cursor.fetchall()
    mcp_available = False
    try:
        client = MCPClient()
        mcp_status = etree.XML(client.list())
        mcp_available = True
    except Exception:
        pass
    objects = []
    for sipuuid, timestamp in sipuuids_and_timestamps:
        timestamp = float(timestamp)
        item = {'sipuuid': sipuuid, 'timestamp': timestamp}
        # Check if hidden (TODO: this method is slow)
        if models.SIP.objects.is_hidden(sipuuid):
            continue
        jobs = models.Job.objects\
            .filter(sipuuid=item['sipuuid'], subjobof='')\
            .order_by('-createdtime', 'subjobof')
        item['directory'] = utils.get_directory_name_from_job(jobs)
        item['uuid'] = item['sipuuid']
        item['id'] = item['sipuuid']
        del item['sipuuid']
        item['jobs'] = []
        for job in jobs:
            newJob = {}
            item['jobs'].append(newJob)
            newJob['uuid'] = job.jobuuid
            newJob['type'] = job.jobtype
            newJob['microservicegroup'] = job.microservicegroup
            newJob['subjobof'] = job.subjobof
            newJob['currentstep'] = job.currentstep
            newJob['currentstep_label'] = job.get_currentstep_display()
            newJob['timestamp'] = '%d.%s' % (calendar.timegm(
                job.createdtime.timetuple()), str(
                    job.createdtimedec).split('.')[-1])
            try:
                mcp_status
            except NameError:
                pass
            else:
                xml_unit = mcp_status.xpath(
                    'choicesAvailableForUnit[UUID="%s"]' % job.jobuuid)
                if xml_unit:
                    xml_unit_choices = xml_unit[0].findall('choices/choice')
                    choices = {}
                    for choice in xml_unit_choices:
                        choices[choice.find("chainAvailable").
                                text] = choice.find("description").text
                    newJob['choices'] = choices
        objects.append(item)
    response = {}
    response['objects'] = objects
    response['mcp'] = mcp_available
    return HttpResponse(json.dumps(response), content_type='application/json')