|
| 1 | +# -*- coding:utf-8 -*- |
| 2 | +# |
| 3 | +# DataWay Algorithm SDK |
| 4 | +# Initial Date: 2018.10.27 |
| 5 | +# |
| 6 | +# Title: methods for metadata of pattern |
| 7 | +# |
| 8 | +# Version 1.0 |
| 9 | +# |
| 10 | + |
| 11 | +from dwf.ormmodels import * |
| 12 | +from dwf.common.log import logger |
| 13 | +from dwf.common.exception import * |
| 14 | +from dwf.util.id import generate_primary_key |
| 15 | + |
| 16 | + |
| 17 | +class DataPatternCRUD: |
| 18 | + |
| 19 | + def __init__(self, db_session): |
| 20 | + self.db_session = db_session |
| 21 | + |
| 22 | + def add_datapattern(self, name, semantic=None): |
| 23 | + # NO.A317 |
| 24 | + # Wait for jinying |
| 25 | + # Args: |
| 26 | + # package_name - The name of package. |
| 27 | + # deployment_path - The path to deploy algorithm. |
| 28 | + # upload_source - The upload source of package. |
| 29 | + # requirement_list - Dependencies of algorithms in this package. |
| 30 | + # Returns: |
| 31 | + # package_id |
| 32 | + # hyperparameter_config |
| 33 | + # Exceptions: |
| 34 | + # ADD_FAILURE |
| 35 | + id = generate_primary_key('DPAT') |
| 36 | + pattern = DataPattern(id=id, name=name, semantic=semantic) |
| 37 | + self.db_session.add(pattern) |
| 38 | + self.db_session.commit() |
| 39 | + return id |
| 40 | + |
| 41 | + def delete_datapattern(self, delete_pattern_id): |
| 42 | + # NO.A320 |
| 43 | + # Wait for jinying |
| 44 | + # Args: |
| 45 | + # package_id: The id of package to be deleted. |
| 46 | + # Returns: |
| 47 | + # None. |
| 48 | + # Exceptions: |
| 49 | + # NON_EXISTING_PACKAGE - The given package_id does not exist. |
| 50 | + # DELETE_FAILURE - The package cannot be deleted. |
| 51 | + pending = self.db_session.query(DataPattern).get(delete_pattern_id) |
| 52 | + self.db_session.delete(pending) |
| 53 | + self.db_session.commit() |
| 54 | + return |
| 55 | + |
| 56 | + def update_datapattern(self, delete_pattern_id, name=None, semantic=None): |
| 57 | + # NO.A321 |
| 58 | + # Wait for jinying |
| 59 | + # Args: |
| 60 | + # package_name - The name of package. |
| 61 | + # deployment_path - The path to deploy algorithm. |
| 62 | + # upload_source - The upload source of package. |
| 63 | + # requirement_list - Dependencies of algorithms in this package. |
| 64 | + # Returns: |
| 65 | + # package_id - The id of package. |
| 66 | + # conda_id - The id of conda. |
| 67 | + # Exceptions: |
| 68 | + # UPDATE_FAILURE - Fail to add this package. |
| 69 | + pending = self.db_session.query(DataPattern).get(delete_pattern_id) |
| 70 | + if delete_pattern_id is None: |
| 71 | + logger.error('delete_pattern_id is needed') |
| 72 | + raise PARAM_LACK |
| 73 | + |
| 74 | + if name is not None: |
| 75 | + pending.plt_name = name |
| 76 | + if semantic is not None: |
| 77 | + pending.semantic = semantic |
| 78 | + self.db_session.commit() |
| 79 | + return pending |
| 80 | + |
| 81 | + def query_datapattern(self, delete_pattern_id): |
| 82 | + # NO.A322 |
| 83 | + # Wait for jinying |
| 84 | + # Args: |
| 85 | + # package_id: The id of package. |
| 86 | + # Returns: |
| 87 | + # { |
| 88 | + # package_name:"***", |
| 89 | + # deployment_path:"***", |
| 90 | + # upload_source:"***", |
| 91 | + # requirement_list:"***" |
| 92 | + # } |
| 93 | + pending = self.db_session.query(DataPattern).get(delete_pattern_id) |
| 94 | + if pending is None: |
| 95 | + logger.error('data pattern is not found') |
| 96 | + raise NON_EXISTING_DATA_PATTERN |
| 97 | + return pending |
0 commit comments