Exemplo n.º 1
0
def handle_synchronous_copy_operation(options, rosrs, response, typ):
    (status, reason, headers, data) = response
    job_location = get_location(headers)
    print "Job URI: %s" % job_location
    print "Job Status: %s" % parse_job(rosrs, job_location)[0]
    while print_job_status(parse_job(rosrs, job_location), options, True):
        time.sleep(1)
    return 0
Exemplo n.º 2
0
def handle_synchronous_copy_operation(options, rosrs, response, typ):
    (status, reason, headers, data) = response
    job_location = get_location(headers)
    print "Job URI: %s" % job_location
    print "Job Status: %s" % parse_job(rosrs, job_location)[0]
    while print_job_status(parse_job(rosrs, job_location), options, True):
        time.sleep(1)
    return 0
Exemplo n.º 3
0
def push_zip(progname, configbase, options, args):
    """
    push RO in zip format
    
    ro push <zip> | -d <dir> [ -f ] [-- new ] [ -r <rosrs_uri> ] [ -t <access_token> [ --asynchronous ] ]    
    """
    ro_config = getroconfig(configbase, options)
    ro_options = {
        "zip": args[2],
        "rosrs_uri":          ro_config['rosrs_uri'],
        "rosrs_access_token": ro_config['rosrs_access_token'],
        "force":          options.force,
        "roId": args[2].replace(".zip", "").split("/")[-1]
        }

    if options.roident:
        ro_options["roId"] = options.roident
    if options.verbose:
        echo = "ro push %(zip)s -r %(rosrs_uri)s -t %(rosrs_access_token)s -i %(roId)s" % dict(ro_options.items() + {'zip':args[2], 'roId':ro_options["roId"]}.items())
        if options.asynchronous:
         echo+=" --asynchronous"
        if options.new:
            echo+=" --new"
        print echo
    rosrs = ROSRS_Session(ro_options["rosrs_uri"], ro_options["rosrs_access_token"])
    if options.new:
        (status, reason, headers, data) = ro_remote_metadata.sendZipRO(rosrs, ro_options["rosrs_uri"], ro_options["roId"], open(args[2], 'rb').read(),"zip/create")
    else:
        (status, reason, headers, data) = ro_remote_metadata.sendZipRO(rosrs, ro_options["rosrs_uri"], ro_options["roId"], open(args[2], 'rb').read())
    jobUri = headers["location"]
    (job_status, target_id, processed_resources, submitted_resources) = ro_utils.parse_job(rosrs, headers["location"])
    print "Your Research Object %s is already processed" % target_id
    print "Job URI: %s" % jobUri
    if options.asynchronous:
        return  handle_asynchronous_zip_push(rosrs, headers["location"])
    #with esc option
    print   "If you don't want to wait until the operation is finished press [ENTER]"
    while printZipJob(ro_utils.parse_job(rosrs, jobUri),jobUri):
        i, o, e = select.select( [sys.stdin], [], [], 2 )
        if (i) and "" == sys.stdin.readline().strip():
            print "You can check the process status using job URI: %s" % jobUri
            return
    if options.verbose:
        print "Status: %s" % status
        print "Reason: %s" % reason
        print "Headers: %s" % headers
        print "Data: %s" % data
    log.debug("Status: %s" % status)
    log.debug("Reason: %s" % reason)
    log.debug("Headers: %s" % headers)
    log.debug("Data: %s" % data)
    return 0
Exemplo n.º 4
0
def freeze(options, args):
    rosrs = ROSRS_Session(options["rosrs_uri"], options["rosrs_access_token"])
    service_uri = urljoin(options["rosrs_uri"], "../evo/finalize/")
    body = {
        'target': args[2],
    }
    body = json.dumps(body)
    reqheaders = {}
    (status, reason, headers,
     data) = response = rosrs.doRequest(uripath=service_uri,
                                        method="POST",
                                        body=body,
                                        ctype="application/json",
                                        reqheaders=reqheaders)
    if "location" in headers:
        while print_job_status(parse_job(rosrs, headers['location']), options,
                               True):
            time.sleep(1)
        print "freeze operation finished successfully"
        return 0
    else:
        print status
        print reason
        print headers
        print data
        print "Given URI isn't correct"
        return -1
