Skip to content

Commit

Permalink
Merge 8659b4f into 5ef32e1
Browse files Browse the repository at this point in the history
  • Loading branch information
Dinos Kousidis committed Jul 20, 2018
2 parents 5ef32e1 + 8659b4f commit 243c461
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 204 deletions.
42 changes: 14 additions & 28 deletions reana_client/api/client.py
Expand Up @@ -82,13 +82,12 @@ def ping(self):
except Exception as e:
raise e

def get_workflows(self, organization, access_token):
def get_workflows(self, access_token):
"""List all existing workflows."""
try:

response, http_response = self._client.api.\
get_workflows(organization=organization,
access_token=access_token).result()
get_workflows(access_token=access_token).result()
if http_response.status_code == 200:
return response
else:
Expand All @@ -108,12 +107,11 @@ def get_workflows(self, organization, access_token):
except Exception as e:
raise e

def get_workflow_status(self, organization, workflow, access_token):
def get_workflow_status(self, workflow, access_token):
"""Get status of previously created workflow."""
try:
response, http_response = self.\
_client.api.get_workflow_status(
organization=organization,
workflow_id_or_name=workflow,
access_token=access_token)\
.result()
Expand All @@ -136,12 +134,11 @@ def get_workflow_status(self, organization, workflow, access_token):
except Exception as e:
raise e

def create_workflow(self, organization, reana_spec, name, access_token):
def create_workflow(self, reana_spec, name, access_token):
"""Create a workflow."""
try:
(response,
http_response) = self._client.api.create_workflow(
organization=organization,
reana_spec=json.loads(json.dumps(
reana_spec, sort_keys=True)),
workflow_name=name,
Expand All @@ -165,12 +162,11 @@ def create_workflow(self, organization, reana_spec, name, access_token):
except Exception as e:
raise e

def start_workflow(self, organization, workflow, access_token):
def start_workflow(self, workflow, access_token):
"""Start a workflow."""
try:
(response,
http_response) = self._client.api.set_workflow_status(
organization=organization,
workflow_id_or_name=workflow,
status='start',
access_token=access_token).result()
Expand All @@ -193,13 +189,11 @@ def start_workflow(self, organization, workflow, access_token):
except Exception as e:
raise e

def upload_file(self, organization, workflow_id, file_, file_name,
access_token):
def upload_file(self, workflow_id, file_, file_name, access_token):
"""Upload file to workflow workspace."""
try:
(response,
http_response) = self._client.api.upload_file(
organization=organization,
workflow_id_or_name=workflow_id,
file_content=file_,
file_name=file_name,
Expand All @@ -224,12 +218,11 @@ def upload_file(self, organization, workflow_id, file_, file_name,
except Exception as e:
raise e

def get_workflow_logs(self, organization, workflow_id):
def get_workflow_logs(self, workflow_id):
"""Get logs from a workflow engine."""
try:
(response,
http_response) = self._client.api.get_workflow_logs(
organization=organization,
workflow_id_or_name=workflow_id).result()

if http_response.status_code == 200:
Expand All @@ -251,11 +244,9 @@ def get_workflow_logs(self, organization, workflow_id):
except Exception as e:
raise e

def download_file(self, organization, workflow_id,
file_name, access_token):
def download_file(self, workflow_id, file_name, access_token):
"""Downdload the requested file if it exists.
:param organization: Organization which the user belongs to.
:param workflow_id: UUID which identifies the workflow.
:param file_name: File name or path to the file requested.
:returns: .
Expand All @@ -264,7 +255,6 @@ def download_file(self, organization, workflow_id,
logging.getLogger("urllib3").setLevel(logging.CRITICAL)
(response,
http_response) = self._client.api.download_file(
organization=organization,
workflow_id_or_name=workflow_id,
file_name=file_name,
access_token=access_token).result()
Expand All @@ -288,18 +278,16 @@ def download_file(self, organization, workflow_id,
except Exception as e:
raise e

def get_files(self, organization, workflow_id, access_token):
def get_files(self, workflow_id, access_token):
"""Return the list of file for a given workflow workspace.
:param organization: Organization which the user belongs to.
:param workflow_id: UUID which identifies the workflow.
:returns: A list of dictionaries composed by the `name`, `size` and
`last-modified`.
"""
try:
(response,
http_response) = self._client.api.get_files(
organization=organization,
workflow_id_or_name=workflow_id,
access_token=access_token).result()

Expand All @@ -322,12 +310,11 @@ def get_files(self, organization, workflow_id, access_token):
except Exception as e:
raise e

def upload_to_server(self, organization, workflow, paths, access_token):
def upload_to_server(self, workflow, paths, access_token):
"""Upload file or directory to REANA-Server.
Shared e.g. by `code upload` and `inputs upload`.
:param organization: Organization ID
:param workflow: ID of that Workflow whose workspace should be
used to store the files.
:param paths: Absolute filepath(s) of files to be uploaded.
Expand All @@ -345,8 +332,7 @@ def upload_to_server(self, organization, workflow, paths, access_token):
# Check if multiple paths were given and iterate over them
if type(paths) is list or type(paths) is tuple:
for path in paths:
self.upload_to_server(organization, workflow, path,
access_token)
self.upload_to_server(workflow, path, access_token)
# `paths` points to a single file or directory
else:
path = paths
Expand All @@ -364,8 +350,8 @@ def upload_to_server(self, organization, workflow, paths, access_token):
uploaded_files = []
for next_path in files + dirs:
next_uploaded_files = self.upload_to_server(
organization, workflow,
os.path.join(root, next_path), access_token)
workflow, os.path.join(root, next_path),
access_token)
uploaded_files.extend(next_uploaded_files)
return uploaded_files

Expand All @@ -391,7 +377,7 @@ def upload_to_server(self, organization, workflow, paths, access_token):
.format(os.path.basename(fname)))
logging.info("Uploading '{}' ...".format(fname))
try:
response = self.upload_file(organization, workflow, f,
response = self.upload_file(workflow, f,
save_path, access_token)
logging.info("File '{}' was successfully "
"uploaded.".format(fname))
Expand Down
8 changes: 1 addition & 7 deletions reana_client/cli/cwl_runner.py
Expand Up @@ -34,7 +34,7 @@
from bravado.exception import HTTPServerError

from reana_client.api import Client
from reana_client.config import default_organization, default_user
from reana_client.config import default_user
from reana_client.utils import load_workflow_spec
from reana_client.version import __version__

Expand Down Expand Up @@ -87,7 +87,6 @@ def cwl_runner(client, quiet, outdir, processfile, jobfile):
reana_spec['workflow']['spec'])
logging.info('Connecting to {0}'.format(client.server_url))
response = client.create_workflow(default_user,
default_organization,
reana_spec,
'cwl-runner')
logging.error(response)
Expand All @@ -101,7 +100,6 @@ def cwl_runner(client, quiet, outdir, processfile, jobfile):
jobfile, workflow_id)

response = client.start_workflow(default_user,
default_organization,
workflow_id)
logging.error(response)

Expand All @@ -110,7 +108,6 @@ def cwl_runner(client, quiet, outdir, processfile, jobfile):
sleep(1)
logging.error('Polling workflow logs')
response = client.get_workflow_logs(default_user,
default_organization,
workflow_id)
logs = response['logs']
if logs != first_logs:
Expand Down Expand Up @@ -172,7 +169,6 @@ def transfer_file(client, file_dict, jobfile, workflow_id):
path)) as f:
response = client.seed_workflow_inputs(
default_user,
default_organization,
workflow_id,
f,
path)
Expand Down Expand Up @@ -289,7 +285,6 @@ def upload_directory(client, spec_file, workflow_id, location, basename=None,
disk_directory_name, basename)
response = client.seed_workflow_inputs(
default_user,
default_organization,
workflow_id,
file_,
directory_name)
Expand Down Expand Up @@ -348,7 +343,6 @@ def upload_file(client, param, spec_file, workflow_id):
os.path.dirname(spec_file)) + "/", "")
response = client.seed_workflow_inputs(
default_user,
default_organization,
workflow_id,
f,
filename)
Expand Down
35 changes: 9 additions & 26 deletions reana_client/cli/files.py
Expand Up @@ -30,7 +30,7 @@

import tablib

from ..config import ERROR_MESSAGES, default_organization, default_user
from ..config import ERROR_MESSAGES, default_user
from ..errors import FileUploadError
from reana_commons.utils import click_table_printer

Expand All @@ -46,11 +46,6 @@ def files(ctx):
@click.command(
'list',
help='List workflow workspace files.')
@click.option(
'-o',
'--organization',
default=default_organization,
help='Organization whose resources will be used.')
@click.option(
'-w',
'--workflow',
Expand All @@ -74,7 +69,7 @@ def files(ctx):
default=os.environ.get('REANA_ACCESS_TOKEN', None),
help='Access token of the current user.')
@click.pass_context
def get_files(ctx, organization, workflow, _filter,
def get_files(ctx, workflow, _filter,
output_format, access_token):
"""List workflow workspace files."""
logging.debug('command: {}'.format(ctx.command_path.replace(" ", ".")))
Expand All @@ -89,8 +84,7 @@ def get_files(ctx, organization, workflow, _filter,
if workflow:
logging.info('Workflow "{}" selected'.format(workflow))
try:
response = ctx.obj.client.get_files(organization,
workflow, access_token)
response = ctx.obj.client.get_files(workflow, access_token)
headers = ['name', 'size', 'last-modified']
data = []
for file_ in response:
Expand Down Expand Up @@ -136,11 +130,6 @@ def get_files(ctx, organization, workflow, _filter,
'file_',
metavar='FILE',
nargs=-1)
@click.option(
'-o',
'--organization',
default=default_organization,
help='Organization whose resources will be used.')
@click.option(
'-w',
'--workflow',
Expand All @@ -157,8 +146,7 @@ def get_files(ctx, organization, workflow, _filter,
default=os.environ.get('REANA_ACCESS_TOKEN', None),
help='Access token of the current user.')
@click.pass_context
def download_files(ctx, organization, workflow, file_,
output_directory, access_token):
def download_files(ctx, workflow, file_, output_directory, access_token):
"""Download workflow workspace file(s)."""
logging.debug('command: {}'.format(ctx.command_path.replace(" ", ".")))
for p in ctx.params:
Expand All @@ -174,8 +162,9 @@ def download_files(ctx, organization, workflow, file_,
for file_name in file_:
try:
binary_file = \
ctx.obj.client.download_file(organization, workflow,
file_name, access_token)
ctx.obj.client.download_file(workflow,
file_name,
access_token)
logging.info('{0} binary file downloaded ... writing to {1}'.
format(file_name, output_directory))

Expand Down Expand Up @@ -220,11 +209,6 @@ def download_files(ctx, organization, workflow, file_,
metavar='FILE(s)',
type=click.Path(exists=True, resolve_path=True),
nargs=-1)
@click.option(
'-o',
'--organization',
default=default_organization,
help='Organization whose resources will be used.')
@click.option(
'-w',
'--workflow',
Expand All @@ -237,7 +221,7 @@ def download_files(ctx, organization, workflow, file_,
default=os.environ.get('REANA_ACCESS_TOKEN', None),
help='Access token of the current user.')
@click.pass_context
def upload_files(ctx, organization, workflow, filenames, access_token):
def upload_files(ctx, workflow, filenames, access_token):
"""Upload file(s) to workflow workspace."""
logging.debug('command: {}'.format(ctx.command_path.replace(" ", ".")))
for p in ctx.params:
Expand All @@ -253,8 +237,7 @@ def upload_files(ctx, organization, workflow, filenames, access_token):
for filename in filenames:
try:
response = ctx.obj.client.\
upload_to_server(organization,
workflow,
upload_to_server(workflow,
filename,
access_token)
for file_ in response:
Expand Down
11 changes: 3 additions & 8 deletions reana_client/cli/status.py
Expand Up @@ -27,7 +27,7 @@

import click

from ..config import (default_organization, default_user)
from ..config import default_user


@click.command()
Expand All @@ -37,12 +37,7 @@
'--user',
default=default_user,
help='User who has created the workflow.')
@click.option(
'-o',
'--organization',
default=default_organization,
help='Organization whose resources will be used.')
def status(ctx, user, organization):
def status(ctx, user):
"""Show current status of the client session."""
try:
click.echo(click.style('User: {}'.format(user), fg='green'))
Expand All @@ -54,7 +49,7 @@ def status(ctx, user, organization):
click.echo(click.style('Workflow selected: {}'.
format(workflow), fg='green'))
workflow_status_response = ctx.obj.client.get_workflow_status(
user, organization, workflow)
user, workflow)
click.echo(click.style('Workflow status: {}'.
format(workflow_status_response['status']),
fg='green'))
Expand Down

0 comments on commit 243c461

Please sign in to comment.