Przeglądaj źródła

HUE-2449 [oozie] Raise an exception if oozie frequency is invalid

Erick Tryzelaar 11 lat temu
rodzic
commit
3ec3ff79d7
1 zmienionych plików z 20 dodań i 3 usunięć
  1. 20 3
      apps/oozie/src/oozie/utils.py

+ 20 - 3
apps/oozie/src/oozie/utils.py

@@ -135,8 +135,25 @@ def oozie_to_django_datetime(dt_string):
   return None
 
 
+class InvalidFrequency(Exception):
+  pass
+
+
 def oozie_to_hue_frequency(frequency_string):
-  # Get frequency number and units from frequency
-  # frequency units and number are just different parts of the EL function.
+  """
+  Get frequency number and units from frequency, which must be of the format
+  "${coord:$unit($number)}".
+
+  frequency units and number are just different parts of the EL function.
+
+  Returns:
+    A tuple of the frequency unit and number
+
+  Raises:
+    InvalidFrequency: If the `frequency_string` does not match the frequency pattern.
+  """
   matches = re.match(FREQUENCY_REGEX, frequency_string)
-  return matches.group('frequency_unit'), matches.group('frequency_number')
+  if matches:
+    return matches.group('frequency_unit'), matches.group('frequency_number')
+  else:
+    raise InvalidFrequency(_('invalid frequency: %s') % frequency_string)