Ejemplo n.º 1
0
def failed_report():

    if not request.is_json:
        return "INVALID: Request is not json"    
    proposal = request.get_json()
    # Checks the required fields
    req_fields = ["date (Run)", "VolCon-ID", "download time", "Error"]
    req_check = l2_contains_l1(req_fields, proposal.keys())

    if req_check != []:
        return "INVALID: Lacking the following json fields to be read: "+",".join([str(a) for a in req_check])

    VolCon_ID = proposal["VolCon-ID"]
    if not mints.VolCon_ID_exists(VolCon_ID):
        return "INVALID: VolCon-ID does not exist"

    date_run = proposal["date (Run)"]
    download_time = proposal["download time"]
    received_time = mints.timnow()
    Error = proposal["Error"]
    outcome = Error

    user_token = mints.token_from_VolCon_ID(VolCon_ID)
    researcher_email = email_from_token(user_token)

    # Sends email to user, no attachments since the job did not run
    email_notification = ec.send_mail_complete(researcher_email, "BOINC job failed", ec.automatic_text(received_time, outcome, user_token, []),
                    [])

    client_IP = request.environ['REMOTE_ADDR']

    # Updates the database
    mints.failed_execution_report(VolCon_ID, date_run, download_time, Error, email_notification, client_IP)

    return "Server has processed the results"
Ejemplo n.º 2
0
def results_upload(VID):

    prestime = mints.timnow()

    # Checks out if the given VolCon-ID exists in database
    if not mints.VolCon_ID_exists(VID):
        return "INVALID: VolCon-ID does not exist"

    try:
        file = request.files["file"]
    except:
        return "INVALID, file not provided"

    # Always in the same location
    location = "/results/volcon/"+present_day()

    # Creates directory if needed
    if present_day() not in os.listdir("/results/volcon"):
        # Creates directory, avoids race conditions
        try:
            os.mkdir(location)
        except:
            pass

    new_name = secure_filename(file.filename)
    # Saves the file
    file.save(location+"/"+new_name)

    # Saves the location of the file
    mints.update_results_path_apache(VID, location+"/"+new_name)

    # Updates the status in the database
    mints.update_job_status(VID, "Results received", False)

    return "Results uploaded"
Ejemplo n.º 3
0
def upload_report():

    if not request.is_json:
        return "INVALID: Request is not json"    
    proposal = request.get_json()
    # Checks the required fields
    req_fields = ["date (Run)", "VolCon-ID", "download time", "Commands", "Result Error", "computation time"]
    req_check = l2_contains_l1(req_fields, proposal.keys())

    if req_check != []:
        return "INVALID: Lacking the following json fields to be read: "+",".join([str(a) for a in req_check])

    VolCon_ID = proposal["VolCon-ID"]
    if not mints.VolCon_ID_exists(VolCon_ID):
        return "INVALID: VolCon-ID does not exist"

    command_errors = proposal["Commands"][1]
    computation_time = proposal["computation time"]
    date_run = proposal["date (Run)"]
    download_time = proposal["download time"]
    received_time = mints.timnow()
    result_error = proposal["Result Error"]

    user_token = mints.token_from_VolCon_ID(VolCon_ID)
    researcher_email = email_from_token(user_token)

    Error = "" # By default

    if set(command_errors) != {"Success"}:
        Error = ",".join([str(x) for x, y in zip(range(0, len(command_errors)), command_errors) if y != "Success" ])

    if result_error != "0":
        Error += ";"+result_error
        # No attachments can be added since none where updated
        attachments = []
    else:
        # Finds the attachments, in chronological order starting at a date
        attachments = mints.read_results_path_apache(VolCon_ID)
        result_error = "No errors retrieving data"

    if Error == "":
        Error = None
        outcome = "Success"
        specific_command_errors = None
        # Uploads the data to Reef
        requests.post('http://'+os.environ['Reef_IP']+':2001/reef/result_upload/'+os.environ['Reef_Key']+'/'+user_token,
                    files={"file": open(attachments[0], "rb")})
        mints.update_results_path_reef(VolCon_ID, attachments[0])
    else:
        # Types of error
        outcome = "Computational error"
        attachments = []
        specific_command_errors = ",".join(command_errors)+";"+result_error

    # Sends email to user
    email_notification = ec.send_mail_complete(researcher_email, "BOINC job complete", ec.automatic_text(received_time, outcome, user_token, attachments),
                    attachments)

    client_IP = request.environ['REMOTE_ADDR']

    # Updates the database
    mints.update_execution_report(VolCon_ID, specific_command_errors, computation_time, date_run, download_time,
                                Error, email_notification, client_IP)

    return "Server has processed the results"