component_metadata.py 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #
  2. # Copyright 2018-2022 Elyra Authors
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. #
  16. from typing import Any
  17. from elyra.metadata.metadata import Metadata
  18. # Rather than importing only the ComponentCache class needed in the post_save and
  19. # post_delete hooks below, the component_catalog module must be imported in its
  20. # entirety in order to avoid a circular reference issue
  21. try:
  22. from elyra.pipeline import component_catalog
  23. except ImportError:
  24. import sys
  25. component_catalog = sys.modules[__package__ + ".component_catalog"]
  26. from elyra.pipeline.runtime_type import RuntimeProcessorType # noqa:I202
  27. class ComponentRegistryMetadata(Metadata):
  28. pass
  29. class ComponentCatalogMetadata(Metadata):
  30. """
  31. This class contains methods to trigger cache updates on modification
  32. and deletion of component catalog metadata instances.
  33. """
  34. @property
  35. def runtime_type(self) -> RuntimeProcessorType:
  36. return RuntimeProcessorType.get_instance_by_name(self.metadata["runtime_type"])
  37. def post_save(self, **kwargs: Any) -> None:
  38. try: # Modify components associated with this catalog on creates and updates.
  39. component_catalog.ComponentCache.instance().update(catalog=self, action="modify")
  40. except Exception:
  41. # An attempted component cache update will fail silently with most errors
  42. # logged from the ComponentCache class methods. However, a log message
  43. # should eventually be added here as well
  44. pass
  45. def post_delete(self, **kwargs: Any) -> None:
  46. try: # Remove components associated with this catalog on deletes.
  47. component_catalog.ComponentCache.instance().update(catalog=self, action="delete")
  48. except Exception:
  49. # An attempted component cache update will fail silently with most errors
  50. # logged from the ComponentCache class methods. However, a log message
  51. # should eventually be added here as well
  52. pass
  53. class UrlCatalogMetadata(ComponentCatalogMetadata):
  54. pass
  55. class DirectoryCatalogMetadata(ComponentCatalogMetadata):
  56. pass
  57. class FilenameCatalogMetadata(ComponentCatalogMetadata):
  58. pass