Exemple #1
0
def main():
    context = get_context()
    try:
        m = context['message_dict']['text']
        reducer = context['message_dict']['reducer']
        print("Got JSON.")
    except Exception:
        print("Didnt get JSON, using raw message.")
        reducer = None
        m = context.raw_message
    wordcount = {}
    for word in m.split():
        w = word.lower()
        if w in wordcount:
            wordcount[w] += 1
        else:
            wordcount[w] = 1
    print("Final word count:")
    for k, v in wordcount.items():
        print("{}: {}".format(k, v))
    if reducer:
        print("Sending message to reducer {}".format(reducer))
        ag = get_client()
        ag.actors.sendMessage(actorId=reducer,
                              body={'message': {
                                  'count': wordcount
                              }})
Exemple #2
0
def main():
    print("executing")
    context = get_context()
    path = context['message_dict'].get('path', '/data/samples')
    system_id = context['message_dict'].get('system_id',
                                            'reactors.storage.sample')
    ag = get_client()
    try:
        fs = ag.files.list(systemId=system_id, filePath=path)
    except Exception as e:
        try:
            print("files error; content: {}".format(e.response.content))
        except Exception as e2:
            print("files original: {}; 2nd: {}".format(e, e2))
    try:
        p = ag.profiles.get()
    except Exception as e:
        try:
            print("profiles error; content: {}".format(e.response.content))
        except Exception as e2:
            print("profiles original: {}; 2nd: {}".format(e, e2))
    try:
        a = ag.apps.list()
    except Exception as e:
        try:
            print("apps error; content: {}".format(e.response.content))
        except Exception as e2:
            print("apps original: {}; 2nd: {}".format(e, e2))

    try:
        print(len(fs))
        print(p)
        print(a)
    except Exception as e:
        print("failure: {}".format(e))
Exemple #3
0
def main():
    context = get_context()
    print("Contents of context:")
    for k, v in context.items():
        print("key: {}. value: {}".format(k, v))
    print("Contents of env: {}".format(os.environ))

    # check identity:
    print("*** Posix Identity Information ***")
    try:
        print("Posix username: {}".format(getpass.getuser()))
    except Exception as e:
        # it is possible to get an exception trying to look up the username because the uid may not
        # exist there. Swallow it and keep going.
        print("Got an exception trying to look up the username: {}".format(e))

    print("Posix uid: {}".format(os.getuid()))
    print("Posix gid: {}".format(os.getgid()))

    # instantiate the agavepy client:
    try:
        ag = get_client()
    except Exception as e:
        print("Got exception {} trying to get client.".format(e))
        sys.exit()

    try:
        prof = ag.profiles.get()
        print("This actor was executed by the user with profile: {}".format(
            prof))
    except Exception as e:
        print(
            "Got an exception trying to get the profile. Exception: {}".format(
                e))
Exemple #4
0
def main():
    context = get_context()
    path = context['message_dict'].get('path', '/data/samples')
    system_id = context['message_dict'].get('system_id',
                                            'reactors.storage.sample')
    ag = get_client()
    fs = ag.files.list(systemId=system_id, filePath=path)
    print("Files: {}".format(fs))
Exemple #5
0
def get_apy_client(context):
    """Instantiate the agavepy client:
    """
    try:
        ag = get_client()
    except Exception as e:
        print("Got exception {} trying to get client.".format(e))
        sys.exit()
    return ag
Exemple #6
0
def main():

    context = get_context()
    ag = get_client()
    try:
        job = ag.jobs.submit(body=context['message_dict'])
        print("jobs {} submitted successfully.".format(job))
    except Exception as e:
        print("Exception submitting job: {}".format(e))
