elyra_app.py 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. import os
  17. from jupyter_server.extension.application import ExtensionApp
  18. from jupyter_server.extension.application import ExtensionAppJinjaMixin
  19. from elyra._version import __version__
  20. from elyra.api.handlers import YamlSpecHandler
  21. from elyra.contents.handlers import ContentHandler
  22. from elyra.metadata.handlers import MetadataHandler
  23. from elyra.metadata.handlers import MetadataResourceHandler
  24. from elyra.metadata.handlers import SchemaHandler
  25. from elyra.metadata.handlers import SchemaResourceHandler
  26. from elyra.metadata.handlers import SchemaspaceHandler
  27. from elyra.metadata.handlers import SchemaspaceResourceHandler
  28. from elyra.metadata.manager import MetadataManager
  29. from elyra.metadata.schema import SchemaManager
  30. from elyra.metadata.storage import FileMetadataCache
  31. from elyra.pipeline.catalog_connector import ComponentCatalogConnector
  32. from elyra.pipeline.component_catalog import ComponentCache
  33. from elyra.pipeline.handlers import ComponentCacheCatalogHandler
  34. from elyra.pipeline.handlers import ComponentCacheHandler
  35. from elyra.pipeline.handlers import PipelineComponentHandler
  36. from elyra.pipeline.handlers import PipelineComponentPropertiesHandler
  37. from elyra.pipeline.handlers import PipelineExportHandler
  38. from elyra.pipeline.handlers import PipelinePropertiesHandler
  39. from elyra.pipeline.handlers import PipelineRuntimeTypesHandler
  40. from elyra.pipeline.handlers import PipelineSchedulerHandler
  41. from elyra.pipeline.handlers import PipelineValidationHandler
  42. from elyra.pipeline.processor import PipelineProcessor
  43. from elyra.pipeline.processor import PipelineProcessorManager
  44. from elyra.pipeline.processor import PipelineProcessorRegistry
  45. from elyra.pipeline.validation import PipelineValidationManager
  46. DEFAULT_STATIC_FILES_PATH = os.path.join(os.path.dirname(__file__), "static")
  47. DEFAULT_TEMPLATE_FILES_PATH = os.path.join(os.path.dirname(__file__), "templates")
  48. class ElyraApp(ExtensionAppJinjaMixin, ExtensionApp):
  49. # The name of the extension.
  50. name = "elyra"
  51. version = __version__
  52. description = "Elyra Server"
  53. extension_url = "/lab"
  54. load_other_extensions = True
  55. classes = [FileMetadataCache, MetadataManager, PipelineProcessor, ComponentCatalogConnector, ComponentCache]
  56. # Local path to static files directory.
  57. static_paths = [
  58. os.path.join(DEFAULT_STATIC_FILES_PATH, "icons"),
  59. ]
  60. # Local path to templates directory.
  61. # template_paths = [
  62. # DEFAULT_TEMPLATE_FILES_PATH
  63. # ]
  64. # Define ElyraApp configurables here..
  65. def initialize_handlers(self):
  66. schemaspace_regex = r"(?P<schemaspace>[\w\.\-]+)"
  67. resource_regex = r"(?P<resource>[\w\.\-]+)"
  68. path_regex = r"(?P<path>(?:(?:/[^/]+)+|/?))" # same as jupyter server and will include a leading slash
  69. processor_regex = r"(?P<runtime_type>[\w]+)"
  70. component_regex = r"(?P<component_id>[\w\.\-:%]+)"
  71. catalog_regex = r"(?P<catalog>[\w\.\-:]+)"
  72. self.handlers.extend(
  73. [
  74. # API
  75. (f"/{self.name}/{YamlSpecHandler.get_resource_metadata()[0]}", YamlSpecHandler),
  76. # Content
  77. (f"/{self.name}/contents/properties{path_regex}", ContentHandler),
  78. # Metadata
  79. (f"/{self.name}/metadata/{schemaspace_regex}", MetadataHandler),
  80. (f"/{self.name}/metadata/{schemaspace_regex}/{resource_regex}", MetadataResourceHandler),
  81. (f"/{self.name}/schema/{schemaspace_regex}", SchemaHandler),
  82. (f"/{self.name}/schema/{schemaspace_regex}/{resource_regex}", SchemaResourceHandler),
  83. (f"/{self.name}/schemaspace", SchemaspaceHandler),
  84. (f"/{self.name}/schemaspace/{schemaspace_regex}", SchemaspaceResourceHandler),
  85. # Pipeline
  86. (f"/{self.name}/pipeline/components/cache", ComponentCacheHandler),
  87. (f"/{self.name}/pipeline/components/cache/{catalog_regex}", ComponentCacheCatalogHandler),
  88. (f"/{self.name}/pipeline/components/{processor_regex}", PipelineComponentHandler),
  89. (
  90. f"/{self.name}/pipeline/components/{processor_regex}/{component_regex}",
  91. PipelineComponentPropertiesHandler,
  92. ),
  93. (
  94. f"/{self.name}/pipeline/components/{processor_regex}/{component_regex}/properties",
  95. PipelineComponentPropertiesHandler,
  96. ),
  97. (f"/{self.name}/pipeline/export", PipelineExportHandler),
  98. (f"/{self.name}/pipeline/{processor_regex}/properties", PipelinePropertiesHandler),
  99. (f"/{self.name}/pipeline/runtimes/types", PipelineRuntimeTypesHandler),
  100. (f"/{self.name}/pipeline/schedule", PipelineSchedulerHandler),
  101. (f"/{self.name}/pipeline/validate", PipelineValidationHandler),
  102. ]
  103. )
  104. def initialize_settings(self):
  105. self.log.info(f"Config {self.config}")
  106. # Instantiate singletons with appropriate parent to enable configurability, and convey
  107. # root_dir to PipelineProcessorManager.
  108. PipelineProcessorRegistry.instance(root_dir=self.settings["server_root_dir"], parent=self)
  109. PipelineProcessorManager.instance(root_dir=self.settings["server_root_dir"], parent=self)
  110. PipelineValidationManager.instance(root_dir=self.settings["server_root_dir"], parent=self)
  111. FileMetadataCache.instance(parent=self)
  112. ComponentCache.instance(parent=self).load()
  113. SchemaManager.instance(parent=self)
  114. def initialize_templates(self):
  115. pass
  116. async def stop_extension(self):
  117. if ComponentCache.initialized():
  118. ComponentCache.instance(parent=self).cache_manager.stop() # terminate CacheUpdateManager
  119. launch_instance = ElyraApp.launch_instance