Skip to content

Commit

Permalink
fix azure tags
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Heisterkamp committed Oct 29, 2024
1 parent f3c7b81 commit 58f17b5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
32 changes: 15 additions & 17 deletions src/spetlr/utils/AzureTags.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
import json
from typing import Dict

from spetlr.spark import Spark


class AzureTags:
"""Represents easy access to the azure resource tags of the workspace."""

_tags = None
def __init__(self):
tags_json = Spark.get().conf.get(
"spark.databricks.clusterUsageTags.clusterAllTags"
)
self._tags: Dict[str, str] = {
i["key"]: i["value"] for i in json.loads(tags_json)
}

@classmethod
def init(cls):
if cls._tags is None:
tags_json = Spark.get().conf.get(
"spark.databricks.clusterUsageTags.clusterAllTags"
)
cls._tags = {i["key"]: i["value"] for i in json.loads(tags_json)}
def keys(self):
return self._tags.keys()

@classmethod
def keys(cls):
cls.init()
return cls._tags.keys()

@classmethod
def __getattr__(cls, attr):
def __getattr__(self, attr) -> str:
# only called when self.attr doesn't exist
cls.init()
return cls._tags[attr]
return self._tags[attr]

def asDict(self) -> Dict[str, str]:
return self._tags.copy()
2 changes: 1 addition & 1 deletion tests/cluster/eh/test_eh_saving.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def test_01_publish_and_read(self):
time.sleep(100) # just wait the EH captures once a minute anyway.

tc = Configurator()
tc.register("ws", AzureTags.resource_name)
tc.register("ws", AzureTags().resource_name)

tc.register(
"SpetlrEh",
Expand Down

0 comments on commit 58f17b5

Please sign in to comment.