コード例 #1
0
ファイル: __init__.py プロジェクト: GunioRobot/skywriting
def allinone_main(options, args):
    
    ciel.log = CielLogger()
    
    script_filename = args[0]
    run_id = args[1] if len(args) > 1 else 'allinone'
    
    base_dir = tempfile.mkdtemp(prefix=os.getenv('TEMP', default='/tmp/sw-files-'))
    ciel.log('Writing block store files to %s' % base_dir, 'ALLINONE', logging.INFO)
    
    if options.blockstore is not None:
        base_dir = options.blockstore
    else:
        base_dir = tempfile.mkdtemp(prefix=os.getenv('TEMP', default='/tmp/sw-files-'))
        options.blockstore = base_dir
        
    block_store = BlockStore(ciel.engine, 'localhost', 8000, base_dir, True)
    
    initial_task_descriptor, cont_ref = build_initial_task_descriptor(script_filename, block_store, 'root', 'root_cont', 'root_output')
        
    initial_task_object = build_taskpool_task_from_descriptor(initial_task_descriptor, None)
    
    task_runner = TaskRunner(initial_task_object, cont_ref, block_store, options)
    
    try:
        print run_id, 'SUBMITTED_JOB', now_as_timestamp()
        result = task_runner.run()
        print run_id, 'GOT_RESULT', now_as_timestamp()
        print block_store.retrieve_object_for_ref(result, 'json')
        
    except:
        pass
コード例 #2
0
ファイル: __init__.py プロジェクト: smowton/skywriting
def allinone_main(options, args):

    ciel.log = CielLogger()

    script_filename = args[0]
    run_id = args[1] if len(args) > 1 else "allinone"

    base_dir = tempfile.mkdtemp(prefix=os.getenv("TEMP", default="/tmp/sw-files-"))
    ciel.log("Writing block store files to %s" % base_dir, "ALLINONE", logging.INFO)

    if options.blockstore is not None:
        base_dir = options.blockstore
    else:
        base_dir = tempfile.mkdtemp(prefix=os.getenv("TEMP", default="/tmp/sw-files-"))
        options.blockstore = base_dir

    block_store = BlockStore(ciel.engine, "localhost", 8000, base_dir, True)

    initial_task_descriptor, cont_ref = build_initial_task_descriptor(
        script_filename, block_store, "root", "root_cont", "root_output"
    )

    initial_task_object = build_taskpool_task_from_descriptor(initial_task_descriptor, None)

    task_runner = TaskRunner(initial_task_object, cont_ref, block_store, options)

    try:
        print run_id, "SUBMITTED_JOB", now_as_timestamp()
        result = task_runner.run()
        print run_id, "GOT_RESULT", now_as_timestamp()
        print block_store.retrieve_object_for_ref(result, "json", None)

    except:
        pass
コード例 #3
0
ファイル: skypy_submit.py プロジェクト: GunioRobot/skywriting
def main():
    parser = OptionParser()
    parser.add_option("-m", "--master", action="store", dest="master", help="Master URI", metavar="MASTER", default=os.getenv("SW_MASTER"))
    parser.add_option("-s", "--skypy-stub", action="store", dest="skypy_stub", help="Path to Skypy stub.py", metavar="PATH", default=None)
    (options, args) = parser.parse_args()
   
    if not options.master:
        parser.print_help()
        print >> sys.stderr, "Must specify master URI with --master"
        sys.exit(1)

    master_uri = options.master
    
    script_name = args[0]
    script_args = args[1:]

    sp_package = {"skypymain": {"filename": script_name}}
    sp_args = {"pyfile_ref": {"__package__": "skypymain"}, "entry_point": "skypy_main", "entry_args": script_args}

    new_job = skywriting.runtime.util.start_job.submit_job_with_package(sp_package, "skypy", sp_args, os.getcwd(), master_uri, args)
    
    result = skywriting.runtime.util.start_job.await_job(new_job["job_id"], master_uri)

    fakeBlockStore = BlockStore(ciel.engine, None, None, "/tmp")
    reflist = fakeBlockStore.retrieve_object_for_ref(result, "json")

    return reflist[0]