Exemplo n.º 5
0
    def testPushZipAsynchronous(self):
        """
        Push a Research Object in zip format to ROSRS.

        ro push <zip> | -d <dir>  [ -f ] [ -r <rosrs_uri> ] [ -t <access_token> ] 
        """
        args = [
            "ro", "push", "zips/pushro-6.zip",
            "-r", ro_test_config.ROSRS_URI,
            "-t", ro_test_config.ROSRS_ACCESS_TOKEN,
            "--asynchronous",
            "-v"
            ]
        
        #preparing
        httpsession = ROSRS_Session(ro_test_config.ROSRS_URI,
        accesskey=ro_test_config.ROSRS_ACCESS_TOKEN)
        ro_remote_metadata.deleteRO(httpsession, ro_test_config.ROSRS_URI + "ro/")
        
        with SwitchStdout(self.outstr):
            status = ro.runCommand(ro_test_config.CONFIGDIR, ro_test_config.ROBASEDIR, args)
        assert status == 0
        self.assertEqual(self.outstr.getvalue().count("Job URI"),1)
        #self.assertEqual(self.outstr.getvalue().count("Job Status:"),1)
        for line in self.outstr.getvalue().split("\n"):
            if "Job URI:" in line:
                jobLocation = line.split("Job URI:")[1].strip()
                status = "RUNNING"
                while status == "RUNNING":
                    time.sleep(1)
                    (status, id, processed_resources, submitted_resources) = parse_job(self.rosrs, jobLocation)
                assert status == "DONE"
                self.rosrs.deleteRO(id)
Exemplo n.º 6
0
 def testSnapshotAsynchronous(self):
     args = [
         "ro", "snapshot" , str(self.CREATED_RO), self.TEST_SNAPHOT_ID, 
         "--asynchronous",
         "-t", ro_test_config.ROSRS_ACCESS_TOKEN,
         "-r", ro_test_config.ROSRS_URI,
         "-v"
     ]    
     outLines = ""
     with SwitchStdout(self.outstr):
         status = ro.runCommand(ro_test_config.CONFIGDIR, ro_test_config.ROBASEDIR, args)
         assert status == 0
         # simple check if the verbouse mode works well            
         for word in ("ro snapshot --asynchronous "+ro_test_config.ROSRS_URI + self.TEST_RO_ID + " " + self.TEST_SNAPHOT_ID).split(" "):
             self.assertTrue(self.outstr.getvalue().count(word+ " ") or self.outstr.getvalue().count(" " + word), "snapshot command wasn't parse well")
         self.assertEqual(self.outstr.getvalue().count("Job Status: "), 1)
         self.assertEqual(self.outstr.getvalue().count("Job URI: "), 1)
         self.assertEqual(self.outstr.getvalue().count("Target URI: "), 1)
         self.assertEqual(self.outstr.getvalue().count("Target Name: "), 1)
         self.assertEqual(self.outstr.getvalue().count("Response Status: "), 1)
         self.assertEqual(self.outstr.getvalue().count("Response Reason: "), 1)
         outLines = self.outstr.getvalue().split("\n")
     for line in outLines:
         if "Job URI:" in line:
             jobLocation = line.split("Job URI:")[1].strip()
             status = "RUNNING"
             while status == "RUNNING":
                 (status, id) = parse_job(self.rosrs, jobLocation)
             assert status == "DONE"
             self.rosrs.deleteRO(id)
     return
Exemplo n.º 7
0
def handle_synchronous_copy_operation_with_esc_option(options, rosrs, response, type):
    (status, reason, headers, data) = response
    job_location = get_location(headers)
    if type == "SNAPSHOT" :
        print "Snapshot is processed"
    else:
        print "Archive is processed"
    print "If you don't want to wait until the operation is finished press [ENTER]"
    print "Job URI: %s" % str(job_location)
    while print_job_status(parse_job(rosrs, str(job_location)), options, False):
        i, o, e = select.select( [sys.stdin], [], [], 3 )
        if (i) and "" == sys.stdin.readline().strip():
            print "Job URI: %s" % job_location
            print_job_status(parse_job(rosrs, job_location), options, True, True)
            break
    return 0
Exemplo n.º 8
0
def handle_synchronous_copy_operation_with_esc_option(options, rosrs, response,
                                                      type):
    (status, reason, headers, data) = response
    job_location = get_location(headers)
    if type == "SNAPSHOT":
        print "Snapshot is processed"
    else:
        print "Archive is processed"
    print "If you don't want to wait until the operation is finished press [ENTER]"
    print "Job URI: %s" % str(job_location)
    while print_job_status(parse_job(rosrs, str(job_location)), options,
                           False):
        i, o, e = select.select([sys.stdin], [], [], 3)
        if (i) and "" == sys.stdin.readline().strip():
            print "Job URI: %s" % job_location
            print_job_status(parse_job(rosrs, job_location), options, True,
                             True)
            break
    return 0
Exemplo n.º 9
0
 def testPushZip(self):
     httpsession = ROSRS_Session(ro_test_config.ROSRS_URI,
     accesskey=ro_test_config.ROSRS_ACCESS_TOKEN)
     (status, reason, headers, data) = sendZipRO(httpsession, ro_test_config.ROSRS_URI, "ro1", open("zips/pushro-6.zip", 'rb').read())
     status = "RUNNING"
     while (status == "RUNNING"):
         time.sleep(1)
         (status, target_id, processed_resources, submitted_resources) = ro_utils.parse_job(httpsession, headers['location'])
     self.assertEqual("DONE", status)
     deleteRO(httpsession,target_id)
     self.assertEqual(reason, "Created")                
