Ejemplo n.º 1
0
def get(event, context):
    """
    gets the information for the specific record in the dynamodb database
    """

    if 'pathParameters' in event:
        parameters = event['pathParameters']
        if 'sample' in parameters and 'job' in parameters:
            tm = TableManager()
            id = tm.generate_job_id(parameters['job'], parameters['sample'])
            table = tm.get_job_sample_state_table()

            result = table.query(
                KeyConditionExpression=Key('id').eq(id)
            )

            if "Items" in result and len(result['Items']) > 0:
                return {
                    "statusCode": 200,
                    "headers": __HTTP_HEADERS__,
                    "body": json.dumps(result['Items'][0])
                }
            else:
                return {
                    "statusCode": 404,
                    "headers": __HTTP_HEADERS__,
                    "body": json.dumps({"error": "no sample found with this identifier : {}".format(
                        event['pathParameters']['sample'])})
                }
        # invalid!
    return {
        'statusCode': 503
    }
Ejemplo n.º 2
0
def remove_sample_for_job(event, context):
    """
    remove a sample from a stored job
    """

    logger.info(event)
    if 'pathParameters' in event:
        parameters = event['pathParameters']
        if 'sample' in parameters and 'job' in parameters:
            tm = TableManager()
            rid = tm.generate_job_id(parameters['job'], parameters['sample'])
            trktable = tm.get_job_sample_state_table()

            logger.info(f"generated id: {rid}")
            try:
                saved = trktable.delete_item(Key={
                    'id': rid,
                    'job': parameters['job']
                })  # save or update our item

                logger.info(saved)
                return {
                    'body': '',
                    'statusCode': 200,
                    'isBase64Encoded': False,
                    'headers': __HTTP_HEADERS__
                }
            except Exception as e:

                traceback.print_exc()
                return {
                    'body': str(e),
                    'statusCode': 500,
                    'isBase64Encoded': False,
                    'headers': __HTTP_HEADERS__
                }
        return {'statusCode': 503}
Ejemplo n.º 3
0
def description(event, context):
    """
    returns the complete job description, which can be rather long
    """
    if 'pathParameters' in event:
        parameters = event['pathParameters']
        if 'job' in parameters:
            job = parameters['job']
            tm = TableManager()
            table = tm.get_job_sample_state_table()

            if 'psize' in event['pathParameters']:
                page_size = int(event['pathParameters']['psize'])
            else:
                page_size = 10

            query_params = {
                'IndexName': 'job-id-index',
                'Select': 'ALL_ATTRIBUTES',
                'KeyConditionExpression': Key('job').eq(job),
                'Limit': page_size
            }

            if 'last_key' in event['pathParameters']:
                logger.info(f"pagination mode, last key was {event['pathParameters']['last_key']}")

                query_params['ExclusiveStartKey'] = {
                    "job": job,
                    "id": event['pathParameters']['last_key']
                }

            result = table.query(**query_params
                                 )

            if "Items" in result and len(result['Items']) > 0:

                # here we now need to reference the actual stasis tracking table
                result = result['Items']

                result = list(filter(lambda x: x is not None,result))
                # kinda expensive and should be avoided
                final_result = []
                for x in result:
                    tracked_sample = get_tracked_sample(x['sample'])
                    if tracked_sample is None:
                        logger.info(f"the tracked sample was not found: {x['sample']}")
                    else:
                        x['history'] = get_tracked_sample(x['sample'])['status']
                        x['state'] = max(x['history'], key=lambda y: y['priority'])['value']
                        final_result.append(x)

                return {
                    "statusCode": 200,
                    "headers": __HTTP_HEADERS__,
                    "body": json.dumps(
                        final_result
                    )
                }
            else:
                return {
                    "statusCode": 404,
                    "headers": __HTTP_HEADERS__,
                    "body": json.dumps({"error": "no job found with this identifier : {}".format(
                        event['pathParameters']['job'])})
                }
        # invalid!
    return {
        'statusCode': 503
    }