Skip to content

Commit

Permalink
basics of volume_mount config working
Browse files Browse the repository at this point in the history
  • Loading branch information
msneddon committed Jun 7, 2016
1 parent 2ad9fb3 commit 1ddc58d
Show file tree
Hide file tree
Showing 12 changed files with 447 additions and 15 deletions.
8 changes: 6 additions & 2 deletions catalog.spec
Original file line number Diff line number Diff line change
Expand Up @@ -704,9 +704,12 @@ module Catalog {
list <VolumeMount> volume_mounts;
} VolumeMountConfig;


/* must specify all properties of the VolumeMountConfig */
funcdef set_volume_mount(VolumeMountConfig config) returns () authentication required;

/* must specify module_name, app_id, client_group and this method will delete any configured mounts */
funcdef remove_volume_mount(VolumeMountConfig config) returns () authentication required;

/*
Parameters for listing VolumeMountConfigs. If nothing is set, everything is
returned. Otherwise, will return everything that matches all fields set. For
Expand All @@ -720,7 +723,8 @@ module Catalog {
string client_group;
} VolumeMountFilter;

funcdef list_volume_mounts(VolumeMountFilter filter) returns (list<VolumeMountConfig> volume_mount_configs);
funcdef list_volume_mounts(VolumeMountFilter filter)
returns (list<VolumeMountConfig> volume_mount_configs) authentication required;

/* returns true (1) if the user is an admin, false (0) otherwise */
funcdef is_admin(string username) returns (boolean);
Expand Down
103 changes: 101 additions & 2 deletions lib/Bio/KBase/Catalog/Client.pm
Original file line number Diff line number Diff line change
Expand Up @@ -4013,7 +4013,7 @@ boolean is an int
=item Description
must specify all properties of the VolumeMountConfig
=back
Expand Down Expand Up @@ -4066,6 +4066,105 @@ boolean is an int



=head2 remove_volume_mount
$obj->remove_volume_mount($config)
=over 4
=item Parameter and return types
=begin html
<pre>
$config is a Catalog.VolumeMountConfig
VolumeMountConfig is a reference to a hash where the following keys are defined:
module_name has a value which is a string
app_id has a value which is a string
client_group has a value which is a string
volume_mounts has a value which is a reference to a list where each element is a Catalog.VolumeMount
VolumeMount is a reference to a hash where the following keys are defined:
host_dir has a value which is a string
container_dir has a value which is a string
read_only has a value which is a Catalog.boolean
boolean is an int
</pre>
=end html
=begin text
$config is a Catalog.VolumeMountConfig
VolumeMountConfig is a reference to a hash where the following keys are defined:
module_name has a value which is a string
app_id has a value which is a string
client_group has a value which is a string
volume_mounts has a value which is a reference to a list where each element is a Catalog.VolumeMount
VolumeMount is a reference to a hash where the following keys are defined:
host_dir has a value which is a string
container_dir has a value which is a string
read_only has a value which is a Catalog.boolean
boolean is an int
=end text
=item Description
must specify module_name, app_id, client_group and this method will delete any configured mounts
=back
=cut

sub remove_volume_mount
{
my($self, @args) = @_;

# Authentication: required

if ((my $n = @args) != 1)
{
Bio::KBase::Exceptions::ArgumentValidationError->throw(error =>
"Invalid argument count for function remove_volume_mount (received $n, expecting 1)");
}
{
my($config) = @args;

my @_bad_arguments;
(ref($config) eq 'HASH') or push(@_bad_arguments, "Invalid type for argument 1 \"config\" (value was \"$config\")");
if (@_bad_arguments) {
my $msg = "Invalid arguments passed to remove_volume_mount:\n" . join("", map { "\t$_\n" } @_bad_arguments);
Bio::KBase::Exceptions::ArgumentValidationError->throw(error => $msg,
method_name => 'remove_volume_mount');
}
}

my $result = $self->{client}->call($self->{url}, $self->{headers}, {
method => "Catalog.remove_volume_mount",
params => \@args,
});
if ($result) {
if ($result->is_error) {
Bio::KBase::Exceptions::JSONRPC->throw(error => $result->error_message,
code => $result->content->{error}->{code},
method_name => 'remove_volume_mount',
data => $result->content->{error}->{error} # JSON::RPC::ReturnObject only supports JSONRPC 1.1 or 1.O
);
} else {
return;
}
} else {
Bio::KBase::Exceptions::HTTP->throw(error => "Error invoking method remove_volume_mount",
status_line => $self->{client}->status_line,
method_name => 'remove_volume_mount',
);
}
}