Exemplo n.º 10
0
 def freeze(self, ro_uri):
     rosrs = ROSRS_Session(ro_test_config.ROSRS_URI, ro_test_config.ROSRS_ACCESS_TOKEN)
     service_uri = urljoin(ro_test_config.ROSRS_URI, "../evo/finalize/")
     body = {
             'target': ro_uri,
     }
     body = json.dumps(body)
     reqheaders = {}
     (status, reason, headers, data) = rosrs.doRequest(uripath=service_uri, method="POST", body=body, ctype="application/json", reqheaders=reqheaders)
     job_location = get_location(headers)
     status = "RUNNING"
     while status == "RUNNING":
         (status, id) = parse_job(rosrs, job_location)
     return status
Exemplo n.º 11
0
def handle_asynchronous_copy_operation(options, rosrs, response, type):
    (status, reason, headers, data) = response
    job_location = get_location(headers)
    (job_status, target_id) = parse_job(rosrs, job_location)
    if type == "SNAPSHOT":
        print "Snapshot is processed"
    else:
        print "Archive if processed"
    print "Response Status: %s" % status
    print "Response Reason: %s" % reason
    print "Job Status: %s" % job_status
    print "Job URI: %s" % job_location
    print "Target Name: %s" % target_id.split(options["rosrs_uri"])[1][0:-1]
    print "Target URI: %s" % urljoin(options["rosrs_uri"], str(target_id))
    return 0
Exemplo n.º 12
0
def handle_asynchronous_copy_operation(options, rosrs, response, type):
    (status, reason, headers, data) = response
    job_location = get_location(headers)  
    (job_status, target_id) = parse_job(rosrs,job_location)
    if type == "SNAPSHOT":
        print "Snapshot is processed"
    else:
        print "Archive if processed"
    print "Response Status: %s" % status
    print "Response Reason: %s" % reason
    print "Job Status: %s" % job_status
    print "Job URI: %s" % job_location
    print "Target Name: %s" % target_id.split(options["rosrs_uri"])[1][0:-1]
    print "Target URI: %s" % urljoin(options["rosrs_uri"],str(target_id))
    return 0
Exemplo n.º 13
0
def handle_synchronous_zip_push(rosrs,location):
    status = "RUNNING"
    first = True
    while (status == "RUNNING"):
        (status, target_id, processed_resources, submitted_resources) = ro_utils.parse_job(rosrs, location)
        if(first):
            #print "Job Status: %s" % status
            print "RO URI: % s" % target_id
            first = False
        if submitted_resources != "0":
            print "Prcessed resources/Submitted resources: %s/%s" %(processed_resources, submitted_resources)
        time.sleep(2)
    if (status == "DONE"):
        print "Operation finised successfully"
        return 0
    else: 
        print "Oparation failed, check details: %s" % location
        return 0
Exemplo n.º 14
0
def freeze(options, args):
    rosrs = ROSRS_Session(options["rosrs_uri"], options["rosrs_access_token"])
    service_uri = urljoin(options["rosrs_uri"], "../evo/finalize/")
    body = {
        'target': args[2],
    }
    body = json.dumps(body)
    reqheaders = {}
    (status, reason, headers, data) = response = rosrs.doRequest(uripath=service_uri, method="POST", body=body, ctype="application/json", reqheaders=reqheaders)
    if "location" in headers:
        while print_job_status(parse_job(rosrs, headers['location']), options, True):
            time.sleep(1)
        print "freeze operation finished successfully"
        return 0
    else:
        print status
        print reason
        print headers
        print data
        print "Given URI isn't correct"
        return -1
Exemplo n.º 15
0
 def createArchive(self, live_name,sp_name,freeze = True):
     service_uri = urljoin(ro_test_config.ROSRS_URI, "../evo/copy/")
     body = {
             'copyfrom': live_name,
             'target': sp_name,
             'type': "ARCHIVE",
             'finalize': ( "%s" % freeze).lower()
         }
     
     body = json.dumps(body)
     reqheaders = {
         'token': ro_test_config.ROSRS_ACCESS_TOKEN,
         'Slug' : sp_name,
     }       
     rosrs = ROSRS_Session(ro_test_config.ROSRS_URI, ro_test_config.ROSRS_ACCESS_TOKEN)
     (status, reason, headers, data) = rosrs.doRequest(uripath=service_uri, method="POST", body=body, ctype="application/json", reqheaders=reqheaders)
     job_location = get_location(headers)
     status = "RUNNING"
     while status == "RUNNING":
         (status, id) = parse_job(rosrs, job_location)
     return (status, id)
Exemplo n.º 16
0
def handle_asynchronous_zip_push(rosrs,location):
    status = "RUNNING"
    while (status == "RUNNING"):
        (status, target_id, processed_resources, submitted_resources) = ro_utils.parse_job(rosrs, location)
        print "RO URI: % s" % target_id
        return 0