weaver.store.mongodb
¶
Stores to read/write data to from/to MongoDB using pymongo.
Module Contents¶
-
class
weaver.store.mongodb.
MongodbStore
(: Collection, collection: Optional[Dict[AnyStr, Any]], sane_name_config=None)[source]¶ Base class extended by all concrete store implementations.
Initialize self. See help(type(self)) for accurate signature.
-
classmethod
get_args_kwargs
(cls: Any, *args: Any, **kwargs) → Tuple[Tuple, Dict][source]¶ Filters
MongodbStore
-specific arguments to safely pass them down its__init__
.
-
classmethod
-
class
weaver.store.mongodb.
MongodbServiceStore
(*args, **kwargs)[source]¶ Registry for OWS services. Uses MongoDB to store service url and attributes.
Initialize self. See help(type(self)) for accurate signature.
-
save_service
(self: Service, service: bool, overwrite: Optional[Request] = True, request=None) → Service[source]¶ Stores an OWS service in mongodb.
-
delete_service
(self: AnyStr, name: Optional[Request], request=None) → bool[source]¶ Removes service from MongoDB storage.
-
list_services
(self: Optional[Request], request=None) → List[Service][source]¶ Lists all services in MongoDB storage.
-
fetch_by_name
(self: AnyStr, name: Optional[AnyStr], visibility: Optional[Request] = None, request=None) → Service[source]¶ Gets service for given
name
from MongoDB storage.
-
-
class
weaver.store.mongodb.
MongodbProcessStore
(*args, **kwargs)[source]¶ Registry for processes. Uses MongoDB to store processes and attributes.
Initialize self. See help(type(self)) for accurate signature.
-
static
_get_process_field
(process: AnyProcess, function_dict: Union[Dict[AnyProcessType, Callable[], Any]], Callable[], Any]]) → Any[source]¶ Takes a lambda expression or a dict of process-specific lambda expressions to retrieve a field. Validates that the passed process object is one of the supported types.
- Parameters
process – process to retrieve the field from.
function_dict – lambda or dict of lambda of process type
- Returns
retrieved field if the type was supported
- Raises
ProcessInstanceError – invalid process type
-
save_process
(self: Union[Process, ProcessWPS], process: bool, overwrite: Optional[Request] = True, request=None) → Process[source]¶ Stores a process in storage.
- Parameters
process – An instance of
weaver.datatype.Process
.overwrite – Overwrite the matching process instance by name if conflicting.
request – <unused>
-
delete_process
(self: AnyStr, process_id: Optional[AnyStr], visibility: Optional[Request] = None, request=None) → bool[source]¶ Removes process from database, optionally filtered by visibility. If
visibility=None
, the process is deleted (if existing) regardless of its visibility value.
-
list_processes
(self: Optional[AnyStr], visibility: Optional[Request] = None, request=None) → List[Process][source]¶ Lists all processes in database, optionally filtered by visibility.
- Parameters
visibility – One value amongst weaver.visibility.
request – <unused>
-
fetch_by_id
(self: AnyStr, process_id: Optional[AnyStr], visibility: Optional[Request] = None, request=None) → Process[source]¶ Get process for given process_id from storage, optionally filtered by visibility. If
visibility=None
, the process is retrieved (if existing) regardless of its visibility value.- Parameters
process_id – process identifier
visibility – one value amongst weaver.visibility.
request – <unused>
- Returns
An instance of
weaver.datatype.Process
.
-
get_visibility
(self: AnyStr, process_id: Optional[Request], request=None) → AnyStr[source]¶ Get visibility of a process.
- Returns
One value amongst weaver.visibility.
-
set_visibility
(self: AnyStr, process_id: AnyStr, visibility: Optional[Request], request=None) → None[source]¶ Set visibility of a process.
- Parameters
visibility – One value amongst weaver.visibility.
process_id –
request – <unused>
- Raises
ValueError – when
visibility
is not one ofweaver.visibility.VISIBILITY_VALUES
.
-
static
-
class
weaver.store.mongodb.
MongodbJobStore
(*args, **kwargs)[source]¶ Registry for process jobs tracking. Uses MongoDB to store job attributes.
Initialize self. See help(type(self)) for accurate signature.
-
save_job
(self, task_id: AnyStr, process: AnyStr, service: Optional[AnyStr] = None, inputs: Optional[List[Any]] = None, is_workflow: bool = False, user_id: Optional[int] = None, execute_async: bool = True, custom_tags: Optional[List[AnyStr]] = None, access: Optional[AnyStr] = None, notification_email: Optional[AnyStr] = None, accept_language: Optional[AnyStr] = None) → Job[source]¶ Stores a job in mongodb.
-
update_job
(self: Job, job) → Job[source]¶ Updates a job parameters in MongoDB storage. :param job: instance of
weaver.datatype.Job
.
-
delete_job
(self: AnyStr, job_id: Optional[Request], request=None) → bool[source]¶ Removes job from MongoDB storage.
-
fetch_by_id
(self: AnyStr, job_id: Optional[Request], request=None) → Job[source]¶ Gets job for given
job_id
from MongoDB storage.
-
list_jobs
(self: Optional[Request], request=None) → List[Job][source]¶ Lists all jobs in MongoDB storage. For user-specific access to available jobs, use
MongodbJobStore.find_jobs()
instead.
-
find_jobs
(self, request: Request, process: Optional[AnyStr] = None, service: Optional[AnyStr] = None, tags: Optional[List[AnyStr]] = None, access: Optional[AnyStr] = None, notification_email: Optional[AnyStr] = None, status: Optional[AnyStr] = None, sort: Optional[AnyStr] = None, page: int = 0, limit: int = 10, group_by: Optional[Union[AnyStr, List[AnyStr]]] = None) → Union[JobListAndCount, JobCategoriesAndCount][source]¶ Finds all jobs in MongoDB storage matching search filters to obtain results with requested paging or grouping.
- Parameters
request – request that lead to this call to obtain permissions and user id.
process – process name to filter matching jobs.
service – service name to filter matching jobs.
tags – list of tags to filter matching jobs.
access – access visibility to filter matching jobs (default: PUBLIC).
notification_email – notification email to filter matching jobs.
status – status to filter matching jobs.
sort – field which is used for sorting results (default: creation date, descending).
page – page number to return when using result paging (only when not using
group_by
).limit – number of jobs per page when using result paging (only when not using
group_by
).group_by – one or many fields specifying categories to form matching groups of jobs (paging disabled).
- Returns
(list of jobs matching paging OR list of {categories, list of jobs, count}) AND total of matched job
Example:
Using paging (default), result will be in the form:
( [Job(1), Job(2), Job(3), ...], <total> )
Where
<total>
will indicate the complete count of matched jobs with filters, but the list of jobs will be limited only topage
index andlimit
specified.Using grouping with a list of field specified with
group_by
, results will be in the form:( [{category: {field1: valueA, field2: valueB, ...}, [Job(1), Job(2), ...], count: <count>}, {category: {field1: valueC, field2: valueD, ...}, [Job(x), Job(y), ...], count: <count>}, ... ], <total> )
Where
<total>
will again indicate all matched jobs by every category combined, and<count>
will indicate the amount of jobs matched for each individual category. Also,category
will indicate values of specified fields (fromgroup_by
) that compose corresponding jobs with matching values.
-
-
class
weaver.store.mongodb.
MongodbQuoteStore
(*args, **kwargs)[source]¶ Registry for quotes. Uses MongoDB to store quote attributes.
Initialize self. See help(type(self)) for accurate signature.
-
fetch_by_id
(self: AnyStr, quote_id) → Quote[source]¶ Gets quote for given
quote_id
from MongoDB storage.
-
find_quotes
(self: Optional[AnyStr], process_id: int = None, page: int = 0, limit: Optional[AnyStr] = 10, sort=None) → Tuple[List[Quote], int][source]¶ Finds all quotes in MongoDB storage matching search filters.
Returns a tuple of filtered
items
and theircount
, whereitems
can have paging and be limited to a maximum per page, butcount
always indicate the total number of matches.
-
-
class
weaver.store.mongodb.
MongodbBillStore
(*args, **kwargs)[source]¶ Registry for bills. Uses MongoDB to store bill attributes.
Initialize self. See help(type(self)) for accurate signature.
-
fetch_by_id
(self: AnyStr, bill_id) → Bill[source]¶ Gets bill for given
bill_id
from MongoDB storage.
-
find_bills
(self: Optional[AnyStr], quote_id: int = None, page: int = 0, limit: Optional[AnyStr] = 10, sort=None) → Tuple[List[Bill], int][source]¶ Finds all bills in MongoDB storage matching search filters.
Returns a tuple of filtered
items
and theircount
, whereitems
can have paging and be limited to a maximum per page, butcount
always indicate the total number of matches.
-