=head2 list_volume_mounts
$volume_mount_configs = $obj->list_volume_mounts($filter)
Expand Down Expand Up @@ -4132,7 +4231,7 @@ boolean is an int
{
my($self, @args) = @_;

# Authentication: none
# Authentication: required

if ((my $n = @args) != 1)
{
Expand Down
16 changes: 16 additions & 0 deletions lib/biokbase/catalog/Client.py
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,7 @@ def get_client_groups(self, params, context=None):

def set_volume_mount(self, config, context=None):
"""
must specify all properties of the VolumeMountConfig
:param config: instance of type "VolumeMountConfig" (for a module,
app, and client group, set mount configurations) -> structure:
parameter "module_name" of String, parameter "app_id" of String,
Expand All @@ -855,6 +856,21 @@ def set_volume_mount(self, config, context=None):
'Catalog.set_volume_mount',
[config], self._service_ver, context)

def remove_volume_mount(self, config, context=None):
"""
must specify module_name, app_id, client_group and this method will delete any configured mounts
:param config: instance of type "VolumeMountConfig" (for a module,
app, and client group, set mount configurations) -> structure:
parameter "module_name" of String, parameter "app_id" of String,
parameter "client_group" of String, parameter "volume_mounts" of
list of type "VolumeMount" -> structure: parameter "host_dir" of
String, parameter "container_dir" of String, parameter "read_only"
of type "boolean" (@range [0,1])
"""
return self._client.call_method(
'Catalog.remove_volume_mount',
[config], self._service_ver, context)

def list_volume_mounts(self, filter, context=None):
"""
:param filter: instance of type "VolumeMountFilter" (Parameters for
Expand Down
28 changes: 21 additions & 7 deletions lib/biokbase/catalog/Impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Catalog:
#########################################
VERSION = "0.0.1"
GIT_URL = "git@github.com:kbase/catalog.git"
GIT_COMMIT_HASH = "07df43086e8b31434364c0fbe18a826e345b6383"
GIT_COMMIT_HASH = "2ad9fb3923f3afba86d2a7635f1dbdfa82854c03"

#BEGIN_CLASS_HEADER
#END_CLASS_HEADER
Expand Down Expand Up @@ -1158,6 +1158,7 @@ def get_client_groups(self, ctx, params):

def set_volume_mount(self, ctx, config):
"""
must specify all properties of the VolumeMountConfig
:param config: instance of type "VolumeMountConfig" (for a module,
app, and client group, set mount configurations) -> structure:
parameter "module_name" of String, parameter "app_id" of String,
Expand All @@ -1168,12 +1169,27 @@ def set_volume_mount(self, ctx, config):
"""
# ctx is the context object
#BEGIN set_volume_mount



self.cc.set_volume_mount(ctx['user_id'], config)
#END set_volume_mount
pass

def remove_volume_mount(self, ctx, config):
"""
must specify module_name, app_id, client_group and this method will delete any configured mounts
:param config: instance of type "VolumeMountConfig" (for a module,
app, and client group, set mount configurations) -> structure:
parameter "module_name" of String, parameter "app_id" of String,
parameter "client_group" of String, parameter "volume_mounts" of
list of type "VolumeMount" -> structure: parameter "host_dir" of
String, parameter "container_dir" of String, parameter "read_only"
of type "boolean" (@range [0,1])
"""
# ctx is the context object
#BEGIN remove_volume_mount
self.cc.remove_volume_mount(ctx['user_id'], config)
#END remove_volume_mount
pass

def list_volume_mounts(self, ctx, filter):
"""
:param filter: instance of type "VolumeMountFilter" (Parameters for
Expand All @@ -1196,9 +1212,7 @@ def list_volume_mounts(self, ctx, filter):
# ctx is the context object
# return variables are: volume_mount_configs
#BEGIN list_volume_mounts


volume_mount_configs = []
volume_mount_configs = self.cc.list_volume_mounts(ctx['user_id'], filter)
#END list_volume_mounts

# At some point might do deeper type checking...
Expand Down
6 changes: 5 additions & 1 deletion lib/biokbase/catalog/Server.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,10 +491,14 @@ def __init__(self):
name='Catalog.set_volume_mount',
types=[dict])
self.method_authentication['Catalog.set_volume_mount'] = 'required'
self.rpc_service.add(impl_Catalog.remove_volume_mount,
name='Catalog.remove_volume_mount',
types=[dict])
self.method_authentication['Catalog.remove_volume_mount'] = 'required'
self.rpc_service.add(impl_Catalog.list_volume_mounts,
name='Catalog.list_volume_mounts',
types=[dict])
self.method_authentication['Catalog.list_volume_mounts'] = 'none'
self.method_authentication['Catalog.list_volume_mounts'] = 'required'
self.rpc_service.add(impl_Catalog.is_admin,
name='Catalog.is_admin',
types=[basestring])
Expand Down
125 changes: 125 additions & 0 deletions lib/biokbase/catalog/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -1224,6 +1224,131 @@ def get_client_groups(self, params):
return self.db.list_client_groups(app_ids)


def set_volume_mount(self, username, config):
# must be an admin
if not self.is_admin(username):
raise ValueError('You do not have permission to set volume mounts.')

# do lots of parameter checking
record = {}

if 'module_name' not in config:
raise ValueError('module_name parameter field is required')
if not isinstance(config['module_name'],basestring):
raise ValueError('module_name parameter field must be a string')
record['module_name'] = config['module_name'].strip()

if 'app_id' not in config:
raise ValueError('app_id parameter field is required')
if not isinstance(config['app_id'],basestring):
raise ValueError('app_id parameter field must be a string')
record['app_id'] = config['app_id'].strip()

if 'client_group' not in config:
raise ValueError('client_group parameter field is required')
if not isinstance(config['client_group'],basestring):
raise ValueError('client_group parameter field must be a string')
record['client_group'] = config['client_group'].strip()

if 'volume_mounts' not in config:
raise ValueError('volume_mounts parameter field is required')
if not isinstance(config['volume_mounts'],list):
raise ValueError('volume_mounts parameter field must be a list')

record['volume_mounts'] = []
for v in config['volume_mounts']:
vm = {}
if 'host_dir' not in v:
raise ValueError('host_dir parameter field is required in all volume_mount configurations')
if not isinstance(v['host_dir'],basestring):
raise ValueError('host_dir parameter field in volume_mount list must be a string')
vm['host_dir'] = v['host_dir'].strip()

if 'container_dir' not in v:
raise ValueError('container_dir parameter field is required in all volume_mount configurations')
if not isinstance(v['container_dir'],basestring):
raise ValueError('container_dir parameter field in volume_mount list must be a string')
vm['container_dir'] = v['container_dir'].strip()

if 'read_only' not in v:
raise ValueError('read_only parameter field is required in all volume_mount configurations')
if not isinstance(str(v['read_only']),basestring):
raise ValueError('read_only parameter field in volume_mount list must be either 1 (true) or 0 (false)')

if str(v['read_only']) not in ['0', '1']:
raise ValueError('read_only parameter field in volume_mount list must be either 1 (true) or 0 (false)')
if str(v['read_only']) == '0':
vm['read_only'] = 0
else:
vm['read_only'] = 1

record['volume_mounts'].append(vm)

error = self.db.set_volume_mount(record)
if error is not None:
raise ValueError('Insert/update probably failed, blame mongo: upsert operation returned: '+error)


def remove_volume_mount(self, username, config):
# do some parameter checks
if not self.is_admin(username):
raise ValueError('You do not have permission to remove volume mounts.')

selection = {}

if 'module_name' not in config:
raise ValueError('module_name parameter field is required')
if not isinstance(config['module_name'],basestring):
raise ValueError('module_name parameter field must be a string')
selection['module_name'] = config['module_name'].strip()

if 'app_id' not in config:
raise ValueError('app_id parameter field is required')
if not isinstance(config['app_id'],basestring):
raise ValueError('app_id parameter field must be a string')
selection['app_id'] = config['app_id'].strip()

if 'client_group' not in config:
raise ValueError('client_group parameter field is required')
if not isinstance(config['client_group'],basestring):
raise ValueError('client_group parameter field must be a string')
selection['client_group'] = config['client_group'].strip()

error = self.db.remove_volume_mount(selection)
if error is not None:
raise ValueError('Removal probably failed, blame mongo: remove operation returned: '+error)


def list_volume_mounts(self, username, filter):
# add some checks on the filter
if not self.is_admin(username):
raise ValueError('You do not have permission to view volume mounts.')

processed_filter = {}
if filter:
if 'module_name' in filter:
if not isinstance(filter['module_name'],basestring):
raise ValueError('module_name parameter field must be a string')
processed_filter['module_name'] = filter['module_name'].strip()

if 'app_id' in filter:
if not isinstance(filter['app_id'],basestring):
raise ValueError('app_id parameter field must be a string')
processed_filter['app_id'] = filter['app_id'].strip()

if 'client_group' in filter:
if not isinstance(filter['client_group'],basestring):
raise ValueError('client_group parameter field must be a string')
processed_filter['client_group'] = filter['client_group'].strip()

return self.db.list_volume_mounts(processed_filter)









# NOT PART OF CLASS CATALOG!!
Expand Down
Loading

0 comments on commit 1ddc58d

Please sign in to comment.