-$usernames is a reference to a list where each element is an UserProfile.username
-$users is a reference to a hash where the key is an UserProfile.username and the value is an UserProfile.GlobusUser
-username is a string
-GlobusUser is a reference to a hash where the following keys are defined:
- email has a value which is a string
- fullName has a value which is a string
- userName has a value which is a string
-
-
-
-=end html
-
-=begin text
-
-$usernames is a reference to a list where each element is an UserProfile.username
-$users is a reference to a hash where the key is an UserProfile.username and the value is an UserProfile.GlobusUser
-username is a string
-GlobusUser is a reference to a hash where the following keys are defined:
- email has a value which is a string
- fullName has a value which is a string
- userName has a value which is a string
-
-
-=end text
-
-=item Description
-
-
-
-=back
-
-=cut
-
- sub lookup_globus_user
-{
- my($self, @args) = @_;
-
-# Authentication: required
-
- if ((my $n = @args) != 1)
- {
- Bio::KBase::Exceptions::ArgumentValidationError->throw(error =>
- "Invalid argument count for function lookup_globus_user (received $n, expecting 1)");
- }
- {
- my($usernames) = @args;
-
- my @_bad_arguments;
- (ref($usernames) eq 'ARRAY') or push(@_bad_arguments, "Invalid type for argument 1 \"usernames\" (value was \"$usernames\")");
- if (@_bad_arguments) {
- my $msg = "Invalid arguments passed to lookup_globus_user:\n" . join("", map { "\t$_\n" } @_bad_arguments);
- Bio::KBase::Exceptions::ArgumentValidationError->throw(error => $msg,
- method_name => 'lookup_globus_user');
- }
- }
-
- my $url = $self->{url};
- my $result = $self->{client}->call($url, $self->{headers}, {
- method => "UserProfile.lookup_globus_user",
- params => \@args,
- });
- if ($result) {
- if ($result->is_error) {
- Bio::KBase::Exceptions::JSONRPC->throw(error => $result->error_message,
- code => $result->content->{error}->{code},
- method_name => 'lookup_globus_user',
- data => $result->content->{error}->{error} # JSON::RPC::ReturnObject only supports JSONRPC 1.1 or 1.O
- );
- } else {
- return wantarray ? @{$result->result} : $result->result->[0];
- }
- } else {
- Bio::KBase::Exceptions::HTTP->throw(error => "Error invoking method lookup_globus_user",
- status_line => $self->{client}->status_line,
- method_name => 'lookup_globus_user',
- );
- }
-}
-
sub status
{
@@ -725,16 +640,16 @@ sub version {
Bio::KBase::Exceptions::JSONRPC->throw(
error => $result->error_message,
code => $result->content->{code},
- method_name => 'lookup_globus_user',
+ method_name => 'update_user_profile',
);
} else {
return wantarray ? @{$result->result} : $result->result->[0];
}
} else {
Bio::KBase::Exceptions::HTTP->throw(
- error => "Error invoking method lookup_globus_user",
+ error => "Error invoking method update_user_profile",
status_line => $self->{client}->status_line,
- method_name => 'lookup_globus_user',
+ method_name => 'update_user_profile',
);
}
}
@@ -980,40 +895,6 @@ profile has a value which is an UserProfile.UserProfile
-=head2 GlobusUser
-
-=over 4
-
-
-
-=item Definition
-
-=begin html
-
-
-a reference to a hash where the following keys are defined:
-email has a value which is a string
-fullName has a value which is a string
-userName has a value which is a string
-
-
-
-=end html
-
-=begin text
-
-a reference to a hash where the following keys are defined:
-email has a value which is a string
-fullName has a value which is a string
-userName has a value which is a string
-
-
-=end text
-
-=back
-
-
-
=cut
package Bio::KBase::UserProfile::Client::RpcClient;
diff --git a/lib/biokbase/user_profile/authclient.py b/lib/biokbase/user_profile/authclient.py
deleted file mode 100644
index 9a15713..0000000
--- a/lib/biokbase/user_profile/authclient.py
+++ /dev/null
@@ -1,91 +0,0 @@
-'''
-Created on Aug 1, 2016
-
-A very basic KBase auth client for the Python server.
-
-@author: gaprice@lbl.gov
-'''
-import time as _time
-import requests as _requests
-import threading as _threading
-import hashlib
-
-
-class TokenCache(object):
- ''' A basic cache for tokens. '''
-
- _MAX_TIME_SEC = 5 * 60 # 5 min
-
- _lock = _threading.RLock()
-
- def __init__(self, maxsize=2000):
- self._cache = {}
- self._maxsize = maxsize
- self._halfmax = maxsize / 2 # int division to round down
-
- def get_user(self, token):
- token = hashlib.sha256(token).hexdigest()
- with self._lock:
- usertime = self._cache.get(token)
- if not usertime:
- return None
-
- user, intime = usertime
- if _time.time() - intime > self._MAX_TIME_SEC:
- return None
- return user
-
- def add_valid_token(self, token, user):
- if not token:
- raise ValueError('Must supply token')
- if not user:
- raise ValueError('Must supply user')
- token = hashlib.sha256(token).hexdigest()
- with self._lock:
- self._cache[token] = [user, _time.time()]
- if len(self._cache) > self._maxsize:
- for i, (t, _) in enumerate(sorted(self._cache.items(),
- key=lambda (_, v): v[1])):
- if i <= self._halfmax:
- del self._cache[t]
- else:
- break
-
-
-class KBaseAuth(object):
- '''
- A very basic KBase auth client for the Python server.
- '''
-
- _LOGIN_URL = 'https://kbase.us/services/authorization/Sessions/Login'
-
- def __init__(self, auth_url=None):
- '''
- Constructor
- '''
- self._authurl = auth_url
- if not self._authurl:
- self._authurl = self._LOGIN_URL
- self._cache = TokenCache()
-
- def get_user(self, token):
- if not token:
- raise ValueError('Must supply token')
- user = self._cache.get_user(token)
- if user:
- return user
-
- d = {'token': token, 'fields': 'user_id'}
- ret = _requests.post(self._authurl, data=d)
- if not ret.ok:
- try:
- err = ret.json()
- except:
- ret.raise_for_status()
- raise ValueError('Error connecting to auth service: {} {}\n{}'
- .format(ret.status_code, ret.reason,
- err['error_msg']))
-
- user = ret.json()['user_id']
- self._cache.add_valid_token(token, user)
- return user
diff --git a/lib/biokbase/user_profile/baseclient.py b/lib/biokbase/user_profile/baseclient.py
index 3d2a61a..7dc1ce1 100644
--- a/lib/biokbase/user_profile/baseclient.py
+++ b/lib/biokbase/user_profile/baseclient.py
@@ -11,6 +11,9 @@
import requests as _requests
import random as _random
import os as _os
+import traceback as _traceback
+from requests.exceptions import ConnectionError
+from urllib3.exceptions import ProtocolError
try:
from configparser import ConfigParser as _ConfigParser # py 3
@@ -26,6 +29,7 @@
_CT = 'content-type'
_AJ = 'application/json'
_URL_SCHEME = frozenset(['http', 'https'])
+_CHECK_JOB_RETRYS = 3
def _get_token(user_id, password, auth_svc):
@@ -121,7 +125,7 @@ def __init__(
self, url=None, timeout=30 * 60, user_id=None,
password=None, token=None, ignore_authrc=False,
trust_all_ssl_certificates=False,
- auth_svc='https://kbase.us/services/authorization/Sessions/Login',
+ auth_svc='https://kbase.us/services/auth/api/legacy/KBase/Sessions/Login',
lookup_url=False,
async_job_check_time_ms=100,
async_job_check_time_scale_percent=150,
@@ -236,20 +240,30 @@ def run_job(self, service_method, args, service_ver=None, context=None):
mod, _ = service_method.split('.')
job_id = self._submit_job(service_method, args, service_ver, context)
async_job_check_time = self.async_job_check_time
- while True:
+ check_job_failures = 0
+ while check_job_failures < _CHECK_JOB_RETRYS:
time.sleep(async_job_check_time)
async_job_check_time = (async_job_check_time *
self.async_job_check_time_scale_percent /
100.0)
if async_job_check_time > self.async_job_check_max_time:
async_job_check_time = self.async_job_check_max_time
- job_state = self._check_job(mod, job_id)
+
+ try:
+ job_state = self._check_job(mod, job_id)
+ except (ConnectionError, ProtocolError):
+ _traceback.print_exc()
+ check_job_failures += 1
+ continue
+
if job_state['finished']:
if not job_state['result']:
return
if len(job_state['result']) == 1:
return job_state['result'][0]
return job_state['result']
+ raise RuntimeError("_check_job failed {} times and exceeded limit".format(
+ check_job_failures))
def call_method(self, service_method, args, service_ver=None,
context=None):
diff --git a/lib/biokbase/user_profile/client.py b/lib/biokbase/user_profile/client.py
index ae8244f..60ff366 100644
--- a/lib/biokbase/user_profile/client.py
+++ b/lib/biokbase/user_profile/client.py
@@ -12,7 +12,7 @@
try:
# baseclient and this client are in a package
from .baseclient import BaseClient as _BaseClient # @UnusedImport
-except:
+except ImportError:
# no they aren't
from baseclient import BaseClient as _BaseClient # @Reimport
@@ -23,9 +23,9 @@ def __init__(
self, url=None, timeout=30 * 60, user_id=None,
password=None, token=None, ignore_authrc=False,
trust_all_ssl_certificates=False,
- auth_svc='https://kbase.us/services/authorization/Sessions/Login'):
+ auth_svc='https://ci.kbase.us/services/auth/api/legacy/KBase/Sessions/Login'):
if url is None:
- url = 'https://kbase.us/services/user_profile/rpc'
+ url = 'https://ci.kbase.us/services/user_profile/rpc'
self._service_ver = None
self._client = _BaseClient(
url, timeout=timeout, user_id=user_id, password=password,
@@ -37,9 +37,8 @@ def ver(self, context=None):
"""
:returns: instance of String
"""
- return self._client.call_method(
- 'UserProfile.ver',
- [], self._service_ver, context)
+ return self._client.call_method('UserProfile.ver',
+ [], self._service_ver, context)
def filter_users(self, p, context=None):
"""
@@ -52,9 +51,8 @@ def filter_users(self, p, context=None):
"username" of type "username", parameter "realname" of type
"realname", parameter "thumbnail" of String
"""
- return self._client.call_method(
- 'UserProfile.filter_users',
- [p], self._service_ver, context)
+ return self._client.call_method('UserProfile.filter_users',
+ [p], self._service_ver, context)
def get_user_profile(self, usernames, context=None):
"""
@@ -68,9 +66,8 @@ def get_user_profile(self, usernames, context=None):
parameter "thumbnail" of String, parameter "profile" of
unspecified object
"""
- return self._client.call_method(
- 'UserProfile.get_user_profile',
- [usernames], self._service_ver, context)
+ return self._client.call_method('UserProfile.get_user_profile',
+ [usernames], self._service_ver, context)
def set_user_profile(self, p, context=None):
"""
@@ -85,9 +82,8 @@ def set_user_profile(self, p, context=None):
"username", parameter "realname" of type "realname", parameter
"thumbnail" of String, parameter "profile" of unspecified object
"""
- return self._client.call_method(
- 'UserProfile.set_user_profile',
- [p], self._service_ver, context)
+ return self._client.call_method('UserProfile.set_user_profile',
+ [p], self._service_ver, context)
def update_user_profile(self, p, context=None):
"""
@@ -103,20 +99,8 @@ def update_user_profile(self, p, context=None):
"username", parameter "realname" of type "realname", parameter
"thumbnail" of String, parameter "profile" of unspecified object
"""
- return self._client.call_method(
- 'UserProfile.update_user_profile',
- [p], self._service_ver, context)
-
- def lookup_globus_user(self, usernames, context=None):
- """
- :param usernames: instance of list of type "username"
- :returns: instance of mapping from type "username" to type
- "GlobusUser" -> structure: parameter "email" of String, parameter
- "fullName" of String, parameter "userName" of String
- """
- return self._client.call_method(
- 'UserProfile.lookup_globus_user',
- [usernames], self._service_ver, context)
+ return self._client.call_method('UserProfile.update_user_profile',
+ [p], self._service_ver, context)
def status(self, context=None):
return self._client.call_method('UserProfile.status',
diff --git a/lib/javascript/UserProfile/Client.js b/lib/javascript/UserProfile/Client.js
index df60872..0417b33 100644
--- a/lib/javascript/UserProfile/Client.js
+++ b/lib/javascript/UserProfile/Client.js
@@ -17,7 +17,7 @@ function UserProfile(url, auth, auth_cb, timeout, async_job_check_time_ms, servi
this.service_version = service_version;
if (typeof(_url) != "string" || _url.length == 0) {
- _url = "https://kbase.us/services/user_profile/rpc";
+ _url = "https://ci.kbase.us/services/user_profile/rpc";
}
var _auth = auth ? auth : { 'token' : '', 'user_id' : ''};
var _auth_cb = auth_cb;
@@ -84,19 +84,6 @@ function UserProfile(url, auth, auth_cb, timeout, async_job_check_time_ms, servi
return json_call_ajax(_url, "UserProfile.update_user_profile",
[p], 0, _callback, _errorCallback);
};
-
- this.lookup_globus_user = function (usernames, _callback, _errorCallback) {
- if (typeof usernames === 'function')
- throw 'Argument usernames can not be a function';
- if (_callback && typeof _callback !== 'function')
- throw 'Argument _callback must be a function if defined';
- if (_errorCallback && typeof _errorCallback !== 'function')
- throw 'Argument _errorCallback must be a function if defined';
- if (typeof arguments === 'function' && arguments.length > 1+2)
- throw 'Too many arguments ('+arguments.length+' instead of '+(1+2)+')';
- return json_call_ajax(_url, "UserProfile.lookup_globus_user",
- [usernames], 1, _callback, _errorCallback);
- };
this.status = function (_callback, _errorCallback) {
if (_callback && typeof _callback !== 'function')
diff --git a/server_scripts/build_server_control_scripts.py b/server_scripts/build_server_control_scripts.py
deleted file mode 100755
index 6175ce8..0000000
--- a/server_scripts/build_server_control_scripts.py
+++ /dev/null
@@ -1,86 +0,0 @@
-#!/usr/bin/env python
-'''
-Created on Mar 11, 2014
-
-@author: gaprice@lbl.gov
-'''
-from __future__ import print_function
-import sys
-from configobj import ConfigObj
-import os
-import stat
-
-PORT = 'port'
-THREADS = 'server-threads'
-MINMEM = 'min-memory'
-MAXMEM = 'max-memory'
-
-
-def printerr(*objs):
- print(*objs, file=sys.stderr)
- sys.exit(1)
-
-
-def make_executable(path):
- st = os.stat(path)
- os.chmod(path, st.st_mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)
-
-
-def getConfig(param, cfg, cfile):
- if param not in cfg:
- printerr('Missing expected parameter {} in config file {}'
- .format(param, cfile))
- return cfg[param]
-
-if len(sys.argv) < 8:
- printerr("Missing arguments to build_server_control_scripts")
-if len(sys.argv) == 8:
- _, serviceDir, war, target, javaHome, deployCfg, asadmin, serviceDomain =\
- sys.argv
- port = None
-else:
- _, serviceDir, war, target, javaHome, deployCfg, asadmin, serviceDomain,\
- port = sys.argv
-
-if not os.path.isfile(deployCfg):
- printerr('Configuration parameter is not a file: ' + deployCfg)
-cfg = ConfigObj(deployCfg)
-if serviceDomain not in cfg:
- printerr('No {} section in config file {} - '.format(
- serviceDomain, deployCfg))
-wscfg = cfg[serviceDomain]
-
-if port is None:
- if PORT not in wscfg:
- printerr("Port not provided as argument or in config")
- port = wscfg[PORT]
-
-threads = getConfig(THREADS, wscfg, deployCfg)
-minmem = getConfig(MINMEM, wscfg, deployCfg)
-maxmem = getConfig(MAXMEM, wscfg, deployCfg)
-
-with open(os.path.join(serviceDir, 'start_service'), 'w') as ss:
- ss.write('export JAVA_HOME={}\n'.format(javaHome))
- ss.write('export PATH=$JAVA_HOME/bin:$PATH\n')
- ss.write(('JARS={}/lib/jars\n').format(target))
- ss.write('if [ -z "$KB_DEPLOYMENT_CONFIG" ]\n')
- ss.write('then\n')
- ss.write(' export KB_DEPLOYMENT_CONFIG={}/deployment.cfg\n'
- .format(target))
- ss.write('fi\n')
- ss.write(('cd {}\n').format(serviceDir))
- ss.write(('java -cp $JARS/jetty/jetty-start-7.0.0.jar:$JARS/jetty/jetty-all-7.0.0.jar:$JARS/servlet/servlet-api-2.5.jar ' +
- '-Xmx{}m ' +
- '-Djetty.port={} ' +
- '-DKB_DEPLOYMENT_CONFIG=$KB_DEPLOYMENT_CONFIG ' +
- 'org.eclipse.jetty.start.Main jetty.xml\n')
- .format(maxmem,port,serviceDir,serviceDir))
-
-with open(os.path.join(serviceDir, 'stop_service'), 'w') as ss:
- ss.write('export JAVA_HOME={}\n'.format(javaHome))
- ss.write('export PATH=$JAVA_HOME/bin:$PATH\n')
- ss.write('export CLASSPATH=\n')
- ss.write('killall java\n')
-
-make_executable(os.path.join(serviceDir, 'start_service'))
-make_executable(os.path.join(serviceDir, 'stop_service'))
diff --git a/server_scripts/get_deploy_cfg.pm b/server_scripts/get_deploy_cfg.pm
deleted file mode 100644
index bcded36..0000000
--- a/server_scripts/get_deploy_cfg.pm
+++ /dev/null
@@ -1,71 +0,0 @@
-#!/usr/bin/env perl
-use strict;
-use warnings;
-use Getopt::Long;
-use Config::Simple;
-
-my $DESCRIPTION =
-"
-usage:
- get_deploy_cfg [Options] [VariableName]
-
- Retrieve the value of a variable in a KBase 'deploy.cfg' file (essentially a simple
- INI file) by variable name. The value is printed to standard out.
-
- -d, --deploy-cfg [FILE]
- (optional) the location of the deploy.cfg file to use; if not provided, the
- script assumes the file is named 'deploy.cfg' in your current working directory
-
- -h, --help
- diplay this help message, ignore all arguments
-";
-
-my $help = '';
-my $deploy_cfg_file = 'deploy.cfg';
-my $opt = GetOptions (
- "help|h" => \$help,
- "deploy-cfg|d=s" => \$deploy_cfg_file
- );
-if($help) {
- print $DESCRIPTION;
- exit 0;
-}
-
-#process args
-my $n_args = $#ARGV+1;
-if ($n_args != 1) {
- print STDERR "ERROR: Incorrect number of arguments- must specify a variable name.\n";
- print STDERR $DESCRIPTION;
- exit 1;
-}
-my $varname = $ARGV[0];
-
-#read the cfg file
-if (!-e $deploy_cfg_file) {
- print STDERR "ERROR: Cannot find deploy.cfg (looking for '$deploy_cfg_file').\n";
- print STDERR "Rerun with --help option for usage.\n";
- exit 1;
-}
-my $cfg_lookup={};
-Config::Simple->import_from($deploy_cfg_file, $cfg_lookup);
-
-if (defined $cfg_lookup->{$varname}) {
- print STDOUT $cfg_lookup->{$varname};
-} else {
- print STDERR "ERROR: Variable '$varname' not defined in config file '$deploy_cfg_file').\n";
- print STDERR " Available variables are: \n";
- if (scalar(keys(%$cfg_lookup))==0) {
- print STDERR " --no variables were found--\n";
- }
- else {
- foreach my $key (keys %$cfg_lookup) {
- print STDERR " $key\n";
- }
- }
-}
-
-exit 0;
-
-
-
-
diff --git a/server_scripts/glassfish_administer_service.py b/server_scripts/glassfish_administer_service.py
deleted file mode 100755
index f07a370..0000000
--- a/server_scripts/glassfish_administer_service.py
+++ /dev/null
@@ -1,315 +0,0 @@
-#!/usr/bin/env python
-'''
-Created on Dec 6, 2013
-
-@author: gaprice@lbl.gov
-'''
-from __future__ import print_function
-from argparse import ArgumentParser
-import subprocess
-import os
-import xml.etree.ElementTree as ET
-import urllib2
-from subprocess import CalledProcessError
-import sys
-
-_PARALLEL_GC = "-XX:-UseParallelGC"
-_PARALLEL_GC_ESC = "-XX\:-UseParallelGC"
-
-
-def _parseArgs():
- parser = ArgumentParser(description='script to administer a Glassfish ' +
- ' application.')
- parser.add_argument('-w', '--war',
- help='path to the application WAR file. If ' +
- 'omitted, the service at the port and domain is ' +
- 'stopped.')
- parser.add_argument('-a', '--admin', required=True,
- help='location of the Glassfish asadmin program.')
- parser.add_argument('-d', '--domain', required=True,
- help='name of the Glassfish domain where the ' +
- 'application is or will be installed.')
- parser.add_argument('-l', '--domain-dir',
- help='directory where the glassfish domain ' +
- 'information and logs will be stored. Defaults to ' +
- 'glassfish/domains.')
- parser.add_argument('-p', '--port', required=True, type=int,
- help='the port where the application runs.')
- parser.add_argument('-t', '--threads', type=int, default=20,
- help='the number of threads for the application.')
- parser.add_argument('-s', '--Xms', type=int,
- help='minimum memory for the domain in MB. ' +
- 'This will cause a domain restart if changed.')
- parser.add_argument('-x', '--Xmx', type=int,
- help='maximum memory for the domain in MB. ' +
- 'This will cause a domain restart if changed.')
- parser.add_argument('-r', '--properties', nargs='*',
- help='JVM system properties to add to the server.')
- parser.add_argument('-g', '--noparallelgc', action='store_true',
- help='turn off the parallel garbage ' +
- ' collector and use the standard gc.')
- return parser.parse_args()
-
-
-class CommandGlassfishDomain(object):
-
- def __init__(self, asadminpath, domain, domainpath):
- self.asadminpath = asadminpath
- self.domain = domain
- self.path = None
- if (domainpath):
- domaindir = os.path.abspath(os.path.expanduser(domainpath))
- if not os.path.isdir(domaindir):
- if not os.path.exists(domaindir):
- os.mkdir(domaindir)
- else:
- print('Domain path ' + domainpath + ' must be a directory')
- sys.exit(1)
- self.path = domaindir
- p = (' at ' + self.path) if(self.path) else ''
- if self.exists():
- print('Domain ' + self.domain + ' exists' + p +
- ', skipping creation')
- else:
- print('Creating domain ' + self.domain + p)
- print(self._run_local_command('create-domain', '--nopassword=true',
- self.domain).rstrip())
- self.adminport = self.get_admin_port()
- self.start_domain()
-
- def get_admin_port(self):
- #the fact I have to do this is moronic
- if (self.path):
- domains = self.path
- else:
- bindir = os.path.dirname(self.asadminpath)
- glassfish = os.path.join(bindir, "..")
- domains = os.path.join(glassfish, "domains")
- domain = os.path.join(domains, self.domain)
- configfile = os.path.join(domain, "config/domain.xml")
- xml = ET.parse(configfile)
- root = xml.getroot()
- config = root.findall("./configs/config[@name='server-config']")[0]
- adminlist = config.findall(
- "./network-config/network-listeners/network-listener[@protocol=" +
- "'admin-listener']")[0]
- return adminlist.attrib['port']
-
- def start_domain(self):
- if self.is_running():
- print ("Domain " + self.domain + " is already running on port " +
- self.adminport)
- else:
- print("Starting domain " + self.domain)
- print(self._run_local_command('start-domain', self.domain)
- .rstrip())
- self.adminport = self.get_admin_port()
-
- def restart_domain(self):
- if self.is_running():
- print("Restarting " + self.domain + ", please wait")
- print(self._run_local_command('restart-domain', self.domain)
- .rstrip())
- else:
- self.start_domain()
-
- def exists(self):
- return self.domain in self._list_domains()
-
- def is_running(self):
- return self.domain + " running" in self._list_domains()
-
- def start_service(self, war, port, threads):
- portstr = str(port)
- threadstr = str(threads)
- if 'server-' + portstr in self._run_remote_command(
- 'list-virtual-servers'):
- print("Virtual server already exists")
- else:
- print(self._run_remote_command(
- 'create-virtual-server', '--hosts',
- '${com.sun.aas.hostName}', 'server-' + portstr).rstrip())
- if 'thread-pool-' + portstr in self._run_remote_command(
- 'list-threadpools', 'server'):
- print("Threadpool already exists")
- else:
- print(self._run_remote_command(
- 'create-threadpool', '--maxthreadpoolsize=' + threadstr,
- '--minthreadpoolsize=' + threadstr, 'thread-pool-' + portstr)
- .rstrip())
- if 'http-listener-' + portstr in self._run_remote_command(
- 'list-http-listeners'):
- print('Http listener already exists')
- else:
- print(self._run_remote_command(
- 'create-http-listener', '--listeneraddress', '0.0.0.0',
- '--listenerport', portstr,
- '--default-virtual-server', 'server-' + portstr,
- '--securityEnabled=false', '--acceptorthreads=' + threadstr,
- 'http-listener-' + portstr).rstrip())
- print(self._run_remote_command(
- 'set', 'server.network-config.network-listeners.' +
- 'network-listener.http-listener-' + portstr +
- '.thread-pool=thread-pool-' + portstr).rstrip())
- print(self._run_remote_command(
- 'set', 'server.network-config.protocols.protocol.' +
- 'http-listener-' + portstr + '.http.timeout-seconds=1800')
- .rstrip())
- if 'app-' + portstr in self._run_remote_command('list-applications'):
- print(self._run_remote_command('undeploy', 'app-' + portstr)
- .rstrip())
- print(self._run_remote_command(
- 'deploy', '--virtualservers', 'server-' + portstr,
- '--contextroot', '/', '--name', 'app-' + portstr, war).rstrip())
- try:
- localCheckUrl = 'http://localhost:' + portstr + '/rpc'
- print('Attempting to check if rpc service is up here: '+localCheckUrl)
- urllib2.urlopen(localCheckUrl)
- except urllib2.HTTPError as h:
- resp = h.read()
- else:
- print('Unexpected response from server - the server did not ' +
- 'start up successfully. Please check the glassfish logs.')
- return False
- if '32603' in resp:
- print('The server failed to start up successfully and is ' +
- 'running in protected mode. Please check the system and ' +
- 'glassfish logs.')
- return False
- elif '32300' in resp:
- print('The server started successfully.')
- return True
- else:
- print('The server failed to start up successfully and is not '
- + 'running. Please check the system and glassfish logs.')
- return False
-
- def stop_service(self, port):
- portstr = str(port)
- if 'app-' + portstr in self._run_remote_command('list-applications'):
- print(self._run_remote_command('undeploy', 'app-' + portstr)
- .rstrip())
- if 'http-listener-' + portstr in self._run_remote_command(
- 'list-http-listeners'):
- print(self._run_remote_command(
- 'delete-http-listener', 'http-listener-' + portstr).rstrip())
- if 'http-listener-' + portstr in self._run_remote_command(
- 'list-protocols'):
- print(self._run_remote_command(
- 'delete-protocol', 'http-listener-' + portstr).rstrip())
- if 'thread-pool-' + portstr in self._run_remote_command(
- 'list-threadpools', 'server'):
- print(self._run_remote_command(
- 'delete-threadpool', 'thread-pool-' + portstr).rstrip())
- if 'server-' + portstr in self._run_remote_command(
- 'list-virtual-servers'):
- print(self._run_remote_command(
- 'delete-virtual-server', 'server-' + portstr).rstrip())
-
- def set_min_max_memory(self, minm, maxm):
- # will restart the domain if changes are necessary
- xmx = []
- xms = []
- for o in self._run_remote_command('list-jvm-options').split('\n'):
- if o.startswith('-Xmx'):
- xmx.append(o)
- if o.startswith('-Xms'):
- xms.append(o)
- if (len(xms) > 1 and minm is None):
- print('WARNING: multiple Xms parameters set on service: ' +
- str(xms))
- if (len(xmx) > 1 and maxm is None):
- print('WARNING: multiple Xmx parameters set on service: ' +
- str(xmx))
- changed = self._set_memory(None if minm is None else '-Xms' +
- str(minm) + 'm', xms)
- changed2 = self._set_memory(None if maxm is None else '-Xmx'
- + str(maxm) + 'm', xmx)
- if changed or changed2:
- self.restart_domain()
-
- def reenable_parallel_gc(self):
- if self.parallel_gc_is_disabled():
- self.delete_jvm_option(_PARALLEL_GC_ESC)
- self.restart_domain()
-
- def parallel_gc_is_disabled(self):
- for o in self._run_remote_command('list-jvm-options').split('\n'):
- if o == _PARALLEL_GC:
- return True
- return False
-
- def stop_parallel_gc(self):
- if not self.parallel_gc_is_disabled():
- self.create_jvm_option(_PARALLEL_GC_ESC)
- self.restart_domain()
-
- def create_property(self, prop):
- print('Creating property ' + prop)
- print(self._run_remote_command('create-system-properties', prop)
- .rstrip())
-
- def create_jvm_option(self, prop):
- print('Creating jvm property ' + prop)
- print(self._run_remote_command('create-jvm-options', prop)
- .rstrip())
-
- def delete_jvm_option(self, prop):
- print('Removing jvm property ' + prop)
- print(self._run_remote_command('delete-jvm-options', prop).rstrip())
-
- def _set_memory(self, memstr, memlist):
- if (memstr is not None and [memstr] != memlist):
- print("Removing options " + str(memlist))
- for o in memlist:
- self._remove_option(o)
- print("Setting option " + memstr)
- self._set_option(memstr)
- return True
- else:
- return False
-
- def _set_option(self, opt):
- self._run_remote_command('create-jvm-options', opt)
-
- def _remove_option(self, opt):
- self._run_remote_command('delete-jvm-options', opt)
-
- def _list_domains(self):
- return self._run_local_command('list-domains')
-
- def _run_local_command(self, subcmd, *args):
- cmd = [self.asadminpath, subcmd]
- if (self.path):
- cmd.extend(['--domaindir', self.path])
- try:
- return subprocess.check_output(cmd + list(args))
- except CalledProcessError as cpe:
- print(cpe.output.rstrip())
- sys.exit(1)
-
- def _run_remote_command(self, *cmd):
- try:
- return subprocess.check_output([self.asadminpath, '-p',
- self.adminport] + list(cmd))
- except CalledProcessError as cpe:
- print(cpe.output.rstrip())
- sys.exit(1)
-
-
-if __name__ == '__main__':
- args = _parseArgs()
- gf = CommandGlassfishDomain(args.admin, args.domain, args.domain_dir)
- if (args.war == None):
- gf.stop_service(args.port)
- else:
- if (args.noparallelgc):
- gf.stop_parallel_gc()
- else:
- gf.reenable_parallel_gc()
- gf.set_min_max_memory(args.Xms, args.Xmx)
- for p in args.properties:
- gf.create_property(p)
- success = gf.start_service(args.war, args.port, args.threads)
- if not success:
- sys.exit(1)
diff --git a/server_scripts/jetty.xml b/server_scripts/jetty.xml
deleted file mode 100644
index ff58d23..0000000
--- a/server_scripts/jetty.xml
+++ /dev/null
@@ -1,94 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
- 5
- 200
-
-
-
-
-
-
- 0.0.0.0
-
- 1800000
- 2
- false
-
- 10000
- 5000
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- /webapps/root.war
- /
-
-
- org.eclipse.jetty.webapp.WebInfConfiguration
- org.eclipse.jetty.webapp.WebXmlConfiguration
- org.eclipse.jetty.webapp.MetaInfConfiguration
- org.eclipse.jetty.webapp.JettyWebXmlConfiguration
- org.eclipse.jetty.webapp.TagLibConfiguration
-
-
- /temp/
- true
- true
- false
-
- org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern
- .*/.*jsp-api-[^/]*\.jar$|.*/.*jsp-[^/]*\.jar$|.*/.*taglibs[^/]*\.jar$
-
-
-
-
-
-
- ./yyyy_mm_dd.request.log
- yyyy_MM_dd
- 90
- true
- false
- false
- GMT
-
-
-
-
- true
- true
- true
- 1000
-
-
diff --git a/settings.gradle b/settings.gradle
new file mode 100644
index 0000000..63e88cd
--- /dev/null
+++ b/settings.gradle
@@ -0,0 +1,8 @@
+/*
+ * This file was generated by the Gradle 'init' task.
+ *
+ * The settings file is used to specify which projects to include in your build.
+ * For more detailed information on multi-project builds, please refer to https://docs.gradle.org/8.7/userguide/multi_project_builds.html in the Gradle documentation.
+ */
+
+rootProject.name = 'user_profile'
diff --git a/src/us/kbase/userprofile/FilterParams.java b/src/main/java/us/kbase/userprofile/FilterParams.java
similarity index 100%
rename from src/us/kbase/userprofile/FilterParams.java
rename to src/main/java/us/kbase/userprofile/FilterParams.java
diff --git a/src/main/java/us/kbase/userprofile/MongoController.java b/src/main/java/us/kbase/userprofile/MongoController.java
new file mode 100644
index 0000000..40e38e4
--- /dev/null
+++ b/src/main/java/us/kbase/userprofile/MongoController.java
@@ -0,0 +1,278 @@
+package us.kbase.userprofile;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+
+
+/*
+import org.apache.commons.lang3.StringUtils;*/
+
+import com.mongodb.client.FindIterable;
+import com.mongodb.client.MongoClient;
+import com.mongodb.client.MongoClients;
+import com.mongodb.client.MongoCollection;
+import com.mongodb.client.MongoDatabase;
+import com.mongodb.client.model.IndexOptions;
+import us.kbase.common.service.UObject;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.mongodb.MongoClientSettings;
+import com.mongodb.MongoCredential;
+import com.mongodb.ServerAddress;
+import org.bson.Document;
+
+public class MongoController {
+
+ private static final String COL_PROFILES = "profiles";
+
+ private final MongoCollection profiles;
+
+ public MongoController(final String host, final String database, final boolean mongoRetryWrites) {
+ final MongoDatabase db = getDB(host, database, null, null, mongoRetryWrites);
+ profiles = db.getCollection(COL_PROFILES);
+ ensureIndex();
+ }
+
+ public MongoController(final String host, final String database,
+ final String mongoUser, final String mongoPswd,
+ final boolean mongoRetryWrites) {
+ final MongoDatabase db = getDB(host, database, mongoUser, mongoPswd, mongoRetryWrites);
+ profiles = db.getCollection(COL_PROFILES);
+ ensureIndex();
+ }
+
+ private MongoDatabase getDB(final String host, final String db, final String user,
+ final String pwd, final boolean retryWrites) {
+ final MongoClientSettings.Builder mongoBuilder = MongoClientSettings.builder()
+ .retryWrites(retryWrites)
+ .applyToClusterSettings(
+ builder -> builder.hosts(Arrays.asList(new ServerAddress(host))));
+ final MongoClient cli;
+ if (user != null) {
+ final MongoCredential creds = MongoCredential.createCredential(
+ user, db, pwd.toCharArray());
+ // unclear if and when it's safe to clear the password
+ cli = MongoClients.create(mongoBuilder.credential(creds).build());
+ } else {
+ cli = MongoClients.create(mongoBuilder.build());
+ }
+ return cli.getDatabase(db);
+ }
+
+
+ public List filterUsers(String filter) {
+ List users = new ArrayList<>();
+
+ if(filter.trim().isEmpty()) {
+ //return all
+ FindIterable docs = profiles.find(new Document()).projection(new Document("user", 1));
+ for (Document document : docs) {
+ Document d = document.get("user", Document.class);
+ // TODO we should check the DB to see if there are any users without usernames, and if not
+ // alter these lines so we assume the username always exists and throws an error otherwise
+ if (!d.containsKey("username")) {
+ continue;
+ }
+ User u = new User();
+ u.setUsername(d.get("username").toString());
+
+ if (d.get("realname") != null) {
+ u.setRealname(d.get("realname").toString());
+ }
+ if (d.get("thumbnail") != null) {
+ u.setThumbnail(d.get("thumbnail").toString());
+ }
+
+ users.add(u);
+ }
+ return users;
+ }
+
+ // for now we do text search here instead of on the DB side
+ // todo: see if we can install a text search index
+ FindIterable docs = profiles.find(new Document()).projection(new Document("user", 1));
+ String [] terms = filter.split("\\s+");
+ for(Document document : docs) {
+ Document d = document.get("user", Document.class);
+ // TODO we should check the DB to see if there are any users without usernames, and if not
+ // alter these lines so we assume the username always exists and throws an error otherwise
+ if(!d.containsKey("username")) {
+ continue;
+ }
+ User u = new User();
+ String uname = d.get("username").toString();
+ u.setUsername(uname);
+ boolean add = true;
+ for(int i = 0; i < terms.length; i++) {
+ if(!uname.toLowerCase().contains(terms[i].toLowerCase())){
+ add = false; break;
+ }
+ }
+
+ if(d.containsKey("realname")) {
+ if(d.get("realname")!=null) {
+ String rname = d.get("realname").toString();
+ u.setRealname(rname);
+ if(!add) {
+ add = true;
+ for(int i=0; i> fields = profileNode.fields();
+ while(fields.hasNext()) {
+ final Map.Entry e = fields.next();
+ final Object val = UObject.transformJacksonToObject(e.getValue(), Object.class);
+ update.put("profile." + e.getKey(), val);
+ }
+ } else {
+ throw new RuntimeException("Profile must be an object if defined.");
+ }
+ }
+
+ profiles.updateOne(
+ new Document("user.username", up.getUser().getUsername()),
+ new Document("$set", update));
+
+ } else {
+ Document user = new Document("username", up.getUser().getUsername())
+ .append("realname", up.getUser().getRealname())
+ .append("thumbnail", up.getUser().getThumbnail());
+
+ Document profile = new Document("user", user);
+ if(up.getProfile() != null) {
+ if(up.getProfile().asJsonNode().isObject()) {
+ profile.put("profile", Document.parse(up.getProfile().asJsonNode().toString()));
+ } else {
+ throw new RuntimeException("Profile must be an object if defined.");
+ }
+ } else {
+ profile.put("profile", null);
+ }
+ profiles.insertOne(profile);
+ }
+ }
+
+
+}
diff --git a/src/us/kbase/userprofile/SetUserProfileParams.java b/src/main/java/us/kbase/userprofile/SetUserProfileParams.java
similarity index 100%
rename from src/us/kbase/userprofile/SetUserProfileParams.java
rename to src/main/java/us/kbase/userprofile/SetUserProfileParams.java
diff --git a/src/us/kbase/userprofile/User.java b/src/main/java/us/kbase/userprofile/User.java
similarity index 100%
rename from src/us/kbase/userprofile/User.java
rename to src/main/java/us/kbase/userprofile/User.java
diff --git a/src/us/kbase/userprofile/UserProfile.java b/src/main/java/us/kbase/userprofile/UserProfile.java
similarity index 100%
rename from src/us/kbase/userprofile/UserProfile.java
rename to src/main/java/us/kbase/userprofile/UserProfile.java
diff --git a/src/us/kbase/userprofile/UserProfileClient.java b/src/main/java/us/kbase/userprofile/UserProfileClient.java
similarity index 92%
rename from src/us/kbase/userprofile/UserProfileClient.java
rename to src/main/java/us/kbase/userprofile/UserProfileClient.java
index 7b26f7e..68a7727 100644
--- a/src/us/kbase/userprofile/UserProfileClient.java
+++ b/src/main/java/us/kbase/userprofile/UserProfileClient.java
@@ -25,7 +25,7 @@ public class UserProfileClient {
private static URL DEFAULT_URL = null;
static {
try {
- DEFAULT_URL = new URL("https://kbase.us/services/user_profile/rpc");
+ DEFAULT_URL = new URL("https://ci.kbase.us/services/user_profile/rpc");
} catch (MalformedURLException mue) {
throw new RuntimeException("Compile error in client - bad url compiled");
}
@@ -292,23 +292,6 @@ public void updateUserProfile(SetUserProfileParams p, RpcContext... jsonRpcConte
caller.jsonrpcCall("UserProfile.update_user_profile", args, retType, false, true, jsonRpcContext, this.serviceVersion);
}
- /**
- *
Original spec-file function name: lookup_globus_user
- *
- *
- * @param usernames instance of list of original type "username"
- * @return parameter "users" of mapping from original type "username" to type {@link us.kbase.userprofile.GlobusUser GlobusUser}
- * @throws IOException if an IO exception occurs
- * @throws JsonClientException if a JSON RPC exception occurs
- */
- public Map lookupGlobusUser(List usernames, RpcContext... jsonRpcContext) throws IOException, JsonClientException {
- List
- *
- *
- */
-@JsonInclude(JsonInclude.Include.NON_NULL)
-@Generated("com.googlecode.jsonschema2pojo")
-@JsonPropertyOrder({
- "email",
- "fullName",
- "userName"
-})
-public class GlobusUser {
-
- @JsonProperty("email")
- private String email;
- @JsonProperty("fullName")
- private String fullName;
- @JsonProperty("userName")
- private String userName;
- private Map additionalProperties = new HashMap();
-
- @JsonProperty("email")
- public String getEmail() {
- return email;
- }
-
- @JsonProperty("email")
- public void setEmail(String email) {
- this.email = email;
- }
-
- public GlobusUser withEmail(String email) {
- this.email = email;
- return this;
- }
-
- @JsonProperty("fullName")
- public String getFullName() {
- return fullName;
- }
-
- @JsonProperty("fullName")
- public void setFullName(String fullName) {
- this.fullName = fullName;
- }
-
- public GlobusUser withFullName(String fullName) {
- this.fullName = fullName;
- return this;
- }
-
- @JsonProperty("userName")
- public String getUserName() {
- return userName;
- }
-
- @JsonProperty("userName")
- public void setUserName(String userName) {
- this.userName = userName;
- }
-
- public GlobusUser withUserName(String userName) {
- this.userName = userName;
- return this;
- }
-
- @JsonAnyGetter
- public Map getAdditionalProperties() {
- return this.additionalProperties;
- }
-
- @JsonAnySetter
- public void setAdditionalProperties(String name, Object value) {
- this.additionalProperties.put(name, value);
- }
-
- @Override
- public String toString() {
- return ((((((((("GlobusUser"+" [email=")+ email)+", fullName=")+ fullName)+", userName=")+ userName)+", additionalProperties=")+ additionalProperties)+"]");
- }
-
-}
diff --git a/src/us/kbase/userprofile/MongoController.java b/src/us/kbase/userprofile/MongoController.java
deleted file mode 100644
index af77393..0000000
--- a/src/us/kbase/userprofile/MongoController.java
+++ /dev/null
@@ -1,285 +0,0 @@
-package us.kbase.userprofile;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map.Entry;
-
-
-
-/*
-import org.apache.commons.lang3.StringUtils;*/
-
-import us.kbase.common.service.UObject;
-
-import com.fasterxml.jackson.databind.JsonNode;
-import com.mongodb.BasicDBObject;
-import com.mongodb.DB;
-import com.mongodb.DBCollection;
-import com.mongodb.DBCursor;
-import com.mongodb.DBObject;
-import com.mongodb.MongoClient;
-import com.mongodb.MongoClientOptions;
-import com.mongodb.MongoCredential;
-import com.mongodb.ServerAddress;
-import com.mongodb.util.JSON;
-
-public class MongoController {
-
- private static final String COL_PROFILES = "profiles";
-
- private final DBCollection profiles;
- //private final MongoCollection jProfiles;
-
- public MongoController(final String host, final String database) {
-
- final DB db = getDB(host, database, null, null);
- profiles = db.getCollection(COL_PROFILES);
- //jProfiles = jongo.getCollection(COL_PROFILES);
- ensureIndex();
- /*System.out.println(getProfile("mike3"));
-
- User u = new User().withUsername("mike3").withRealname("oh yeah");
- Map m = new HashMap();
- m.put("email", "test@test.com");
- //m.put("stuff", "things");
- UserProfile up = new UserProfile().withUser(u)
- .withProfile(new UObject(m));
- setProfile(up);
- System.out.println(getProfile("mike2"));
-
- System.out.println("filtering...");
- filterUsers("ik");*/
- }
-
- public MongoController(final String host, final String database,
- final String mongoUser, final String mongoPswd) {
- final DB db = getDB(host, database, mongoUser, mongoPswd);
- profiles = db.getCollection(COL_PROFILES);
- //jProfiles = jongo.getCollection(COL_PROFILES);
- ensureIndex();
- }
-
- private DB getDB(final String host, final String db, final String user, final String pwd) {
- // TODO update to non-deprecated APIs
- final MongoClient cli;
- if (user != null) {
- final MongoCredential creds = MongoCredential.createCredential(
- user, db, pwd.toCharArray());
- // unclear if and when it's safe to clear the password
- cli = new MongoClient(new ServerAddress(host), creds,
- MongoClientOptions.builder().build());
- } else {
- cli = new MongoClient(new ServerAddress(host));
- }
- return cli.getDB(db);
- }
-
-
- public List filterUsers(String filter) {
-
- if(filter.trim().isEmpty()) {
- //return all
- DBCursor cursor = profiles.find(new BasicDBObject(),
- new BasicDBObject().append("user",1));
- List users = new ArrayList(cursor.count());
- while(cursor.hasNext()) {
- User u = new User();
- DBObject d = (DBObject)cursor.next().get("user");
- if(!d.containsField("username")) continue;
- u.setUsername(d.get("username").toString());
- if(d.containsField("realname")) {
- if(d.get("realname")!=null) {
- u.setRealname(d.get("realname").toString());
- }
- }
- if(d.containsField("thumbnail")) {
- if(d.get("thumbnail")!=null) {
- u.setThumbnail(d.get("thumbnail").toString());
- }
- }
- //System.out.println(u);
- users.add(u);
- }
- return users;
- }
-
- // for now we do text search here instead of on the DB side
- // todo: see if we can install a text search index
- DBCursor cursor = profiles.find(new BasicDBObject(),
- new BasicDBObject().append("user",1));
- List users = new ArrayList(cursor.count());
- String [] terms = filter.split("\\s+");
- while(cursor.hasNext()) {
- User u = new User();
- DBObject d = (DBObject)cursor.next().get("user");
- if(!d.containsField("username")) continue;
- String uname = d.get("username").toString();
- u.setUsername(uname);
- boolean add = true;
- for(int i=0; i> fields = profileNode.fields();
- while(fields.hasNext()) {
- Entry e= fields.next();
- update.put("profile."+e.getKey(), JSON.parse(e.getValue().toString()));
- }
- } else {
- throw new RuntimeException("Profile must be an object if defined.");
- }
- }
- System.out.println(update);
- profiles.update(
- new BasicDBObject("user.username",up.getUser().getUsername()),
- new BasicDBObject("$set",update));
- } else {
- DBObject user = new BasicDBObject("username",up.getUser().getUsername())
- .append("realname", up.getUser().getRealname())
- .append("thumbnail", up.getUser().getThumbnail());
-
- DBObject profile = new BasicDBObject("user",user);
- if(up.getProfile()!=null) {
- if(up.getProfile().asJsonNode().isObject())
- profile.put("profile", JSON.parse(up.getProfile().asJsonNode().toString()));
- else {
- throw new RuntimeException("Profile must be an object if defined.");
- }
- } else {
- profile.put("profile", null);
- }
- profiles.insert(profile);
- }
- }
-
-
-}
diff --git a/test/test.cfg.example b/test.cfg.example
similarity index 55%
rename from test/test.cfg.example
rename to test.cfg.example
index d29e5bf..b0718d3 100644
--- a/test/test.cfg.example
+++ b/test.cfg.example
@@ -2,13 +2,10 @@
[UserProfile]
-test.temp-dir = test/temp
-test.remove-temp-dir = 1
+test.mongo-exe-path=/path/to/mongod
-test.mongodb-host = localhost
-test.mongodb-database = user_profile_test
-
-test.admin = kbuserprofileadmin
+test.temp-dir = user_profile_test_temp
+test.remove-temp-dir = true
# admin token is required
test.admin-token = xxx
@@ -16,8 +13,6 @@ test.admin-token = xxx
# token is required
test.usr1-token = xxx
-
test.auth-service-url = https://ci.kbase.us/services/auth/api/legacy/KBase
-test.globus-url = https://ci.kbase.us/services/auth/api/legacy/globus
#test.auth-service-url-allow-insecure = false
diff --git a/test/cfg_to_runner.py b/test/cfg_to_runner.py
deleted file mode 100755
index f8dfc40..0000000
--- a/test/cfg_to_runner.py
+++ /dev/null
@@ -1,71 +0,0 @@
-#!/usr/bin/env python
-'''
-Created on Aug 30, 2013
-
-@author: gaprice@lbl.gov
-'''
-from configobj import ConfigObj
-import os
-import sys
-
-ANT = 'ant'
-
-CFG_SECTION = 'UserProfile'
-
-CONFIG_OPTS = ['test.temp-dir',
- 'test.remove-temp-dir',
- 'test.mongodb-host',
- 'test.mongodb-database',
- 'test.admin',
- 'test.admin-pwd',
- 'test.admin-token',
- 'test.usr1',
- 'test.usr1-pwd',
- 'test.usr1-token',
- 'test.auth-service-url',
- 'test.globus-url',
- 'test.auth-service-url-allow-insecure'
- ]
-
-
-def write_runner(out, ant_target):
- with open(out, 'w') as run:
- run.write('# Generated file - do not check into git\n')
-# run.write('cd ..\n')
- run.write(ANT + ' ' + ant_target)
- for o in CONFIG_OPTS:
- if o in testcfg:
- run.write(' -D' + o + '=' + testcfg[o])
- run.write('\n')
- os.chmod(out, 0755)
- print 'Writing test runner with target "' + ant_target + '" to: ' + out
-
-
-if __name__ == '__main__':
- d, _ = os.path.split(os.path.abspath(__file__))
- fn = 'test.cfg'
- if len(sys.argv) > 1:
- fn = sys.argv[1]
- fn = os.path.join(d, fn)
- if not os.path.isfile(fn):
- print 'No such config file ' + fn + '. Halting.'
- sys.exit(1)
- print 'Using test config file ' + fn
- out_run_tests = os.path.join(d, 'run_tests.sh')
- out_run_script_tests = os.path.join(d, 'run_script_tests.sh')
- cfg = ConfigObj(fn)
- try:
- testcfg = cfg[CFG_SECTION]
- except KeyError as ke:
- print 'Test config file ' + fn + ' is missing section ' +\
- CFG_SECTION + '. Halting.'
- sys.exit(1)
-
- write_runner(out_run_tests, 'test')
- #write_runner(out_run_script_tests, 'test-scripts')
-
- #create a copy of the cfg file in the test/scripts/files dir for script
- # tests -mike
- #scriptcfgfile = os.path.join(d, 'scripts', 'files', 'test.cfg.copy')
- #with open(scriptcfgfile, 'w') as copyfile:
- # cfg.write(copyfile)