Exemple #7
0
def main():
    ag = get_client()
    context = get_context()
    m = context.message_dict
    file_m = m.get('file')
    if not file_m:
        print "Not a file event."
        sys.exit()
    status = file_m['status']
    path = file_m['path']
    system_id = file_m['systemId']
    native_format = file_m['nativeFormat']
    print "Status: {} path:{} system_id:{} format:{} ".format(
        status, path, system_id, native_format)
    try:
        rsp = ag.files.list(systemId=system_id, filePath=path)
    except Exception as e:
        print "Got an exception trying to list files: {}".format(e)
        print "URL on the request: {}".format(e.request.url)
        print "Request headers: {}".format(e.request.headers)
        print "Request body: {}".format(e.request.body)

    print "Agave files response: {}".format(rsp)
    if status == 'STAGING_COMPLETED' or status == 'TRANSFORMING_COMPLETED':
        if native_format == 'dir':
            # new project directory, let's add our project skeleton
            ag.files.manage(systemId=system_id,
                            filePath=path,
                            body={
                                'action': 'mkdir',
                                'path': 'data'
                            })
            ag.files.manage(systemId=system_id,
                            filePath=path,
                            body={
                                'action': 'mkdir',
                                'path': 'analysis'
                            })
            ag.files.manage(systemId=system_id,
                            filePath=path,
                            body={
                                'action': 'mkdir',
                                'path': 'logs'
                            })
        else:
            print "Skipping since native_format was {}, not 'dir'".format(
                native_format)
    else:
        print "Skipping since status was {}".format(status)
Exemple #8
0
def get_client_with_mock_support():
    """
    Return the Abaco actor's API client if
    running as a function. Try to return
    user's local Agave client for debug
    and test purposes.
    """
    _client = None
    if os.environ.get('_abaco_access_token') is None:
        from agavepy.agave import Agave
        try:
            _client = Agave.restore()
        except TypeError:
            _client = None
    else:
        _client = get_client()

    return _client
Exemple #9
0
def load_client(permissive=False):
    """Gets the current Tapis API client

    Returns the Abaco actor's client if running deployed. Attempts to
    bootstrap a client from supplied credentials if running in local or
    debug mode.
    """
    # Resolution order (agavepy.actors#getclient)
    #
    # 1. Abaco context variables
    # 2. Values from TAPIS_BASE_URL + TAPIS_TOKEN
    # 3. Cache from ~/.agave/current
    try:
        return get_client()
    except Exception:
        if permissive is True:
            return None
        else:
            raise
Exemple #10
0
def get_client_with_mock_support():
    '''
    Get the current Actor API client

    Returns the Abaco actor's client if running deployed. Attempts to
    bootstrap a client from supplied credentials if running in local or
    debug mode.
    '''
    _client = None
    if os.environ.get('_abaco_access_token') is None:
        from agavepy.agave import Agave
        try:
            _client = Agave.restore()
        except TypeError:
            _client = None
    else:
        _client = get_client()

    return _client
Exemple #11
0
def main():
    ag = get_client()
    context = get_context()
    m = context.message_dict
    print "new_project actor running for message: {}".format(m)
    file_m = m.get('file')
    if not file_m:
        print "Not a file event."
        sys.exit()
    status = file_m.get('status')
    if status == 'STAGING_COMPLETED':
        native_format = file_m['nativeFormat']
        if native_format == 'raw':
            path = file_m['path']
            system_id = file_m['systemId']
            process_image(ag, path, system_id)
        else:
            print "Skipping since native_format was {}, not 'raw'".format(
                native_format)
    else:
        print "Skipping since status was {}".format(status)
Exemple #12
0
def get_client_with_mock_support():
    '''
    Get the current Actor API client

    Returns the Abaco actor's client if running deployed. Attempts to
    bootstrap a client from supplied credentials if running in local or
    debug mode.
    '''
    client = None
    if '_abaco_access_token' not in os.environ:
        try:
            client = Agave.restore()
        except TypeError as err:
            raise AgaveError('Unable to restore Agave client: {}'.format(err))
    else:
        try:
            client = get_client()
        except Exception as err:
            raise AgaveError('Unable to get Agave client from context: {}'.format(err))

    return client
Exemple #13
0
def get_vars(agave_context):
    '''Returns container, system, and outdir variables'''
    # check if passed as JSON
    if type(context.message_dict) is dict:
        c, s, o = get_vars_json(agave_context)
    else:
        c, s, o = get_vars_env(agave_context)
    return (c, s, o)


if __name__ == '__main__':

    # get context and client
    context = get_context()
    ag = get_client()

    # container, agave system, and path to outdir
    container, system, outdir = get_vars(context)

    # execute d2s with bash
    d2s_cmd = 'bash /docker2singularity.sh {}'.format(container)
    process = Popen(d2s_cmd.split()).wait()
    assert int(
        process) == 0, 'd2s command finished with non-zero status: {}'.format(
            str(process))

    # find image file produced
    files = ' '.join(listdir('/output'))
    regex = container.replace('/', '_').replace(
        ':', '_') + '-[0-9]{4}-[0-9]{2}-[0-9]{2}-\w{12}\.img'