runtime_type.py 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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 enum import Enum
  17. from enum import unique
  18. from typing import Any
  19. from typing import Dict
  20. from typing import List
  21. @unique
  22. class RuntimeProcessorType(Enum):
  23. """RuntimeProcessorType enumerates the set of platforms targeted by runtime processors.
  24. Each runtime processor implementation (subclass of PipelineProcessor) will reflect one
  25. of these values. Users implementing their own runtime processor that corresponds to a
  26. type not listed in this enumeration are responsible for appropriately extending this
  27. enumeration and reflecting that entry in the corresponding runtime schema in order to
  28. fully integrate their processor with Elyra.
  29. """
  30. LOCAL = "Local"
  31. KUBEFLOW_PIPELINES = "Kubeflow Pipelines"
  32. APACHE_AIRFLOW = "Apache Airflow"
  33. ARGO = "Argo"
  34. ######################################
  35. # Add new entry here for each new type
  36. ######################################
  37. @staticmethod
  38. def get_instance_by_name(name: str) -> "RuntimeProcessorType":
  39. """Returns an instance of RuntimeProcessorType corresponding to the given name.
  40. Raises KeyError if parameter is not a name in the enumeration.
  41. """
  42. return RuntimeProcessorType.__members__[name]
  43. @staticmethod
  44. def get_instance_by_value(value: str) -> "RuntimeProcessorType":
  45. """Returns an instance of RuntimeProcessorType corresponding to the given value.
  46. Raises KeyError if parameter is not a value in the enumeration.
  47. """
  48. for instance in RuntimeProcessorType.__members__.values():
  49. if instance.value == value:
  50. return instance
  51. raise KeyError(f"'{value}'")
  52. class RuntimeTypeResources(object):
  53. """Base class for a runtime processor's information"""
  54. type: RuntimeProcessorType
  55. icon_endpoint: str
  56. export_file_types: List[Dict[str, str]]
  57. @classmethod
  58. def get_instance_by_type(cls, runtime_type: RuntimeProcessorType) -> "RuntimeTypeResources":
  59. if runtime_type == RuntimeProcessorType.KUBEFLOW_PIPELINES:
  60. return KubeflowPipelinesResources()
  61. if runtime_type == RuntimeProcessorType.APACHE_AIRFLOW:
  62. return ApacheAirflowResources()
  63. if runtime_type == RuntimeProcessorType.ARGO:
  64. return ArgoResources()
  65. if runtime_type == RuntimeProcessorType.LOCAL:
  66. return LocalResources()
  67. raise ValueError(f"Runtime type {runtime_type} is not recognized.")
  68. @property
  69. def id(self) -> str:
  70. return self.type.name
  71. @property
  72. def display_name(self) -> str:
  73. return self.type.value
  74. def to_dict(self) -> Dict[str, Any]:
  75. d = dict(
  76. id=self.id,
  77. display_name=self.display_name,
  78. icon=self.icon_endpoint,
  79. export_file_types=self.export_file_types,
  80. )
  81. return d
  82. def get_export_extensions(self) -> List[str]:
  83. """
  84. Return a list of supported export file extensions (as represented by the 'id'
  85. key of each dictionary in the export_file_types list).
  86. """
  87. return [file_type.get("id") for file_type in self.export_file_types]
  88. class ArgoResources(RuntimeTypeResources):
  89. """Holds static information relative to Argo processors"""
  90. type = RuntimeProcessorType.ARGO
  91. icon_endpoint = "static/elyra/argo.svg"
  92. export_file_types = [{"id": "py", "display_name": "Argo domain-specific language Python code"}]
  93. class ApacheAirflowResources(RuntimeTypeResources):
  94. """Holds static information relative to Apache Airflow processors"""
  95. type = RuntimeProcessorType.APACHE_AIRFLOW
  96. icon_endpoint = "static/elyra/airflow.svg"
  97. export_file_types = [{"id": "py", "display_name": "Airflow domain-specific language Python code"}]
  98. class KubeflowPipelinesResources(RuntimeTypeResources):
  99. """Holds static information relative to Kubeflow Pipelines processors"""
  100. type = RuntimeProcessorType.KUBEFLOW_PIPELINES
  101. icon_endpoint = "static/elyra/kubeflow.svg"
  102. export_file_types = [{"id": "yaml", "display_name": "KFP static configuration file (YAML formatted)"}]
  103. class LocalResources(RuntimeTypeResources):
  104. """Holds static information relative to local processors"""
  105. type = RuntimeProcessorType.LOCAL
  106. icon_endpoint = "static/elyra/pipeline-flow.svg"
  107. export_file_types = []
  108. ###########################################################
  109. # Add new platform info definitions here for each new type
  110. ###########################################################