コード例 #4
0
ファイル: cat.py プロジェクト: mrry/skywriting
def main():
    parser = OptionParser()
    parser.add_option("-m", "--master", action="store", dest="master", help="Master URI", metavar="MASTER", default=os.getenv("SW_MASTER"))
    parser.add_option("-r", "--refs", action="store_true", dest="refs", help="Set this option to look up reference names in the master", default=False)
    parser.add_option("-j", "--json", action="store_true", dest="json", help="Set this option to use JSON pretty printing", default=False)
    (options, args) = parser.parse_args()
    
    # Retrieves should work anyway; the arguments are mainly needed for storing
    # stuff.
    bs = BlockStore("dummy_hostname", "0", None)
    
    if options.refs:
        ref_ids = args
        
        for ref_id in ref_ids:
            
            # Fetch information about the ref from the master.
            h = httplib2.Http()
            _, content = h.request(urljoin(options.master, '/refs/%s' % ref_id), 'GET')
            ref_info = simplejson.loads(content, object_hook=json_decode_object_hook)
            ref = ref_info['ref']
            
            if options.json:
                obj = bs.retrieve_object_for_ref(ref, 'json')
                simplejson.dump(obj, sys.stdout, cls=SWReferenceJSONEncoder, indent=4)
                print
            else:
                fh = bs.retrieve_object_for_ref(ref, 'handle')
                for line in fh:
                    sys.stdout.write(line)
                fh.close()
            
    else:
        urls = args    
        
        for url in urls:
            if options.json:
                obj = bs.retrieve_object_for_ref(SWURLReference([url]), 'json')
                simplejson.dump(obj, sys.stdout, cls=SWReferenceJSONEncoder, indent=4)
                print
            else:
                fh = bs.retrieve_object_for_ref(SWURLReference([url]), 'handle')
                print fh
                for line in fh:
                    sys.stdout.write(line)
                fh.close()
コード例 #5
0
def main():

    parser = OptionParser()
    parser.add_option("-m",
                      "--master",
                      action="store",
                      dest="master",
                      help="Master URI",
                      metavar="MASTER",
                      default=os.getenv("SW_MASTER"))

    (options, args) = parser.parse_args()
    master_uri = options.master

    if master_uri is None or master_uri == "":
        raise Exception("Must specify a master with -m or SW_MASTER")

    with open(args[0], "r") as package_file:
        job_dict = simplejson.load(package_file)

    package_dict = job_dict["package"]
    start_dict = job_dict["start"]
    start_handler = start_dict["handler"]
    start_args = start_dict["args"]
    try:
        job_options = job_dict["options"]
    except KeyError:
        job_options = {}

    (package_path, _) = os.path.split(args[0])

    print "BEFORE_SUBMIT", now_as_timestamp()

    new_job = submit_job_with_package(package_dict, start_handler, start_args,
                                      job_options, package_path, master_uri,
                                      args[1:])

    print "SUBMITTED", now_as_timestamp()

    job_url = urlparse.urljoin(master_uri,
                               "control/browse/job/%s" % new_job['job_id'])
    print "JOB_URL", job_url

    result = await_job(new_job['job_id'], master_uri)

    fakeBlockStore = BlockStore(ciel.engine, None, None, "/tmp")
    reflist = fakeBlockStore.retrieve_object_for_ref(result, "json")

    print "GOT_RESULT", now_as_timestamp()

    return reflist
コード例 #6
0
def main():
    parser = OptionParser()
    parser.add_option("-m", "--master", action="store", dest="master", help="Master URI", metavar="MASTER", default=os.getenv("SW_MASTER"))
    parser.add_option("-i", "--id", action="store", dest="id", help="Job ID", metavar="ID", default="default")
    parser.add_option("-e", "--env", action="store_true", dest="send_env", help="Set this flag to send the current environment with the script as _env", default=False)
    (options, args) = parser.parse_args()
   
    if not options.master:
        parser.print_help()
        print >> sys.stderr, "Must specify master URI with --master"
        sys.exit(1)

    if len(args) != 1:
        parser.print_help()
        print >> sys.stderr, "Must specify one script file to execute, as argument"
        sys.exit(1)

    script_name = args[0]
    master_uri = options.master
    id = options.id
    
    print id, "STARTED", now_as_timestamp()

    swi_package = {"swimain": {"filename": script_name}}
    swi_args = {"sw_file_ref": {"__package__": "swimain"}, "start_args": args}
    if options.send_env:
        swi_args["start_env"] = dict(os.environ)

    new_job = skywriting.runtime.util.start_job.submit_job_with_package(swi_package, "swi", swi_args, {}, os.getcwd(), master_uri, args[1:])
    
    result = skywriting.runtime.util.start_job.await_job(new_job["job_id"], master_uri)
    
    fakeBlockStore = BlockStore(ciel.engine, None, None, "/tmp")
    reflist = fakeBlockStore.retrieve_object_for_ref(result, "json")
    sw_return = fakeBlockStore.retrieve_object_for_ref(reflist[0], "json")
    #fakeBlockStore.stop_thread()
    return sw_return
