runtimes_metadata.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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 logging import getLogger
  17. from typing import Any
  18. from elyra.metadata.manager import MetadataManager
  19. from elyra.metadata.metadata import Metadata
  20. class RuntimesMetadata(Metadata):
  21. """
  22. This class will be instantiated for any instance for a schema within the
  23. Runtimes schemaspace.
  24. """
  25. def on_load(self, **kwargs: Any) -> None:
  26. """Perform any necessary adjustments, migrations when instance is loaded."""
  27. # If there's no runtime_type property in the instance metadata, infer from schema_name
  28. if "runtime_type" not in self.metadata:
  29. if self.schema_name == "kfp":
  30. self.metadata["runtime_type"] = "KUBEFLOW_PIPELINES"
  31. elif self.schema_name == "airflow":
  32. self.metadata["runtime_type"] = "APACHE_AIRFLOW"
  33. elif self.schema_name == "argo":
  34. self.metadata["runtime_type"] = "ARGO"
  35. else:
  36. raise ValueError(f"Unknown Runtimes schema name detected: '{self.schema_name}'! Skipping...")
  37. getLogger("ServerApp").info(
  38. f"Upgrading runtime {self.schema_name} instance '{self.name}' "
  39. f"to include runtime_type '{self.metadata['runtime_type']}'..."
  40. )
  41. MetadataManager(schemaspace="runtimes").update(self.name, self, for_migration=True)