Explorar el Código

HUE-2881 [oozie] A fork can point to a deleted node

This does not fix the root cause, but could not reproduce it.
This however remove the dead link from the fork at submission time.
Romain Rigaux hace 10 años
padre
commit
6903d54
Se han modificado 2 ficheros con 16 adiciones y 1 borrados
  1. 7 0
      apps/oozie/src/oozie/models2.py
  2. 9 1
      apps/oozie/src/oozie/tests2.py

+ 7 - 0
apps/oozie/src/oozie/models2.py

@@ -311,6 +311,13 @@ class Node():
     if self.data['type'] == 'hive2' and not self.data['properties']['jdbc_url']:
       self.data['properties']['jdbc_url'] = _get_hiveserver2_url()
 
+    if self.data['type'] == 'fork':
+      links = [link for link in self.data['children'] if link['to'] in node_mapping]
+      if len(links) != len(self.data['children']):
+        LOG.warn('Fork has some children links that do not exist, ignoring them: links %s, existing links %s, links %s, existing links %s' \
+                 % (len(links), len(self.data['children']), links, self.data['children']))
+        self.data['children'] = links
+
     data = {
       'node': self.data,
       'mapping': mapping,

+ 9 - 1
apps/oozie/src/oozie/tests2.py

@@ -21,7 +21,7 @@ import logging
 
 from nose.tools import assert_true, assert_false, assert_equal, assert_not_equal
 
-from oozie.models2 import Workflow, find_dollar_variables, find_dollar_braced_variables
+from oozie.models2 import Workflow, find_dollar_variables, find_dollar_braced_variables, Node
 
 
 LOG = logging.getLogger(__name__)
@@ -109,3 +109,11 @@ LIMIT $limit"""))
 
     job.update_name('My <...> 1st W$rkflow [With] (Bad) letter$')
     assert_equal('My_______1st_W$rkflow__With___Bad__lette', job.validated_name)
+
+  def test_ignore_dead_fork_link(self):
+    data = {'id': 1, 'type': 'fork', 'children': [{'to': 1, 'id': 1}, {'to': 2, 'id': 2}], 'properties': {}, 'name': 'my-fork'} # to --> 2 does not exist
+    fork = Node(data)
+
+    node_mapping = {1: fork} # Point to ourself
+
+    assert_equal(['<fork', 'name="my-fork">', '<path', 'start="my-fork"', '/>', '</fork>'], fork.to_xml(node_mapping=node_mapping).split())