コード例 #7
0
def main():

    parser = OptionParser()
    parser.add_option("-m", "--master", action="store", dest="master", help="Master URI", metavar="MASTER", default=os.getenv("SW_MASTER"))
    
    (options, args) = parser.parse_args()
    master_uri = options.master

    if master_uri is None or master_uri == "":
        raise Exception("Must specify a master with -m or SW_MASTER")
    
    with open(args[0], "r") as package_file:
        job_dict = simplejson.load(package_file)

    package_dict = job_dict["package"]
    start_dict = job_dict["start"]
    start_handler = start_dict["handler"]
    start_args = start_dict["args"]
    try:
        job_options = job_dict["options"]
    except KeyError:
        job_options = {}
    

    (package_path, _) = os.path.split(args[0])

    print "BEFORE_SUBMIT", now_as_timestamp()

    new_job = submit_job_with_package(package_dict, start_handler, start_args, job_options, package_path, master_uri, args[1:])

    print "SUBMITTED", now_as_timestamp()
    
    job_url = urlparse.urljoin(master_uri, "control/browse/job/%s" % new_job['job_id'])
    print "JOB_URL", job_url

    result = await_job(new_job['job_id'], master_uri)

    fakeBlockStore = BlockStore(ciel.engine, None, None, "/tmp")
    reflist = fakeBlockStore.retrieve_object_for_ref(result, "json")

    print "GOT_RESULT", now_as_timestamp()

    return reflist
コード例 #8
0
def main():
    parser = OptionParser()
    parser.add_option("-m",
                      "--master",
                      action="store",
                      dest="master",
                      help="Master URI",
                      metavar="MASTER",
                      default=os.getenv("SW_MASTER"))
    parser.add_option(
        "-r",
        "--refs",
        action="store_true",
        dest="refs",
        help="Set this option to look up reference names in the master",
        default=False)
    parser.add_option("-j",
                      "--json",
                      action="store_true",
                      dest="json",
                      help="Set this option to use JSON pretty printing",
                      default=False)
    (options, args) = parser.parse_args()

    # Retrieves should work anyway; the arguments are mainly needed for storing
    # stuff.
    bs = BlockStore("dummy_hostname", "0", None)

    if options.refs:
        ref_ids = args

        for ref_id in ref_ids:

            # Fetch information about the ref from the master.
            h = httplib2.Http()
            _, content = h.request(
                urljoin(options.master, '/refs/%s' % ref_id), 'GET')
            ref_info = simplejson.loads(content,
                                        object_hook=json_decode_object_hook)
            ref = ref_info['ref']

            if options.json:
                obj = bs.retrieve_object_for_ref(ref, 'json')
                simplejson.dump(obj,
                                sys.stdout,
                                cls=SWReferenceJSONEncoder,
                                indent=4)
                print
            else:
                fh = bs.retrieve_object_for_ref(ref, 'handle')
                for line in fh:
                    sys.stdout.write(line)
                fh.close()

    else:
        urls = args

        for url in urls:
            if options.json:
                obj = bs.retrieve_object_for_ref(SWURLReference([url]), 'json')
                simplejson.dump(obj,
                                sys.stdout,
                                cls=SWReferenceJSONEncoder,
                                indent=4)
                print
            else:
                fh = bs.retrieve_object_for_ref(SWURLReference([url]),
                                                'handle')
                print fh
                for line in fh:
                    sys.stdout.write(line)
                fh.close()