Răsfoiți Sursa

HUE-1294 [jobsub] 2.x to 2.3 upgrade broken

- Refactor to use OozieDesign
- Workflow construction was broken... fixed
Abraham Elmahrek 12 ani în urmă
părinte
comite
5b06b1e565

+ 28 - 5
apps/jobsub/src/jobsub/migrations/0005_unify_with_oozie.py

@@ -1,32 +1,55 @@
 # encoding: utf-8
 import datetime
+from django.contrib.auth.models import User
 from django.utils.translation import ugettext as _
 from south.db import db
 from south.v2 import DataMigration
 from django.db import models
 from oozie.import_jobsub import convert_jobsub_design
-from oozie.models import Workflow
+from oozie.models import Workflow, Kill, Start, End
 
 
 class Migration(DataMigration):
+    depends_on = (
+        # Need to ensure oozie is completely sync'd before jobsub.
+        # This migration relies on the existence of the complete oozie model in the DB.
+        # If a new oozie schema migration is added, then this will need to be updated as well.
+        ("oozie", "0021_auto__chg_field_java_args__add_field_job_is_trashed"),
+    )
+
     def forwards(self, orm):
         """ Find every design and move them into Oozie. """
-        for design in orm.JobDesign.objects.all():
+        for design in orm.OozieDesign.objects.all():
             action = convert_jobsub_design(design)
 
             if not action:
                 raise RuntimeError(_("Cannot convert %s design into an Oozie action.") % design.name)
 
-            workflow = Workflow.objects.new_workflow(request.user)
+            # User is guaranteed to exist since this executes for upgrades only.
+            workflow = Workflow.objects.new_workflow(User.objects.get(id=design.owner.pk))
             workflow.name = action.name
-            workflow.owner = design.owner
             workflow.description = design.description
             # Inform oozie to not manage this workflow.
             workflow.managed = False
+            workflow.save()
+
+            workflow.start.workflow = workflow
+            workflow.start.save()
+            workflow.start = Start.objects.get(id=workflow.start.id)
+
+            workflow.end.workflow = workflow
+            workflow.end.save()
+            workflow.end = End.objects.get(id=workflow.end.id)
+
+            Kill.objects.create(name='kill', workflow=workflow, node_type=Kill.node_type)
+
             action.workflow = workflow
+            action.save()
+
+            workflow.start.add_node(action)
+            action.add_node(workflow.end)
 
             workflow.save()
-            action.save()
 
 
     def backwards(self, orm):

+ 17 - 1
apps/oozie/src/oozie/import_jobsub.py

@@ -6,9 +6,25 @@ from jobsub.models import OozieDesign, OozieMapreduceAction, OozieStreamingActio
 from oozie.models import Mapreduce, Java, Streaming
 
 
+def get_root_action(design):
+  root = design.root_action
+  if root is None:
+    return None
+  if root.action_type == OozieMapreduceAction.ACTION_TYPE:
+    return root.ooziemapreduceaction
+  elif root.action_type == OozieStreamingAction.ACTION_TYPE:
+    return root.ooziestreamingaction
+  elif root.action_type == OozieJavaAction.ACTION_TYPE:
+    return root.ooziejavaaction
+
+  LOG.error("Oozie action type '%s' is not valid (jobsub_oozieaction.id %s)"
+            % (root.action_type, root.id))
+  return None
+
+
 def convert_jobsub_design(jobsub_design):
   """Creates an oozie action from a jobsub design"""
-  action = jobsub_design.get_root_action()
+  action = get_root_action(jobsub_design)
   if action is None:
     return None
   if action.action_type == OozieMapreduceAction.ACTION_TYPE: