Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

convert KB_WORKSPACE_ID to KB_WORKSPACE_NAME #1756

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions docs/HeadlessTesting.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ but override the default entrypoint with "headless-narrative".
You will need to pass in the following environment variables via -e parameters on the
docker run command line:
* KB_AUTH_TOKEN - this is a standard KBase authentication token with access to the narrative to be run
* KB_WORKSPACE_ID - this is a workspace that the KB_AUTH_TOKEN has access to. A narrative needs to run within some
* KB_WORKSPACE_NAME - this is a workspace that the KB_AUTH_TOKEN has access to. A narrative needs to run within some
workspace. This can be the same as the workspace of the narrative being run, or another workspace that the token has access to
* ENVIRON - [optional] this is environment to use from (ci, next, appdev, prod). At runtime this
value is substituted into the config.json file's "config" setting to determine the set of endpoints
Expand Down Expand Up @@ -88,7 +88,7 @@ come up when you mouse over a narrative in the data panel:
~~~
(narrative) 177:narrative sychan$ docker run -i -t \
> -e "KB_AUTH_TOKEN=un=sychan|tokenid=...secret_squirrel_decoder_string..." \
> -e "KB_WORKSPACE_ID=sychan:1474590456472" \
> -e "KB_WORKSPACE_NAME=sychan:1474590456472" \
> --entrypoint="headless-narrative" \
kbase/narrative:latest 11546/1/20
Configuring KBase logging from defaults (KBASE_PROXY_CONFIG is empty, or not found)
Expand All @@ -101,7 +101,7 @@ Here is an example of setting the environment to the AppDev environment and then
~~~
(narrative) 177:narrative sychan$ docker run -i -t \
> -e "KB_AUTH_TOKEN=un=sychan|tokenid=...secret_squirrel_decoder_string..." \
> -e "KB_WORKSPACE_ID=sychan:1474590456472" \
> -e "KB_WORKSPACE_NAME=sychan:1474590456472" \
> -e "ENVIRON=appdev" \
> --entrypoint="headless-narrative" kbase/narrative:latest 2012/1/4
Configuring KBase logging from defaults (KBASE_PROXY_CONFIG is empty, or not found)
Expand All @@ -113,7 +113,7 @@ Here we run the first narrative, but displaying all the codecells as well as the
~~~
docker run -i -t \
> -e "KB_AUTH_TOKEN=un=sychan|tokenid=...blahblahblah..." \
> -e "KB_WORKSPACE_ID=sychan:1474590456472" \
> -e "KB_WORKSPACE_NAME=sychan:1474590456472" \
> --entrypoint="headless-narrative" \
kbase/narrative:latest --codecells --all 11546/1/20
Configuring KBase logging from defaults (KBASE_PROXY_CONFIG is empty, or not found)
Expand Down
2 changes: 1 addition & 1 deletion kbase-extension/static/kbase/js/kbaseNarrativePrestart.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ define(
Jupyter.notebook.kernel.execute(
'import os;' +
'os.environ["KB_AUTH_TOKEN"]="' + auth.getAuthToken() + '";' +
'os.environ["KB_WORKSPACE_ID"]="' + Jupyter.notebook.metadata.ws_name + '"'
'os.environ["KB_WORKSPACE_NAME"]="' + Jupyter.notebook.metadata.ws_name + '"'
);
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Output widget for genome variation in Jbrowse
* Output widget for genome variation in Jbrowse
* @author Priya Ranjan <[email protected]>
* @public
*/
Expand All @@ -18,7 +18,7 @@
$,
Config,
kbaseAuthenticatedWidget,
DynamicServiceClient,
DynamicServiceClient
) {
return KBWidget({
name: "kbaseVariation",
Expand Down
4 changes: 2 additions & 2 deletions src/biokbase/narrative/app_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ def system_variable(var):
"""
var = var.lower()
if var == 'workspace':
return os.environ.get('KB_WORKSPACE_ID', None)
return os.environ.get('KB_WORKSPACE_NAME', None)
elif var == 'workspace_id':
ws_name = os.environ.get('KB_WORKSPACE_ID', None)
ws_name = os.environ.get('KB_WORKSPACE_NAME', None)
if ws_name is None:
return None
try:
Expand Down
2 changes: 1 addition & 1 deletion src/biokbase/narrative/common/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class _KBaseEnv(object):
env_narrative = "KB_NARRATIVE"
env_session = "KB_SESSION"
env_client_ip = "KB_CLIENT_IP"
env_workspace = "KB_WORKSPACE_ID"
env_workspace = "KB_WORKSPACE_NAME"
env_user = "KB_USER_ID"
env_env = "KB_ENVIRONMENT"

Expand Down

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/biokbase/narrative/tests/data/updater_test_nar.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/biokbase/narrative/tests/data/wjriehl_nar_private.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"info": [1, "Narrative.1433005498810", "KBaseNarrative.Narrative-3.0", "2015-05-30T17:04:44+0000", 3, "wjriehl", 630, "wjriehl:1433005498810", "aaab44fc8ba9d847243708e26547b37e", 2303, {"methods": "{\"ipython\": {\"code\": 6, \"markdown\": 0}, \"output\": 0, \"app\": {}, \"method\": {}}", "format": "ipynb", "description": "", "creator": "wjriehl", "job_info": "{\"queue_time\": 0, \"running\": 0, \"completed\": 0, \"run_time\": 0, \"error\": 0}", "data_dependencies": "[]", "ws_name": "wjriehl:1433005498810", "type": "KBaseNarrative.Narrative", "name": "Code cell genome fetching"}], "created": "2015-05-30T17:04:44+0000", "refs": [], "provenance": [{"input_ws_objects": [], "description": "saved through the narrative interface", "external_data": [], "service": "narrative", "resolved_ws_objects": []}], "creator": "wjriehl", "copy_source_inaccessible": 0, "data": {"nbformat": 3, "nbformat_minor": 0, "worksheets": [{"cells": [{"cell_type": "code", "language": "python", "outputs": [], "collapsed": false, "prompt_number": 1, "input": "genome_list = ['shew_mr1']\nurl_list = ['ftp://ftp.ncbi.nlm.nih.gov/genomes/Bacteria/Shewanella_MR_4_uid58345/NC_008321.gbk']", "metadata": {}}, {"cell_type": "code", "language": "python", "outputs": [], "collapsed": false, "prompt_number": 6, "input": "from biokbase.Transform.Client import Transform\ntransform_client = Transform('https://ci.kbase.us/services/transform')\n\nfrom biokbase.userandjobstate.client import UserAndJobState\nujs_client = UserAndJobState('https://ci.kbase.us/services/userandjobstate')\n\nimport os\nws_id = os.environ['KB_WORKSPACE_ID']", "metadata": {}}, {"cell_type": "code", "language": "python", "outputs": [], "collapsed": false, "prompt_number": 7, "input": "def set_genome_fetch_args(genome_name, url, ws_id):\n return {'external_type': 'Genbank.Genome', \n 'kbase_type': 'KBaseGenomes.Genome', \n 'workspace_name': ws_id, \n 'object_name': genome_name,\n 'optional_arguments': {'validate':{},'transform':{}},\n 'url_mapping': {'Genbank.Genome': url}}", "metadata": {}}, {"cell_type": "code", "language": "python", "outputs": [], "collapsed": false, "prompt_number": 8, "input": "upload_jobs = []\nfor i in range(len(genome_list)):\n transform_args = set_genome_fetch_args(genome_list[i], url_list[i], ws_id)\n upload_jobs.append(transform_client.upload(transform_args))", "metadata": {}}, {"cell_type": "code", "language": "python", "outputs": [{"output_type": "stream", "stream": "stdout", "text": "Job 5569ed87e4b095f8092a40aa is complete with message Upload to wjriehl:1433005498810 completed\n"}], "collapsed": false, "prompt_number": 11, "input": "for job in upload_jobs:\n status = ujs_client.get_job_status(job[1])\n print(\"Job {} is {} with message {}\".format(job[1], status[1], status[2]))", "metadata": {}}, {"cell_type": "code", "language": "python", "outputs": [], "collapsed": false, "input": "", "metadata": {}}], "metadata": {}}], "metadata": {"name": "Code cell genome fetching", "format": "ipynb", "creator": "wjriehl", "data_dependencies": [], "ws_name": "wjriehl:1433005498810", "type": "KBaseNarrative.Narrative", "job_ids": {"job_usage": {"queue_time": 0, "run_time": 0}, "apps": [], "methods": []}, "description": ""}}, "extracted_ids": {}}
{"info": [1, "Narrative.1433005498810", "KBaseNarrative.Narrative-3.0", "2015-05-30T17:04:44+0000", 3, "wjriehl", 630, "wjriehl:1433005498810", "aaab44fc8ba9d847243708e26547b37e", 2303, {"methods": "{\"ipython\": {\"code\": 6, \"markdown\": 0}, \"output\": 0, \"app\": {}, \"method\": {}}", "format": "ipynb", "description": "", "creator": "wjriehl", "job_info": "{\"queue_time\": 0, \"running\": 0, \"completed\": 0, \"run_time\": 0, \"error\": 0}", "data_dependencies": "[]", "ws_name": "wjriehl:1433005498810", "type": "KBaseNarrative.Narrative", "name": "Code cell genome fetching"}], "created": "2015-05-30T17:04:44+0000", "refs": [], "provenance": [{"input_ws_objects": [], "description": "saved through the narrative interface", "external_data": [], "service": "narrative", "resolved_ws_objects": []}], "creator": "wjriehl", "copy_source_inaccessible": 0, "data": {"nbformat": 3, "nbformat_minor": 0, "worksheets": [{"cells": [{"cell_type": "code", "language": "python", "outputs": [], "collapsed": false, "prompt_number": 1, "input": "genome_list = ['shew_mr1']\nurl_list = ['ftp://ftp.ncbi.nlm.nih.gov/genomes/Bacteria/Shewanella_MR_4_uid58345/NC_008321.gbk']", "metadata": {}}, {"cell_type": "code", "language": "python", "outputs": [], "collapsed": false, "prompt_number": 6, "input": "from biokbase.Transform.Client import Transform\ntransform_client = Transform('https://ci.kbase.us/services/transform')\n\nfrom biokbase.userandjobstate.client import UserAndJobState\nujs_client = UserAndJobState('https://ci.kbase.us/services/userandjobstate')\n\nimport os\nws_id = os.environ['KB_WORKSPACE_NAME']", "metadata": {}}, {"cell_type": "code", "language": "python", "outputs": [], "collapsed": false, "prompt_number": 7, "input": "def set_genome_fetch_args(genome_name, url, ws_id):\n return {'external_type': 'Genbank.Genome', \n 'kbase_type': 'KBaseGenomes.Genome', \n 'workspace_name': ws_id, \n 'object_name': genome_name,\n 'optional_arguments': {'validate':{},'transform':{}},\n 'url_mapping': {'Genbank.Genome': url}}", "metadata": {}}, {"cell_type": "code", "language": "python", "outputs": [], "collapsed": false, "prompt_number": 8, "input": "upload_jobs = []\nfor i in range(len(genome_list)):\n transform_args = set_genome_fetch_args(genome_list[i], url_list[i], ws_id)\n upload_jobs.append(transform_client.upload(transform_args))", "metadata": {}}, {"cell_type": "code", "language": "python", "outputs": [{"output_type": "stream", "stream": "stdout", "text": "Job 5569ed87e4b095f8092a40aa is complete with message Upload to wjriehl:1433005498810 completed\n"}], "collapsed": false, "prompt_number": 11, "input": "for job in upload_jobs:\n status = ujs_client.get_job_status(job[1])\n print(\"Job {} is {} with message {}\".format(job[1], status[1], status[2]))", "metadata": {}}, {"cell_type": "code", "language": "python", "outputs": [], "collapsed": false, "input": "", "metadata": {}}], "metadata": {}}], "metadata": {"name": "Code cell genome fetching", "format": "ipynb", "creator": "wjriehl", "data_dependencies": [], "ws_name": "wjriehl:1433005498810", "type": "KBaseNarrative.Narrative", "job_ids": {"job_usage": {"queue_time": 0, "run_time": 0}, "apps": [], "methods": []}, "description": ""}}, "extracted_ids": {}}
20 changes: 10 additions & 10 deletions src/biokbase/narrative/tests/test_app_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,27 +55,27 @@ def test_sys_var_user(self):
self.assertEqual(system_variable('user_id'), self.user_id)

def test_sys_var_no_ws(self):
if 'KB_WORKSPACE_ID' in os.environ:
del os.environ['KB_WORKSPACE_ID']
if 'KB_WORKSPACE_NAME' in os.environ:
del os.environ['KB_WORKSPACE_NAME']
self.assertIsNone(system_variable('workspace'))

def test_sys_var_workspace(self):
os.environ['KB_WORKSPACE_ID'] = self.workspace
os.environ['KB_WORKSPACE_NAME'] = self.workspace
self.assertEqual(system_variable('workspace'), self.workspace)

def test_sys_var_no_ws_id(self):
if 'KB_WORKSPACE_ID' in os.environ:
del os.environ['KB_WORKSPACE_ID']
if 'KB_WORKSPACE_NAME' in os.environ:
del os.environ['KB_WORKSPACE_NAME']
self.assertIsNone(system_variable('workspace_id'))

@mock.patch('biokbase.narrative.app_util.clients.get', get_mock_client)
def test_sys_var_workspace_id(self):
os.environ['KB_WORKSPACE_ID'] = self.workspace
os.environ['KB_WORKSPACE_NAME'] = self.workspace
self.assertEqual(system_variable('workspace_id'), 12345)

@mock.patch('biokbase.narrative.app_util.clients.get', get_mock_client)
def test_sys_var_workspace_id_except(self):
os.environ['KB_WORKSPACE_ID'] = 'invalid_workspace'
os.environ['KB_WORKSPACE_NAME'] = 'invalid_workspace'
self.assertIsNone(system_variable('workspace_id'))

def test_sys_var_user_bad(self):
Expand Down Expand Up @@ -193,7 +193,7 @@ def test_map_inputs_from_job(self):
self.assertDictEqual(map_inputs_from_job(inputs, app_spec), expected)

def test_map_outputs_from_state_simple(self):
os.environ['KB_WORKSPACE_ID'] = self.workspace
os.environ['KB_WORKSPACE_NAME'] = self.workspace
app_spec = {
'parameters': [],
'behavior': {
Expand All @@ -207,7 +207,7 @@ def test_map_outputs_from_state_simple(self):
self.assertTupleEqual(map_outputs_from_state(None, None, app_spec), ('kbaseDefaultNarrativeOutput', self.workspace))

def test_map_outputs_from_state(self):
os.environ['KB_WORKSPACE_ID'] = self.workspace
os.environ['KB_WORKSPACE_NAME'] = self.workspace
app_spec = {
'widgets': {
'input': None,
Expand Down Expand Up @@ -253,7 +253,7 @@ def test_map_outputs_from_state(self):
self.assertTupleEqual(map_outputs_from_state(state, params, app_spec), expected)

def test_map_outputs_from_state_bad_spec(self):
os.environ['KB_WORKSPACE_ID'] = self.workspace
os.environ['KB_WORKSPACE_NAME'] = self.workspace
app_spec = {
'not': 'really'
}
Expand Down
30 changes: 15 additions & 15 deletions src/biokbase/narrative/tests/test_appmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def test_available_apps_bad(self):
@mock.patch('biokbase.narrative.jobs.appmanager.JobComm')
@mock.patch('biokbase.narrative.jobs.appmanager.auth.get_agent_token', side_effect=mock_agent_token)
def test_dry_run_app(self, c, auth):
os.environ['KB_WORKSPACE_ID'] = self.public_ws
os.environ['KB_WORKSPACE_NAME'] = self.public_ws
output = self.am.run_app(
self.test_app_id,
self.test_app_params,
Expand All @@ -109,7 +109,7 @@ def test_dry_run_app(self, c, auth):
@mock.patch('biokbase.narrative.jobs.appmanager.auth.get_agent_token', side_effect=mock_agent_token)
def test_run_app_good_inputs(self, c, auth):
c.return_value.send_comm_message.return_value = None
os.environ['KB_WORKSPACE_ID'] = self.public_ws
os.environ['KB_WORKSPACE_NAME'] = self.public_ws
new_job = self.am.run_app(
self.test_app_id,
self.test_app_params,
Expand All @@ -126,7 +126,7 @@ def test_run_app_good_inputs(self, c, auth):
@mock.patch('biokbase.narrative.jobs.appmanager.auth.get_agent_token', side_effect=mock_agent_token)
def test_run_app_from_gui_cell(self, c, auth):
c.return_value.send_comm_message.return_value = None
os.environ['KB_WORKSPACE_ID'] = self.public_ws
os.environ['KB_WORKSPACE_NAME'] = self.public_ws
self.assertIsNone(self.am.run_app(
self.test_app_id,
self.test_app_params,
Expand Down Expand Up @@ -179,7 +179,7 @@ def test_run_app_bad_version(self, c):
@mock.patch('biokbase.narrative.jobs.appmanager.auth.get_agent_token', side_effect=mock_agent_token)
def test_run_app_batch_good_inputs(self, c, auth):
c.return_value.send_comm_message.return_value = None
os.environ['KB_WORKSPACE_ID'] = self.public_ws
os.environ['KB_WORKSPACE_NAME'] = self.public_ws
new_job = self.am.run_app_batch(
self.test_app_id,
[
Expand All @@ -199,7 +199,7 @@ def test_run_app_batch_good_inputs(self, c, auth):
@mock.patch('biokbase.narrative.jobs.appmanager.auth.get_agent_token', side_effect=mock_agent_token)
def test_run_app_batch_gui_cell(self, c, auth):
c.return_value.send_comm_message.return_value = None
os.environ['KB_WORKSPACE_ID'] = self.public_ws
os.environ['KB_WORKSPACE_NAME'] = self.public_ws
self.assertIsNone(self.am.run_app_batch(
self.test_app_id,
[
Expand Down Expand Up @@ -290,18 +290,18 @@ def test_validate_params(self):
}
app_id = "NarrativeTest/test_create_set"
tag = "dev"
prev_ws_id = os.environ.get('KB_WORKSPACE_ID')
os.environ['KB_WORKSPACE_ID'] = self.public_ws
prev_ws_id = os.environ.get('KB_WORKSPACE_NAME')
os.environ['KB_WORKSPACE_NAME'] = self.public_ws
sm = specmanager.SpecManager()
spec = sm.get_spec(app_id, tag=tag)
(params, ws_inputs) = app_util.validate_parameters(app_id, tag, sm.app_params(spec), inputs)
self.assertDictEqual(params, inputs)
self.assertIn('12345/8/1', ws_inputs)
self.assertIn('12345/7/1', ws_inputs)
if prev_ws_id is None:
del(os.environ['KB_WORKSPACE_ID'])
del(os.environ['KB_WORKSPACE_NAME'])
else:
os.environ['KB_WORKSPACE_ID'] = prev_ws_id
os.environ['KB_WORKSPACE_NAME'] = prev_ws_id

@mock.patch('biokbase.narrative.jobs.appmanager.specmanager.clients.get', get_mock_client)
@mock.patch('biokbase.narrative.jobs.specmanager.clients.get', get_mock_client)
Expand Down Expand Up @@ -331,8 +331,8 @@ def test_input_mapping(self):
app_id = "NarrativeTest/test_create_set"
tag = "dev"
ws_name = self.public_ws
prev_ws_id = os.environ.get('KB_WORKSPACE_ID', None)
os.environ['KB_WORKSPACE_ID'] = ws_name
prev_ws_id = os.environ.get('KB_WORKSPACE_NAME', None)
os.environ['KB_WORKSPACE_NAME'] = ws_name
sm = specmanager.SpecManager()
spec = sm.get_spec(app_id, tag=tag)
spec_params = sm.app_params(spec)
Expand Down Expand Up @@ -366,9 +366,9 @@ def test_input_mapping(self):
ret = app_util.transform_param_value("resolved-ref", ref_path, None)
self.assertEqual(ret, ws_name + '/MyReadsSet;18836/5/1')
if prev_ws_id is None:
del(os.environ['KB_WORKSPACE_ID'])
del(os.environ['KB_WORKSPACE_NAME'])
else:
os.environ['KB_WORKSPACE_ID'] = prev_ws_id
os.environ['KB_WORKSPACE_NAME'] = prev_ws_id

@mock.patch('biokbase.narrative.jobs.appmanager.specmanager.clients.get', get_mock_client)
def test_generate_input(self):
Expand All @@ -393,7 +393,7 @@ def test_generate_input_bad(self):

def test_transform_input_good(self):
ws_name = self.public_ws
os.environ['KB_WORKSPACE_ID'] = ws_name
os.environ['KB_WORKSPACE_NAME'] = ws_name
test_data = [
{
'value': 'input_value',
Expand Down Expand Up @@ -494,7 +494,7 @@ def test_transform_input_good(self):
spec = test.get('spec', None)
ret = app_util.transform_param_value(test['type'], test['value'], spec)
self.assertEqual(ret, test['expected'])
del(os.environ['KB_WORKSPACE_ID'])
del(os.environ['KB_WORKSPACE_NAME'])

def test_transform_input_bad(self):
with self.assertRaises(ValueError):
Expand Down
2 changes: 1 addition & 1 deletion src/biokbase/narrative/tests/test_jobcomm.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class JobCommTestCase(unittest.TestCase):
def setUpClass(cls):
cls.jm = biokbase.narrative.jobs.jobmanager.JobManager()
cls.job_ids = list(job_info.keys())
os.environ['KB_WORKSPACE_ID'] = config.get('jobs', 'job_test_wsname')
os.environ['KB_WORKSPACE_NAME'] = config.get('jobs', 'job_test_wsname')

cls.jc = biokbase.narrative.jobs.jobcomm.JobComm()
cls.jc._comm = MockComm()
Expand Down
2 changes: 1 addition & 1 deletion src/biokbase/narrative/tests/test_jobmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class JobManagerTest(unittest.TestCase):
def setUpClass(cls):
cls.jm = biokbase.narrative.jobs.jobmanager.JobManager()
cls.job_ids = list(job_info.keys())
os.environ['KB_WORKSPACE_ID'] = config.get('jobs', 'job_test_wsname')
os.environ['KB_WORKSPACE_NAME'] = config.get('jobs', 'job_test_wsname')

@mock.patch('biokbase.narrative.jobs.jobmanager.clients.get', get_mock_client)
def setUp(self):
Expand Down
Loading